]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliESDInputHandler.cxx
Added ptHard to the information in the AliAODMCHeader, filled in the AODHandler
[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
60996693 89 if (fEvent) {
90 delete fEvent;
91 fEvent = 0;
6989bff3 92 }
60996693 93 fEvent = new AliESDEvent();
94
95 fEvent->ReadFromTree(fTree);
4d2a7370 96 fNEvents = fTree->GetEntries();
6ccd727b 97
98 if (fUseHLT) {
99 // Get HLTesdTree from current file
100 TTree* cTree = tree;
101 if (fTree->GetTree()) cTree = fTree->GetTree();
102 TFile* cFile = cTree->GetCurrentFile();
103 cFile->GetObject("HLTesdTree", fHLTTree);
104 if (fHLTEvent) {
105 delete fHLTEvent;
106 fHLTEvent = 0;
107 }
108 if (fHLTTree) {
109 fHLTEvent = new AliESDEvent();
110 fHLTEvent->ReadFromTree(fHLTTree);
111 }
112 }
113
d3dd3d14 114 return kTRUE;
115}
116
6ccd727b 117Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
d3dd3d14 118{
119 // Copy from old to new format if necessary
d7749dec 120 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
121 if (old) {
d3dd3d14 122 ((AliESDEvent*)fEvent)->CopyFromOldESD();
123 old->Reset();
d7749dec 124 }
6ccd727b 125
126 if (fHLTTree) {
127 fHLTTree->GetEntry(entry);
128 }
129
d7749dec 130 return kTRUE;
d3dd3d14 131}
132
e12e402c 133Bool_t AliESDInputHandler::FinishEvent()
134{
135 // Finish the event
136 if(fEvent)fEvent->Reset();
137 return kTRUE;
6989bff3 138}
139
1aa09fd1 140Bool_t AliESDInputHandler::Notify(const char* path)
141{
142 // Notify a directory change
a5112f7d 143 AliInfo(Form("Directory change %s \n", path));
144 //
1aa09fd1 145 if (!fUseTags) return (kTRUE);
146
147 Bool_t zip = kFALSE;
148
149 TString fileName(path);
150 if(fileName.Contains("#AliESDs.root")){
1aa09fd1 151 zip = kTRUE;
152 }
153 else if (fileName.Contains("AliESDs.root")){
154 fileName.ReplaceAll("AliESDs.root", "");
155 }
156 else if(fileName.Contains("#AliAOD.root")){
1aa09fd1 157 zip = kTRUE;
158 }
159 else if(fileName.Contains("AliAOD.root")){
160 fileName.ReplaceAll("AliAOD.root", "");
161 }
162 else if(fileName.Contains("#galice.root")){
163 // For running with galice and kinematics alone...
1aa09fd1 164 zip = kTRUE;
165 }
166 else if(fileName.Contains("galice.root")){
167 // For running with galice and kinematics alone...
168 fileName.ReplaceAll("galice.root", "");
169 }
170
1aa09fd1 171
be4763e2 172 TString pathName("./");
173 if (fileName.Length() != 0) {
174 pathName = fileName;
175 }
176
177 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
6ccd727b 178
1aa09fd1 179 if (fRunTag) {
180 fRunTag->Clear();
181 } else {
182 fRunTag = new AliRunTag();
183 }
184
185 delete fTreeT; fTreeT = 0;
6ccd727b 186
1aa09fd1 187 if (fChainT) {
188 delete fChainT;
189 fChainT = 0;
190 }
191
192 if (!fChainT) {
193 fChainT = new TChain("T");
194 }
195
196
197
198 const char* tagPattern = "ESD.tag.root";
199 const char* name = 0x0;
200 TString tagFilename;
201 if (zip) {
8ac5c1d7 202 TFile* file = fTree->GetCurrentFile();
1aa09fd1 203 TArchiveFile* arch = file->GetArchive();
204 TObjArray* arr = arch->GetMembers();
205 TIter next(arr);
206
7cec0871 207 while ((file = (TFile*) next())) {
1aa09fd1 208 name = file->GetName();
209 if (strstr(name,tagPattern)) {
be4763e2 210 tagFilename = pathName.Data();
1aa09fd1 211 tagFilename += "#";
212 tagFilename += name;
213 fChainT->Add(tagFilename);
214 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
215 }//pattern check
216 } // archive file loop
217 } else {
be4763e2 218 void * dirp = gSystem->OpenDirectory(pathName.Data());
1aa09fd1 219 while((name = gSystem->GetDirEntry(dirp))) {
220 if (strstr(name,tagPattern)) {
be4763e2 221 tagFilename = pathName.Data();
1aa09fd1 222 tagFilename += "/";
223 tagFilename += name;
224 fChainT->Add(tagFilename);
225 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
226 }//pattern check
227 }//directory loop
228 }
229 fChainT->SetBranchAddress("AliTAG",&fRunTag);
230 fChainT->GetEntry(0);
231 return kTRUE;
232}
233
234
c2b6979d 235
236Option_t *AliESDInputHandler::GetDataType() const
237{
238// Returns handled data type.
239 return gESDDataType;
240}