]>
Commit | Line | Data |
---|---|---|
c6e7c68c | 1 | //===================== ANALYSIS TRAIN ========================================== |
2 | // To use: copy this macro to your work directory, modify the global part to match | |
3 | // your needs, then run root. | |
4 | // root[0] .L AnalysisTrain.C | |
5 | // Grid full mode as below (other modes: test, offline, submit, terminate) | |
6 | // root[1] AnalysisTrainNew("grid", "full") | |
7 | // CAF mode (requires root v5-23-02 + aliroot v4-16-Rev08) | |
8 | // root[2] AnalysisTrainNew("proof") | |
9 | // Local mode requires AliESds.root or AliAOD.root in the work directory | |
10 | // root[3] AnalysisTrainNew("local") | |
11 | ||
12 | const char *root_version = "v5-23-02"; | |
13 | const char *aliroot_version = "v4-16-Rev-08"; | |
14 | const char *cluster = "alicecaf.cern.ch"; | |
15 | //const char *AFversion = "AF-v4-16"; | |
16 | const char *AFversion = ""; | |
17 | // Dataset name. If empty assumes local ESD/AOD. In CAF it is a dataset name. | |
18 | // In grid has to point to an xml file or be empty if using the plugin | |
19 | // === PROOF | |
20 | const char *proof_dataset = "/COMMON/COMMON/LHC09a4_run8100X#/esdTree"; | |
21 | ||
22 | // === ALIEN | |
23 | const char *dataset = ""; | |
24 | const char *alien_datadir = "/alice/sim/PDC_09/LHC09a4/"; | |
25 | Int_t run_numbers[10] = {81071, 0, 0, 0, 0, | |
26 | 0, 0, 0, 0, 0}; | |
27 | ||
28 | Bool_t useDBG = kTRUE; | |
29 | Bool_t useMC = kFALSE; | |
30 | Bool_t usePAR = kTRUE; | |
31 | Bool_t useTR = kFALSE; | |
32 | Bool_t usePLUGIN = kTRUE; | |
33 | Bool_t useCORRFW = kFALSE; // do not change | |
34 | ||
35 | Int_t iAODanalysis = 0; | |
36 | Int_t iAODhandler = 1; | |
37 | Int_t iESDfilter = 1; | |
38 | Int_t iMUONfilter = 0; | |
39 | Int_t iMUONcopyAOD = 0; | |
40 | Int_t iJETAN = 1; | |
41 | Int_t iPWG4partcorr = 1; | |
42 | Int_t iPWG4pi0 = 1; | |
43 | Int_t iPWG3vertexing = 0; | |
44 | Int_t iPWG2femto = 0; | |
45 | Int_t iPWG2spectra = 1; | |
46 | Int_t iPWG2flow = 0; | |
47 | Int_t iPWG2res = 0; | |
48 | ||
49 | TString anaPars = ""; | |
50 | TString anaLibs = ""; | |
51 | // Function signatures | |
52 | class AliAnalysisGrid; | |
53 | ||
54 | //______________________________________________________________________________ | |
55 | void AnalysisTrainNew(const char *analysis_mode="grid", const char *plugin_mode="test") | |
56 | { | |
57 | // Example of running analysis train | |
58 | TString smode(analysis_mode); | |
59 | smode.ToUpper(); | |
60 | // Check compatibility of selected modules | |
61 | CheckModuleFlags(smode); | |
62 | ||
63 | printf("==================================================================\n"); | |
64 | printf("=========== RUNNING ANALYSIS TRAIN IN %s MODE ==========\n", smode.Data()); | |
65 | printf("==================================================================\n"); | |
66 | printf("= Configuring analysis train for: =\n"); | |
67 | if (iAODanalysis) printf("= AOD analysis =\n"); | |
68 | else printf("= ESD analysis =\n"); | |
69 | if (iESDfilter) printf("= ESD filter =\n"); | |
70 | if (iMUONfilter) printf("= MUON filter =\n"); | |
71 | if (iMUONcopyAOD) printf("= MUON copy AOD =\n"); | |
72 | if (iJETAN) printf("= Jet analysis =\n"); | |
f0e8e44e | 73 | if (iPWG2spectra) printf("= PWG2 proton, checkCascade, checkV0, strange =\n"); |
c6e7c68c | 74 | if (iPWG2femto) printf("= PWG2 femtoscopy =\n"); |
75 | if (iPWG2flow) printf("= PWG2 flow =\n"); | |
76 | if (iPWG2res) printf("= PWG2 resonances =\n"); | |
77 | if (iPWG3vertexing) printf("= PWG3 vertexing =\n"); | |
78 | if (iPWG4partcorr) printf("= PWG4 gamma-hadron correlations =\n"); | |
79 | if (iPWG4pi0) printf("= PWG4 pi0 analysis =\n"); | |
80 | printf("==================================================================\n"); | |
81 | printf(":: use MC truth %d\n", (UInt_t)useMC); | |
82 | printf(":: use track refs %d\n", (UInt_t)useTR); | |
83 | printf(":: use debugging %d\n", (UInt_t)useDBG); | |
84 | printf(":: use PAR files %d\n", (UInt_t)usePAR); | |
85 | printf(":: use AliEn plugin %d\n", (UInt_t)usePLUGIN); | |
86 | ||
87 | // Connect to back-end system | |
88 | if (!Connect(smode)) { | |
89 | ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode); | |
90 | return; | |
91 | } | |
92 | ||
93 | // Load common libraries and set include path | |
94 | if (!LoadCommonLibraries(smode)) { | |
95 | ::Error("AnalysisTrain", "Could not load common libraries"); | |
96 | return; | |
97 | } | |
98 | ||
99 | // Load analysis specific libraries | |
100 | if (!LoadAnalysisLibraries(smode)) { | |
101 | ::Error("AnalysisTrain", "Could not load analysis libraries"); | |
102 | return; | |
103 | } | |
104 | ||
105 | ||
106 | //========================================================================== | |
107 | // Make the analysis manager and connect event handlers | |
108 | AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train", "Production train"); | |
109 | ||
110 | // Create input handler (input container created automatically) | |
111 | if (iAODanalysis) { | |
112 | // AOD input handler | |
113 | AliAODInputHandler *aodH = new AliAODInputHandler(); | |
114 | mgr->SetInputEventHandler(aodH); | |
115 | } else { | |
116 | // ESD input handler | |
117 | AliESDInputHandler *esdHandler = new AliESDInputHandler(); | |
118 | mgr->SetInputEventHandler(esdHandler); | |
119 | } | |
120 | // Monte Carlo handler | |
121 | if (useMC && !iAODanalysis) { | |
122 | AliMCEventHandler* mcHandler = new AliMCEventHandler(); | |
123 | mgr->SetMCtruthEventHandler(mcHandler); | |
124 | mcHandler->SetReadTR(useTR); | |
125 | } | |
126 | // AOD output container, created automatically when setting an AOD handler | |
127 | if (iAODhandler) { | |
128 | // AOD output handler | |
129 | AliAODHandler* aodHandler = new AliAODHandler(); | |
130 | mgr->SetOutputEventHandler(aodHandler); | |
131 | aodHandler->SetOutputFileName("AliAOD.root"); | |
132 | } | |
133 | // Debugging if needed | |
134 | if (useDBG) mgr->SetDebugLevel(3); | |
135 | ||
136 | //========================================================================== | |
137 | // Create the chain. In this example it is created only from ALIEN files but | |
138 | // can be done to work in batch or grid mode as well. | |
139 | TChain *chain = CreateChain(smode, plugin_mode); | |
140 | ||
141 | //========================================================================== | |
142 | // Load the tasks configuration macros for all wagons. These files are supposed now to be | |
143 | // in the current workdir, but in AliEn they will be in the file catalog, | |
144 | // mapped from AliRoot and pecified in the jdl input list. | |
145 | ||
146 | // For now connection to top input container and common AOD output container | |
147 | // is done in this macro, but in future these containers will be connected | |
148 | // from each task configuration macro. | |
149 | ||
150 | if (iESDfilter && !iAODanalysis) { | |
151 | // ESD filter task configuration. | |
152 | gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C"); | |
153 | AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(); | |
154 | } | |
155 | ||
156 | // Muon filter | |
157 | if (iMUONfilter && !iAODanalysis) { | |
158 | // There is no configuration from outside for this task yet. | |
159 | AliAnalysisTaskESDMuonFilter *taskesdmuonfilter = new AliAnalysisTaskESDMuonFilter("ESD Muon Filter"); | |
160 | mgr->AddTask(taskesdmuonfilter); | |
161 | // Connect to data containers | |
162 | mgr->ConnectInput (taskesdmuonfilter, 0, mgr->GetCommonInputContainer()); | |
163 | } | |
164 | ||
165 | // Jet analysis | |
166 | if (iJETAN) { | |
167 | gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C"); | |
168 | AliAnalysisTaskJets *taskjets = AddTaskJets("ESD", "UA1"); | |
169 | } | |
170 | ||
171 | // Proton analysis | |
172 | if (iPWG2spectra) { | |
f0e8e44e | 173 | // protons |
c6e7c68c | 174 | gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskProtons.C"); |
175 | AliAnalysisTaskProtons *taskprotons = AddTaskProtons(); | |
f0e8e44e | 176 | // cascades |
177 | gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCheckCascade.C"); | |
178 | AliAnalysisTaskCheckCascade *taskcheckcascade = AddTaskCheckCascade(); | |
c6e7c68c | 179 | } |
180 | ||
181 | // PWG4 hadron correlations | |
182 | if (iPWG4partcorr) { | |
183 | gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskGammaHadronCorr.C"); | |
184 | AliAnalysisTaskParticleCorrelation *taskgammahadron = AddTaskGammaHadronCorr(); | |
185 | } | |
186 | ||
187 | // PWG4 pi0 | |
188 | if (iPWG4pi0) { | |
189 | gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPi0.C"); | |
190 | AliAnalysisTaskParticleCorrelation *taskpi0 = AddTaskPi0(); | |
191 | } | |
192 | ||
193 | //========================================================================== | |
194 | // FOR THE REST OF THE TASKS THE MACRO AddTaskXXX() is not yet implemented/ | |
195 | // Run the analysis | |
196 | // | |
197 | if (mgr->InitAnalysis()) { | |
198 | mgr->PrintStatus(); | |
199 | StartAnalysis(smode, chain); | |
200 | } | |
201 | } | |
202 | ||
203 | //______________________________________________________________________________ | |
204 | void StartAnalysis(const char *mode, TChain *chain) { | |
205 | // Start analysis. | |
206 | Int_t imode = -1; | |
207 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
208 | if (!strcmp(mode, "LOCAL")) imode = 0; | |
209 | if (!strcmp(mode, "PROOF")) imode = 1; | |
210 | if (!strcmp(mode, "GRID")) imode = 2; | |
211 | switch (imode) { | |
212 | case 0: | |
213 | if (!chain) { | |
214 | ::Error("StartAnalysis", "Cannot create the chain"); | |
215 | return; | |
216 | } | |
217 | mgr->StartAnalysis(mode, chain); | |
218 | return; | |
219 | case 1: | |
220 | if (!strlen(proof_dataset)) { | |
221 | ::Error("StartAnalysis", "proof_dataset is empty"); | |
222 | return; | |
223 | } | |
224 | mgr->StartAnalysis(mode, proof_dataset, 1000); | |
225 | return; | |
226 | case 2: | |
227 | if (usePLUGIN) { | |
228 | if (!mgr->GetGridHandler()) { | |
229 | ::Error("StartAnalysis", "Grid plugin not initialized"); | |
230 | return; | |
231 | } | |
232 | mgr->StartAnalysis("grid"); | |
233 | } else { | |
234 | if (!chain) { | |
235 | ::Error("StartAnalysis", "Cannot create the chain"); | |
236 | return; | |
237 | } | |
238 | mgr->StartAnalysis(mode, chain); | |
239 | } | |
240 | return; | |
241 | } | |
242 | } | |
243 | ||
244 | //______________________________________________________________________________ | |
245 | void CheckModuleFlags(const char *mode) { | |
246 | // Checks selected modules and insure compatibility | |
247 | Int_t imode = -1; | |
248 | if (!strcmp(mode, "LOCAL")) imode = 0; | |
249 | if (!strcmp(mode, "PROOF")) imode = 1; | |
250 | if (!strcmp(mode, "GRID")) imode = 2; | |
251 | if (imode==1) { | |
252 | usePAR = kTRUE; | |
253 | } | |
254 | if (iAODanalysis) { | |
255 | // AOD analysis | |
256 | useMC = kFALSE; | |
257 | useTR = kFALSE; | |
258 | iESDfilter = 0; | |
259 | iMUONfilter = 0; | |
260 | // Disable tasks that do not work yet on AOD data | |
261 | } else { | |
262 | // ESD analysis | |
263 | iMUONcopyAOD = 0; | |
264 | iPWG3vertexing = 0; | |
265 | } | |
266 | if (iMUONfilter || iJETAN) iESDfilter=1; | |
267 | if (iESDfilter) iAODhandler=1; | |
268 | if (iAODanalysis || !iAODhandler) { | |
269 | iPWG4partcorr=0; | |
270 | iPWG4pi0=0; | |
271 | } | |
272 | if (iPWG2spectra || iPWG2flow) useCORRFW = kTRUE; | |
273 | } | |
274 | ||
275 | //______________________________________________________________________________ | |
276 | Bool_t Connect(const char *mode) { | |
277 | // Connect <username> to the back-end system. | |
278 | Int_t imode = -1; | |
279 | if (!strcmp(mode, "LOCAL")) imode = 0; | |
280 | if (!strcmp(mode, "PROOF")) imode = 1; | |
281 | if (!strcmp(mode, "GRID")) imode = 2; | |
282 | TString username = gSystem->Getenv("alien_API_USER"); | |
283 | switch (imode) { | |
284 | case 0: | |
285 | break; | |
286 | case 1: | |
287 | if (!username.Length()) { | |
288 | ::Error(Form("Connect <%s>", mode), "Make sure you:\n \ | |
289 | 1. Have called: alien-token-init <username>\n \ | |
290 | 2. Have called: >source /tmp/gclient_env_$UID"); | |
291 | return kFALSE; | |
292 | } | |
293 | ::Info("Connect", "Connecting user <%s> to PROOF cluster <%s>", | |
294 | username.Data(), cluster); | |
295 | TProof::Open(Form("%s@%s", username.Data(), cluster)); | |
296 | if (!gProof) { | |
297 | if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch")) | |
298 | ::Error(Form("Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch"); | |
299 | return kFALSE; | |
300 | } | |
301 | break; | |
302 | case 2: | |
303 | if (!username.Length()) { | |
304 | ::Error(Form("Connect <%s>", mode), "Make sure you:\n \ | |
305 | 1. Have called: alien-token-init <username>\n \ | |
306 | 2. Have called: >source /tmp/gclient_env_$UID"); | |
307 | return kFALSE; | |
308 | } | |
309 | if (usePLUGIN && !gSystem->Getenv("alien_CLOSE_SE")) { | |
310 | ::Error(Form("Connect <%s>", mode), | |
311 | "When using the AliEn plugin it is preferable to define the \ | |
312 | variable alien_CLOSE_SE in your environment."); | |
313 | return kFALSE; | |
314 | } | |
315 | ::Info("Connect", "Connecting user <%s> to AliEn ...", | |
316 | username.Data()); | |
317 | TGrid::Connect("alien://"); | |
318 | if (!gGrid || !gGrid->IsConnected()) return kFALSE; | |
319 | break; | |
320 | default: | |
321 | ::Error("Connect", "Unknown run mode: %s", mode); | |
322 | return kFALSE; | |
323 | } | |
324 | ::Info("Connect","Connected in %s mode", mode); | |
325 | return kTRUE; | |
326 | } | |
327 | ||
328 | //______________________________________________________________________________ | |
329 | Bool_t LoadCommonLibraries(const char *mode) | |
330 | { | |
331 | // Load common analysis libraries. | |
332 | Int_t imode = -1; | |
333 | if (!strcmp(mode, "LOCAL")) imode = 0; | |
334 | if (!strcmp(mode, "PROOF")) imode = 1; | |
335 | if (!strcmp(mode, "GRID")) imode = 2; | |
336 | if (!gSystem->Getenv("ALICE_ROOT")) { | |
337 | ::Error("LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot"); | |
338 | return kFALSE; | |
339 | } | |
340 | Bool_t success = kTRUE; | |
341 | // ROOT libraries | |
342 | gSystem->Load("libTree.so"); | |
343 | gSystem->Load("libGeom.so"); | |
344 | gSystem->Load("libVMC.so"); | |
345 | gSystem->Load("libPhysics.so"); | |
346 | ||
347 | // Load framework classes. Par option ignored here. | |
348 | switch (imode) { | |
349 | case 0: | |
350 | case 2: | |
351 | success &= LoadLibrary("libSTEERBase.so", mode); | |
352 | success &= LoadLibrary("libESD.so", mode); | |
353 | success &= LoadLibrary("libAOD.so", mode); | |
354 | success &= LoadLibrary("libANALYSIS.so", mode); | |
355 | success &= LoadLibrary("libANALYSISalice.so", mode); | |
356 | if (useCORRFW) success &= LoadLibrary("libCORRFW.so", mode); | |
357 | gROOT->ProcessLine(".include $ALICE_ROOT/include"); | |
358 | break; | |
359 | case 1: | |
360 | Int_t ires = -1; | |
361 | if (!gSystem->AccessPathName(AFversion)) ires = gProof->UploadPackage(AFversion); | |
362 | if (ires < 0) { | |
363 | success &= LoadLibrary("STEERBase", mode); | |
364 | success &= LoadLibrary("ESD", mode); | |
365 | success &= LoadLibrary("AOD", mode); | |
366 | success &= LoadLibrary("ANALYSIS", mode); | |
367 | success &= LoadLibrary("ANALYSISalice", mode); | |
368 | if (useCORRFW) success &= LoadLibrary("CORRFW", mode); | |
369 | } else { | |
370 | ires = gProof->EnablePackage(AFversion); | |
371 | if (useCORRFW) success &= LoadLibrary("CORRFW", mode); | |
372 | } | |
373 | if (ires<0) success = kFALSE; | |
374 | break; | |
375 | default: | |
376 | ::Error("LoadCommonLibraries", "Unknown run mode: %s", mode); | |
377 | return kFALSE; | |
378 | } | |
379 | if (success) { | |
380 | ::Info("LoadCommodLibraries", "Load common libraries: SUCCESS"); | |
381 | ::Info("LoadCommodLibraries", "Include path for Aclic compilation:\n%s", | |
382 | gSystem->GetIncludePath()); | |
383 | } else { | |
384 | ::Info("LoadCommodLibraries", "Load common libraries: FAILED"); | |
385 | } | |
386 | ||
387 | return success; | |
388 | } | |
389 | ||
390 | //______________________________________________________________________________ | |
391 | Bool_t LoadAnalysisLibraries(const char *mode) | |
392 | { | |
393 | // Load common analysis libraries. | |
394 | Bool_t success = kTRUE; | |
395 | if (iMUONfilter) { | |
396 | if (!LoadLibrary("PWG3base", mode, kTRUE) || | |
397 | !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE; | |
398 | } | |
399 | // JETAN | |
400 | if (iJETAN) { | |
401 | if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE; | |
402 | } | |
403 | ||
404 | // PWG4 particle correlations | |
405 | if (iPWG4partcorr || iPWG4pi0) { | |
406 | if (!LoadLibrary("PWG4PartCorrBase", mode, kTRUE) || | |
407 | !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE; | |
408 | TFile::Cp(gSystem->ExpandPathName("$(ALICE_ROOT)/PWG4/macros/ConfigAnalysisGammaHadronCorrelation.C"), "ConfigAnalysisGammaHadronCorrelation.C"); | |
409 | TFile::Cp(gSystem->ExpandPathName("$(ALICE_ROOT)/PWG4/macros/ConfigAnalysisPi0.C"), "ConfigAnalysisPi0.C"); | |
410 | } | |
411 | // PWG2 task protons | |
412 | if (iPWG2spectra) { | |
413 | if (!LoadLibrary("PWG2spectra", mode, kTRUE)) return kFALSE; | |
414 | } | |
415 | // PWG2 flow | |
416 | if (iPWG2flow) { | |
417 | if (!LoadLibrary("PWG2AOD", mode, kTRUE) || | |
418 | !LoadLibrary("PWG2flow", mode, kTRUE)) return kFALSE; | |
419 | } | |
420 | // PWG2 resonances | |
421 | if (iPWG2res) { | |
422 | if (!LoadLibrary("PWG2resonances", mode, kTRUE)) return kFALSE; | |
423 | } | |
424 | // PWG2 femtoscopy | |
425 | if (iPWG2femto) { | |
426 | if (!LoadLibrary("PWG2AOD", mode, kTRUE) || | |
427 | !LoadLibrary("PWG2femtoscopy", mode, kTRUE) || | |
428 | !LoadLibrary("PWG2femtoscopyUser", mode, kTRUE)) return kFALSE; | |
429 | } | |
430 | // Vertexing HF | |
431 | if (iPWG3vertexing) { | |
432 | if (!LoadLibrary("PWG3vertexingHF", mode, kTRUE)) return kFALSE; | |
433 | } | |
434 | ::Info("LoadAnalysisLibraries", "Load other libraries: SUCCESS"); | |
435 | return kTRUE; | |
436 | } | |
437 | ||
438 | //______________________________________________________________________________ | |
439 | Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE) | |
440 | { | |
441 | // Load a module library in a given mode. Reports success. | |
442 | Int_t imode = -1; | |
443 | Int_t result; | |
444 | TString smodule(module); | |
445 | if (!strcmp(mode, "LOCAL")) imode = 0; | |
446 | if (!strcmp(mode, "PROOF")) imode = 1; | |
447 | if (!strcmp(mode, "GRID")) imode = 2; | |
448 | TString mod(module); | |
449 | if (!mod.Length()) { | |
450 | ::Error("LoadLibrary", "Empty module name"); | |
451 | return kFALSE; | |
452 | } | |
453 | // If a library is specified, just load it | |
454 | if (smodule.EndsWith(".so")) { | |
455 | mod.Remove(mod.Index(".so")); | |
456 | result = gSystem->Load(mod); | |
457 | if (result < 0) { | |
458 | ::Error("LoadLibrary", "Could not load library %s", module); | |
459 | return kFALSE; | |
460 | } | |
461 | if (rec) anaLibs += Form("%s.so ",mod.Data()); | |
462 | return kTRUE; | |
463 | } | |
464 | // Check if the library is already loaded | |
465 | if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0) | |
466 | return kTRUE; | |
467 | switch (imode) { | |
468 | case 0: | |
469 | case 2: | |
470 | if (usePAR) { | |
471 | result = SetupPar(module); | |
472 | if (rec) anaPars += Form("%s.par ", module); | |
473 | } else { | |
474 | result = gSystem->Load(Form("lib%s.so", module)); | |
475 | if (rec) anaLibs += Form("lib%s.so ", module); | |
476 | } | |
477 | break; | |
478 | case 1: | |
479 | result = gProof->UploadPackage(module); | |
480 | if (result<0) { | |
481 | result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module))); | |
482 | if (result<0) { | |
483 | ::Error("LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module); | |
484 | return kFALSE; | |
485 | } | |
486 | } | |
487 | result = gProof->EnablePackage(module); | |
488 | break; | |
489 | default: | |
490 | return kFALSE; | |
491 | } | |
492 | if (result < 0) { | |
493 | ::Error("LoadLibrary", "Could not load module %s", module); | |
494 | return kFALSE; | |
495 | } | |
496 | return kTRUE; | |
497 | } | |
498 | ||
499 | ||
500 | //______________________________________________________________________________ | |
501 | TChain *CreateChain(const char *mode, const char *plugin_mode) | |
502 | { | |
503 | // Create the input chain | |
504 | Int_t imode = -1; | |
505 | if (!strcmp(mode, "LOCAL")) imode = 0; | |
506 | if (!strcmp(mode, "PROOF")) imode = 1; | |
507 | if (!strcmp(mode, "GRID")) imode = 2; | |
508 | TChain *chain = NULL; | |
509 | // Local chain | |
510 | switch (imode) { | |
511 | case 0: | |
512 | if (iAODanalysis) { | |
513 | if (!strlen(dataset)) { | |
514 | // Local AOD | |
515 | chain = new TChain("aodTree"); | |
516 | if (gSystem->AccessPathName("AliAOD.root")) | |
517 | ::Error("CreateChain", "File: AliAOD.root not in current dir"); | |
518 | else chain->Add("AliAOD.root"); | |
519 | } else { | |
520 | // Interactive AOD | |
521 | chain = CreateChainSingle(dataset, "aodTree"); | |
522 | } | |
523 | } else { | |
524 | if (!strlen(dataset)) { | |
525 | // Local ESD | |
526 | chain = new TChain("esdTree"); | |
527 | if (gSystem->AccessPathName("AliESDs.root")) | |
528 | ::Error("CreateChain", "File: AliESDs.root not in current dir"); | |
529 | else chain->Add("AliESDs.root"); | |
530 | } else { | |
531 | // Interactive ESD | |
532 | chain = CreateChainSingle(dataset, "esdTree"); | |
533 | } | |
534 | } | |
535 | break; | |
536 | case 1: | |
537 | break; | |
538 | case 2: | |
539 | if (usePLUGIN) { | |
540 | AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode); | |
541 | AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler); | |
542 | } else { | |
543 | TString treeName = "esdTree"; | |
544 | if (iAODanalysis) treeName = "aodTree"; | |
545 | chain = CreateChainSingle("wn.xml", treeName); | |
546 | } | |
547 | break; | |
548 | default: | |
549 | } | |
550 | if (chain && chain->GetNtrees()) return chain; | |
551 | return NULL; | |
552 | } | |
553 | ||
554 | //______________________________________________________________________________ | |
555 | TChain* CreateChainSingle(const char* xmlfile, const char *treeName) | |
556 | { | |
557 | printf("*******************************\n"); | |
558 | printf("*** Getting the ESD Chain ***\n"); | |
559 | printf("*******************************\n"); | |
560 | TAlienCollection * myCollection = TAlienCollection::Open(xmlfile); | |
561 | ||
562 | if (!myCollection) { | |
563 | ::Error("CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ; | |
564 | return NULL ; | |
565 | } | |
566 | ||
567 | TChain* chain = new TChain(treeName); | |
568 | myCollection->Reset() ; | |
569 | while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ; | |
570 | chain->ls(); | |
571 | return chain; | |
572 | } | |
573 | ||
574 | //______________________________________________________________________________ | |
575 | Int_t SetupPar(char* pararchivename) | |
576 | { | |
577 | if (!pararchivename || !strlen(pararchivename)) return -1; | |
578 | char processline[1024]; | |
579 | if (gSystem->AccessPathName(Form("%s.par", pararchivename))) { | |
580 | if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) { | |
581 | ::Info("SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename); | |
582 | TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)), | |
583 | Form("%s.par",pararchivename)); | |
584 | } else { | |
585 | ::Error("SetupPar", "Cannot find %s.par", pararchivename); | |
586 | return -1; | |
587 | } | |
588 | } | |
589 | gSystem->Exec(Form("tar xvzf %s.par", pararchivename)); | |
590 | ||
591 | TString ocwd = gSystem->WorkingDirectory(); | |
592 | if (!gSystem->ChangeDirectory(pararchivename)) return -1; | |
593 | ||
594 | // check for BUILD.sh and execute | |
595 | if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) { | |
596 | printf("*******************************\n"); | |
597 | printf("*** Building PAR archive ***\n"); | |
598 | printf("*******************************\n"); | |
599 | if (gSystem->Exec("PROOF-INF/BUILD.sh")) { | |
600 | Error("runProcess","Cannot Build the PAR Archive! - Abort!"); | |
601 | return -1; | |
602 | } | |
603 | } | |
604 | ||
605 | // check for SETUP.C and execute | |
606 | if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) { | |
607 | printf("*******************************\n"); | |
608 | printf("*** Setup PAR archive ***\n"); | |
609 | printf("*******************************\n"); | |
610 | gROOT->Macro("PROOF-INF/SETUP.C"); | |
611 | } | |
612 | if (!gSystem->ChangeDirectory(ocwd.Data())) return -1; | |
613 | return 0; | |
614 | } | |
615 | ||
616 | //______________________________________________________________________________ | |
617 | AliAnalysisGrid* CreateAlienHandler(const char *plugin_mode) | |
618 | { | |
619 | // Check if user has a valid token, otherwise make one. This has limitations. | |
620 | // One can always follow the standard procedure of calling alien-token-init then | |
621 | // source /tmp/gclient_env_$UID in the current shell. | |
622 | if (!AliAnalysisGrid::CreateToken()) return NULL; | |
623 | AliAnalysisAlien *plugin = new AliAnalysisAlien(); | |
624 | // Set the run mode (can be "full", "test", "offline", "submit" or "terminate") | |
625 | plugin->SetRunMode(plugin_mode); | |
626 | plugin->SetNtestFiles(1); | |
627 | plugin->SetPreferedSE("ALICE::NIHAM::FILE"); | |
628 | // Set versions of used packages | |
629 | plugin->SetAPIVersion("V2.4"); | |
630 | plugin->SetROOTVersion(root_version); | |
631 | plugin->SetAliROOTVersion(aliroot_version); | |
632 | // Declare input data to be processed. | |
633 | // Method 1: Create automatically XML collections using alien 'find' command. | |
634 | // Define production directory LFN | |
635 | plugin->SetGridDataDir(alien_datadir); | |
636 | // Set data search pattern | |
637 | plugin->SetDataPattern("*ESDs.root"); | |
638 | // ...then add run numbers to be considered | |
639 | for (Int_t i=0; i<10; i++) { | |
640 | if (run_numbers[i]==0) break; | |
641 | plugin->AddRunNumber(run_numbers[i]); | |
642 | } | |
643 | // Method 2: Declare existing data files (raw collections, xml collections, root file) | |
644 | // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir()) | |
645 | // XML collections added via this method can be combined with the first method if | |
646 | // the content is compatible (using or not tags) | |
647 | // plugin->AddDataFile("tag.xml"); | |
648 | // plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root"); | |
649 | // Define alien work directory where all files will be copied. Relative to alien $HOME. | |
650 | plugin->SetGridWorkingDir("analysisESD"); | |
651 | // Declare alien output directory. Relative to working directory. | |
652 | plugin->SetGridOutputDir("output"); // In this case will be $HOME/work/output | |
653 | ||
654 | TString ana_sources = ""; | |
655 | TString ana_add = ""; | |
656 | if (usePAR && anaPars.Length()) { | |
657 | TObjArray *arr; | |
658 | TObjString *objstr; | |
659 | arr = anaPars.Tokenize(" "); | |
660 | TIter next(arr); | |
661 | while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString()); | |
662 | delete arr; | |
663 | } | |
664 | ||
665 | // Declare the analysis source files names separated by blancs. To be compiled runtime | |
666 | // using ACLiC on the worker nodes. | |
667 | ana_sources = ana_sources.Strip(); | |
668 | // Declare all libraries (other than the default ones for the framework. These will be | |
669 | // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here. | |
670 | anaLibs = anaLibs.Strip(); | |
671 | if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources); | |
672 | if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs); | |
673 | ||
674 | // Declare the output file names separated by blancs. | |
675 | // (can be like: file.root or file.root@ALICE::Niham::File) | |
676 | plugin->SetDefaultOutputs(); | |
677 | plugin->SetMergeExcludes("AliAOD.root"); | |
678 | // plugin->SetOutputFiles("AliAOD.root"); | |
679 | // Optionally define the files to be archived. | |
680 | // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:*.root@ALICE::NIHAM::File"); | |
681 | plugin->SetOutputArchive("log_archive.zip:stdout,stderr"); | |
682 | // Optionally set a name for the generated analysis macro (default MyAnalysis.C) | |
683 | plugin->SetAnalysisMacro("testAnalysis.C"); | |
684 | // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore) | |
685 | plugin->SetSplitMaxInputFileNumber(50); | |
686 | // Optionally set number of failed jobs that will trigger killing waiting sub-jobs. | |
687 | // plugin->SetMaxInitFailed(5); | |
688 | // Optionally resubmit threshold. | |
689 | // plugin->SetMasterResubmitThreshold(90); | |
690 | // Optionally set time to live (default 30000 sec) | |
691 | plugin->SetTTL(30000); | |
692 | // Optionally set input format (default xml-single) | |
693 | plugin->SetInputFormat("xml-single"); | |
694 | // Optionally modify the name of the generated JDL (default analysis.jdl) | |
695 | plugin->SetJDLName("testAnalysis.jdl"); | |
696 | // Optionally modify job price (default 1) | |
697 | plugin->SetPrice(1); | |
698 | // Optionally modify split mode (default 'se') | |
699 | plugin->SetSplitMode("se"); | |
700 | return plugin; | |
701 | } |