In Notify, correct handling of the local case where the path is empty. (R. Arnaldi...
[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>
d3dd3d14 32
33#include "AliESDInputHandler.h"
34#include "AliESDEvent.h"
35#include "AliESD.h"
1aa09fd1 36#include "AliRunTag.h"
37#include "AliEventTag.h"
300d5701 38#include "AliLog.h"
d3dd3d14 39
40ClassImp(AliESDInputHandler)
41
42//______________________________________________________________________________
6989bff3 43AliESDInputHandler::AliESDInputHandler() :
44 AliInputEventHandler(),
0cd61c1d 45 fEvent(0x0),
865d620a 46 fBranches(""),
1aa09fd1 47 fBranchesOn(""),
48 fAnalysisType(0),
49 fUseTags(kFALSE),
50 fChainT(0),
51 fTreeT(0),
52 fRunTag(0)
d3dd3d14 53{
54 // default constructor
55}
56
57//______________________________________________________________________________
58AliESDInputHandler::~AliESDInputHandler()
59{
1aa09fd1 60 // destructor
6989bff3 61 // delete fEvent;
d3dd3d14 62}
63
64//______________________________________________________________________________
65AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
1aa09fd1 66 AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn(""), fAnalysisType(0),
67 fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
d3dd3d14 68{
e12e402c 69 // Constructor
d3dd3d14 70}
71
1aa09fd1 72Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
d3dd3d14 73{
300d5701 74 // Initialisation necessary for each new tree
1aa09fd1 75 fAnalysisType = opt;
76 fTree = tree;
300d5701 77
6073f8c9 78 if (!fTree) return kFALSE;
d3dd3d14 79 // Get pointer to ESD event
300d5701 80 SwitchOffBranches();
3858dd64 81 SwitchOnBranches();
300d5701 82
60996693 83 if (fEvent) {
84 delete fEvent;
85 fEvent = 0;
6989bff3 86 }
60996693 87 fEvent = new AliESDEvent();
88
89 fEvent->ReadFromTree(fTree);
d3dd3d14 90 return kTRUE;
91}
92
ed97dc98 93Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
d3dd3d14 94{
95 // Copy from old to new format if necessary
d7749dec 96 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
97 if (old) {
d3dd3d14 98 ((AliESDEvent*)fEvent)->CopyFromOldESD();
99 old->Reset();
d7749dec 100 }
101 return kTRUE;
d3dd3d14 102}
103
e12e402c 104Bool_t AliESDInputHandler::FinishEvent()
105{
106 // Finish the event
107 if(fEvent)fEvent->Reset();
108 return kTRUE;
6989bff3 109}
110
1aa09fd1 111Bool_t AliESDInputHandler::Notify(const char* path)
112{
113 // Notify a directory change
a5112f7d 114 AliInfo(Form("Directory change %s \n", path));
115 //
1aa09fd1 116 if (!fUseTags) return (kTRUE);
117
118 Bool_t zip = kFALSE;
119
120 TString fileName(path);
121 if(fileName.Contains("#AliESDs.root")){
122 fileName.ReplaceAll("#AliESDs.root", "");
123 zip = kTRUE;
124 }
125 else if (fileName.Contains("AliESDs.root")){
126 fileName.ReplaceAll("AliESDs.root", "");
127 }
128 else if(fileName.Contains("#AliAOD.root")){
129 fileName.ReplaceAll("#AliAOD.root", "");
130 zip = kTRUE;
131 }
132 else if(fileName.Contains("AliAOD.root")){
133 fileName.ReplaceAll("AliAOD.root", "");
134 }
135 else if(fileName.Contains("#galice.root")){
136 // For running with galice and kinematics alone...
137 fileName.ReplaceAll("#galice.root", "");
138 zip = kTRUE;
139 }
140 else if(fileName.Contains("galice.root")){
141 // For running with galice and kinematics alone...
142 fileName.ReplaceAll("galice.root", "");
143 }
144
1aa09fd1 145
d161aeeb 146 TString* pathName = new TString("./");
147 if (fileName.Length() != 0) {
148 *pathName = fileName;
149 }
150
1aa09fd1 151 printf("AliESDInputHandler::Notify() Path: %s\n", pathName->Data());
152
153 if (fRunTag) {
154 fRunTag->Clear();
155 } else {
156 fRunTag = new AliRunTag();
157 }
158
159 delete fTreeT; fTreeT = 0;
160
161 if (fChainT) {
162 delete fChainT;
163 fChainT = 0;
164 }
165
166 if (!fChainT) {
167 fChainT = new TChain("T");
168 }
169
170
171
172 const char* tagPattern = "ESD.tag.root";
173 const char* name = 0x0;
174 TString tagFilename;
175 if (zip) {
176 TFile* file = TFile::Open(fileName.Data());
177 TArchiveFile* arch = file->GetArchive();
178 TObjArray* arr = arch->GetMembers();
179 TIter next(arr);
180
7cec0871 181 while ((file = (TFile*) next())) {
1aa09fd1 182 name = file->GetName();
183 if (strstr(name,tagPattern)) {
184 tagFilename = pathName->Data();
185 tagFilename += "#";
186 tagFilename += name;
187 fChainT->Add(tagFilename);
188 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
189 }//pattern check
190 } // archive file loop
191 } else {
192 void * dirp = gSystem->OpenDirectory(pathName->Data());
193 while((name = gSystem->GetDirEntry(dirp))) {
194 if (strstr(name,tagPattern)) {
195 tagFilename = pathName->Data();
196 tagFilename += "/";
197 tagFilename += name;
198 fChainT->Add(tagFilename);
199 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
200 }//pattern check
201 }//directory loop
202 }
203 fChainT->SetBranchAddress("AliTAG",&fRunTag);
204 fChainT->GetEntry(0);
205 return kTRUE;
206}
207
208
300d5701 209void AliESDInputHandler::SwitchOffBranches() const {
210 //
211 // Switch of branches on user request
3858dd64 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)
217 continue;
218 fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
219 AliInfo(Form("Branch %s switched off \n", str.Data()));
220 }
221}
222
223void AliESDInputHandler::SwitchOnBranches() const {
224 //
225 // Switch of branches on user request
226 TObjArray * tokens = fBranchesOn.Tokenize(" ");
300d5701 227 Int_t ntok = tokens->GetEntries();
3858dd64 228
300d5701 229 for (Int_t i = 0; i < ntok; i++) {
3858dd64 230 TString str = ((TObjString*) tokens->At(i))->GetString();
231 if (str.Length() == 0)
232 continue;
233 fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 1);
234 AliInfo(Form("Branch %s switched on \n", str.Data()));
300d5701 235 }
236}