]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/centraltrain/AnalysisTrainPWG2.C
Coverity fixes
[u/mrichter/AliRoot.git] / PWG2 / centraltrain / AnalysisTrainPWG2.C
CommitLineData
a000cab6 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 ./data directory
10// root[3] AnalysisTrainNew("local")
11// In proof and grid modes, a token is needed and sourcing the produced environment file.
12//
13// If 'saveTrain' flag is set, the train will generate a directory name and run
14// in this directory. A configuration file 'ConfigTrain.C' will be generated.
15// One can replay at any time the train via:
16// root[1] AnalysisTrainNew(ana_mode, plugin_mode, "train_default_<date>/ConfigTrain.C")
17
18//================== TRAIN NAME ============================================
19TString train_name = "PWG2"; // local folder name
20TString train_tag = "_Pb-Pb_"; // Train special tag appended to
21 // visible name. ("data", "sim", "pp", "highmult", ...)
22 // Name in train page (DON'T CHANGE)
23TString visible_name = Form("PWG2%s$2_$3", train_tag.Data()); //# FIXED #
24 // Add train composition and other comments
25TString job_comment = "PWG2 tasks on ESDs";
26TString job_tag = Form("%s: %s", visible_name.Data(), job_comment.Data());
27//==============================================================================
28
29// ### Settings that make sense in PROOF only
30//==============================================================================
31TString proof_cluster = "alice-caf.cern.ch";
32Bool_t useAFPAR = kFALSE; // use AF special par file
33TString AFversion = "AF-v4-17";
34// Change CAF dataset here
35TString proof_dataset = "/COMMON/COMMON/LHC09a4_run8100X#/esdTree";
36TString proof_outdir = "";
37
38// ### Settings that make sense when using the Alien plugin
39//==============================================================================
40Int_t runOnData = 1; // Set to 1 if processing real data
41Int_t iCollision = 1; // 0=pp, 1=Pb-Pb
42Bool_t usePLUGIN = kTRUE; // do not change
43Bool_t useProductionMode = kTRUE; // use the plugin in production mode
44// Usage of par files ONLY in grid mode and ONLY if the code is not available
45// in the deployed AliRoot versions. Par file search path: local dir, if not there $ALICE_ROOT.
46// To refresh par files, remove the ones in the workdir, then do "make <target.par>" in
47// AliRoot.
48Bool_t usePAR = kFALSE; // use par files for extra libs
49Bool_t useCPAR = kFALSE; // use par files for common libs
50TString root_version = "v5-27-06c"; // *CHANGE ME IF MORE RECENT IN GRID*
51TString aliroot_version = "v4-21-15-AN"; // *CHANGE ME IF MORE RECENT IN GRID*
52// Change production base directory here (test mode)
53TString alien_datadir = "/alice/data/2010/LHC10h";
54 // Work directory in GRID (DON'T CHANGE)
55TString grid_workdir = "/alice/cern.ch/user/a/alidaq/PWG2/PWG2_$2";
56 // Data pattern - change as needed for test mode
57// TString data_pattern = "*ESDs/pass1/AOD033/*AOD.root";
58TString data_pattern = "*ESDs/pass1/*ESDs.root";
59// Set the run range
60Int_t run_numbers[10] = {137844}; // **********************!!!!!!!
61// AliEn output directory. If blank will become output_<train_name>
62 // Output directory (DON'T CHANGE)
63TString alien_outdir = "$1/PWG2OUT$2";
64 // Input collection (production mode)
65TString data_collection = "$1/input.xml";
66// Output folder to write delta AOD's. Considered if not null.
67TString outputSingleFolder = "";
68//TString outputSingleFolder = "deltas";
69// Number of files merged in a chunk
70Int_t maxMergeFiles = 20;
71// Files that should not be merged
72TString mergeExclude = "AliAOD.root AliAOD.VertexingHF.root AliAOD.Jets.root deltaAODPartCorr.root AliAOD.Muons.root AliAOD.Dimuons.root AliAOD.Dielectron.root AliAODCentrality.root";
73TString mergeDirName = "PWG2OUT$2";
74// Make replicas on the storages below
75TString outputStorages = "disk=4";
76// Number of runs per master job
77Int_t nRunsPerMaster = 10;
78// Maximum number of files per job (gives size of AOD)
79Int_t nFilesPerJob = 5;
80// Int_t nFilesPerJob = 1; (AOD->delta AOD production case)
81// ### Settings that make sense only for local analysis
82//==============================================================================
83// Change local xml dataset for local interactive analysis
84TString local_xmldataset = "";
85
86// ### Other flags to steer the analysis
87//==============================================================================
88Bool_t usePhysicsSelection = kFALSE; // use physics selection
89Bool_t useBKrejection = kFALSE; // use BK rejection
90Bool_t useCentrality = kFALSE; // centrality delta AOD
91Bool_t useTender = kFALSE; // use tender wagon
92Bool_t useV0tender = kFALSE; // use V0 correction in tender
93Bool_t useMergeViaJDL = kTRUE; // merge via JDL
94Bool_t useFastReadOption = kFALSE; // use xrootd tweaks
95Bool_t useOverwriteMode = kTRUE; // overwrite existing collections
96Bool_t useDATE = kFALSE; // use date in train name
97Bool_t useDBG = kTRUE; // activate debugging
98Bool_t useMC = kFALSE; // use MC info
99Bool_t useTAGS = kFALSE; // use ESD tags for selection
100Bool_t useKFILTER = kFALSE; // use Kinematics filter
101Bool_t useTR = kFALSE; // use track references
102Bool_t useCORRFW = kTRUE; // do not change
103Bool_t useAODTAGS = kFALSE; // use AOD tags
104Bool_t saveTrain = kTRUE; // save train configuration as:
105Bool_t saveCanvases = kFALSE; // save canvases created in Terminate
106Bool_t saveProofToAlien = kFALSE; // save proof outputs in AliEn
107
108// ### Analysis modules to be included. Some may not be yet fully implemented.
109//==============================================================================
110Int_t iAODanalysis = 0; // Analysis on input AOD's
111Int_t iAODhandler = 1; // Analysis produces an AOD or dAOD's
112
113Int_t iPWG2fmd = 0; // FMD forward analysis (PWG2)
114Int_t iPWG2femto = 1; // Femtoscopy two-track analysis (PWG2)
115
116
117// Temporaries.
118TString anaPars = "";
119TString anaLibs = "";
120// Function signatures
121class AliAnalysisAlien;
122
123//______________________________________________________________________________
124void AnalysisTrainPWG2(const char *analysis_mode="local",
125 const char *plugin_mode="full",
126 const char *config_file="")
127{
128// Main analysis train macro. If a configuration file is provided, all parameters
129// are taken from there but may be altered by CheckModuleFlags.
130 if (strlen(config_file) && !LoadConfig(config_file)) return;
131 TString smode(analysis_mode);
132 smode.ToUpper();
133 TString spmode(plugin_mode);
134 spmode.ToLower();
135 if (spmode == "test") useProductionMode = kFALSE;
136 // Check compatibility of selected modules
137 CheckModuleFlags(smode);
138 if (saveTrain) WriteConfig();
139
140 printf("==================================================================\n");
141 printf("=========== RUNNING ANALYSIS TRAIN %s IN %s MODE ==========\n", train_name.Data(),smode.Data());
142 printf("==================================================================\n");
143 printf("= Configuring analysis train for: =\n");
144 if (iAODanalysis) printf("= AOD analysis =\n");
145 else printf("= ESD analysis =\n");
146 if (usePhysicsSelection) printf("= Physics selection =\n");
147 if (useTender) printf("= TENDER =\n");
148 if (iPWG2fmd) printf("= PWG2 FMD =\n");
149 if (iPWG2femto) printf("= PWG2 Femtoscopy =\n");
150 printf("==================================================================\n");
151 printf(":: use physics selection: %d\n", (UInt_t)usePhysicsSelection);
152 printf(":: use xrootd tweaks: %d\n", (UInt_t)useFastReadOption);
153 printf(":: use overwrite xml : %d\n", (UInt_t)useOverwriteMode);
154 printf(":: use merge via JDL: %d\n", (UInt_t)useMergeViaJDL);
155 printf(":: use MC truth: %d\n", (UInt_t)useMC);
156 printf(":: use KINE filter: %d\n", (UInt_t)useKFILTER);
157 printf(":: use track references: %d\n", (UInt_t)useTR);
158 printf(":: use tags: %d\n", (UInt_t)useTAGS);
159 printf(":: use AOD tags: %d\n", (UInt_t)useAODTAGS);
160 printf(":: use debugging: %d\n", (UInt_t)useDBG);
161 printf(":: use PAR files: %d\n", (UInt_t)usePAR);
162 printf(":: use AliEn plugin: %d\n", (UInt_t)usePLUGIN);
163
164 //==========================================================================
165 // Connect to back-end system
166// if (!Connect(smode)) {
167// ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode);
168// return;
169// }
170
171 // Load common libraries and set include path
172 if (!LoadCommonLibraries(smode)) {
173 ::Error("AnalysisTrain", "Could not load common libraries");
174 return;
175 }
176
177 // Make the analysis manager and connect event handlers
178 AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train", "Production train");
179 if (saveProofToAlien) mgr->SetSpecialOutputLocation(proof_outdir);
180 if (!strcmp(plugin_mode, "test")) mgr->SetNSysInfo(1);
181 // Load analysis specific libraries
182 if (!LoadAnalysisLibraries(smode)) {
183 ::Error("AnalysisTrain", "Could not load analysis libraries");
184 return;
185 }
186
187 // Create input handler (input container created automatically)
188 if (iAODanalysis) {
189 // AOD input handler
190 AliAODInputHandler *aodH = new AliAODInputHandler();
191 mgr->SetInputEventHandler(aodH);
192 } else {
193 // ESD input handler
194 AliESDInputHandler *esdHandler = new AliESDInputHandler();
195 if (useTAGS) esdHandler->SetReadTags();
196 mgr->SetInputEventHandler(esdHandler);
197 }
198 // Monte Carlo handler
199 if (useMC && !iAODanalysis) {
200 AliMCEventHandler* mcHandler = new AliMCEventHandler();
201 mgr->SetMCtruthEventHandler(mcHandler);
202 mcHandler->SetReadTR(useTR);
203 }
204 // AOD output container, created automatically when setting an AOD handler
205 if (iAODhandler) {
206 // AOD output handler
207 AliAODHandler* aodHandler = new AliAODHandler();
208 aodHandler->SetOutputFileName("AliAOD.root");
209 mgr->SetOutputEventHandler(aodHandler);
210 if (iAODanalysis) {
211 aodHandler->SetFillAOD(kFALSE);
212 aodHandler->SetCreateNonStandardAOD();
213// if (iPWG3vertexing) aodHandler->SetOutputFileName("AliAOD.VertexingHF.root");
214 }
215 }
216 // Debugging if needed
217 if (useDBG) mgr->SetDebugLevel(3);
218 if (saveCanvases) mgr->SetSaveCanvases(kTRUE);
219
220 //==========================================================================
221 // Create the chain. In this example it is created only from ALIEN files but
222 // can be done to work in batch or grid mode as well.
223 TChain *chain = CreateChain(smode, plugin_mode);
224
225 //==========================================================================
226 // Load the tasks configuration macros for all wagons. These files are supposed now to be
227 // in the current workdir, but in AliEn they will be in the file catalog,
228 // mapped from AliRoot and pecified in the jdl input list.
229
230 // For now connection to top input container and common AOD output container
231 // is done in this macro, but in future these containers will be connected
232 // from each task configuration macro.
233
234 AddAnalysisTasks();
235
236 // Run the analysis
237 //
238 if (usePLUGIN) {
239 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
240 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
241 }
242
243 if (mgr->InitAnalysis()) {
244 mgr->PrintStatus();
245 if (saveTrain || strlen(config_file)) gSystem->ChangeDirectory(train_name);
246 StartAnalysis(smode, chain);
247 }
248}
249
250//______________________________________________________________________________
251void AddAnalysisTasks()
252{
253// Add all analysis task wagons to the train
254 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
255
256 //
257 // Tender and supplies. Needs to be called for every event.
258 //
259 if (useTender) {
260 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/TenderSupplies/AddTaskTender.C");
261 // IF V0 tender needed, put kTRUE below
262 AliAnalysisTaskSE *tender = AddTaskTender(useV0tender);
263// tender->SetDebugLevel(2);
264 }
265
266 if (usePhysicsSelection) {
267 // Physics selection task
268 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
269 mgr->RegisterExtraFile("event_stat.root");
270 AliPhysicsSelectionTask *physSelTask = AddTaskPhysicsSelection(useMC,useBKrejection);
271 mgr->AddStatisticsTask(AliVEvent::kMB);
272 }
273
274 // AOD tags
275 if (useAODTAGS) {
276 AliAnalysisTaskTagCreator* tagTask = new AliAnalysisTaskTagCreator("AOD Tag Creator");
277 mgr->AddTask(tagTask);
278 AliAnalysisDataContainer *coutTags = mgr->CreateContainer("cTag", TTree::Class(),
279 AliAnalysisManager::kOutputContainer, "AOD.tag.root");
280 mgr->ConnectInput (tagTask, 0, mgr->GetCommonInputContainer());
281 mgr->ConnectOutput(tagTask, 1, coutTags);
282 }
283
284
285// ********** PWG2 wagons ******************************************************
286 AliAnalysisManager::SetCommonFileName("PWG2histograms.root");
287
288 // PWG2 FMD
289 if (iPWG2fmd) {
290 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/AddTaskFMD.C");
291 AliAnalysisTask *taskFMD = AddTaskFMD(useMC, iCollision+1, iCollision?7000:2750, 0.5);
292 if (!taskFMD) ::Warning("AnalysisTrainNew", "AliAnalysisTaskFMD cannot run for this train conditions - EXCLUDED");
293 }
294
295 // PWG2 Femtoscopy
296 if (iPWG2femto) {
297 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FEMTOSCOPY/macros/AddTaskFemto.C");
298 AliAnalysisTask *taskFemto = AddTaskFemto("$ALICE_ROOT/PWG2/FEMTOSCOPY/macros/Train/TwoTrackQA/ConfigFemtoAnalysis.C");
299 if (!taskFemto) ::Warning("AnalysisTrainNew", "AliAnalysisTaskFemto cannot run for this train conditions - EXCLUDED");
300 }
301}
302
303//______________________________________________________________________________
304void StartAnalysis(const char *mode, TChain *chain) {
305// Start analysis.
306 Int_t imode = -1;
307 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
308 if (!strcmp(mode, "LOCAL")) imode = 0;
309 if (!strcmp(mode, "PROOF")) imode = 1;
310 if (!strcmp(mode, "GRID")) imode = 2;
311 switch (imode) {
312 case 0:
313 if (!chain) {
314 ::Error("AnalysisTrainNew.C::StartAnalysis", "Cannot create the chain");
315 return;
316 }
317 mgr->StartAnalysis(mode, chain);
318 return;
319 case 1:
320 if (!proof_dataset.Length()) {
321 ::Error("AnalysisTrainNew.C::StartAnalysis", "proof_dataset is empty");
322 return;
323 }
324 mgr->StartAnalysis(mode, proof_dataset, 1000);
325 return;
326 case 2:
327 if (usePLUGIN) {
328 if (!mgr->GetGridHandler()) {
329 ::Error("AnalysisTrainNew.C::StartAnalysis", "Grid plugin not initialized");
330 return;
331 }
332 mgr->StartAnalysis("grid");
333 } else {
334 if (!chain) {
335 ::Error("AnalysisTrainNew.C::StartAnalysis", "Cannot create the chain");
336 return;
337 }
338 mgr->StartAnalysis(mode, chain);
339 }
340 return;
341 }
342}
343
344//______________________________________________________________________________
345void CheckModuleFlags(const char *mode) {
346// Checks selected modules and insure compatibility
347 Int_t imode = -1;
348 if (!strcmp(mode, "LOCAL")) imode = 0;
349 if (!strcmp(mode, "PROOF")) imode = 1;
350 if (!strcmp(mode, "GRID")) imode = 2;
351 if (imode==1) {
352 if (!usePAR) {
353 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
354 usePAR = kTRUE;
355 }
356 }
357 if (imode != 2) {
358 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
359 usePLUGIN = kFALSE;
360 }
361 if (iAODanalysis) {
362 // AOD analysis
363 if (useMC)
364 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "MC usage disabled in analysis on AOD's");
365 if (useAODTAGS)
366 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "AOD tags usage disabled in analysis on AOD's");
367 useMC = kFALSE;
368 useTR = kFALSE;
369 useAODTAGS = kFALSE;
370 } else {
371 // ESD analysis
372 if (!useMC) useTR = kFALSE;
373 if (!useTR) {
374 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "iPWG2evchar disabled if not reading track references");
375 iPWG2evchar = 0;
376 }
377 }
378 if (useKFILTER && !useMC) useKFILTER = kFALSE;
379 if (useAODTAGS && !iAODhandler) useAODTAGS = kFALSE;
380}
381
382//______________________________________________________________________________
383Bool_t Connect(const char *mode) {
384// Connect <username> to the back-end system.
385 Int_t imode = -1;
386 if (!strcmp(mode, "LOCAL")) imode = 0;
387 if (!strcmp(mode, "PROOF")) imode = 1;
388 if (!strcmp(mode, "GRID")) imode = 2;
389 TString username = gSystem->Getenv("alien_API_USER");
390 switch (imode) {
391 case 0:
392 break;
393 case 1:
394 if (!username.Length()) {
395 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Make sure you:\n \
396 1. Have called: alien-token-init <username>\n \
397 2. Have called: >source /tmp/gclient_env_$UID");
398 return kFALSE;
399 }
400 ::Info("AnalysisTrainNew.C::Connect", "Connecting user <%s> to PROOF cluster <%s>",
401 username.Data(), proof_cluster.Data());
402 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
403// TProof::Open(Form("%s@%s:31093", username.Data(), proof_cluster.Data()));
404 TProof::Open(Form("%s@%s", username.Data(), proof_cluster.Data()));
405 if (!gProof) {
406 if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
407 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
408 return kFALSE;
409 }
410 TGrid::Connect("alien://");
411 if (gGrid) {
412 TString homedir = gGrid->GetHomeDirectory();
413 TString workdir = homedir + train_name;
414 if (!gGrid->Cd(workdir)) {
415 gGrid->Cd(homedir);
416 if (gGrid->Mkdir(workdir)) {
417 gGrid->Cd(train_name);
418 ::Info("AnalysisTrainNew::Connect()", "Directory %s created", gGrid->Pwd());
419 }
420 }
421 gGrid->Mkdir("proof_output");
422 gGrid->Cd("proof_output");
423 proof_outdir = Form("alien://%s", gGrid->Pwd());
424 }
425 break;
426 case 2:
427 if (usePLUGIN && !gSystem->Getenv("alien_CLOSE_SE")) {
428 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode),
429 "When using the AliEn plugin it is preferable to define the \
430 variable alien_CLOSE_SE in your environment.");
431 return kFALSE;
432 }
433 ::Info("AnalysisTrainNew.C::Connect", "Connecting user <%s> to AliEn ...",
434 username.Data());
435 TGrid::Connect("alien://");
436 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
437 break;
438 default:
439 ::Error("AnalysisTrainNew.C::Connect", "Unknown run mode: %s", mode);
440 return kFALSE;
441 }
442 ::Info("AnalysisTrainNew.C::Connect","Connected in %s mode", mode);
443 return kTRUE;
444}
445
446//______________________________________________________________________________
447Bool_t LoadCommonLibraries(const char *mode)
448{
449// Load common analysis libraries.
450 Int_t imode = -1;
451 if (!strcmp(mode, "LOCAL")) imode = 0;
452 if (!strcmp(mode, "PROOF")) imode = 1;
453 if (!strcmp(mode, "GRID")) imode = 2;
454 if (!gSystem->Getenv("ALICE_ROOT")) {
455 ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
456 return kFALSE;
457 }
458 Bool_t success = kTRUE;
459 // ROOT libraries
460 gSystem->Load("libTree.so");
461 gSystem->Load("libGeom.so");
462 gSystem->Load("libVMC.so");
463 gSystem->Load("libPhysics.so");
464 gSystem->Load("libMinuit.so");
465
466 // Load framework classes. Par option ignored here.
467 switch (imode) {
468 case 0:
469 case 2:
470 if (useCPAR) {
471 success &= LoadLibrary("STEERBase", mode, kTRUE);
472 success &= LoadLibrary("ESD", mode, kTRUE);
473 success &= LoadLibrary("AOD", mode, kTRUE);
474 success &= LoadLibrary("ANALYSIS", mode, kTRUE);
475 success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
476 if (useCORRFW) success &= LoadLibrary("CORRFW", mode, kTRUE);
477 } else {
478 success &= LoadLibrary("libSTEERBase.so", mode);
479 success &= LoadLibrary("libESD.so", mode);
480 success &= LoadLibrary("libAOD.so", mode);
481 success &= LoadLibrary("libANALYSIS.so", mode);
482 success &= LoadLibrary("libANALYSISalice.so", mode);
483 if (useCORRFW) success &= LoadLibrary("libCORRFW.so", mode);
484 gROOT->ProcessLine(".include $ALICE_ROOT/include");
485 }
486 break;
487 case 1:
488 Int_t ires = -1;
489 if (useAFPAR && !gSystem->AccessPathName(AFversion)) ires = gProof->UploadPackage(AFversion);
490 if (ires < 0) {
491 success &= LoadLibrary("STEERBase", mode);
492 success &= LoadLibrary("ESD", mode);
493 success &= LoadLibrary("AOD", mode);
494 success &= LoadLibrary("ANALYSIS", mode);
495 success &= LoadLibrary("ANALYSISalice", mode);
496 if (useCORRFW) success &= LoadLibrary("CORRFW", mode);
497 } else {
498 ires = gProof->EnablePackage(AFversion);
499 if (ires<0) success = kFALSE;
500 if (useCORRFW) success &= LoadLibrary("CORRFW", mode);
501 }
502 break;
503 default:
504 ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
505 return kFALSE;
506 }
507 if (success) {
508 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
509 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
510 gSystem->GetIncludePath());
511 } else {
512 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries: FAILED");
513 }
514
515 return success;
516}
517
518//______________________________________________________________________________
519Bool_t LoadAnalysisLibraries(const char *mode)
520{
521// Load common analysis libraries.
522 Bool_t success = kTRUE;
523 if (useTender) {
524 if (!LoadLibrary("TENDER", mode, kTRUE) ||
525 !LoadLibrary("TENDERSupplies", mode, kTRUE)) return kFALSE;
526 }
527 // PWG2 fmd
528 if (iPWG2fmd) {
529 if (!LoadLibrary("PWG2forward", mode, kTRUE)) return kFALSE;
530 }
531 // PWG2 femtoscopy
532 if (iPWG2femto) {
533 if (!LoadLibrary("PWG2AOD", mode, kTRUE) ||
534 !LoadLibrary("PWG2femtoscopy", mode, kTRUE) ||
535 !LoadLibrary("PWG2femtoscopyUser", mode, kTRUE)) return kFALSE;
536 }
537
538 ::Info("AnalysisTrainNew.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
539 return kTRUE;
540}
541
542//______________________________________________________________________________
543Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
544{
545// Load a module library in a given mode. Reports success.
546 Int_t imode = -1;
547 Int_t result;
548 TString smodule(module);
549 if (!strcmp(mode, "LOCAL")) imode = 0;
550 if (!strcmp(mode, "PROOF")) imode = 1;
551 if (!strcmp(mode, "GRID")) imode = 2;
552 TString mod(module);
553 if (!mod.Length()) {
554 ::Error("AnalysisTrainNew.C::LoadLibrary", "Empty module name");
555 return kFALSE;
556 }
557 // If a library is specified, just load it
558 if (smodule.EndsWith(".so")) {
559 mod.Remove(mod.Index(".so"));
560 result = gSystem->Load(mod);
561 if (result < 0) {
562 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load library %s", module);
563 return kFALSE;
564 }
565 if (rec) anaLibs += Form("%s.so ",mod.Data());
566 return kTRUE;
567 }
568 // Check if the library is already loaded
569 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
570 return kTRUE;
571 switch (imode) {
572 case 0:
573 case 2:
574 if (usePAR) {
575 result = SetupPar(module);
576 if (rec) anaPars += Form("%s.par ", module);
577 } else {
578 result = gSystem->Load(Form("lib%s.so", module));
579 if (rec) anaLibs += Form("lib%s.so ", module);
580 }
581 break;
582 case 1:
583 result = gProof->UploadPackage(module);
584 if (result<0) {
585 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
586 if (result<0) {
587 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
588 return kFALSE;
589 }
590 }
591 result = gProof->EnablePackage(module);
592 break;
593 default:
594 return kFALSE;
595 }
596 if (result < 0) {
597 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load module %s", module);
598 return kFALSE;
599 }
600 return kTRUE;
601}
602
603
604//______________________________________________________________________________
605TChain *CreateChain(const char *mode, const char *plugin_mode)
606{
607// Create the input chain
608 Int_t imode = -1;
609 if (!strcmp(mode, "LOCAL")) imode = 0;
610 if (!strcmp(mode, "PROOF")) imode = 1;
611 if (!strcmp(mode, "GRID")) imode = 2;
612 TChain *chain = NULL;
613 // Local chain
614 switch (imode) {
615 case 0:
616 if (iAODanalysis) {
617 if (!local_xmldataset.Length()) {
618 // Local AOD
619 chain = new TChain("aodTree");
620 if (gSystem->AccessPathName("data/AliAOD.root"))
621 ::Error("AnalysisTrainNew.C::CreateChain", "File: AliAOD.root not in ./data dir");
622 else {
623 if (!saveTrain) chain->Add("data/AliAOD.root");
624 else chain->Add("../data/AliAOD.root");
625 }
626 } else {
627 // Interactive AOD
628 chain = CreateChainSingle(local_xmldataset, "aodTree");
629 }
630 } else {
631 if (!local_xmldataset.Length()) {
632 // Local ESD
633 chain = new TChain("esdTree");
634 if (gSystem->AccessPathName("data/AliESDs.root"))
635 ::Error("AnalysisTrainNew.C::CreateChain", "File: AliESDs.root not in ./data dir");
636 else {
637 if (!saveTrain) chain->Add("data/AliESDs.root");
638 else chain->Add("../data/AliESDs.root");
639 }
640 } else {
641 // Interactive ESD
642 chain = CreateChainSingle(local_xmldataset, "esdTree");
643 }
644 }
645 break;
646 case 1:
647 break;
648 case 2:
649 if (usePLUGIN) {
650// AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
651// AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
652 } else {
653 TString treeName = "esdTree";
654 if (iAODanalysis) treeName = "aodTree";
655 chain = CreateChainSingle("wn.xml", treeName);
656 }
657 break;
658 default:
659 }
660 if (chain && chain->GetNtrees()) return chain;
661 return NULL;
662}
663
664//______________________________________________________________________________
665TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
666{
667 printf("*******************************\n");
668 printf("*** Getting the ESD Chain ***\n");
669 printf("*******************************\n");
670 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
671
672 if (!myCollection) {
673 ::Error("AnalysisTrainNew.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
674 return NULL ;
675 }
676
677 TChain* chain = new TChain(treeName);
678 myCollection->Reset() ;
679 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
680 chain->ls();
681 return chain;
682}
683
684//______________________________________________________________________________
685Int_t SetupPar(char* pararchivename)
686{
687 if (!pararchivename || !strlen(pararchivename)) return -1;
688 char processline[1024];
689 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
690 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
691 ::Info("AnalysisTrainNew.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
692 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
693 Form("%s.par",pararchivename));
694 } else {
695 ::Error("AnalysisTrainNew.C::SetupPar", "Cannot find %s.par", pararchivename);
696 return -1;
697 }
698 }
699 if (usePLUGIN && saveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, train_name.Data()));
700 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
701
702 TString ocwd = gSystem->WorkingDirectory();
703 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
704
705 // check for BUILD.sh and execute
706 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
707 printf("*******************************\n");
708 printf("*** Building PAR archive ***\n");
709 printf("*******************************\n");
710 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
711 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
712 return -1;
713 }
714 }
715
716 // check for SETUP.C and execute
717 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
718 printf("*******************************\n");
719 printf("*** Setup PAR archive ***\n");
720 printf("*******************************\n");
721 gROOT->Macro("PROOF-INF/SETUP.C");
722 }
723 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
724 return 0;
725}
726
727//______________________________________________________________________________
728AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
729{
730// Check if user has a valid token, otherwise make one. This has limitations.
731// One can always follow the standard procedure of calling alien-token-init then
732 AliAnalysisAlien *plugin = new AliAnalysisAlien();
733// Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
734 plugin->SetRunMode(plugin_mode);
735 if (useProductionMode) {
736 plugin->SetProductionMode();
737 plugin->AddDataFile(data_collection);
738 }
739
740 if (!outputSingleFolder.IsNull()) {
741 plugin->SetOutputSingleFolder(outputSingleFolder);
742 plugin->SetOutputToRunNo();
743 }
744 plugin->SetJobTag(job_tag);
745 plugin->SetNtestFiles(5);
746 plugin->SetCheckCopy(kFALSE);
747 plugin->SetMergeDirName(mergeDirName);
748// Set versions of used packages
749 plugin->SetAPIVersion("V1.1x");
750 plugin->SetROOTVersion(root_version);
751 plugin->SetAliROOTVersion(aliroot_version);
752// Declare input data to be processed.
753// Method 1: Create automatically XML collections using alien 'find' command.
754// Define production directory LFN
755 plugin->SetGridDataDir(alien_datadir);
756// Set data search pattern
757 plugin->SetDataPattern(data_pattern);
758 if (!useProductionMode) {
759 if (runOnData) {
760 plugin->SetRunPrefix("%09d");
761 }
762// if (!iAODanalysis) plugin->SetRunRange(run_range[0], run_range[1]);
763 for (Int_t i=0; i<10; i++) {
764 if (run_numbers[i]==0) break;
765 plugin->AddRunNumber(run_numbers[i]);
766 }
767 }
768// Define alien work directory where all files will be copied. Relative to alien $HOME.
769 plugin->SetGridWorkingDir(grid_workdir);
770// Declare alien output directory. Relative to working directory.
771 if (alien_outdir.IsNull()) alien_outdir = Form("output_%s",train_name.Data());
772 plugin->SetGridOutputDir(alien_outdir);
773
774 TString ana_sources = "";
775 TString ana_add = "";
776 if (usePAR && anaPars.Length()) {
777 printf("%s\n", anaPars.Data());
778 TObjArray *arr;
779 TObjString *objstr;
780 arr = anaPars.Tokenize(" ");
781 TIter next(arr);
782 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
783 delete arr;
784 }
785
786// Declare the analysis source files names separated by blancs. To be compiled runtime
787// using ACLiC on the worker nodes.
788 ana_sources = ana_sources.Strip();
789// Declare all libraries (other than the default ones for the framework. These will be
790// loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
791 anaLibs = anaLibs.Strip();
792 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
793 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs);
794
795// Declare the output file names separated by blancs.
796// (can be like: file.root or file.root@ALICE::Niham::File)
797 plugin->SetDefaultOutputs();
798 plugin->SetMergeExcludes(mergeExclude);
799 plugin->SetMaxMergeFiles(maxMergeFiles);
800 plugin->SetNrunsPerMaster(nRunsPerMaster);
801// Optionally define the files to be archived.
802// plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
803
804
805 // Put default output files to archive
806 TString listhists = "";
807 TString listaods = "";
808 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
809 TIter next(mgr->GetOutputs());
810 AliAnalysisDataContainer *output;
811 while ((output=(AliAnalysisDataContainer*)next())) {
812 const char *filename = output->GetFileName();
813 if (!(strcmp(filename, "default"))) {
814 if (!mgr->GetOutputEventHandler()) continue;
815 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
816 if (listaods.Length()) listaods += ",";
817 listaods += filename;
818 listaods += ",";
819 listaods += "pyxsec_hists.root";
820 } else {
821 if (!strcmp(filename, "pyxsec_hists.root")) continue;
822 if (listhists.Contains(filename)) continue;
823 if (listhists.Length()) listhists += ",";
824 listhists += filename;
825 }
826 }
827 if (mgr->GetExtraFiles().Length()) {
828 if (listaods.Length()) listaods += ",";
829 listaods += mgr->GetExtraFiles();
830 listaods.ReplaceAll(" ", ",");
831 }
832 if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), outputStorages.Data());
833 if (listaods.Length()) listaods = Form("aod_archive.zip:%s@%s", listaods.Data(), outputStorages.Data());
834 if (!listhists.Length() && !listaods.Length()) {
835 ::Fatal("AnalysisTrainNew", "No task output !");
836 }
837 TString outputArchive = Form("log_archive.zip:stderr@%s", outputStorages.Data());
838 if (listaods.Length()) {
839 outputArchive += " ";
840 outputArchive += listaods;
841 }
842 if (listhists.Length()) {
843 outputArchive += " ";
844 outputArchive += listhists;
845 }
846// Set friends
847// if (iAODanalysis && iPWG3d2h)
848// plugin->SetFriendChainName("AliAOD.VertexingHF.root");
849// plugin->SetOutputArchive(outputArchive);
850// Optionally set a name for the generated analysis macro (default MyAnalysis.C)
851 plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
852// Optionally set a name for the generated validation script
853 plugin->SetValidationScript("PWG2validation.sh");
854// Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
855 plugin->SetSplitMaxInputFileNumber(nFilesPerJob);
856// Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
857// plugin->SetMaxInitFailed(5);
858// Optionally modify the number of replicas
859 plugin->SetNumberOfReplicas(4);
860// Optionally resubmit threshold.
861// plugin->SetMasterResubmitThreshold(90);
862// Optionally set time to live (default 30000 sec)
863 plugin->SetTTL(70000);
864// Optionally set input format (default xml-single)
865 plugin->SetInputFormat("xml-single");
866// Optionally modify the name of the generated JDL (default analysis.jdl)
867 plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
868// Optionally modify the executable name (default analysis.sh)
869 plugin->SetExecutable(Form("%s.sh", train_name.Data()));
870// Optionally modify job price (default 1)
871 plugin->SetPrice(1);
872// Merge via JDL
873 plugin->SetMergeViaJDL(useMergeViaJDL);
874// Use fastread option
875 plugin->SetFastReadOption(useFastReadOption);
876// UseOverwrite mode
877 plugin->SetOverwriteMode(useOverwriteMode);
878 plugin->SetExecutableCommand("aliroot -b -q");
879// Optionally modify split mode (default 'se')
880 plugin->SetSplitMode("se");
881 return plugin;
882}
883
884//______________________________________________________________________________
885void WriteConfig()
886{
887// Write train configuration in a file. The file name has the format:
888// train_[trainName]_ddMonthyyyy_time.C
889 if (useDATE) {
890 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
891 ifstream fdate("date.tmp");
892 if (!fdate.is_open()) {
893 ::Error("AnalysisTrainNew.C::Export","Could not generate file name");
894 return;
895 }
896 const char date[64];
897 fdate.getline(date,64);
898 fdate.close();
899 gSystem->Exec("rm date.tmp");
900 train_name = Form("%s_%s", train_name.Data(), date);
901 }
902 TString cdir = gSystem->WorkingDirectory();
903 gSystem->MakeDirectory(train_name);
904 gSystem->ChangeDirectory(train_name);
905 ofstream out;
906 out.open(Form("%sConfig.C",train_name.Data()), ios::out);
907 if (out.bad()) {
908 ::Error("AnalysisTrainNew.C::Export", "Cannot open ConfigTrain.C for writing");
909 return;
910 }
911 out << "{" << endl;
912 out << " train_name = " << "\"" << train_name.Data() << "\";" << endl;
913 out << " proof_cluster = " << "\"" << proof_cluster.Data() << "\";" << endl;
914 out << " useAFPAR = " << useAFPAR << ";" << endl;
915 if (useAFPAR)
916 out << " AFversion = " << AFversion.Data() << ";" << endl;
917 out << " proof_dataset = " << "\"" << proof_dataset.Data() << "\";" << endl;
918 out << " usePLUGIN = " << usePLUGIN << ";" << endl;
919 out << " usePAR = " << usePAR << ";" << endl;
920 out << " useCPAR = " << useCPAR << ";" << endl;
921 out << " root_version = " << "\"" << root_version.Data() << "\";" << endl;
922 out << " aliroot_version = " << "\"" << aliroot_version.Data() << "\";" << endl;
923 out << " alien_datadir = " << "\"" << alien_datadir.Data() << "\";" << endl;
924 if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
925 out << " alien_outdir = " << "\"" << alien_outdir.Data() << "\";" << endl;
926 out << " maxMergeFiles = " << maxMergeFiles << ";" << endl;
927 out << " mergeExclude = " << "\"" << mergeExclude.Data() << "\";" << endl;
928 out << " nRunsPerMaster = " << nRunsPerMaster << ";" << endl;
929 out << " nFilesPerJob = " << nFilesPerJob << ";" << endl;
930// for (Int_t i=0; i<10; i++) {
931// if (run_numbers[i])
932// out << " run_numbers[" << i << "] = " << run_numbers[i] << ";" << endl;
933// }
934// out << " run_range[0] = " << run_range[0] << ";" << endl;
935// out << " run_range[1] = " << run_range[1] << ";" << endl;
936 out << " usePhysicsSelection = " << usePhysicsSelection << ";" << endl;
937 out << " useTender = " << useTender << ";" << endl;
938 out << " useMergeViaJDL = " << useMergeViaJDL << ";" << endl;
939 out << " useOverwriteMode = " << useOverwriteMode << ";" << endl;
940 out << " useFastReadOption = " << useFastReadOption << ";" << endl;
941 out << " useDBG = " << useDBG << ";" << endl;
942 out << " useMC = " << useMC << ";" << endl;
943 out << " useTAGS = " << useTAGS << ";" << endl;
944 out << " useKFILTER = " << useKFILTER << ";" << endl;
945 out << " useTR = " << useTR << ";" << endl;
946 out << " useCORRFW = " << useCORRFW << ";" << endl;
947 out << " useAODTAGS = " << useAODTAGS << ";" << endl;
948 out << " saveTrain = " << "kFALSE;" << endl << endl;
949 out << " // Analysis modules" << endl;
950 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
951 out << " iAODhandler = " << iAODhandler << ";" << endl;
952 out << " iPWG2fmd = " << iPWG2fmd << ";" << endl;
953 out << " iPWG2femto = " << iPWG2femto << ";" << endl;
954 out << "}" << endl;
955 ::Info("AnalysisTrainNew.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", train_name.Data()));
956 gSystem->ChangeDirectory(cdir);
957}
958
959//______________________________________________________________________________
960Bool_t LoadConfig(const char *filename)
961{
962// Read train configuration from file
963 if (gSystem->AccessPathName(filename)) {
964 ::Error("AnalysisTrainNew.C::LoadConfig", "Config file name not found");
965 return kFALSE;
966 }
967 gROOT->ProcessLine(Form(".x %s", filename));
968 ::Info("AnalysisTrainNew.C::LoadConfig", "Train configuration loaded from file %s", filename);
969 return kTRUE;
970}