LCOV - code coverage report
Current view: top level - RAW/RAWDatarec - AliRawReaderChain.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 191 1.0 %
Date: 2016-06-14 17:26:59 Functions: 2 25 8.0 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : ///////////////////////////////////////////////////////////////////////////////
      17             : ///
      18             : /// This is a class for reading raw data from a root chain.
      19             : /// There are two constructors available - one from a text file containing the
      20             : /// list of root raw-data files to be processed and one directly from
      21             : /// TFileCollection.
      22             : ///
      23             : /// cvetan.cheshkov@cern.ch 29/07/2008
      24             : ///
      25             : ///////////////////////////////////////////////////////////////////////////////
      26             : 
      27             : #include <TChain.h>
      28             : #include <TFileCollection.h>
      29             : #include <TEntryList.h>
      30             : #include "TGridCollection.h"
      31             : #include <TPluginManager.h>
      32             : #include <TROOT.h>
      33             : #include <TSystem.h>
      34             : #include <TFile.h>
      35             : #include <TKey.h>
      36             : #include <TGrid.h>
      37             : #include <TGridResult.h>
      38             : 
      39             : #include "AliRawReaderChain.h"
      40             : #include "AliRawVEvent.h"
      41             : #include "AliLog.h"
      42             : 
      43         128 : ClassImp(AliRawReaderChain)
      44             : 
      45         128 : TString AliRawReaderChain::fgSearchPath = "/alice/data";
      46             : 
      47             : AliRawReaderChain::AliRawReaderChain() :
      48           0 :   AliRawReaderRoot(),
      49           0 :   fChain(NULL)
      50           0 : {
      51             :   // default constructor
      52           0 : }
      53             : 
      54             : AliRawReaderChain::AliRawReaderChain(const char* fileName) :
      55           0 :   AliRawReaderRoot(),
      56           0 :   fChain(NULL)
      57           0 : {
      58             : // create raw-reader objects which takes as an input a root chain
      59             : // either from the file list found in 'fileName' (IsCollection = true)
      60             : // or from entry list found in 'filename' (IsCollection = false)
      61             : // The entry-list syntax follows root convetion: filename.root/listname
      62             : 
      63           0 :   fChain = new TChain("RAW");
      64             : 
      65           0 :   TString fileNameStr = fileName;
      66           0 :   if (fileNameStr.EndsWith(".xml")) {
      67             : 
      68             :     TGridCollection *collection = NULL;
      69           0 :     TPluginManager* pluginManager = gROOT->GetPluginManager();
      70           0 :     TPluginHandler* pluginHandler = pluginManager->FindHandler("TGridCollection", "alice");
      71           0 :     if (!pluginHandler) {
      72           0 :       pluginManager->AddHandler("TGridCollection", "alice", 
      73             :                                 "AliXMLCollection", "ANALYSISalice", "AliXMLCollection(const char*)");
      74           0 :       pluginHandler = pluginManager->FindHandler("TGridCollection", "alice");
      75           0 :     }
      76           0 :     gSystem->Load("libANALYSIS");
      77           0 :     if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
      78           0 :       collection = (TGridCollection*)pluginHandler->ExecPlugin(1,fileNameStr.Data());
      79             :     }
      80             :     else {
      81           0 :       fIsValid = kFALSE;
      82           0 :       return;
      83             :     }
      84           0 :     collection->Reset();
      85             :     Bool_t elistsExist = kFALSE;
      86           0 :     TEntryList *elist = new TEntryList();
      87           0 :     while (collection->Next()) {
      88           0 :       fChain->Add(collection->GetTURL(""));
      89           0 :       TEntryList *list = (TEntryList *)collection->GetEntryList("");
      90           0 :       if (list) {
      91           0 :         list->SetTreeName("RAW");
      92           0 :         list->SetFileName(collection->GetTURL(""));
      93           0 :         elist->Add(list);
      94             :         elistsExist = kTRUE;
      95           0 :       }
      96             :     }
      97           0 :     if (elistsExist) {
      98           0 :       fChain->SetEntryList(elist,"ne");
      99             :     }
     100             :     else {
     101           0 :       Info("AliRawReaderChain", "no entry lists found in %s. Using all entries", fileNameStr.Data());
     102           0 :       delete elist;
     103             :     }
     104           0 :   }
     105           0 :   else if (fileNameStr.EndsWith(".root")) {
     106             : 
     107           0 :     TDirectory* dir = gDirectory;
     108           0 :     TFile *listFile = TFile::Open(fileNameStr.Data());
     109           0 :     dir->cd();
     110           0 :     if (!listFile || !listFile->IsOpen()) {
     111           0 :       Error("AliRawReaderChain", "could not open file %s", fileNameStr.Data());
     112           0 :       fIsValid = kFALSE;
     113           0 :       return;
     114             :     }
     115             : 
     116             :     TEntryList *elist = NULL;
     117             :     TKey *key = NULL;
     118           0 :     TIter nextkey(listFile->GetListOfKeys());
     119           0 :     while ((key=(TKey*)nextkey())){
     120           0 :       if (strcmp("TEntryList", key->GetClassName())==0){
     121           0 :         elist = (TEntryList*)key->ReadObj();
     122           0 :       }
     123             :     }
     124           0 :     if (!elist) {
     125           0 :       Error("AliRawReaderChain", "no TEntryList found in %s", fileNameStr.Data());
     126           0 :       fIsValid = kFALSE;
     127           0 :       return;
     128             :     }
     129             : 
     130             :     TEntryList *templist = NULL;
     131           0 :     TList *elists = elist->GetLists();
     132           0 :     TIter next(elists);
     133           0 :     while((templist = (TEntryList*)next())){
     134           0 :       Info("AliRawReaderChain", "%s added to the chain", templist->GetFileName());
     135           0 :       fChain->Add(templist->GetFileName());
     136             :     }
     137           0 :     fChain->SetEntryList(elist,"ne");
     138           0 :   }
     139             :   else {
     140             : 
     141           0 :     TFileCollection collection("RAW",
     142             :                                "Collection with raw-data files",
     143           0 :                                fileNameStr.Data());
     144             : 
     145           0 :     if (!fChain->AddFileInfoList((TCollection*)(collection.GetList()))) {
     146           0 :       Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
     147           0 :       fIsValid = kFALSE;
     148           0 :       return;
     149             :     }
     150           0 :   }
     151             : 
     152           0 :   fChain->SetBranchStatus("*",1);
     153           0 :   fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
     154           0 : }
     155             : 
     156             : AliRawReaderChain::AliRawReaderChain(TFileCollection *collection) :
     157           0 :   AliRawReaderRoot(),
     158           0 :   fChain(NULL)
     159           0 : {
     160             : // create raw-reader objects which takes as an input a root chain
     161             : // from a root file collection
     162             : 
     163           0 :   fChain = new TChain("RAW");
     164           0 :   if (!fChain->AddFileInfoList((TCollection*)(collection->GetList()))) {
     165           0 :     Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
     166           0 :     fIsValid = kFALSE;
     167           0 :     return;
     168             :   }
     169             : 
     170           0 :   fChain->SetBranchStatus("*",1);
     171           0 :   fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
     172           0 : }
     173             : 
     174             : AliRawReaderChain::AliRawReaderChain(TChain *chain) :
     175           0 :   AliRawReaderRoot(),
     176           0 :   fChain(chain)
     177           0 : {
     178             : // create raw-reader objects which takes as an input a root chain
     179             : // from a root file collection
     180             : 
     181           0 :   if (!fChain) {
     182           0 :     fIsValid = kFALSE;
     183           0 :     return;
     184             :   }
     185             : 
     186           0 :   fChain->SetBranchStatus("*",1);
     187           0 :   fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
     188           0 : }
     189             : 
     190             : AliRawReaderChain::AliRawReaderChain(TEntryList *elist) :
     191           0 :   AliRawReaderRoot(),
     192           0 :   fChain(NULL)
     193           0 : {
     194             : // create raw-reader objects which takes as an input a root chain
     195             : // from a root file collection
     196             : 
     197           0 :   if (!elist) {
     198           0 :     fIsValid = kFALSE;
     199           0 :     return;
     200             :   }
     201             : 
     202           0 :   fChain = new TChain("RAW");
     203             : 
     204             :   TEntryList *templist = NULL;
     205           0 :   TList *elists = elist->GetLists();
     206           0 :   TIter next(elists);
     207           0 :   while((templist = (TEntryList*)next())){
     208           0 :     fChain->Add(templist->GetFileName());
     209             :   }
     210           0 :   fChain->SetEntryList(elist,"ne");
     211             : 
     212           0 :   fChain->SetBranchStatus("*",1);
     213           0 :   fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
     214           0 : }
     215             : 
     216             : AliRawReaderChain::AliRawReaderChain(Int_t runNumber) :
     217           0 :   AliRawReaderRoot(),
     218           0 :   fChain(NULL)
     219           0 : {
     220             : // create raw-reader objects which takes as an input a root chain
     221             : // with the raw-data files for a given run
     222             : // It queries alien FC in order to do that and therefore
     223             : // it needs alien API to be enabled
     224             : 
     225           0 :   if (runNumber <= 0) {
     226           0 :     Error("AliRawReaderChain","Bad run number:%d",runNumber);
     227           0 :     fIsValid = kFALSE;
     228           0 :   }
     229             : 
     230           0 :   if (!gGrid) TGrid::Connect("alien://");
     231           0 :   if (!gGrid) {
     232           0 :     fIsValid = kFALSE;
     233           0 :     return;
     234             :   }
     235             : 
     236           0 :   if (fgSearchPath.IsNull()) fgSearchPath = "/alice/data";
     237           0 :   TGridResult *res = gGrid->Query(fgSearchPath.Data(),Form("%09d/raw/*%09d*.root",runNumber,runNumber));
     238           0 :   Int_t nFiles = res->GetEntries();
     239           0 :   if (!nFiles) {
     240           0 :     Error("AliRawReaderChain","No raw-data files found for run %d",runNumber);
     241           0 :     fIsValid = kFALSE;
     242           0 :     delete res;
     243           0 :     return;
     244             :   }
     245             : 
     246           0 :   fChain = new TChain("RAW");
     247           0 :   for (Int_t i = 0; i < nFiles; i++) {
     248           0 :     TString filename = res->GetKey(i, "turl");
     249           0 :     if(filename == "") continue;
     250           0 :     fChain->Add(filename.Data());
     251           0 :   }
     252           0 :   delete res;
     253             : 
     254           0 :   fChain->SetBranchStatus("*",1);
     255           0 :   fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
     256           0 : }
     257             : 
     258             : 
     259             : AliRawReaderChain::AliRawReaderChain(const AliRawReaderChain& rawReader) :
     260           0 :   AliRawReaderRoot(rawReader),
     261           0 :   fChain(rawReader.fChain)
     262           0 : {
     263             : // copy constructor
     264           0 : }
     265             : 
     266             : AliRawReaderChain& AliRawReaderChain::operator = (const AliRawReaderChain& 
     267             :                                                   rawReader)
     268             : {
     269             : // assignment operator
     270             : 
     271           0 :   this->~AliRawReaderChain();
     272           0 :   new(this) AliRawReaderChain(rawReader);
     273           0 :   return *this;
     274           0 : }
     275             : 
     276             : AliRawReaderChain::~AliRawReaderChain()
     277           0 : {
     278             : // delete objects and close root file
     279             : 
     280           0 :   if (fChain) {
     281           0 :     delete fChain;
     282           0 :     fChain = NULL;
     283           0 :   }
     284           0 : }
     285             : 
     286             : Bool_t AliRawReaderChain::NextEvent()
     287             : {
     288             : // go to the next event in the root file
     289             : 
     290           0 :   if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
     291             : 
     292             :   do {
     293           0 :     delete fEvent;
     294           0 :     fEvent = NULL;
     295           0 :     fEventHeader = NULL;
     296           0 :     Long64_t treeEntry = fChain->LoadTree(fEventIndex+1);
     297           0 :     if (!fBranch)
     298           0 :       return kFALSE;
     299           0 :     if (fBranch->GetEntry(treeEntry) <= 0)
     300           0 :       return kFALSE;
     301           0 :     fEventHeader = fEvent->GetHeader();
     302           0 :     fEventIndex++;
     303           0 :   } while (!IsEventSelected());
     304           0 :   fEventNumber++;
     305           0 :   return Reset();
     306           0 : }
     307             : 
     308             : Bool_t AliRawReaderChain::RewindEvents()
     309             : {
     310             : // go back to the beginning of the root file
     311             : 
     312           0 :   fEventIndex = -1;
     313           0 :   delete fEvent;
     314           0 :   fEvent = NULL;
     315           0 :   fEventHeader = NULL;
     316           0 :   fEventNumber = -1;
     317           0 :   return Reset();
     318             : }
     319             : 
     320             : Bool_t  AliRawReaderChain::GotoEvent(Int_t event)
     321             : {
     322             :   // go to a particular event
     323             :   // Uses the absolute event index inside the
     324             :   // chain with raw data
     325             : 
     326           0 :   if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
     327             : 
     328           0 :   delete fEvent;
     329           0 :   fEvent = NULL;
     330           0 :   fEventHeader = NULL;
     331           0 :   Long64_t treeEntry = fChain->LoadTree(event);
     332           0 :    if (!fBranch)
     333           0 :     return kFALSE;
     334           0 :   if (fBranch->GetEntry(treeEntry) <= 0)
     335           0 :     return kFALSE;
     336           0 :   fEventHeader = fEvent->GetHeader();
     337           0 :   fEventIndex = event;
     338           0 :   fEventNumber++;
     339           0 :   return Reset();
     340           0 : }
     341             : 
     342             : Int_t AliRawReaderChain::GetNumberOfEvents() const
     343             : {
     344             :   // Get the total number of events in the chain
     345             :   // of raw-data files
     346             : 
     347           0 :   if (!fChain) return -1;
     348             : 
     349           0 :   return fChain->GetEntries();
     350           0 : }
     351             : 
     352             : void AliRawReaderChain::SetSearchPath(const char* path)
     353             : {
     354             :   // set alien query search path
     355           0 :   AliInfoGeneral("SetSearchPath",Form("Setting search path to \"%s\" (was \"%s\")",path,fgSearchPath.Data()));
     356           0 :   fgSearchPath = path;
     357           0 : }

Generated by: LCOV version 1.11