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