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