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