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