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