]>
Commit | Line | Data |
---|---|---|
dd2b6810 | 1 | #include "AliReaderAOD.h" |
2 | ||
3 | ClassImp(AliReaderAOD) | |
4 | ||
5 | #include <TError.h> | |
6 | #include <TFile.h> | |
7 | #include <TTree.h> | |
8 | #include "AliAOD.h" | |
9 | ||
efdb0cc9 | 10 | |
11 | const TString AliReaderAOD::fgkTreeName("TAOD"); | |
12 | const TString AliReaderAOD::fgkRecosntructedDataBranchName("reconstructed."); | |
13 | const TString AliReaderAOD::fgkSimulatedDataBranchName("simulated."); | |
14 | ||
15 | AliReaderAOD::AliReaderAOD(const Char_t* aodfilename): | |
16 | fFileName(aodfilename), | |
17 | fReadSim(kFALSE), | |
18 | fTree(0x0), | |
19 | fFile(0x0), | |
20 | fSimBuffer(0x0), | |
21 | fRecBuffer(0x0) | |
22 | { | |
23 | //ctor | |
24 | } | |
25 | /********************************************************************/ | |
26 | ||
27 | AliReaderAOD::~AliReaderAOD() | |
28 | { | |
29 | //dtor | |
30 | if (fEventSim == fSimBuffer ) | |
31 | { | |
32 | fEventSim = 0x0; | |
33 | fEventRec = 0x0; | |
34 | } | |
35 | delete fSimBuffer; | |
36 | delete fRecBuffer; | |
37 | ||
38 | delete fTree; | |
39 | delete fFile; | |
40 | } | |
41 | /********************************************************************/ | |
42 | ||
43 | void AliReaderAOD::Rewind() | |
44 | { | |
45 | //Rewinds reading | |
46 | delete fTree; | |
47 | fTree = 0x0; | |
48 | delete fFile; | |
49 | fFile = 0x0; | |
50 | fCurrentDir = 0; | |
51 | fNEventsRead= 0; | |
52 | } | |
53 | /********************************************************************/ | |
54 | Int_t AliReaderAOD::ReadNext() | |
55 | { | |
56 | //Reads next event | |
57 | ||
d9122a01 | 58 | Info("ReadNext","Entered"); |
efdb0cc9 | 59 | do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./" |
60 | { | |
61 | if (fFile == 0x0) | |
62 | { | |
63 | Int_t opened = OpenFile(fCurrentDir);//rl is opened here | |
64 | if (opened) | |
65 | { | |
66 | //Error("ReadNext","Error Occured while opening directory number %d",fCurrentDir); | |
67 | fCurrentDir++; | |
68 | continue; | |
69 | } | |
70 | fCurrentEvent = 0; | |
71 | } | |
d9122a01 | 72 | Info("ReadNext","Getting event %d",fCurrentEvent); |
efdb0cc9 | 73 | fTree->GetEvent(fCurrentEvent); |
d9122a01 | 74 | Info("ReadNext","Getting event %d Done",fCurrentEvent); |
efdb0cc9 | 75 | |
76 | //Temporary testing sollution | |
77 | fEventSim = fSimBuffer; | |
78 | fEventRec = fRecBuffer; | |
79 | ||
80 | fCurrentEvent++; | |
81 | fNEventsRead++; | |
82 | ||
83 | if (fTree) | |
84 | { | |
85 | if ( fCurrentEvent >= fTree->GetEntries() ) | |
86 | { | |
87 | delete fTree; | |
88 | fTree = 0x0; | |
89 | delete fFile; | |
90 | fFile = 0x0; | |
d9122a01 | 91 | fSimBuffer = 0x0; |
92 | fRecBuffer = 0x0; | |
efdb0cc9 | 93 | fCurrentDir++; |
94 | } | |
95 | } | |
96 | ||
97 | ||
98 | return 0;//success -> read one event | |
99 | ||
100 | }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array | |
101 | ||
102 | return 1; //no more directories to read | |
103 | ||
104 | ||
105 | } | |
106 | /********************************************************************/ | |
107 | ||
108 | Int_t AliReaderAOD::OpenFile(Int_t n) | |
109 | { | |
110 | //opens fFile with tree | |
111 | ||
d9122a01 | 112 | // Info("ReadNext","Opening File %d",n); |
113 | const TString dirname = GetDirName(n); | |
efdb0cc9 | 114 | if (dirname == "") |
115 | { | |
116 | if (AliVAODParticle::GetDebug() > 2 ) | |
117 | { | |
118 | Info("OpenFile","Got empty string as a directory name."); | |
119 | } | |
120 | return 1; | |
121 | } | |
122 | ||
123 | TString filename = dirname +"/"+ fFileName; | |
124 | fFile = TFile::Open(filename.Data()); | |
125 | if ( fFile == 0x0) | |
126 | { | |
127 | Error("OpenFile","Can't open fFile %s",filename.Data()); | |
128 | return 2; | |
129 | } | |
130 | if (!fFile->IsOpen()) | |
131 | { | |
132 | Error("OpenFile","Can't open fFile %s",filename.Data()); | |
133 | delete fFile; | |
134 | fFile = 0x0; | |
135 | return 3; | |
136 | } | |
d9122a01 | 137 | |
138 | Info("ReadNext","File Is Opened, Getting the TREE"); | |
efdb0cc9 | 139 | |
140 | fTree = dynamic_cast<TTree*>(fFile->Get(fgkTreeName)); | |
141 | if (fTree == 0x0) | |
142 | { | |
143 | if (AliVAODParticle::GetDebug() > 2 ) | |
144 | { | |
145 | Info("ReadNext","Can not find TTree object named %s",fgkTreeName.Data()); | |
146 | } | |
147 | fCurrentDir++; | |
148 | delete fFile;//we have to assume there is no more ESD objects in the fFile | |
149 | fFile = 0x0; | |
150 | return 4; | |
151 | } | |
152 | ||
d9122a01 | 153 | // Info("ReadNext","Got TREE, Setting branch addresses"); |
154 | ||
efdb0cc9 | 155 | fTree->SetBranchAddress(fgkSimulatedDataBranchName,&fSimBuffer); |
156 | fTree->SetBranchAddress(fgkRecosntructedDataBranchName,&fRecBuffer); | |
157 | ||
d9122a01 | 158 | // Info("ReadNext","Got TREE, Addresses are set."); |
159 | // Info("ReadNext","Quitting the method."); | |
160 | ||
efdb0cc9 | 161 | return 0; |
162 | ||
163 | } | |
164 | ||
165 | /********************************************************************/ | |
166 | ||
beb1c41d | 167 | Int_t AliReaderAOD::WriteAOD(AliReader* reader, const char* outfilename, const char* pclassname, Bool_t /*multcheck*/) |
dd2b6810 | 168 | { |
169 | //reads tracks from runs and writes them to file | |
170 | ::Info("AliReaderAOD::Write","________________________________________________________"); | |
171 | ::Info("AliReaderAOD::Write","________________________________________________________"); | |
172 | ::Info("AliReaderAOD::Write","________________________________________________________"); | |
173 | ||
174 | if (reader == 0x0) | |
175 | { | |
176 | ::Error("AliReaderAOD::Write","Input Reader is NULL"); | |
177 | return -1; | |
178 | } | |
179 | TFile *outfile = TFile::Open(outfilename,"recreate"); | |
180 | if (outfile == 0x0) | |
181 | { | |
182 | ::Error("AliReaderAOD::Write","Can not open output file %s",outfilename); | |
183 | return -1; | |
184 | } | |
185 | ||
efdb0cc9 | 186 | TTree *tree = new TTree(fgkTreeName,"Tree with tracks"); |
dd2b6810 | 187 | |
188 | TBranch *recbranch = 0x0, *simbranch = 0x0; | |
dd2b6810 | 189 | |
beb1c41d | 190 | AliAOD* eventrec = new AliAOD();//must be created before Branch is called. Otherwise clones array is not splitted |
191 | AliAOD* eventsim = new AliAOD();//AOD together with fParticles clones array knowing exact type of particles | |
192 | ||
193 | eventrec->SetParticleClassName(pclassname); | |
194 | eventsim->SetParticleClassName(pclassname); | |
efdb0cc9 | 195 | |
196 | AliAOD* recbuffer = eventrec; | |
197 | AliAOD* simbuffer = eventsim; | |
beb1c41d | 198 | |
efdb0cc9 | 199 | if (reader->ReadsRec()) recbranch = tree->Branch(fgkRecosntructedDataBranchName,"AliAOD",&recbuffer,32000,99); |
200 | if (reader->ReadsSim()) simbranch = tree->Branch(fgkSimulatedDataBranchName,"AliAOD",&simbuffer,32000,99); | |
dd2b6810 | 201 | |
202 | reader->Rewind(); | |
203 | while (reader->Next() == kFALSE) | |
204 | { | |
205 | ||
dd2b6810 | 206 | if (reader->ReadsRec()) |
efdb0cc9 | 207 | {//here we can get AOD that has different particle type |
208 | AliAOD* event = reader->GetEventRec(); | |
209 | if ( eventrec->GetParticleClass() != event->GetParticleClass() ) | |
210 | {//if class type is not what what we whant we copy particles | |
211 | eventrec->CopyData(event); | |
212 | recbuffer = eventrec; | |
213 | } | |
214 | else | |
215 | {//else just pointer to event from input reader is passed | |
216 | recbuffer = event; | |
217 | } | |
beb1c41d | 218 | } |
219 | ||
220 | if (reader->ReadsSim()) | |
221 | { | |
d9122a01 | 222 | AliAOD* event = reader->GetEventSim(); |
efdb0cc9 | 223 | if ( eventsim->GetParticleClass() != event->GetParticleClass() ) |
224 | {//if class type is not what what we whant we copy particles | |
225 | eventsim->CopyData(event); | |
226 | simbuffer = eventrec; | |
227 | } | |
228 | else | |
229 | {//else just pointer to event from input reader is passed | |
230 | simbuffer = event; | |
231 | } | |
dd2b6810 | 232 | } |
d9122a01 | 233 | recbuffer->GetParticle(0)->Print(); |
234 | simbuffer->GetParticle(0)->Print(); | |
dd2b6810 | 235 | tree->Fill(); |
dd2b6810 | 236 | } |
237 | ||
238 | ::Info("AliReaderAOD::Write","Written %d events",tree->GetEntries()); | |
239 | outfile->cd(); | |
240 | tree->Write(); | |
efdb0cc9 | 241 | |
242 | delete eventsim; | |
243 | delete eventrec; | |
244 | ||
dd2b6810 | 245 | delete tree; |
246 | delete outfile; | |
247 | return 0; | |
248 | } | |
249 |