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