]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - STEER/AliESDInputHandler.cxx
MakeAlObjsArray is not const in the base class
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandler.cxx
... / ...
CommitLineData
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
23#include <TTree.h>
24#include <TChain.h>
25#include <TFile.h>
26#include <TArchiveFile.h>
27#include <TObjArray.h>
28#include <TSystem.h>
29#include <TString.h>
30#include <TObjString.h>
31#include <TProcessID.h>
32
33#include "AliESDInputHandler.h"
34#include "AliESDEvent.h"
35#include "AliESD.h"
36#include "AliRunTag.h"
37#include "AliEventTag.h"
38#include "AliLog.h"
39
40ClassImp(AliESDInputHandler)
41
42static Option_t *gESDDataType = "ESD";
43
44//______________________________________________________________________________
45AliESDInputHandler::AliESDInputHandler() :
46 AliInputEventHandler(),
47 fEvent(0x0),
48 fBranches(""),
49 fBranchesOn(""),
50 fAnalysisType(0),
51 fNEvents(0),
52 fUseTags(kFALSE),
53 fChainT(0),
54 fTreeT(0),
55 fRunTag(0)
56{
57 // default constructor
58}
59
60//______________________________________________________________________________
61AliESDInputHandler::~AliESDInputHandler()
62{
63 // destructor
64 // delete fEvent;
65}
66
67//______________________________________________________________________________
68AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
69 AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn(""), fAnalysisType(0),
70 fNEvents(0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
71{
72 // Constructor
73}
74
75Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
76{
77 // Initialisation necessary for each new tree
78 fAnalysisType = opt;
79 fTree = tree;
80
81 if (!fTree) return kFALSE;
82 // Get pointer to ESD event
83 SwitchOffBranches();
84 SwitchOnBranches();
85
86 if (fEvent) {
87 delete fEvent;
88 fEvent = 0;
89 }
90 fEvent = new AliESDEvent();
91
92 fEvent->ReadFromTree(fTree);
93 fNEvents = fTree->GetEntries();
94 return kTRUE;
95}
96
97Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
98{
99 // Copy from old to new format if necessary
100 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
101 if (old) {
102 ((AliESDEvent*)fEvent)->CopyFromOldESD();
103 old->Reset();
104 }
105 return kTRUE;
106}
107
108Bool_t AliESDInputHandler::FinishEvent()
109{
110 // Finish the event
111 if(fEvent)fEvent->Reset();
112 return kTRUE;
113}
114
115Bool_t AliESDInputHandler::Notify(const char* path)
116{
117 // Notify a directory change
118 AliInfo(Form("Directory change %s \n", path));
119 //
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
149
150 TString pathName("./");
151 if (fileName.Length() != 0) {
152 pathName = fileName;
153 }
154
155 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
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
185 while ((file = (TFile*) next())) {
186 name = file->GetName();
187 if (strstr(name,tagPattern)) {
188 tagFilename = pathName.Data();
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 {
196 void * dirp = gSystem->OpenDirectory(pathName.Data());
197 while((name = gSystem->GetDirEntry(dirp))) {
198 if (strstr(name,tagPattern)) {
199 tagFilename = pathName.Data();
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
213void AliESDInputHandler::SwitchOffBranches() const {
214 //
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)
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(" ");
231 Int_t ntok = tokens->GetEntries();
232
233 for (Int_t i = 0; i < ntok; i++) {
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()));
239 }
240}
241
242Option_t *AliESDInputHandler::GetDataType() const
243{
244// Returns handled data type.
245 return gESDDataType;
246}