]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliESDInputHandler.cxx
Setting the class name meta-data field in the constructor
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandler.cxx
CommitLineData
d3dd3d14 1/**************************************************************************
2 * Copyright(c) 1998-2007, 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/* $Id$ */
17
18//-------------------------------------------------------------------------
19// Event handler for ESD input
20// Author: Andreas Morsch, CERN
21//-------------------------------------------------------------------------
22
933fd60f 23#include <TTree.h>
1aa09fd1 24#include <TChain.h>
25#include <TFile.h>
26#include <TArchiveFile.h>
27#include <TObjArray.h>
28#include <TSystem.h>
300d5701 29#include <TString.h>
30#include <TObjString.h>
80e1b60a 31#include <TProcessID.h>
f0f29480 32#include <TMap.h>
d3dd3d14 33
34#include "AliESDInputHandler.h"
35#include "AliESDEvent.h"
36#include "AliESD.h"
1aa09fd1 37#include "AliRunTag.h"
38#include "AliEventTag.h"
300d5701 39#include "AliLog.h"
d3dd3d14 40
41ClassImp(AliESDInputHandler)
42
c2b6979d 43static Option_t *gESDDataType = "ESD";
44
d3dd3d14 45//______________________________________________________________________________
6989bff3 46AliESDInputHandler::AliESDInputHandler() :
47 AliInputEventHandler(),
0cd61c1d 48 fEvent(0x0),
1aa09fd1 49 fAnalysisType(0),
4d2a7370 50 fNEvents(0),
6ccd727b 51 fHLTEvent(0x0),
52 fHLTTree(0x0),
53 fUseHLT(kFALSE),
f0f29480 54 fTagCutSumm(0x0),
1aa09fd1 55 fUseTags(kFALSE),
56 fChainT(0),
57 fTreeT(0),
58 fRunTag(0)
d3dd3d14 59{
60 // default constructor
61}
62
63//______________________________________________________________________________
64AliESDInputHandler::~AliESDInputHandler()
65{
1aa09fd1 66 // destructor
6989bff3 67 // delete fEvent;
d3dd3d14 68}
69
70//______________________________________________________________________________
71AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
f16ba708 72 AliInputEventHandler(name, title), fEvent(0x0), fAnalysisType(0),
f0f29480 73 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
d3dd3d14 74{
e12e402c 75 // Constructor
d3dd3d14 76}
77
1aa09fd1 78Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
d3dd3d14 79{
300d5701 80 // Initialisation necessary for each new tree
1aa09fd1 81 fAnalysisType = opt;
82 fTree = tree;
300d5701 83
6073f8c9 84 if (!fTree) return kFALSE;
6ccd727b 85 fTree->GetEntry(0);
86
d3dd3d14 87 // Get pointer to ESD event
300d5701 88 SwitchOffBranches();
3858dd64 89 SwitchOnBranches();
300d5701 90
efea3f54 91 if (!fEvent) fEvent = new AliESDEvent();
60996693 92 fEvent->ReadFromTree(fTree);
4d2a7370 93 fNEvents = fTree->GetEntries();
6ccd727b 94
50aaaf00 95
d3dd3d14 96 return kTRUE;
97}
98
6ccd727b 99Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
d3dd3d14 100{
101 // Copy from old to new format if necessary
d7749dec 102 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
103 if (old) {
d3dd3d14 104 ((AliESDEvent*)fEvent)->CopyFromOldESD();
105 old->Reset();
d7749dec 106 }
6ccd727b 107
108 if (fHLTTree) {
109 fHLTTree->GetEntry(entry);
110 }
111
d7749dec 112 return kTRUE;
d3dd3d14 113}
114
e12e402c 115Bool_t AliESDInputHandler::FinishEvent()
116{
117 // Finish the event
118 if(fEvent)fEvent->Reset();
119 return kTRUE;
6989bff3 120}
121
1aa09fd1 122Bool_t AliESDInputHandler::Notify(const char* path)
123{
124 // Notify a directory change
a5112f7d 125 AliInfo(Form("Directory change %s \n", path));
126 //
50aaaf00 127 if (fUseHLT) {
128 // Get HLTesdTree from current file
129 TTree* cTree = fTree;
130 if (fTree->GetTree()) cTree = fTree->GetTree();
131 TFile* cFile = cTree->GetCurrentFile();
132 cFile->GetObject("HLTesdTree", fHLTTree);
133
134 if (fHLTTree) {
135 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
136 fHLTEvent->ReadFromTree(fHLTTree);
137 }
138 }
139
1aa09fd1 140 if (!fUseTags) return (kTRUE);
141
142 Bool_t zip = kFALSE;
143
144 TString fileName(path);
145 if(fileName.Contains("#AliESDs.root")){
1aa09fd1 146 zip = kTRUE;
147 }
148 else if (fileName.Contains("AliESDs.root")){
149 fileName.ReplaceAll("AliESDs.root", "");
150 }
151 else if(fileName.Contains("#AliAOD.root")){
1aa09fd1 152 zip = kTRUE;
153 }
154 else if(fileName.Contains("AliAOD.root")){
155 fileName.ReplaceAll("AliAOD.root", "");
156 }
157 else if(fileName.Contains("#galice.root")){
158 // For running with galice and kinematics alone...
1aa09fd1 159 zip = kTRUE;
160 }
161 else if(fileName.Contains("galice.root")){
162 // For running with galice and kinematics alone...
163 fileName.ReplaceAll("galice.root", "");
164 }
165
1aa09fd1 166
be4763e2 167 TString pathName("./");
168 if (fileName.Length() != 0) {
169 pathName = fileName;
170 }
171
172 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
6ccd727b 173
1aa09fd1 174 if (fRunTag) {
175 fRunTag->Clear();
176 } else {
177 fRunTag = new AliRunTag();
178 }
179
180 delete fTreeT; fTreeT = 0;
6ccd727b 181
1aa09fd1 182 if (fChainT) {
183 delete fChainT;
184 fChainT = 0;
185 }
186
187 if (!fChainT) {
188 fChainT = new TChain("T");
189 }
190
191
192
193 const char* tagPattern = "ESD.tag.root";
194 const char* name = 0x0;
195 TString tagFilename;
196 if (zip) {
8ac5c1d7 197 TFile* file = fTree->GetCurrentFile();
1aa09fd1 198 TArchiveFile* arch = file->GetArchive();
199 TObjArray* arr = arch->GetMembers();
200 TIter next(arr);
201
7cec0871 202 while ((file = (TFile*) next())) {
1aa09fd1 203 name = file->GetName();
204 if (strstr(name,tagPattern)) {
be4763e2 205 tagFilename = pathName.Data();
1aa09fd1 206 tagFilename += "#";
207 tagFilename += name;
208 fChainT->Add(tagFilename);
209 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
210 }//pattern check
211 } // archive file loop
212 } else {
be4763e2 213 void * dirp = gSystem->OpenDirectory(pathName.Data());
1aa09fd1 214 while((name = gSystem->GetDirEntry(dirp))) {
215 if (strstr(name,tagPattern)) {
be4763e2 216 tagFilename = pathName.Data();
1aa09fd1 217 tagFilename += "/";
218 tagFilename += name;
219 fChainT->Add(tagFilename);
220 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
221 }//pattern check
222 }//directory loop
223 }
224 fChainT->SetBranchAddress("AliTAG",&fRunTag);
225 fChainT->GetEntry(0);
226 return kTRUE;
227}
228
229
c2b6979d 230
231Option_t *AliESDInputHandler::GetDataType() const
232{
233// Returns handled data type.
234 return gESDDataType;
235}
f0f29480 236
237Int_t AliESDInputHandler::GetNEventAcceptedInFile()
238{
239 // Get number of events in file accepted by the tag cuts
240 // return -1 if no info is available
241 if (!fTagCutSumm) {
242 TList *luo = fTree->GetUserInfo();
243 if (!luo) {
244 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
245 return -1;
246 }
247 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
248 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
249 if (fTagCutSumm) break;
250 }
251 if (!fTagCutSumm) {
252 AliInfo(Form("No tag summary map in input tree\n"));
253 return -1;
254 }
255 }
256
257 TObjString *ostr = 0;
258 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
259 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
260 else {
261 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
262 return -1;
263 }
264 char *iTagInfo;
265 iTagInfo = strdup(ostr->GetString().Data());
266
267 Int_t iAcc = atoi(strtok(iTagInfo, ","));
268
269 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
270
271 free(iTagInfo);
272
273 return iAcc;
274}
275Int_t AliESDInputHandler::GetNEventRejectedInFile()
276{
277 // Get number of events in file rejected by the tag cuts
278 // return -1 if no info is available
279 if (!fTagCutSumm) {
280 TList *luo = fTree->GetUserInfo();
281 if (!luo) {
282 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
283 return -1;
284 }
285 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
286 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
287 if (fTagCutSumm) break;
288 }
289 if (!fTagCutSumm) {
290 AliInfo(Form("No tag summary map in input tree\n"));
291 return -1;
292 }
293 }
294
295 TObjString *ostr = 0;
296 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
297 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
298 else {
299 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
300 return -1;
301 }
302 char *iTagInfo;
303 iTagInfo = strdup(ostr->GetString().Data());
304
305 strtok(iTagInfo, ",");
306 Int_t iRej = atoi(strtok(NULL, ","));
307
308 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
309
310 free(iTagInfo);
311
312 return iRej;
313}
c334d0d3 314Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
315{
316 // Get number of events in the full chain
317 // Count accepted and rejected events
318 // return kFALSE if no info is available
319 if (!fTagCutSumm) {
320 TList *luo = fTree->GetUserInfo();
321 if (!luo) {
322 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
323 return kFALSE;
324 }
325 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
326 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
327 if (fTagCutSumm) break;
328 }
329 if (!fTagCutSumm) {
330 AliInfo(Form("No tag summary map in input tree\n"));
331 return kFALSE;
332 }
333 }
334
335 TMapIter *tIter = new TMapIter(fTagCutSumm);
336
337 Int_t iTotList=0, iAccList=0, iRejList=0;
338
339 TObject *cobj;
9a587f77 340 while ((cobj = tIter->Next())) {
c334d0d3 341 TObjString *kstr = (TObjString *) cobj;
342 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
343 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
344 char *iTagInfo;
345 iTagInfo = strdup(vstr->GetString().Data());
346
347 Int_t iAcc = atoi(strtok(iTagInfo, ","));
348 Int_t iRej = atoi(strtok(NULL, ","));
349
350 iAccList += iAcc;
351 iRejList += iRej;
352 iTotList += (iAcc+iRej);
353 }
354
355 *aTotal = iTotList;
356 *aAccepted = iAccList;
357 *aRejected = iRejList;
358
359 return kTRUE;
360}
361
362Int_t AliESDInputHandler::GetNFilesEmpty()
363{
364 // Count number of files in which all events were de-selected
365 // For such files Notify() will NOT be called
366 // return -1 if no info is available
367 if (!fTagCutSumm) {
368 TList *luo = fTree->GetUserInfo();
369 if (!luo) {
370 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
371 return -1;
372 }
373 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
374 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
375 if (fTagCutSumm) break;
376 }
377 if (!fTagCutSumm) {
378 AliInfo(Form("No tag summary map in input tree\n"));
379 return -1;
380 }
381 }
382
383 TMapIter *tIter = new TMapIter(fTagCutSumm);
384
385 Int_t iFilesEmpty = 0;
386
387 TObject *cobj;
9a587f77 388 while ((cobj = tIter->Next())) {
c334d0d3 389 TObjString *kstr = (TObjString *) cobj;
390 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
391 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
392 char *iTagInfo;
393 iTagInfo = strdup(vstr->GetString().Data());
394
395 Int_t iAcc = atoi(strtok(iTagInfo, ","));
396 Int_t iRej = atoi(strtok(NULL, ","));
397
398 if ((iAcc == 0) && ((iRej+iAcc)>0))
399 iFilesEmpty++;
400 }
401
402 return iFilesEmpty;
403
404}