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