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