]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReaderChain.cxx
New raw-reader from root chain.
[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(TString 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.Data());
52
53   TChain* fChain = new TChain("RAW");
54   if (!fChain->AddFileInfoList((TCollection*)(collection.GetList()))) {
55     Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
56     return;
57   }
58
59   fChain->SetBranchStatus("*",0);
60   fChain->SetBranchStatus("rawevent",1);
61
62   fEvent = new AliRawEvent;
63   fChain->SetBranchAddress("rawevent", &fEvent);
64 }
65
66 AliRawReaderChain::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
73   TChain* fChain = new TChain("RAW");
74   if (!fChain->AddFileInfoList((TCollection*)(collection->GetList()))) {
75     Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
76     return;
77   }
78
79   fChain->SetBranchStatus("*",0);
80   fChain->SetBranchStatus("rawevent",1);
81
82   fEvent = new AliRawEvent;
83   fChain->SetBranchAddress("rawevent", &fEvent);
84 }
85
86 AliRawReaderChain::AliRawReaderChain(const AliRawReaderChain& rawReader) :
87   AliRawReaderRoot(rawReader),
88   fChain(rawReader.fChain)
89 {
90 // copy constructor
91 }
92
93 AliRawReaderChain& AliRawReaderChain::operator = (const AliRawReaderChain& 
94                                                   rawReader)
95 {
96 // assignment operator
97
98   this->~AliRawReaderChain();
99   new(this) AliRawReaderChain(rawReader);
100   return *this;
101 }
102
103 AliRawReaderChain::~AliRawReaderChain()
104 {
105 // delete objects and close root file
106
107   if (fChain) {
108     delete fChain;
109     fChain = NULL;
110   }
111 }
112
113 Bool_t AliRawReaderChain::NextEvent()
114 {
115 // go to the next event in the root file
116
117   if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
118
119   do {
120     delete fEvent;
121     fEvent = new AliRawEvent;
122     if (fChain->GetEntry(fEventIndex+1) <= 0)
123       return kFALSE;
124     fEventIndex++;
125   } while (!IsEventSelected());
126   fEventNumber++;
127   return Reset();
128 }
129
130 Bool_t AliRawReaderChain::RewindEvents()
131 {
132 // go back to the beginning of the root file
133
134   fEventIndex = -1;
135   delete fEvent;
136   fEvent = new AliRawEvent;
137   fEventNumber = -1;
138   return Reset();
139 }