]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AnalysisTrainHMPID.C
Tracking procedure updated, it is based now on AliTrackerBase method. The parameters...
[u/mrichter/AliRoot.git] / HMPID / AnalysisTrainHMPID.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 AnalysisTrainHMPID.C
5 // Grid full mode as below (other modes: test, offline, submit, terminate)
6 //    root[1] AnalysisTrainHMPID("grid", "full")
7 // CAF mode (requires root v5-23-02 + aliroot v4-16-Rev08)
8 //    root[2] AnalysisTrainHMPID("proof")
9 // Local mode requires AliESds.root or AliAOD.root in ./data directory
10 //    root[3] AnalysisTrainHMPID("local")
11 // In proof and grid modes, a token is needed and sourcing the produced environment file.
12 //
13
14 // =============================================================================
15 // ### General Steering variables
16 // =============================================================================
17 //== general setup variables
18 TString     kTrainName         = "hmpidAnalysis"; // (no blancs or special characters)
19 TString     kJobTag            = "HMPID Tasks analysis train configured"; //
20 Bool_t      kUsePAR            = kFALSE;  // use par files for extra libs
21 Bool_t      kUseCPAR           = kFALSE;  // use par files for common libs
22 Bool_t      kFillAOD           = kFALSE;  // switch of AOD filling for on the fly analysis
23
24 Int_t       iAODhandler        = 1;      // Analysis produces an AOD or dAOD's
25 Int_t       iESDfilter         = 0;      // ESD to AOD filter (barrel + muon tracks)
26 Int_t       iPhysicsSelection  = 1;      // Physics selection task
27 Bool_t      kUseKinefilter     = kFALSE; // use Kinematics filter
28 Bool_t      kUseMuonfilter     = kFALSE; // use muon filter
29 TString     kCommonOutputFileName = "HmpidOutput.root";
30
31
32 //== general process variables
33
34 // ### Other flags to steer the analysis
35 //==============================================================================
36 Bool_t      kSkipTerminate      = kFALSE; // Do not call Teminate
37 Bool_t      kDebugLevel         = kTRUE; // activate debugging
38 Int_t       kUseSysInfo         = 0; // activate debugging
39 Bool_t      kUseMC              = kTRUE;  // use MC info
40 Bool_t      kIsMC               = kTRUE;  // is MC info, if false it overwrites Use(AOD)MC
41 Bool_t      kUseESDTags         = kTRUE; // use ESD tags for selection
42 Bool_t      kUseTR              = kFALSE;  // use track references
43
44 // ### Analysis modules to be included. Some may not be yet fully implemented.
45 //==============================================================================
46 Int_t       iHMPID             = 1;      // Basic HMPID analysis task
47 Int_t       iJETAN             = 0;      // Jet analysis (PWG4) // 1 write standard 2 write non-standard jets
48 Int_t       iJETANLib          = 0;
49 Int_t       kHighPtFilterMask  = 16;     // change depending on the used AOD Filter
50
51
52 //==============================================================================
53 // ### PROOF Steering varibales
54 //==============================================================================
55 //== proof setup variables
56 TString     kProofCluster      = "alice-caf.cern.ch";
57 Bool_t      kProofUseAFPAR     = kTRUE;  // use AF special par file
58 TString     kProofAFversion    = "VO_ALICE@AliRoot::v4-20-08-AN";
59 //== proof input and output variables
60 TString     kProofDataSet      = "/alice/sim/LHC10d2_117220";
61 //== proof process variables
62 Bool_t      kProofClearPackages = kFALSE;
63 Int_t       kProofEvents = 10000;
64 Int_t       kProofOffset = 0;
65
66 //==============================================================================
67 // ### Grid plugin Steering varibiables
68 //==============================================================================
69 //== grid plugin setup variables
70 Bool_t      kPluginUse         = kTRUE;   // do not change
71 Bool_t      kPluginUseProductionMode  = kFALSE;   // use the plugin in production mode
72 TString     kPluginRootVersion       = "v5-27-06b";  // *CHANGE ME IF MORE RECENT IN GRID*
73 TString     kPluginAliRootVersion    = "v4-21-05-AN";  // *CHANGE ME IF MORE RECENT IN GRID*                                          
74 Bool_t      kPluginMergeViaJDL       = kTRUE;  // merge via JDL
75 Bool_t      kPluginFastReadOption    = kFALSE;  // use xrootd flags to reduce timeouts
76 Bool_t      kPluginOverwriteMode     = kTRUE;  // overwrite existing collections
77 Int_t       kPluginOutputToRunNumber = 1;     // write the output to subdirs named after run number
78 TString kPluginExecutableCommand = "root -b -q";
79
80 // == grid plugin input and output variables
81 TString     kGridDatadir      = "/alice/sim/LHC10d4a";
82 TString     kGridLocalRunList = "";
83 TString     kGridWorkDir      = "HmpidAnalysis/LHC10d4a";   // Alien working directory
84 TString     kGridOutdir       = ""; // AliEn output directory. If blank will become output_<kTrainName>
85 TString     kGridDataSet      = ""; // sub working directory not to confuse different run xmls 
86 Int_t       kGridRunRange[2]       = {120820, 120820}; // Set the run range
87 TString     kGridRunPattern        = "%03d"; // important for leading zeroes!!
88 TString     kGridPassPattern       = "";
89 TString     kGridExtraFiles        = ""; // files that will be added to the input list in the JDL...
90 Int_t       kGridMaxMergeFiles      = 12; // Number of files merged in a chunk grid run range
91 TString     kGridMergeExclude       = "AliAOD.root"; // Files that should not be merged
92 TString     kGridOutputStorages      = "disk=2"; // Make replicas on the storages
93 // == grid process variables
94 Int_t       kGridRunsPerMaster     = 1; // Number of runs per master job
95 Int_t       kGridFilesPerJob       = 100; // Maximum number of files per job (gives size of AOD)
96
97 //==============================================================================
98 // ### Local Steering variables
99 //==============================================================================
100 //== local setup variables
101 //== local input and output variables
102 TString     kLocalXMLDataset   = ""; // Change local xml dataset for local interactive analysis
103 TString     kLocalDataList   = "local_deltaaod.txt"; // Change local xml dataset for local interactive analysis
104 // == local process variables
105
106
107
108 // Temporaries.
109 TString anaPars = "";
110 TString anaLibs = "";
111 TString anaLibsExtra = "";
112 TString anaSources = "";
113 // Function signatures
114 class AliAnalysisAlien;
115
116 //______________________________________________________________________________
117 void AnalysisTrainHMPID(const char *analysis_mode="local", const char *plugin_mode="",
118                         const char *config_file="",Int_t iOffset = 0)
119 {
120 // Main analysis train macro. If a configuration file is provided, all parameters
121 // are taken from there but may be altered by CheckModuleFlags.
122
123    if (strlen(config_file) && !LoadConfig(config_file)) return;
124
125    if(iOffset)kProofOffset = iOffset;
126    TString smode(analysis_mode);
127    smode.ToUpper();
128    // Check compatibility of selected modules
129    CheckModuleFlags(smode);
130
131    printf("==================================================================\n");
132    printf("===========    RUNNING ANALYSIS TRAIN %s IN %s MODE   ==========\n", kTrainName.Data(),smode.Data());
133    printf("==================================================================\n");
134    printf("=  Configuring analysis train for:                               =\n");
135    printf("=  ESD analysis                                                  =\n");
136    if (iPhysicsSelection)   printf("=  Physics selection                                                    =\n");
137    if (iESDfilter)   printf("=  ESD filter                                                    =\n");
138    if (iJETAN)       printf("=  Jet analysis                                                  =\n");
139    printf("==================================================================\n");
140    printf(":: use MC truth      %d\n", (UInt_t)kUseMC);
141    printf(":: use KINE filter   %d\n", (UInt_t)kUseKinefilter);
142    printf(":: use track refs    %d\n", (UInt_t)kUseTR);
143    printf(":: use tags          %d\n", (UInt_t)kUseESDTags);
144    printf(":: use debugging     %d\n", (UInt_t)kDebugLevel);
145    printf(":: use PAR files     %d\n", (UInt_t)kUsePAR);
146    printf(":: use AliEn plugin  %d\n", (UInt_t)kPluginUse);
147    
148    //==========================================================================
149    // Connect to back-end system
150    if (!Connect(smode)) {
151       ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode);
152       return;
153    }   
154
155    // Load common libraries and set include path
156    if (!LoadCommonLibraries(smode)) {
157       ::Error("AnalysisTrain", "Could not load common libraries");
158       return;
159    }
160
161
162     
163    // Make the analysis manager and connect event handlers
164    AliAnalysisManager *mgr  = new AliAnalysisManager("HMPIDTrain", "HMPID train");
165    if (kCommonOutputFileName.Length()>0)mgr->SetCommonFileName(kCommonOutputFileName.Data());
166    mgr->SetNSysInfo(0);
167    if (!strcmp(plugin_mode, "test")) mgr->SetNSysInfo(1);
168    if (kUseSysInfo)mgr->SetNSysInfo(kUseSysInfo);
169    mgr->SetSkipTerminate(kSkipTerminate);
170
171    // Load analysis specific libraries
172    if (!LoadAnalysisLibraries(smode)) {
173       ::Error("AnalysisTrain", "Could not load analysis libraries");
174      return;
175    }   
176
177    // Create input handler (input container created automatically)
178    // ESD input handler
179    AliESDInputHandler *esdHandler = new AliESDInputHandler();
180    if (kUseESDTags) esdHandler->SetReadTags();
181    esdHandler->SetReadFriends(kFALSE);
182    mgr->SetInputEventHandler(esdHandler);       
183
184    // Monte Carlo handler
185    if (kUseMC) {
186       AliMCEventHandler* mcHandler = new AliMCEventHandler();
187       mgr->SetMCtruthEventHandler(mcHandler);
188       mcHandler->SetReadTR(kUseTR); 
189    }   
190
191    // AOD output container, created automatically when setting an AOD handler
192    if (iAODhandler) {
193       // AOD output handler
194       AliAODHandler* aodHandler   = new AliAODHandler();
195       aodHandler->SetOutputFileName("AliAOD.root");
196       aodHandler->SetFillAODforRun(kFillAOD);
197       
198       mgr->SetOutputEventHandler(aodHandler);
199       AliAnalysisDataContainer *cout_aod = mgr->GetCommonOutputContainer();
200       cout_aod->SetSpecialOutput();
201    }
202
203    // Debugging if needed
204    if (kDebugLevel){
205       mgr->SetDebugLevel(3);
206    }
207    if(kUseSysInfo>0){
208       mgr->RegisterExtraFile("syswatch.root");
209       if(kGridMergeExclude.Length())kGridMergeExclude += " ";
210       kGridMergeExclude += "syswatch.root";
211    } else {
212       AliLog::SetGlobalLogLevel(AliLog::kError);
213    }
214
215    //==========================================================================
216    // Create the chain. In this example it is created only from ALIEN files but
217    // can be done to work in batch or grid mode as well.
218    TChain *chain = CreateChain(smode, plugin_mode);
219         
220    //==========================================================================
221    // Load the tasks configuration macros for all wagons. These files are supposed now to be
222    // in the current workdir, but in AliEn they will be in the file catalog, 
223    // mapped from AliRoot and pecified in the jdl input list.
224    if(iPhysicsSelection){
225      gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
226      AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kIsMC,kTRUE,kTRUE); // last flag also adds information on  
227    }
228
229    if (iESDfilter) {
230       //  ESD filter task configuration.
231       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
232       AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kUseKinefilter,kUseMuonfilter);
233       if(kIsMC){
234          mgr->RegisterExtraFile("pyxsec_hists.root");
235          if(kGridMergeExclude.Length())kGridMergeExclude += " ";
236          kGridMergeExclude += "pyxsec_hists.root";
237       }
238    }   
239
240     // Jet analysis
241    if (iJETAN) {
242       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
243       AliAnalysisTaskJets *taskjets = 0;
244       if (iJETAN&1) taskjets = AddTaskJets(kHighPtFilterMask); 
245       if (!taskjets) ::Warning("AnalysisTrainHMPID", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
246    }
247
248    if(iHMPID){
249      gROOT->LoadMacro("$ALICE_ROOT/HMPID/AddTaskHMPID.C");
250      AliHMPIDAnalysisTask *taskHmpid = AddTaskHMPID(kUseMC);
251      if (!taskHmpid) ::Warning("AnalysisTrainHMPID", "AliAnalysisTaskHMPID cannot run for this train conditions - EXCLUDED");
252    }
253
254    if (kPluginUse) {
255       AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
256       AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
257    }
258
259    if (mgr->InitAnalysis()) {
260      mgr->PrintStatus();
261      if (!strcmp(plugin_mode,"submit") && smode=="GRID"){
262        TString alien_workdir = gGrid->GetHomeDirectory();
263        alien_workdir += kGridWorkDir.Data();
264        if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
265        AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
266        printf("=== AnalysisTrainHMPID:: Registering jdl in the work directory alien://%s/%s, should be done by the manager! ===\n",
267               alien_workdir.Data(),gridhandler->GetGridOutputDir());
268
269        TString dest;
270        dest = Form("%s/%s/%s.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
271        if(AliAnalysisAlien::FileExists(dest.Data())){
272      //  Printf("%s exist on grid removing...",dest.Data());
273      //  gGrid->Rm(dest.Data());
274        }
275        TFile::Cp(Form("file:%s.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
276
277
278        TString dest;
279        dest = Form("%s/%s/%s_merge.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
280        if(AliAnalysisAlien::FileExists(dest.Data())){
281          //      Printf("%s exist on grid removing...",dest.Data());
282          //      gGrid->Rm(dest.Data());
283        }
284        TFile::Cp(Form("file:%s_merge.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
285      }
286
287      AliLog::SetGlobalLogLevel(AliLog::kError);
288      if((kUseSysInfo>0 && smode=="LOCAL") || !strcmp(plugin_mode, "test")){
289        TFile *fM = TFile::Open("manager_local.root","RECREATE");
290        mgr->Write();
291        fM->Close();
292      }
293
294      StartAnalysis(smode, chain);
295        
296      if((kUseSysInfo>0 && smode=="LOCAL") || !strcmp(plugin_mode, "test")){
297        for(int i = 0;i < mgr->GetTopTasks()->GetEntries();i++){
298          mgr->ProfileTask(i);
299        }
300      }
301      if (!strcmp(plugin_mode, "offline") && smode=="GRID"){
302        // Offline mode path files
303        //       PatchJDL();
304        PatchAnalysisMacro();
305      }
306    }
307 }
308
309
310 //______________________________________________________________________________
311 void StartAnalysis(const char *mode, TChain *chain) {
312
313    Int_t imode = -1;
314    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
315    if (!strcmp(mode, "LOCAL")) imode = 0;
316    if (!strcmp(mode, "PROOF")) imode = 1;
317    if (!strcmp(mode, "GRID"))  imode = 2;
318    switch (imode) {
319       case 0:
320          if (!chain) {
321             ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Cannot create the chain");
322             return;
323          }
324          mgr->StartAnalysis(mode, chain,kNumberOfEvents);
325          return;
326       case 1:
327          if (!kProofDataSet.Length()) {
328             ::Error("AnalysisTrainHMPID.C::StartAnalysis", "kProofDataSet is empty");
329             return;
330          }
331          mgr->StartAnalysis(mode, kProofDataSet, kProofEvents,kProofOffset);
332          return;
333       case 2:
334          if (kPluginUse) {
335             if (!mgr->GetGridHandler()) {
336                ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Grid plugin not initialized");
337                return;
338             }
339             mgr->StartAnalysis("grid");
340          } else {
341             if (!chain) {
342                ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Cannot create the chain");
343                return;
344             }
345             mgr->StartAnalysis(mode, chain);
346          }
347       return;
348    }
349 }
350
351 //______________________________________________________________________________
352 void CheckModuleFlags(const char *mode) {
353 // Checks selected modules and insure compatibility
354    Int_t imode = -1;
355    if (!strcmp(mode, "LOCAL")) imode = 0;
356    if (!strcmp(mode, "PROOF")) imode = 1;
357    if (!strcmp(mode, "GRID"))  imode = 2;
358
359
360    if (kUseCPAR) {
361      kPluginAliRootVersion    = ""; // NO aliroot if we use CPAR
362    }
363
364    if (imode==1) {
365       if (!kUsePAR) {
366          ::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
367          kUsePAR = kTRUE;
368       }   
369    }  
370    if (imode != 2) {
371       ::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
372       kPluginUse = kFALSE; 
373    }
374
375    if(!kIsMC){
376      // switch off anthin related to MC
377      kUseMC = 0;
378      kUseTR = kFALSE;
379    }
380
381  // ESD analysis
382    if (!kUseMC){
383      kUseTR = kFALSE;
384      if(kUseKinefilter)::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "Kine Filter disabled in analysis without MC");
385      kUseKinefilter = kFALSE;
386    }
387    if (iJETAN){
388      iESDfilter=1;
389    }
390    if (!iESDfilter){
391      kUseKinefilter = kFALSE;
392      kUseMuonfilter = kFALSE;
393    }
394
395    iJETANLib = iJETAN && 1;
396    if (iESDfilter) {iAODhandler=1;}
397    if (kUseKinefilter && !kUseMC) kUseKinefilter = kFALSE;
398    
399 }
400
401
402 //______________________________________________________________________________
403 Bool_t Connect(const char *mode) {
404 // Connect <username> to the back-end system.
405    Int_t imode = -1;
406    if (!strcmp(mode, "LOCAL")) imode = 0;
407    if (!strcmp(mode, "PROOF")) imode = 1;
408    if (!strcmp(mode, "GRID"))  imode = 2;
409    TString username = gSystem->Getenv("alien_API_USER");
410    switch (imode) {
411      case 0:
412        break;
413      case 1:
414        if  (!username.Length()) {
415          ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode), "Make sure you:\n \
416                         1. Have called: alien-token-init <username>\n \
417                         2. Have called: >source /tmp/gclient_env_$UID");
418          return kFALSE;
419        }
420        ::Info("AnalysisTrainHMPID.C::Connect", "Connecting user <%s> to PROOF cluster <%s>", 
421                 username.Data(), kProofCluster.Data());
422        gEnv->SetValue("XSec.GSI.DelegProxy", "2");
423        TProof::Open(Form("%s@%s", username.Data(), kProofCluster.Data()));       
424        if (!gProof) {
425          if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
426            ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
427            return kFALSE;
428          }
429        if(kProofClearPackages)gProof->ClearPackages();
430        break;
431      case 2:      
432        if  (!username.Length()) {
433          ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode), "Make sure you:\n \
434                         1. Have called: alien-token-init <username>\n \
435                         2. Have called: >source /tmp/gclient_env_$UID");
436          return kFALSE;
437        }
438        if (kPluginUse && !gSystem->Getenv("alien_CLOSE_SE")) {
439          ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode), 
440                         "When using the AliEn plugin it is preferable to define the \
441                         variable alien_CLOSE_SE in your environment.");
442          return kFALSE;
443        }
444        ::Info("AnalysisTrainHMPID.C::Connect", "Connecting user <%s> to AliEn ...", 
445                 username.Data());
446        TGrid::Connect("alien://");
447        if (!gGrid || !gGrid->IsConnected()) return kFALSE;
448        break;
449      default:
450        ::Error("AnalysisTrainHMPID.C::Connect", "Unknown run mode: %s", mode);
451        return kFALSE;
452    }
453    ::Info("AnalysisTrainHMPID.C::Connect","Connected in %s mode", mode);
454    return kTRUE;
455 }
456
457
458 //______________________________________________________________________________
459 Bool_t LoadCommonLibraries(const char *mode)
460 {
461 // Load common analysis libraries.
462    Int_t imode = -1;
463    if (!strcmp(mode, "LOCAL")) imode = 0;
464    if (!strcmp(mode, "PROOF")) imode = 1;
465    if (!strcmp(mode, "GRID"))  imode = 2;
466    if (!gSystem->Getenv("ALICE_ROOT")) {
467       ::Error("AnalysisTrainHMPID.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot"); 
468       return kFALSE;
469    }   
470    Bool_t success = kTRUE;
471    // ROOT libraries
472    gSystem->Load("libTree.so");
473    gSystem->Load("libGeom.so");
474    gSystem->Load("libVMC.so");
475    gSystem->Load("libPhysics.so");
476    
477    // Load framework classes. Par option ignored here.
478    switch (imode) {
479       case 0:
480       case 2:
481          if (kUseCPAR) {
482             success &= LoadLibrary("STEERBase", mode, kTRUE);
483             success &= LoadLibrary("ESD", mode, kTRUE);
484             success &= LoadLibrary("AOD", mode, kTRUE);
485             success &= LoadLibrary("ANALYSIS", mode, kTRUE);
486             success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
487             success &= LoadLibrary("CORRFW", mode, kTRUE);
488          } else {   
489             success &= LoadLibrary("libSTEERBase.so", mode);
490             success &= LoadLibrary("libESD.so", mode);
491             success &= LoadLibrary("libAOD.so", mode);
492             success &= LoadLibrary("libANALYSIS.so", mode);
493             success &= LoadLibrary("libANALYSISalice.so", mode);
494             success &= LoadLibrary("libCORRFW.so", mode);
495             gROOT->ProcessLine(".include $ALICE_ROOT/include");
496          }   
497          break;
498       case 1:
499          if (!kProofUseAFPAR) {
500             success &= LoadLibrary("STEERBase", mode);
501             success &= LoadLibrary("ESD", mode);
502             success &= LoadLibrary("AOD", mode);
503             success &= LoadLibrary("ANALYSIS", mode);
504             success &= LoadLibrary("ANALYSISalice", mode);
505             success &= LoadLibrary("CORRFW", mode);
506          } else { 
507             success &= !gProof->EnablePackage(kProofAFversion);
508             success &= LoadLibrary("CORRFW", mode);
509          }
510          break;         
511       default:
512          ::Error("AnalysisTrainHMPID.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
513          return kFALSE;
514    }
515    if (success) {
516       ::Info("AnalysisTrainHMPID.C::LoadCommodLibraries", "Load common libraries:    SUCCESS");
517       ::Info("AnalysisTrainHMPID.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
518               gSystem->GetIncludePath());
519    } else {           
520       ::Info("AnalysisTrainHMPID.C::LoadCommodLibraries", "Load common libraries:    FAILED");
521    }   
522       
523    return success;
524 }
525
526
527 //______________________________________________________________________________
528 Bool_t LoadAnalysisLibraries(const char *mode)
529 {
530 // Load common analysis libraries.
531    Bool_t success = kTRUE;
532    if (iESDfilter) {
533       if (!LoadLibrary("PWG3base", mode, kTRUE) ||
534           !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
535    }   
536
537    if(iHMPID){
538      if (!LoadSource(Form("%s/HMPID/AliHMPIDAnalysisTask.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
539    }
540
541    if (iJETANLib) {
542      if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
543    }
544
545    ::Info("AnalysisTrainHMPID.C::LoadAnalysisLibraries", "Load other libraries:   SUCCESS");
546    return kTRUE;
547 }
548
549
550 //______________________________________________________________________________
551 Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
552 {
553 // Load a module library in a given mode. Reports success.
554    Int_t imode = -1;
555    Int_t result;
556    TString smodule(module);
557    if (!strcmp(mode, "LOCAL")) imode = 0;
558    if (!strcmp(mode, "PROOF")) imode = 1;
559    if (!strcmp(mode, "GRID"))  imode = 2;
560    TString mod(module);
561    if (!mod.Length()) {
562       ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Empty module name");
563       return kFALSE;
564    }   
565    // If a library is specified, just load it
566    if (smodule.EndsWith(".so")) {
567       mod.Remove(mod.Index(".so"));
568       result = gSystem->Load(mod);
569       if (result < 0) {
570          ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not load library %s", module);
571          return kFALSE;
572       }
573       if (rec) anaLibs += Form("%s.so ",mod.Data()); 
574       if (rec) anaLibsExtra += Form("%s.so ",mod.Data()); 
575       return kTRUE;
576    } 
577    // Check if the library is already loaded
578    if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
579       return kTRUE;    
580    switch (imode) {
581       case 0:
582       case 2:
583          if (kUsePAR) {
584             result = SetupPar(module);
585             if (rec) anaPars += Form("%s.par ", module);
586          } else {
587             result = gSystem->Load(Form("lib%s.so", module));
588             if (rec) anaLibs += Form("lib%s.so ", module);
589          }   
590          break;
591       case 1:
592              if(!gSystem->AccessPathName(module)){
593                ::Info("AnalysisTrainHMPID.C::LoadLibrary", "Removing directory %s",module);
594                gSystem->Exec(Form("rm -rf %s",module));
595          }
596          result = gProof->UploadPackage(module);
597          if (result<0) {
598             result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
599             if (result<0) {
600                ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
601                return kFALSE;
602             }
603          }   
604          result = gProof->EnablePackage(module);
605          break;
606       default:
607          return kFALSE;
608    }         
609    if (result < 0) {
610       ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not load module %s", module);
611       return kFALSE;
612    }
613    return kTRUE;
614 }           
615
616 //______________________________________________________________________________
617 Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
618 {
619 // Load a module library in a given mode. Reports success.
620    Int_t imode = -1;
621    Int_t result = -1;
622    if (!strcmp(mode, "LOCAL")) imode = 0;
623    if (!strcmp(mode, "PROOF")) imode = 1;
624    if (!strcmp(mode, "GRID"))  imode = 2;
625    TString ssource(source);
626    TString basename = gSystem->BaseName(ssource.Data());
627    if (!ssource.Length()) {
628       ::Error("AnalysisTrainHMPID.C::LoadSource", "Empty task name");
629       return kFALSE;
630    }
631    // we have a source code so compile it
632    if (ssource.EndsWith(".cxx")) {
633      // need to copy it here other wise the path is also used on grid...
634      ssource.Remove(ssource.Index(".cxx"));
635      basename.Remove(basename.Index(".cxx"));
636      Printf("LoadSources:: Copying...  path %s{cxx,h}",ssource.Data());
637      gSystem->Exec(Form("cp %s.cxx . ",ssource.Data()));
638      gSystem->Exec(Form("cp %s.h . ",ssource.Data()));
639      // Path to code
640      // only needed for local compilation, in grid and proof mode 
641      // the task headers are uploaded 
642      //     path.Remove(path.Index(gSystem->BaseName(path.Data())));
643      // Printf("LoadSources:: Including path %s",path.Data());
644      //  if(path.Length()>0)gROOT->ProcessLine(Form(".include %s",path.Data()));
645      Printf("LoadSources:: Loading...  path %s",basename.Data());
646      switch (imode) {
647      case 0:
648        result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
649        break;
650      case 1:
651        result = gProof->Load(Form("%s.cxx++g",basename.Data()));
652        break;
653      case 2:
654        result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
655        if (rec){
656        // what we want to compile
657          anaSources += Form("%s.cxx ",basename.Data());
658        // what we need as input...
659          anaLibs += Form("%s.cxx %s.h ",basename.Data(),basename.Data());
660        }
661        break;
662      default:
663        return kFALSE;
664      }
665    }
666    if (result < 0) {
667       ::Error("AnalysisTrainHMPID.C::LoadSources", "Could not load source %s", source);
668       return kFALSE;
669    }
670    return kTRUE;
671 }
672
673 //______________________________________________________________________________
674 TChain *CreateChain(const char *mode, const char *plugin_mode)
675 {
676 // Create the input chain
677    Int_t imode = -1;
678    if (!strcmp(mode, "LOCAL")) imode = 0;
679    if (!strcmp(mode, "PROOF")) imode = 1;
680    if (!strcmp(mode, "GRID"))  imode = 2;
681    TChain *chain = NULL;
682    // Local chain
683    switch (imode) {
684       case 0:
685              if (!kLocalXMLDataset.Length()) {
686                // Local ESD
687                chain = new TChain("esdTree");
688                TString line;
689                ifstream in;
690                in.open(kLocalDataList.Data());
691                while (in.good()) {
692                  in >> line;
693                  if (line.Length() == 0) continue;
694                  cout << " line = " << line << endl;
695                  chain->Add(line.Data());
696                }       
697              } else {
698                // Interactive ESD
699            chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
700              }   
701          break;
702       case 1:
703          break;
704       case 2:
705          if (kPluginUse) {
706             AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
707             AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
708          } else {
709             TString treeName = "esdTree";
710             chain = CreateChainSingle("wn.xml", treeName);
711          }
712          break;      
713       default:   
714    }
715    if (chain && chain->GetNtrees()) return chain;
716    return NULL;
717 }   
718
719 //______________________________________________________________________________
720 TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
721 {
722    printf("*******************************\n");
723    printf("*** Getting the ESD Chain   ***\n");
724    printf("*******************************\n");
725    TAlienCollection * myCollection  = TAlienCollection::Open(xmlfile);
726
727    if (!myCollection) {
728       ::Error("AnalysisTrainHMPID.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
729       return NULL ;
730    }
731
732    TChain* chain = new TChain(treeName);
733    myCollection->Reset() ;
734    while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
735    chain->ls();
736    return chain;
737 }
738
739 //______________________________________________________________________________
740 Int_t SetupPar(char* pararchivename)
741 {
742    if (!pararchivename || !strlen(pararchivename)) return -1;
743    char processline[1024];
744    if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
745       if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
746          ::Info("AnalysisTrainHMPID.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
747          TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)), 
748                    Form("%s.par",pararchivename));
749       } else {
750          ::Error("AnalysisTrainHMPID.C::SetupPar", "Cannot find %s.par", pararchivename);
751          return -1;
752       }   
753    }
754    gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
755
756    TString ocwd = gSystem->WorkingDirectory();
757    if (!gSystem->ChangeDirectory(pararchivename)) return -1;
758         
759    // check for BUILD.sh and execute
760    if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
761       printf("*******************************\n");
762       printf("*** Building PAR archive    ***\n");
763       printf("*******************************\n");          
764       if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
765          Error("runProcess","Cannot Build the PAR Archive! - Abort!");
766          return -1;
767       }
768    }
769
770         // check for SETUP.C and execute
771         if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
772             printf("*******************************\n");
773             printf("*** Setup PAR archive       ***\n");
774             printf("*******************************\n");
775             gROOT->Macro("PROOF-INF/SETUP.C");
776         }       
777         if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
778    return 0;
779 }
780
781 //______________________________________________________________________________
782 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
783 {
784 // Check if user has a valid token, otherwise make one. This has limitations.
785 // One can always follow the standard procedure of calling alien-token-init then
786 //   source /tmp/gclient_env_$UID in the current shell.
787    if (!AliAnalysisGrid::CreateToken()) return NULL;
788    AliAnalysisAlien *plugin = new AliAnalysisAlien();
789 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
790    plugin->SetRunMode(plugin_mode);
791    if (kPluginUseProductionMode) plugin->SetProductionMode();
792    plugin->SetJobTag(kJobTag);
793    plugin->SetNtestFiles(1);
794 //   plugin->SetPreferedSE("ALICE::NIHAM::File");
795 // Set versions of used packages
796    plugin->SetAPIVersion("V1.1x");
797    plugin->SetROOTVersion(kPluginRootVersion);
798    plugin->SetAliROOTVersion(kPluginAliRootVersion);
799
800 // Declare input data to be processed.
801 // Method 1: Create automatically XML collections using alien 'find' command.
802 // Define production directory LFN
803    plugin->SetGridDataDir(kGridDatadir.Data());
804 // Set data search pattern
805    plugin->SetDataPattern(Form(" %s/*/*ESDs.root",kGridPassPattern.Data()));
806 // ...then add run numbers to be considered
807    plugin->SetRunRange(kGridRunRange[0], kGridRunRange[1]);
808
809    if(kGridLocalRunList.Length()>0){
810      ifstream in1;
811      in1.open(kGridLocalRunList.Data());
812      int iRun;
813      // just use run numbers, negatives will be excluded
814      while(in1>>iRun){
815        if(iRun>0){
816        Printf("AnalysisTrainHMPID Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
817        plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
818        } else{
819          Printf("AnalysisTrainHMPID Skipping run number from File %d", iRun);
820        }
821      }
822    }
823
824 // Method 2: Declare existing data files (raw collections, xml collections, root file)
825 // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
826 // XML collections added via this method can be combined with the first method if
827 // the content is compatible (using or not tags)
828 //   plugin->AddDataFile("Hijing.xml");
829 //   plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
830 // Define alien work directory where all files will be copied. Relative to alien $HOME.
831    TString alien_workdir = "";
832
833    alien_workdir += kGridWorkDir.Data();
834    if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
835    plugin->SetGridWorkingDir(alien_workdir.Data());
836
837    // Declare alien output directory. Relative to working directory.
838    if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
839    plugin->SetGridOutputDir(kGridOutdir);
840
841    // set extra libs before par file compilation
842    anaLibs += kGridExtraFiles;
843    anaLibs  = anaLibs.Strip();   
844    Printf("anaLibs %s",anaLibs.Data());
845    Printf("anaLibsExtra %s",anaLibsExtra.Data());
846
847    if (anaLibs.Length())          plugin->SetAdditionalLibs(anaLibs.Data());
848    if (anaLibsExtra.Length())     plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
849
850    TString ana_sources = "";
851    TString ana_add = "";
852    if (kUsePAR && anaPars.Length()) {
853       printf("%s\n", anaPars.Data());
854       TObjArray *arr;
855       TObjString *objstr;
856       arr = anaPars.Tokenize(" ");
857       TIter next(arr);
858       while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
859       delete arr;
860    } 
861    
862 // Declare the analysis source files names separated by blancs. To be compiled runtime
863 // using ACLiC on the worker nodes.
864    ana_sources = anaSources.Strip();
865 // Declare all libraries (other than the default ones for the framework. These will be
866 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
867
868    if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
869    plugin->SetExecutableCommand(kPluginExecutableCommand.Data());
870    // Declare the output file names separated by blancs.
871    // (can be like: file.root or file.root@ALICE::Niham::File)
872    plugin->SetUseSubmitPolicy(kFALSE);
873    plugin->SetMergeExcludes(kGridMergeExclude);
874    plugin->SetMaxMergeFiles(kGridMaxMergeFiles);
875    plugin->SetNrunsPerMaster(kGridRunsPerMaster);
876    plugin->SetMergeViaJDL(kPluginMergeViaJDL);
877    // Use fastread option
878    plugin->SetFastReadOption(kPluginFastReadOption);
879    // UseOverwrite mode
880    plugin->SetOverwriteMode(kPluginOverwriteMode);
881    // Optionally define the files to be archived.
882    //   plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
883    plugin->SetOutputToRunNo(kPluginOutputToRunNumber);     // write the output to subdirs named after run number
884 //   plugin->SetDefaultOutputs(kFALSE);
885
886    // Put default output files to archive
887    TString listhists = "";
888    TString listaods  = "";
889    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
890    TIter next(mgr->GetOutputs());
891    AliAnalysisDataContainer *output;
892    while ((output=(AliAnalysisDataContainer*)next())) {
893       const char *filename = output->GetFileName();
894       if (!(strcmp(filename, "default"))) {
895          if (!mgr->GetOutputEventHandler()) continue;
896          filename = mgr->GetOutputEventHandler()->GetOutputFileName();
897          if (listaods.Length()) listaods += " ";
898          listaods += filename;
899       } else {
900          if(!listhists.Contains(filename)){
901             if (listhists.Length()) listhists += " ";
902             listhists += filename;
903          }
904       }
905    }
906
907    if (mgr->GetExtraFiles().Length()) {
908      if (listaods.Length()) listaods += " ";
909      listaods += mgr->GetExtraFiles();
910    }
911
912    TString outputArchive;
913    outputArchive = Form("log_archive.zip:std*r@%s",kGridOutputStorages.Data());
914    listaods.ReplaceAll(" ", ",");
915    listhists.ReplaceAll(" ", ",");
916    if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), kGridOutputStorages.Data());
917    if (listaods.Length())  listaods  = Form("aod_archive.zip:%s@%s", listaods.Data(), kGridOutputStorages.Data());
918
919    if (!listhists.Length() && !listaods.Length()) {
920       ::Fatal("AnalysisTrainHMPID", "No task output !");
921    }
922
923    if (listaods.Length()) {
924       outputArchive += " ";
925       outputArchive += listaods;
926    }
927    if (listhists.Length()) {
928       outputArchive += " ";
929       outputArchive += listhists;
930    }
931 //   plugin->SetOutputArchive(outputArchive);
932
933 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
934    plugin->SetAnalysisMacro(Form("%s.C", kTrainName.Data()));
935 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
936    plugin->SetSplitMaxInputFileNumber(kGridFilesPerJob);
937 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
938 //   plugin->SetMaxInitFailed(5);
939 // Optionally resubmit threshold.
940 //   plugin->SetMasterResubmitThreshold(90);
941 // Optionally set time to live (default 30000 sec)
942    plugin->SetTTL(30000);
943 // Optionally set input format (default xml-single)
944    plugin->SetInputFormat("xml-single");
945 // Optionally modify the name of the generated JDL (default analysis.jdl)
946    plugin->SetJDLName(Form("%s.jdl", kTrainName.Data()));
947 // Optionally modify the executable name (default analysis.sh)
948    plugin->SetExecutable(Form("%s.sh", kTrainName.Data()));
949 // Optionally modify job price (default 1)
950    plugin->SetPrice(1);      
951 // Optionally modify split mode (default 'se')    
952    plugin->SetSplitMode("se");
953    plugin->SetCheckCopy(kFALSE);
954    return plugin;
955 }
956
957 //______________________________________________________________________________
958 Bool_t LoadConfig(const char *filename)
959 {
960 // Read train configuration from file
961    if (gSystem->AccessPathName(filename)) {
962       ::Error("AnalysisTrainHMPID.C::LoadConfig", "Config file name not found");
963       return kFALSE;
964    }   
965    gROOT->ProcessLine(Form(".x %s", filename));
966    ::Info("AnalysisTrainHMPID.C::LoadConfig", "Train configuration loaded from file %s", filename);
967    return kTRUE;
968 }
969
970 //______________________________________________________________________________
971 Bool_t PatchJDL(){
972   Printf(">>> Patching JDL");
973   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
974   AliAnalysisAlien*    gridHandler = (AliAnalysisAlien*)mgr->GetGridHandler();
975   TGridJDL *jdl = gridHandler->GetGridJDL();
976   if(iJETAN)jdl->AddToPackages("fastjet","v2.4.0");
977   gridHandler->WriteJDL(kFALSE);
978   Printf("<<<  Patching JDL");
979   return kTRUE;
980 }
981
982 //______________________________________________________________________________
983 Bool_t PatchAnalysisMacro(){
984   Printf(">>> Patching AnalysisMacro");
985   gSystem->Exec(Form("mv %s.C %s.C_tmp",kTrainName.Data(),kTrainName.Data()));
986
987   ifstream in1; 
988   in1.open(Form("%s.C_tmp", kTrainName.Data()));
989   char cLine[250];
990   TString st;
991   while(in1.getline(cLine,250)){
992     st += cLine;
993     st += "\n";
994   }
995   Int_t index= -1;
996   index = st.Index("gSystem->Load(\"libPhysics\");");
997   index += strlen("gSystem->Load(\"libPhysics\");");
998   /*
999     TObjArray *arr;
1000     TObjString *objstr;
1001     arr = anaLibs.Tokenize(" ");
1002     TIter next(arr);
1003
1004     add += "\n\n // added by CKB \n";
1005     while ((objstr=(TObjString*)next())){
1006       if(objstr->GetString().Contains("PWG3"))continue;
1007       if(objstr->GetString().EndsWith(".so"))add += Form("gSystem->Load(\"%s\");\n",objstr->GetString().Data());
1008     }
1009     delete arr; 
1010     */
1011     //    add += Form("AliLog::SetGlobalLogLevel(%d);\n",AliLog::GetGlobalLogLevel());
1012   TString add = "";
1013
1014   if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1015   add += "\n\n // added by CKB \n";
1016   add += "\n gSystem->AddIncludePath(\"./\"); \n";
1017   if(gGrid && kPluginAliRootVersion.Length()==0){
1018     add += "\n // Dirty hack for TRD reference data \n";
1019     add += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1020     add += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1021     add += "\"); \n";
1022   }
1023   add += "// BKC \n\n";
1024   st.Insert(index,add.Data());
1025
1026   if(kUseCPAR && kPluginAliRootVersion.Length()==0){
1027     index = st.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1028     if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1029     st.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1030   }
1031
1032   ofstream out;
1033   out.open(Form("%s.C", kTrainName.Data()));
1034   if (out.bad()) {
1035     return kFALSE;
1036   }
1037   out << st << endl;
1038   Printf("<<< Patching AnalysisMacro");
1039
1040   Printf(">>> Patching Merge Macro");
1041   gSystem->Exec(Form("mv %s_merge.C %s_merge.C_tmp",kTrainName.Data(),kTrainName.Data()));
1042
1043   ifstream in2; 
1044   in2.open(Form("%s_merge.C_tmp", kTrainName.Data()));
1045   TString st2;
1046   while(in2.getline(cLine,250)){
1047     st2 += cLine;
1048     st2 += "\n";
1049   }
1050   index = st2.Index("gSystem->Load(\"libPhysics\");");
1051   index += strlen("gSystem->Load(\"libPhysics\");");
1052   TString add2 = "";
1053   add2 += "\n gSystem->AddIncludePath(\"./\"); \n";
1054   if(gGrid&&kPluginAliRootVersion.Length()==0){
1055     add2 += "\n // Dirty hack for TRD reference data \n";
1056     add2 += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1057     add2 += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1058     add2 += "\"); \n";
1059   }
1060   add2 += "// BKC \n\n";
1061   if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1062   st2.Insert(index,add.Data());
1063
1064   if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
1065     index = st2.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1066     if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1067     st2.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1068   }
1069
1070   // do not exclude the extra files from merign, this is done explicitly in this train script
1071   index = st2.Index("mergeExcludes +="); // uncommen $ALICE_ROOT include for par files
1072   if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1073   st2.Insert(index,"// CKB comment out, handled explicitly by the train macro \n //");
1074
1075
1076   ofstream out2;
1077   out2.open(Form("%s_merge.C", kTrainName.Data()));
1078   if (out2.bad()) {
1079     return kFALSE;
1080   }
1081   out2 << st2 << endl;
1082   Printf("<<< Patching Merging Macro");
1083
1084
1085   return kTRUE;
1086
1087 }