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