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 iAODanalysis = 0; // Analysis on input AOD's
25 Int_t iAODhandler = 1; // Analysis produces an AOD or dAOD's
26 Int_t iESDfilter = 0; // ESD to AOD filter (barrel + muon tracks)
27 Int_t iPhysicsSelection = 1; // Physics selection task
28 Int_t iCentrality = 0; // Physics selection task
29 Bool_t kUseKinefilter = kFALSE; // use Kinematics filter
30 Bool_t kUseMuonfilter = kFALSE; // use muon filter
31 TString kCommonOutputFileName = "HmpidOutput.root";
34 //== general process variables
36 // ### Other flags to steer the analysis
37 //==============================================================================
38 Bool_t kSkipTerminate = kFALSE; // Do not call Teminate
39 Bool_t kDebugLevel = kTRUE; // activate debugging
40 Int_t kUseSysInfo = 0; // activate debugging
41 Long64_t kNumberOfEvents = 1234567890; // number of events to process from the chain
42 Bool_t kUseMC = kFALSE; // use MC info
43 Bool_t kIsMC = kFALSE; // is MC info, if false it overwrites Use(AOD)MC
44 Bool_t kUseESDTags = kFALSE; // use ESD tags for selection
45 Bool_t kUseTR = kFALSE; // use track references
47 // ### Analysis modules to be included. Some may not be yet fully implemented.
48 //==============================================================================
49 Int_t iHMPID = 1; // Basic HMPID analysis task
50 Int_t iHMPIDperf = 0; // Basic HMPID performance task
51 Int_t iJETAN = 0; // Jet analysis (PWG4) // 1 write standard 2 write non-standard jets
52 Int_t iHMPIDJets = 0; // Jet chemistry with HMPID
54 Int_t kHighPtFilterMask = 16; // change depending on the used AOD Filter
57 //==============================================================================
58 // ### PROOF Steering varibales
59 //==============================================================================
60 //== proof setup variables
61 TString kProofCluster = "alice-caf.cern.ch";
62 Bool_t kProofUseAFPAR = kTRUE; // use AF special par file
63 TString kProofAFversion = "VO_ALICE@AliRoot::v4-20-08-AN";
64 //== proof input and output variables
65 TString kProofDataSet = "/alice/sim/LHC10d2_117220";
66 //== proof process variables
67 Bool_t kProofClearPackages = kFALSE;
68 Int_t kProofEvents = 10000;
69 Int_t kProofOffset = 0;
71 //==============================================================================
72 // ### Grid plugin Steering varibiables
73 //==============================================================================
74 //== grid plugin setup variables
75 Bool_t kPluginUse = kTRUE; // do not change
76 Bool_t kPluginUseProductionMode = kFALSE; // use the plugin in production mode
77 TString kPluginRootVersion = "v5-28-00d"; // *CHANGE ME IF MORE RECENT IN GRID*
78 TString kPluginAliRootVersion = "v4-21-26-AN"; // *CHANGE ME IF MORE RECENT IN GRID*
79 Bool_t kPluginMergeViaJDL = kTRUE; // merge via JDL
80 Bool_t kPluginFastReadOption = kFALSE; // use xrootd flags to reduce timeouts
81 Bool_t kPluginOverwriteMode = kTRUE; // overwrite existing collections
82 Int_t kPluginOutputToRunNumber = 1; // write the output to subdirs named after run number
83 TString kPluginExecutableCommand = "aliroot -b -q";
85 // == grid plugin input and output variables
86 TString kGridDatadir = "/alice/data/2010/LHC10e";
87 TString kGridLocalRunList = "";
88 TString kGridWorkDir = ""; // Alien working directory
89 TString kGridOutdir = ""; // AliEn output directory. If blank will become output_<kTrainName>
90 TString kGridDataSet = ""; // sub working directory not to confuse different run xmls
91 Int_t kGridRunRange[2] = {128260,128260}; // Set the run range
92 TString kGridRunPattern = "%03d"; // important for leading zeroes!!
93 TString kGridPassPattern = "/ESDs/pass2";
94 TString kGridExtraFiles = ""; // files that will be added to the input list in the JDL...
95 Int_t kGridMaxMergeFiles = 12; // Number of files merged in a chunk grid run range
96 Int_t kGridMaxMergeStages = 3; // Number of stages in the merging procedure
97 TString kGridMergeExclude = "AliAOD.root"; // Files that should not be merged
98 TString kGridOutputStorages = "disk=2"; // Make replicas on the storages
99 // == grid process variables
100 Int_t kGridRunsPerMaster = 1; // Number of runs per master job
101 Int_t kGridFilesPerJob = 100; // Maximum number of files per job (gives size of AOD)
103 //==============================================================================
104 // ### Local Steering variables
105 //==============================================================================
106 //== local setup variables
107 //== local input and output variables
108 TString kLocalXMLDataset = ""; // Change local xml dataset for local interactive analysis
109 TString kLocalDataList = "local_deltaaod.txt"; // Change local xml dataset for local interactive analysis
110 // == local process variables
115 TString anaPars = "";
116 TString anaLibs = "";
117 TString anaLibsExtra = "";
118 TString anaSources = "";
119 // Function signatures
120 class AliAnalysisAlien;
122 //______________________________________________________________________________
123 void AnalysisTrainHMPID(const char *analysis_mode="local", const char *plugin_mode="",
124 const char *config_file="",Int_t iOffset = 0)
126 // Main analysis train macro. If a configuration file is provided, all parameters
127 // are taken from there but may be altered by CheckModuleFlags.
129 if (strlen(config_file) && !LoadConfig(config_file)) return;
131 if(iOffset)kProofOffset = iOffset;
132 TString smode(analysis_mode);
134 // Check compatibility of selected modules
135 CheckModuleFlags(smode);
137 printf("==================================================================\n");
138 printf("=========== RUNNING ANALYSIS TRAIN %s IN %s MODE ==========\n", kTrainName.Data(),smode.Data());
139 printf("==================================================================\n");
140 printf("= Configuring analysis train for: =\n");
141 if (iAODanalysis) printf("= AOD analysis =\n");
142 else printf("= ESD analysis =\n");
143 if (iPhysicsSelection) printf("= Physics selection =\n");
144 if (iCentrality) printf("= Centrality =\n");
145 if (iESDfilter) printf("= ESD filter =\n");
146 if (iJETAN) printf("= Jet analysis =\n");
147 if (iHMPID) printf("= HMPID generic =\n");
148 if (iHMPIDperf) printf("= HMPID performance =\n");
149 if (iHMPIDJets) printf("= HMPID Jet chemistry =\n");
150 printf("==================================================================\n");
151 printf(":: use MC truth %d\n", (UInt_t)kUseMC);
152 printf(":: use KINE filter %d\n", (UInt_t)kUseKinefilter);
153 printf(":: use track refs %d\n", (UInt_t)kUseTR);
154 printf(":: use tags %d\n", (UInt_t)kUseESDTags);
155 printf(":: use debugging %d\n", (UInt_t)kDebugLevel);
156 printf(":: use PAR files %d\n", (UInt_t)kUsePAR);
157 printf(":: use AliEn plugin %d\n", (UInt_t)kPluginUse);
159 //==========================================================================
160 // Connect to back-end system
161 if (!Connect(smode)) {
162 ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode);
166 // Load common libraries and set include path
167 if (!LoadCommonLibraries(smode)) {
168 ::Error("AnalysisTrain", "Could not load common libraries");
173 // Make the analysis manager and connect event handlers
174 AliAnalysisManager *mgr = new AliAnalysisManager("HMPIDTrain", "HMPID train");
175 if (kCommonOutputFileName.Length()>0)mgr->SetCommonFileName(kCommonOutputFileName.Data());
177 if (!strcmp(plugin_mode, "test")) mgr->SetNSysInfo(1);
178 if (kUseSysInfo)mgr->SetNSysInfo(kUseSysInfo);
179 mgr->SetSkipTerminate(kSkipTerminate);
181 // Load analysis specific libraries
182 if (!LoadAnalysisLibraries(smode)) {
183 ::Error("AnalysisTrain", "Could not load analysis libraries");
187 // Create input handler (input container created automatically)
190 AliAODInputHandler *aodH = new AliAODInputHandler();
191 mgr->SetInputEventHandler(aodH);
194 AliESDInputHandler *esdHandler = new AliESDInputHandler();
195 if (kUseESDTags) esdHandler->SetReadTags();
196 esdHandler->SetReadFriends(kTRUE);
197 mgr->SetInputEventHandler(esdHandler);
200 // Monte Carlo handler
201 if (kUseMC && !iAODanalysis) {
202 AliMCEventHandler* mcHandler = new AliMCEventHandler();
203 mgr->SetMCtruthEventHandler(mcHandler);
204 mcHandler->SetReadTR(kUseTR);
207 // AOD output container, created automatically when setting an AOD handler
209 // AOD output handler
210 AliAODHandler* aodHandler = new AliAODHandler();
211 aodHandler->SetOutputFileName("AliAOD.root");
212 aodHandler->SetFillAODforRun(kFillAOD);
214 mgr->SetOutputEventHandler(aodHandler);
215 AliAnalysisDataContainer *cout_aod = mgr->GetCommonOutputContainer();
216 cout_aod->SetSpecialOutput();
219 // Debugging if needed
221 mgr->SetDebugLevel(3);
224 mgr->RegisterExtraFile("syswatch.root");
225 if(kGridMergeExclude.Length())kGridMergeExclude += " ";
226 kGridMergeExclude += "syswatch.root";
228 AliLog::SetGlobalLogLevel(AliLog::kError);
231 //==========================================================================
232 // Create the chain. In this example it is created only from ALIEN files but
233 // can be done to work in batch or grid mode as well.
234 TChain *chain = CreateChain(smode, plugin_mode);
236 //==========================================================================
237 // Load the tasks configuration macros for all wagons. These files are supposed now to be
238 // in the current workdir, but in AliEn they will be in the file catalog,
239 // mapped from AliRoot and pecified in the jdl input list.
240 if(iPhysicsSelection && !iAODanalysis){
241 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
242 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kIsMC,kTRUE,kTRUE); // last flag also adds information on
245 if(iCentrality && !iAODanalysis){
246 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
247 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
248 taskCentrality->SetPass(2); // remember to set the pass you are processing!!!
251 if (iESDfilter && !iAODanalysis) {
252 // ESD filter task configuration.
253 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
254 AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kUseKinefilter,kUseMuonfilter);
256 mgr->RegisterExtraFile("pyxsec_hists.root");
257 if(kGridMergeExclude.Length())kGridMergeExclude += " ";
258 kGridMergeExclude += "pyxsec_hists.root";
264 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
265 AliAnalysisTaskJets *taskjets = 0;
266 if (iJETAN&1) taskjets = AddTaskJets(kHighPtFilterMask);
267 if (!taskjets) ::Warning("AnalysisTrainHMPID", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
271 gROOT->LoadMacro("$ALICE_ROOT/HMPID/AddTaskHMPID.C");
272 AliHMPIDAnalysisTask *taskHmpid = AddTaskHMPID(kUseMC);
273 if (!taskHmpid) ::Warning("AnalysisTrainHMPID", "AliHMPIDAnalysisTask cannot run for this train conditions - EXCLUDED");
277 gROOT->LoadMacro("$ALICE_ROOT/HMPID/AddTaskHMPIDPerformance.C");
278 AliHMPIDPerformanceTask *taskHmpidPerformance = AddTaskHMPIDPerformance(kUseMC);
279 if (!taskHmpidPerformance) ::Warning("AnalysisTrainHMPID", "AliHMPIDPerformanceTask cannot run for this train conditions - EXCLUDED");
283 gROOT->LoadMacro("$ALICE_ROOT/HMPID/AddTaskJetsHMPID.C");
284 AliAnalysisTaskJetsHMPID *taskHmpidJets = AddTaskJetsHMPID("clustersAOD_ANTIKT04_B0_Filter00256_Cut00150_Skip00","jeteventbackground_clustersAOD_KT04_B0_Filter00256_Cut00150_Skip00");
285 if (!taskHmpidJets) ::Warning("AnalysisTrainHMPID", "AliAnalysisTaskJetsHMPID cannot run for this train conditions - EXCLUDED");
289 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
290 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
293 if (mgr->InitAnalysis()) {
295 if (!strcmp(plugin_mode,"submit") && smode=="GRID"){
296 TString alien_workdir = gGrid->GetHomeDirectory();
297 alien_workdir += kGridWorkDir.Data();
298 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
299 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
300 printf("=== AnalysisTrainHMPID:: Registering jdl in the work directory alien://%s/%s, should be done by the manager! ===\n",
301 alien_workdir.Data(),gridhandler->GetGridOutputDir());
304 dest = Form("%s/%s/%s.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
305 if(AliAnalysisAlien::FileExists(dest.Data())){
306 // Printf("%s exist on grid removing...",dest.Data());
307 // gGrid->Rm(dest.Data());
309 TFile::Cp(Form("file:%s.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
313 dest = Form("%s/%s/%s_merge.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
314 if(AliAnalysisAlien::FileExists(dest.Data())){
315 // Printf("%s exist on grid removing...",dest.Data());
316 // gGrid->Rm(dest.Data());
318 TFile::Cp(Form("file:%s_merge.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
321 AliLog::SetGlobalLogLevel(AliLog::kError);
322 if((kUseSysInfo>0 && smode=="LOCAL") || !strcmp(plugin_mode, "test")){
323 TFile *fM = TFile::Open("manager_local.root","RECREATE");
328 StartAnalysis(smode, chain);
330 if((kUseSysInfo>0 && smode=="LOCAL") || !strcmp(plugin_mode, "test")){
331 for(int i = 0;i < mgr->GetTopTasks()->GetEntries();i++){
335 if (!strcmp(plugin_mode, "offline") && smode=="GRID"){
336 // Offline mode path files
338 PatchAnalysisMacro();
344 //______________________________________________________________________________
345 void StartAnalysis(const char *mode, TChain *chain) {
348 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
349 if (!strcmp(mode, "LOCAL")) imode = 0;
350 if (!strcmp(mode, "PROOF")) imode = 1;
351 if (!strcmp(mode, "GRID")) imode = 2;
355 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Cannot create the chain");
358 mgr->StartAnalysis(mode, chain, kNumberOfEvents);
361 if (!kProofDataSet.Length()) {
362 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "kProofDataSet is empty");
365 mgr->StartAnalysis(mode, kProofDataSet, kProofEvents,kProofOffset);
369 if (!mgr->GetGridHandler()) {
370 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Grid plugin not initialized");
373 mgr->StartAnalysis("grid");
376 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Cannot create the chain");
379 mgr->StartAnalysis(mode, chain);
385 //______________________________________________________________________________
386 void CheckModuleFlags(const char *mode) {
387 // Checks selected modules and insure compatibility
389 if (!strcmp(mode, "LOCAL")) imode = 0;
390 if (!strcmp(mode, "PROOF")) imode = 1;
391 if (!strcmp(mode, "GRID")) imode = 2;
395 kPluginAliRootVersion = ""; // NO aliroot if we use CPAR
400 ::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
405 ::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
410 // switch off anything related to MC
418 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "MC usage disabled in analysis on AOD's");
422 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "ESD filter disabled in analysis on AOD's");
424 if (iPhysicsSelection)
425 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "Physics Selection disabled in analysis on AOD's");
426 iPhysicsSelection = 0;
429 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "JETAN disabled in analysis on AOD's without AOD handler");
432 if(iHMPID)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "HMPID analysis disabled in analysis on AOD's");
434 if(iHMPIDperf)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "HMPID performance disabled in analysis on AOD's");
440 if(kUseKinefilter)::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "Kine Filter disabled in analysis without MC");
441 kUseKinefilter = kFALSE;
447 kUseKinefilter = kFALSE;
448 kUseMuonfilter = kFALSE;
452 iJETANLib = iJETAN && 1;
453 if (iESDfilter) {iAODhandler=1;}
454 if (kUseKinefilter && !kUseMC) kUseKinefilter = kFALSE;
459 //______________________________________________________________________________
460 Bool_t Connect(const char *mode) {
461 // Connect <username> to the back-end system.
463 if (!strcmp(mode, "LOCAL")) imode = 0;
464 if (!strcmp(mode, "PROOF")) imode = 1;
465 if (!strcmp(mode, "GRID")) imode = 2;
466 TString username = gSystem->Getenv("alien_API_USER");
471 if (!username.Length()) {
472 ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode), "Make sure you:\n \
473 1. Have called: alien-token-init <username>\n \
474 2. Have called: >source /tmp/gclient_env_$UID");
477 ::Info("AnalysisTrainHMPID.C::Connect", "Connecting user <%s> to PROOF cluster <%s>",
478 username.Data(), kProofCluster.Data());
479 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
480 TProof::Open(Form("%s@%s", username.Data(), kProofCluster.Data()));
482 if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
483 ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
486 if(kProofClearPackages)gProof->ClearPackages();
489 if (!username.Length()) {
490 ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode), "Make sure you:\n \
491 1. Have called: alien-token-init <username>\n \
492 2. Have called: >source /tmp/gclient_env_$UID");
495 if (kPluginUse && !gSystem->Getenv("alien_CLOSE_SE")) {
496 ::Error(Form("AnalysisTrainHMPID.C::Connect <%s>", mode),
497 "When using the AliEn plugin it is preferable to define the \
498 variable alien_CLOSE_SE in your environment.");
501 ::Info("AnalysisTrainHMPID.C::Connect", "Connecting user <%s> to AliEn ...",
503 TGrid::Connect("alien://");
504 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
507 ::Error("AnalysisTrainHMPID.C::Connect", "Unknown run mode: %s", mode);
510 ::Info("AnalysisTrainHMPID.C::Connect","Connected in %s mode", mode);
515 //______________________________________________________________________________
516 Bool_t LoadCommonLibraries(const char *mode)
518 // Load common analysis libraries.
520 if (!strcmp(mode, "LOCAL")) imode = 0;
521 if (!strcmp(mode, "PROOF")) imode = 1;
522 if (!strcmp(mode, "GRID")) imode = 2;
523 if (!gSystem->Getenv("ALICE_ROOT")) {
524 ::Error("AnalysisTrainHMPID.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
527 Bool_t success = kTRUE;
529 gSystem->Load("libTree.so");
530 gSystem->Load("libGeom.so");
531 gSystem->Load("libVMC.so");
532 gSystem->Load("libPhysics.so");
534 // Load framework classes. Par option ignored here.
539 success &= LoadLibrary("STEERBase", mode, kTRUE);
540 success &= LoadLibrary("ESD", mode, kTRUE);
541 success &= LoadLibrary("AOD", mode, kTRUE);
542 success &= LoadLibrary("ANALYSIS", mode, kTRUE);
543 success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
544 success &= LoadLibrary("CORRFW", mode, kTRUE);
546 success &= LoadLibrary("libSTEERBase.so", mode);
547 success &= LoadLibrary("libESD.so", mode);
548 success &= LoadLibrary("libAOD.so", mode);
549 success &= LoadLibrary("libANALYSIS.so", mode);
550 success &= LoadLibrary("libANALYSISalice.so", mode);
551 success &= LoadLibrary("libCORRFW.so", mode);
552 gROOT->ProcessLine(".include $ALICE_ROOT/include");
556 if (!kProofUseAFPAR) {
557 success &= LoadLibrary("STEERBase", mode);
558 success &= LoadLibrary("ESD", mode);
559 success &= LoadLibrary("AOD", mode);
560 success &= LoadLibrary("ANALYSIS", mode);
561 success &= LoadLibrary("ANALYSISalice", mode);
562 success &= LoadLibrary("CORRFW", mode);
564 success &= !gProof->EnablePackage(kProofAFversion);
565 success &= LoadLibrary("CORRFW", mode);
569 ::Error("AnalysisTrainHMPID.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
573 ::Info("AnalysisTrainHMPID.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
574 ::Info("AnalysisTrainHMPID.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
575 gSystem->GetIncludePath());
577 ::Info("AnalysisTrainHMPID.C::LoadCommodLibraries", "Load common libraries: FAILED");
584 //______________________________________________________________________________
585 Bool_t LoadAnalysisLibraries(const char *mode)
587 // Load common analysis libraries.
588 Bool_t success = kTRUE;
590 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
591 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
595 if (!LoadSource(Form("%s/HMPID/AliHMPIDAnalysisTask.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
599 if (!LoadSource(Form("%s/HMPID/AliHMPIDPerformanceTask.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
603 if (!LoadSource(Form("%s/HMPID/AliAnalysisTaskJetsHMPID.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
607 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
610 ::Info("AnalysisTrainHMPID.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
615 //______________________________________________________________________________
616 Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
618 // Load a module library in a given mode. Reports success.
621 TString smodule(module);
622 if (!strcmp(mode, "LOCAL")) imode = 0;
623 if (!strcmp(mode, "PROOF")) imode = 1;
624 if (!strcmp(mode, "GRID")) imode = 2;
627 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Empty module name");
630 // If a library is specified, just load it
631 if (smodule.EndsWith(".so")) {
632 mod.Remove(mod.Index(".so"));
633 result = gSystem->Load(mod);
635 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not load library %s", module);
638 if (rec) anaLibs += Form("%s.so ",mod.Data());
639 if (rec) anaLibsExtra += Form("%s.so ",mod.Data());
642 // Check if the library is already loaded
643 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
649 result = SetupPar(module);
650 if (rec) anaPars += Form("%s.par ", module);
652 result = gSystem->Load(Form("lib%s.so", module));
653 if (rec) anaLibs += Form("lib%s.so ", module);
657 if(!gSystem->AccessPathName(module)){
658 ::Info("AnalysisTrainHMPID.C::LoadLibrary", "Removing directory %s",module);
659 gSystem->Exec(Form("rm -rf %s",module));
661 result = gProof->UploadPackage(module);
663 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
665 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
669 result = gProof->EnablePackage(module);
675 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not load module %s", module);
681 //______________________________________________________________________________
682 Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
684 // Load a module library in a given mode. Reports success.
687 if (!strcmp(mode, "LOCAL")) imode = 0;
688 if (!strcmp(mode, "PROOF")) imode = 1;
689 if (!strcmp(mode, "GRID")) imode = 2;
690 TString ssource(source);
691 TString basename = gSystem->BaseName(ssource.Data());
692 if (!ssource.Length()) {
693 ::Error("AnalysisTrainHMPID.C::LoadSource", "Empty task name");
696 // we have a source code so compile it
697 if (ssource.EndsWith(".cxx")) {
698 // need to copy it here other wise the path is also used on grid...
699 ssource.Remove(ssource.Index(".cxx"));
700 basename.Remove(basename.Index(".cxx"));
701 Printf("LoadSources:: Copying... path %s{cxx,h}",ssource.Data());
702 gSystem->Exec(Form("cp %s.cxx . ",ssource.Data()));
703 gSystem->Exec(Form("cp %s.h . ",ssource.Data()));
705 // only needed for local compilation, in grid and proof mode
706 // the task headers are uploaded
707 // path.Remove(path.Index(gSystem->BaseName(path.Data())));
708 // Printf("LoadSources:: Including path %s",path.Data());
709 // if(path.Length()>0)gROOT->ProcessLine(Form(".include %s",path.Data()));
710 Printf("LoadSources:: Loading... path %s",basename.Data());
713 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
716 result = gProof->Load(Form("%s.cxx++g",basename.Data()));
719 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
721 // what we want to compile
722 anaSources += Form("%s.cxx ",basename.Data());
723 // what we need as input...
724 anaLibs += Form("%s.cxx %s.h ",basename.Data(),basename.Data());
732 ::Error("AnalysisTrainHMPID.C::LoadSources", "Could not load source %s", source);
738 //______________________________________________________________________________
739 TChain *CreateChain(const char *mode, const char *plugin_mode)
741 // Create the input chain
743 if (!strcmp(mode, "LOCAL")) imode = 0;
744 if (!strcmp(mode, "PROOF")) imode = 1;
745 if (!strcmp(mode, "GRID")) imode = 2;
746 TChain *chain = NULL;
751 if (!kLocalXMLDataset.Length()) {
753 chain = new TChain("aodTree");
756 in.open(kLocalDataList.Data());
759 if (line.Length() == 0) continue;
760 // cout << " line = " << line << endl;
761 chain->Add(line.Data());
765 chain = CreateChainSingle(kLocalXMLDataset, "aodTree");
768 if (!kLocalXMLDataset.Length()) {
770 chain = new TChain("esdTree");
773 in.open(kLocalDataList.Data());
776 if (line.Length() == 0) continue;
777 cout << " line = " << line << endl;
778 chain->Add(line.Data());
782 chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
790 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
791 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
793 TString treeName = "esdTree";
794 if (iAODanalysis) treeName = "aodTree";
795 chain = CreateChainSingle("wn.xml", treeName);
800 if (chain && chain->GetNtrees()) return chain;
804 //______________________________________________________________________________
805 TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
807 printf("*******************************\n");
808 printf("*** Getting the ESD Chain ***\n");
809 printf("*******************************\n");
810 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
813 ::Error("AnalysisTrainHMPID.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
817 TChain* chain = new TChain(treeName);
818 myCollection->Reset() ;
819 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
824 //______________________________________________________________________________
825 Int_t SetupPar(char* pararchivename)
827 if (!pararchivename || !strlen(pararchivename)) return -1;
828 char processline[1024];
829 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
830 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
831 ::Info("AnalysisTrainHMPID.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
832 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
833 Form("%s.par",pararchivename));
835 ::Error("AnalysisTrainHMPID.C::SetupPar", "Cannot find %s.par", pararchivename);
839 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
841 TString ocwd = gSystem->WorkingDirectory();
842 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
844 // check for BUILD.sh and execute
845 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
846 printf("*******************************\n");
847 printf("*** Building PAR archive ***\n");
848 printf("*******************************\n");
849 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
850 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
855 // check for SETUP.C and execute
856 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
857 printf("*******************************\n");
858 printf("*** Setup PAR archive ***\n");
859 printf("*******************************\n");
860 gROOT->Macro("PROOF-INF/SETUP.C");
862 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
866 //______________________________________________________________________________
867 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
869 // Check if user has a valid token, otherwise make one. This has limitations.
870 // One can always follow the standard procedure of calling alien-token-init then
871 // source /tmp/gclient_env_$UID in the current shell.
872 if (!AliAnalysisGrid::CreateToken()) return NULL;
873 AliAnalysisAlien *plugin = new AliAnalysisAlien();
874 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
875 plugin->SetRunMode(plugin_mode);
876 if (kPluginUseProductionMode) plugin->SetProductionMode();
877 plugin->SetJobTag(kJobTag);
878 plugin->SetNtestFiles(1);
879 // plugin->SetPreferedSE("ALICE::NIHAM::File");
880 // Set versions of used packages
881 plugin->SetAPIVersion("V1.1x");
882 plugin->SetROOTVersion(kPluginRootVersion);
883 plugin->SetAliROOTVersion(kPluginAliRootVersion);
885 // Declare input data to be processed.
886 // Method 1: Create automatically XML collections using alien 'find' command.
887 // Define production directory LFN
888 plugin->SetGridDataDir(kGridDatadir.Data());
889 // Set data search pattern
890 if (iAODanalysis) plugin->SetDataPattern(" *AliAOD.root");
891 else plugin->SetDataPattern(Form(" %s/*/*ESDs.root",kGridPassPattern.Data()));
892 // ...then add run numbers to be considered
893 plugin->SetRunPrefix("000"); // if real data
894 plugin->SetRunRange(kGridRunRange[0], kGridRunRange[1]);
896 if(kGridLocalRunList.Length()>0){
898 in1.open(kGridLocalRunList.Data());
900 // just use run numbers, negatives will be excluded
903 Printf("AnalysisTrainHMPID Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
904 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
906 Printf("AnalysisTrainHMPID Skipping run number from File %d", iRun);
911 // Method 2: Declare existing data files (raw collections, xml collections, root file)
912 // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
913 // XML collections added via this method can be combined with the first method if
914 // the content is compatible (using or not tags)
915 // plugin->AddDataFile("Hijing.xml");
916 // plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
917 // Define alien work directory where all files will be copied. Relative to alien $HOME.
918 TString alien_workdir = "";
920 alien_workdir += kGridWorkDir.Data();
921 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
922 plugin->SetGridWorkingDir(alien_workdir.Data());
924 // Declare alien output directory. Relative to working directory.
925 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
926 plugin->SetGridOutputDir(kGridOutdir);
928 // set extra libs before par file compilation
929 anaLibs += kGridExtraFiles;
930 anaLibs = anaLibs.Strip();
931 Printf("anaLibs %s",anaLibs.Data());
932 Printf("anaLibsExtra %s",anaLibsExtra.Data());
934 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs.Data());
935 if (anaLibsExtra.Length()) plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
937 TString ana_sources = "";
938 TString ana_add = "";
939 if (kUsePAR && anaPars.Length()) {
940 printf("%s\n", anaPars.Data());
943 arr = anaPars.Tokenize(" ");
945 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
949 // Declare the analysis source files names separated by blancs. To be compiled runtime
950 // using ACLiC on the worker nodes.
951 ana_sources = anaSources.Strip();
952 // Declare all libraries (other than the default ones for the framework. These will be
953 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
955 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
956 plugin->SetExecutableCommand(kPluginExecutableCommand.Data());
957 // Declare the output file names separated by blancs.
958 // (can be like: file.root or file.root@ALICE::Niham::File)
959 plugin->SetUseSubmitPolicy(kFALSE);
960 plugin->SetMergeExcludes(kGridMergeExclude);
961 plugin->SetMaxMergeFiles(kGridMaxMergeFiles);
962 plugin->SetMaxMergeStages(kGridMaxMergeStages);
963 plugin->SetNrunsPerMaster(kGridRunsPerMaster);
964 plugin->SetMergeViaJDL(kPluginMergeViaJDL);
965 // Use fastread option
966 plugin->SetFastReadOption(kPluginFastReadOption);
968 plugin->SetOverwriteMode(kPluginOverwriteMode);
969 // Optionally define the files to be archived.
970 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
971 plugin->SetOutputToRunNo(kPluginOutputToRunNumber); // write the output to subdirs named after run number
972 // plugin->SetDefaultOutputs(kFALSE);
974 // Put default output files to archive
975 TString listhists = "";
976 TString listaods = "";
977 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
978 TIter next(mgr->GetOutputs());
979 AliAnalysisDataContainer *output;
980 while ((output=(AliAnalysisDataContainer*)next())) {
981 const char *filename = output->GetFileName();
982 if (!(strcmp(filename, "default"))) {
983 if (!mgr->GetOutputEventHandler()) continue;
984 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
985 if (listaods.Length()) listaods += " ";
986 listaods += filename;
988 if(!listhists.Contains(filename)){
989 if (listhists.Length()) listhists += " ";
990 listhists += filename;
995 if (mgr->GetExtraFiles().Length()) {
996 if (listaods.Length()) listaods += " ";
997 listaods += mgr->GetExtraFiles();
1000 TString outputArchive;
1001 outputArchive = Form("log_archive.zip:std*r@%s",kGridOutputStorages.Data());
1002 listaods.ReplaceAll(" ", ",");
1003 listhists.ReplaceAll(" ", ",");
1004 if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), kGridOutputStorages.Data());
1005 if (listaods.Length()) listaods = Form("aod_archive.zip:%s@%s", listaods.Data(), kGridOutputStorages.Data());
1007 if (!listhists.Length() && !listaods.Length()) {
1008 ::Fatal("AnalysisTrainHMPID", "No task output !");
1011 if (listaods.Length()) {
1012 outputArchive += " ";
1013 outputArchive += listaods;
1015 if (listhists.Length()) {
1016 outputArchive += " ";
1017 outputArchive += listhists;
1019 // plugin->SetOutputArchive(outputArchive);
1021 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
1022 plugin->SetAnalysisMacro(Form("%s.C", kTrainName.Data()));
1023 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
1024 plugin->SetSplitMaxInputFileNumber(kGridFilesPerJob);
1025 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1026 // plugin->SetMaxInitFailed(5);
1027 // Optionally resubmit threshold.
1028 // plugin->SetMasterResubmitThreshold(90);
1029 // Optionally set time to live (default 30000 sec)
1030 plugin->SetTTL(30000);
1031 // Optionally set input format (default xml-single)
1032 plugin->SetInputFormat("xml-single");
1033 // Optionally modify the name of the generated JDL (default analysis.jdl)
1034 plugin->SetJDLName(Form("%s.jdl", kTrainName.Data()));
1035 // Optionally modify the executable name (default analysis.sh)
1036 plugin->SetExecutable(Form("%s.sh", kTrainName.Data()));
1037 // Optionally modify job price (default 1)
1038 plugin->SetPrice(1);
1039 // Optionally modify split mode (default 'se')
1040 plugin->SetSplitMode("se");
1041 plugin->SetCheckCopy(kFALSE);
1045 //______________________________________________________________________________
1046 Bool_t LoadConfig(const char *filename)
1048 // Read train configuration from file
1049 if (gSystem->AccessPathName(filename)) {
1050 ::Error("AnalysisTrainHMPID.C::LoadConfig", "Config file name not found");
1053 gROOT->ProcessLine(Form(".x %s", filename));
1054 ::Info("AnalysisTrainHMPID.C::LoadConfig", "Train configuration loaded from file %s", filename);
1058 //______________________________________________________________________________
1060 Printf(">>> Patching JDL");
1061 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1062 AliAnalysisAlien* gridHandler = (AliAnalysisAlien*)mgr->GetGridHandler();
1063 TGridJDL *jdl = gridHandler->GetGridJDL();
1064 if(iJETAN)jdl->AddToPackages("fastjet","v2.4.0");
1065 gridHandler->WriteJDL(kFALSE);
1066 Printf("<<< Patching JDL");
1070 //______________________________________________________________________________
1071 Bool_t PatchAnalysisMacro(){
1072 Printf(">>> Patching AnalysisMacro");
1073 gSystem->Exec(Form("mv %s.C %s.C_tmp",kTrainName.Data(),kTrainName.Data()));
1076 in1.open(Form("%s.C_tmp", kTrainName.Data()));
1079 while(in1.getline(cLine,250)){
1084 index = st.Index("gSystem->Load(\"libPhysics\");");
1085 index += strlen("gSystem->Load(\"libPhysics\");");
1089 arr = anaLibs.Tokenize(" ");
1092 add += "\n\n // added by CKB \n";
1093 while ((objstr=(TObjString*)next())){
1094 if(objstr->GetString().Contains("PWG3"))continue;
1095 if(objstr->GetString().EndsWith(".so"))add += Form("gSystem->Load(\"%s\");\n",objstr->GetString().Data());
1099 // add += Form("AliLog::SetGlobalLogLevel(%d);\n",AliLog::GetGlobalLogLevel());
1102 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1103 add += "\n\n // added by CKB \n";
1104 add += "\n gSystem->AddIncludePath(\"./\"); \n";
1105 if(gGrid && kPluginAliRootVersion.Length()==0){
1106 add += "\n // Dirty hack for TRD reference data \n";
1107 add += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1108 add += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1111 add += "// BKC \n\n";
1112 st.Insert(index,add.Data());
1114 if(kUseCPAR && kPluginAliRootVersion.Length()==0){
1115 index = st.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1116 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1117 st.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1121 out.open(Form("%s.C", kTrainName.Data()));
1126 Printf("<<< Patching AnalysisMacro");
1128 Printf(">>> Patching Merge Macro");
1129 gSystem->Exec(Form("mv %s_merge.C %s_merge.C_tmp",kTrainName.Data(),kTrainName.Data()));
1132 in2.open(Form("%s_merge.C_tmp", kTrainName.Data()));
1134 while(in2.getline(cLine,250)){
1138 index = st2.Index("gSystem->Load(\"libPhysics\");");
1139 index += strlen("gSystem->Load(\"libPhysics\");");
1141 add2 += "\n gSystem->AddIncludePath(\"./\"); \n";
1142 if(gGrid&&kPluginAliRootVersion.Length()==0){
1143 add2 += "\n // Dirty hack for TRD reference data \n";
1144 add2 += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1145 add2 += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1148 add2 += "// BKC \n\n";
1149 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1150 st2.Insert(index,add.Data());
1152 if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
1153 index = st2.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1154 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1155 st2.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1158 // do not exclude the extra files from merign, this is done explicitly in this train script
1159 index = st2.Index("mergeExcludes +="); // uncommen $ALICE_ROOT include for par files
1160 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1161 st2.Insert(index,"// CKB comment out, handled explicitly by the train macro \n //");
1165 out2.open(Form("%s_merge.C", kTrainName.Data()));
1169 out2 << st2 << endl;
1170 Printf("<<< Patching Merging Macro");