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