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