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