]>
Commit | Line | Data |
---|---|---|
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 | |
40 | ClassImp(AliESDInputHandler) | |
41 | ||
c2b6979d | 42 | static Option_t *gESDDataType = "ESD"; |
43 | ||
d3dd3d14 | 44 | //______________________________________________________________________________ |
6989bff3 | 45 | AliESDInputHandler::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 | //______________________________________________________________________________ | |
61 | AliESDInputHandler::~AliESDInputHandler() | |
62 | { | |
1aa09fd1 | 63 | // destructor |
6989bff3 | 64 | // delete fEvent; |
d3dd3d14 | 65 | } |
66 | ||
67 | //______________________________________________________________________________ | |
68 | AliESDInputHandler::AliESDInputHandler(const char* name, const char* title): | |
1aa09fd1 | 69 | AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn(""), fAnalysisType(0), |
361a8f3c | 70 | fNEvents(0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0) |
d3dd3d14 | 71 | { |
e12e402c | 72 | // Constructor |
d3dd3d14 | 73 | } |
74 | ||
1aa09fd1 | 75 | Bool_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 | 97 | Bool_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 | 108 | Bool_t AliESDInputHandler::FinishEvent() |
109 | { | |
110 | // Finish the event | |
111 | if(fEvent)fEvent->Reset(); | |
112 | return kTRUE; | |
6989bff3 | 113 | } |
114 | ||
1aa09fd1 | 115 | Bool_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")){ | |
1aa09fd1 | 126 | zip = kTRUE; |
127 | } | |
128 | else if (fileName.Contains("AliESDs.root")){ | |
129 | fileName.ReplaceAll("AliESDs.root", ""); | |
130 | } | |
131 | else if(fileName.Contains("#AliAOD.root")){ | |
1aa09fd1 | 132 | zip = kTRUE; |
133 | } | |
134 | else if(fileName.Contains("AliAOD.root")){ | |
135 | fileName.ReplaceAll("AliAOD.root", ""); | |
136 | } | |
137 | else if(fileName.Contains("#galice.root")){ | |
138 | // For running with galice and kinematics alone... | |
1aa09fd1 | 139 | zip = kTRUE; |
140 | } | |
141 | else if(fileName.Contains("galice.root")){ | |
142 | // For running with galice and kinematics alone... | |
143 | fileName.ReplaceAll("galice.root", ""); | |
144 | } | |
145 | ||
1aa09fd1 | 146 | |
be4763e2 | 147 | TString pathName("./"); |
148 | if (fileName.Length() != 0) { | |
149 | pathName = fileName; | |
150 | } | |
151 | ||
152 | printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data()); | |
1aa09fd1 | 153 | |
154 | if (fRunTag) { | |
155 | fRunTag->Clear(); | |
156 | } else { | |
157 | fRunTag = new AliRunTag(); | |
158 | } | |
159 | ||
160 | delete fTreeT; fTreeT = 0; | |
161 | ||
162 | if (fChainT) { | |
163 | delete fChainT; | |
164 | fChainT = 0; | |
165 | } | |
166 | ||
167 | if (!fChainT) { | |
168 | fChainT = new TChain("T"); | |
169 | } | |
170 | ||
171 | ||
172 | ||
173 | const char* tagPattern = "ESD.tag.root"; | |
174 | const char* name = 0x0; | |
175 | TString tagFilename; | |
176 | if (zip) { | |
8ac5c1d7 | 177 | TFile* file = fTree->GetCurrentFile(); |
1aa09fd1 | 178 | TArchiveFile* arch = file->GetArchive(); |
179 | TObjArray* arr = arch->GetMembers(); | |
180 | TIter next(arr); | |
181 | ||
7cec0871 | 182 | while ((file = (TFile*) next())) { |
1aa09fd1 | 183 | name = file->GetName(); |
184 | if (strstr(name,tagPattern)) { | |
be4763e2 | 185 | tagFilename = pathName.Data(); |
1aa09fd1 | 186 | tagFilename += "#"; |
187 | tagFilename += name; | |
188 | fChainT->Add(tagFilename); | |
189 | AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data())); | |
190 | }//pattern check | |
191 | } // archive file loop | |
192 | } else { | |
be4763e2 | 193 | void * dirp = gSystem->OpenDirectory(pathName.Data()); |
1aa09fd1 | 194 | while((name = gSystem->GetDirEntry(dirp))) { |
195 | if (strstr(name,tagPattern)) { | |
be4763e2 | 196 | tagFilename = pathName.Data(); |
1aa09fd1 | 197 | tagFilename += "/"; |
198 | tagFilename += name; | |
199 | fChainT->Add(tagFilename); | |
200 | AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data())); | |
201 | }//pattern check | |
202 | }//directory loop | |
203 | } | |
204 | fChainT->SetBranchAddress("AliTAG",&fRunTag); | |
205 | fChainT->GetEntry(0); | |
206 | return kTRUE; | |
207 | } | |
208 | ||
209 | ||
300d5701 | 210 | void AliESDInputHandler::SwitchOffBranches() const { |
211 | // | |
212 | // Switch of branches on user request | |
3858dd64 | 213 | TObjArray * tokens = fBranches.Tokenize(" "); |
214 | Int_t ntok = tokens->GetEntries(); | |
215 | for (Int_t i = 0; i < ntok; i++) { | |
216 | TString str = ((TObjString*) tokens->At(i))->GetString(); | |
217 | if (str.Length() == 0) | |
218 | continue; | |
219 | fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0); | |
220 | AliInfo(Form("Branch %s switched off \n", str.Data())); | |
221 | } | |
222 | } | |
223 | ||
224 | void AliESDInputHandler::SwitchOnBranches() const { | |
225 | // | |
226 | // Switch of branches on user request | |
227 | TObjArray * tokens = fBranchesOn.Tokenize(" "); | |
300d5701 | 228 | Int_t ntok = tokens->GetEntries(); |
3858dd64 | 229 | |
300d5701 | 230 | for (Int_t i = 0; i < ntok; i++) { |
3858dd64 | 231 | TString str = ((TObjString*) tokens->At(i))->GetString(); |
232 | if (str.Length() == 0) | |
233 | continue; | |
234 | fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 1); | |
235 | AliInfo(Form("Branch %s switched on \n", str.Data())); | |
300d5701 | 236 | } |
237 | } | |
c2b6979d | 238 | |
239 | Option_t *AliESDInputHandler::GetDataType() const | |
240 | { | |
241 | // Returns handled data type. | |
242 | return gESDDataType; | |
243 | } |