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