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