Fixes in reconstruction:
[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) {
b9748bfd 732 if (!LoadLibrary("EMCALUtils", mode, kTRUE) ||
733 !LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
c6e7c68c 734 !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
c6e7c68c 735 }
c3a83447 736 // PWG4 gamma conversion
737 if (iPWG4gammaconv) {
738 if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
739 }
5c4c538a 740 // PWG4 omega to 3 pions
741 if (iPWG4omega3pi) {
742 if (!LoadLibrary("PWG4omega3pi", mode, kTRUE)) return kFALSE;
743 }
c6e7c68c 744 // PWG2 task protons
745 if (iPWG2spectra) {
746 if (!LoadLibrary("PWG2spectra", mode, kTRUE)) return kFALSE;
747 }
748 // PWG2 flow
749 if (iPWG2flow) {
e4d0b516 750 if (!LoadLibrary("PWG2flowCommon", mode, kTRUE) ||
751 !LoadLibrary("PWG2flowTasks", mode, kTRUE)) return kFALSE;
c6e7c68c 752 }
753 // PWG2 resonances
754 if (iPWG2res) {
755 if (!LoadLibrary("PWG2resonances", mode, kTRUE)) return kFALSE;
756 }
081194a7 757 // PWG2 kink
758 if (iPWG2kink) {
759 if (!LoadLibrary("PWG2kink", mode, kTRUE)) return kFALSE;
760 }
c0893d28 761 // PWG2 unicor
762 if (iPWG2unicor) {
763 if (!LoadLibrary("PWG2unicor", mode, kTRUE)) return kFALSE;
764 }
765 // PWG2 evchar
766 if (iPWG2evchar) {
767 if (!LoadLibrary("PWG2evchar", mode, kTRUE)) return kFALSE;
768 }
c6e7c68c 769 // PWG2 femtoscopy
770 if (iPWG2femto) {
771 if (!LoadLibrary("PWG2AOD", mode, kTRUE) ||
772 !LoadLibrary("PWG2femtoscopy", mode, kTRUE) ||
773 !LoadLibrary("PWG2femtoscopyUser", mode, kTRUE)) return kFALSE;
a42c0df6 774 TFile::Cp(gSystem->ExpandPathName("$(ALICE_ROOT)/PWG2/FEMTOSCOPY/macros/ConfigFemtoAnalysis.C"), Form("%s/ConfigFemtoAnalysis.C", train_name.Data()));
775 anaLibs += "ConfigFemtoAnalysis.C ";
c6e7c68c 776 }
2a47e7b4 777 // PWG3 Vertexing HF
c6e7c68c 778 if (iPWG3vertexing) {
15dac83a 779 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
780 !LoadLibrary("PWG3vertexingHF", mode, kTRUE)) return kFALSE;
c6e7c68c 781 }
2a47e7b4 782 // PWG3 hfe
783 if (iPWG3hfe) {
784 if (!LoadLibrary("PWG3hfe", mode, kTRUE)) return kFALSE;
785 }
786
a42c0df6 787 ::Info("AnalysisTrainNew.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
c6e7c68c 788 return kTRUE;
789}
790
791//______________________________________________________________________________
792Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
793{
794// Load a module library in a given mode. Reports success.
795 Int_t imode = -1;
796 Int_t result;
797 TString smodule(module);
798 if (!strcmp(mode, "LOCAL")) imode = 0;
799 if (!strcmp(mode, "PROOF")) imode = 1;
800 if (!strcmp(mode, "GRID")) imode = 2;
801 TString mod(module);
802 if (!mod.Length()) {
a42c0df6 803 ::Error("AnalysisTrainNew.C::LoadLibrary", "Empty module name");
c6e7c68c 804 return kFALSE;
805 }
806 // If a library is specified, just load it
807 if (smodule.EndsWith(".so")) {
808 mod.Remove(mod.Index(".so"));
809 result = gSystem->Load(mod);
810 if (result < 0) {
a42c0df6 811 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load library %s", module);
c6e7c68c 812 return kFALSE;
813 }
814 if (rec) anaLibs += Form("%s.so ",mod.Data());
815 return kTRUE;
816 }
817 // Check if the library is already loaded
818 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
819 return kTRUE;
820 switch (imode) {
821 case 0:
822 case 2:
823 if (usePAR) {
824 result = SetupPar(module);
825 if (rec) anaPars += Form("%s.par ", module);
826 } else {
827 result = gSystem->Load(Form("lib%s.so", module));
828 if (rec) anaLibs += Form("lib%s.so ", module);
829 }
830 break;
831 case 1:
832 result = gProof->UploadPackage(module);
833 if (result<0) {
834 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
835 if (result<0) {
a42c0df6 836 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
c6e7c68c 837 return kFALSE;
838 }
839 }
840 result = gProof->EnablePackage(module);
841 break;
842 default:
843 return kFALSE;
844 }
845 if (result < 0) {
a42c0df6 846 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load module %s", module);
c6e7c68c 847 return kFALSE;
848 }
849 return kTRUE;
850}
851
852
853//______________________________________________________________________________
854TChain *CreateChain(const char *mode, const char *plugin_mode)
855{
856// Create the input chain
857 Int_t imode = -1;
858 if (!strcmp(mode, "LOCAL")) imode = 0;
859 if (!strcmp(mode, "PROOF")) imode = 1;
860 if (!strcmp(mode, "GRID")) imode = 2;
861 TChain *chain = NULL;
862 // Local chain
863 switch (imode) {
864 case 0:
865 if (iAODanalysis) {
a42c0df6 866 if (!local_xmldataset.Length()) {
c6e7c68c 867 // Local AOD
868 chain = new TChain("aodTree");
274ff025 869 if (gSystem->AccessPathName("data/AliAOD.root"))
a42c0df6 870 ::Error("AnalysisTrainNew.C::CreateChain", "File: AliAOD.root not in ./data dir");
b160b576 871 else {
872 if (!saveTrain) chain->Add("data/AliAOD.root");
873 else chain->Add("../data/AliAOD.root");
874 }
c6e7c68c 875 } else {
876 // Interactive AOD
a42c0df6 877 chain = CreateChainSingle(local_xmldataset, "aodTree");
c6e7c68c 878 }
879 } else {
a42c0df6 880 if (!local_xmldataset.Length()) {
c6e7c68c 881 // Local ESD
882 chain = new TChain("esdTree");
099d8f33 883 if (gSystem->AccessPathName("data/AliESDs.root"))
a42c0df6 884 ::Error("AnalysisTrainNew.C::CreateChain", "File: AliESDs.root not in ./data dir");
b160b576 885 else {
886 if (!saveTrain) chain->Add("data/AliESDs.root");
887 else chain->Add("../data/AliESDs.root");
888 }
c6e7c68c 889 } else {
890 // Interactive ESD
a42c0df6 891 chain = CreateChainSingle(local_xmldataset, "esdTree");
c6e7c68c 892 }
893 }
894 break;
895 case 1:
896 break;
897 case 2:
898 if (usePLUGIN) {
899 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
900 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
901 } else {
902 TString treeName = "esdTree";
903 if (iAODanalysis) treeName = "aodTree";
904 chain = CreateChainSingle("wn.xml", treeName);
905 }
906 break;
907 default:
908 }
909 if (chain && chain->GetNtrees()) return chain;
910 return NULL;
911}
912
913//______________________________________________________________________________
914TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
915{
916 printf("*******************************\n");
917 printf("*** Getting the ESD Chain ***\n");
918 printf("*******************************\n");
919 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
920
921 if (!myCollection) {
a42c0df6 922 ::Error("AnalysisTrainNew.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
c6e7c68c 923 return NULL ;
924 }
925
926 TChain* chain = new TChain(treeName);
927 myCollection->Reset() ;
928 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
929 chain->ls();
930 return chain;
931}
932
933//______________________________________________________________________________
934Int_t SetupPar(char* pararchivename)
935{
936 if (!pararchivename || !strlen(pararchivename)) return -1;
937 char processline[1024];
938 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
939 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
a42c0df6 940 ::Info("AnalysisTrainNew.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
c6e7c68c 941 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
942 Form("%s.par",pararchivename));
943 } else {
a42c0df6 944 ::Error("AnalysisTrainNew.C::SetupPar", "Cannot find %s.par", pararchivename);
c6e7c68c 945 return -1;
946 }
947 }
a42c0df6 948 if (usePLUGIN && saveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, train_name.Data()));
c6e7c68c 949 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
950
951 TString ocwd = gSystem->WorkingDirectory();
952 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
953
954 // check for BUILD.sh and execute
955 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
956 printf("*******************************\n");
957 printf("*** Building PAR archive ***\n");
958 printf("*******************************\n");
959 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
960 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
961 return -1;
962 }
963 }
964
965 // check for SETUP.C and execute
966 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
967 printf("*******************************\n");
968 printf("*** Setup PAR archive ***\n");
969 printf("*******************************\n");
970 gROOT->Macro("PROOF-INF/SETUP.C");
971 }
972 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
973 return 0;
974}
975
976//______________________________________________________________________________
5c4c538a 977AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
c6e7c68c 978{
979// Check if user has a valid token, otherwise make one. This has limitations.
980// One can always follow the standard procedure of calling alien-token-init then
981// source /tmp/gclient_env_$UID in the current shell.
982 if (!AliAnalysisGrid::CreateToken()) return NULL;
983 AliAnalysisAlien *plugin = new AliAnalysisAlien();
984// Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
985 plugin->SetRunMode(plugin_mode);
5c4c538a 986 if (useProductionMode) plugin->SetProductionMode();
0d5d317c 987 plugin->SetJobTag(job_tag);
c6e7c68c 988 plugin->SetNtestFiles(1);
0d5d317c 989// plugin->SetPreferedSE("ALICE::Legnaro::SE");
c6e7c68c 990// Set versions of used packages
991 plugin->SetAPIVersion("V2.4");
992 plugin->SetROOTVersion(root_version);
993 plugin->SetAliROOTVersion(aliroot_version);
994// Declare input data to be processed.
995// Method 1: Create automatically XML collections using alien 'find' command.
996// Define production directory LFN
997 plugin->SetGridDataDir(alien_datadir);
998// Set data search pattern
274ff025 999 if (iAODanalysis) plugin->SetDataPattern("*AliAOD.root");
275942e0 1000 else plugin->SetDataPattern("*ESD.tag.root");
c6e7c68c 1001// ...then add run numbers to be considered
3b1610cf 1002 plugin->SetRunRange(run_range[0], run_range[1]);
1003// for (Int_t i=0; i<10; i++) {
1004// if (run_numbers[i]==0) break;
1005// plugin->AddRunNumber(run_numbers[i]);
1006// }
c6e7c68c 1007// Method 2: Declare existing data files (raw collections, xml collections, root file)
1008// If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
1009// XML collections added via this method can be combined with the first method if
1010// the content is compatible (using or not tags)
1011// plugin->AddDataFile("tag.xml");
1012// plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
1013// Define alien work directory where all files will be copied. Relative to alien $HOME.
274ff025 1014 if (iAODanalysis) plugin->SetGridWorkingDir("analysisAOD");
1015 else plugin->SetGridWorkingDir("analysisESD");
c6e7c68c 1016// Declare alien output directory. Relative to working directory.
371c967e 1017 if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
1018 plugin->SetGridOutputDir(alien_outdir);
c6e7c68c 1019
1020 TString ana_sources = "";
1021 TString ana_add = "";
1022 if (usePAR && anaPars.Length()) {
7581b1bc 1023 printf("%s\n", anaPars.Data());
c6e7c68c 1024 TObjArray *arr;
1025 TObjString *objstr;
1026 arr = anaPars.Tokenize(" ");
1027 TIter next(arr);
1028 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
1029 delete arr;
1030 }
1031
1032// Declare the analysis source files names separated by blancs. To be compiled runtime
1033// using ACLiC on the worker nodes.
1034 ana_sources = ana_sources.Strip();
1035// Declare all libraries (other than the default ones for the framework. These will be
1036// loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
1037 anaLibs = anaLibs.Strip();
1038 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
1039 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs);
1040
1041// Declare the output file names separated by blancs.
1042// (can be like: file.root or file.root@ALICE::Niham::File)
1043 plugin->SetDefaultOutputs();
275942e0 1044 plugin->SetMergeExcludes(mergeExclude);
1045 plugin->SetMaxMergeFiles(maxMergeFiles);
1046 plugin->SetNrunsPerMaster(nRunsPerMaster);
c6e7c68c 1047// Optionally define the files to be archived.
526b1502 1048// plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
2a47e7b4 1049 plugin->SetOutputArchive(Form("log_archive.zip:stdout,stderr@ALICE::CERN::SE %s",outputArchive.Data()));
c6e7c68c 1050// Optionally set a name for the generated analysis macro (default MyAnalysis.C)
a42c0df6 1051 plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
c6e7c68c 1052// Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
275942e0 1053 plugin->SetSplitMaxInputFileNumber(nFilesPerJob);
c6e7c68c 1054// Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1055// plugin->SetMaxInitFailed(5);
1056// Optionally resubmit threshold.
1057// plugin->SetMasterResubmitThreshold(90);
1058// Optionally set time to live (default 30000 sec)
1059 plugin->SetTTL(30000);
1060// Optionally set input format (default xml-single)
1061 plugin->SetInputFormat("xml-single");
1062// Optionally modify the name of the generated JDL (default analysis.jdl)
a42c0df6 1063 plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
7ceeacc7 1064// Optionally modify the executable name (default analysis.sh)
a42c0df6 1065 plugin->SetExecutable(Form("%s.sh", train_name.Data()));
c6e7c68c 1066// Optionally modify job price (default 1)
1067 plugin->SetPrice(1);
1068// Optionally modify split mode (default 'se')
1069 plugin->SetSplitMode("se");
1070 return plugin;
1071}
a42c0df6 1072
1073//______________________________________________________________________________
1074void WriteConfig()
1075{
1076// Write train configuration in a file. The file name has the format:
1077// train_[trainName]_ddMonthyyyy_time.C
371c967e 1078 if (useDATE) {
0d5d317c 1079 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
1080 ifstream fdate("date.tmp");
1081 if (!fdate.is_open()) {
1082 ::Error("AnalysisTrainNew.C::Export","Could not generate file name");
1083 return;
1084 }
371c967e 1085 const char date[64];
1086 fdate.getline(date,64);
1087 fdate.close();
1088 gSystem->Exec("rm date.tmp");
1089 train_name = Form("train_%s_%s", train_name.Data(), date);
1090 } else {
1091 train_name = Form("train_%s", train_name.Data());
1092 }
a42c0df6 1093 TString cdir = gSystem->WorkingDirectory();
1094 gSystem->MakeDirectory(train_name);
1095 gSystem->ChangeDirectory(train_name);
1096 ofstream out;
0d5d317c 1097 out.open(Form("%sConfig.C",train_name.Data()), ios::out);
a42c0df6 1098 if (out.bad()) {
1099 ::Error("AnalysisTrainNew.C::Export", "Cannot open ConfigTrain.C for writing");
1100 return;
1101 }
1102 out << "{" << endl;
1103 out << " train_name = " << "\"" << train_name.Data() << "\";" << endl;
1104 out << " proof_cluster = " << "\"" << proof_cluster.Data() << "\";" << endl;
1105 out << " useAFPAR = " << useAFPAR << ";" << endl;
1106 if (useAFPAR)
1107 out << " AFversion = " << AFversion.Data() << ";" << endl;
1108 out << " proof_dataset = " << "\"" << proof_dataset.Data() << "\";" << endl;
1109 out << " usePLUGIN = " << usePLUGIN << ";" << endl;
1110 out << " usePAR = " << usePAR << ";" << endl;
1111 out << " useCPAR = " << useCPAR << ";" << endl;
1112 out << " root_version = " << "\"" << root_version.Data() << "\";" << endl;
1113 out << " aliroot_version = " << "\"" << aliroot_version.Data() << "\";" << endl;
1114 out << " alien_datadir = " << "\"" << alien_datadir.Data() << "\";" << endl;
371c967e 1115 if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
1116 out << " alien_outdir = " << "\"" << alien_outdir.Data() << "\";" << endl;
275942e0 1117 out << " maxMergeFiles = " << maxMergeFiles << ";" << endl;
1118 out << " mergeExclude = " << "\"" << mergeExclude.Data() << "\";" << endl;
1119 out << " nRunsPerMaster = " << nRunsPerMaster << ";" << endl;
1120 out << " nFilesPerJob = " << nFilesPerJob << ";" << endl;
3b1610cf 1121// for (Int_t i=0; i<10; i++) {
1122// if (run_numbers[i])
1123// out << " run_numbers[" << i << "] = " << run_numbers[i] << ";" << endl;
1124// }
1125 out << " run_range[0] = " << run_range[0] << ";" << endl;
1126 out << " run_range[1] = " << run_range[1] << ";" << endl;
a42c0df6 1127 out << " useDBG = " << useDBG << ";" << endl;
1128 out << " useMC = " << useMC << ";" << endl;
1129 out << " useTAGS = " << useTAGS << ";" << endl;
1130 out << " useKFILTER = " << useKFILTER << ";" << endl;
1131 out << " useTR = " << useTR << ";" << endl;
1132 out << " useCORRFW = " << useCORRFW << ";" << endl;
1133 out << " useAODTAGS = " << useAODTAGS << ";" << endl;
1134 out << " saveTrain = " << "kFALSE;" << endl << endl;
1135 out << " // Analysis modules" << endl;
1136 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
1137 out << " iAODhandler = " << iAODhandler << ";" << endl;
1138 out << " iESDfilter = " << iESDfilter << ";" << endl;
1139 out << " iMUONcopyAOD = " << iMUONcopyAOD << ";" << endl;
1140 out << " iJETAN = " << iJETAN << ";" << endl;
1141 out << " iPWG4partcorr = " << iPWG4partcorr << ";" << endl;
c3a83447 1142 out << " iPWG4gammaconv = " << iPWG4gammaconv << ";" << endl;
5c4c538a 1143 out << " iPWG4omega3pi = " << iPWG4omega3pi << ";" << endl;
2a47e7b4 1144 out << " iPWG3vertexing = " << iPWG3vertexing << ";" << endl;
1145 out << " iPWG3hfe = " << iPWG3hfe << ";" << endl;
a42c0df6 1146 out << " iPWG2femto = " << iPWG2femto << ";" << endl;
1147 out << " iPWG2spectra = " << iPWG2spectra << ";" << endl;
0d5d317c 1148 out << " iPWG2protons = " << iPWG2protons << ";" << endl;
1149 out << " iPWG2checkcascade = " << iPWG2checkcascade << ";" << endl;
1150 out << " iPWG2perfcascade = " << iPWG2perfcascade << ";" << endl;
1151 out << " iPWG2checkv0 = " << iPWG2checkv0 << ";" << endl;
1152 out << " iPWG2strange = " << iPWG2strange << ";" << endl;
a42c0df6 1153 out << " iPWG2flow = " << iPWG2flow << ";" << endl;
1154 out << " iPWG2res = " << iPWG2res << ";" << endl;
1155 out << " iPWG2kink = " << iPWG2kink << ";" << endl;
0d5d317c 1156 out << " iPWG2kinkESDMC = " << iPWG2kinkESDMC << ";" << endl;
1157 out << " iPWG2kinkres = " << iPWG2kinkres << ";" << endl;
1158 out << " iPWG2kinklikesign = " << iPWG2kinklikesign << ";" << endl;
c0893d28 1159 out << " iPWG2unicor = " << iPWG2unicor << ";" << endl;
1160 out << " iPWG2evchar = " << iPWG2evchar << ";" << endl;
a42c0df6 1161 out << "}" << endl;
1162 ::Info("AnalysisTrainNew.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", train_name.Data()));
1163 gSystem->ChangeDirectory(cdir);
1164}
1165
1166//______________________________________________________________________________
1167Bool_t LoadConfig(const char *filename)
1168{
1169// Read train configuration from file
1170 if (gSystem->AccessPathName(filename)) {
1171 ::Error("AnalysisTrainNew.C::LoadConfig", "Config file name not found");
1172 return kFALSE;
1173 }
1174 gROOT->ProcessLine(Form(".x %s", filename));
1175 ::Info("AnalysisTrainNew.C::LoadConfig", "Train configuration loaded from file %s", filename);
1176 return kTRUE;
1177}