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