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 "AliRawEvent.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;
240 fEvent = new AliRawEvent;
241 Long64_t treeEntry = fChain->LoadTree(fEventIndex+1);
244 if (fBranch->GetEntry(treeEntry) <= 0)
247 } while (!IsEventSelected());
252 Bool_t AliRawReaderChain::RewindEvents()
254 // go back to the beginning of the root file
258 fEvent = new AliRawEvent;
263 Bool_t AliRawReaderChain::GotoEvent(Int_t event)
265 // go to a particular event
266 // Uses the absolute event index inside the
267 // chain with raw data
269 if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
272 fEvent = new AliRawEvent;
273 Long64_t treeEntry = fChain->LoadTree(event);
276 if (fBranch->GetEntry(treeEntry) <= 0)
283 Int_t AliRawReaderChain::GetNumberOfEvents() const
285 // Get the total number of events in the chain
288 if (!fChain) return -1;
290 return fChain->GetEntries();