1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Event handler for ESD input
20 // Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
26 #include <TArchiveFile.h>
27 #include <TObjArray.h>
30 #include <TObjString.h>
31 #include <TProcessID.h>
33 #include "AliESDInputHandler.h"
34 #include "AliESDEvent.h"
36 #include "AliRunTag.h"
37 #include "AliEventTag.h"
40 ClassImp(AliESDInputHandler)
42 static Option_t *gESDDataType = "ESD";
44 //______________________________________________________________________________
45 AliESDInputHandler::AliESDInputHandler() :
46 AliInputEventHandler(),
58 // default constructor
61 //______________________________________________________________________________
62 AliESDInputHandler::~AliESDInputHandler()
68 //______________________________________________________________________________
69 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
70 AliInputEventHandler(name, title), fEvent(0x0), fAnalysisType(0),
71 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
76 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
78 // Initialisation necessary for each new tree
82 if (!fTree) return kFALSE;
85 // Get pointer to ESD event
89 if (!fEvent) fEvent = new AliESDEvent();
90 fEvent->ReadFromTree(fTree);
91 fNEvents = fTree->GetEntries();
97 Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
99 // Copy from old to new format if necessary
100 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
102 ((AliESDEvent*)fEvent)->CopyFromOldESD();
107 fHLTTree->GetEntry(entry);
113 Bool_t AliESDInputHandler::FinishEvent()
116 if(fEvent)fEvent->Reset();
120 Bool_t AliESDInputHandler::Notify(const char* path)
122 // Notify a directory change
123 AliInfo(Form("Directory change %s \n", path));
126 // Get HLTesdTree from current file
127 TTree* cTree = fTree;
128 if (fTree->GetTree()) cTree = fTree->GetTree();
129 TFile* cFile = cTree->GetCurrentFile();
130 cFile->GetObject("HLTesdTree", fHLTTree);
133 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
134 fHLTEvent->ReadFromTree(fHLTTree);
138 if (!fUseTags) return (kTRUE);
142 TString fileName(path);
143 if(fileName.Contains("#AliESDs.root")){
146 else if (fileName.Contains("AliESDs.root")){
147 fileName.ReplaceAll("AliESDs.root", "");
149 else if(fileName.Contains("#AliAOD.root")){
152 else if(fileName.Contains("AliAOD.root")){
153 fileName.ReplaceAll("AliAOD.root", "");
155 else if(fileName.Contains("#galice.root")){
156 // For running with galice and kinematics alone...
159 else if(fileName.Contains("galice.root")){
160 // For running with galice and kinematics alone...
161 fileName.ReplaceAll("galice.root", "");
165 TString pathName("./");
166 if (fileName.Length() != 0) {
170 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
175 fRunTag = new AliRunTag();
178 delete fTreeT; fTreeT = 0;
186 fChainT = new TChain("T");
191 const char* tagPattern = "ESD.tag.root";
192 const char* name = 0x0;
195 TFile* file = fTree->GetCurrentFile();
196 TArchiveFile* arch = file->GetArchive();
197 TObjArray* arr = arch->GetMembers();
200 while ((file = (TFile*) next())) {
201 name = file->GetName();
202 if (strstr(name,tagPattern)) {
203 tagFilename = pathName.Data();
206 fChainT->Add(tagFilename);
207 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
209 } // archive file loop
211 void * dirp = gSystem->OpenDirectory(pathName.Data());
212 while((name = gSystem->GetDirEntry(dirp))) {
213 if (strstr(name,tagPattern)) {
214 tagFilename = pathName.Data();
217 fChainT->Add(tagFilename);
218 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
222 fChainT->SetBranchAddress("AliTAG",&fRunTag);
223 fChainT->GetEntry(0);
229 Option_t *AliESDInputHandler::GetDataType() const
231 // Returns handled data type.