]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReaderChain.cxx
New method to clone current raw-data event and create a single-event raw-reader....
[u/mrichter/AliRoot.git] / RAW / AliRawReaderChain.cxx
CommitLineData
6923e953 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>
3d456d99 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>
6923e953 36
37#include "AliRawReaderChain.h"
33314186 38#include "AliRawVEvent.h"
6923e953 39
40ClassImp(AliRawReaderChain)
41
42AliRawReaderChain::AliRawReaderChain() :
43 AliRawReaderRoot(),
44 fChain(NULL)
45{
46 // default constructor
47}
48
3d456d99 49AliRawReaderChain::AliRawReaderChain(const char* fileName) :
6923e953 50 AliRawReaderRoot(),
51 fChain(NULL)
52{
53// create raw-reader objects which takes as an input a root chain
3d456d99 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
6923e953 57
acce5036 58 fChain = new TChain("RAW");
3d456d99 59
60 TString fileNameStr = fileName;
61 if (fileNameStr.EndsWith(".xml")) {
62
63 TGridCollection *collection = NULL;
64 TPluginManager* pluginManager = gROOT->GetPluginManager();
65 TPluginHandler* pluginHandler = pluginManager->FindHandler("TGridCollection", "alice");
66 if (!pluginHandler) {
67 pluginManager->AddHandler("TGridCollection", "alice",
68 "AliXMLCollection", "ANALYSISalice", "AliXMLCollection(const char*)");
69 pluginHandler = pluginManager->FindHandler("TGridCollection", "alice");
70 }
71 gSystem->Load("libANALYSIS");
72 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
73 collection = (TGridCollection*)pluginHandler->ExecPlugin(1,fileNameStr.Data());
74 }
75 else {
76 fIsValid = kFALSE;
77 return;
78 }
79 collection->Reset();
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("");
85 if (list) {
86 list->SetTreeName("RAW");
87 list->SetFileName(collection->GetTURL(""));
88 elist->Add(list);
89 elistsExist = kTRUE;
90 }
91 }
92 if (elistsExist) {
93 fChain->SetEntryList(elist,"ne");
94 }
95 else {
96 Info("AliRawReaderChain", "no entry lists found in %s. Using all entries", fileNameStr.Data());
97 delete elist;
98 }
99 }
100 else if (fileNameStr.EndsWith(".root")) {
101
102 TDirectory* dir = gDirectory;
103 TFile *listFile = TFile::Open(fileNameStr.Data());
104 dir->cd();
105 if (!listFile || !listFile->IsOpen()) {
106 Error("AliRawReaderChain", "could not open file %s", fileNameStr.Data());
107 fIsValid = kFALSE;
108 return;
109 }
110
111 TEntryList *elist = NULL;
112 TKey *key = NULL;
113 TIter nextkey(listFile->GetListOfKeys());
114 while ((key=(TKey*)nextkey())){
115 if (strcmp("TEntryList", key->GetClassName())==0){
116 elist = (TEntryList*)key->ReadObj();
117 }
118 }
119 if (!elist) {
120 Error("AliRawReaderChain", "no TEntryList found in %s", fileNameStr.Data());
121 fIsValid = kFALSE;
122 return;
123 }
124
125 TEntryList *templist = NULL;
126 TList *elists = elist->GetLists();
127 TIter next(elists);
128 while((templist = (TEntryList*)next())){
129 Info("AliRawReaderChain", "%s added to the chain", templist->GetFileName());
130 fChain->Add(templist->GetFileName());
131 }
132 fChain->SetEntryList(elist,"ne");
133 }
134 else {
135
136 TFileCollection collection("RAW",
137 "Collection with raw-data files",
138 fileNameStr.Data());
139
140 if (!fChain->AddFileInfoList((TCollection*)(collection.GetList()))) {
141 Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
142 fIsValid = kFALSE;
143 return;
144 }
6923e953 145 }
146
636c1780 147 fChain->SetBranchStatus("*",1);
4ebdfbcc 148 fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
6923e953 149}
150
151AliRawReaderChain::AliRawReaderChain(TFileCollection *collection) :
152 AliRawReaderRoot(),
153 fChain(NULL)
154{
155// create raw-reader objects which takes as an input a root chain
156// from a root file collection
157
acce5036 158 fChain = new TChain("RAW");
6923e953 159 if (!fChain->AddFileInfoList((TCollection*)(collection->GetList()))) {
160 Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
a97af23d 161 fIsValid = kFALSE;
6923e953 162 return;
163 }
164
636c1780 165 fChain->SetBranchStatus("*",1);
4ebdfbcc 166 fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
636c1780 167}
168
169AliRawReaderChain::AliRawReaderChain(TChain *chain) :
170 AliRawReaderRoot(),
171 fChain(chain)
172{
173// create raw-reader objects which takes as an input a root chain
174// from a root file collection
175
a97af23d 176 if (!fChain) fIsValid = kFALSE;
177
636c1780 178 fChain->SetBranchStatus("*",1);
4ebdfbcc 179 fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
6923e953 180}
181
3d456d99 182AliRawReaderChain::AliRawReaderChain(TEntryList *elist) :
183 AliRawReaderRoot(),
184 fChain(NULL)
185{
186// create raw-reader objects which takes as an input a root chain
187// from a root file collection
188
189 if (!elist) fIsValid = kFALSE;
190
191 fChain = new TChain("RAW");
192
193 TEntryList *templist = NULL;
194 TList *elists = elist->GetLists();
195 TIter next(elists);
196 while((templist = (TEntryList*)next())){
197 fChain->Add(templist->GetFileName());
198 }
199 fChain->SetEntryList(elist,"ne");
200
201 fChain->SetBranchStatus("*",1);
202 fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
203}
204
6923e953 205AliRawReaderChain::AliRawReaderChain(const AliRawReaderChain& rawReader) :
206 AliRawReaderRoot(rawReader),
207 fChain(rawReader.fChain)
208{
209// copy constructor
210}
211
212AliRawReaderChain& AliRawReaderChain::operator = (const AliRawReaderChain&
213 rawReader)
214{
215// assignment operator
216
217 this->~AliRawReaderChain();
218 new(this) AliRawReaderChain(rawReader);
219 return *this;
220}
221
222AliRawReaderChain::~AliRawReaderChain()
223{
224// delete objects and close root file
225
226 if (fChain) {
227 delete fChain;
228 fChain = NULL;
229 }
230}
231
232Bool_t AliRawReaderChain::NextEvent()
233{
234// go to the next event in the root file
235
236 if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
237
238 do {
239 delete fEvent;
33314186 240 fEvent = NULL;
241 fEventHeader = NULL;
4ebdfbcc 242 Long64_t treeEntry = fChain->LoadTree(fEventIndex+1);
243 if (!fBranch)
636c1780 244 return kFALSE;
4ebdfbcc 245 if (fBranch->GetEntry(treeEntry) <= 0)
6923e953 246 return kFALSE;
33314186 247 fEventHeader = fEvent->GetHeader();
6923e953 248 fEventIndex++;
249 } while (!IsEventSelected());
250 fEventNumber++;
251 return Reset();
252}
253
254Bool_t AliRawReaderChain::RewindEvents()
255{
256// go back to the beginning of the root file
257
258 fEventIndex = -1;
259 delete fEvent;
33314186 260 fEvent = NULL;
261 fEventHeader = NULL;
6923e953 262 fEventNumber = -1;
263 return Reset();
264}
636c1780 265
266Bool_t AliRawReaderChain::GotoEvent(Int_t event)
267{
268 // go to a particular event
269 // Uses the absolute event index inside the
270 // chain with raw data
271
272 if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
273
274 delete fEvent;
33314186 275 fEvent = NULL;
276 fEventHeader = NULL;
4ebdfbcc 277 Long64_t treeEntry = fChain->LoadTree(event);
278 if (!fBranch)
636c1780 279 return kFALSE;
4ebdfbcc 280 if (fBranch->GetEntry(treeEntry) <= 0)
636c1780 281 return kFALSE;
33314186 282 fEventHeader = fEvent->GetHeader();
636c1780 283 fEventIndex = event;
284 fEventNumber++;
285 return Reset();
286}
25e82ff5 287
288Int_t AliRawReaderChain::GetNumberOfEvents() const
289{
290 // Get the total number of events in the chain
291 // of raw-data files
292
293 if (!fChain) return -1;
294
295 return fChain->GetEntries();
296}