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
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
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
32 //== general process variables
\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
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
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
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
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
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
110 TString anaPars = "";
\r
111 TString anaLibs = "";
\r
112 TString anaLibsExtra = "";
\r
113 TString anaSources = "";
\r
114 // Function signatures
\r
115 class AliAnalysisAlien;
\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
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
124 if (strlen(config_file) && !LoadConfig(config_file)) return;
\r
126 if(iOffset)kProofOffset = iOffset;
\r
127 TString smode(analysis_mode);
\r
129 // Check compatibility of selected modules
\r
130 CheckModuleFlags(smode);
\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
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
156 // Load common libraries and set include path
\r
157 if (!LoadCommonLibraries(smode)) {
\r
158 ::Error("AnalysisTrain", "Could not load common libraries");
\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
172 // Load analysis specific libraries
\r
173 if (!LoadAnalysisLibraries(smode)) {
\r
174 ::Error("AnalysisTrain", "Could not load analysis libraries");
\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
185 // Monte Carlo handler
\r
187 AliMCEventHandler* mcHandler = new AliMCEventHandler();
\r
188 mgr->SetMCtruthEventHandler(mcHandler);
\r
189 mcHandler->SetReadTR(kUseTR);
\r
192 // AOD output container, created automatically when setting an AOD handler
\r
194 // AOD output handler
\r
195 AliAODHandler* aodHandler = new AliAODHandler();
\r
196 aodHandler->SetOutputFileName("AliAOD.root");
\r
197 aodHandler->SetFillAODforRun(kFillAOD);
\r
199 mgr->SetOutputEventHandler(aodHandler);
\r
200 AliAnalysisDataContainer *cout_aod = mgr->GetCommonOutputContainer();
\r
201 cout_aod->SetSpecialOutput();
\r
204 // Debugging if needed
\r
206 mgr->SetDebugLevel(3);
\r
209 mgr->RegisterExtraFile("syswatch.root");
\r
210 if(kGridMergeExclude.Length())kGridMergeExclude += " ";
\r
211 kGridMergeExclude += "syswatch.root";
\r
213 AliLog::SetGlobalLogLevel(AliLog::kError);
\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
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
231 // ESD filter task configuration.
\r
232 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
\r
233 AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kUseKinefilter,kUseMuonfilter);
\r
235 mgr->RegisterExtraFile("pyxsec_hists.root");
\r
236 if(kGridMergeExclude.Length())kGridMergeExclude += " ";
\r
237 kGridMergeExclude += "pyxsec_hists.root";
\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
249 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
\r
250 AliAnalysisTaskPIDResponse *taskPIDResponse = AddTaskPIDResponse();
\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
261 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
\r
262 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
\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
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
281 TFile::Cp(Form("file:%s.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
\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
290 TFile::Cp(Form("file:%s_merge.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
\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
300 StartAnalysis(smode, chain);
\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
307 if (!strcmp(plugin_mode, "offline") && smode=="GRID"){
\r
308 // Offline mode path files
\r
310 PatchAnalysisMacro();
\r
316 //______________________________________________________________________________
\r
317 void StartAnalysis(const char *mode, TChain *chain) {
\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
327 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Cannot create the chain");
\r
330 mgr->StartAnalysis(mode, chain);
\r
333 if (!kProofDataSet.Length()) {
\r
334 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "kProofDataSet is empty");
\r
337 mgr->StartAnalysis(mode, kProofDataSet, kProofEvents,kProofOffset);
\r
341 if (!mgr->GetGridHandler()) {
\r
342 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Grid plugin not initialized");
\r
345 mgr->StartAnalysis("grid");
\r
348 ::Error("AnalysisTrainHMPID.C::StartAnalysis", "Cannot create the chain");
\r
351 mgr->StartAnalysis(mode, chain);
\r
357 //______________________________________________________________________________
\r
358 void CheckModuleFlags(const char *mode) {
\r
359 // Checks selected modules and insure compatibility
\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
367 kPluginAliRootVersion = ""; // NO aliroot if we use CPAR
\r
372 ::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
\r
377 ::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
\r
378 kPluginUse = kFALSE;
\r
382 // switch off anthin related to MC
\r
390 if(kUseKinefilter)::Info("AnalysisTrainHMPID.C::CheckModuleFlags", "Kine Filter disabled in analysis without MC");
\r
391 kUseKinefilter = kFALSE;
\r
397 kUseKinefilter = kFALSE;
\r
398 kUseMuonfilter = kFALSE;
\r
401 iJETANLib = iJETAN && 1;
\r
402 if (iESDfilter) {iAODhandler=1;}
\r
403 if (kUseKinefilter && !kUseMC) kUseKinefilter = kFALSE;
\r
408 //______________________________________________________________________________
\r
409 Bool_t Connect(const char *mode) {
\r
410 // Connect <username> to the back-end system.
\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
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
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
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
435 if(kProofClearPackages)gProof->ClearPackages();
\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
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
450 ::Info("AnalysisTrainHMPID.C::Connect", "Connecting user <%s> to AliEn ...",
\r
452 TGrid::Connect("alien://");
\r
453 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
\r
456 ::Error("AnalysisTrainHMPID.C::Connect", "Unknown run mode: %s", mode);
\r
459 ::Info("AnalysisTrainHMPID.C::Connect","Connected in %s mode", mode);
\r
464 //______________________________________________________________________________
\r
465 Bool_t LoadCommonLibraries(const char *mode)
\r
467 // Load common analysis libraries.
\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
476 Bool_t success = kTRUE;
\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
483 // Load framework classes. Par option ignored here.
\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
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
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
513 success &= !gProof->EnablePackage(kProofAFversion);
\r
514 success &= LoadLibrary("CORRFW", mode);
\r
518 ::Error("AnalysisTrainHMPID.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
\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
526 ::Info("AnalysisTrainHMPID.C::LoadCommodLibraries", "Load common libraries: FAILED");
\r
533 //______________________________________________________________________________
\r
534 Bool_t LoadAnalysisLibraries(const char *mode)
\r
536 // Load common analysis libraries.
\r
537 Bool_t success = kTRUE;
\r
539 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
\r
540 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
\r
544 if (!LoadSource(Form("%s/AliHMPIDAnalysisTask.cxx",gSystem->ExpandPathName(".")), mode, kTRUE))return kFALSE;
\r
548 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
\r
551 ::Info("AnalysisTrainHMPID.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
\r
556 //______________________________________________________________________________
\r
557 Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
\r
559 // Load a module library in a given mode. Reports success.
\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
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
576 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not load library %s", module);
\r
579 if (rec) anaLibs += Form("%s.so ",mod.Data());
\r
580 if (rec) anaLibsExtra += Form("%s.so ",mod.Data());
\r
583 // Check if the library is already loaded
\r
584 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
\r
590 result = SetupPar(module);
\r
591 if (rec) anaPars += Form("%s.par ", module);
\r
593 result = gSystem->Load(Form("lib%s.so", module));
\r
594 if (rec) anaLibs += Form("lib%s.so ", module);
\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
602 result = gProof->UploadPackage(module);
\r
604 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
\r
606 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
\r
610 result = gProof->EnablePackage(module);
\r
616 ::Error("AnalysisTrainHMPID.C::LoadLibrary", "Could not load module %s", module);
\r
622 //______________________________________________________________________________
\r
623 Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
\r
625 // Load a module library in a given mode. Reports success.
\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
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
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
654 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
\r
657 result = gProof->Load(Form("%s.cxx++g",basename.Data()));
\r
660 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
\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
673 ::Error("AnalysisTrainHMPID.C::LoadSources", "Could not load source %s", source);
\r
679 //______________________________________________________________________________
\r
680 TChain *CreateChain(const char *mode, const char *plugin_mode)
\r
682 // Create the input chain
\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
691 if (!kLocalXMLDataset.Length()) {
\r
693 chain = new TChain("esdTree");
\r
696 in.open(kLocalDataList.Data());
\r
697 while (in.good()) {
\r
699 if (line.Length() == 0) continue;
\r
700 cout << " line = " << line << endl;
\r
701 chain->Add(line.Data());
\r
705 chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
\r
712 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
\r
713 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
\r
715 TString treeName = "esdTree";
\r
716 chain = CreateChainSingle("wn.xml", treeName);
\r
721 if (chain && chain->GetNtrees()) return chain;
\r
725 //______________________________________________________________________________
\r
726 TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
\r
728 printf("*******************************\n");
\r
729 printf("*** Getting the ESD Chain ***\n");
\r
730 printf("*******************************\n");
\r
731 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
\r
733 if (!myCollection) {
\r
734 ::Error("AnalysisTrainHMPID.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
\r
738 TChain* chain = new TChain(treeName);
\r
739 myCollection->Reset() ;
\r
740 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
\r
745 //______________________________________________________________________________
\r
746 Int_t SetupPar(char* pararchivename)
\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
756 ::Error("AnalysisTrainHMPID.C::SetupPar", "Cannot find %s.par", pararchivename);
\r
760 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
\r
762 TString ocwd = gSystem->WorkingDirectory();
\r
763 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
\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
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
783 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
\r
787 //______________________________________________________________________________
\r
788 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
\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
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
816 if(kGridLocalRunList.Length()>0){
\r
818 in1.open(kGridLocalRunList.Data());
\r
820 // just use run numbers, negatives will be excluded
\r
823 Printf("AnalysisTrainHMPID Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
\r
824 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
\r
826 Printf("AnalysisTrainHMPID Skipping run number from File %d", iRun);
\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
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
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
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
854 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs.Data());
\r
855 if (anaLibsExtra.Length()) plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
\r
857 TString ana_sources = "";
\r
858 TString ana_add = "";
\r
859 if (kUsePAR && anaPars.Length()) {
\r
860 printf("%s\n", anaPars.Data());
\r
862 TObjString *objstr;
\r
863 arr = anaPars.Tokenize(" ");
\r
865 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
\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
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
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
907 if(!listhists.Contains(filename)){
\r
908 if (listhists.Length()) listhists += " ";
\r
909 listhists += filename;
\r
914 if (mgr->GetExtraFiles().Length()) {
\r
915 if (listaods.Length()) listaods += " ";
\r
916 listaods += mgr->GetExtraFiles();
\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
926 if (!listhists.Length() && !listaods.Length()) {
\r
927 ::Fatal("AnalysisTrainHMPID", "No task output !");
\r
930 if (listaods.Length()) {
\r
931 outputArchive += " ";
\r
932 outputArchive += listaods;
\r
934 if (listhists.Length()) {
\r
935 outputArchive += " ";
\r
936 outputArchive += listhists;
\r
938 // plugin->SetOutputArchive(outputArchive);
\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
964 //______________________________________________________________________________
\r
965 Bool_t LoadConfig(const char *filename)
\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
972 gROOT->ProcessLine(Form(".x %s", filename));
\r
973 ::Info("AnalysisTrainHMPID.C::LoadConfig", "Train configuration loaded from file %s", filename);
\r
977 //______________________________________________________________________________
\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
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
995 in1.open(Form("%s.C_tmp", kTrainName.Data()));
\r
998 while(in1.getline(cLine,250)){
\r
1003 index = st.Index("gSystem->Load(\"libPhysics\");");
\r
1004 index += strlen("gSystem->Load(\"libPhysics\");");
\r
1007 TObjString *objstr;
\r
1008 arr = anaLibs.Tokenize(" ");
\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
1018 // add += Form("AliLog::SetGlobalLogLevel(%d);\n",AliLog::GetGlobalLogLevel());
\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
1030 add += "// BKC \n\n";
\r
1031 st.Insert(index,add.Data());
\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
1040 out.open(Form("%s.C", kTrainName.Data()));
\r
1044 out << st << endl;
\r
1045 Printf("<<< Patching AnalysisMacro");
\r
1047 Printf(">>> Patching Merge Macro");
\r
1048 gSystem->Exec(Form("mv %s_merge.C %s_merge.C_tmp",kTrainName.Data(),kTrainName.Data()));
\r
1051 in2.open(Form("%s_merge.C_tmp", kTrainName.Data()));
\r
1053 while(in2.getline(cLine,250)){
\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
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
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
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
1084 out2.open(Form("%s_merge.C", kTrainName.Data()));
\r
1088 out2 << st2 << endl;
\r
1089 Printf("<<< Patching Merging Macro");
\r