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