]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/macros/AnalysisTrainNew.C
Fixed calling sequence for FLOW analysis.
[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           = 0;      // 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       AliAnalysisTaskCheckPerformanceCascade *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       AliAnalysisTaskKinkResonance *taskkinkres = AddTaskKinkResonance();
266       if (!taskkinkres) ::Warning("AnalysisTrainNew", "AliAnalysisTaskKinkResonance 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 LYZ1SUM  = kTRUE;
277       Bool_t LYZ1PROD = kTRUE;
278       Bool_t LYZ2SUM  = kFALSE; 
279       Bool_t LYZ2PROD = kFALSE;
280       Bool_t LYZEP    = kFALSE; 
281       Bool_t GFC      = kTRUE;
282       Bool_t QC       = kTRUE;
283       Bool_t FQD      = kFALSE;
284       Bool_t MCEP     = kFALSE; //does not work yet 24/12/08
285       Bool_t kineFromESD = kTRUE;
286       Bool_t METHODS[] = {SP,LYZ1SUM,LYZ1PROD,LYZ2SUM,LYZ2PROD,LYZEP,GFC,QC,FQD,MCEP};
287       // Analysis type can be ESD, AOD, MC, ESDMC0, ESDMC1
288       TString type = "AOD";
289       if (!iAODanalysis) type = "ESD";
290       if (useMC) {
291          type += "MC";
292          if (!kineFromESD) type += "1";
293          else type += "0";
294       }   
295       // Boolean to fill/not fill the QA histograms
296       Bool_t QA = kTRUE;   
297       // Boolean to use/not use weights for the Q vector
298       Bool_t WEIGHTS[] = {kFALSE,kFALSE,kFALSE}; //Phi, v'(pt), v'(eta)
299       AliAnalysisTaskFlowEvent* taskFE = AddTaskFlow(type,METHODS,QA,WEIGHTS);
300       if (!taskFE) ::Warning("AnalysisTrainNew", "AliAnalysisTaskFlowEvent cannot run for this train conditions - EXCLUDED");
301    }   
302
303    // PWG2 resonances
304    if (iPWG2res) {
305       gROOT->LoadMacro("$ALICE_ROOT/PWG2/RESONANCES/macros/AddAnalysisTaskRsn.C");
306       AddAnalysisTaskRsn(AliLog::kError, kFALSE, "output_rsn.root", !(Bool_t)iAODhandler);
307    }   
308            
309    // PWG3 vertexing
310    if (iPWG3vertexing) {
311       gROOT->LoadMacro("$ALICE_ROOT/PWG3/vertexingHF/AddTaskVertexingHF.C");
312       AliAnalysisTaskSEVertexingHF *taskvertexingHF = AddTaskVertexingHF();
313       if (!taskvertexingHF) ::Warning("AnalysisTrainNew", "AliAnalysisTaskSEVertexingHF cannot run for this train conditions - EXCLUDED");
314    }   
315       
316    // PWG4 hadron correlations
317    if (iPWG4partcorr) {
318       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
319       AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS");
320       if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
321       AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL");
322       if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
323    }   
324
325    // PWG4 gamma conversion analysis
326    if (iPWG4gammaconv) {
327       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
328       TString fileIn = "";
329       TString arguments = " -data-list "+  fileIn+ " -output-file-name common" + " -run-on-train"+" -run-jet"+" -run-chic"+" -run-neutralmeson";
330       AliAnalysisTaskGammaConversion * taskGammaConversion = AddTaskGammaConversion(arguments,mgr->GetCommonInputContainer());
331       if (!taskGammaConversion) ::Warning("AnalysisTrainNew", "AliAnalysisTaskGammaConversion cannot run for these train conditions - EXCLUDED");
332    }   
333    //==========================================================================
334    // FOR THE REST OF THE TASKS THE MACRO AddTaskXXX() is not yet implemented/
335    // Run the analysis
336    //    
337    if (mgr->InitAnalysis()) {
338       mgr->PrintStatus();
339       if (saveTrain || strlen(config_file)) gSystem->ChangeDirectory(train_name);
340       StartAnalysis(smode, chain);
341       if (saveTrain) {
342          printf("=== Registering ConfigTrain.C in the output directory <%s> ===\n",
343                 alien_outdir.Data());
344          TFile::Cp("file:ConfigTrain.C", Form("alien://%s/ConfigTrain.C", alien_outdir.Data()));
345       }
346    }
347 }
348
349 //______________________________________________________________________________
350 void StartAnalysis(const char *mode, TChain *chain) {
351 // Start analysis.
352    Int_t imode = -1;
353    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
354    if (!strcmp(mode, "LOCAL")) imode = 0;
355    if (!strcmp(mode, "PROOF")) imode = 1;
356    if (!strcmp(mode, "GRID"))  imode = 2;
357    switch (imode) {
358       case 0:
359          if (!chain) {
360             ::Error("AnalysisTrainNew.C::StartAnalysis", "Cannot create the chain");
361             return;
362          }   
363          mgr->StartAnalysis(mode, chain);
364          return;
365       case 1:
366          if (!proof_dataset.Length()) {
367             ::Error("AnalysisTrainNew.C::StartAnalysis", "proof_dataset is empty");
368             return;
369          }   
370          mgr->StartAnalysis(mode, proof_dataset, 1000);
371          return;
372       case 2:
373          if (usePLUGIN) {
374             if (!mgr->GetGridHandler()) {
375                ::Error("AnalysisTrainNew.C::StartAnalysis", "Grid plugin not initialized");
376                return;
377             }   
378             mgr->StartAnalysis("grid");
379          } else {
380             if (!chain) {
381                ::Error("AnalysisTrainNew.C::StartAnalysis", "Cannot create the chain");
382                return;
383             }   
384             mgr->StartAnalysis(mode, chain);
385          }   
386          return;
387    }      
388 }          
389     
390 //______________________________________________________________________________
391 void CheckModuleFlags(const char *mode) {
392 // Checks selected modules and insure compatibility
393    Int_t imode = -1;
394    if (!strcmp(mode, "LOCAL")) imode = 0;
395    if (!strcmp(mode, "PROOF")) imode = 1;
396    if (!strcmp(mode, "GRID"))  imode = 2;
397    if (imode==1) {
398       if (!usePAR) {
399          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
400          usePAR = kTRUE;
401       }   
402    }  
403    if (imode != 2) {
404       ::Info("AnalysisTrainNew.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
405       usePLUGIN = kFALSE; 
406    }   
407    if (iAODanalysis) {
408    // AOD analysis
409       if (useMC)
410          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "MC usage disabled in analysis on AOD's");
411       useMC = kFALSE;
412       useTR = kFALSE;
413       if (iESDfilter)
414          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "ESD filter disabled in analysis on AOD's");
415       iESDfilter   = 0;
416       if (!iAODhandler) {
417          if (iJETAN) 
418             ::Info("AnalysisTrainNew.C::CheckModuleFlags", "JETAN disabled in analysis on AOD's without AOD handler");
419          iJETAN = 0;
420          if (iPWG4gammaconv)
421             ::Info("AnalysisTrainNew.C::CheckModuleFlags", "iPWG4gammaconv disabled on AOD's");
422       }
423       // Disable tasks that do not work yet on AOD data
424       if (iPWG2kink)         
425          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2kink disabled in analysis on AOD's");
426          iPWG2kink = 0;
427    } else {   
428    // ESD analysis
429       iMUONcopyAOD = 0;
430    }       
431    if (iJETAN) iESDfilter=1;
432    if (iESDfilter) iAODhandler=1;
433    if (iPWG2spectra || iPWG2flow || iPWG3vertexing) useCORRFW = kTRUE;
434    if (useKFILTER && !useMC) useKFILTER = kFALSE;
435    if (useAODTAGS && !iAODhandler) useAODTAGS = kFALSE;
436 }
437
438 //______________________________________________________________________________
439 Bool_t Connect(const char *mode) {
440 // Connect <username> to the back-end system.
441    Int_t imode = -1;
442    if (!strcmp(mode, "LOCAL")) imode = 0;
443    if (!strcmp(mode, "PROOF")) imode = 1;
444    if (!strcmp(mode, "GRID"))  imode = 2;
445    TString username = gSystem->Getenv("alien_API_USER");
446    switch (imode) {
447       case 0:
448          break;
449       case 1:
450          if  (!username.Length()) {
451             ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Make sure you:\n \
452                            1. Have called: alien-token-init <username>\n \
453                            2. Have called: >source /tmp/gclient_env_$UID");
454             return kFALSE;
455          }
456          ::Info("AnalysisTrainNew.C::Connect", "Connecting user <%s> to PROOF cluster <%s>", 
457                 username.Data(), proof_cluster.Data());
458          gEnv->SetValue("XSec.GSI.DelegProxy", "2");
459 //         TProof::Open(Form("%s@%s:31093", username.Data(), proof_cluster.Data()));       
460          TProof::Open(Form("%s@%s", username.Data(), proof_cluster.Data()));       
461          if (!gProof) {
462             if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
463                ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
464             return kFALSE;
465          }
466          TGrid::Connect("alien://");
467          if (gGrid) {
468             TString homedir = gGrid->GetHomeDirectory();
469             TString workdir = homedir + train_name;
470             if (!gGrid->Cd(workdir)) {
471                gGrid->Cd(homedir);
472                if (gGrid->Mkdir(workdir)) {
473                   gGrid->Cd(train_name);
474                   ::Info("AnalysisTrainNew::Connect()", "Directory %s created", gGrid->Pwd());
475                }
476             }
477             gGrid->Mkdir("proof_output");
478             gGrid->Cd("proof_output");
479             proof_outdir = Form("alien://%s", gGrid->Pwd());
480          }   
481          break;
482       case 2:      
483          if  (!username.Length()) {
484             ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Make sure you:\n \
485                            1. Have called: alien-token-init <username>\n \
486                            2. Have called: >source /tmp/gclient_env_$UID");
487             return kFALSE;
488          }
489          if (usePLUGIN && !gSystem->Getenv("alien_CLOSE_SE")) {
490             ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), 
491                            "When using the AliEn plugin it is preferable to define the \
492                            variable alien_CLOSE_SE in your environment.");
493             return kFALSE;
494          }
495          ::Info("AnalysisTrainNew.C::Connect", "Connecting user <%s> to AliEn ...", 
496                 username.Data());
497          TGrid::Connect("alien://");
498          if (!gGrid || !gGrid->IsConnected()) return kFALSE;
499          break;
500       default:
501          ::Error("AnalysisTrainNew.C::Connect", "Unknown run mode: %s", mode);
502          return kFALSE;
503    }
504    ::Info("AnalysisTrainNew.C::Connect","Connected in %s mode", mode);
505    return kTRUE;
506 }
507
508 //______________________________________________________________________________
509 Bool_t LoadCommonLibraries(const char *mode)
510 {
511 // Load common analysis libraries.
512    Int_t imode = -1;
513    if (!strcmp(mode, "LOCAL")) imode = 0;
514    if (!strcmp(mode, "PROOF")) imode = 1;
515    if (!strcmp(mode, "GRID"))  imode = 2;
516    if (!gSystem->Getenv("ALICE_ROOT")) {
517       ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot"); 
518       return kFALSE;
519    }   
520    Bool_t success = kTRUE;
521    // ROOT libraries
522    gSystem->Load("libTree.so");
523    gSystem->Load("libGeom.so");
524    gSystem->Load("libVMC.so");
525    gSystem->Load("libPhysics.so");
526    
527    // Load framework classes. Par option ignored here.
528    switch (imode) {
529       case 0:
530       case 2:
531          if (useCPAR) {
532             success &= LoadLibrary("STEERBase", mode, kTRUE);
533             success &= LoadLibrary("ESD", mode, kTRUE);
534             success &= LoadLibrary("AOD", mode, kTRUE);
535             success &= LoadLibrary("ANALYSIS", mode, kTRUE);
536             success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
537             if (useCORRFW) success &= LoadLibrary("CORRFW", mode, kTRUE);
538          } else {   
539             success &= LoadLibrary("libSTEERBase.so", mode);
540             success &= LoadLibrary("libESD.so", mode);
541             success &= LoadLibrary("libAOD.so", mode);
542             success &= LoadLibrary("libANALYSIS.so", mode);
543             success &= LoadLibrary("libANALYSISalice.so", mode);
544             if (useCORRFW) success &= LoadLibrary("libCORRFW.so", mode);
545             gROOT->ProcessLine(".include $ALICE_ROOT/include");
546          }   
547          break;
548       case 1:
549          Int_t ires = -1;
550          if (useAFPAR && !gSystem->AccessPathName(AFversion)) ires = gProof->UploadPackage(AFversion);
551          if (ires < 0) {
552             success &= LoadLibrary("STEERBase", mode);
553             success &= LoadLibrary("ESD", mode);
554             success &= LoadLibrary("AOD", mode);
555             success &= LoadLibrary("ANALYSIS", mode);
556             success &= LoadLibrary("ANALYSISalice", mode);
557             if (useCORRFW) success &= LoadLibrary("CORRFW", mode);
558          } else { 
559             ires = gProof->EnablePackage(AFversion);
560             if (ires<0) success = kFALSE;
561             if (useCORRFW) success &= LoadLibrary("CORRFW", mode);
562          }
563          break;         
564       default:
565          ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
566          return kFALSE;
567    }
568    if (success) {
569       ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries:    SUCCESS");
570       ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
571               gSystem->GetIncludePath());
572    } else {           
573       ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries:    FAILED");
574    }   
575       
576    return success;
577 }
578
579 //______________________________________________________________________________
580 Bool_t LoadAnalysisLibraries(const char *mode)
581 {
582 // Load common analysis libraries.
583    Bool_t success = kTRUE;
584    if (iESDfilter) {
585       if (!LoadLibrary("PWG3base", mode, kTRUE) ||
586           !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
587    }   
588    // JETAN
589    if (iJETAN) {
590       if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
591    }               
592    // PWG4 particle correlations
593    if (iPWG4partcorr) {   
594       if (!LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
595           !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
596    }
597    // PWG4 gamma conversion
598    if (iPWG4gammaconv) {
599       if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
600    }      
601    // PWG2 task protons 
602    if (iPWG2spectra) {
603       if (!LoadLibrary("PWG2spectra", mode, kTRUE)) return kFALSE;
604    }
605    // PWG2 flow
606    if (iPWG2flow) {
607       if (!LoadLibrary("PWG2flowCommon", mode, kTRUE) ||
608           !LoadLibrary("PWG2flowTasks", mode, kTRUE)) return kFALSE;
609    }
610    // PWG2 resonances
611    if (iPWG2res) {
612       if (!LoadLibrary("PWG2resonances", mode, kTRUE)) return kFALSE;
613    }   
614    // PWG2 kink
615    if (iPWG2kink) {
616       if (!LoadLibrary("PWG2kink", mode, kTRUE)) return kFALSE;
617    }   
618    // PWG2 femtoscopy
619    if (iPWG2femto) {
620       if (!LoadLibrary("PWG2AOD", mode, kTRUE) ||
621           !LoadLibrary("PWG2femtoscopy", mode, kTRUE) ||
622           !LoadLibrary("PWG2femtoscopyUser", mode, kTRUE)) return kFALSE;
623       TFile::Cp(gSystem->ExpandPathName("$(ALICE_ROOT)/PWG2/FEMTOSCOPY/macros/ConfigFemtoAnalysis.C"), Form("%s/ConfigFemtoAnalysis.C", train_name.Data()));
624       anaLibs += "ConfigFemtoAnalysis.C ";
625    }   
626    // Vertexing HF
627    if (iPWG3vertexing) {
628       if (!LoadLibrary("PWG3base", mode, kTRUE) ||
629           !LoadLibrary("PWG3vertexingHF", mode, kTRUE)) return kFALSE;
630    }   
631    ::Info("AnalysisTrainNew.C::LoadAnalysisLibraries", "Load other libraries:   SUCCESS");
632    return kTRUE;
633 }
634
635 //______________________________________________________________________________
636 Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
637 {
638 // Load a module library in a given mode. Reports success.
639    Int_t imode = -1;
640    Int_t result;
641    TString smodule(module);
642    if (!strcmp(mode, "LOCAL")) imode = 0;
643    if (!strcmp(mode, "PROOF")) imode = 1;
644    if (!strcmp(mode, "GRID"))  imode = 2;
645    TString mod(module);
646    if (!mod.Length()) {
647       ::Error("AnalysisTrainNew.C::LoadLibrary", "Empty module name");
648       return kFALSE;
649    }   
650    // If a library is specified, just load it
651    if (smodule.EndsWith(".so")) {
652       mod.Remove(mod.Index(".so"));
653       result = gSystem->Load(mod);
654       if (result < 0) {
655          ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load library %s", module);
656          return kFALSE;
657       }
658       if (rec) anaLibs += Form("%s.so ",mod.Data()); 
659       return kTRUE;
660    } 
661    // Check if the library is already loaded
662    if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
663       return kTRUE;    
664    switch (imode) {
665       case 0:
666       case 2:
667          if (usePAR) {
668             result = SetupPar(module);
669             if (rec) anaPars += Form("%s.par ", module);
670          } else {
671             result = gSystem->Load(Form("lib%s.so", module));
672             if (rec) anaLibs += Form("lib%s.so ", module);
673          }   
674          break;
675       case 1:
676          result = gProof->UploadPackage(module);
677          if (result<0) {
678             result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
679             if (result<0) {
680                ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
681                return kFALSE;
682             }
683          }   
684          result = gProof->EnablePackage(module);
685          break;
686       default:
687          return kFALSE;
688    }         
689    if (result < 0) {
690       ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load module %s", module);
691       return kFALSE;
692    }
693    return kTRUE;
694 }           
695
696
697 //______________________________________________________________________________
698 TChain *CreateChain(const char *mode, const char *plugin_mode)
699 {
700 // Create the input chain
701    Int_t imode = -1;
702    if (!strcmp(mode, "LOCAL")) imode = 0;
703    if (!strcmp(mode, "PROOF")) imode = 1;
704    if (!strcmp(mode, "GRID"))  imode = 2;
705    TChain *chain = NULL;
706    // Local chain
707    switch (imode) {
708       case 0:
709          if (iAODanalysis) {
710             if (!local_xmldataset.Length()) {
711                // Local AOD
712                chain = new TChain("aodTree");
713                if (gSystem->AccessPathName("data/AliAOD.root")) 
714                   ::Error("AnalysisTrainNew.C::CreateChain", "File: AliAOD.root not in ./data dir");
715                else {
716                   if (!saveTrain) chain->Add("data/AliAOD.root");
717                   else            chain->Add("../data/AliAOD.root");
718                }   
719             } else {
720                // Interactive AOD
721                chain = CreateChainSingle(local_xmldataset, "aodTree");
722             }
723          } else {      
724             if (!local_xmldataset.Length()) {
725                // Local ESD
726                chain = new TChain("esdTree");
727                if (gSystem->AccessPathName("data/AliESDs.root")) 
728                   ::Error("AnalysisTrainNew.C::CreateChain", "File: AliESDs.root not in ./data dir");
729                else {
730                   if (!saveTrain) chain->Add("data/AliESDs.root");
731                   else            chain->Add("../data/AliESDs.root");
732                }   
733             } else {
734                // Interactive ESD
735                chain = CreateChainSingle(local_xmldataset, "esdTree");
736             }   
737          }
738          break;
739       case 1:
740          break;
741       case 2:
742          if (usePLUGIN) {
743             AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
744             AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
745          } else {
746             TString           treeName = "esdTree";
747             if (iAODanalysis) treeName = "aodTree";
748             chain = CreateChainSingle("wn.xml", treeName);
749          }
750          break;      
751       default:   
752    }
753    if (chain && chain->GetNtrees()) return chain;
754    return NULL;
755 }   
756
757 //______________________________________________________________________________
758 TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
759 {
760    printf("*******************************\n");
761    printf("*** Getting the ESD Chain   ***\n");
762    printf("*******************************\n");
763    TAlienCollection * myCollection  = TAlienCollection::Open(xmlfile);
764
765    if (!myCollection) {
766       ::Error("AnalysisTrainNew.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
767       return NULL ;
768    }
769
770    TChain* chain = new TChain(treeName);
771    myCollection->Reset() ;
772    while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
773    chain->ls();
774    return chain;
775 }
776
777 //______________________________________________________________________________
778 Int_t SetupPar(char* pararchivename)
779 {
780    if (!pararchivename || !strlen(pararchivename)) return -1;
781    char processline[1024];
782    if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
783       if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
784          ::Info("AnalysisTrainNew.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
785          TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)), 
786                    Form("%s.par",pararchivename));
787       } else {
788          ::Error("AnalysisTrainNew.C::SetupPar", "Cannot find %s.par", pararchivename);
789          return -1;
790       }   
791    }
792    if (usePLUGIN && saveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, train_name.Data()));
793    gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
794
795    TString ocwd = gSystem->WorkingDirectory();
796    if (!gSystem->ChangeDirectory(pararchivename)) return -1;
797         
798    // check for BUILD.sh and execute
799    if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
800       printf("*******************************\n");
801       printf("*** Building PAR archive    ***\n");
802       printf("*******************************\n");          
803       if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
804          Error("runProcess","Cannot Build the PAR Archive! - Abort!");
805          return -1;
806       }
807    }
808
809         // check for SETUP.C and execute
810         if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
811             printf("*******************************\n");
812             printf("*** Setup PAR archive       ***\n");
813             printf("*******************************\n");
814             gROOT->Macro("PROOF-INF/SETUP.C");
815         }       
816         if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
817    return 0;
818 }
819
820 //______________________________________________________________________________
821 AliAnalysisGrid* CreateAlienHandler(const char *plugin_mode)
822 {
823 // Check if user has a valid token, otherwise make one. This has limitations.
824 // One can always follow the standard procedure of calling alien-token-init then
825 //   source /tmp/gclient_env_$UID in the current shell.
826    if (!AliAnalysisGrid::CreateToken()) return NULL;
827    AliAnalysisAlien *plugin = new AliAnalysisAlien();
828 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
829    plugin->SetRunMode(plugin_mode);
830    plugin->SetNtestFiles(1);
831    plugin->SetPreferedSE("ALICE::Legnaro::SE");
832 // Set versions of used packages
833    plugin->SetAPIVersion("V2.4");
834    plugin->SetROOTVersion(root_version);
835    plugin->SetAliROOTVersion(aliroot_version);
836 // Declare input data to be processed.
837 // Method 1: Create automatically XML collections using alien 'find' command.
838 // Define production directory LFN
839    plugin->SetGridDataDir(alien_datadir);
840 // Set data search pattern
841    if (iAODanalysis) plugin->SetDataPattern("*AliAOD.root");
842    else              plugin->SetDataPattern("*ESD.tag.root");
843 // ...then add run numbers to be considered
844    plugin->SetRunRange(run_range[0], run_range[1]);
845 //   for (Int_t i=0; i<10; i++) {
846 //      if (run_numbers[i]==0) break;
847 //      plugin->AddRunNumber(run_numbers[i]);
848 //   }   
849 // Method 2: Declare existing data files (raw collections, xml collections, root file)
850 // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
851 // XML collections added via this method can be combined with the first method if
852 // the content is compatible (using or not tags)
853 //   plugin->AddDataFile("tag.xml");
854 //   plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
855 // Define alien work directory where all files will be copied. Relative to alien $HOME.
856    if (iAODanalysis) plugin->SetGridWorkingDir("analysisAOD");
857    else              plugin->SetGridWorkingDir("analysisESD");
858 // Declare alien output directory. Relative to working directory.
859    if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
860    plugin->SetGridOutputDir(alien_outdir);
861
862    TString ana_sources = "";
863    TString ana_add = "";
864    if (usePAR && anaPars.Length()) {
865       printf("%s\n", anaPars.Data());
866       TObjArray *arr;
867       TObjString *objstr;
868       arr = anaPars.Tokenize(" ");
869       TIter next(arr);
870       while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
871       delete arr;
872    } 
873    
874 // Declare the analysis source files names separated by blancs. To be compiled runtime
875 // using ACLiC on the worker nodes.
876    ana_sources = ana_sources.Strip();
877 // Declare all libraries (other than the default ones for the framework. These will be
878 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
879    anaLibs     = anaLibs.Strip();   
880    if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
881    if (anaLibs.Length())     plugin->SetAdditionalLibs(anaLibs);
882      
883 // Declare the output file names separated by blancs.
884 // (can be like: file.root or file.root@ALICE::Niham::File)
885    plugin->SetDefaultOutputs();
886    plugin->SetMergeExcludes(mergeExclude);
887    plugin->SetMaxMergeFiles(maxMergeFiles);
888    plugin->SetNrunsPerMaster(nRunsPerMaster);
889 // Optionally define the files to be archived.
890 //   plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:*.root@ALICE::NIHAM::File");
891    plugin->SetOutputArchive("log_archive.zip:stdout,stderr");
892 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
893    plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
894 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
895    plugin->SetSplitMaxInputFileNumber(nFilesPerJob);
896 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
897 //   plugin->SetMaxInitFailed(5);
898 // Optionally resubmit threshold.
899 //   plugin->SetMasterResubmitThreshold(90);
900 // Optionally set time to live (default 30000 sec)
901    plugin->SetTTL(30000);
902 // Optionally set input format (default xml-single)
903    plugin->SetInputFormat("xml-single");
904 // Optionally modify the name of the generated JDL (default analysis.jdl)
905    plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
906 // Optionally modify the executable name (default analysis.sh)
907    plugin->SetExecutable(Form("%s.sh", train_name.Data()));
908 // Optionally modify job price (default 1)
909    plugin->SetPrice(1);      
910 // Optionally modify split mode (default 'se')    
911    plugin->SetSplitMode("se");
912    return plugin;
913 }
914
915 //______________________________________________________________________________
916 void WriteConfig()
917 {
918 // Write train configuration in a file. The file name has the format:
919 // train_[trainName]_ddMonthyyyy_time.C
920    gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
921    ifstream fdate("date.tmp");
922    if (!fdate.is_open()) {
923       ::Error("AnalysisTrainNew.C::Export","Could not generate file name");
924       return;
925    }
926    if (useDATE) {
927       const char date[64];
928       fdate.getline(date,64);
929       fdate.close();
930       gSystem->Exec("rm date.tmp");
931       train_name = Form("train_%s_%s", train_name.Data(), date);
932    } else {
933       train_name = Form("train_%s", train_name.Data());
934    }   
935    TString cdir = gSystem->WorkingDirectory();
936    gSystem->MakeDirectory(train_name);
937    gSystem->ChangeDirectory(train_name);
938    ofstream out;
939    out.open("ConfigTrain.C", ios::out); 
940    if (out.bad()) {
941       ::Error("AnalysisTrainNew.C::Export", "Cannot open ConfigTrain.C for writing");
942       return;
943    }
944    out << "{" << endl;
945    out << "   train_name      = " << "\"" << train_name.Data() << "\";" << endl;
946    out << "   proof_cluster   = " << "\"" << proof_cluster.Data() << "\";" << endl;
947    out << "   useAFPAR        = " << useAFPAR << ";" << endl;
948    if (useAFPAR) 
949       out << "   AFversion       = " << AFversion.Data() << ";" << endl;
950    out << "   proof_dataset   = " << "\"" << proof_dataset.Data() << "\";" << endl;
951    out << "   usePLUGIN       = " << usePLUGIN << ";" << endl;
952    out << "   usePAR          = " << usePAR << ";" << endl;
953    out << "   useCPAR         = " << useCPAR << ";" << endl;
954    out << "   root_version    = " << "\"" << root_version.Data() << "\";" << endl;
955    out << "   aliroot_version = " << "\"" << aliroot_version.Data() << "\";" << endl;
956    out << "   alien_datadir   = " << "\"" << alien_datadir.Data() << "\";" << endl;
957    if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
958    out << "   alien_outdir    = " << "\"" << alien_outdir.Data() << "\";" << endl;
959    out << "   maxMergeFiles   = " << maxMergeFiles << ";" << endl;
960    out << "   mergeExclude    = " << "\"" << mergeExclude.Data() << "\";" << endl;
961    out << "   nRunsPerMaster  = " << nRunsPerMaster << ";" << endl;
962    out << "   nFilesPerJob    = " << nFilesPerJob << ";" << endl;
963 //   for (Int_t i=0; i<10; i++) {
964 //      if (run_numbers[i]) 
965 //         out << "   run_numbers[" << i << "]  = " << run_numbers[i] << ";" << endl;
966 //   }
967    out << "   run_range[0]    = " << run_range[0] << ";" << endl;
968    out << "   run_range[1]    = " << run_range[1] << ";" << endl;
969    out << "   useDBG          = " << useDBG << ";" << endl;
970    out << "   useMC           = " << useMC << ";" << endl;
971    out << "   useTAGS         = " << useTAGS << ";" << endl;
972    out << "   useKFILTER      = " << useKFILTER << ";" << endl;
973    out << "   useTR           = " << useTR << ";" << endl;
974    out << "   useCORRFW       = " << useCORRFW << ";" << endl;
975    out << "   useAODTAGS      = " << useAODTAGS << ";" << endl;
976    out << "   saveTrain       = " << "kFALSE;" << endl << endl;
977    out << "   // Analysis modules" << endl;
978    out << "   iAODanalysis    = " << iAODanalysis << ";" << endl;
979    out << "   iAODhandler     = " << iAODhandler << ";" << endl;
980    out << "   iESDfilter      = " << iESDfilter << ";" << endl;
981    out << "   iMUONcopyAOD    = " << iMUONcopyAOD << ";" << endl;
982    out << "   iJETAN          = " << iJETAN << ";" << endl;
983    out << "   iPWG4partcorr   = " << iPWG4partcorr << ";" << endl;
984    out << "   iPWG4gammaconv  = " << iPWG4gammaconv << ";" << endl;
985    out << "   iPWG2femto      = " << iPWG2femto << ";" << endl;
986    out << "   iPWG2spectra    = " << iPWG2spectra << ";" << endl;
987    out << "   iPWG2flow       = " << iPWG2flow << ";" << endl;
988    out << "   iPWG2res        = " << iPWG2res << ";" << endl;
989    out << "   iPWG2kink       = " << iPWG2kink << ";" << endl;
990    out << "}" << endl;
991    ::Info("AnalysisTrainNew.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", train_name.Data()));
992    gSystem->ChangeDirectory(cdir);
993 }   
994
995 //______________________________________________________________________________
996 Bool_t LoadConfig(const char *filename)
997 {
998 // Read train configuration from file
999    if (gSystem->AccessPathName(filename)) {
1000       ::Error("AnalysisTrainNew.C::LoadConfig", "Config file name not found");
1001       return kFALSE;
1002    }   
1003    gROOT->ProcessLine(Form(".x %s", filename));
1004    ::Info("AnalysisTrainNew.C::LoadConfig", "Train configuration loaded from file %s", filename);
1005    return kTRUE;
1006 }