]>
Commit | Line | Data |
---|---|---|
b86ddfbb | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, 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 | // Various utilities usefull for analysis | |
17 | // | |
18 | //*-- Yves Schutz | |
19 | ////////////////////////////////////////////////////////////////////////////// | |
20 | ||
21 | #include "AliAnalysisDataContainer.h" | |
22 | #include "AliTagAnalysis.h" | |
23 | #include "AliEventTagCuts.h" | |
24 | #include "AliRunTagCuts.h" | |
25 | #include "AliXMLCollection.h" | |
26 | #include "AliAnalysisGoodies.h" | |
27 | #include "AliAnalysisManager.h" | |
28 | #include "AliAnalysisTask.h" | |
b86ddfbb | 29 | #include "AliLog.h" |
30 | ||
31 | #include <Riostream.h> | |
9c0977a1 | 32 | #ifdef WITHALIEN |
31829163 | 33 | #include <TGridResult.h> |
d08133e6 | 34 | #include <TFileMerger.h> |
9c0977a1 | 35 | #endif |
b86ddfbb | 36 | #include <TChain.h> |
b86ddfbb | 37 | #include <TGrid.h> |
38 | #include <TROOT.h> | |
39 | #include <TSystem.h> | |
d775a1d2 | 40 | #include <TEntryList.h> |
b86ddfbb | 41 | |
42 | //______________________________________________________________________________ | |
43 | AliAnalysisGoodies::AliAnalysisGoodies() : | |
91605856 | 44 | TObject(), |
45 | fTimer(), | |
b86ddfbb | 46 | fESDTreeName("esdTree"), |
47 | fnumberOfTasks(0), | |
48 | fTaskList(0), | |
49 | fTaskInType(0), | |
50 | fTaskOuType(0) | |
51 | { | |
52 | fTimer.Reset() ; | |
53 | ||
54 | TString token = gSystem->Getenv("GRID_TOKEN") ; | |
55 | ||
56 | if ( token == "OK" ) | |
57 | TGrid::Connect("alien://"); | |
58 | else | |
59 | AliInfo("You are not connected to the GRID") ; | |
60 | } | |
61 | ||
91605856 | 62 | //______________________________________________________________________________ |
63 | AliAnalysisGoodies::AliAnalysisGoodies(const AliAnalysisGoodies& ag) : | |
64 | TObject(), | |
65 | fTimer(), | |
66 | fESDTreeName(""), | |
67 | fnumberOfTasks(0), | |
68 | fTaskList(0), | |
69 | fTaskInType(0), | |
70 | fTaskOuType(0) | |
71 | { | |
72 | ||
73 | fESDTreeName = ag.fESDTreeName ; | |
74 | TString token = gSystem->Getenv("GRID_TOKEN") ; | |
75 | ||
76 | if ( token == "OK" ) | |
77 | TGrid::Connect("alien://"); | |
78 | else | |
79 | AliInfo("You are not connected to the GRID") ; | |
80 | } | |
81 | ||
b86ddfbb | 82 | //______________________________________________________________________________ |
83 | void AliAnalysisGoodies::Help() const | |
84 | { | |
85 | AliInfo("Analysis utilities:\n") ; | |
003ca69e | 86 | printf(" *** Alien2Local : copy files ESD files listed in an xml collection from AliEn catalog to local storage and creates a local xml collection \n") ; |
87 | printf(" usage: Alien2Local(in, out)\n") ; | |
b86ddfbb | 88 | printf(" in: a xml esd collection file name \n") ; |
89 | printf(" ou: the local directory where to save the esd root files \n") ; | |
90 | printf(" *** Make : makes esd collection from tags \n") ; | |
91 | printf(" usage: Make(tags, esds)\n") ; | |
92 | printf(" tags: is either a tag root file or an xml tag collection \n") ; | |
93 | printf(" esds: is an esd collection \n") ; | |
94 | printf(" *** Merge : merges files listed in a xml collection \n") ; | |
95 | printf(" usage Merge(collection, outputDile)\n") ; | |
96 | printf(" collection: is a xml collection \n") ; | |
97 | printf(" *** Process : process the events with an Analysis Task \n") ; | |
98 | printf(" usage: Process(esdFile, tagCuts) \n") ; | |
99 | printf(" esdFile: can be a root file with the ESD Tree ( ex: esd?AliESDs.root) \n") ; | |
100 | printf(" or a root file with the Tag Tree ( ex: tag?Run100.Event0_100.ESD.tag.root) \n") ; | |
101 | printf(" or a local or alien xml file with the ESD collection ( ex: esd?esdCollection.xml) \n") ; | |
102 | printf(" or a local or alien xml file with the TAG collection ( ex: tag?tagCollection.xml) \n") ; | |
103 | printf(" or a TChain of esd TTrees \n") ; | |
104 | printf(" tagCuts: is the AliEventTagCuts (needed only for tag? cases \n") ; | |
105 | printf(" *** Register: register files already stored in a MSS into the AliEn catalog\n") ; | |
106 | printf(" usage: Register(lfndir, pfndir, pfnFileName) \n") ; | |
107 | printf(" lfndir : AliEn directory ( ex: /alice/data/2006/LHC06c/PHOS_TestBeam/\n") ; | |
108 | printf(" pfndir : MSS directory ( ex: /castor/cern.ch/alice/testbeam/phos/2006 \n") ; | |
109 | printf(" file : text file with a list of the file names to be registered\n ") ; | |
110 | ||
111 | } | |
112 | ||
113 | //______________________________________________________________________ | |
c49bca36 | 114 | Bool_t AliAnalysisGoodies::Alien2Local(const TString collectionNameIn, const TString localDir) |
b86ddfbb | 115 | { |
116 | // copy files ESD files listed in an xml collection from AliEn catalog to local storage and creates a local xml collection | |
117 | // usage: Alien2Local(in, out) | |
118 | // in: a xml esd collection file name | |
119 | // ou: the local directory where to save the esd root files | |
120 | ||
d08133e6 | 121 | #ifdef WITHALIEN |
b86ddfbb | 122 | Bool_t rv = kTRUE ; |
123 | ||
124 | fTimer.Start() ; | |
125 | ||
126 | AliXMLCollection * collectionIn = AliXMLCollection::Open(collectionNameIn) ; | |
127 | collectionIn->Reset() ; | |
128 | ||
129 | AliXMLCollection * collectionOu = new AliXMLCollection() ; | |
130 | TString collectionNameOu(collectionIn->GetCollectionName()) ; | |
131 | collectionNameOu.Append("Local") ; | |
132 | collectionOu->SetCollectionName(collectionNameOu) ; | |
133 | collectionOu->WriteHeader() ; | |
134 | ||
135 | TFileMerger merger ; | |
136 | ||
137 | const char* ocwd = gSystem->WorkingDirectory(); | |
138 | ||
c16bb9ed | 139 | Int_t counter = 1 ; |
b86ddfbb | 140 | while ( collectionIn->Next() ) { |
141 | gSystem->ChangeDirectory(localDir) ; | |
142 | TString fileTURL = collectionIn->GetTURL("") ; | |
143 | ||
144 | TString tempo(fileTURL) ; | |
145 | tempo.Remove(tempo.Last('/'), tempo.Length()) ; | |
146 | TString evtsNumber = tempo(tempo.Last('/')+1, tempo.Length())+"/"; | |
147 | tempo.Remove(tempo.Last('/'), tempo.Length()) ; | |
148 | TString runNumber = tempo(tempo.Last('/')+1, tempo.Length())+"/" ; | |
149 | TString dir = localDir + runNumber ; | |
d775a1d2 | 150 | dir += evtsNumber ; |
151 | char line[1024] ; | |
152 | sprintf(line, ".! mkdir -p %s", dir.Data()) ; | |
153 | gROOT->ProcessLine(line) ; | |
154 | printf("***************************%s\n", line) ; | |
b86ddfbb | 155 | TEntryList * list = collectionIn->GetEventList("") ; |
d775a1d2 | 156 | if (!list) |
157 | list = new TEntryList() ; | |
d775a1d2 | 158 | tempo = fileTURL ; |
159 | TString filename = tempo(tempo.Last('/')+1, tempo.Length()) ; | |
160 | dir += filename ; | |
161 | AliInfo(Form("Copying %s to %s\n", fileTURL.Data(), dir.Data())) ; | |
c16bb9ed | 162 | collectionOu->WriteBody(counter, collectionIn->GetGUID(""), collectionIn->GetLFN(""), dir, list) ; |
163 | counter++ ; | |
b86ddfbb | 164 | merger.Cp(fileTURL, dir) ; |
165 | } | |
166 | collectionOu->Export() ; | |
167 | gSystem->ChangeDirectory(ocwd) ; | |
168 | ||
169 | fTimer.Stop(); | |
170 | fTimer.Print(); | |
171 | ||
d08133e6 | 172 | return rv ; |
173 | #else | |
174 | return kFALSE; | |
175 | #endif | |
b86ddfbb | 176 | } |
177 | ||
178 | //______________________________________________________________________ | |
91605856 | 179 | Bool_t AliAnalysisGoodies::Make(AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts *evtCuts, const char * in, const char * out) const |
b86ddfbb | 180 | { |
181 | // makes esd collection from tags | |
182 | // usage Make(tags, esds) | |
183 | // tags: is either a tag root file or an xml tag collection | |
184 | // esds: is an esd collection | |
185 | ||
186 | Bool_t rv = kTRUE ; | |
187 | ||
188 | if ( !evtCuts && !runCuts ) { | |
189 | AliError("No Tag cuts provided") ; | |
190 | return kFALSE ; | |
191 | } | |
192 | ||
193 | TString file(in) ; | |
194 | if ( file.Contains(".root") ) | |
91605856 | 195 | rv = MakeEsdCollectionFromTagFile(runCuts, lhcCuts, detCuts, evtCuts, file.Data(), out) ; |
b86ddfbb | 196 | else if ( file.Contains(".xml") ) |
91605856 | 197 | rv = MakeEsdCollectionFromTagCollection(runCuts, lhcCuts, detCuts, evtCuts, file.Data(), out) ; |
b86ddfbb | 198 | else { |
199 | AliError(Form("%s is not a valid file format", in)) ; | |
200 | rv = kFALSE ; | |
201 | } | |
202 | ||
203 | return rv ; | |
204 | } | |
205 | ||
206 | //______________________________________________________________________ | |
91605856 | 207 | Bool_t AliAnalysisGoodies::MakeEsdCollectionFromTagFile(AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts *evtCuts, const char * in, const char * out) const |
b86ddfbb | 208 | { |
209 | // Makes an esd collection from a root tag file | |
210 | Bool_t rv = kTRUE ; | |
211 | // Open the file collection | |
212 | printf("*** Create Collection ***\n"); | |
213 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
214 | printf("*** file = |%s| \n",in); | |
215 | ||
216 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
217 | rv = tagAna->AddTagsFile(in); | |
218 | if ( ! rv ) | |
219 | return rv ; | |
220 | ||
91605856 | 221 | tagAna->CreateXMLCollection(out, runCuts, lhcCuts, detCuts, evtCuts) ; |
b86ddfbb | 222 | |
223 | return rv ; | |
224 | ||
225 | } | |
226 | ||
227 | //______________________________________________________________________ | |
91605856 | 228 | Bool_t AliAnalysisGoodies::MakeEsdCollectionFromTagCollection(AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts *evtCuts, const char * in, const char * out) const |
b86ddfbb | 229 | { |
230 | // Makes an esd collection from a xml tag collection | |
231 | Bool_t rv = kTRUE ; | |
232 | // Open the file collection | |
233 | printf("*** Create Collection ***\n"); | |
234 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
235 | printf("*** Coll = |%s| \n",in); | |
9c0977a1 | 236 | |
237 | #ifdef WITHALIEN | |
b86ddfbb | 238 | |
50026a5f | 239 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(%s)",in)); |
b86ddfbb | 240 | TGridResult* result = collection->GetGridResult(""); |
241 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
242 | tagAna->ChainGridTags(result); | |
243 | ||
91605856 | 244 | tagAna->CreateXMLCollection(out, runCuts, lhcCuts, detCuts, evtCuts) ; |
b86ddfbb | 245 | |
9c0977a1 | 246 | #else |
d775a1d2 | 247 | rv = kFALSE; |
9c0977a1 | 248 | #endif |
d775a1d2 | 249 | return rv ; |
b86ddfbb | 250 | } |
251 | ||
252 | //______________________________________________________________________ | |
91605856 | 253 | Bool_t AliAnalysisGoodies::MakeEsdCollectionFromTagCollection(const char * runCuts, const char *lhcCuts, const char *detCuts, const char * evtCuts, const char * in, const char * out) const |
b86ddfbb | 254 | { |
255 | // Makes an esd collection from a xml tag collection | |
256 | ||
257 | Bool_t rv = kTRUE ; | |
258 | ||
259 | // Open the file collection | |
260 | printf("*** Create Collection ***\n"); | |
261 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
262 | printf("*** Coll = |%s| \n",in); | |
263 | ||
9c0977a1 | 264 | #ifdef WITHALIEN |
265 | ||
50026a5f | 266 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(%s)",in)); |
b86ddfbb | 267 | TGridResult* result = collection->GetGridResult(""); |
268 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
269 | tagAna->ChainGridTags(result); | |
270 | ||
91605856 | 271 | tagAna->CreateXMLCollection(out, runCuts, lhcCuts, detCuts, evtCuts) ; |
b86ddfbb | 272 | |
9c0977a1 | 273 | #else |
50026a5f | 274 | rv = kFALSE; |
9c0977a1 | 275 | #endif |
50026a5f | 276 | return rv ; |
b86ddfbb | 277 | } |
278 | ||
279 | //______________________________________________________________________ | |
c49bca36 | 280 | Bool_t AliAnalysisGoodies::Merge(const char * collectionFile, const char * subFile, const char * outFile) |
b86ddfbb | 281 | { |
282 | // merges files listed in a xml collection | |
283 | // usage Merge(collection, outputFile)) | |
284 | // collection: is a xml collection | |
285 | ||
286 | Bool_t rv = kFALSE ; | |
287 | ||
288 | if ( strstr(collectionFile, ".xml") == 0 ) { | |
289 | AliError("Input collection file must be an \".xml\" file\n") ; | |
290 | return kFALSE ; | |
291 | } | |
292 | ||
293 | fTimer.Start() ; | |
294 | ||
295 | // Open the file collection | |
296 | printf("*** Create Collection ***\n"); | |
297 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
298 | printf("*** Coll = |%s| \n",collectionFile); | |
299 | ||
9c0977a1 | 300 | #ifdef WITHALIEN |
301 | ||
50026a5f | 302 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(%s)",collectionFile)); |
b86ddfbb | 303 | TGridResult* result = collection->GetGridResult(""); |
304 | ||
305 | Int_t index = 0 ; | |
306 | const char * turl ; | |
307 | TFileMerger merger ; | |
308 | if (!outFile) { | |
309 | TString tempo(collectionFile) ; | |
310 | if ( subFile) | |
311 | tempo.ReplaceAll(".xml", subFile) ; | |
312 | else | |
313 | tempo.ReplaceAll(".xml", "_Merged.root") ; | |
314 | outFile = tempo.Data() ; | |
315 | } | |
316 | merger.OutputFile(outFile) ; | |
317 | ||
318 | while ( (turl = result->GetKey(index, "turl")) ) { | |
319 | char file[2048] ; | |
320 | if ( subFile ) | |
321 | sprintf(file, "%s#%s", turl, subFile) ; | |
322 | else | |
323 | sprintf(file, "%s", turl) ; | |
324 | ||
325 | printf("%s\n", file) ; | |
326 | merger.AddFile(file) ; | |
327 | index++ ; | |
328 | } | |
329 | ||
330 | if (index) | |
331 | merger.Merge() ; | |
332 | ||
333 | AliInfo(Form("Files merged into %s\n", outFile)) ; | |
334 | ||
335 | fTimer.Stop(); | |
336 | fTimer.Print(); | |
337 | ||
9c0977a1 | 338 | #else |
50026a5f | 339 | rv = kFALSE; |
9c0977a1 | 340 | #endif |
50026a5f | 341 | return rv ; |
b86ddfbb | 342 | } |
343 | ||
344 | //______________________________________________________________________ | |
c49bca36 | 345 | Bool_t AliAnalysisGoodies::Process(TChain * chain) |
b86ddfbb | 346 | { |
347 | // process events starting from a chain of esd Trees | |
348 | Bool_t rv = kFALSE ; | |
b86ddfbb | 349 | fTimer.Start() ; |
350 | ||
351 | rv = ProcessChain(chain) ; | |
352 | ||
353 | fTimer.Stop(); | |
354 | fTimer.Print(); | |
355 | ||
356 | return rv ; | |
357 | } | |
358 | ||
359 | //______________________________________________________________________ | |
c49bca36 | 360 | Bool_t AliAnalysisGoodies::Process(const char * inFile) |
b86ddfbb | 361 | { |
362 | // process the events with an Analysis Task | |
363 | // usage Process(esdFile) | |
364 | // esdFile: is of the form opt?file_lfn | |
365 | Bool_t rv = kFALSE ; | |
91605856 | 366 | AliRunTagCuts * runCuts = 0x0 ; |
367 | AliLHCTagCuts * lhcCuts = 0x0 ; | |
368 | AliDetectorTagCuts * detCuts = 0x0 ; | |
369 | AliEventTagCuts * evtCuts = 0x0 ; | |
b86ddfbb | 370 | |
91605856 | 371 | rv = Process(inFile, runCuts, lhcCuts, detCuts, evtCuts) ; |
b86ddfbb | 372 | |
373 | return rv ; | |
374 | } | |
375 | ||
376 | //______________________________________________________________________ | |
91605856 | 377 | Bool_t AliAnalysisGoodies::Process(const char * inFile, AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts * evtCuts ) |
b86ddfbb | 378 | { |
379 | // process the events with an Analysis Task | |
380 | // usage Process(esdFile, runtagCuts, evtTagCuts) | |
381 | // esdFile: is of the form opt?file_lfn | |
382 | ||
383 | Bool_t rv = kFALSE ; | |
384 | ||
385 | fTimer.Start() ; | |
386 | ||
387 | TString file(inFile) ; | |
388 | if ( file.Contains("esd?") && file.Contains(".root") ) { | |
389 | file.ReplaceAll("esd?", "") ; | |
390 | rv = ProcessEsdFile(file.Data()) ; | |
391 | ||
392 | } else if ( file.Contains("esd?") && file.Contains(".xml") ) { | |
393 | file.ReplaceAll("esd?", "") ; | |
394 | rv = ProcessEsdXmlCollection(file.Data()) ; | |
395 | ||
396 | } else if (file.Contains("tag?") && file.Contains(".root") ) { | |
397 | file.ReplaceAll("tag?", "") ; | |
91605856 | 398 | rv = ProcessTagFile(file.Data(), runCuts, lhcCuts, detCuts, evtCuts) ; |
b86ddfbb | 399 | |
400 | } else if (file.Contains("tag?") && file.Contains(".xml") ) { | |
401 | file.ReplaceAll("tag?", "") ; | |
91605856 | 402 | rv = ProcessTagXmlCollection(file.Data(), runCuts, lhcCuts, detCuts, evtCuts) ; |
b86ddfbb | 403 | |
404 | } else { | |
405 | AliError(Form("%s is not a valid file format", inFile)) ; | |
406 | rv = kFALSE ; | |
407 | } | |
408 | ||
409 | fTimer.Stop(); | |
410 | fTimer.Print(); | |
411 | ||
412 | return rv ; | |
413 | } | |
414 | ||
415 | //______________________________________________________________________ | |
91605856 | 416 | Bool_t AliAnalysisGoodies::Process(const char * inFile, const char * runCuts, const char * lhcCuts, const char * detCuts, const char * evtCuts) |
b86ddfbb | 417 | { |
418 | // process the events with an Analysis Task | |
419 | // usage Process(esdFile, runtagCuts, evtTagCuts) | |
420 | // esdFile: is of the form opt?file_lfn | |
421 | ||
422 | Bool_t rv = kFALSE ; | |
423 | ||
424 | fTimer.Start() ; | |
425 | ||
426 | TString file(inFile) ; | |
427 | if ( file.Contains("esd?") && file.Contains(".root") ) { | |
428 | file.ReplaceAll("esd?", "") ; | |
429 | rv = ProcessEsdFile(file.Data()) ; | |
430 | ||
431 | } else if ( file.Contains("esd?") && file.Contains(".xml") ) { | |
432 | file.ReplaceAll("esd?", "") ; | |
433 | rv = ProcessEsdXmlCollection(file.Data()) ; | |
434 | ||
435 | } else if (file.Contains("tag?") && file.Contains(".root") ) { | |
436 | file.ReplaceAll("tag?", "") ; | |
91605856 | 437 | rv = ProcessTagFile(file.Data(), runCuts, lhcCuts, detCuts, evtCuts) ; |
b86ddfbb | 438 | |
439 | } else if (file.Contains("tag?") && file.Contains(".xml") ) { | |
440 | file.ReplaceAll("tag?", "") ; | |
91605856 | 441 | rv = ProcessTagXmlCollection(file.Data(), runCuts, lhcCuts, detCuts, evtCuts) ; |
b86ddfbb | 442 | |
443 | } else { | |
444 | AliError(Form("%s is not a valid file format", inFile)) ; | |
445 | rv = kFALSE ; | |
446 | } | |
447 | ||
448 | fTimer.Stop(); | |
449 | fTimer.Print(); | |
450 | ||
451 | return rv ; | |
452 | } | |
453 | ||
454 | //______________________________________________________________________ | |
c49bca36 | 455 | Bool_t AliAnalysisGoodies::ProcessChain(TChain * chain) const |
b86ddfbb | 456 | { |
457 | // Procees a TChain. | |
458 | ||
459 | Bool_t rv = kTRUE ; | |
460 | ||
461 | if (! fTaskList ) { | |
462 | AliError("No tasks defined") ; | |
463 | return kFALSE ; | |
464 | } | |
3d868cda | 465 | |
b86ddfbb | 466 | // Make the analysis manager |
3d868cda | 467 | AliAnalysisManager * mgr = new AliAnalysisManager("Goodies Manager", "Analysis manager created by AliAnalysisGoodies") ; |
b86ddfbb | 468 | |
469 | // Make tasks | |
470 | // The top input must be common to all top tasks | |
471 | TClass * classIn = fTaskInType[0] ; | |
c52c2132 | 472 | AliAnalysisDataContainer * taskInput = mgr->CreateContainer("InputContainer", classIn, AliAnalysisManager::kInputContainer) ; |
b86ddfbb | 473 | Int_t index ; |
474 | for (index = 0; index < fnumberOfTasks; index++) { | |
6797e4bc | 475 | |
476 | TClass * classOu = fTaskOuType[index] ; | |
b86ddfbb | 477 | AliAnalysisTask * task = fTaskList[index] ; |
6797e4bc | 478 | |
479 | AliAnalysisDataContainer * taskOutput = mgr->CreateContainer(Form("OutputContainer%d",index), classOu, AliAnalysisManager::kOutputContainer, Form("%s.root",task->GetName())) ; | |
b86ddfbb | 480 | mgr->AddTask(task) ; |
6797e4bc | 481 | |
b86ddfbb | 482 | // Create containers for input/output |
6797e4bc | 483 | |
b86ddfbb | 484 | mgr->ConnectInput (task, 0, taskInput); |
485 | mgr->ConnectOutput(task, 0, taskOutput); | |
486 | } | |
487 | ||
91605856 | 488 | // start processing |
b86ddfbb | 489 | |
490 | if (mgr->InitAnalysis()) { | |
491 | mgr->PrintStatus(); | |
c52c2132 | 492 | mgr->StartAnalysis("local",chain); |
b86ddfbb | 493 | } else |
494 | rv = kFALSE ; | |
495 | ||
496 | return rv ; | |
497 | } | |
498 | ||
499 | //______________________________________________________________________ | |
c49bca36 | 500 | Bool_t AliAnalysisGoodies::ProcessEsdFile(const char * esdFile) const |
b86ddfbb | 501 | { |
502 | // process the events in a single ESD file with an Analysis Task | |
503 | // usage ProcessLocalEsdFile(esdFile) | |
504 | // esdFile: is the root file (local or in alien) with the ESD Tree ( ex: AliESDs.root) | |
505 | ||
506 | Bool_t rv = kTRUE ; | |
507 | ||
508 | printf("*** Process ***\n"); | |
509 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
510 | printf("*** Coll = |%s| \n",esdFile); | |
511 | ||
512 | // Makes the ESD chain | |
513 | printf("*** Getting the Chain ***\n"); | |
514 | TChain* analysisChain = new TChain(fESDTreeName) ; | |
515 | analysisChain->AddFile(esdFile); | |
516 | ||
517 | // Process the events | |
518 | rv = ProcessChain(analysisChain) ; | |
519 | ||
520 | return rv; | |
521 | } | |
522 | ||
523 | //______________________________________________________________________ | |
91605856 | 524 | Bool_t AliAnalysisGoodies::ProcessTagFile(const char * tagFile, AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts *evtCuts) const |
b86ddfbb | 525 | { |
526 | // process the events in a single Tag file with an Analysis Task | |
527 | // usage ProcessLocalEsdFile(tagFile) | |
528 | // tagFile: is the root file (local or in alien) with the Tag Tree (ex: Run102.Event0_100.ESD.tag.root) | |
529 | ||
530 | Bool_t rv = kTRUE ; | |
531 | ||
532 | if ( !evtCuts && !runCuts ) { | |
533 | AliError("No Tag cuts provided") ; | |
534 | return kFALSE ; | |
535 | } | |
536 | ||
537 | printf("*** Process ***\n"); | |
538 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
539 | printf("*** Coll = |%s| \n",tagFile); | |
540 | ||
541 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
542 | rv = tagAna->AddTagsFile(tagFile); | |
543 | if ( ! rv ) | |
544 | return rv ; | |
545 | ||
546 | // Query the tag file and make the analysis chain | |
547 | TChain * analysisChain = new TChain(fESDTreeName) ; | |
91605856 | 548 | analysisChain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evtCuts); |
b86ddfbb | 549 | |
550 | // Process the events | |
551 | rv = ProcessChain(analysisChain) ; | |
552 | ||
553 | return rv; | |
554 | } | |
555 | ||
556 | //______________________________________________________________________ | |
91605856 | 557 | Bool_t AliAnalysisGoodies::ProcessTagFile(const char * tagFile, const char * runCuts, const char * lhcCuts, const char * detCuts, const char * evtCuts) const |
b86ddfbb | 558 | { |
559 | // process the events in a single Tag file with an Analysis Task | |
560 | // usage ProcessLocalEsdFile(tagFile) | |
561 | // tagFile: is the root file (local or in alien) with the Tag Tree (ex: Run102.Event0_100.ESD.tag.root) | |
562 | ||
563 | Bool_t rv = kTRUE ; | |
564 | ||
565 | ||
566 | if ( !evtCuts && !runCuts ) { | |
567 | AliError("No Tag cuts provided") ; | |
568 | return kFALSE ; | |
569 | } | |
570 | ||
571 | printf("*** Process ***\n"); | |
572 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
573 | printf("*** Coll = |%s| \n",tagFile); | |
574 | ||
575 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
576 | rv = tagAna->AddTagsFile(tagFile); | |
577 | if ( ! rv ) | |
578 | return rv ; | |
579 | ||
580 | // Query the tag file and make the analysis chain | |
581 | TChain * analysisChain = new TChain(fESDTreeName) ; | |
91605856 | 582 | analysisChain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evtCuts); |
b86ddfbb | 583 | |
584 | // Process the events | |
585 | rv = ProcessChain(analysisChain) ; | |
586 | ||
587 | return rv; | |
588 | } | |
589 | ||
590 | //______________________________________________________________________ | |
c49bca36 | 591 | Bool_t AliAnalysisGoodies::ProcessEsdXmlCollection(const char * xmlFile) const |
b86ddfbb | 592 | { |
593 | // process the events in a xml ESD collection with an Analysis Task | |
594 | // usage ProcessLocalEsdFile(xmlFile) | |
595 | // xmlFile: is the local xml file with the ESD collection ( ex: esdCollection.xml) | |
596 | ||
597 | Bool_t rv = kTRUE ; | |
598 | ||
599 | printf("*** Process ***\n"); | |
600 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
601 | printf("*** Coll = |%s| \n",xmlFile); | |
602 | ||
9c0977a1 | 603 | #ifdef WITHALIEN |
6797e4bc | 604 | //AliXMLCollection * collection = AliXMLCollection::Open(xmlFile,0) ; |
37b5342b | 605 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(%s,0)",xmlFile)); |
b86ddfbb | 606 | if (! collection) { |
607 | AliError(Form("%s not found", xmlFile)) ; | |
608 | return kFALSE ; | |
609 | } | |
610 | ||
611 | TGridResult* result = collection->GetGridResult(""); | |
612 | TList* analysisfilelist = result->GetFileInfoList(); | |
613 | ||
614 | // Makes the ESD chain | |
615 | printf("*** Getting the Chain ***\n"); | |
616 | TChain* analysisChain = new TChain(fESDTreeName); | |
617 | analysisChain->AddFileInfoList(analysisfilelist); | |
6797e4bc | 618 | |
b86ddfbb | 619 | // Process the events |
620 | rv = ProcessChain(analysisChain) ; | |
621 | ||
9c0977a1 | 622 | #else |
50026a5f | 623 | rv = kFALSE; |
6797e4bc | 624 | |
9c0977a1 | 625 | #endif |
6797e4bc | 626 | |
50026a5f | 627 | return rv ; |
b86ddfbb | 628 | } |
629 | ||
630 | //______________________________________________________________________ | |
91605856 | 631 | Bool_t AliAnalysisGoodies::ProcessTagXmlCollection(const char * xmlFile, AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts * evtCuts) const |
b86ddfbb | 632 | { |
633 | // process the events in a xml ESD collection with an Analysis Task | |
634 | // usage ProcessLocalEsdFile(xmlFile) | |
635 | // xmlFile: is the local xml file with the tag collection ( ex: tagCollection.xml) | |
636 | ||
637 | Bool_t rv = kTRUE ; | |
638 | ||
639 | if ( !evtCuts && !runCuts ) { | |
640 | AliError("No Tag cuts provided") ; | |
641 | return kFALSE ; | |
642 | } | |
643 | ||
644 | printf("*** Process ***\n"); | |
645 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
646 | printf("*** Coll = |%s| \n",xmlFile); | |
647 | ||
648 | // check if file is local or alien | |
649 | if ( gSystem->AccessPathName(xmlFile) ) | |
650 | TGrid::Connect("alien://"); | |
651 | ||
9c0977a1 | 652 | #ifdef WITHALIEN |
653 | ||
50026a5f | 654 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(%s)",xmlFile)); |
b86ddfbb | 655 | if (! collection) { |
656 | AliError(Form("%s not found", xmlFile)) ; | |
657 | return kFALSE ; | |
658 | } | |
659 | ||
660 | TGridResult* result = collection->GetGridResult(""); | |
661 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
662 | tagAna->ChainGridTags(result); | |
663 | ||
664 | // Query the tag file and make the analysis chain | |
665 | TChain * analysisChain = new TChain(fESDTreeName) ; | |
91605856 | 666 | analysisChain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evtCuts); |
b86ddfbb | 667 | |
668 | // Process the events | |
669 | rv = ProcessChain(analysisChain) ; | |
670 | ||
9c0977a1 | 671 | #else |
50026a5f | 672 | rv = kFALSE; |
9c0977a1 | 673 | #endif |
50026a5f | 674 | return rv ; |
b86ddfbb | 675 | } |
676 | ||
677 | //______________________________________________________________________ | |
91605856 | 678 | Bool_t AliAnalysisGoodies::ProcessTagXmlCollection(const char * xmlFile, const char * runCuts, const char * lhcCuts, const char * detCuts, const char * evtCuts) const |
b86ddfbb | 679 | { |
680 | // process the events in a xml ESD collection with an Analysis Task | |
681 | // usage ProcessLocalEsdFile(xmlFile) | |
682 | // xmlFile: is the local xml file with the tag collection ( ex: tagCollection.xml) | |
683 | ||
684 | Bool_t rv = kTRUE ; | |
685 | ||
686 | if ( !evtCuts && !runCuts ) { | |
687 | AliError("No Tag cuts provided") ; | |
688 | return kFALSE ; | |
689 | } | |
690 | ||
691 | printf("*** Process ***\n"); | |
692 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
693 | printf("*** Coll = |%s| \n",xmlFile); | |
694 | ||
9c0977a1 | 695 | #ifdef WITHALIEN |
696 | ||
b86ddfbb | 697 | // check if file is local or alien |
698 | if ( gSystem->AccessPathName(xmlFile) ) | |
699 | TGrid::Connect("alien://"); | |
700 | ||
50026a5f | 701 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(%s)",xmlFile)); |
b86ddfbb | 702 | if (! collection) { |
703 | AliError(Form("%s not found", xmlFile)) ; | |
704 | return kFALSE ; | |
705 | } | |
706 | ||
707 | TGridResult* result = collection->GetGridResult(""); | |
708 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
709 | tagAna->ChainGridTags(result); | |
710 | ||
711 | // Query the tag file and make the analysis chain | |
712 | TChain * analysisChain = new TChain(fESDTreeName) ; | |
91605856 | 713 | analysisChain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evtCuts); |
b86ddfbb | 714 | |
715 | // Process the events | |
716 | rv = ProcessChain(analysisChain) ; | |
717 | ||
9c0977a1 | 718 | #else |
50026a5f | 719 | rv = kFALSE; |
9c0977a1 | 720 | #endif |
50026a5f | 721 | return rv ; |
b86ddfbb | 722 | } |
723 | ||
724 | //______________________________________________________________________ | |
c49bca36 | 725 | Bool_t AliAnalysisGoodies::Register( const char * lfndir, const char * pfndir, const char * file) |
b86ddfbb | 726 | { |
727 | // register files already stored in a MSS into the AliEn catalog | |
728 | // usage: Register(lfndir, pfndir, pfnFileName) | |
729 | // lfndir : AliEn directory ( ex: /alice/data/2006/LHC06c/PHOS_TestBeam/ ) | |
730 | // pfndir : MSS directory ( ex: /castor/cern.ch/alice/testbeam/phos/2006 ) | |
731 | // file : text file with a list of the file names to be registered | |
732 | ||
733 | Bool_t rv = kTRUE ; | |
734 | fTimer.Start() ; | |
735 | ||
736 | ifstream in; | |
737 | in.open(file); | |
738 | if ( in.bad() ) { | |
739 | AliError(Form("Cannot open file %s\n", file)) ; | |
740 | return kFALSE ; | |
741 | } | |
742 | ||
743 | TGrid::Connect("alien://"); | |
744 | ||
745 | char fileName[1024] ; | |
746 | ||
747 | while (1) { | |
748 | in >> fileName ; | |
749 | if (!in.good()) | |
750 | break; | |
751 | char lfn[1024] ; | |
752 | ||
753 | sprintf(lfn, "%s/%s", lfndir, fileName) ; | |
754 | ||
755 | char pfn[1024] ; | |
756 | ||
757 | sprintf(pfn, "castor://Alice::CERN::Castor2/%s/%s", pfndir, fileName) ; | |
758 | ||
759 | printf("Register %s as %s\n", pfn, lfn) ; | |
760 | ||
761 | gGrid->Register(lfn, pfn) ; | |
762 | } | |
763 | ||
764 | fTimer.Stop(); | |
765 | fTimer.Print(); | |
766 | ||
767 | return rv; | |
768 | } | |
769 | ||
770 | //______________________________________________________________________ | |
771 | void AliAnalysisGoodies::SetTasks(Int_t nb, AliAnalysisTask ** taskList, TClass ** inputType, TClass ** outputType) | |
772 | { | |
773 | // define a task with its output and input type | |
774 | ||
775 | ||
776 | fnumberOfTasks= nb; | |
777 | fTaskList = taskList ; | |
778 | fTaskInType = inputType ; | |
779 | fTaskOuType = outputType ; | |
780 | } |