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.
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")
18 //================== TRAIN NAME ============================================
19 TString train_name = "LHC09a5"; // enters file names, so no blancs or special characters
20 //==============================================================================
22 // ### Settings that make sense in PROOF only
23 //==============================================================================
24 TString proof_cluster = "alicecaf.cern.ch";
25 Bool_t useAFPAR = kFALSE; // use AF special par file
26 TString AFversion = "AF-v4-16";
27 // Change CAF dataset here
28 TString proof_dataset = "/COMMON/COMMON/LHC09a4_run8100X#/esdTree";
29 TString proof_outdir = "";
31 // ### Settings that make sense when using the Alien plugin
32 //==============================================================================
33 Bool_t usePLUGIN = kTRUE; // do not change
34 // Usage of par files ONLY in grid mode and ONLY if the code is not available
35 // in the deployed AliRoot versions. Par file search path: local dir, if not there $ALICE_ROOT.
36 // To refresh par files, remove the ones in the workdir, then do "make <target.par>" in
38 Bool_t usePAR = kFALSE; // use par files for extra libs
39 Bool_t useCPAR = kFALSE; // use par files for common libs
40 TString root_version = "v5-23-04";
41 TString aliroot_version = "v4-17-03";
42 // Change production base directory here
43 TString alien_datadir = "/alice/sim/PDC_09/LHC09a5/";
44 // AliEn output directory. If blank will become output_<train_name>
45 TString alien_outdir = "/alice/sim/PDC_09/LHC09a5/AOD";
46 // Number of files merged in a chunk
47 Int_t maxMergeFiles = 50;
48 // Files that should not be merged
49 TString mergeExclude = "AliAOD.root AliAOD.VertexingHF.root AOD.tag.root";
50 // Number of runs per master job
51 Int_t nRunsPerMaster = 10;
52 // Maximum number of files per job (gives size of AOD)
53 Int_t nFilesPerJob = 100;
55 Int_t run_range[2] = {90000, 90040};
56 // ### Settings that make sense only for local analysis
57 //==============================================================================
58 // Change local xml dataset for local interactive analysis
59 TString local_xmldataset = "";
61 // ### Other flags to steer the analysis
62 //==============================================================================
63 Bool_t useDATE = kFALSE; // use date in train name
64 Bool_t useDBG = kFALSE; // activate debugging
65 Bool_t useMC = kTRUE; // use MC info
66 Bool_t useTAGS = kFALSE; // use ESD tags for selection
67 Bool_t useKFILTER = kTRUE; // use Kinematics filter
68 Bool_t useTR = kTRUE; // use track references
69 Bool_t useCORRFW = kFALSE; // do not change
70 Bool_t useAODTAGS = kTRUE; // use AOD tags
71 Bool_t saveTrain = kTRUE; // save train configuration as:
72 Bool_t saveProofToAlien = kFALSE; // save proof outputs in AliEn
73 // train_[trainName]_ddMonthyyyy_time.C
74 // ### Analysis modules to be included. Some may not be yet fully implemented.
75 //==============================================================================
76 Int_t iAODanalysis = 0; // Analysis on input AOD's
77 Int_t iAODhandler = 1; // Analysis produces an AOD or dAOD's
78 Int_t iESDfilter = 1; // ESD to AOD filter (barrel + muon tracks)
79 Int_t iMUONcopyAOD = 0; // Task that copies only muon events in a separate AOD (PWG3)
80 Int_t iJETAN = 1; // Jet analysis (PWG4) - needs ESD filter
81 Int_t iPWG4partcorr = 1; // Gamma-hadron correlations task (PWG4)
82 Int_t iPWG4gammaconv = 0; // Gamma conversion analysis (PWG4)
83 Int_t iPWG3vertexing = 1; // Vertexing HF task (PWG2)
84 Int_t iPWG2femto = 1; // Femtoscopy task (PWG2)
85 Int_t iPWG2spectra = 1; // Spectra PWG2 tasks (protons, cascades, V0 check, strange)
86 Int_t iPWG2flow = 1; // Flow analysis task (PWG2)
87 Int_t iPWG2res = 0; // Resonances task (PWG2)
88 Int_t iPWG2kink = 1; // Kink analysis task (PWG2)
89 Int_t iPWG2evchar = 1; // Event characteristics (PWG2)
90 Int_t iPWG2unicor = 1; // Unicor analysis (PWG2)
95 // Function signatures
96 class AliAnalysisGrid;
98 //______________________________________________________________________________
99 void AnalysisTrainNew(const char *analysis_mode="grid",
100 const char *plugin_mode="full",
101 const char *config_file="")
103 // Main analysis train macro. If a configuration file is provided, all parameters
104 // are taken from there but may be altered by CheckModuleFlags.
105 if (strlen(config_file) && !LoadConfig(config_file)) return;
106 TString smode(analysis_mode);
108 if (saveTrain) WriteConfig();
109 // Check compatibility of selected modules
110 CheckModuleFlags(smode);
112 printf("==================================================================\n");
113 printf("=========== RUNNING ANALYSIS TRAIN %s IN %s MODE ==========\n", train_name.Data(),smode.Data());
114 printf("==================================================================\n");
115 printf("= Configuring analysis train for: =\n");
116 if (iAODanalysis) printf("= AOD analysis =\n");
117 else printf("= ESD analysis =\n");
118 if (iESDfilter) printf("= ESD filter =\n");
119 if (iMUONcopyAOD) printf("= MUON copy AOD =\n");
120 if (iJETAN) printf("= Jet analysis =\n");
121 if (iPWG2spectra) printf("= PWG2 proton, checkCascade, checkV0, strange, performance cascade =\n");
122 if (iPWG2femto) printf("= PWG2 femtoscopy =\n");
123 if (iPWG2flow) printf("= PWG2 flow =\n");
124 if (iPWG2res) printf("= PWG2 resonances =\n");
125 if (iPWG2kink) printf("= PWG2 kink analysis =\n");
126 if (iPWG2evchar) printf("= PWG2 event characteristics =\n");
127 if (iPWG2unicor) printf("= PWG2 Unicor analysis =\n");
128 if (iPWG3vertexing) printf("= PWG3 vertexing =\n");
129 if (iPWG4partcorr) printf("= PWG4 gamma-hadron, pi0 and gamma-jet correlations =\n");
130 if (iPWG4gammaconv) printf("= PWG4 gamma conversion =\n");
131 printf("==================================================================\n");
132 printf(":: use MC truth %d\n", (UInt_t)useMC);
133 printf(":: use KINE filter %d\n", (UInt_t)useKFILTER);
134 printf(":: use track refs %d\n", (UInt_t)useTR);
135 printf(":: use tags %d\n", (UInt_t)useTAGS);
136 printf(":: use AOD tags %d\n", (UInt_t)useAODTAGS);
137 printf(":: use debugging %d\n", (UInt_t)useDBG);
138 printf(":: use PAR files %d\n", (UInt_t)usePAR);
139 printf(":: use AliEn plugin %d\n", (UInt_t)usePLUGIN);
141 //==========================================================================
142 // Connect to back-end system
143 if (!Connect(smode)) {
144 ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode);
148 // Load common libraries and set include path
149 if (!LoadCommonLibraries(smode)) {
150 ::Error("AnalysisTrain", "Could not load common libraries");
154 // Make the analysis manager and connect event handlers
155 AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train", "Production train");
156 if (saveProofToAlien) mgr->SetSpecialOutputLocation(proof_outdir);
158 // Load analysis specific libraries
159 if (!LoadAnalysisLibraries(smode)) {
160 ::Error("AnalysisTrain", "Could not load analysis libraries");
164 // Create input handler (input container created automatically)
167 AliAODInputHandler *aodH = new AliAODInputHandler();
168 mgr->SetInputEventHandler(aodH);
171 AliESDInputHandler *esdHandler = new AliESDInputHandler();
172 if (useTAGS) esdHandler->SetReadTags();
173 mgr->SetInputEventHandler(esdHandler);
175 // Monte Carlo handler
176 if (useMC && !iAODanalysis) {
177 AliMCEventHandler* mcHandler = new AliMCEventHandler();
178 mgr->SetMCtruthEventHandler(mcHandler);
179 mcHandler->SetReadTR(useTR);
181 // AOD output container, created automatically when setting an AOD handler
183 // AOD output handler
184 AliAODHandler* aodHandler = new AliAODHandler();
185 aodHandler->SetOutputFileName("AliAOD.root");
186 mgr->SetOutputEventHandler(aodHandler);
188 aodHandler->SetCreateNonStandardAOD();
189 if (iPWG3vertexing) aodHandler->SetOutputFileName("AliAOD.VertexingHF.root");
192 // Debugging if needed
193 if (useDBG) mgr->SetDebugLevel(3);
195 //==========================================================================
196 // Create the chain. In this example it is created only from ALIEN files but
197 // can be done to work in batch or grid mode as well.
198 TChain *chain = CreateChain(smode, plugin_mode);
200 //==========================================================================
201 // Load the tasks configuration macros for all wagons. These files are supposed now to be
202 // in the current workdir, but in AliEn they will be in the file catalog,
203 // mapped from AliRoot and pecified in the jdl input list.
205 // For now connection to top input container and common AOD output container
206 // is done in this macro, but in future these containers will be connected
207 // from each task configuration macro.
209 if (iESDfilter && !iAODanalysis) {
210 // ESD filter task configuration.
211 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
212 AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(useKFILTER);
217 AliAnalysisTaskTagCreator* tagTask = new AliAnalysisTaskTagCreator("AOD Tag Creator");
218 mgr->AddTask(tagTask);
219 AliAnalysisDataContainer *coutTags = mgr->CreateContainer("cTag", TTree::Class(),
220 AliAnalysisManager::kOutputContainer, "AOD.tag.root");
221 mgr->ConnectInput (tagTask, 0, mgr->GetCommonInputContainer());
222 mgr->ConnectOutput(tagTask, 1, coutTags);
227 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
228 AliAnalysisTaskJets *taskjets = AddTaskJets("AOD", "UA1");
229 if (!taskjets) ::Warning("AnalysisTrainNew", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
235 gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskProtons.C");
236 AliAnalysisTaskProtons *taskprotons = AddTaskProtons();
237 if (!taskprotons) ::Warning("AnalysisTrainNew", "AliAnalysisTaskProtons cannot run for this train conditions - EXCLUDED");
239 gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskCheckCascade.C");
240 AliAnalysisTaskCheckCascade *taskcheckcascade = AddTaskCheckCascade();
241 if (!taskcheckcascade) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCheckCascade cannot run for this train conditions - EXCLUDED");
243 gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskCheckV0.C");
244 AliAnalysisTaskCheckV0 *taskcheckV0 = AddTaskCheckV0();
245 if (!taskcheckV0) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCheckV0 cannot run for this train conditions - EXCLUDED");
247 gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskStrange.C");
248 AliAnalysisTaskStrange *taskstrange = AddTaskStrange();
249 if (!taskstrange) ::Warning("AnalysisTrainNew", "AliAnalysisTaskStrange cannot run for this train conditions - EXCLUDED");
250 // performance cascades
251 gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskCheckPerformanceCascade.C");
252 AliAnalysisTaskCheckPerformanceCascade *taskperfcascade = AddTaskCheckPerformanceCascade();
253 if (!taskperfcascade) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCheckPerformanceCascade cannot run for this train conditions - EXCLUDED");
256 // Femtoscopy analysis modules
258 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FEMTOSCOPY/macros/AddTaskFemto.C");
259 AliAnalysisTaskFemto *taskfemto = AddTaskFemto();
260 if (!taskfemto) ::Warning("AnalysisTrainNew", "AliAnalysisTaskFemto cannot run for this train conditions - EXCLUDED");
265 gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKink.C");
266 AliAnalysisKinkESDMC *taskkink = AddTaskKink();
267 if (!taskkink) ::Warning("AnalysisTrainNew", "AliAnalysisKinkESDMC cannot run for this train conditions - EXCLUDED");
268 gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonance.C");
269 AliAnalysisTaskKinkResonance *taskkinkres = AddTaskKinkResonance();
270 if (!taskkinkres) ::Warning("AnalysisTrainNew", "AliAnalysisTaskKinkResonance cannot run for this train conditions - EXCLUDED");
271 gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonanceLikeSign.C");
272 AliResonanceKinkLikeSign *taskkinklikesign = AddTaskKinkResonanceLikeSign();
273 if (!taskkinklikesign) ::Warning("AnalysisTrainNew", "AliResonanceKinkLikeSign cannot run for this train conditions - EXCLUDED");
276 // Event characterization
278 gROOT->LoadMacro("$ALICE_ROOT/PWG2/EVCHAR/macros/AddTaskSPDdNdEta.C");
279 AliAnalysisTaskSPDdNdEta *taskspddndeta = AddTaskSPDdNdEta();
280 if (!taskspddndeta) ::Warning("AnalysisTrainNew", "AliAnalysisTaskSPDdNdEta cannot run for this train conditions - EXCLUDED");
281 taskspddndeta->SetReadMC(useMC);
286 gROOT->LoadMacro("$ALICE_ROOT/PWG2/UNICOR/AddTaskUnicor.C");
287 AliAnalysisTaskUnicor *taskunicor = AddTaskUnicor();
288 if (!taskspddndeta) ::Warning("AnalysisTrainNew", "AliAnalysisTaskUnicor cannot run for this train conditions - EXCLUDED");
293 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FLOW/macros/AddTaskFlow.C");
295 Bool_t LYZ1SUM = kTRUE;
296 Bool_t LYZ1PROD = kTRUE;
297 Bool_t LYZ2SUM = kFALSE;
298 Bool_t LYZ2PROD = kFALSE;
299 Bool_t LYZEP = kFALSE;
303 Bool_t MCEP = kFALSE; //does not work yet 24/12/08
304 Bool_t kineFromESD = kTRUE;
305 Bool_t METHODS[] = {SP,LYZ1SUM,LYZ1PROD,LYZ2SUM,LYZ2PROD,LYZEP,GFC,QC,FQD,MCEP};
306 // Analysis type can be ESD, AOD, MC, ESDMC0, ESDMC1
307 TString type = "AOD";
308 if (!iAODanalysis) type = "ESD";
311 if (!kineFromESD) type += "1";
314 // Boolean to fill/not fill the QA histograms
316 // Boolean to use/not use weights for the Q vector
317 Bool_t WEIGHTS[] = {kFALSE,kFALSE,kFALSE}; //Phi, v'(pt), v'(eta)
318 AliAnalysisTaskFlowEvent* taskFE = AddTaskFlow(type,METHODS,QA,WEIGHTS);
319 if (!taskFE) ::Warning("AnalysisTrainNew", "AliAnalysisTaskFlowEvent cannot run for this train conditions - EXCLUDED");
324 gROOT->LoadMacro("$ALICE_ROOT/PWG2/RESONANCES/macros/AddAnalysisTaskRsn.C");
325 AddAnalysisTaskRsn(AliLog::kError, kFALSE, "output_rsn.root", !(Bool_t)iAODhandler);
329 if (iPWG3vertexing) {
330 gROOT->LoadMacro("$ALICE_ROOT/PWG3/vertexingHF/AddTaskVertexingHF.C");
331 AliAnalysisTaskSEVertexingHF *taskvertexingHF = AddTaskVertexingHF();
332 if (!taskvertexingHF) ::Warning("AnalysisTrainNew", "AliAnalysisTaskSEVertexingHF cannot run for this train conditions - EXCLUDED");
335 // PWG4 hadron correlations
337 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
338 AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS");
339 if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
340 AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL");
341 if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
344 // PWG4 gamma conversion analysis
345 if (iPWG4gammaconv) {
346 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
348 TString arguments = " -data-list "+ fileIn+ " -output-file-name common" + " -run-on-train"+" -run-jet"+" -run-chic"+" -run-neutralmeson";
349 AliAnalysisTaskGammaConversion * taskGammaConversion = AddTaskGammaConversion(arguments,mgr->GetCommonInputContainer());
350 if (!taskGammaConversion) ::Warning("AnalysisTrainNew", "AliAnalysisTaskGammaConversion cannot run for these train conditions - EXCLUDED");
352 //==========================================================================
353 // FOR THE REST OF THE TASKS THE MACRO AddTaskXXX() is not yet implemented/
356 if (mgr->InitAnalysis()) {
358 if (saveTrain || strlen(config_file)) gSystem->ChangeDirectory(train_name);
359 StartAnalysis(smode, chain);
360 if (saveTrain && smode=="GRID") {
361 printf("=== Registering ConfigTrain.C in the output directory <%s> ===\n",
362 alien_outdir.Data());
363 TFile::Cp("file:ConfigTrain.C", Form("alien://%s/ConfigTrain.C", alien_outdir.Data()));
368 //______________________________________________________________________________
369 void StartAnalysis(const char *mode, TChain *chain) {
372 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
373 if (!strcmp(mode, "LOCAL")) imode = 0;
374 if (!strcmp(mode, "PROOF")) imode = 1;
375 if (!strcmp(mode, "GRID")) imode = 2;
379 ::Error("AnalysisTrainNew.C::StartAnalysis", "Cannot create the chain");
382 mgr->StartAnalysis(mode, chain);
385 if (!proof_dataset.Length()) {
386 ::Error("AnalysisTrainNew.C::StartAnalysis", "proof_dataset is empty");
389 mgr->StartAnalysis(mode, proof_dataset, 1000);
393 if (!mgr->GetGridHandler()) {
394 ::Error("AnalysisTrainNew.C::StartAnalysis", "Grid plugin not initialized");
397 mgr->StartAnalysis("grid");
400 ::Error("AnalysisTrainNew.C::StartAnalysis", "Cannot create the chain");
403 mgr->StartAnalysis(mode, chain);
409 //______________________________________________________________________________
410 void CheckModuleFlags(const char *mode) {
411 // Checks selected modules and insure compatibility
413 if (!strcmp(mode, "LOCAL")) imode = 0;
414 if (!strcmp(mode, "PROOF")) imode = 1;
415 if (!strcmp(mode, "GRID")) imode = 2;
418 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
423 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
429 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "MC usage disabled in analysis on AOD's");
433 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "ESD filter disabled in analysis on AOD's");
437 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "JETAN disabled in analysis on AOD's without AOD handler");
440 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "iPWG4gammaconv disabled on AOD's");
442 // Disable tasks that do not work yet on AOD data
444 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2kink disabled in analysis on AOD's");
447 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2unicor disabled in analysis on AOD's");
452 if (!useMC) useTR = kFALSE;
454 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "iPWG2evchar disabled if not reading track references");
458 if (iJETAN) iESDfilter=1;
459 if (iESDfilter) iAODhandler=1;
460 if (iPWG2spectra || iPWG2flow || iPWG3vertexing) useCORRFW = kTRUE;
461 if (useKFILTER && !useMC) useKFILTER = kFALSE;
462 if (useAODTAGS && !iAODhandler) useAODTAGS = kFALSE;
465 //______________________________________________________________________________
466 Bool_t Connect(const char *mode) {
467 // Connect <username> to the back-end system.
469 if (!strcmp(mode, "LOCAL")) imode = 0;
470 if (!strcmp(mode, "PROOF")) imode = 1;
471 if (!strcmp(mode, "GRID")) imode = 2;
472 TString username = gSystem->Getenv("alien_API_USER");
477 if (!username.Length()) {
478 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Make sure you:\n \
479 1. Have called: alien-token-init <username>\n \
480 2. Have called: >source /tmp/gclient_env_$UID");
483 ::Info("AnalysisTrainNew.C::Connect", "Connecting user <%s> to PROOF cluster <%s>",
484 username.Data(), proof_cluster.Data());
485 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
486 // TProof::Open(Form("%s@%s:31093", username.Data(), proof_cluster.Data()));
487 TProof::Open(Form("%s@%s", username.Data(), proof_cluster.Data()));
489 if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
490 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
493 TGrid::Connect("alien://");
495 TString homedir = gGrid->GetHomeDirectory();
496 TString workdir = homedir + train_name;
497 if (!gGrid->Cd(workdir)) {
499 if (gGrid->Mkdir(workdir)) {
500 gGrid->Cd(train_name);
501 ::Info("AnalysisTrainNew::Connect()", "Directory %s created", gGrid->Pwd());
504 gGrid->Mkdir("proof_output");
505 gGrid->Cd("proof_output");
506 proof_outdir = Form("alien://%s", gGrid->Pwd());
510 if (!username.Length()) {
511 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Make sure you:\n \
512 1. Have called: alien-token-init <username>\n \
513 2. Have called: >source /tmp/gclient_env_$UID");
516 if (usePLUGIN && !gSystem->Getenv("alien_CLOSE_SE")) {
517 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode),
518 "When using the AliEn plugin it is preferable to define the \
519 variable alien_CLOSE_SE in your environment.");
522 ::Info("AnalysisTrainNew.C::Connect", "Connecting user <%s> to AliEn ...",
524 TGrid::Connect("alien://");
525 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
528 ::Error("AnalysisTrainNew.C::Connect", "Unknown run mode: %s", mode);
531 ::Info("AnalysisTrainNew.C::Connect","Connected in %s mode", mode);
535 //______________________________________________________________________________
536 Bool_t LoadCommonLibraries(const char *mode)
538 // Load common analysis libraries.
540 if (!strcmp(mode, "LOCAL")) imode = 0;
541 if (!strcmp(mode, "PROOF")) imode = 1;
542 if (!strcmp(mode, "GRID")) imode = 2;
543 if (!gSystem->Getenv("ALICE_ROOT")) {
544 ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
547 Bool_t success = kTRUE;
549 gSystem->Load("libTree.so");
550 gSystem->Load("libGeom.so");
551 gSystem->Load("libVMC.so");
552 gSystem->Load("libPhysics.so");
554 // Load framework classes. Par option ignored here.
559 success &= LoadLibrary("STEERBase", mode, kTRUE);
560 success &= LoadLibrary("ESD", mode, kTRUE);
561 success &= LoadLibrary("AOD", mode, kTRUE);
562 success &= LoadLibrary("ANALYSIS", mode, kTRUE);
563 success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
564 if (useCORRFW) success &= LoadLibrary("CORRFW", mode, kTRUE);
566 success &= LoadLibrary("libSTEERBase.so", mode);
567 success &= LoadLibrary("libESD.so", mode);
568 success &= LoadLibrary("libAOD.so", mode);
569 success &= LoadLibrary("libANALYSIS.so", mode);
570 success &= LoadLibrary("libANALYSISalice.so", mode);
571 if (useCORRFW) success &= LoadLibrary("libCORRFW.so", mode);
572 gROOT->ProcessLine(".include $ALICE_ROOT/include");
577 if (useAFPAR && !gSystem->AccessPathName(AFversion)) ires = gProof->UploadPackage(AFversion);
579 success &= LoadLibrary("STEERBase", mode);
580 success &= LoadLibrary("ESD", mode);
581 success &= LoadLibrary("AOD", mode);
582 success &= LoadLibrary("ANALYSIS", mode);
583 success &= LoadLibrary("ANALYSISalice", mode);
584 if (useCORRFW) success &= LoadLibrary("CORRFW", mode);
586 ires = gProof->EnablePackage(AFversion);
587 if (ires<0) success = kFALSE;
588 if (useCORRFW) success &= LoadLibrary("CORRFW", mode);
592 ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
596 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
597 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
598 gSystem->GetIncludePath());
600 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries: FAILED");
606 //______________________________________________________________________________
607 Bool_t LoadAnalysisLibraries(const char *mode)
609 // Load common analysis libraries.
610 Bool_t success = kTRUE;
612 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
613 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
617 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
619 // PWG4 particle correlations
621 if (!LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
622 !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
624 // PWG4 gamma conversion
625 if (iPWG4gammaconv) {
626 if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
630 if (!LoadLibrary("PWG2spectra", mode, kTRUE)) return kFALSE;
634 if (!LoadLibrary("PWG2flowCommon", mode, kTRUE) ||
635 !LoadLibrary("PWG2flowTasks", mode, kTRUE)) return kFALSE;
639 if (!LoadLibrary("PWG2resonances", mode, kTRUE)) return kFALSE;
643 if (!LoadLibrary("PWG2kink", mode, kTRUE)) return kFALSE;
647 if (!LoadLibrary("PWG2unicor", mode, kTRUE)) return kFALSE;
651 if (!LoadLibrary("PWG2evchar", mode, kTRUE)) return kFALSE;
655 if (!LoadLibrary("PWG2AOD", mode, kTRUE) ||
656 !LoadLibrary("PWG2femtoscopy", mode, kTRUE) ||
657 !LoadLibrary("PWG2femtoscopyUser", mode, kTRUE)) return kFALSE;
658 TFile::Cp(gSystem->ExpandPathName("$(ALICE_ROOT)/PWG2/FEMTOSCOPY/macros/ConfigFemtoAnalysis.C"), Form("%s/ConfigFemtoAnalysis.C", train_name.Data()));
659 anaLibs += "ConfigFemtoAnalysis.C ";
662 if (iPWG3vertexing) {
663 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
664 !LoadLibrary("PWG3vertexingHF", mode, kTRUE)) return kFALSE;
666 ::Info("AnalysisTrainNew.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
670 //______________________________________________________________________________
671 Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
673 // Load a module library in a given mode. Reports success.
676 TString smodule(module);
677 if (!strcmp(mode, "LOCAL")) imode = 0;
678 if (!strcmp(mode, "PROOF")) imode = 1;
679 if (!strcmp(mode, "GRID")) imode = 2;
682 ::Error("AnalysisTrainNew.C::LoadLibrary", "Empty module name");
685 // If a library is specified, just load it
686 if (smodule.EndsWith(".so")) {
687 mod.Remove(mod.Index(".so"));
688 result = gSystem->Load(mod);
690 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load library %s", module);
693 if (rec) anaLibs += Form("%s.so ",mod.Data());
696 // Check if the library is already loaded
697 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
703 result = SetupPar(module);
704 if (rec) anaPars += Form("%s.par ", module);
706 result = gSystem->Load(Form("lib%s.so", module));
707 if (rec) anaLibs += Form("lib%s.so ", module);
711 result = gProof->UploadPackage(module);
713 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
715 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
719 result = gProof->EnablePackage(module);
725 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load module %s", module);
732 //______________________________________________________________________________
733 TChain *CreateChain(const char *mode, const char *plugin_mode)
735 // Create the input chain
737 if (!strcmp(mode, "LOCAL")) imode = 0;
738 if (!strcmp(mode, "PROOF")) imode = 1;
739 if (!strcmp(mode, "GRID")) imode = 2;
740 TChain *chain = NULL;
745 if (!local_xmldataset.Length()) {
747 chain = new TChain("aodTree");
748 if (gSystem->AccessPathName("data/AliAOD.root"))
749 ::Error("AnalysisTrainNew.C::CreateChain", "File: AliAOD.root not in ./data dir");
751 if (!saveTrain) chain->Add("data/AliAOD.root");
752 else chain->Add("../data/AliAOD.root");
756 chain = CreateChainSingle(local_xmldataset, "aodTree");
759 if (!local_xmldataset.Length()) {
761 chain = new TChain("esdTree");
762 if (gSystem->AccessPathName("data/AliESDs.root"))
763 ::Error("AnalysisTrainNew.C::CreateChain", "File: AliESDs.root not in ./data dir");
765 if (!saveTrain) chain->Add("data/AliESDs.root");
766 else chain->Add("../data/AliESDs.root");
770 chain = CreateChainSingle(local_xmldataset, "esdTree");
778 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
779 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
781 TString treeName = "esdTree";
782 if (iAODanalysis) treeName = "aodTree";
783 chain = CreateChainSingle("wn.xml", treeName);
788 if (chain && chain->GetNtrees()) return chain;
792 //______________________________________________________________________________
793 TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
795 printf("*******************************\n");
796 printf("*** Getting the ESD Chain ***\n");
797 printf("*******************************\n");
798 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
801 ::Error("AnalysisTrainNew.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
805 TChain* chain = new TChain(treeName);
806 myCollection->Reset() ;
807 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
812 //______________________________________________________________________________
813 Int_t SetupPar(char* pararchivename)
815 if (!pararchivename || !strlen(pararchivename)) return -1;
816 char processline[1024];
817 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
818 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
819 ::Info("AnalysisTrainNew.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
820 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
821 Form("%s.par",pararchivename));
823 ::Error("AnalysisTrainNew.C::SetupPar", "Cannot find %s.par", pararchivename);
827 if (usePLUGIN && saveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, train_name.Data()));
828 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
830 TString ocwd = gSystem->WorkingDirectory();
831 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
833 // check for BUILD.sh and execute
834 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
835 printf("*******************************\n");
836 printf("*** Building PAR archive ***\n");
837 printf("*******************************\n");
838 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
839 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
844 // check for SETUP.C and execute
845 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
846 printf("*******************************\n");
847 printf("*** Setup PAR archive ***\n");
848 printf("*******************************\n");
849 gROOT->Macro("PROOF-INF/SETUP.C");
851 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
855 //______________________________________________________________________________
856 AliAnalysisGrid* CreateAlienHandler(const char *plugin_mode)
858 // Check if user has a valid token, otherwise make one. This has limitations.
859 // One can always follow the standard procedure of calling alien-token-init then
860 // source /tmp/gclient_env_$UID in the current shell.
861 if (!AliAnalysisGrid::CreateToken()) return NULL;
862 AliAnalysisAlien *plugin = new AliAnalysisAlien();
863 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
864 plugin->SetRunMode(plugin_mode);
865 plugin->SetNtestFiles(1);
866 plugin->SetPreferedSE("ALICE::Legnaro::SE");
867 // Set versions of used packages
868 plugin->SetAPIVersion("V2.4");
869 plugin->SetROOTVersion(root_version);
870 plugin->SetAliROOTVersion(aliroot_version);
871 // Declare input data to be processed.
872 // Method 1: Create automatically XML collections using alien 'find' command.
873 // Define production directory LFN
874 plugin->SetGridDataDir(alien_datadir);
875 // Set data search pattern
876 if (iAODanalysis) plugin->SetDataPattern("*AliAOD.root");
877 else plugin->SetDataPattern("*ESD.tag.root");
878 // ...then add run numbers to be considered
879 plugin->SetRunRange(run_range[0], run_range[1]);
880 // for (Int_t i=0; i<10; i++) {
881 // if (run_numbers[i]==0) break;
882 // plugin->AddRunNumber(run_numbers[i]);
884 // Method 2: Declare existing data files (raw collections, xml collections, root file)
885 // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
886 // XML collections added via this method can be combined with the first method if
887 // the content is compatible (using or not tags)
888 // plugin->AddDataFile("tag.xml");
889 // plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
890 // Define alien work directory where all files will be copied. Relative to alien $HOME.
891 if (iAODanalysis) plugin->SetGridWorkingDir("analysisAOD");
892 else plugin->SetGridWorkingDir("analysisESD");
893 // Declare alien output directory. Relative to working directory.
894 if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
895 plugin->SetGridOutputDir(alien_outdir);
897 TString ana_sources = "";
898 TString ana_add = "";
899 if (usePAR && anaPars.Length()) {
900 printf("%s\n", anaPars.Data());
903 arr = anaPars.Tokenize(" ");
905 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
909 // Declare the analysis source files names separated by blancs. To be compiled runtime
910 // using ACLiC on the worker nodes.
911 ana_sources = ana_sources.Strip();
912 // Declare all libraries (other than the default ones for the framework. These will be
913 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
914 anaLibs = anaLibs.Strip();
915 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
916 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs);
918 // Declare the output file names separated by blancs.
919 // (can be like: file.root or file.root@ALICE::Niham::File)
920 plugin->SetDefaultOutputs();
921 plugin->SetMergeExcludes(mergeExclude);
922 plugin->SetMaxMergeFiles(maxMergeFiles);
923 plugin->SetNrunsPerMaster(nRunsPerMaster);
924 // Optionally define the files to be archived.
925 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:*.root@ALICE::NIHAM::File");
926 plugin->SetOutputArchive("log_archive.zip:stdout,stderr");
927 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
928 plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
929 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
930 plugin->SetSplitMaxInputFileNumber(nFilesPerJob);
931 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
932 // plugin->SetMaxInitFailed(5);
933 // Optionally resubmit threshold.
934 // plugin->SetMasterResubmitThreshold(90);
935 // Optionally set time to live (default 30000 sec)
936 plugin->SetTTL(30000);
937 // Optionally set input format (default xml-single)
938 plugin->SetInputFormat("xml-single");
939 // Optionally modify the name of the generated JDL (default analysis.jdl)
940 plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
941 // Optionally modify the executable name (default analysis.sh)
942 plugin->SetExecutable(Form("%s.sh", train_name.Data()));
943 // Optionally modify job price (default 1)
945 // Optionally modify split mode (default 'se')
946 plugin->SetSplitMode("se");
950 //______________________________________________________________________________
953 // Write train configuration in a file. The file name has the format:
954 // train_[trainName]_ddMonthyyyy_time.C
955 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
956 ifstream fdate("date.tmp");
957 if (!fdate.is_open()) {
958 ::Error("AnalysisTrainNew.C::Export","Could not generate file name");
963 fdate.getline(date,64);
965 gSystem->Exec("rm date.tmp");
966 train_name = Form("train_%s_%s", train_name.Data(), date);
968 train_name = Form("train_%s", train_name.Data());
970 TString cdir = gSystem->WorkingDirectory();
971 gSystem->MakeDirectory(train_name);
972 gSystem->ChangeDirectory(train_name);
974 out.open("ConfigTrain.C", ios::out);
976 ::Error("AnalysisTrainNew.C::Export", "Cannot open ConfigTrain.C for writing");
980 out << " train_name = " << "\"" << train_name.Data() << "\";" << endl;
981 out << " proof_cluster = " << "\"" << proof_cluster.Data() << "\";" << endl;
982 out << " useAFPAR = " << useAFPAR << ";" << endl;
984 out << " AFversion = " << AFversion.Data() << ";" << endl;
985 out << " proof_dataset = " << "\"" << proof_dataset.Data() << "\";" << endl;
986 out << " usePLUGIN = " << usePLUGIN << ";" << endl;
987 out << " usePAR = " << usePAR << ";" << endl;
988 out << " useCPAR = " << useCPAR << ";" << endl;
989 out << " root_version = " << "\"" << root_version.Data() << "\";" << endl;
990 out << " aliroot_version = " << "\"" << aliroot_version.Data() << "\";" << endl;
991 out << " alien_datadir = " << "\"" << alien_datadir.Data() << "\";" << endl;
992 if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
993 out << " alien_outdir = " << "\"" << alien_outdir.Data() << "\";" << endl;
994 out << " maxMergeFiles = " << maxMergeFiles << ";" << endl;
995 out << " mergeExclude = " << "\"" << mergeExclude.Data() << "\";" << endl;
996 out << " nRunsPerMaster = " << nRunsPerMaster << ";" << endl;
997 out << " nFilesPerJob = " << nFilesPerJob << ";" << endl;
998 // for (Int_t i=0; i<10; i++) {
999 // if (run_numbers[i])
1000 // out << " run_numbers[" << i << "] = " << run_numbers[i] << ";" << endl;
1002 out << " run_range[0] = " << run_range[0] << ";" << endl;
1003 out << " run_range[1] = " << run_range[1] << ";" << endl;
1004 out << " useDBG = " << useDBG << ";" << endl;
1005 out << " useMC = " << useMC << ";" << endl;
1006 out << " useTAGS = " << useTAGS << ";" << endl;
1007 out << " useKFILTER = " << useKFILTER << ";" << endl;
1008 out << " useTR = " << useTR << ";" << endl;
1009 out << " useCORRFW = " << useCORRFW << ";" << endl;
1010 out << " useAODTAGS = " << useAODTAGS << ";" << endl;
1011 out << " saveTrain = " << "kFALSE;" << endl << endl;
1012 out << " // Analysis modules" << endl;
1013 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
1014 out << " iAODhandler = " << iAODhandler << ";" << endl;
1015 out << " iESDfilter = " << iESDfilter << ";" << endl;
1016 out << " iMUONcopyAOD = " << iMUONcopyAOD << ";" << endl;
1017 out << " iJETAN = " << iJETAN << ";" << endl;
1018 out << " iPWG4partcorr = " << iPWG4partcorr << ";" << endl;
1019 out << " iPWG4gammaconv = " << iPWG4gammaconv << ";" << endl;
1020 out << " iPWG2femto = " << iPWG2femto << ";" << endl;
1021 out << " iPWG2spectra = " << iPWG2spectra << ";" << endl;
1022 out << " iPWG2flow = " << iPWG2flow << ";" << endl;
1023 out << " iPWG2res = " << iPWG2res << ";" << endl;
1024 out << " iPWG2kink = " << iPWG2kink << ";" << endl;
1025 out << " iPWG2unicor = " << iPWG2unicor << ";" << endl;
1026 out << " iPWG2evchar = " << iPWG2evchar << ";" << endl;
1028 ::Info("AnalysisTrainNew.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", train_name.Data()));
1029 gSystem->ChangeDirectory(cdir);
1032 //______________________________________________________________________________
1033 Bool_t LoadConfig(const char *filename)
1035 // Read train configuration from file
1036 if (gSystem->AccessPathName(filename)) {
1037 ::Error("AnalysisTrainNew.C::LoadConfig", "Config file name not found");
1040 gROOT->ProcessLine(Form(".x %s", filename));
1041 ::Info("AnalysisTrainNew.C::LoadConfig", "Train configuration loaded from file %s", filename);