1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
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
23 /// cvetan.cheshkov@cern.ch 29/07/2008
25 ///////////////////////////////////////////////////////////////////////////////
28 #include <TFileCollection.h>
29 #include <TEntryList.h>
30 #include "TGridCollection.h"
31 #include <TPluginManager.h>
37 #include "AliRawReaderChain.h"
38 #include "AliRawVEvent.h"
40 ClassImp(AliRawReaderChain)
42 AliRawReaderChain::AliRawReaderChain() :
46 // default constructor
49 AliRawReaderChain::AliRawReaderChain(const char* fileName) :
53 // create raw-reader objects which takes as an input a root chain
54 // either from the file list found in 'fileName' (IsCollection = true)
55 // or from entry list found in 'filename' (IsCollection = false)
56 // The entry-list syntax follows root convetion: filename.root/listname
58 fChain = new TChain("RAW");
60 TString fileNameStr = fileName;
61 if (fileNameStr.EndsWith(".xml")) {
63 TGridCollection *collection = NULL;
64 TPluginManager* pluginManager = gROOT->GetPluginManager();
65 TPluginHandler* pluginHandler = pluginManager->FindHandler("TGridCollection", "alice");
67 pluginManager->AddHandler("TGridCollection", "alice",
68 "AliXMLCollection", "ANALYSISalice", "AliXMLCollection(const char*)");
69 pluginHandler = pluginManager->FindHandler("TGridCollection", "alice");
71 gSystem->Load("libANALYSIS");
72 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
73 collection = (TGridCollection*)pluginHandler->ExecPlugin(1,fileNameStr.Data());
80 Bool_t elistsExist = kFALSE;
81 TEntryList *elist = new TEntryList();
82 while (collection->Next()) {
83 fChain->Add(collection->GetTURL(""));
84 TEntryList *list = (TEntryList *)collection->GetEntryList("");
86 list->SetTreeName("RAW");
87 list->SetFileName(collection->GetTURL(""));
93 fChain->SetEntryList(elist,"ne");
96 Info("AliRawReaderChain", "no entry lists found in %s. Using all entries", fileNameStr.Data());
100 else if (fileNameStr.EndsWith(".root")) {
102 TDirectory* dir = gDirectory;
103 TFile *listFile = TFile::Open(fileNameStr.Data());
105 if (!listFile || !listFile->IsOpen()) {
106 Error("AliRawReaderChain", "could not open file %s", fileNameStr.Data());
111 TEntryList *elist = NULL;
113 TIter nextkey(listFile->GetListOfKeys());
114 while ((key=(TKey*)nextkey())){
115 if (strcmp("TEntryList", key->GetClassName())==0){
116 elist = (TEntryList*)key->ReadObj();
120 Error("AliRawReaderChain", "no TEntryList found in %s", fileNameStr.Data());
125 TEntryList *templist = NULL;
126 TList *elists = elist->GetLists();
128 while((templist = (TEntryList*)next())){
129 Info("AliRawReaderChain", "%s added to the chain", templist->GetFileName());
130 fChain->Add(templist->GetFileName());
132 fChain->SetEntryList(elist,"ne");
136 TFileCollection collection("RAW",
137 "Collection with raw-data files",
140 if (!fChain->AddFileInfoList((TCollection*)(collection.GetList()))) {
141 Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
147 fChain->SetBranchStatus("*",1);
148 fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
151 AliRawReaderChain::AliRawReaderChain(TFileCollection *collection) :
155 // create raw-reader objects which takes as an input a root chain
156 // from a root file collection
158 fChain = new TChain("RAW");
159 if (!fChain->AddFileInfoList((TCollection*)(collection->GetList()))) {
160 Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
165 fChain->SetBranchStatus("*",1);
166 fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
169 AliRawReaderChain::AliRawReaderChain(TChain *chain) :
173 // create raw-reader objects which takes as an input a root chain
174 // from a root file collection
176 if (!fChain) fIsValid = kFALSE;
178 fChain->SetBranchStatus("*",1);
179 fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
182 AliRawReaderChain::AliRawReaderChain(TEntryList *elist) :
186 // create raw-reader objects which takes as an input a root chain
187 // from a root file collection
189 if (!elist) fIsValid = kFALSE;
191 fChain = new TChain("RAW");
193 TEntryList *templist = NULL;
194 TList *elists = elist->GetLists();
196 while((templist = (TEntryList*)next())){
197 fChain->Add(templist->GetFileName());
199 fChain->SetEntryList(elist,"ne");
201 fChain->SetBranchStatus("*",1);
202 fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
205 AliRawReaderChain::AliRawReaderChain(const AliRawReaderChain& rawReader) :
206 AliRawReaderRoot(rawReader),
207 fChain(rawReader.fChain)
212 AliRawReaderChain& AliRawReaderChain::operator = (const AliRawReaderChain&
215 // assignment operator
217 this->~AliRawReaderChain();
218 new(this) AliRawReaderChain(rawReader);
222 AliRawReaderChain::~AliRawReaderChain()
224 // delete objects and close root file
232 Bool_t AliRawReaderChain::NextEvent()
234 // go to the next event in the root file
236 if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
242 Long64_t treeEntry = fChain->LoadTree(fEventIndex+1);
245 if (fBranch->GetEntry(treeEntry) <= 0)
247 fEventHeader = fEvent->GetHeader();
249 } while (!IsEventSelected());
254 Bool_t AliRawReaderChain::RewindEvents()
256 // go back to the beginning of the root file
266 Bool_t AliRawReaderChain::GotoEvent(Int_t event)
268 // go to a particular event
269 // Uses the absolute event index inside the
270 // chain with raw data
272 if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
277 Long64_t treeEntry = fChain->LoadTree(event);
280 if (fBranch->GetEntry(treeEntry) <= 0)
282 fEventHeader = fEvent->GetHeader();
288 Int_t AliRawReaderChain::GetNumberOfEvents() const
290 // Get the total number of events in the chain
293 if (!fChain) return -1;
295 return fChain->GetEntries();