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.
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
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 Int_t iCentrality = 0; // Physics selection task
28 Bool_t kUseKinefilter = kFALSE; // use Kinematics filter
29 Bool_t kUseMuonfilter = kFALSE; // use muon filter
30 TString kCommonOutputFileName = "HmpidOutput.root";
33 //== general process variables
35 // ### Other flags to steer the analysis
36 //==============================================================================
37 Bool_t kSkipTerminate = kFALSE; // Do not call Teminate
38 Bool_t kDebugLevel = kTRUE; // activate debugging
39 Int_t kUseSysInfo = 0; // activate debugging
40 Bool_t kUseMC = kFALSE; // use MC info
41 Bool_t kIsMC = kFALSE; // is MC info, if false it overwrites Use(AOD)MC
42 Bool_t kUseESDTags = kTRUE; // use ESD tags for selection
43 Bool_t kUseTR = kFALSE; // use track references
45 // ### Analysis modules to be included. Some may not be yet fully implemented.
46 //==============================================================================
47 Int_t iHMPID = 0; // Basic HMPID analysis task
48 Int_t iHMPIDperf = 1; // Basic HMPID performance task
49 Int_t iJETAN = 0; // Jet analysis (PWG4) // 1 write standard 2 write non-standard jets
51 Int_t kHighPtFilterMask = 16; // change depending on the used AOD Filter
54 //==============================================================================
55 // ### PROOF Steering varibales
56 //==============================================================================
57 //== proof setup variables
58 TString kProofCluster = "alice-caf.cern.ch";
59 Bool_t kProofUseAFPAR = kTRUE; // use AF special par file
60 TString kProofAFversion = "VO_ALICE@AliRoot::v4-20-08-AN";
61 //== proof input and output variables
62 TString kProofDataSet = "/alice/sim/LHC10d2_117220";
63 //== proof process variables
64 Bool_t kProofClearPackages = kFALSE;
65 Int_t kProofEvents = 10000;
66 Int_t kProofOffset = 0;
68 //==============================================================================
69 // ### Grid plugin Steering varibiables
70 //==============================================================================
71 //== grid plugin setup variables
72 Bool_t kPluginUse = kTRUE; // do not change
73 Bool_t kPluginUseProductionMode = kFALSE; // use the plugin in production mode
74 TString kPluginRootVersion = "v5-28-00d"; // *CHANGE ME IF MORE RECENT IN GRID*
75 TString kPluginAliRootVersion = "v4-21-25-AN"; // *CHANGE ME IF MORE RECENT IN GRID*
76 Bool_t kPluginMergeViaJDL = kTRUE; // merge via JDL
77 Bool_t kPluginFastReadOption = kFALSE; // use xrootd flags to reduce timeouts
78 Bool_t kPluginOverwriteMode = kTRUE; // overwrite existing collections
79 Int_t kPluginOutputToRunNumber = 1; // write the output to subdirs named after run number
80 TString kPluginExecutableCommand = "aliroot -b -q";
82 // == grid plugin input and output variables
83 TString kGridDatadir = "/alice/data/2010/LHC10e";
84 TString kGridLocalRunList = "";
85 TString kGridWorkDir = "HmpidAnalysis/LHC10d4a"; // Alien working directory
86 TString kGridOutdir = ""; // AliEn output directory. If blank will become output_<kTrainName>
87 TString kGridDataSet = ""; // sub working directory not to confuse different run xmls
88 Int_t kGridRunRange[2] = {128260,128260}; // Set the run range
89 TString kGridRunPattern = "%03d"; // important for leading zeroes!!
90 TString kGridPassPattern = "/ESDs/pass2";
91 TString kGridExtraFiles = ""; // files that will be added to the input list in the JDL...
92 Int_t kGridMaxMergeFiles = 12; // Number of files merged in a chunk grid run range
93 TString kGridMergeExclude = "AliAOD.root"; // Files that should not be merged
94 TString kGridOutputStorages = "disk=2"; // Make replicas on the storages
95 // == grid process variables
96 Int_t kGridRunsPerMaster = 1; // Number of runs per master job
97 Int_t kGridFilesPerJob = 100; // Maximum number of files per job (gives size of AOD)
99 //==============================================================================
100 // ### Local Steering variables
101 //==============================================================================
102 //== local setup variables
103 //== local input and output variables
104 TString kLocalXMLDataset = ""; // Change local xml dataset for local interactive analysis
105 TString kLocalDataList = "local_deltaaod.txt"; // Change local xml dataset for local interactive analysis
106 // == local process variables
111 TString anaPars = "";
112 TString anaLibs = "";
113 TString anaLibsExtra = "";
114 TString anaSources = "";
115 // Function signatures
116 class AliAnalysisAlien;
118 //______________________________________________________________________________
119 void AnalysisTrainHMPID(const char *analysis_mode="local", const char *plugin_mode="",
120 const char *config_file="",Int_t iOffset = 0)
122 // Main analysis train macro. If a configuration file is provided, all parameters
123 // are taken from there but may be altered by CheckModuleFlags.
125 if (strlen(config_file) && !LoadConfig(config_file)) return;
127 if(iOffset)kProofOffset = iOffset;
128 TString smode(analysis_mode);
130 // Check compatibility of selected modules
131 CheckModuleFlags(smode);
133 printf("==================================================================\n");
134 printf("=========== RUNNING ANALYSIS TRAIN %s IN %s MODE ==========\n", kTrainName.Data(),smode.Data());
135 printf("==================================================================\n");
136 printf("= Configuring analysis train for: =\n");
137 printf("= ESD analysis =\n");
138 if (iPhysicsSelection) printf("= Physics selection =\n");
139 if (iESDfilter) printf("= ESD filter =\n");
140 if (iJETAN) printf("= Jet analysis =\n");
141 printf("==================================================================\n");
142 printf(":: use MC truth %d\n", (UInt_t)kUseMC);
143 printf(":: use KINE filter %d\n", (UInt_t)kUseKinefilter);
144 printf(":: use track refs %d\n", (UInt_t)kUseTR);
145 printf(":: use tags %d\n", (UInt_t)kUseESDTags);
146 printf(":: use debugging %d\n", (UInt_t)kDebugLevel);
147 printf(":: use PAR files %d\n", (UInt_t)kUsePAR);
148 printf(":: use AliEn plugin %d\n", (UInt_t)kPluginUse);
150 //==========================================================================
151 // Connect to back-end system
152 if (!Connect(smode)) {
153 ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode);
157 // Load common libraries and set include path
158 if (!LoadCommonLibraries(smode)) {
159 ::Error("AnalysisTrain", "Could not load common libraries");
165 // Make the analysis manager and connect event handlers
166 AliAnalysisManager *mgr = new AliAnalysisManager("HMPIDTrain", "HMPID train");
167 if (kCommonOutputFileName.Length()>0)mgr->SetCommonFileName(kCommonOutputFileName.Data());
169 if (!strcmp(plugin_mode, "test")) mgr->SetNSysInfo(1);
170 if (kUseSysInfo)mgr->SetNSysInfo(kUseSysInfo);
171 mgr->SetSkipTerminate(kSkipTerminate);
173 // Load analysis specific libraries
174 if (!LoadAnalysisLibraries(smode)) {
175 ::Error("AnalysisTrain", "Could not load analysis libraries");
179 // Create input handler (input container created automatically)
181 AliESDInputHandler *esdHandler = new AliESDInputHandler();
182 if (kUseESDTags) esdHandler->SetReadTags();
183 esdHandler->SetReadFriends(kTRUE);
184 mgr->SetInputEventHandler(esdHandler);
186 // Monte Carlo handler
188 AliMCEventHandler* mcHandler = new AliMCEventHandler();
189 mgr->SetMCtruthEventHandler(mcHandler);
190 mcHandler->SetReadTR(kUseTR);
193 // AOD output container, created automatically when setting an AOD handler
195 // AOD output handler
196 AliAODHandler* aodHandler = new AliAODHandler();
197 aodHandler->SetOutputFileName("AliAOD.root");
198 aodHandler->SetFillAODforRun(kFillAOD);
200 mgr->SetOutputEventHandler(aodHandler);
201 AliAnalysisDataContainer *cout_aod = mgr->GetCommonOutputContainer();
202 cout_aod->SetSpecialOutput();
205 // Debugging if needed
207 mgr->SetDebugLevel(3);
210 mgr->RegisterExtraFile("syswatch.root");
211 if(kGridMergeExclude.Length())kGridMergeExclude += " ";
212 kGridMergeExclude += "syswatch.root";
214 AliLog::SetGlobalLogLevel(AliLog::kError);
217 //==========================================================================
218 // Create the chain. In this example it is created only from ALIEN files but
219 // can be done to work in batch or grid mode as well.
220 TChain *chain = CreateChain(smode, plugin_mode);
222 //==========================================================================
223 // Load the tasks configuration macros for all wagons. These files are supposed now to be
224 // in the current workdir, but in AliEn they will be in the file catalog,
225 // mapped from AliRoot and pecified in the jdl input list.
226 if(iPhysicsSelection){
227 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
228 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kIsMC,kTRUE,kTRUE); // last flag also adds information on
232 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
233 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
234 taskCentrality->SetPass(2); // remember to set the pass you are processing!!!
238 // ESD filter task configuration.
239 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
240 AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kUseKinefilter,kUseMuonfilter);
242 mgr->RegisterExtraFile("pyxsec_hists.root");
243 if(kGridMergeExclude.Length())kGridMergeExclude += " ";
244 kGridMergeExclude += "pyxsec_hists.root";
250 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
251 AliAnalysisTaskJets *taskjets = 0;
252 if (iJETAN&1) taskjets = AddTaskJets(kHighPtFilterMask);
253 if (!taskjets) ::Warning("AnalysisTrainHMPID", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
257 gROOT->LoadMacro("$ALICE_ROOT/HMPID/AddTaskHMPID.C");
258 AliHMPIDAnalysisTask *taskHmpid = AddTaskHMPID(kUseMC);
259 if (!taskHmpid) ::Warning("AnalysisTrainHMPID", "AliHMPIDAnalysisTask cannot run for this train conditions - EXCLUDED");
263 gROOT->LoadMacro("$ALICE_ROOT/HMPID/AddTaskHMPIDPerformance.C");
264 AliHMPIDPerformanceTask *taskHmpidPerformance = AddTaskHMPIDPerformance(kUseMC);
265 if (!taskHmpidPerformance) ::Warning("AnalysisTrainHMPID", "AliHMPIDPerformanceTask cannot run for this train conditions - EXCLUDED");
269 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
270 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
273 if (mgr->InitAnalysis()) {
275 if (!strcmp(plugin_mode,"submit") && smode=="GRID"){
276 TString alien_workdir = gGrid->GetHomeDirectory();
277 alien_workdir += kGridWorkDir.Data();
278 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
279 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
280 printf("=== AnalysisTrainHMPID:: Registering jdl in the work directory alien://%s/%s, should be done by the manager! ===\n",
281 alien_workdir.Data(),gridhandler->GetGridOutputDir());
284 dest = Form("%s/%s/%s.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
285 if(AliAnalysisAlien::FileExists(dest.Data())){
286 // Printf("%s exist on grid removing...",dest.Data());
287 // gGrid->Rm(dest.Data());
289 TFile::Cp(Form("file:%s.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
293 dest = Form("%s/%s/%s_merge.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
294 if(AliAnalysisAlien::FileExists(dest.Data())){
295 // Printf("%s exist on grid removing...",dest.Data());
296 // gGrid->Rm(dest.Data());
298 TFile::Cp(Form("file:%s_merge.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
301 AliLog::SetGlobalLogLevel(AliLog::kError);
302 if((kUseSysInfo>0 && smode=="LOCAL") || !strcmp(plugin_mode, "test")){
303 TFile *fM = TFile::Open("manager_local.root","RECREATE");
308 StartAnalysis(smode, chain);
310 if((kUseSysInfo>0 && smode=="LOCAL") || !strcmp(plugin_mode, "test")){
311 for(int i = 0;i < mgr->GetTopTasks()->GetEntries();i++){
315 if (!strcmp(plugin_mode, "offline") && smode=="GRID"){
316 // Offline mode path files
318 PatchAnalysisMacro();
324 //______________________________________________________________________________
325 void StartAnalysis(const char *mode, TChain *chain) {
328 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
329 if (!strcmp(mode, "LOCAL")) imode = 0;
330 if (!strcmp(mode, "PROOF")) imode = 1;
331 if (!strcmp(mode, "GRID")) imode = 2;
335 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Cannot create the chain");
338 mgr->StartAnalysis(mode, chain,kNumberOfEvents);
341 if (!kProofDataSet.Length()) {
342 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "kProofDataSet is empty");
345 mgr->StartAnalysis(mode, kProofDataSet, kProofEvents,kProofOffset);
349 if (!mgr->GetGridHandler()) {
350 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Grid plugin not initialized");
353 mgr->StartAnalysis("grid");
356 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Cannot create the chain");
359 mgr->StartAnalysis(mode, chain);
365 //______________________________________________________________________________
366 void CheckModuleFlags(const char *mode) {
367 // Checks selected modules and insure compatibility
369 if (!strcmp(mode, "LOCAL")) imode = 0;
370 if (!strcmp(mode, "PROOF")) imode = 1;
371 if (!strcmp(mode, "GRID")) imode = 2;
375 kPluginAliRootVersion = ""; // NO aliroot if we use CPAR
380 ::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
385 ::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
390 // switch off anthin related to MC
398 if(kUseKinefilter)::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "Kine Filter disabled in analysis without MC");
399 kUseKinefilter = kFALSE;
405 kUseKinefilter = kFALSE;
406 kUseMuonfilter = kFALSE;
409 iJETANLib = iJETAN && 1;
410 if (iESDfilter) {iAODhandler=1;}
411 if (kUseKinefilter && !kUseMC) kUseKinefilter = kFALSE;
416 //______________________________________________________________________________
417 Bool_t Connect(const char *mode) {
418 // Connect <username> to the back-end system.
420 if (!strcmp(mode, "LOCAL")) imode = 0;
421 if (!strcmp(mode, "PROOF")) imode = 1;
422 if (!strcmp(mode, "GRID")) imode = 2;
423 TString username = gSystem->Getenv("alien_API_USER");
428 if (!username.Length()) {
429 ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode), "Make sure you:\n \
430 1. Have called: alien-token-init <username>\n \
431 2. Have called: >source /tmp/gclient_env_$UID");
434 ::Info("AnalysisTrainHMPID.C::Connect", "Connecting user <%s> to PROOF cluster <%s>",
435 username.Data(), kProofCluster.Data());
436 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
437 TProof::Open(Form("%s@%s", username.Data(), kProofCluster.Data()));
439 if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
440 ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
443 if(kProofClearPackages)gProof->ClearPackages();
446 if (!username.Length()) {
447 ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode), "Make sure you:\n \
448 1. Have called: alien-token-init <username>\n \
449 2. Have called: >source /tmp/gclient_env_$UID");
452 if (kPluginUse && !gSystem->Getenv("alien_CLOSE_SE")) {
453 ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode),
454 "When using the AliEn plugin it is preferable to define the \
455 variable alien_CLOSE_SE in your environment.");
458 ::Info("AnalysisTrainHMPID.C::Connect", "Connecting user <%s> to AliEn ...",
460 TGrid::Connect("alien://");
461 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
464 ::Error("AnalysisTrainHMPID.C::Connect", "Unknown run mode: %s", mode);
467 ::Info("AnalysisTrainHMPID.C::Connect","Connected in %s mode", mode);
472 //______________________________________________________________________________
473 Bool_t LoadCommonLibraries(const char *mode)
475 // Load common analysis libraries.
477 if (!strcmp(mode, "LOCAL")) imode = 0;
478 if (!strcmp(mode, "PROOF")) imode = 1;
479 if (!strcmp(mode, "GRID")) imode = 2;
480 if (!gSystem->Getenv("ALICE_ROOT")) {
481 ::Error("AnalysisTrainHMPID.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
484 Bool_t success = kTRUE;
486 gSystem->Load("libTree.so");
487 gSystem->Load("libGeom.so");
488 gSystem->Load("libVMC.so");
489 gSystem->Load("libPhysics.so");
491 // Load framework classes. Par option ignored here.
496 success &= LoadLibrary("STEERBase", mode, kTRUE);
497 success &= LoadLibrary("ESD", mode, kTRUE);
498 success &= LoadLibrary("AOD", mode, kTRUE);
499 success &= LoadLibrary("ANALYSIS", mode, kTRUE);
500 success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
501 success &= LoadLibrary("CORRFW", mode, kTRUE);
503 success &= LoadLibrary("libSTEERBase.so", mode);
504 success &= LoadLibrary("libESD.so", mode);
505 success &= LoadLibrary("libAOD.so", mode);
506 success &= LoadLibrary("libANALYSIS.so", mode);
507 success &= LoadLibrary("libANALYSISalice.so", mode);
508 success &= LoadLibrary("libCORRFW.so", mode);
509 gROOT->ProcessLine(".include $ALICE_ROOT/include");
513 if (!kProofUseAFPAR) {
514 success &= LoadLibrary("STEERBase", mode);
515 success &= LoadLibrary("ESD", mode);
516 success &= LoadLibrary("AOD", mode);
517 success &= LoadLibrary("ANALYSIS", mode);
518 success &= LoadLibrary("ANALYSISalice", mode);
519 success &= LoadLibrary("CORRFW", mode);
521 success &= !gProof->EnablePackage(kProofAFversion);
522 success &= LoadLibrary("CORRFW", mode);
526 ::Error("AnalysisTrainHMPID.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
530 ::Info("AnalysisTrainHMPID.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
531 ::Info("AnalysisTrainHMPID.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
532 gSystem->GetIncludePath());
534 ::Info("AnalysisTrainHMPID.C::LoadCommodLibraries", "Load common libraries: FAILED");
541 //______________________________________________________________________________
542 Bool_t LoadAnalysisLibraries(const char *mode)
544 // Load common analysis libraries.
545 Bool_t success = kTRUE;
547 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
548 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
552 if (!LoadSource(Form("%s/HMPID/AliHMPIDAnalysisTask.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
556 if (!LoadSource(Form("%s/HMPID/AliHMPIDPerformanceTask.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
560 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
563 ::Info("AnalysisTrainHMPID.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
568 //______________________________________________________________________________
569 Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
571 // Load a module library in a given mode. Reports success.
574 TString smodule(module);
575 if (!strcmp(mode, "LOCAL")) imode = 0;
576 if (!strcmp(mode, "PROOF")) imode = 1;
577 if (!strcmp(mode, "GRID")) imode = 2;
580 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Empty module name");
583 // If a library is specified, just load it
584 if (smodule.EndsWith(".so")) {
585 mod.Remove(mod.Index(".so"));
586 result = gSystem->Load(mod);
588 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not load library %s", module);
591 if (rec) anaLibs += Form("%s.so ",mod.Data());
592 if (rec) anaLibsExtra += Form("%s.so ",mod.Data());
595 // Check if the library is already loaded
596 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
602 result = SetupPar(module);
603 if (rec) anaPars += Form("%s.par ", module);
605 result = gSystem->Load(Form("lib%s.so", module));
606 if (rec) anaLibs += Form("lib%s.so ", module);
610 if(!gSystem->AccessPathName(module)){
611 ::Info("AnalysisTrainHMPID.C::LoadLibrary", "Removing directory %s",module);
612 gSystem->Exec(Form("rm -rf %s",module));
614 result = gProof->UploadPackage(module);
616 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
618 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
622 result = gProof->EnablePackage(module);
628 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not load module %s", module);
634 //______________________________________________________________________________
635 Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
637 // Load a module library in a given mode. Reports success.
640 if (!strcmp(mode, "LOCAL")) imode = 0;
641 if (!strcmp(mode, "PROOF")) imode = 1;
642 if (!strcmp(mode, "GRID")) imode = 2;
643 TString ssource(source);
644 TString basename = gSystem->BaseName(ssource.Data());
645 if (!ssource.Length()) {
646 ::Error("AnalysisTrainHMPID.C::LoadSource", "Empty task name");
649 // we have a source code so compile it
650 if (ssource.EndsWith(".cxx")) {
651 // need to copy it here other wise the path is also used on grid...
652 ssource.Remove(ssource.Index(".cxx"));
653 basename.Remove(basename.Index(".cxx"));
654 Printf("LoadSources:: Copying... path %s{cxx,h}",ssource.Data());
655 gSystem->Exec(Form("cp %s.cxx . ",ssource.Data()));
656 gSystem->Exec(Form("cp %s.h . ",ssource.Data()));
658 // only needed for local compilation, in grid and proof mode
659 // the task headers are uploaded
660 // path.Remove(path.Index(gSystem->BaseName(path.Data())));
661 // Printf("LoadSources:: Including path %s",path.Data());
662 // if(path.Length()>0)gROOT->ProcessLine(Form(".include %s",path.Data()));
663 Printf("LoadSources:: Loading... path %s",basename.Data());
666 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
669 result = gProof->Load(Form("%s.cxx++g",basename.Data()));
672 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
674 // what we want to compile
675 anaSources += Form("%s.cxx ",basename.Data());
676 // what we need as input...
677 anaLibs += Form("%s.cxx %s.h ",basename.Data(),basename.Data());
685 ::Error("AnalysisTrainHMPID.C::LoadSources", "Could not load source %s", source);
691 //______________________________________________________________________________
692 TChain *CreateChain(const char *mode, const char *plugin_mode)
694 // Create the input chain
696 if (!strcmp(mode, "LOCAL")) imode = 0;
697 if (!strcmp(mode, "PROOF")) imode = 1;
698 if (!strcmp(mode, "GRID")) imode = 2;
699 TChain *chain = NULL;
703 if (!kLocalXMLDataset.Length()) {
705 chain = new TChain("esdTree");
708 in.open(kLocalDataList.Data());
711 if (line.Length() == 0) continue;
712 cout << " line = " << line << endl;
713 chain->Add(line.Data());
717 chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
724 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
725 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
727 TString treeName = "esdTree";
728 chain = CreateChainSingle("wn.xml", treeName);
733 if (chain && chain->GetNtrees()) return chain;
737 //______________________________________________________________________________
738 TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
740 printf("*******************************\n");
741 printf("*** Getting the ESD Chain ***\n");
742 printf("*******************************\n");
743 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
746 ::Error("AnalysisTrainHMPID.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
750 TChain* chain = new TChain(treeName);
751 myCollection->Reset() ;
752 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
757 //______________________________________________________________________________
758 Int_t SetupPar(char* pararchivename)
760 if (!pararchivename || !strlen(pararchivename)) return -1;
761 char processline[1024];
762 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
763 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
764 ::Info("AnalysisTrainHMPID.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
765 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
766 Form("%s.par",pararchivename));
768 ::Error("AnalysisTrainHMPID.C::SetupPar", "Cannot find %s.par", pararchivename);
772 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
774 TString ocwd = gSystem->WorkingDirectory();
775 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
777 // check for BUILD.sh and execute
778 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
779 printf("*******************************\n");
780 printf("*** Building PAR archive ***\n");
781 printf("*******************************\n");
782 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
783 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
788 // check for SETUP.C and execute
789 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
790 printf("*******************************\n");
791 printf("*** Setup PAR archive ***\n");
792 printf("*******************************\n");
793 gROOT->Macro("PROOF-INF/SETUP.C");
795 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
799 //______________________________________________________________________________
800 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
802 // Check if user has a valid token, otherwise make one. This has limitations.
803 // One can always follow the standard procedure of calling alien-token-init then
804 // source /tmp/gclient_env_$UID in the current shell.
805 if (!AliAnalysisGrid::CreateToken()) return NULL;
806 AliAnalysisAlien *plugin = new AliAnalysisAlien();
807 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
808 plugin->SetRunMode(plugin_mode);
809 if (kPluginUseProductionMode) plugin->SetProductionMode();
810 plugin->SetJobTag(kJobTag);
811 plugin->SetNtestFiles(1);
812 // plugin->SetPreferedSE("ALICE::NIHAM::File");
813 // Set versions of used packages
814 plugin->SetAPIVersion("V1.1x");
815 plugin->SetROOTVersion(kPluginRootVersion);
816 plugin->SetAliROOTVersion(kPluginAliRootVersion);
818 // Declare input data to be processed.
819 // Method 1: Create automatically XML collections using alien 'find' command.
820 // Define production directory LFN
821 plugin->SetGridDataDir(kGridDatadir.Data());
822 // Set data search pattern
823 plugin->SetDataPattern(Form(" %s/*/*ESDs.root",kGridPassPattern.Data()));
824 // ...then add run numbers to be considered
825 plugin->SetRunPrefix("000"); // if real data
826 plugin->SetRunRange(kGridRunRange[0], kGridRunRange[1]);
828 if(kGridLocalRunList.Length()>0){
830 in1.open(kGridLocalRunList.Data());
832 // just use run numbers, negatives will be excluded
835 Printf("AnalysisTrainHMPID Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
836 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
838 Printf("AnalysisTrainHMPID Skipping run number from File %d", iRun);
843 // Method 2: Declare existing data files (raw collections, xml collections, root file)
844 // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
845 // XML collections added via this method can be combined with the first method if
846 // the content is compatible (using or not tags)
847 // plugin->AddDataFile("Hijing.xml");
848 // plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
849 // Define alien work directory where all files will be copied. Relative to alien $HOME.
850 TString alien_workdir = "";
852 alien_workdir += kGridWorkDir.Data();
853 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
854 plugin->SetGridWorkingDir(alien_workdir.Data());
856 // Declare alien output directory. Relative to working directory.
857 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
858 plugin->SetGridOutputDir(kGridOutdir);
860 // set extra libs before par file compilation
861 anaLibs += kGridExtraFiles;
862 anaLibs = anaLibs.Strip();
863 Printf("anaLibs %s",anaLibs.Data());
864 Printf("anaLibsExtra %s",anaLibsExtra.Data());
866 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs.Data());
867 if (anaLibsExtra.Length()) plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
869 TString ana_sources = "";
870 TString ana_add = "";
871 if (kUsePAR && anaPars.Length()) {
872 printf("%s\n", anaPars.Data());
875 arr = anaPars.Tokenize(" ");
877 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
881 // Declare the analysis source files names separated by blancs. To be compiled runtime
882 // using ACLiC on the worker nodes.
883 ana_sources = anaSources.Strip();
884 // Declare all libraries (other than the default ones for the framework. These will be
885 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
887 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
888 plugin->SetExecutableCommand(kPluginExecutableCommand.Data());
889 // Declare the output file names separated by blancs.
890 // (can be like: file.root or file.root@ALICE::Niham::File)
891 plugin->SetUseSubmitPolicy(kFALSE);
892 plugin->SetMergeExcludes(kGridMergeExclude);
893 plugin->SetMaxMergeFiles(kGridMaxMergeFiles);
894 plugin->SetNrunsPerMaster(kGridRunsPerMaster);
895 plugin->SetMergeViaJDL(kPluginMergeViaJDL);
896 // Use fastread option
897 plugin->SetFastReadOption(kPluginFastReadOption);
899 plugin->SetOverwriteMode(kPluginOverwriteMode);
900 // Optionally define the files to be archived.
901 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
902 plugin->SetOutputToRunNo(kPluginOutputToRunNumber); // write the output to subdirs named after run number
903 // plugin->SetDefaultOutputs(kFALSE);
905 // Put default output files to archive
906 TString listhists = "";
907 TString listaods = "";
908 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
909 TIter next(mgr->GetOutputs());
910 AliAnalysisDataContainer *output;
911 while ((output=(AliAnalysisDataContainer*)next())) {
912 const char *filename = output->GetFileName();
913 if (!(strcmp(filename, "default"))) {
914 if (!mgr->GetOutputEventHandler()) continue;
915 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
916 if (listaods.Length()) listaods += " ";
917 listaods += filename;
919 if(!listhists.Contains(filename)){
920 if (listhists.Length()) listhists += " ";
921 listhists += filename;
926 if (mgr->GetExtraFiles().Length()) {
927 if (listaods.Length()) listaods += " ";
928 listaods += mgr->GetExtraFiles();
931 TString outputArchive;
932 outputArchive = Form("log_archive.zip:std*r@%s",kGridOutputStorages.Data());
933 listaods.ReplaceAll(" ", ",");
934 listhists.ReplaceAll(" ", ",");
935 if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), kGridOutputStorages.Data());
936 if (listaods.Length()) listaods = Form("aod_archive.zip:%s@%s", listaods.Data(), kGridOutputStorages.Data());
938 if (!listhists.Length() && !listaods.Length()) {
939 ::Fatal("AnalysisTrainHMPID", "No task output !");
942 if (listaods.Length()) {
943 outputArchive += " ";
944 outputArchive += listaods;
946 if (listhists.Length()) {
947 outputArchive += " ";
948 outputArchive += listhists;
950 // plugin->SetOutputArchive(outputArchive);
952 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
953 plugin->SetAnalysisMacro(Form("%s.C", kTrainName.Data()));
954 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
955 plugin->SetSplitMaxInputFileNumber(kGridFilesPerJob);
956 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
957 // plugin->SetMaxInitFailed(5);
958 // Optionally resubmit threshold.
959 // plugin->SetMasterResubmitThreshold(90);
960 // Optionally set time to live (default 30000 sec)
961 plugin->SetTTL(30000);
962 // Optionally set input format (default xml-single)
963 plugin->SetInputFormat("xml-single");
964 // Optionally modify the name of the generated JDL (default analysis.jdl)
965 plugin->SetJDLName(Form("%s.jdl", kTrainName.Data()));
966 // Optionally modify the executable name (default analysis.sh)
967 plugin->SetExecutable(Form("%s.sh", kTrainName.Data()));
968 // Optionally modify job price (default 1)
970 // Optionally modify split mode (default 'se')
971 plugin->SetSplitMode("se");
972 plugin->SetCheckCopy(kFALSE);
976 //______________________________________________________________________________
977 Bool_t LoadConfig(const char *filename)
979 // Read train configuration from file
980 if (gSystem->AccessPathName(filename)) {
981 ::Error("AnalysisTrainHMPID.C::LoadConfig", "Config file name not found");
984 gROOT->ProcessLine(Form(".x %s", filename));
985 ::Info("AnalysisTrainHMPID.C::LoadConfig", "Train configuration loaded from file %s", filename);
989 //______________________________________________________________________________
991 Printf(">>> Patching JDL");
992 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
993 AliAnalysisAlien* gridHandler = (AliAnalysisAlien*)mgr->GetGridHandler();
994 TGridJDL *jdl = gridHandler->GetGridJDL();
995 if(iJETAN)jdl->AddToPackages("fastjet","v2.4.0");
996 gridHandler->WriteJDL(kFALSE);
997 Printf("<<< Patching JDL");
1001 //______________________________________________________________________________
1002 Bool_t PatchAnalysisMacro(){
1003 Printf(">>> Patching AnalysisMacro");
1004 gSystem->Exec(Form("mv %s.C %s.C_tmp",kTrainName.Data(),kTrainName.Data()));
1007 in1.open(Form("%s.C_tmp", kTrainName.Data()));
1010 while(in1.getline(cLine,250)){
1015 index = st.Index("gSystem->Load(\"libPhysics\");");
1016 index += strlen("gSystem->Load(\"libPhysics\");");
1020 arr = anaLibs.Tokenize(" ");
1023 add += "\n\n // added by CKB \n";
1024 while ((objstr=(TObjString*)next())){
1025 if(objstr->GetString().Contains("PWG3"))continue;
1026 if(objstr->GetString().EndsWith(".so"))add += Form("gSystem->Load(\"%s\");\n",objstr->GetString().Data());
1030 // add += Form("AliLog::SetGlobalLogLevel(%d);\n",AliLog::GetGlobalLogLevel());
1033 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1034 add += "\n\n // added by CKB \n";
1035 add += "\n gSystem->AddIncludePath(\"./\"); \n";
1036 if(gGrid && kPluginAliRootVersion.Length()==0){
1037 add += "\n // Dirty hack for TRD reference data \n";
1038 add += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1039 add += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1042 add += "// BKC \n\n";
1043 st.Insert(index,add.Data());
1045 if(kUseCPAR && kPluginAliRootVersion.Length()==0){
1046 index = st.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1047 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1048 st.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1052 out.open(Form("%s.C", kTrainName.Data()));
1057 Printf("<<< Patching AnalysisMacro");
1059 Printf(">>> Patching Merge Macro");
1060 gSystem->Exec(Form("mv %s_merge.C %s_merge.C_tmp",kTrainName.Data(),kTrainName.Data()));
1063 in2.open(Form("%s_merge.C_tmp", kTrainName.Data()));
1065 while(in2.getline(cLine,250)){
1069 index = st2.Index("gSystem->Load(\"libPhysics\");");
1070 index += strlen("gSystem->Load(\"libPhysics\");");
1072 add2 += "\n gSystem->AddIncludePath(\"./\"); \n";
1073 if(gGrid&&kPluginAliRootVersion.Length()==0){
1074 add2 += "\n // Dirty hack for TRD reference data \n";
1075 add2 += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1076 add2 += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1079 add2 += "// BKC \n\n";
1080 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1081 st2.Insert(index,add.Data());
1083 if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
1084 index = st2.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1085 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1086 st2.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1089 // do not exclude the extra files from merign, this is done explicitly in this train script
1090 index = st2.Index("mergeExcludes +="); // uncommen $ALICE_ROOT include for par files
1091 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1092 st2.Insert(index,"// CKB comment out, handled explicitly by the train macro \n //");
1096 out2.open(Form("%s_merge.C", kTrainName.Data()));
1100 out2 << st2 << endl;
1101 Printf("<<< Patching Merging Macro");