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(),
57 // default constructor
60 //______________________________________________________________________________
61 AliESDInputHandler::~AliESDInputHandler()
67 //______________________________________________________________________________
68 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
69 AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn(""), fAnalysisType(0),
70 fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
75 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
77 // Initialisation necessary for each new tree
81 if (!fTree) return kFALSE;
82 // Get pointer to ESD event
90 fEvent = new AliESDEvent();
92 fEvent->ReadFromTree(fTree);
93 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();
108 Bool_t AliESDInputHandler::FinishEvent()
111 if(fEvent)fEvent->Reset();
115 Bool_t AliESDInputHandler::Notify(const char* path)
117 // Notify a directory change
118 AliInfo(Form("Directory change %s \n", path));
120 if (!fUseTags) return (kTRUE);
124 TString fileName(path);
125 if(fileName.Contains("#AliESDs.root")){
126 fileName.ReplaceAll("#AliESDs.root", "");
129 else if (fileName.Contains("AliESDs.root")){
130 fileName.ReplaceAll("AliESDs.root", "");
132 else if(fileName.Contains("#AliAOD.root")){
133 fileName.ReplaceAll("#AliAOD.root", "");
136 else if(fileName.Contains("AliAOD.root")){
137 fileName.ReplaceAll("AliAOD.root", "");
139 else if(fileName.Contains("#galice.root")){
140 // For running with galice and kinematics alone...
141 fileName.ReplaceAll("#galice.root", "");
144 else if(fileName.Contains("galice.root")){
145 // For running with galice and kinematics alone...
146 fileName.ReplaceAll("galice.root", "");
150 TString pathName("./");
151 if (fileName.Length() != 0) {
155 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
160 fRunTag = new AliRunTag();
163 delete fTreeT; fTreeT = 0;
171 fChainT = new TChain("T");
176 const char* tagPattern = "ESD.tag.root";
177 const char* name = 0x0;
180 TFile* file = TFile::Open(fileName.Data());
181 TArchiveFile* arch = file->GetArchive();
182 TObjArray* arr = arch->GetMembers();
185 while ((file = (TFile*) next())) {
186 name = file->GetName();
187 if (strstr(name,tagPattern)) {
188 tagFilename = pathName.Data();
191 fChainT->Add(tagFilename);
192 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
194 } // archive file loop
196 void * dirp = gSystem->OpenDirectory(pathName.Data());
197 while((name = gSystem->GetDirEntry(dirp))) {
198 if (strstr(name,tagPattern)) {
199 tagFilename = pathName.Data();
202 fChainT->Add(tagFilename);
203 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
207 fChainT->SetBranchAddress("AliTAG",&fRunTag);
208 fChainT->GetEntry(0);
213 void AliESDInputHandler::SwitchOffBranches() const {
215 // Switch of branches on user request
216 TObjArray * tokens = fBranches.Tokenize(" ");
217 Int_t ntok = tokens->GetEntries();
218 for (Int_t i = 0; i < ntok; i++) {
219 TString str = ((TObjString*) tokens->At(i))->GetString();
220 if (str.Length() == 0)
222 fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
223 AliInfo(Form("Branch %s switched off \n", str.Data()));
227 void AliESDInputHandler::SwitchOnBranches() const {
229 // Switch of branches on user request
230 TObjArray * tokens = fBranchesOn.Tokenize(" ");
231 Int_t ntok = tokens->GetEntries();
233 for (Int_t i = 0; i < ntok; i++) {
234 TString str = ((TObjString*) tokens->At(i))->GetString();
235 if (str.Length() == 0)
237 fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 1);
238 AliInfo(Form("Branch %s switched on \n", str.Data()));
242 Option_t *AliESDInputHandler::GetDataType() const
244 // Returns handled data type.