]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/macros/test/runAlienPlugin.C
Removed AliRsnEvent data member from streaming in AliRsnPair - modified test macros
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / macros / test / runAlienPlugin.C
1 //
2 // This is an example steering macro for running RSN analysis task
3 // with the AliEn plugin to launch a multiple analysis.
4 //
5 // Inputs:
6 //   - runList     = list of runs to be processed
7 //   - runPath     = path containing the runs
8 //   - runMode     = AliEn plugin run mode
9 //   - pluginMacro = macro which loads and initializes the plugin
10 //   - addTaskName = name of the macro to add the RSN analysis task
11 //                   (assumed to have inside it a function named like the file)
12 //   - inputSource = name of the file containing all the inputs
13 //                   ---> to run on a local collection, the collection file 
14 //                        must contain on each line the full path 
15 //                        of one input file and it must have the ".txt" extension
16 //                   ---> to run on an AliEn collection, the collection file must be an XML
17 //                        file collection like those built from the "find -x" method in aliensh.
18 //   - dataLabel   = a label which is used to know what kind of data are being read
19 //                   (it is propagated to the 'addTask' macro for eventual setting up of something
20 //   - outName     = name for the file with RSN package outputs (without ROOT extension)
21 //                   in this case it is fundamental to define the names of all plugin objects
22 //
23 // Notes:
24 //   - in case the source is an ESD, and if inputs are a MC production
25 //     the MC input handler is created by default
26 // 
27 //
28 // In principle, the user should never modify this macro. 
29 //
30 void runAlienPlugin
31 (
32   const char *runList     = "117112-117116-117099-117220-117048-117109-117060-117054-117065",
33   const char *runPath     = "/alice/data/2010/LHC10b",
34   const char *runMode     = "terminate",
35   const char *pluginMacro = "PluginDataByRun.C",
36   const char *addTaskName = "AddAnalysisTaskRsnTest.C",
37   const char *dataLabel   = "7TeV_pass2_data_ESD",
38   const char *outName     = "rsnTest"
39 )
40 {
41   
42   // convert the last argument into a BOOL variable
43   TString strDataLabel(dataLabel);
44   Bool_t isESD = strDataLabel.Contains("ESD");
45   Bool_t isAOD = strDataLabel.Contains("AOD");
46   Bool_t isSim = strDataLabel.Contains("sim");   
47   
48   //AliLog::SetGlobalDebugLevel(AliLog::kDebug+2);
49
50   // load compiled libraries (for aliroot session)
51   gSystem->Load("libANALYSIS.so");
52   gSystem->Load("libANALYSISalice.so");
53   gSystem->Load("libCORRFW.so");
54   gSystem->Load("libPWG2resonances.so");
55   
56   //
57   // === PLUGIN CONFIGURATION =====================================================================
58   //
59   
60   // check token
61   if (!AliAnalysisGrid::CreateToken()) return;
62   
63   // load and execute plugin configuration macro
64   // pass to the macro, as FIRST argument, the common name
65   // which is used for the output, since it must be equal
66   // to the one defined here for the common output (for merging)
67   TString splugin(pluginMacro);
68   gROOT->LoadMacro(pluginMacro);
69   splugin.ReplaceAll(".C", Form("(\"%s\",\"%s\",\"%s\")", outName, runList, runPath));
70   AliAnalysisAlien *plugin = (AliAnalysisAlien*)gROOT->ProcessLine(splugin);
71   
72   // set run mode
73   plugin->SetRunMode(runMode);
74   
75   //
76   // === ANALYSIS MANAGER CONFIGURATION ===========================================================
77   //
78
79   // create analysis manager
80   AliAnalysisManager *mgr = new AliAnalysisManager("taskRsnTest");
81   mgr->SetGridHandler(plugin);
82   mgr->SetCommonFileName(Form("%s.root", outName));
83   
84   // create input handler
85   if (isESD)
86   {
87     AliESDInputHandler *esdHandler = new AliESDInputHandler();
88     mgr->SetInputEventHandler(esdHandler);
89     // if possible, create also MC handler
90     if (isSim)
91     {
92       AliMCEventHandler *mcHandler  = new AliMCEventHandler();
93       mgr->SetMCtruthEventHandler(mcHandler);
94     }
95   }
96   else if (isAOD)
97   {
98     AliAODInputHandler *aodHandler = new AliAODInputHandler();
99     mgr->SetInputEventHandler(aodHandler);
100   }
101   else
102   {
103     ::Error("Required an ESD or AOD input data set");
104     return;
105   }
106   
107   //
108   // === ANALYSIS TASK CREATION AND INCLUSION =====================================================
109   //
110   
111   // add event selection for data
112   gROOT->LoadMacro("$(ALICE_ROOT)/ANALYSIS/macros/AddTaskPhysicsSelection.C");
113   AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(isSim);
114   
115   // add task macro
116   gROOT->ProcessLine(Form(".x %s(\"%s\")", addTaskName, dataLabel));
117
118   // initialize and start analysis
119   if (!mgr->InitAnalysis()) return;
120   mgr->PrintStatus();
121   mgr->StartAnalysis("grid");
122 }
123
124 //_________________________________________________________________________________________________
125 Bool_t LoadPars(const char *parList, const char *path)
126 {
127 //
128 // Load PAR libraries locally
129 // ---
130 // Arguments:
131 //  - parList = list of PARs without extension, separated by ':'
132 //  - path    = path where PARs are stored
133 //
134
135   // store position of working directory
136   TString ocwd = gSystem->WorkingDirectory();
137
138   // tokenize list
139   TString     pars(parList);
140   TObjArray  *array = pars.Tokenize(":");
141
142   // loop on list
143   TObjString *ostr;
144   TString     str;
145   Char_t      parName[200], parFile[200];
146   for (Int_t i = 0; i < array->GetEntriesFast(); i++)
147   {
148     ostr = (TObjString*) array->At(i);
149     str = ostr->GetString();
150     sprintf(parName, "%s", str.Data());
151     sprintf(parFile, "%s/%s.par", path, str.Data());
152
153     // check that file exists
154     if (!gSystem->AccessPathName(parFile))
155     {
156       // explode tar-ball and enter it
157       gROOT->ProcessLine(Form(".! tar xzf %s", parFile));
158       gSystem->ChangeDirectory(Form("%s", parName));
159       // checks for BUILD.sh and execute it
160       if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh"))
161       {
162         ::Info("", ">> Building PARs: %s", parName);
163         if (gSystem->Exec("PROOF-INF/BUILD.sh"))
164         {
165           ::Error("LoadPars", Form("BUILD.sh error for '%s'", parFile));
166           gSystem->ChangeDirectory(ocwd);
167           return kFALSE;
168         }
169       }
170       // check and execute SETUP.C
171       if (!gSystem->AccessPathName("PROOF-INF/SETUP.C"))
172       {
173         ::Info("", ">> Setting up PARs: %s", parName);
174         if (gROOT->Macro("PROOF-INF/SETUP.C"))
175         {
176           Error("LoadPars", Form("SETUP.C error for '%s'", parFile));
177           gSystem->ChangeDirectory(ocwd);
178           return kFALSE;
179         }
180       }
181     }
182     else
183     {
184       Error("LoadParsLocal", Form("File '%s' not found", parFile));
185       return kFALSE;
186     }
187   }
188
189   gSystem->ChangeDirectory(ocwd);
190   return kTRUE;
191 }