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 //______________________________________________________________________________
43 AliESDInputHandler::AliESDInputHandler() :
44 AliInputEventHandler(),
54 // default constructor
57 //______________________________________________________________________________
58 AliESDInputHandler::~AliESDInputHandler()
64 //______________________________________________________________________________
65 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
66 AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn(""), fAnalysisType(0),
67 fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
72 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
74 // Initialisation necessary for each new tree
78 if (!fTree) return kFALSE;
79 // Get pointer to ESD event
87 fEvent = new AliESDEvent();
89 fEvent->ReadFromTree(fTree);
93 Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
95 // Copy from old to new format if necessary
96 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
98 ((AliESDEvent*)fEvent)->CopyFromOldESD();
104 Bool_t AliESDInputHandler::FinishEvent()
107 if(fEvent)fEvent->Reset();
111 Bool_t AliESDInputHandler::Notify(const char* path)
113 // Notify a directory change
114 AliInfo(Form("Directory change %s \n", path));
116 if (!fUseTags) return (kTRUE);
120 TString fileName(path);
121 if(fileName.Contains("#AliESDs.root")){
122 fileName.ReplaceAll("#AliESDs.root", "");
125 else if (fileName.Contains("AliESDs.root")){
126 fileName.ReplaceAll("AliESDs.root", "");
128 else if(fileName.Contains("#AliAOD.root")){
129 fileName.ReplaceAll("#AliAOD.root", "");
132 else if(fileName.Contains("AliAOD.root")){
133 fileName.ReplaceAll("AliAOD.root", "");
135 else if(fileName.Contains("#galice.root")){
136 // For running with galice and kinematics alone...
137 fileName.ReplaceAll("#galice.root", "");
140 else if(fileName.Contains("galice.root")){
141 // For running with galice and kinematics alone...
142 fileName.ReplaceAll("galice.root", "");
146 TString* pathName = new TString("./");
147 if (fileName.Length() != 0) {
148 *pathName = fileName;
151 printf("AliESDInputHandler::Notify() Path: %s\n", pathName->Data());
156 fRunTag = new AliRunTag();
159 delete fTreeT; fTreeT = 0;
167 fChainT = new TChain("T");
172 const char* tagPattern = "ESD.tag.root";
173 const char* name = 0x0;
176 TFile* file = TFile::Open(fileName.Data());
177 TArchiveFile* arch = file->GetArchive();
178 TObjArray* arr = arch->GetMembers();
181 while ((file = (TFile*) next())) {
182 name = file->GetName();
183 if (strstr(name,tagPattern)) {
184 tagFilename = pathName->Data();
187 fChainT->Add(tagFilename);
188 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
190 } // archive file loop
192 void * dirp = gSystem->OpenDirectory(pathName->Data());
193 while((name = gSystem->GetDirEntry(dirp))) {
194 if (strstr(name,tagPattern)) {
195 tagFilename = pathName->Data();
198 fChainT->Add(tagFilename);
199 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
203 fChainT->SetBranchAddress("AliTAG",&fRunTag);
204 fChainT->GetEntry(0);
209 void AliESDInputHandler::SwitchOffBranches() const {
211 // Switch of branches on user request
212 TObjArray * tokens = fBranches.Tokenize(" ");
213 Int_t ntok = tokens->GetEntries();
214 for (Int_t i = 0; i < ntok; i++) {
215 TString str = ((TObjString*) tokens->At(i))->GetString();
216 if (str.Length() == 0)
218 fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
219 AliInfo(Form("Branch %s switched off \n", str.Data()));
223 void AliESDInputHandler::SwitchOnBranches() const {
225 // Switch of branches on user request
226 TObjArray * tokens = fBranchesOn.Tokenize(" ");
227 Int_t ntok = tokens->GetEntries();
229 for (Int_t i = 0; i < ntok; i++) {
230 TString str = ((TObjString*) tokens->At(i))->GetString();
231 if (str.Length() == 0)
233 fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 1);
234 AliInfo(Form("Branch %s switched on \n", str.Data()));