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