Make use of new method AliRawReader::GetNumberOfEvents() - goinf to the last event...
[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>
29
30#include "AliRawReaderChain.h"
31#include "AliRawEvent.h"
32
33ClassImp(AliRawReaderChain)
34
35AliRawReaderChain::AliRawReaderChain() :
36 AliRawReaderRoot(),
37 fChain(NULL)
38{
39 // default constructor
40}
41
acce5036 42AliRawReaderChain::AliRawReaderChain(const char* listFileName) :
6923e953 43 AliRawReaderRoot(),
44 fChain(NULL)
45{
46// create raw-reader objects which takes as an input a root chain
47// from the file list found in 'listFileName'
48
49 TFileCollection collection("RAW",
50 "Collection with raw-data files",
acce5036 51 listFileName);
6923e953 52
acce5036 53 fChain = new TChain("RAW");
6923e953 54 if (!fChain->AddFileInfoList((TCollection*)(collection.GetList()))) {
55 Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
a97af23d 56 fIsValid = kFALSE;
6923e953 57 return;
58 }
59
636c1780 60 fChain->SetBranchStatus("*",1);
6923e953 61
62 fEvent = new AliRawEvent;
63 fChain->SetBranchAddress("rawevent", &fEvent);
64}
65
66AliRawReaderChain::AliRawReaderChain(TFileCollection *collection) :
67 AliRawReaderRoot(),
68 fChain(NULL)
69{
70// create raw-reader objects which takes as an input a root chain
71// from a root file collection
72
acce5036 73 fChain = new TChain("RAW");
6923e953 74 if (!fChain->AddFileInfoList((TCollection*)(collection->GetList()))) {
75 Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
a97af23d 76 fIsValid = kFALSE;
6923e953 77 return;
78 }
79
636c1780 80 fChain->SetBranchStatus("*",1);
81
82 fEvent = new AliRawEvent;
83 fChain->SetBranchAddress("rawevent", &fEvent);
84}
85
86AliRawReaderChain::AliRawReaderChain(TChain *chain) :
87 AliRawReaderRoot(),
88 fChain(chain)
89{
90// create raw-reader objects which takes as an input a root chain
91// from a root file collection
92
a97af23d 93 if (!fChain) fIsValid = kFALSE;
94
636c1780 95 fChain->SetBranchStatus("*",1);
6923e953 96
97 fEvent = new AliRawEvent;
98 fChain->SetBranchAddress("rawevent", &fEvent);
99}
100
101AliRawReaderChain::AliRawReaderChain(const AliRawReaderChain& rawReader) :
102 AliRawReaderRoot(rawReader),
103 fChain(rawReader.fChain)
104{
105// copy constructor
106}
107
108AliRawReaderChain& AliRawReaderChain::operator = (const AliRawReaderChain&
109 rawReader)
110{
111// assignment operator
112
113 this->~AliRawReaderChain();
114 new(this) AliRawReaderChain(rawReader);
115 return *this;
116}
117
118AliRawReaderChain::~AliRawReaderChain()
119{
120// delete objects and close root file
121
122 if (fChain) {
123 delete fChain;
124 fChain = NULL;
125 }
126}
127
128Bool_t AliRawReaderChain::NextEvent()
129{
130// go to the next event in the root file
131
132 if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
133
134 do {
135 delete fEvent;
136 fEvent = new AliRawEvent;
636c1780 137 TBranch *branch = fChain->GetBranch("rawevent");
138 if (!branch)
139 return kFALSE;
140 if (branch->GetEntry(fEventIndex+1) <= 0)
6923e953 141 return kFALSE;
142 fEventIndex++;
143 } while (!IsEventSelected());
144 fEventNumber++;
145 return Reset();
146}
147
148Bool_t AliRawReaderChain::RewindEvents()
149{
150// go back to the beginning of the root file
151
152 fEventIndex = -1;
153 delete fEvent;
154 fEvent = new AliRawEvent;
155 fEventNumber = -1;
156 return Reset();
157}
636c1780 158
159Bool_t AliRawReaderChain::GotoEvent(Int_t event)
160{
161 // go to a particular event
162 // Uses the absolute event index inside the
163 // chain with raw data
164
165 if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
166
167 delete fEvent;
168 fEvent = new AliRawEvent;
169 TBranch *branch = fChain->GetBranch("rawevent");
170 if (!branch)
171 return kFALSE;
172 if (branch->GetEntry(event) <= 0)
173 return kFALSE;
174 fEventIndex = event;
175 fEventNumber++;
176 return Reset();
177}
25e82ff5 178
179Int_t AliRawReaderChain::GetNumberOfEvents() const
180{
181 // Get the total number of events in the chain
182 // of raw-data files
183
184 if (!fChain) return -1;
185
186 return fChain->GetEntries();
187}