Added possibility to save canvases created by Terminate as pictures.
[u/mrichter/AliRoot.git] / ANALYSIS / macros / AnalysisTrainNew.C
CommitLineData
a42c0df6 1//===================== ANALYSIS TRAIN =========================================
c6e7c68c 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.
a42c0df6 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")
c6e7c68c 17
a42c0df6 18//================== TRAIN NAME ============================================
6e428ea7 19TString train_name = "LHC09a4ESDanalysis"; // *CHANGE ME* (no blancs or special characters)
20//TString job_tag = "LHC09a4: standard AODs with MC info, AOD tags and vertexing HF delta AODs with v4-18-07-AN"; // *CHANGE ME*
21TString job_tag = "Standard analysis train configured for ESD+MC without AOD producers"; // *CHANGE ME*
a42c0df6 22//==============================================================================
23
24// ### Settings that make sense in PROOF only
25//==============================================================================
26TString proof_cluster = "alicecaf.cern.ch";
27Bool_t useAFPAR = kFALSE; // use AF special par file
6e428ea7 28TString AFversion = "AF-v4-17";
7581b1bc 29// Change CAF dataset here
a42c0df6 30TString proof_dataset = "/COMMON/COMMON/LHC09a4_run8100X#/esdTree";
b160b576 31TString proof_outdir = "";
c6e7c68c 32
a42c0df6 33// ### Settings that make sense when using the Alien plugin
34//==============================================================================
35Bool_t usePLUGIN = kTRUE; // do not change
5c4c538a 36Bool_t useProductionMode = kTRUE; // use the plugin in production mode
a42c0df6 37// Usage of par files ONLY in grid mode and ONLY if the code is not available
7581b1bc 38// in the deployed AliRoot versions. Par file search path: local dir, if not there $ALICE_ROOT.
39// To refresh par files, remove the ones in the workdir, then do "make <target.par>" in
40// AliRoot.
a42c0df6 41Bool_t usePAR = kFALSE; // use par files for extra libs
42Bool_t useCPAR = kFALSE; // use par files for common libs
6e428ea7 43TString root_version = "v5-25-02"; // *CHANGE ME IF MORE RECENT IN GRID*
44TString aliroot_version = "v4-18-08-AN"; // *CHANGE ME IF MORE RECENT IN GRID*
a42c0df6 45// Change production base directory here
2a47e7b4 46TString alien_datadir = "/alice/sim/PDC_09/LHC09a4/";
371c967e 47// AliEn output directory. If blank will become output_<train_name>
6e428ea7 48TString alien_outdir = "/alice/sim/PDC_09/LHC09a4/analysis/ESD/train1";
526b1502 49// TString alien_outdir = "";
275942e0 50// Number of files merged in a chunk
51Int_t maxMergeFiles = 50;
52// Files that should not be merged
0d5d317c 53TString mergeExclude = "AliAOD.root AliAOD.VertexingHF.root";
6e428ea7 54// Make replicas on the storages below
55TString outputStorages = "ALICE::NIHAM::File,ALICE::CNAF::SE,ALICE::FZK::SE,ALICE::GSI::SE,ALICE::Legnaro::SE";
275942e0 56// Number of runs per master job
2a47e7b4 57Int_t nRunsPerMaster = 10;
275942e0 58// Maximum number of files per job (gives size of AOD)
2a47e7b4 59Int_t nFilesPerJob = 200;
275942e0 60// Set the run range
2a47e7b4 61Int_t run_range[2] = {81000, 81656}; // LHC09a4 *CHANGE ME*
6e428ea7 62//Int_t run_range[2] = {90000, 90001}; // LHC09a5
a42c0df6 63// ### Settings that make sense only for local analysis
64//==============================================================================
65// Change local xml dataset for local interactive analysis
66TString local_xmldataset = "";
c6e7c68c 67
a42c0df6 68// ### Other flags to steer the analysis
69//==============================================================================
371c967e 70Bool_t useDATE = kFALSE; // use date in train name
2a47e7b4 71Bool_t useDBG = kFALSE; // activate debugging
a42c0df6 72Bool_t useMC = kTRUE; // use MC info
73Bool_t useTAGS = kFALSE; // use ESD tags for selection
6e428ea7 74Bool_t useKFILTER = kFALSE; // use Kinematics filter
75Bool_t useTR = kTRUE; // use track references
a42c0df6 76Bool_t useCORRFW = kFALSE; // do not change
6e428ea7 77Bool_t useAODTAGS = kFALSE; // use AOD tags
a42c0df6 78Bool_t saveTrain = kTRUE; // save train configuration as:
b160b576 79Bool_t saveProofToAlien = kFALSE; // save proof outputs in AliEn
a42c0df6 80 // train_[trainName]_ddMonthyyyy_time.C
81// ### Analysis modules to be included. Some may not be yet fully implemented.
82//==============================================================================
83Int_t iAODanalysis = 0; // Analysis on input AOD's
6e428ea7 84Int_t iAODhandler = 0; // Analysis produces an AOD or dAOD's
85Int_t iESDfilter = 0; // ESD to AOD filter (barrel + muon tracks)
a42c0df6 86Int_t iMUONcopyAOD = 0; // Task that copies only muon events in a separate AOD (PWG3)
526b1502 87Int_t iJETAN = 0; // Jet analysis (PWG4) - needs ESD filter
88Int_t iPWG4partcorr = 0; // Gamma-hadron correlations task (PWG4)
6e428ea7 89Int_t iPWG4gammaconv = 1; // Gamma conversion analysis (PWG4) # NOT YET WORKING - WAITING FOR FEEDBACK #
90Int_t iPWG4omega3pi = 1; // Omega to 3 pi analysis (PWG4)
91Int_t iPWG3vertexing = 0; // Vertexing HF task (PWG2)
92Int_t iPWG3hfe = 1; // Electrons analysis (PWG3)
93Int_t iPWG2femto = 1; // Femtoscopy task (PWG2)
94Int_t iPWG2spectra = 1; // Spectra tasks (PWG2
95Int_t iPWG2protons = 1; // Proton-antiproton analysis
96Int_t iPWG2checkcascade = 1; // Check cascades task
97Int_t iPWG2perfcascade = 1; // Check performance cascade
98Int_t iPWG2checkv0 = 1; // Check V0 task
99Int_t iPWG2strange = 1; // Strangeness task
100Int_t iPWG2flow = 1; // Flow analysis tasks (PWG2) = crashes in AliCFManager
101Int_t iPWG2res = 1; // Resonances task (PWG2)
102Int_t iPWG2kink = 1; // Kink analysis tasks (PWG2)
103Int_t iPWG2kinkESDMC = 1; // Kink ESD-MC comparison (PWG2)
104Int_t iPWG2kinkres = 1; // Kink resonances (PWG2)
105Int_t iPWG2kinklikesign = 1; // Kink like-sign (PWG2)
106Int_t iPWG2evchar = 1; // Event characteristics (PWG2)
107Int_t iPWG2unicor = 1; // Unicor analysis (PWG2)
108Int_t iPWG2forward = 0; // FMD analysis (PWG2)
109
110// ### Configuration macros used for each module
111//==============================================================================
112TString configPWG2femto = "$ALICE_ROOT/PWG2/FEMTOSCOPY/macros/Train/Train3/ConfigFemtoAnalysis.C";
a42c0df6 113
114// Temporaries.
c6e7c68c 115TString anaPars = "";
116TString anaLibs = "";
117// Function signatures
5c4c538a 118class AliAnalysisAlien;
c6e7c68c 119
120//______________________________________________________________________________
a42c0df6 121void AnalysisTrainNew(const char *analysis_mode="grid",
122 const char *plugin_mode="full",
123 const char *config_file="")
c6e7c68c 124{
a42c0df6 125// Main analysis train macro. If a configuration file is provided, all parameters
126// are taken from there but may be altered by CheckModuleFlags.
127 if (strlen(config_file) && !LoadConfig(config_file)) return;
c6e7c68c 128 TString smode(analysis_mode);
a42c0df6 129 smode.ToUpper();
130 if (saveTrain) WriteConfig();
c6e7c68c 131 // Check compatibility of selected modules
132 CheckModuleFlags(smode);
133
134 printf("==================================================================\n");
a42c0df6 135 printf("=========== RUNNING ANALYSIS TRAIN %s IN %s MODE ==========\n", train_name.Data(),smode.Data());
c6e7c68c 136 printf("==================================================================\n");
137 printf("= Configuring analysis train for: =\n");
138 if (iAODanalysis) printf("= AOD analysis =\n");
139 else printf("= ESD analysis =\n");
140 if (iESDfilter) printf("= ESD filter =\n");
c6e7c68c 141 if (iMUONcopyAOD) printf("= MUON copy AOD =\n");
142 if (iJETAN) printf("= Jet analysis =\n");
0d5d317c 143 if (iPWG2spectra) {
144 printf("= PWG2 SPECTRA tasks : =\n");
145 if (iPWG2protons) printf("= PWG2 proton-antiproton =\n");
146 if (iPWG2checkcascade) printf("= PWG2 check cascades =\n");
147 if (iPWG2perfcascade) printf("= PWG2 performance cascades =\n");
148 if (iPWG2checkv0) printf("= PWG2 check V0 =\n");
149 if (iPWG2strange) printf("= PWG2 strangeness =\n");
150 }
6e428ea7 151 if (iPWG2femto) {
152 printf("= PWG2 femtoscopy =\n");
153 printf(" +++ configured by: %s\n", configPWG2femto.Data());
154 }
c6e7c68c 155 if (iPWG2flow) printf("= PWG2 flow =\n");
156 if (iPWG2res) printf("= PWG2 resonances =\n");
0d5d317c 157 if (iPWG2kink) {
158 printf("= PWG2 kink analysis tasks: =\n");
159 if (iPWG2kinkESDMC) printf("= PWG2 ESD-MC kinks =\n");
160 if (iPWG2kinkres) printf("= PWG2 kink resonances =\n");
161 if (iPWG2kinklikesign) printf("= PWG2 kink like-sign analysis =\n");
162 }
6e428ea7 163 if (iPWG2evchar) printf("= PWG2 event characteristics =\n");
164 if (iPWG2unicor) printf("= PWG2 Unicor analysis =\n");
165 if (iPWG2forward) printf("= PWG2 forward: sharing, density, bkg. correction, dNdEta =\n");
166 if (iPWG3vertexing) printf("= PWG3 vertexing =\n");
167 if (iPWG3hfe) printf("= PWG3 electrons =\n");
168 if (iPWG4partcorr) printf("= PWG4 gamma-hadron, pi0 and gamma-jet correlations =\n");
169 if (iPWG4gammaconv) printf("= PWG4 gamma conversion =\n");
170 if (iPWG4omega3pi) printf("= PWG4 omega to 3 pions =\n");
c6e7c68c 171 printf("==================================================================\n");
172 printf(":: use MC truth %d\n", (UInt_t)useMC);
099d8f33 173 printf(":: use KINE filter %d\n", (UInt_t)useKFILTER);
c6e7c68c 174 printf(":: use track refs %d\n", (UInt_t)useTR);
099d8f33 175 printf(":: use tags %d\n", (UInt_t)useTAGS);
176 printf(":: use AOD tags %d\n", (UInt_t)useAODTAGS);
c6e7c68c 177 printf(":: use debugging %d\n", (UInt_t)useDBG);
178 printf(":: use PAR files %d\n", (UInt_t)usePAR);
179 printf(":: use AliEn plugin %d\n", (UInt_t)usePLUGIN);
180
b160b576 181 //==========================================================================
c6e7c68c 182 // Connect to back-end system
183 if (!Connect(smode)) {
184 ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode);
185 return;
186 }
187
188 // Load common libraries and set include path
189 if (!LoadCommonLibraries(smode)) {
190 ::Error("AnalysisTrain", "Could not load common libraries");
191 return;
b160b576 192 }
c6e7c68c 193
b160b576 194 // Make the analysis manager and connect event handlers
195 AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train", "Production train");
196 if (saveProofToAlien) mgr->SetSpecialOutputLocation(proof_outdir);
6e428ea7 197 if (!strcmp(plugin_mode, "test")) mgr->SetNSysInfo(1);
c6e7c68c 198 // Load analysis specific libraries
199 if (!LoadAnalysisLibraries(smode)) {
200 ::Error("AnalysisTrain", "Could not load analysis libraries");
201 return;
202 }
203
c6e7c68c 204 // Create input handler (input container created automatically)
205 if (iAODanalysis) {
206 // AOD input handler
207 AliAODInputHandler *aodH = new AliAODInputHandler();
208 mgr->SetInputEventHandler(aodH);
209 } else {
210 // ESD input handler
211 AliESDInputHandler *esdHandler = new AliESDInputHandler();
099d8f33 212 if (useTAGS) esdHandler->SetReadTags();
c6e7c68c 213 mgr->SetInputEventHandler(esdHandler);
214 }
215 // Monte Carlo handler
216 if (useMC && !iAODanalysis) {
217 AliMCEventHandler* mcHandler = new AliMCEventHandler();
218 mgr->SetMCtruthEventHandler(mcHandler);
219 mcHandler->SetReadTR(useTR);
220 }
221 // AOD output container, created automatically when setting an AOD handler
222 if (iAODhandler) {
223 // AOD output handler
224 AliAODHandler* aodHandler = new AliAODHandler();
b160b576 225 aodHandler->SetOutputFileName("AliAOD.root");
c6e7c68c 226 mgr->SetOutputEventHandler(aodHandler);
b160b576 227 if (iAODanalysis) {
228 aodHandler->SetCreateNonStandardAOD();
526b1502 229 if (iJETAN) aodHandler->SetOutputFileName("AliAOD.Jets.root");
b160b576 230 if (iPWG3vertexing) aodHandler->SetOutputFileName("AliAOD.VertexingHF.root");
231 }
c6e7c68c 232 }
233 // Debugging if needed
234 if (useDBG) mgr->SetDebugLevel(3);
235
236 //==========================================================================
237 // Create the chain. In this example it is created only from ALIEN files but
238 // can be done to work in batch or grid mode as well.
239 TChain *chain = CreateChain(smode, plugin_mode);
240
241 //==========================================================================
242 // Load the tasks configuration macros for all wagons. These files are supposed now to be
243 // in the current workdir, but in AliEn they will be in the file catalog,
244 // mapped from AliRoot and pecified in the jdl input list.
245
246 // For now connection to top input container and common AOD output container
247 // is done in this macro, but in future these containers will be connected
248 // from each task configuration macro.
249
250 if (iESDfilter && !iAODanalysis) {
251 // ESD filter task configuration.
252 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
099d8f33 253 AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(useKFILTER);
c6e7c68c 254 }
255
099d8f33 256 // AOD tags
257 if (useAODTAGS) {
258 AliAnalysisTaskTagCreator* tagTask = new AliAnalysisTaskTagCreator("AOD Tag Creator");
259 mgr->AddTask(tagTask);
260 AliAnalysisDataContainer *coutTags = mgr->CreateContainer("cTag", TTree::Class(),
261 AliAnalysisManager::kOutputContainer, "AOD.tag.root");
262 mgr->ConnectInput (tagTask, 0, mgr->GetCommonInputContainer());
263 mgr->ConnectOutput(tagTask, 1, coutTags);
c6e7c68c 264 }
265
266 // Jet analysis
267 if (iJETAN) {
268 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
526b1502 269 AliAnalysisTaskJets *taskjets = 0;
270 TString anatype = mgr->GetInputEventHandler()->GetDataType();
271 taskjets = AddTaskJets(anatype, "UA1");
272 taskjets = AddTaskJets(anatype, "Fastjet");
081194a7 273 if (!taskjets) ::Warning("AnalysisTrainNew", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
c6e7c68c 274 }
275
276 // Proton analysis
277 if (iPWG2spectra) {
f0e8e44e 278 // protons
0d5d317c 279 if (iPWG2protons) {
280 gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskProtons.C");
281 AliAnalysisTaskProtons *taskprotons = AddTaskProtons();
282 if (!taskprotons) ::Warning("AnalysisTrainNew", "AliAnalysisTaskProtons cannot run for this train conditions - EXCLUDED");
283 }
f0e8e44e 284 // cascades
0d5d317c 285 if (iPWG2checkcascade) {
286 gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskCheckCascade.C");
287 AliAnalysisTaskCheckCascade *taskcheckcascade = AddTaskCheckCascade();
288 if (!taskcheckcascade) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCheckCascade cannot run for this train conditions - EXCLUDED");
289 }
6e7f8264 290 // v0's
0d5d317c 291 if (iPWG2checkv0) {
292 gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskCheckV0.C");
293 AliAnalysisTaskCheckV0 *taskcheckV0 = AddTaskCheckV0();
294 if (!taskcheckV0) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCheckV0 cannot run for this train conditions - EXCLUDED");
295 }
6e7f8264 296 // strangeness
0d5d317c 297 if (iPWG2strange) {
298 gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskStrange.C");
299 AliAnalysisTaskStrange *taskstrange = AddTaskStrange();
300 if (!taskstrange) ::Warning("AnalysisTrainNew", "AliAnalysisTaskStrange cannot run for this train conditions - EXCLUDED");
301 }
c3a83447 302 // performance cascades
0d5d317c 303 if (iPWG2perfcascade) {
304 gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskCheckPerformanceCascade.C");
305 AliAnalysisTaskCheckPerformanceCascade *taskperfcascade = AddTaskCheckPerformanceCascade();
306 if (!taskperfcascade) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCheckPerformanceCascade cannot run for this train conditions - EXCLUDED");
307 }
c6e7c68c 308 }
309
081194a7 310 // Femtoscopy analysis modules
311 if (iPWG2femto) {
312 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FEMTOSCOPY/macros/AddTaskFemto.C");
6e428ea7 313 AliAnalysisTaskFemto *taskfemto = AddTaskFemto(configPWG2femto);
081194a7 314 if (!taskfemto) ::Warning("AnalysisTrainNew", "AliAnalysisTaskFemto cannot run for this train conditions - EXCLUDED");
315 }
316
317 // Kink analysis
318 if (iPWG2kink) {
0d5d317c 319 if (iPWG2kinkESDMC) {
320 gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKink.C");
321 AliAnalysisKinkESDMC *taskkink = AddTaskKink();
322 if (!taskkink) ::Warning("AnalysisTrainNew", "AliAnalysisKinkESDMC cannot run for this train conditions - EXCLUDED");
323 }
324 if (iPWG2kinkres) {
325 gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonance.C");
326 AliAnalysisTaskKinkResonance *taskkinkres = AddTaskKinkResonance();
327 if (!taskkinkres) ::Warning("AnalysisTrainNew", "AliAnalysisTaskKinkResonance cannot run for this train conditions - EXCLUDED");
328 }
329 if (iPWG2kinklikesign) {
330 gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonanceLikeSign.C");
331 AliResonanceKinkLikeSign *taskkinklikesign = AddTaskKinkResonanceLikeSign();
332 if (!taskkinklikesign) ::Warning("AnalysisTrainNew", "AliResonanceKinkLikeSign cannot run for this train conditions - EXCLUDED");
333 }
081194a7 334 }
e4d0b516 335
c0893d28 336 // Event characterization
337 if (iPWG2evchar) {
338 gROOT->LoadMacro("$ALICE_ROOT/PWG2/EVCHAR/macros/AddTaskSPDdNdEta.C");
339 AliAnalysisTaskSPDdNdEta *taskspddndeta = AddTaskSPDdNdEta();
340 if (!taskspddndeta) ::Warning("AnalysisTrainNew", "AliAnalysisTaskSPDdNdEta cannot run for this train conditions - EXCLUDED");
341 taskspddndeta->SetReadMC(useMC);
342 }
343
344 // Unicor
345 if (iPWG2unicor) {
346 gROOT->LoadMacro("$ALICE_ROOT/PWG2/UNICOR/AddTaskUnicor.C");
347 AliAnalysisTaskUnicor *taskunicor = AddTaskUnicor();
8e1cf110 348 if (!taskunicor) ::Warning("AnalysisTrainNew", "AliAnalysisTaskUnicor cannot run for this train conditions - EXCLUDED");
c0893d28 349 }
350
6e428ea7 351 // FMD
352 if (iPWG2forward) {
353 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis/AddTaskFMD.C");
354 AliFMDAnalysisTaskSE *taskfmd = AddTaskFMD();
355 if (!taskfmd) ::Warning("AnalysisTrainNew", "AliFMDAnalysisTaskSE cannot run for this train conditions - EXCLUDED");
356 }
357
e4d0b516 358 // Flow analysis
359 if (iPWG2flow) {
360 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FLOW/macros/AddTaskFlow.C");
1276f2f0 361 Bool_t SP = kTRUE;
362 Bool_t LYZ1SUM = kTRUE;
363 Bool_t LYZ1PROD = kTRUE;
364 Bool_t LYZ2SUM = kFALSE;
365 Bool_t LYZ2PROD = kFALSE;
366 Bool_t LYZEP = kFALSE;
367 Bool_t GFC = kTRUE;
368 Bool_t QC = kTRUE;
369 Bool_t FQD = kFALSE;
370 Bool_t MCEP = kFALSE; //does not work yet 24/12/08
e4d0b516 371 Bool_t kineFromESD = kTRUE;
1276f2f0 372 Bool_t METHODS[] = {SP,LYZ1SUM,LYZ1PROD,LYZ2SUM,LYZ2PROD,LYZEP,GFC,QC,FQD,MCEP};
e4d0b516 373 // Analysis type can be ESD, AOD, MC, ESDMC0, ESDMC1
374 TString type = "AOD";
375 if (!iAODanalysis) type = "ESD";
376 if (useMC) {
377 type += "MC";
378 if (!kineFromESD) type += "1";
379 else type += "0";
380 }
381 // Boolean to fill/not fill the QA histograms
382 Bool_t QA = kTRUE;
383 // Boolean to use/not use weights for the Q vector
384 Bool_t WEIGHTS[] = {kFALSE,kFALSE,kFALSE}; //Phi, v'(pt), v'(eta)
385 AliAnalysisTaskFlowEvent* taskFE = AddTaskFlow(type,METHODS,QA,WEIGHTS);
386 if (!taskFE) ::Warning("AnalysisTrainNew", "AliAnalysisTaskFlowEvent cannot run for this train conditions - EXCLUDED");
387 }
3b1610cf 388
389 // PWG2 resonances
390 if (iPWG2res) {
0d5d317c 391 gROOT->LoadMacro("$ALICE_ROOT/PWG2/RESONANCES/macros/train/AddAnalysisTaskRsn.C");
392 TString path = gROOT->GetMacroPath();
393 path += ":$ALICE_ROOT/PWG2/RESONANCES/macros/train";
394 gROOT->SetMacroPath(path);
395 AddAnalysisTaskRsn(kTRUE);
3b1610cf 396 }
e4d0b516 397
398 // PWG3 vertexing
15dac83a 399 if (iPWG3vertexing) {
400 gROOT->LoadMacro("$ALICE_ROOT/PWG3/vertexingHF/AddTaskVertexingHF.C");
401 AliAnalysisTaskSEVertexingHF *taskvertexingHF = AddTaskVertexingHF();
081194a7 402 if (!taskvertexingHF) ::Warning("AnalysisTrainNew", "AliAnalysisTaskSEVertexingHF cannot run for this train conditions - EXCLUDED");
15dac83a 403 }
404
2a47e7b4 405 // PWG3 electrons
406 if (iPWG3hfe) {
407 gROOT->LoadMacro("$ALICE_ROOT/PWG3/hfe/AddTaskHFE.C");
408 AliAnalysisTaskHFE *taskHFE = AddTaskHFE();
409 if (!taskHFE) ::Warning("AnalysisTrainNew", "AliAnalysisTaskHFE cannot run for this train conditions - EXCLUDED");
410 }
411
c6e7c68c 412 // PWG4 hadron correlations
413 if (iPWG4partcorr) {
099d8f33 414 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
081194a7 415 AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS");
416 if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
274ff025 417 AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL");
081194a7 418 if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
15dac83a 419 }
c3a83447 420
421 // PWG4 gamma conversion analysis
422 if (iPWG4gammaconv) {
423 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
526b1502 424 TString cdir = gSystem->WorkingDirectory();
425 gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
426 TString gcArguments = "-run-on-train -run-jet -run-chic -run-neutralmeson";
427 AliAnalysisTaskGammaConversion * taskGammaConversion = AddTaskGammaConversion(gcArguments,mgr->GetCommonInputContainer());
428 gSystem->ChangeDirectory(cdir);
c3a83447 429 if (!taskGammaConversion) ::Warning("AnalysisTrainNew", "AliAnalysisTaskGammaConversion cannot run for these train conditions - EXCLUDED");
430 }
5c4c538a 431
432 // PWG4 omega to 3 pions analysis
433 if (iPWG4omega3pi) {
434 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
435 AliAnalysisTaskOmegaPi0PiPi *taskomega3pi = AddTaskomega3pi();
436 if (!taskomega3pi) ::Warning("AnalysisTrainNew", "AliAnalysisTaskomega3pi cannot run for these train conditions - EXCLUDED");
437 }
438
c6e7c68c 439 //==========================================================================
440 // FOR THE REST OF THE TASKS THE MACRO AddTaskXXX() is not yet implemented/
441 // Run the analysis
442 //
6e428ea7 443 if (usePLUGIN) {
444 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
445 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
446 }
447
c6e7c68c 448 if (mgr->InitAnalysis()) {
449 mgr->PrintStatus();
371c967e 450 if (saveTrain || strlen(config_file)) gSystem->ChangeDirectory(train_name);
c6e7c68c 451 StartAnalysis(smode, chain);
c0893d28 452 if (saveTrain && smode=="GRID") {
5c4c538a 453 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
0d5d317c 454 TString alien_workdir = gGrid->GetHomeDirectory();
455 if (iAODanalysis) alien_workdir += "analysisAOD";
456 else alien_workdir += "analysisESD";
5c4c538a 457 alien_outdir = gridhandler->GetGridOutputDir();
0d5d317c 458 printf("=== Registering ConfigTrain.C in the work directory <%s> ===\n",
459 alien_workdir.Data());
460 if (AliAnalysisAlien::FileExists(Form("%s/%sConfig.C", alien_workdir.Data(), train_name.Data())))
461 gGrid->Rm(Form("%s/%sConfig.C", alien_workdir.Data(), train_name.Data()));
2a47e7b4 462 if (strcmp(plugin_mode, "test"))
463 TFile::Cp(Form("file:%sConfig.C",train_name.Data()), Form("alien://%s/%sConfig.C", alien_workdir.Data(), train_name.Data()));
371c967e 464 }
465 }
c6e7c68c 466}
467
468//______________________________________________________________________________
469void StartAnalysis(const char *mode, TChain *chain) {
470// Start analysis.
471 Int_t imode = -1;
472 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
473 if (!strcmp(mode, "LOCAL")) imode = 0;
474 if (!strcmp(mode, "PROOF")) imode = 1;
475 if (!strcmp(mode, "GRID")) imode = 2;
476 switch (imode) {
477 case 0:
478 if (!chain) {
a42c0df6 479 ::Error("AnalysisTrainNew.C::StartAnalysis", "Cannot create the chain");
c6e7c68c 480 return;
481 }
081194a7 482 mgr->StartAnalysis(mode, chain);
c6e7c68c 483 return;
484 case 1:
a42c0df6 485 if (!proof_dataset.Length()) {
486 ::Error("AnalysisTrainNew.C::StartAnalysis", "proof_dataset is empty");
c6e7c68c 487 return;
488 }
b160b576 489 mgr->StartAnalysis(mode, proof_dataset, 1000);
c6e7c68c 490 return;
491 case 2:
492 if (usePLUGIN) {
493 if (!mgr->GetGridHandler()) {
a42c0df6 494 ::Error("AnalysisTrainNew.C::StartAnalysis", "Grid plugin not initialized");
c6e7c68c 495 return;
496 }
497 mgr->StartAnalysis("grid");
498 } else {
499 if (!chain) {
a42c0df6 500 ::Error("AnalysisTrainNew.C::StartAnalysis", "Cannot create the chain");
c6e7c68c 501 return;
502 }
503 mgr->StartAnalysis(mode, chain);
504 }
505 return;
506 }
507}
508
509//______________________________________________________________________________
510void CheckModuleFlags(const char *mode) {
511// Checks selected modules and insure compatibility
512 Int_t imode = -1;
513 if (!strcmp(mode, "LOCAL")) imode = 0;
514 if (!strcmp(mode, "PROOF")) imode = 1;
515 if (!strcmp(mode, "GRID")) imode = 2;
516 if (imode==1) {
081194a7 517 if (!usePAR) {
a42c0df6 518 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
081194a7 519 usePAR = kTRUE;
520 }
274ff025 521 }
081194a7 522 if (imode != 2) {
a42c0df6 523 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
081194a7 524 usePLUGIN = kFALSE;
525 }
c6e7c68c 526 if (iAODanalysis) {
527 // AOD analysis
081194a7 528 if (useMC)
a42c0df6 529 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "MC usage disabled in analysis on AOD's");
526b1502 530 if (useAODTAGS)
531 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "AOD tags usage disabled in analysis on AOD's");
c6e7c68c 532 useMC = kFALSE;
533 useTR = kFALSE;
526b1502 534 useAODTAGS = kFALSE;
081194a7 535 if (iESDfilter)
a42c0df6 536 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "ESD filter disabled in analysis on AOD's");
c6e7c68c 537 iESDfilter = 0;
081194a7 538 if (!iAODhandler) {
539 if (iJETAN)
a42c0df6 540 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "JETAN disabled in analysis on AOD's without AOD handler");
081194a7 541 iJETAN = 0;
c3a83447 542 if (iPWG4gammaconv)
0d5d317c 543 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "iPWG4gammaconv disabled on AOD's without AOD handler");
5c4c538a 544 iPWG4gammaconv = 0;
0d5d317c 545 if (iPWG4partcorr)
546 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4partcorr disabled on AOD's without AOD handler");
547 iPWG4partcorr = 0;
081194a7 548 }
c6e7c68c 549 // Disable tasks that do not work yet on AOD data
0d5d317c 550 if (iPWG2flow)
551 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2flow disabled on AOD's");
552 iPWG2flow = 0;
553 if (iPWG2femto)
554 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2femto disabled on AOD's");
555 iPWG2femto = 0;
556 if (iPWG2res)
557 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2res disabled on AOD's");
558 iPWG2res = 0;
081194a7 559 if (iPWG2kink)
a42c0df6 560 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2kink disabled in analysis on AOD's");
7cbd7add 561 iPWG2kink = 0;
c0893d28 562 if (iPWG2unicor)
563 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2unicor disabled in analysis on AOD's");
564 iPWG2unicor = 0;
0d5d317c 565 if (iPWG2evchar)
566 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4evchar disabled on AOD's");
567 iPWG2evchar = 0;
6e428ea7 568 if (iPWG2forward)
569 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2forward disabled in analysis on AOD's");
570 iPWG2forward = 0;
2a47e7b4 571 if (iPWG3hfe)
572 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG3hfe disabled on AOD's");
573 iPWG3hfe = 0;
5c4c538a 574 if (iPWG4omega3pi)
0d5d317c 575 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4omega3pi disabled on AOD's");
5c4c538a 576 iPWG4omega3pi = 0;
0d5d317c 577 if (iPWG4partcorr)
578 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4partcorr disabled on AOD's");
579 iPWG4partcorr = 0;
c6e7c68c 580 } else {
581 // ESD analysis
582 iMUONcopyAOD = 0;
552f38dc 583 if (!useMC) useTR = kFALSE;
584 if (!useTR) {
585 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "iPWG2evchar disabled if not reading track references");
586 iPWG2evchar = 0;
587 }
0d5d317c 588 }
589 if (!useMC) {
590 if (iPWG2perfcascade)
591 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2perfcascade disabled without MC info");
592 iPWG2perfcascade = 0;
593 }
526b1502 594 if (iJETAN && !iAODanalysis) iESDfilter=1;
595 if (iESDfilter) {iAODhandler=1; useCORRFW = kTRUE;}
2a47e7b4 596 if (iPWG2spectra || iPWG2flow || iPWG3vertexing || iPWG3hfe) useCORRFW = kTRUE;
099d8f33 597 if (useKFILTER && !useMC) useKFILTER = kFALSE;
598 if (useAODTAGS && !iAODhandler) useAODTAGS = kFALSE;
c6e7c68c 599}
600
601//______________________________________________________________________________
602Bool_t Connect(const char *mode) {
603// Connect <username> to the back-end system.
604 Int_t imode = -1;
605 if (!strcmp(mode, "LOCAL")) imode = 0;
606 if (!strcmp(mode, "PROOF")) imode = 1;
607 if (!strcmp(mode, "GRID")) imode = 2;
608 TString username = gSystem->Getenv("alien_API_USER");
609 switch (imode) {
610 case 0:
611 break;
612 case 1:
613 if (!username.Length()) {
a42c0df6 614 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Make sure you:\n \
c6e7c68c 615 1. Have called: alien-token-init <username>\n \
616 2. Have called: >source /tmp/gclient_env_$UID");
617 return kFALSE;
618 }
a42c0df6 619 ::Info("AnalysisTrainNew.C::Connect", "Connecting user <%s> to PROOF cluster <%s>",
620 username.Data(), proof_cluster.Data());
b160b576 621 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
7cbd7add 622// TProof::Open(Form("%s@%s:31093", username.Data(), proof_cluster.Data()));
623 TProof::Open(Form("%s@%s", username.Data(), proof_cluster.Data()));
c6e7c68c 624 if (!gProof) {
625 if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
a42c0df6 626 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
c6e7c68c 627 return kFALSE;
628 }
b160b576 629 TGrid::Connect("alien://");
630 if (gGrid) {
631 TString homedir = gGrid->GetHomeDirectory();
632 TString workdir = homedir + train_name;
633 if (!gGrid->Cd(workdir)) {
634 gGrid->Cd(homedir);
635 if (gGrid->Mkdir(workdir)) {
636 gGrid->Cd(train_name);
637 ::Info("AnalysisTrainNew::Connect()", "Directory %s created", gGrid->Pwd());
638 }
639 }
640 gGrid->Mkdir("proof_output");
641 gGrid->Cd("proof_output");
642 proof_outdir = Form("alien://%s", gGrid->Pwd());
643 }
c6e7c68c 644 break;
645 case 2:
646 if (!username.Length()) {
a42c0df6 647 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Make sure you:\n \
c6e7c68c 648 1. Have called: alien-token-init <username>\n \
649 2. Have called: >source /tmp/gclient_env_$UID");
650 return kFALSE;
651 }
652 if (usePLUGIN && !gSystem->Getenv("alien_CLOSE_SE")) {
a42c0df6 653 ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode),
c6e7c68c 654 "When using the AliEn plugin it is preferable to define the \
655 variable alien_CLOSE_SE in your environment.");
656 return kFALSE;
657 }
a42c0df6 658 ::Info("AnalysisTrainNew.C::Connect", "Connecting user <%s> to AliEn ...",
c6e7c68c 659 username.Data());
660 TGrid::Connect("alien://");
661 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
662 break;
663 default:
a42c0df6 664 ::Error("AnalysisTrainNew.C::Connect", "Unknown run mode: %s", mode);
c6e7c68c 665 return kFALSE;
666 }
a42c0df6 667 ::Info("AnalysisTrainNew.C::Connect","Connected in %s mode", mode);
c6e7c68c 668 return kTRUE;
669}
670
671//______________________________________________________________________________
672Bool_t LoadCommonLibraries(const char *mode)
673{
674// Load common analysis libraries.
675 Int_t imode = -1;
676 if (!strcmp(mode, "LOCAL")) imode = 0;
677 if (!strcmp(mode, "PROOF")) imode = 1;
678 if (!strcmp(mode, "GRID")) imode = 2;
679 if (!gSystem->Getenv("ALICE_ROOT")) {
a42c0df6 680 ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
c6e7c68c 681 return kFALSE;
682 }
683 Bool_t success = kTRUE;
684 // ROOT libraries
685 gSystem->Load("libTree.so");
686 gSystem->Load("libGeom.so");
687 gSystem->Load("libVMC.so");
688 gSystem->Load("libPhysics.so");
689
690 // Load framework classes. Par option ignored here.
691 switch (imode) {
692 case 0:
693 case 2:
7581b1bc 694 if (useCPAR) {
695 success &= LoadLibrary("STEERBase", mode, kTRUE);
696 success &= LoadLibrary("ESD", mode, kTRUE);
697 success &= LoadLibrary("AOD", mode, kTRUE);
698 success &= LoadLibrary("ANALYSIS", mode, kTRUE);
699 success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
700 if (useCORRFW) success &= LoadLibrary("CORRFW", mode, kTRUE);
701 } else {
702 success &= LoadLibrary("libSTEERBase.so", mode);
703 success &= LoadLibrary("libESD.so", mode);
704 success &= LoadLibrary("libAOD.so", mode);
705 success &= LoadLibrary("libANALYSIS.so", mode);
706 success &= LoadLibrary("libANALYSISalice.so", mode);
707 if (useCORRFW) success &= LoadLibrary("libCORRFW.so", mode);
708 gROOT->ProcessLine(".include $ALICE_ROOT/include");
709 }
c6e7c68c 710 break;
711 case 1:
712 Int_t ires = -1;
a42c0df6 713 if (useAFPAR && !gSystem->AccessPathName(AFversion)) ires = gProof->UploadPackage(AFversion);
c6e7c68c 714 if (ires < 0) {
715 success &= LoadLibrary("STEERBase", mode);
716 success &= LoadLibrary("ESD", mode);
717 success &= LoadLibrary("AOD", mode);
718 success &= LoadLibrary("ANALYSIS", mode);
719 success &= LoadLibrary("ANALYSISalice", mode);
720 if (useCORRFW) success &= LoadLibrary("CORRFW", mode);
721 } else {
722 ires = gProof->EnablePackage(AFversion);
2b142d4b 723 if (ires<0) success = kFALSE;
c6e7c68c 724 if (useCORRFW) success &= LoadLibrary("CORRFW", mode);
725 }
c6e7c68c 726 break;
727 default:
a42c0df6 728 ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
c6e7c68c 729 return kFALSE;
730 }
731 if (success) {
a42c0df6 732 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
733 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
c6e7c68c 734 gSystem->GetIncludePath());
735 } else {
a42c0df6 736 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries: FAILED");
c6e7c68c 737 }
738
739 return success;
740}
741
742//______________________________________________________________________________
743Bool_t LoadAnalysisLibraries(const char *mode)
744{
745// Load common analysis libraries.
746 Bool_t success = kTRUE;
099d8f33 747 if (iESDfilter) {
c6e7c68c 748 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
749 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
750 }
751 // JETAN
752 if (iJETAN) {
753 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
c3a83447 754 }
c6e7c68c 755 // PWG4 particle correlations
274ff025 756 if (iPWG4partcorr) {
b9748bfd 757 if (!LoadLibrary("EMCALUtils", mode, kTRUE) ||
758 !LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
c6e7c68c 759 !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
c6e7c68c 760 }
c3a83447 761 // PWG4 gamma conversion
762 if (iPWG4gammaconv) {
763 if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
764 }
5c4c538a 765 // PWG4 omega to 3 pions
766 if (iPWG4omega3pi) {
767 if (!LoadLibrary("PWG4omega3pi", mode, kTRUE)) return kFALSE;
768 }
c6e7c68c 769 // PWG2 task protons
770 if (iPWG2spectra) {
771 if (!LoadLibrary("PWG2spectra", mode, kTRUE)) return kFALSE;
772 }
773 // PWG2 flow
774 if (iPWG2flow) {
e4d0b516 775 if (!LoadLibrary("PWG2flowCommon", mode, kTRUE) ||
776 !LoadLibrary("PWG2flowTasks", mode, kTRUE)) return kFALSE;
c6e7c68c 777 }
778 // PWG2 resonances
779 if (iPWG2res) {
780 if (!LoadLibrary("PWG2resonances", mode, kTRUE)) return kFALSE;
781 }
081194a7 782 // PWG2 kink
783 if (iPWG2kink) {
784 if (!LoadLibrary("PWG2kink", mode, kTRUE)) return kFALSE;
785 }
c0893d28 786 // PWG2 unicor
787 if (iPWG2unicor) {
788 if (!LoadLibrary("PWG2unicor", mode, kTRUE)) return kFALSE;
789 }
790 // PWG2 evchar
791 if (iPWG2evchar) {
792 if (!LoadLibrary("PWG2evchar", mode, kTRUE)) return kFALSE;
793 }
c6e7c68c 794 // PWG2 femtoscopy
795 if (iPWG2femto) {
796 if (!LoadLibrary("PWG2AOD", mode, kTRUE) ||
797 !LoadLibrary("PWG2femtoscopy", mode, kTRUE) ||
798 !LoadLibrary("PWG2femtoscopyUser", mode, kTRUE)) return kFALSE;
6e428ea7 799// TFile::Cp(gSystem->ExpandPathName("$(ALICE_ROOT)/PWG2/FEMTOSCOPY/macros/ConfigFemtoAnalysis.C"), Form("%s/ConfigFemtoAnalysis.C", train_name.Data()));
800// anaLibs += "ConfigFemtoAnalysis.C ";
801 }
802 // PWG2 FORWARD
803 if (iPWG2forward) {
804 if (!LoadLibrary("PWG2forward", mode, kTRUE)) return kFALSE;
c6e7c68c 805 }
2a47e7b4 806 // PWG3 Vertexing HF
c6e7c68c 807 if (iPWG3vertexing) {
15dac83a 808 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
809 !LoadLibrary("PWG3vertexingHF", mode, kTRUE)) return kFALSE;
c6e7c68c 810 }
2a47e7b4 811 // PWG3 hfe
812 if (iPWG3hfe) {
813 if (!LoadLibrary("PWG3hfe", mode, kTRUE)) return kFALSE;
814 }
815
a42c0df6 816 ::Info("AnalysisTrainNew.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
c6e7c68c 817 return kTRUE;
818}
819
820//______________________________________________________________________________
821Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
822{
823// Load a module library in a given mode. Reports success.
824 Int_t imode = -1;
825 Int_t result;
826 TString smodule(module);
827 if (!strcmp(mode, "LOCAL")) imode = 0;
828 if (!strcmp(mode, "PROOF")) imode = 1;
829 if (!strcmp(mode, "GRID")) imode = 2;
830 TString mod(module);
831 if (!mod.Length()) {
a42c0df6 832 ::Error("AnalysisTrainNew.C::LoadLibrary", "Empty module name");
c6e7c68c 833 return kFALSE;
834 }
835 // If a library is specified, just load it
836 if (smodule.EndsWith(".so")) {
837 mod.Remove(mod.Index(".so"));
838 result = gSystem->Load(mod);
839 if (result < 0) {
a42c0df6 840 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load library %s", module);
c6e7c68c 841 return kFALSE;
842 }
843 if (rec) anaLibs += Form("%s.so ",mod.Data());
844 return kTRUE;
845 }
846 // Check if the library is already loaded
847 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
848 return kTRUE;
849 switch (imode) {
850 case 0:
851 case 2:
852 if (usePAR) {
853 result = SetupPar(module);
854 if (rec) anaPars += Form("%s.par ", module);
855 } else {
856 result = gSystem->Load(Form("lib%s.so", module));
857 if (rec) anaLibs += Form("lib%s.so ", module);
858 }
859 break;
860 case 1:
861 result = gProof->UploadPackage(module);
862 if (result<0) {
863 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
864 if (result<0) {
a42c0df6 865 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
c6e7c68c 866 return kFALSE;
867 }
868 }
869 result = gProof->EnablePackage(module);
870 break;
871 default:
872 return kFALSE;
873 }
874 if (result < 0) {
a42c0df6 875 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load module %s", module);
c6e7c68c 876 return kFALSE;
877 }
878 return kTRUE;
879}
880
881
882//______________________________________________________________________________
883TChain *CreateChain(const char *mode, const char *plugin_mode)
884{
885// Create the input chain
886 Int_t imode = -1;
887 if (!strcmp(mode, "LOCAL")) imode = 0;
888 if (!strcmp(mode, "PROOF")) imode = 1;
889 if (!strcmp(mode, "GRID")) imode = 2;
890 TChain *chain = NULL;
891 // Local chain
892 switch (imode) {
893 case 0:
894 if (iAODanalysis) {
a42c0df6 895 if (!local_xmldataset.Length()) {
c6e7c68c 896 // Local AOD
897 chain = new TChain("aodTree");
274ff025 898 if (gSystem->AccessPathName("data/AliAOD.root"))
a42c0df6 899 ::Error("AnalysisTrainNew.C::CreateChain", "File: AliAOD.root not in ./data dir");
b160b576 900 else {
901 if (!saveTrain) chain->Add("data/AliAOD.root");
902 else chain->Add("../data/AliAOD.root");
903 }
c6e7c68c 904 } else {
905 // Interactive AOD
a42c0df6 906 chain = CreateChainSingle(local_xmldataset, "aodTree");
c6e7c68c 907 }
908 } else {
a42c0df6 909 if (!local_xmldataset.Length()) {
c6e7c68c 910 // Local ESD
911 chain = new TChain("esdTree");
099d8f33 912 if (gSystem->AccessPathName("data/AliESDs.root"))
a42c0df6 913 ::Error("AnalysisTrainNew.C::CreateChain", "File: AliESDs.root not in ./data dir");
b160b576 914 else {
915 if (!saveTrain) chain->Add("data/AliESDs.root");
916 else chain->Add("../data/AliESDs.root");
917 }
c6e7c68c 918 } else {
919 // Interactive ESD
a42c0df6 920 chain = CreateChainSingle(local_xmldataset, "esdTree");
c6e7c68c 921 }
922 }
923 break;
924 case 1:
925 break;
926 case 2:
927 if (usePLUGIN) {
6e428ea7 928// AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
929// AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
c6e7c68c 930 } else {
931 TString treeName = "esdTree";
932 if (iAODanalysis) treeName = "aodTree";
933 chain = CreateChainSingle("wn.xml", treeName);
934 }
935 break;
936 default:
937 }
938 if (chain && chain->GetNtrees()) return chain;
939 return NULL;
940}
941
942//______________________________________________________________________________
943TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
944{
945 printf("*******************************\n");
946 printf("*** Getting the ESD Chain ***\n");
947 printf("*******************************\n");
948 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
949
950 if (!myCollection) {
a42c0df6 951 ::Error("AnalysisTrainNew.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
c6e7c68c 952 return NULL ;
953 }
954
955 TChain* chain = new TChain(treeName);
956 myCollection->Reset() ;
957 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
958 chain->ls();
959 return chain;
960}
961
962//______________________________________________________________________________
963Int_t SetupPar(char* pararchivename)
964{
965 if (!pararchivename || !strlen(pararchivename)) return -1;
966 char processline[1024];
967 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
968 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
a42c0df6 969 ::Info("AnalysisTrainNew.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
c6e7c68c 970 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
971 Form("%s.par",pararchivename));
972 } else {
a42c0df6 973 ::Error("AnalysisTrainNew.C::SetupPar", "Cannot find %s.par", pararchivename);
c6e7c68c 974 return -1;
975 }
976 }
a42c0df6 977 if (usePLUGIN && saveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, train_name.Data()));
c6e7c68c 978 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
979
980 TString ocwd = gSystem->WorkingDirectory();
981 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
982
983 // check for BUILD.sh and execute
984 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
985 printf("*******************************\n");
986 printf("*** Building PAR archive ***\n");
987 printf("*******************************\n");
988 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
989 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
990 return -1;
991 }
992 }
993
994 // check for SETUP.C and execute
995 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
996 printf("*******************************\n");
997 printf("*** Setup PAR archive ***\n");
998 printf("*******************************\n");
999 gROOT->Macro("PROOF-INF/SETUP.C");
1000 }
1001 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
1002 return 0;
1003}
1004
1005//______________________________________________________________________________
5c4c538a 1006AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
c6e7c68c 1007{
1008// Check if user has a valid token, otherwise make one. This has limitations.
1009// One can always follow the standard procedure of calling alien-token-init then
1010// source /tmp/gclient_env_$UID in the current shell.
1011 if (!AliAnalysisGrid::CreateToken()) return NULL;
1012 AliAnalysisAlien *plugin = new AliAnalysisAlien();
1013// Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
1014 plugin->SetRunMode(plugin_mode);
5c4c538a 1015 if (useProductionMode) plugin->SetProductionMode();
0d5d317c 1016 plugin->SetJobTag(job_tag);
c6e7c68c 1017 plugin->SetNtestFiles(1);
6e428ea7 1018// plugin->SetPreferedSE("ALICE::NIHAM::File");
c6e7c68c 1019// Set versions of used packages
1020 plugin->SetAPIVersion("V2.4");
1021 plugin->SetROOTVersion(root_version);
1022 plugin->SetAliROOTVersion(aliroot_version);
1023// Declare input data to be processed.
1024// Method 1: Create automatically XML collections using alien 'find' command.
1025// Define production directory LFN
1026 plugin->SetGridDataDir(alien_datadir);
1027// Set data search pattern
274ff025 1028 if (iAODanalysis) plugin->SetDataPattern("*AliAOD.root");
275942e0 1029 else plugin->SetDataPattern("*ESD.tag.root");
c6e7c68c 1030// ...then add run numbers to be considered
3b1610cf 1031 plugin->SetRunRange(run_range[0], run_range[1]);
1032// for (Int_t i=0; i<10; i++) {
1033// if (run_numbers[i]==0) break;
1034// plugin->AddRunNumber(run_numbers[i]);
1035// }
c6e7c68c 1036// Method 2: Declare existing data files (raw collections, xml collections, root file)
1037// If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
1038// XML collections added via this method can be combined with the first method if
1039// the content is compatible (using or not tags)
1040// plugin->AddDataFile("tag.xml");
1041// plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
1042// Define alien work directory where all files will be copied. Relative to alien $HOME.
274ff025 1043 if (iAODanalysis) plugin->SetGridWorkingDir("analysisAOD");
1044 else plugin->SetGridWorkingDir("analysisESD");
c6e7c68c 1045// Declare alien output directory. Relative to working directory.
371c967e 1046 if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
1047 plugin->SetGridOutputDir(alien_outdir);
c6e7c68c 1048
1049 TString ana_sources = "";
1050 TString ana_add = "";
1051 if (usePAR && anaPars.Length()) {
7581b1bc 1052 printf("%s\n", anaPars.Data());
c6e7c68c 1053 TObjArray *arr;
1054 TObjString *objstr;
1055 arr = anaPars.Tokenize(" ");
1056 TIter next(arr);
1057 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
1058 delete arr;
1059 }
1060
1061// Declare the analysis source files names separated by blancs. To be compiled runtime
1062// using ACLiC on the worker nodes.
1063 ana_sources = ana_sources.Strip();
1064// Declare all libraries (other than the default ones for the framework. These will be
1065// loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
1066 anaLibs = anaLibs.Strip();
1067 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
1068 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs);
1069
1070// Declare the output file names separated by blancs.
1071// (can be like: file.root or file.root@ALICE::Niham::File)
1072 plugin->SetDefaultOutputs();
275942e0 1073 plugin->SetMergeExcludes(mergeExclude);
1074 plugin->SetMaxMergeFiles(maxMergeFiles);
1075 plugin->SetNrunsPerMaster(nRunsPerMaster);
c6e7c68c 1076// Optionally define the files to be archived.
526b1502 1077// plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
6e428ea7 1078
1079
1080 // Put default output files to archive
1081 TString listhists = "";
1082 TString listaods = "";
1083 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1084 TIter next(mgr->GetOutputs());
1085 AliAnalysisDataContainer *output;
1086 while ((output=(AliAnalysisDataContainer*)next())) {
1087 const char *filename = output->GetFileName();
1088 if (!(strcmp(filename, "default"))) {
1089 if (!mgr->GetOutputEventHandler()) continue;
1090 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
1091 if (listaods.Length()) listaods += ",";
1092 listaods += filename;
1093 } else {
1094 if (listhists.Length()) listhists += ",";
1095 listhists += filename;
1096 }
1097 }
1098 if (mgr->GetExtraFiles().Length()) {
1099 if (listaods.Length()) listaods += ",";
1100 listaods += mgr->GetExtraFiles();
1101 listaods.ReplaceAll(" ", ",");
1102 }
1103 if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), outputStorages.Data());;
1104 if (listaods.Length()) listaods = Form("aod_archive.zip:%s@%s", listaods.Data(), outputStorages.Data());;
1105 if (!listhists.Length() && !listaods.Length()) {
1106 ::Fatal("AnalysisTrainNew", "No task output !");
1107 }
1108 TString outputArchive = "log_archive.zip:stdout,stderr@ALICE::CERN::SE";
1109 if (listaods.Length()) {
1110 outputArchive += " ";
1111 outputArchive += listaods;
1112 }
1113 if (listhists.Length()) {
1114 outputArchive += " ";
1115 outputArchive += listhists;
1116 }
1117 plugin->SetOutputArchive(outputArchive);
c6e7c68c 1118// Optionally set a name for the generated analysis macro (default MyAnalysis.C)
a42c0df6 1119 plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
c6e7c68c 1120// Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
275942e0 1121 plugin->SetSplitMaxInputFileNumber(nFilesPerJob);
c6e7c68c 1122// Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1123// plugin->SetMaxInitFailed(5);
1124// Optionally resubmit threshold.
1125// plugin->SetMasterResubmitThreshold(90);
1126// Optionally set time to live (default 30000 sec)
1127 plugin->SetTTL(30000);
1128// Optionally set input format (default xml-single)
1129 plugin->SetInputFormat("xml-single");
1130// Optionally modify the name of the generated JDL (default analysis.jdl)
a42c0df6 1131 plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
7ceeacc7 1132// Optionally modify the executable name (default analysis.sh)
a42c0df6 1133 plugin->SetExecutable(Form("%s.sh", train_name.Data()));
c6e7c68c 1134// Optionally modify job price (default 1)
1135 plugin->SetPrice(1);
1136// Optionally modify split mode (default 'se')
1137 plugin->SetSplitMode("se");
1138 return plugin;
1139}
a42c0df6 1140
1141//______________________________________________________________________________
1142void WriteConfig()
1143{
1144// Write train configuration in a file. The file name has the format:
1145// train_[trainName]_ddMonthyyyy_time.C
371c967e 1146 if (useDATE) {
0d5d317c 1147 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
1148 ifstream fdate("date.tmp");
1149 if (!fdate.is_open()) {
1150 ::Error("AnalysisTrainNew.C::Export","Could not generate file name");
1151 return;
1152 }
371c967e 1153 const char date[64];
1154 fdate.getline(date,64);
1155 fdate.close();
1156 gSystem->Exec("rm date.tmp");
1157 train_name = Form("train_%s_%s", train_name.Data(), date);
1158 } else {
1159 train_name = Form("train_%s", train_name.Data());
1160 }
a42c0df6 1161 TString cdir = gSystem->WorkingDirectory();
1162 gSystem->MakeDirectory(train_name);
1163 gSystem->ChangeDirectory(train_name);
1164 ofstream out;
0d5d317c 1165 out.open(Form("%sConfig.C",train_name.Data()), ios::out);
a42c0df6 1166 if (out.bad()) {
1167 ::Error("AnalysisTrainNew.C::Export", "Cannot open ConfigTrain.C for writing");
1168 return;
1169 }
1170 out << "{" << endl;
1171 out << " train_name = " << "\"" << train_name.Data() << "\";" << endl;
1172 out << " proof_cluster = " << "\"" << proof_cluster.Data() << "\";" << endl;
1173 out << " useAFPAR = " << useAFPAR << ";" << endl;
1174 if (useAFPAR)
1175 out << " AFversion = " << AFversion.Data() << ";" << endl;
1176 out << " proof_dataset = " << "\"" << proof_dataset.Data() << "\";" << endl;
1177 out << " usePLUGIN = " << usePLUGIN << ";" << endl;
1178 out << " usePAR = " << usePAR << ";" << endl;
1179 out << " useCPAR = " << useCPAR << ";" << endl;
1180 out << " root_version = " << "\"" << root_version.Data() << "\";" << endl;
1181 out << " aliroot_version = " << "\"" << aliroot_version.Data() << "\";" << endl;
1182 out << " alien_datadir = " << "\"" << alien_datadir.Data() << "\";" << endl;
371c967e 1183 if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
1184 out << " alien_outdir = " << "\"" << alien_outdir.Data() << "\";" << endl;
275942e0 1185 out << " maxMergeFiles = " << maxMergeFiles << ";" << endl;
1186 out << " mergeExclude = " << "\"" << mergeExclude.Data() << "\";" << endl;
1187 out << " nRunsPerMaster = " << nRunsPerMaster << ";" << endl;
1188 out << " nFilesPerJob = " << nFilesPerJob << ";" << endl;
3b1610cf 1189// for (Int_t i=0; i<10; i++) {
1190// if (run_numbers[i])
1191// out << " run_numbers[" << i << "] = " << run_numbers[i] << ";" << endl;
1192// }
1193 out << " run_range[0] = " << run_range[0] << ";" << endl;
1194 out << " run_range[1] = " << run_range[1] << ";" << endl;
a42c0df6 1195 out << " useDBG = " << useDBG << ";" << endl;
1196 out << " useMC = " << useMC << ";" << endl;
1197 out << " useTAGS = " << useTAGS << ";" << endl;
1198 out << " useKFILTER = " << useKFILTER << ";" << endl;
1199 out << " useTR = " << useTR << ";" << endl;
1200 out << " useCORRFW = " << useCORRFW << ";" << endl;
1201 out << " useAODTAGS = " << useAODTAGS << ";" << endl;
1202 out << " saveTrain = " << "kFALSE;" << endl << endl;
1203 out << " // Analysis modules" << endl;
1204 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
1205 out << " iAODhandler = " << iAODhandler << ";" << endl;
1206 out << " iESDfilter = " << iESDfilter << ";" << endl;
1207 out << " iMUONcopyAOD = " << iMUONcopyAOD << ";" << endl;
1208 out << " iJETAN = " << iJETAN << ";" << endl;
1209 out << " iPWG4partcorr = " << iPWG4partcorr << ";" << endl;
c3a83447 1210 out << " iPWG4gammaconv = " << iPWG4gammaconv << ";" << endl;
5c4c538a 1211 out << " iPWG4omega3pi = " << iPWG4omega3pi << ";" << endl;
2a47e7b4 1212 out << " iPWG3vertexing = " << iPWG3vertexing << ";" << endl;
1213 out << " iPWG3hfe = " << iPWG3hfe << ";" << endl;
a42c0df6 1214 out << " iPWG2femto = " << iPWG2femto << ";" << endl;
1215 out << " iPWG2spectra = " << iPWG2spectra << ";" << endl;
0d5d317c 1216 out << " iPWG2protons = " << iPWG2protons << ";" << endl;
1217 out << " iPWG2checkcascade = " << iPWG2checkcascade << ";" << endl;
1218 out << " iPWG2perfcascade = " << iPWG2perfcascade << ";" << endl;
1219 out << " iPWG2checkv0 = " << iPWG2checkv0 << ";" << endl;
1220 out << " iPWG2strange = " << iPWG2strange << ";" << endl;
a42c0df6 1221 out << " iPWG2flow = " << iPWG2flow << ";" << endl;
1222 out << " iPWG2res = " << iPWG2res << ";" << endl;
1223 out << " iPWG2kink = " << iPWG2kink << ";" << endl;
0d5d317c 1224 out << " iPWG2kinkESDMC = " << iPWG2kinkESDMC << ";" << endl;
1225 out << " iPWG2kinkres = " << iPWG2kinkres << ";" << endl;
1226 out << " iPWG2kinklikesign = " << iPWG2kinklikesign << ";" << endl;
c0893d28 1227 out << " iPWG2unicor = " << iPWG2unicor << ";" << endl;
1228 out << " iPWG2evchar = " << iPWG2evchar << ";" << endl;
6e428ea7 1229 out << " iPWG2forward = " << iPWG2forward << ";" << endl << endl;
1230 out << "// Configuration fot the wagons" << endl;
1231 out << " configPWG2femto = \"" << configPWG2femto << "\";" << endl;
a42c0df6 1232 out << "}" << endl;
1233 ::Info("AnalysisTrainNew.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", train_name.Data()));
1234 gSystem->ChangeDirectory(cdir);
1235}
1236
1237//______________________________________________________________________________
1238Bool_t LoadConfig(const char *filename)
1239{
1240// Read train configuration from file
1241 if (gSystem->AccessPathName(filename)) {
1242 ::Error("AnalysisTrainNew.C::LoadConfig", "Config file name not found");
1243 return kFALSE;
1244 }
1245 gROOT->ProcessLine(Form(".x %s", filename));
1246 ::Info("AnalysisTrainNew.C::LoadConfig", "Train configuration loaded from file %s", filename);
1247 return kTRUE;
1248}