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