]>
Commit | Line | Data |
---|---|---|
d4067772 | 1 | // |
2 | // Example macro to run a full resonance analysis task in a local machine | |
3 | // using data taken from AliEn. This macro can be used as a template to create | |
4 | // an AliEn job which runs this analysis on a collection of source data files (ESD/AOD/MC). | |
5 | // | |
6 | // This macro does the following: | |
7 | // - loads all required PAR libraries | |
8 | // - creates a TChain of events to be analyzed (from an XML collection) | |
9 | // - creates the AnalysisTask macro which does the job | |
10 | // | |
11 | // Since it is possible that all required libraries/macroes are stored in different | |
12 | // directories, for each one a variable must be initialized which gives the path, | |
13 | // but, in order to allow to explode (if necessary) some environment variables, | |
14 | // these variables are NOT arguments, but they are hard-coded in the macro at its | |
15 | // beginning, to allow a user to customize them. | |
16 | // | |
17 | // Arguments: | |
18 | // - name of XM collection for source files | |
19 | // - a flag to know it source data is ESD or AOD | |
20 | // - maximum number of files to be analyzed | |
21 | // - the number of files to be skipped starting from first one in collection. | |
22 | // | |
23 | Bool_t AliRsnTaskAlien | |
24 | ( | |
25 | const char *collectionFile = "wn.xml", | |
26 | Bool_t useESDsource = kTRUE, | |
27 | Int_t maxFiles = 1, | |
28 | Int_t skipFiles = 0 | |
29 | ) | |
30 | { | |
31 | // path for the "AliRsnLoad.C" macro which loads all libraries | |
32 | TString strLoadPath(Form("%s/PWG2/RESONANCES/macros", getenv("ALICE_ROOT"))); | |
33 | strLoadPath.Append("/AliRsnLoad.C"); | |
34 | ||
35 | // path for the "CreateAnalysisManager.C" macro which creates the AnalysisManager | |
36 | TString strTaskPath(Form("%s/PWG2/RESONANCES/macros", getenv("ALICE_ROOT"))); | |
37 | strTaskPath.Append("/CreateAnalysisManager.C"); | |
38 | ||
39 | // connect to grid | |
40 | TGrid::Connect("alien://"); | |
41 | ||
42 | // load the macro for uploading packages; | |
43 | // the unique assumption which must be done here is that the PAR libraries | |
44 | // are in the working directory, which is the case in all kinds of analysis | |
45 | gROOT->LoadMacro(strLoadPath.Data()); | |
46 | AliRsnLoad(); | |
47 | ||
48 | // create the TChain of files to read | |
49 | // its name depends on the kind of source to be read | |
50 | char treeName[200]; | |
51 | if (useESDsource) { | |
52 | sprintf(treeName, "esdTree"); | |
53 | Info("AliRsnSimpleTaskAlien", "Using ESD source data"); | |
54 | } | |
55 | else { | |
56 | sprintf(treeName, "aodTree"); | |
57 | Info("AliRsnSimpleTaskAlien", "Using AOD source data"); | |
58 | } | |
59 | TChain* analysisChain = new TChain(treeName); | |
60 | TAlienCollection *myCollection = TAlienCollection::Open(collectionFile); | |
61 | if (!myCollection) { | |
62 | Error("AliRsnSimpleTaskAlien", Form("Cannot create an AliEn collection from %s", collectionFile)); | |
63 | return kFALSE; | |
64 | } | |
65 | // add files to the TChain, keeping trace of their number with a counter | |
66 | Int_t nfiles = 0; | |
67 | char fileName[255]; | |
68 | myCollection->Reset(); | |
69 | while (myCollection->Next()) { | |
70 | if (skipFiles) { | |
71 | skipFiles--; | |
72 | continue; | |
73 | } | |
74 | sprintf(fileName, "%s", myCollection->GetTURL("")); | |
75 | Info("AliRsnSimpleTaskAlien", Form("Adding file '%s'", fileName)); | |
76 | analysisChain->Add(fileName); | |
77 | nfiles++; | |
78 | if (maxFiles > 0 && nfiles >= maxFiles) break; | |
79 | } | |
80 | Info("AliRsnSimpleTaskAlien", Form("# processed events = %d", (Int_t)analysisChain->GetEntries())); | |
81 | ||
82 | // load and execute the macro which creates the AnalysisManager | |
83 | // this macro is expected to define a function with the standard name | |
84 | // *** "CreateAnalysisManager()" *** [without arguments], | |
85 | // irrespectively of the filename of the macro itself, | |
86 | // which returns an AliAnalysisManager object | |
87 | gROOT->LoadMacro(strTaskPath.Data()); | |
88 | AliAnalysisManager *mgr = CreateAnalysisManager(kFALSE); | |
89 | ||
90 | // initialize analysis and run it in "local" mode | |
91 | if (mgr->InitAnalysis()) { | |
92 | mgr->PrintStatus(); | |
93 | return mgr->StartAnalysis("local", analysisChain); | |
94 | } | |
95 | return kTRUE; | |
96 | } |