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