Improved handling of delta AOD output, (patch merging macro), corrected loading seque...
[u/mrichter/AliRoot.git] / PWG4 / macros / AnalysisTrainPWG4Jets.C
CommitLineData
c38e3b95 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 AnalysisTrain.C
5// Grid full mode as below (other modes: test, offline, submit, terminate)
121e4bd5 6// root[1] AnalysisTrainPWG-244Jets("grid", "full")
c38e3b95 7// CAF mode (requires root v5-23-02 + aliroot v4-16-Rev08)
8// root[2] AnalysisTrainPWG4Jets("proof")
9// Local mode requires AliESds.root or AliAOD.root in ./data directory
10// root[3] AnalysisTrainPWG4Jets("local")
11// In proof and grid modes, a token is needed and sourcing the produced environment file.
12//
13// If 'saveTrain' flag is set, the train will generate a directory name and run
14// in this directory. A configuration file 'ConfigTrain.C' will be generated.
15// One can replay at any time the train via:
16// root[1] AnalysisTrainPWG4Jets(ana_mode, plugin_mode, "train_default_<date>/ConfigTrain.C")
17
18// For Usage with fastjet run in "offline" first and then "submit"
19// jdl and analysismacro are automatically patched after "offline" mode
20
21// =============================================================================
22// ### General Steering variables
23// =============================================================================
24//== general setup variables
25TString kTrainName = "testAnalysis"; // *CHANGE ME* (no blancs or special characters)
26TString kJobTag = "PWG4 Jet Tasks analysis train configured"; // *CHANGE ME*
27
28// Usage of par files ONLY in grid mode and ONLY if the code is not available
29// in the deployed AliRoot versions. Par file search path: local dir, if not there $ALICE_ROOT.
30// To refresh par files, remove the ones in the workdir, then do "make <target.par>" in
31// AliRoot.
32Bool_t kUsePAR = kFALSE; // use par files for extra libs
33Bool_t kUseCPAR = kFALSE; // use par files for common libs
34Bool_t kFillAOD = kFALSE; // switch of AOD filling for on the fly analysis
4721d8c5 35Int_t kSaveAOD = 8; // Bit switch 1 = Full AOD 2 = Jet AOD , 4 = PartCorr, 8 = JCORRAN
c38e3b95 36//== general input and output variables
9a5c5b1e 37
c38e3b95 38Int_t iAODanalysis = 1; // Analysis on input AOD's
39Int_t iAODhandler = 1; // Analysis produces an AOD or dAOD's
40Int_t iESDfilter = 0; // ESD to AOD filter (barrel + muon tracks)
e84da0a5 41Int_t iPhysicsSelection = 1; // ESD to AOD filter (barrel + muon tracks)
c38e3b95 42Bool_t kUseKinefilter = kFALSE; // use Kinematics filter
43Bool_t kUseMuonfilter = kFALSE; // use Kinematics filter
44TString kCommonOutputFileName = "PWG4_JetTasksOutput.root";
45
46
47//== general process variables
48
49// ### Other flags to steer the analysis
50//==============================================================================
9a5c5b1e 51Bool_t kSkipTerminate = kTRUE; // Do not call Teminate
c38e3b95 52Bool_t kUseDate = kFALSE; // use date in train name
53Bool_t kUseDebug = kTRUE; // activate debugging
c28abe00 54Int_t kUseSysInfo = 0; // activate debugging
82ebd295 55Long_t kNumberOfEvents = 1234567890; // number of events to process from the chain
c38e3b95 56Bool_t kUseMC = kTRUE; // use MC info
57Bool_t kIsMC = kTRUE; // is MC info, if false it overwrites Use(AOD)MC
58Bool_t kUseAODMC = kTRUE; // use MC infA
59Bool_t kUseESDTags = kFALSE; // use ESD tags for selection
60Bool_t kUseTR = kFALSE; // use track references
61Bool_t kUseAODTags = kFALSE; // use AOD tags
62Bool_t kSaveTrain = kFALSE; // save train configuration as:
63
9a5c5b1e 64
c38e3b95 65// ### Analysis modules to be included. Some may not be yet fully implemented.
66//==============================================================================
67Int_t iJETAN = 1; // Jet analysis (PWG4) // 1 write standard 2 write non-standard jets, 3 wrtie both
68Int_t iDIJETAN = 1;
e6993a52 69Int_t iJETANLib = 1;
c38e3b95 70Int_t iPWG1QASym = 0; // Eva's QA task compiled on the fly...
71Int_t iPWG4JetTasks = 0; // all jet tasks flag for lib laoding
72Int_t iPWG4JetServices = 0; // jet spectrum analysis
73Int_t iPWG4JetSpectrum = 0; // jet spectrum analysis
58ef946c 74Int_t iPWG4JCORRAN = 0; // JCORRAN module
c38e3b95 75Int_t iPWG4UE = 0; // Underlying Event analysis
c166d299 76Int_t iPWG4TmpSourceSara = 0; // Underlying Event analysis not in svn
77Int_t iPWG4TmpSourceFrag = 0; // Bastian's Fragmentation function not in svn
9f77f0ce 78Int_t iPWG4JetChem = 0; // Jet chemistry
c38e3b95 79Int_t iPWG4PtQAMC = 0; // Marta's QA tasks
80Int_t iPWG4PtSpectra = 0; // Marta's QA tasks
81Int_t iPWG4PtQATPC = 0; // Marta's QA tasks
4721d8c5 82Int_t iPWG4Cosmics = 0; // Marta's Cosmics Taks
c38e3b95 83Int_t iPWG4ThreeJets = 0; // Sona's thrust task
b53f2e4f 84Int_t iPWG4KMeans = 0; // Andreas' KMeans task
d2e6cdd5 85Int_t iPWG4Cluster = 0; // CKB cluster task
4721d8c5 86Int_t iEMCUtilLibs = 0; // Flag to satisfy dependence on EMC utils
911a740f 87Int_t iPWG4PartCorrLibs = 0; // Gustavo's part corr analysis
c38e3b95 88Int_t iPWG4PartCorr = 0; // Gustavo's part corr analysis
d2e6cdd5 89Int_t iPWG4CaloQA = 0; // Gustavo's part corr analysis
90Int_t iPWG4JetCorr = 0; // Paul's jet corr analysis
911a740f 91Int_t iPWG4Tagged = 0; // Gustavo's part corr analysis
121e4bd5 92Int_t iPWG4omega3pi = 0; // Omega to 3 pi analysis (PWG4)
53c63663 93Int_t iPWG4GammaConv = 0; // Gamma Conversio
c38e3b95 94Int_t kHighPtFilterMask = 16; // change depending on the used AOD Filter
e6993a52 95TString kDeltaAODJetName = "AliAOD.Jets.root";
4721d8c5 96TString kDeltaAODJCORRANName = "AliAOD.JCORRAN.root";
53c63663 97TString kDeltaAODPartCorrName = "deltaAODPartCorr.root";
c38e3b95 98
99
100//==============================================================================
101// ### PROOF Steering varibales
102//==============================================================================
103//== proof setup variables
104TString kProofCluster = "alicecaf.cern.ch";
105Bool_t kProofUseAFPAR = kFALSE; // use AF special par file
106TString kProofAFversion = "AF-v4-17";
107//== proof input and output variables
108TString kProofDataSet = "/COMMON/COMMON/LHC09a4_run8100X#/esdTree";
109Bool_t kProofSaveToAlien = kFALSE; // save proof outputs in AliEn train_[trainName]_ddMonthyyyy_time.C
110TString kProofOutdir = "";
111Bool_t kProofClearPackages = kFALSE;
112Int_t kProofEvents = 10000;
113Int_t kProofOffset = 0;
114//== proof process variables
115
116
117//==============================================================================
118// ### Grid plugin Steering varibiables
119//==============================================================================
120//== grid plugin setup variables
121Bool_t kPluginUse = kTRUE; // do not change
122Bool_t kPluginUseProductionMode = kFALSE; // use the plugin in production mode
d3af0232 123TString kPluginRootVersion = "v5-26-00b-7"; // *CHANGE ME IF MORE RECENT IN GRID*
124TString kPluginAliRootVersion = "v4-19-15-AN"; // *CHANGE ME IF MORE RECENT IN GRID*
9a5c5b1e 125Bool_t kPluginMergeViaJDL = kTRUE; // merge via JDL
126Bool_t kPluginFastReadOption = kFALSE; // use xrootd tweaks
127Bool_t kPluginOverwriteMode = kTRUE; // overwrite existing collections
dc6a7461 128Int_t kPluginOutputToRunNumber = 1; // write the output to subdirs named after run number
c38e3b95 129// TString kPluginExecutableCommand = "root -b -q";
130TString kPluginExecutableCommand = "source /Users/kleinb/setup_32bit_aliroot_trunk_clean_root_trunk.sh; alienroot -b -q ";
9a5c5b1e 131
c38e3b95 132// == grid plugin input and output variables
133TString kGridDatadir = "/alice/sim/PDC_08b/LHC09a1/AOD/";
134TString kGridLocalRunList = "";
135TString kGridOutdir = ""; // AliEn output directory. If blank will become output_<kTrainName>
3878a941 136TString kGridDataSet = ""; // sub working directory not to confuse different run xmls
c38e3b95 137Int_t kGridRunRange[2] = {0, -1}; // Set the run range
138TString kGridRunPattern = "%03d"; // important for leading zeroes!!
139TString kGridPassPattern = "";
140TString kGridExtraFiles = ""; // files that will be added to the input list in the JDL...
4721d8c5 141Int_t kGridMaxMergeFiles = 12; // Number of files merged in a chunk grid run range
c38e3b95 142TString kGridMergeExclude = "AliAOD.root"; // Files that should not be merged
6408fe42 143TString kGridOutputStorages = "disk=2"; // Make replicas on the storages
c38e3b95 144// == grid process variables
c28abe00 145Int_t kGridRunsPerMaster = 100; // Number of runs per master job
e84da0a5 146Int_t kGridFilesPerJob = 100; // Maximum number of files per job (gives size of AOD)
c38e3b95 147
148//==============================================================================
149// ### Local Steering variables
150//==============================================================================
151//== local setup variables
152//== local input and output variables
153TString kLocalXMLDataset = ""; // Change local xml dataset for local interactive analysis
154TString kLocalDataList = "local_deltaaod.txt"; // Change local xml dataset for local interactive analysis
155// == local process variables
156
157
158
159// Temporaries.
160TString anaPars = "";
161TString anaLibs = "";
e84da0a5 162TString anaLibsExtra = "";
c38e3b95 163TString anaSources = "";
164// Function signatures
165class AliAnalysisAlien;
166
167//______________________________________________________________________________
168void AnalysisTrainPWG4Jets(const char *analysis_mode="local",
169 const char *plugin_mode="",
170 const char *config_file="",Int_t iOffset = 0)
171{
172// Main analysis train macro. If a configuration file is provided, all parameters
173// are taken from there but may be altered by CheckModuleFlags.
3878a941 174
c38e3b95 175 if (strlen(config_file) && !LoadConfig(config_file)) return;
3878a941 176
c38e3b95 177 if(iOffset)kProofOffset = iOffset;
178 TString smode(analysis_mode);
179 smode.ToUpper();
180 if (kSaveTrain)WriteConfig();
181 // Check compatibility of selected modules
182 CheckModuleFlags(smode);
e84da0a5 183 // gROOT->ProcessLine(".trace");
c38e3b95 184
185 printf("==================================================================\n");
186 printf("=========== RUNNING ANALYSIS TRAIN %s IN %s MODE ==========\n", kTrainName.Data(),smode.Data());
187 printf("==================================================================\n");
188 printf("= Configuring analysis train for: =\n");
189 if (iAODanalysis) printf("= AOD analysis =\n");
190 else printf("= ESD analysis =\n");
e84da0a5 191 if (iPhysicsSelection) printf("= Physics selection =\n");
c38e3b95 192 if (iESDfilter) printf("= ESD filter =\n");
193 if (iJETAN) printf("= Jet analysis =\n");
194 printf("==================================================================\n");
d2e6cdd5 195 printf(":: use Fill AOD %d\n", (UInt_t)kFillAOD);
4721d8c5 196 printf(":: use Save AOD %d\n", (UInt_t)kSaveAOD);
c38e3b95 197 printf(":: use MC truth %d\n", (UInt_t)kUseMC);
198 printf(":: use KINE filter %d\n", (UInt_t)kUseKinefilter);
199 printf(":: use track refs %d\n", (UInt_t)kUseTR);
200 printf(":: use tags %d\n", (UInt_t)kUseESDTags);
201 printf(":: use AOD tags %d\n", (UInt_t)kUseAODTags);
202 printf(":: use debugging %d\n", (UInt_t)kUseDebug);
203 printf(":: use PAR files %d\n", (UInt_t)kUsePAR);
204 printf(":: use AliEn plugin %d\n", (UInt_t)kPluginUse);
4d62ae1a 205 printf(":: use PWG1 QA sym %d\n", iPWG1QASym);
206 printf(":: use PWG4 Source Sara %d\n",iPWG4TmpSourceSara);
207 printf(":: use PWG4 Source BB %d\n",iPWG4TmpSourceFrag);
208 printf(":: use PWG4 Jet Chem %d\n",iPWG4JetChem);
209 printf(":: use PWG4 Jet tasks %d\n",iPWG4JetTasks);
210 printf(":: use PWG4 Jet Services %d\n",iPWG4JetServices);
211 printf(":: use PWG4 Jet Spectrum %d\n",iPWG4JetSpectrum);
212 printf(":: use PWG4 JCORRAN %d\n",iPWG4JCORRAN);
213 printf(":: use PWG4 UE %d \n",iPWG4UE);
214 printf(":: use PWG4 Pt QA MC %d\n",iPWG4PtQAMC);
215 printf(":: use PWG4 Pt Spectra %d\n",iPWG4PtSpectra);
216 printf(":: use PWG4 Pt QA TPC %d\n",iPWG4PtQATPC);
1f329128 217 printf(":: use PWG4 Cosmics %d\n",iPWG4Cosmics);
4d62ae1a 218 printf(":: use PWG4 Three Jets %d\n",iPWG4ThreeJets);
219 printf(":: use PWG4 KMeans %d\n",iPWG4KMeans);
220 printf(":: use PWG4 Cluster %d\n",iPWG4Cluster);
221 printf(":: use PWG4 Part Corr %d\n",iPWG4PartCorr);
222 printf(":: use PWG4 Calo QA %d\n",iPWG4CaloQA);
223 printf(":: use PWG4 Jet Corr %d\n",iPWG4JetCorr);
4721d8c5 224 printf(":: use PWG4 JCORRAN %d\n",iPWG4JCORRAN);
4d62ae1a 225 printf(":: use PWG4 Tagged %d\n",iPWG4Tagged);
226 printf(":: use PWG4 omega to 3 pi %d\n",iPWG4omega3pi);
227 printf(":: use PWG4 Gamma Conv %d\n",iPWG4GammaConv);
228 printf(":: use HighPt FilterMask %d\n",kHighPtFilterMask);
3878a941 229
c38e3b95 230 //==========================================================================
231 // Connect to back-end system
232 if (!Connect(smode)) {
233 ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode);
234 return;
235 }
236
237 // Load common libraries and set include path
238 if (!LoadCommonLibraries(smode)) {
239 ::Error("AnalysisTrain", "Could not load common libraries");
240 return;
241 }
3878a941 242
243
c38e3b95 244
245 // Make the analysis manager and connect event handlers
e84da0a5 246 AliAnalysisManager *mgr = new AliAnalysisManager("PWG4Train", "pwg4 mini train");
c38e3b95 247 if (kCommonOutputFileName.Length()>0)mgr->SetCommonFileName(kCommonOutputFileName.Data());
248 if (kProofSaveToAlien) mgr->SetSpecialOutputLocation(kProofOutdir);
4a6f59cb 249 mgr->SetNSysInfo(0);
c38e3b95 250 if (!strcmp(plugin_mode, "test")) mgr->SetNSysInfo(1);
53c63663 251 if (kUseSysInfo)mgr->SetNSysInfo(kUseSysInfo);
9a5c5b1e 252 mgr->SetSkipTerminate(kSkipTerminate);
4a6f59cb 253
c38e3b95 254 // Load analysis specific libraries
255 if (!LoadAnalysisLibraries(smode)) {
256 ::Error("AnalysisTrain", "Could not load analysis libraries");
257 return;
258 }
259
260 // Create input handler (input container created automatically)
261 if (iAODanalysis) {
262 // AOD input handler
263 AliAODInputHandler *aodH = new AliAODInputHandler();
264 mgr->SetInputEventHandler(aodH);
e6993a52 265 if (iPWG4JetTasks) aodH->AddFriend(Form("deltas/%s",kDeltaAODJetName.Data()));
266 if (iPWG4PartCorr) aodH->AddFriend(Form("deltas/%s"kDeltaAODJetName.Data()));
c38e3b95 267 } else {
268 // ESD input handler
269 AliESDInputHandler *esdHandler = new AliESDInputHandler();
270 if (kUseESDTags) esdHandler->SetReadTags();
c166d299 271 esdHandler->SetReadFriends(kFALSE);
c38e3b95 272 mgr->SetInputEventHandler(esdHandler);
4a6f59cb 273 // if(iPWG4PtQATPC&& !kTrainName.Contains("pass5"))esdHandler->SetActiveBranches("ESDfriend");
c166d299 274
c38e3b95 275 }
f4d11ac8 276
c38e3b95 277 // Monte Carlo handler
278 if (kUseMC && !iAODanalysis) {
279 AliMCEventHandler* mcHandler = new AliMCEventHandler();
280 mgr->SetMCtruthEventHandler(mcHandler);
281 mcHandler->SetReadTR(kUseTR);
282 }
283 // AOD output container, created automatically when setting an AOD handler
284 if (iAODhandler) {
285 // AOD output handler
286 AliAODHandler* aodHandler = new AliAODHandler();
287 aodHandler->SetOutputFileName("AliAOD.root");
6408fe42 288 aodHandler->SetFillAODforRun(kFillAOD);
c38e3b95 289
290 mgr->SetOutputEventHandler(aodHandler);
121e4bd5 291 //
c38e3b95 292 if (iAODanalysis) {
293
294 // aodHandler->SetCreateNonStandardAOD();
295 // if (iJETAN)aodHandler->SetOutputFileName(kDeltaAODJetName.Data());
296 }
297 AliAnalysisDataContainer * cout_aod = mgr->GetCommonOutputContainer();
298 cout_aod->SetSpecialOutput();
299 }
300 // Debugging if needed
b03b08a3 301
3878a941 302 if (kUseDebug){
303 mgr->SetDebugLevel(3);
304 }
4721d8c5 305 if(kUseSysInfo>0){
306 mgr->RegisterExtraFile("syswatch.root");
307 if(kGridMergeExclude.Length())kGridMergeExclude += " ";
308 kGridMergeExclude += "syswatch.root";
309 }
310
b03b08a3 311 else{
312 AliLog::SetGlobalLogLevel(AliLog::kError);
313 }
c38e3b95 314 //==========================================================================
315 // Create the chain. In this example it is created only from ALIEN files but
316 // can be done to work in batch or grid mode as well.
317 TChain *chain = CreateChain(smode, plugin_mode);
318
319 //==========================================================================
320 // Load the tasks configuration macros for all wagons. These files are supposed now to be
321 // in the current workdir, but in AliEn they will be in the file catalog,
322 // mapped from AliRoot and pecified in the jdl input list.
323
324 // For now connection to top input container and common AOD output container
325 // is done in this macro, but in future these containers will be connected
326 // from each task configuration macro.
e84da0a5 327 if(iPhysicsSelection && !iAODanalysis){
d2e6cdd5 328 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
d8f81b37 329 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kIsMC,kTRUE,kTRUE); // last flag also adds information on
e84da0a5 330 }
331
c38e3b95 332 if (iESDfilter && !iAODanalysis) {
333 // ESD filter task configuration.
334 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
335 AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kUseKinefilter,kUseMuonfilter);
4721d8c5 336 if(kIsMC){
337 mgr->RegisterExtraFile("pyxsec_hists.root");
338 if(kGridMergeExclude.Length())kGridMergeExclude += " ";
339 kGridMergeExclude += "pyxsec_hists.root";
340
341 }
c38e3b95 342 }
343
344 // AOD tags
345 if (kUseAODTags) {
346 AliAnalysisTaskTagCreator* tagTask = new AliAnalysisTaskTagCreator("AOD Tag Creator");
347 mgr->AddTask(tagTask);
348 AliAnalysisDataContainer *coutTags = mgr->CreateContainer("cTag", TTree::Class(),
349 AliAnalysisManager::kOutputContainer, "AOD.tag.root");
350 mgr->ConnectInput (tagTask, 0, mgr->GetCommonInputContainer());
351 mgr->ConnectOutput(tagTask, 1, coutTags);
352 }
353
354 // Jet analysis
355 if (iJETAN) {
356 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
357 AliAnalysisTaskJets *taskjets = 0;
358 if(iJETAN&1)taskjets = AddTaskJets(kHighPtFilterMask);
b53f2e4f 359 if(iJETAN&2){
360 UInt_t selection = 0;
d2e6cdd5 361 if(!kFillAOD) selection = 0xffffff; //&~(1<<13);
58ef946c 362 else selection = 0xffffff&~(1<<13);// selection = 1<<0|1<<1|1<<2|1<<5|1<<6|1<<7|1<<8|1<<9|1<<10|1<<11|1<<12;
b53f2e4f 363 AddTaskJetsDelta(kDeltaAODJetName.Data(),kHighPtFilterMask,kUseAODMC,selection);
364 }
c38e3b95 365 if (!taskjets) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
366 }
367
368 if (iDIJETAN) {
369 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskDiJets.C");
370 AliAnalysisTaskDiJets *taskdijets = 0;
82ebd295 371 if(iDIJETAN&1)taskdijets = AddTaskDiJets();
c38e3b95 372 if (!taskdijets) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
82ebd295 373 if(iDIJETAN&2){
374 taskdijets = AddTaskDiJets("jetsAOD_CDF07");
375 taskdijets = AddTaskDiJets("jetsAOD_DA07");
376 taskdijets = AddTaskDiJets("jetsAOD_FASTJET07");
377 taskdijets = AddTaskDiJets("jetsAOD_FASTKT07");
378 taskdijets = AddTaskDiJets("jetsAOD_SISCONE07");
379 taskdijets = AddTaskDiJets("jetsAOD_UA107");
380 }
c38e3b95 381 }
382
c38e3b95 383 if(iPWG1QASym){
5dbdc61f 384 gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskQAsym.C");
c38e3b95 385 AliAnalysisTaskQASym *taskQASym = AddTaskQAsym(-1);
386 if (!taskQASym) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQASym cannot run for this train conditions - EXCLUDED");
121e4bd5 387 }
c38e3b95 388
121e4bd5 389
390
391 if(iPWG4TmpSourceSara){
392 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskEta.C");
393 AliAnalysisTaskEta *taskEta = AddTaskEta();
394 if (!taskEta) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskEta cannot run for this train conditions - EXCLUDED");
c38e3b95 395 }
396
c166d299 397 if(iPWG4TmpSourceFrag){
398 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskFragFunc.C");
399 UInt_t selection = 1<<2;
400 AliAnalysisTaskFragFunc *taskFrag = AddTaskFragFunc(kHighPtFilterMask, kUseAODMC,iPhysicsSelection, selection);
401 if (!taskFrag) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskFragFunc cannot run for this train conditions - EXCLUDED");
402 }
403
c580ebbb 404
9f77f0ce 405 if(iPWG4JetChem){
406 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetChem.C");
407 AliAnalysisTask *taskChem = AddTaskJetChem();
c580ebbb 408 if (!taskChem) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetChem cannot run for this train conditions - EXCLUDED");
409 }
410
411
c38e3b95 412 if(iPWG4JetServices){
413 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetServices.C");
414 AliAnalysisTaskJetServices *taskjetServ = 0;
415 taskjetServ = AddTaskJetServices();
416 if (!taskjetServ) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetServices cannot run for this train conditions - EXCLUDED");
53c63663 417 if(kGridRunRange[0]>0)taskjetServ->SetRunRange(kGridRunRange[0],kGridRunRange[1]);
0971dabc 418 else taskjetServ->SetRunRange(104000,125000);
c28abe00 419 if(!kIsMC) taskjetServ->SetRealData(kTRUE);
dc6a7461 420 taskjetServ->SetUsePhysicsSelection((Bool_t)iPhysicsSelection);
9f77f0ce 421 taskjetServ->SetDebugLevel(0);
c38e3b95 422 }
423
c38e3b95 424 if(iPWG4JetSpectrum){
425 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetSpectrum2.C");
426 AliAnalysisTaskJetSpectrum2 *taskjetSpectrum = 0;
b53f2e4f 427 if(iPWG4JetSpectrum&1){
428 taskjetSpectrum = AddTaskJetSpectrum2("jets","",kHighPtFilterMask,iPhysicsSelection);
e6993a52 429 if(!iAODanalysis){
d3af0232 430 // taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks32",32,iPhysicsSelection); // tmp hack to give it a different name
58ef946c 431 // taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks64",64,iPhysicsSelection);
e6993a52 432 }
d2e6cdd5 433 if (!taskjetSpectrum) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetSpectrum2 cannot run for this train conditions - EXCLUDED");
3878a941 434 taskjetSpectrum->SetDebugLevel(1);
b53f2e4f 435 }
d2e6cdd5 436
e6993a52 437 if(iPWG4JetSpectrum&2){
438 UInt_t selection = 0;
439 if(!iAODanalysis) selection = 0xffffff;
440 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
441 AddTaskJetSpectrum2Delta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,selection);
442 }
c38e3b95 443 }
58ef946c 444 if(iPWG4JCORRAN){
445 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJCORRANTask.C");
4721d8c5 446 AliJCORRANTask* corran = AddTaskJCORRAN(kDeltaAODJCORRANName.Data(),0);
58ef946c 447 if(!corran)::Warning("AnalysisTrainPWG4Jets", "AliJCORRANTask cannot run for this train conditions - EXCLUDED");
4721d8c5 448 else{
449 if(kDeltaAODJCORRANName.Length()>0)mgr->RegisterExtraFile(kDeltaAODJCORRANName.Data());
450 }
58ef946c 451 }
452
c38e3b95 453 if(iPWG4UE){
454 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskUE.C");
455 AliAnalysisTaskUE *taskUE = 0;
456 if(iPWG4UE&1)taskUE = AddTaskUE();
457 if(iPWG4UE&2){
94ee88d4 458 taskUE =AddTaskUE("jetsAOD_CDF04","CDF", "LJ", "TRANSV","MSP"); //finder not yet in train
459 taskUE =AddTaskUE("jetsAOD_CDF07","CDF", "LJ", "TRANSV","MSP");
460 taskUE =AddTaskUE("jetsAOD_SISCONE04","CDF", "LJ", "TRANSV","MSP");
461 taskUE =AddTaskUE("jetsAOD_SISCONE07","CDF", "LJ", "TRANSV","MSP"); //finder not yet in train
462 taskUE =AddTaskUE("jetsAOD_ICDF","CDF","LJ","TRANSV","MSP");
463 taskUE =AddTaskUE("jetsAOD_FASTKT04","CDF", "LJ", "TRANSV","MSP");
464 taskUE =AddTaskUE("jetsAOD_FASTKT07","CDF", "LJ", "TRANSV","MSP"); //finder not yet in train
58ef946c 465 taskUE =AddTaskUE("jetsAOD_NONE","CDF", "MP_eta05", "TRANSV","MSP");
466 taskUE =AddTaskUE("jetsAOD_NONE","CDF", "MP_eta09", "TRANSV","MSP");
c38e3b95 467 }
2bb1f4ca 468
c38e3b95 469 if (!taskUE) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskUE cannot run for this train conditions - EXCLUDED");
470 }
471
472 if(iPWG4ThreeJets){
473 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskThreeJets.C");
474 AliAnalysisTaskThreeJets *taskThree = AddTaskThreeJets();
475 if(!taskThree)::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskThreets cannot run for this train conditions - EXCLUDED");
476 }
c38e3b95 477 if(iPWG4PtQAMC){
478 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQAMC.C");
479 AliPWG4HighPtQAMC *taskQAMC = AddTaskPWG4HighPtQAMC();
480 if (!taskQAMC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQAMC cannot run for this train conditions - EXCLUDED");
481 }
482
483 if(iPWG4PtQATPC){
484 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQATPConly.C");
10295ac3 485 AliPWG4HighPtQATPConly *taskQATPC = 0;
486 if(iPWG4PtQATPC&1)taskQATPC = AddTaskPWG4HighPtQATPConly(1);
487 if(iPWG4PtQATPC&2)taskQATPC = AddTaskPWG4HighPtQATPConly(2);
488
489 if (!taskQATPC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQATPC cannot run for this train conditions - EXCLUDED");
c38e3b95 490 }
3878a941 491
1f329128 492 if(iPWG4Cosmics){
493 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4CosmicCandidates.C");
494
495 AliPWG4CosmicCandidates *taskPWG4CosmicCandidates = AddTaskPWG4CosmicCandidates(0);
496 taskPWG4CosmicCandidates = AddTaskPWG4CosmicCandidates(1);
497
498 if (!taskPWG4CosmicCandidates) ::Warning("AnalysisTrainPWG4Jets", "AddTaskPWG4CosmicCandidates cannot run for this train conditions - EXCLUDED");
499 }
500
501
c38e3b95 502 if(iPWG4PtSpectra){
503 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtSpectra.C");
504 AliPWG4HighPtSpectra *taskPtSpectra = AddTaskPWG4HighPtSpectra();
505 if (!taskPtSpectra) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskPtSpectra cannot run for this train conditions - EXCLUDED");
506 }
b53f2e4f 507 if(iPWG4KMeans){
508 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskKMeans.C");
509 AliAnalysisTaskKMeans *taskKMeans = AddTaskKMeans();
510 if (!taskKMeans) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskKMenans cannot run for this train conditions - EXCLUDED");
511 }
512
d2e6cdd5 513 if(iPWG4Cluster){
514 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetCluster.C");
515 AliAnalysisTaskJetCluster *taskCl = 0;
6408fe42 516 if(iPWG4Cluster&1){
517 taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelection,"KT");
6408fe42 518 }
d2e6cdd5 519 if(iPWG4Cluster&2){
520 UInt_t selection = 0;
521 if(!iAODanalysis) selection = 0xffffff;
522 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
6408fe42 523 AddTaskJetClusterDelta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,"KT",selection);
0971dabc 524 }
525 if(iPWG4Cluster&4){
526 UInt_t selection = 0;
527 if(!iAODanalysis) selection = 0xffffff;
528 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
58ef946c 529 taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelection,"ANTIKT");
530 AddTaskJetClusterDelta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,"ANTIKT",selection);
d2e6cdd5 531 }
0971dabc 532
533
d2e6cdd5 534 if (!taskCl) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskCluster cannot run for this train conditions - EXCLUDED");
535
536 }
c38e3b95 537 if(iPWG4PartCorr){
538 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
14526afb 539 AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS",kFALSE,kIsMC);
c38e3b95 540 if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
14526afb 541 AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL",kFALSE,kIsMC);
c38e3b95 542 if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
4721d8c5 543 if(kDeltaAODPartCorrName.Length()>0)mgr->RegisterExtraFile(kDeltaAODPartCorrName.Data());
121e4bd5 544 }
545
d2e6cdd5 546 if(iPWG4CaloQA){
547 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
f4d11ac8 548 AliAnalysisTaskParticleCorrelation *taskcaloQA = AddTaskCalorimeterQA("ESD",kFALSE,kIsMC);
d2e6cdd5 549 if(!taskcaloQA)::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation QA cannot run - EXCLUDED");
550 }
551
d2e6cdd5 552 if(iPWG4JetCorr){
553 // using namespace JetCorrelHD;
d3af0232 554 TString cdir = gSystem->WorkingDirectory();
555 gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
d2e6cdd5 556 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetCorrel.C");
557 AliAnalysisTaskJetCorrel *taskjetcorr = AddTaskJetCorrel();
d3af0232 558 gSystem->ChangeDirectory(cdir);
c166d299 559 if (!taskjetcorr) ::Warning("AnalysisTrainNew", "AliAnalysisTaskJetCorrel cannot run for this train conditions - EXCLUDED");
d2e6cdd5 560 }
561
911a740f 562 if(iPWG4Tagged){
563 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskTaggedPhotons.C");
564 AliAnalysisTaskTaggedPhotons * taskTagged = AddTaskTaggedPhotons(kFALSE); // EMCAL
58ef946c 565 taskTagged = AddTaskTaggedPhotons(kTRUE); // PHOS
911a740f 566 if (!taskTagged) ::Warning("AnalysisTrainNew", "AliAnalysisTaskTaggedPhotons cannot run for this train conditions - EXCLUDED");
567 }
121e4bd5 568 if (iPWG4omega3pi) {
569 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
570 AliAnalysisTaskOmegaPi0PiPi *taskomega3pi = AddTaskomega3pi();
571 if (!taskomega3pi) ::Warning("AnalysisTrainNew", "AliAnalysisTaskomega3pi cannot run\
572 for these train conditions - EXCLUDED");
573 }
574
53c63663 575 // PWG4 gamma conversion analysis
576 if (iPWG4GammaConv) {
577 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
578 TString cdir = gSystem->WorkingDirectory();
579 gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
580 // TString gcArguments = "-run-on-train -run-jet -run-chic -run-neutralmeson -run-cf";
58ef946c 581 // TString gcArguments = "-run-on-train -run-jet -run-neutralmeson -run-cf -use-own-xyz";
582 // TString gcArguments = "-run-on-train -run-jet -run-neutralmeson -run-cf -use-own-xyz";
82ebd295 583 TString gcArguments = "-run-on-train -run-jet -run-omega-meson -run-neutralmeson";
584 TString kGCAnalysisCutSelectionId="9002111000";
585 gcArguments.Append(Form("-set-cut-selection %s ",kGCAnalysisCutSelectionId.Data()));
53c63663 586 if(!kIsMC)gcArguments += " -mc-off";
587 AliAnalysisTaskGammaConversion * taskGammaConversion = AddTaskGammaConversion(gcArguments,mgr->GetCommonInputContainer());
588 gSystem->ChangeDirectory(cdir);
121e4bd5 589 taskGammaConversion->SelectCollisionCandidates();
53c63663 590 if (!taskGammaConversion) ::Warning("AnalysisTrainNew", "AliAnalysisTaskGammaConversion cannot run for these train conditions - EXCLUDED");
591 }
592
3878a941 593
c38e3b95 594 //==========================================================================
595 // FOR THE REST OF THE TASKS THE MACRO AddTaskXXX() is not yet implemented/
596 // Run the analysis
597 //
598 if (kPluginUse) {
599 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
600 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
601 }
602
603 if (mgr->InitAnalysis()) {
604 mgr->PrintStatus();
605 // if (kSaveTrain || strlen(config_file)) gSystem->ChangeDirectory(kTrainName);
e84da0a5 606 if (!strcmp(plugin_mode,"submit")&&smode=="GRID"){
c38e3b95 607 TString alien_workdir = gGrid->GetHomeDirectory();
608 if (iAODanalysis) alien_workdir += "analysisAOD";
609 else alien_workdir += "analysisESD";
3878a941 610 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
c38e3b95 611 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
e84da0a5 612 printf("=== AnalysisTrainPWG4Jets:: Registering jdl in the work directory alien://%s/%s, should be done by the manager! ===\n",
c38e3b95 613 alien_workdir.Data(),gridhandler->GetGridOutputDir());
58ef946c 614
615 TString dest;
616 dest = Form("%s/%s/%s.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
617 if(AliAnalysisAlien::FileExists(dest.Data())){
618 // Printf("%s exist on grid removing...",dest.Data());
619 // gGrid->Rm(dest.Data());
620 }
621 TFile::Cp(Form("file:%s.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
4721d8c5 622
623
624 TString dest;
625 dest = Form("%s/%s/%s_merge.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
626 if(AliAnalysisAlien::FileExists(dest.Data())){
627 // Printf("%s exist on grid removing...",dest.Data());
628 // gGrid->Rm(dest.Data());
629 }
630 TFile::Cp(Form("file:%s_merge.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
631
58ef946c 632
73b7619a 633 dest = Form("%s/rootfiles/STEER/LQ1dRef_v1.root",gGrid->GetHomeDirectory());
58ef946c 634 if(AliAnalysisAlien::FileExists(dest.Data())){
635 Printf("%s exist on grid removing...",dest.Data());
636 gGrid->Rm(dest.Data());
637 }
638 TFile::Cp(Form("file:%s/STEER/LQ1dRef_v1.root",
639 gSystem->ExpandPathName("$ALICE_ROOT")),
640 Form("alien://%s",dest.Data()));
c38e3b95 641 }
3878a941 642 AliLog::SetGlobalLogLevel(AliLog::kError);
c166d299 643 if((kUseSysInfo>0&&smode=="LOCAL")||!strcmp(plugin_mode, "test")){
644 TFile * fM = TFile::Open("manager_local.root","RECREATE");
645 mgr->Write();
646 fM->Close();
647 }
648
c38e3b95 649 StartAnalysis(smode, chain);
c166d299 650
4a6f59cb 651 if((kUseSysInfo>0&&smode=="LOCAL")||!strcmp(plugin_mode, "test")){
652 for(int i = 0;i < mgr->GetTopTasks()->GetEntries();i++){
653 mgr->ProfileTask(i);
654 }
655 }
c38e3b95 656 if (!strcmp(plugin_mode, "offline")&&smode=="GRID"){
e84da0a5 657 // Offline mode path files
658 // PatchJDL();
659 PatchAnalysisMacro();
660 }
c38e3b95 661
e84da0a5 662 if (kSaveTrain && smode=="GRID") {
663 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
664 TString alien_workdir = gGrid->GetHomeDirectory();
665 if (iAODanalysis) alien_workdir += "analysisAOD";
3878a941 666 else alien_workdir += "analysisESD";
667 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
e84da0a5 668 // kGridOutdir = gridhandler->GetGridOutputDir();
669 printf("=== Registering ConfigTrain.C in the work directory <%s> ===\n",
c38e3b95 670 alien_workdir.Data());
e84da0a5 671 if (AliAnalysisAlien::FileExists(Form("%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data())))
672 gGrid->Rm(Form("%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data()));
673 if (strcmp(plugin_mode, "test"))
674 TFile::Cp(Form("file:%sConfig.C",kTrainName.Data()), Form("alien://%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data()));
675 }
676 }
c38e3b95 677}
678
679//______________________________________________________________________________
680void StartAnalysis(const char *mode, TChain *chain) {
681// Start analysis.
682 Int_t imode = -1;
683 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
684 if (!strcmp(mode, "LOCAL")) imode = 0;
685 if (!strcmp(mode, "PROOF")) imode = 1;
686 if (!strcmp(mode, "GRID")) imode = 2;
687 switch (imode) {
688 case 0:
689 if (!chain) {
690 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Cannot create the chain");
691 return;
692 }
82ebd295 693 mgr->StartAnalysis(mode, chain,kNumberOfEvents);
c38e3b95 694 return;
695 case 1:
696 if (!kProofDataSet.Length()) {
697 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "kProofDataSet is empty");
698 return;
699 }
700 mgr->StartAnalysis(mode, kProofDataSet, kProofEvents,kProofOffset);
701 return;
702 case 2:
703 if (kPluginUse) {
704 if (!mgr->GetGridHandler()) {
705 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Grid plugin not initialized");
706 return;
707 }
708 mgr->StartAnalysis("grid");
709 } else {
710 if (!chain) {
711 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Cannot create the chain");
712 return;
713 }
714 mgr->StartAnalysis(mode, chain);
715 }
716 return;
717 }
718}
719
720//______________________________________________________________________________
721void CheckModuleFlags(const char *mode) {
722// Checks selected modules and insure compatibility
723 Int_t imode = -1;
724 if (!strcmp(mode, "LOCAL")) imode = 0;
725 if (!strcmp(mode, "PROOF")) imode = 1;
726 if (!strcmp(mode, "GRID")) imode = 2;
727
728
e84da0a5 729 if (kUseCPAR) {
730 kPluginAliRootVersion = ""; // NO aliroot if we use CPAR
731 }
c38e3b95 732
733 if (imode==1) {
734 if (!kUsePAR) {
735 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
736 kUsePAR = kTRUE;
737 }
738 }
739 if (imode != 2) {
740 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
741 kPluginUse = kFALSE;
742 }
743
744
745 if(!kIsMC){
746 // switch off anthin related to MC
747 kUseMC = 0;
748 kUseAODMC = 0;
749 kUseTR = kFALSE;
750 }
751
752 if (iAODanalysis) {
753 // AOD analysis
754 if (kUseMC)
755 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "MC usage disabled in analysis on AOD's");
756 if (kUseAODTags)
757 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "AOD tags usage disabled in analysis on AOD's");
758 kUseMC = kFALSE;
759 kUseTR = kFALSE;
760 kUseAODTags = kFALSE;
761 if (iESDfilter)
762 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "ESD filter disabled in analysis on AOD's");
763 iESDfilter = 0;
e84da0a5 764 if (iPhysicsSelection)
765 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "Physics Selection disabled in analysis on AOD's");
766 iPhysicsSelection = 0;
c38e3b95 767 if (!iAODhandler) {
768 if (iJETAN)
769 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "JETAN disabled in analysis on AOD's without AOD handler");
770 iJETAN = 0;
771 iDIJETAN = 0;
772 }
773 // Disable tasks that do not work yet on AOD data
58ef946c 774 if(iPWG4JCORRAN)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 JCORRAN disabled in analysis on AOD's");
4d62ae1a 775 iPWG4JCORRAN = 0;
c38e3b95 776 if( iPWG4PtQAMC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis on AOD's");
777 iPWG4PtQAMC = 0;
778 if( iPWG4PtQATPC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtTPC disabled in analysis on AOD's");
779 iPWG4PtQATPC = 0;
1f329128 780 if( iPWG4Cosmics)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 Comics disabled in analysis on AOD's");
781 iPWG4Cosmics = 0;
782
c38e3b95 783 if( iPWG4PtSpectra)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis on AOD's");
784 iPWG4PtSpectra = 0;
b53f2e4f 785 if(iPWG4KMeans)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4KMeans disabled on AOD's");
786 iPWG4KMeans = 0;
d2e6cdd5 787 if (iPWG4JetCorr)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4Jetcorr disabled on AOD's");
788 iPWG4JetCorr = 0;
c38e3b95 789 if (iPWG4PartCorr)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4partcorr disabled on AOD's");
790 iPWG4PartCorr = 0;
d2e6cdd5 791 if (iPWG4CaloQA)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4CaloQA disabled on AOD's");
792 iPWG4CaloQA = 0;
911a740f 793 if (iPWG4Tagged)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4tagged disabled on AOD's");
794 iPWG4Tagged = 0;
121e4bd5 795 if (iPWG4omega3pi)
796 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4omega3pi disabled on AOD's");
797 iPWG4omega3pi = 0;
c38e3b95 798 if(iPWG1QASym)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG1 QA Sym disabled in analysis on AOD's");
53c63663 799 if (iPWG4GammaConv)::Info("AnalysisPWG4Jets.C::CheckModuleFlags", "PWG4gammaconv disabled on AOD's");
800 iPWG4GammaConv = 0;
c38e3b95 801 iPWG1QASym = 0;
802 } else {
803 // ESD analysis
804 if (!kUseMC){
805 kUseTR = kFALSE;
806
807 if(kUseKinefilter)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 Kine Filter disabled in analysis without MC");
808 kUseKinefilter = kFALSE;
809 if( iPWG4PtQAMC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis without MC");
810 iPWG4PtQAMC = 0;
811
812 }
813 if (!kUseTR) {
c166d299 814 if(iPWG4PtQAMC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "iPWG4QATPCMC disabled if not reading track references");
b03b08a3 815 iPWG4PtQAMC = 0;
c38e3b95 816 }
e84da0a5 817 if (iJETAN){
818 iESDfilter=1;
819 }
c38e3b95 820 if (!iESDfilter){
821 kUseKinefilter = kFALSE;
822 kUseMuonfilter = kFALSE;
823 }
824 if(!iJETAN){
825 iPWG4JetSpectrum = iPWG4UE = iPWG4ThreeJets = iDIJETAN = 0;
826 }
827 }
1f329128 828 iPWG4JetTasks = iPWG4JetServices||iPWG4JetSpectrum||iPWG4UE||iPWG4PtQAMC||iPWG4PtSpectra||iPWG4PtQATPC||iPWG4Cosmics||iPWG4ThreeJets||iPWG4JetChem;
d2e6cdd5 829 iPWG4PartCorrLibs = iPWG4PartCorr||iPWG4Tagged||iPWG4CaloQA;
4721d8c5 830 iEMCUtilLibs = iPWG4PartCorrLibs||iPWG4JCORRAN;
e6993a52 831 iJETANLib = iPWG4JetTasks||iJETAN||iDIJETAN;
c38e3b95 832 if (iESDfilter) {iAODhandler=1;}
833 if (kUseKinefilter && !kUseMC) kUseKinefilter = kFALSE;
834 if (kUseAODTags && !iAODhandler) kUseAODTags = kFALSE;
835
836
837
838}
839
840//______________________________________________________________________________
841Bool_t Connect(const char *mode) {
842// Connect <username> to the back-end system.
843 Int_t imode = -1;
844 if (!strcmp(mode, "LOCAL")) imode = 0;
845 if (!strcmp(mode, "PROOF")) imode = 1;
846 if (!strcmp(mode, "GRID")) imode = 2;
847 TString username = gSystem->Getenv("alien_API_USER");
848 switch (imode) {
849 case 0:
850 break;
851 case 1:
852 if (!username.Length()) {
853 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Make sure you:\n \
854 1. Have called: alien-token-init <username>\n \
855 2. Have called: >source /tmp/gclient_env_$UID");
856 return kFALSE;
857 }
858 ::Info("AnalysisTrainPWG4Jets.C::Connect", "Connecting user <%s> to PROOF cluster <%s>",
859 username.Data(), kProofCluster.Data());
860 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
861// TProof::Open(Form("%s@%s:31093", username.Data(), kProofCluster.Data()));
862 TProof::Open(Form("%s@%s", username.Data(), kProofCluster.Data()));
863 if (!gProof) {
864 if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
865 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
866 return kFALSE;
867 }
868 if(kProofClearPackages)gProof->ClearPackages();
869
870 if(kProofSaveToAlien){
871 TGrid::Connect("alien://");
872 if (gGrid) {
873 TString homedir = gGrid->GetHomeDirectory();
874 TString workdir = homedir + kTrainName;
875 if (!gGrid->Cd(workdir)) {
876 gGrid->Cd(homedir);
877 if (gGrid->Mkdir(workdir)) {
878 gGrid->Cd(kTrainName);
879 ::Info("AnalysisTrainPWG4Jets::Connect()", "Directory %s created", gGrid->Pwd());
880 }
881 }
882 gGrid->Mkdir("proof_output");
883 gGrid->Cd("proof_output");
884 kProofOutdir = Form("alien://%s", gGrid->Pwd());
885 }
886 }
887 break;
888 case 2:
889 if (!username.Length()) {
890 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Make sure you:\n \
891 1. Have called: alien-token-init <username>\n \
892 2. Have called: >source /tmp/gclient_env_$UID");
893 return kFALSE;
894 }
895 if (kPluginUse && !gSystem->Getenv("alien_CLOSE_SE")) {
896 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode),
897 "When using the AliEn plugin it is preferable to define the \
898 variable alien_CLOSE_SE in your environment.");
899 return kFALSE;
900 }
901 ::Info("AnalysisTrainPWG4Jets.C::Connect", "Connecting user <%s> to AliEn ...",
902 username.Data());
903 TGrid::Connect("alien://");
904 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
905 break;
906 default:
907 ::Error("AnalysisTrainPWG4Jets.C::Connect", "Unknown run mode: %s", mode);
908 return kFALSE;
909 }
910 ::Info("AnalysisTrainPWG4Jets.C::Connect","Connected in %s mode", mode);
911 return kTRUE;
912}
913
914//______________________________________________________________________________
915Bool_t LoadCommonLibraries(const char *mode)
916{
917// Load common analysis libraries.
918 Int_t imode = -1;
919 if (!strcmp(mode, "LOCAL")) imode = 0;
920 if (!strcmp(mode, "PROOF")) imode = 1;
921 if (!strcmp(mode, "GRID")) imode = 2;
922 if (!gSystem->Getenv("ALICE_ROOT")) {
923 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
924 return kFALSE;
925 }
926 Bool_t success = kTRUE;
927 // ROOT libraries
928 gSystem->Load("libTree.so");
929 gSystem->Load("libGeom.so");
930 gSystem->Load("libVMC.so");
931 gSystem->Load("libPhysics.so");
932
933 // Load framework classes. Par option ignored here.
934 switch (imode) {
935 case 0:
936 case 2:
937 if (kUseCPAR) {
938 success &= LoadLibrary("STEERBase", mode, kTRUE);
939 success &= LoadLibrary("ESD", mode, kTRUE);
940 success &= LoadLibrary("AOD", mode, kTRUE);
941 success &= LoadLibrary("ANALYSIS", mode, kTRUE);
942 success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
943 success &= LoadLibrary("CORRFW", mode, kTRUE);
944 } else {
945 success &= LoadLibrary("libSTEERBase.so", mode);
946 success &= LoadLibrary("libESD.so", mode);
947 success &= LoadLibrary("libAOD.so", mode);
948 success &= LoadLibrary("libANALYSIS.so", mode);
949 success &= LoadLibrary("libANALYSISalice.so", mode);
950 success &= LoadLibrary("libCORRFW.so", mode);
951 gROOT->ProcessLine(".include $ALICE_ROOT/include");
952 }
953 break;
954 case 1:
955 Int_t ires = -1;
956 if (kProofUseAFPAR && !gSystem->AccessPathName(kProofAFversion)) ires = gProof->UploadPackage(kProofAFversion);
957 if (ires < 0) {
958 success &= LoadLibrary("STEERBase", mode);
959 success &= LoadLibrary("ESD", mode);
960 success &= LoadLibrary("AOD", mode);
961 success &= LoadLibrary("ANALYSIS", mode);
962 success &= LoadLibrary("ANALYSISalice", mode);
963 success &= LoadLibrary("CORRFW", mode);
964 } else {
965 ires = gProof->EnablePackage(kProofAFversion);
966 if (ires<0) success = kFALSE;
967 success &= LoadLibrary("CORRFW", mode);
968 }
969 break;
970 default:
971 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
972 return kFALSE;
973 }
974 if (success) {
975 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
976 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
977 gSystem->GetIncludePath());
978 } else {
979 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Load common libraries: FAILED");
980 }
981
982 return success;
983}
984
985//______________________________________________________________________________
986Bool_t LoadAnalysisLibraries(const char *mode)
987{
988// Load common analysis libraries.
989 Bool_t success = kTRUE;
990 if (iESDfilter) {
991 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
992 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
993 }
994 // JETAN
e6993a52 995 if (iJETANLib) {
b53f2e4f 996 // this part needs some rework in case we do not need the fastjed finders for processing
997 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
c38e3b95 998 if (!strcmp(mode, "PROOF")){
ef1e462f 999 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libCGAL.so\"\)", kTRUE);
c38e3b95 1000 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libfastjet.so\"\)", kTRUE);
1001 // problem when loading siscone copiled with different gcc version??
1002 // gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libsiscone.so\"\)", kTRUE);
1003 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libSISConePlugin.so\"\)", kTRUE);
1004 }
b53f2e4f 1005 if(!kUsePAR){
e84da0a5 1006 if (!LoadLibrary("CGAL", mode, kTRUE)) return kFALSE;
1007 if (!LoadLibrary("fastjet", mode, kTRUE)) return kFALSE;
1008 if (!LoadLibrary("siscone", mode, kTRUE)) return kFALSE;
1009 if (!LoadLibrary("SISConePlugin", mode, kTRUE)) return kFALSE;
1010 }
1011 else{
1012 // par files plus FASTJET needs some extra work... need to change
1013 // the loading sequence in the auto generated .C file
1014 if (!LoadLibrary("libCGAL.so", mode, kTRUE)) return kFALSE;
1015 if (!LoadLibrary("libfastjet.so", mode, kTRUE)) return kFALSE;
1016 if (!LoadLibrary("libsiscone.so", mode, kTRUE)) return kFALSE;
1017 if (!LoadLibrary("libSISConePlugin.so", mode, kTRUE)) return kFALSE;
1018 }
c38e3b95 1019 if (!LoadLibrary("FASTJETAN", mode, kTRUE)) return kFALSE;
1020 }
1021 if(iPWG4JetTasks){
c38e3b95 1022 if (!LoadLibrary("PWG4JetTasks", mode, kTRUE)) return kFALSE;
1023 }
58ef946c 1024
c38e3b95 1025 if(iPWG1QASym){
99bfd7f7 1026 if (!LoadSource(Form("%s/PWG1/AliAnalysisTaskQASym.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
c38e3b95 1027 }
121e4bd5 1028 if(iPWG4TmpSourceSara){
c166d299 1029 if(!kUsePAR)gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
121e4bd5 1030 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskEta.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
1031 }
c166d299 1032 if(iPWG4TmpSourceFrag){
1033 if(!kUsePAR)gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
1034 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskFragFunc.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
1035 }
9f77f0ce 1036
58ef946c 1037
9f77f0ce 1038 /*
1039 if(iPWG4JetChem){
c580ebbb 1040 if(!kUsePAR)gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
1041 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskJetChem.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
1042 }
9f77f0ce 1043 */
c166d299 1044
4721d8c5 1045 if(iEMCUtilLibs){
1046 if (!LoadLibrary("EMCALUtils", mode, kTRUE) ||
1047 !LoadLibrary("PHOSUtils", mode, kTRUE)) return kFALSE;
1048 }
1049
911a740f 1050 if (iPWG4PartCorrLibs) {
4721d8c5 1051 if (!LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
c38e3b95 1052 !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
1053 }
4721d8c5 1054 if(iPWG4JCORRAN){
1055 // PWG4 particle correlations
1056 if(!LoadLibrary("PWG4JCORRAN",mode,kTRUE))return kFALSE;
1057 }
d2e6cdd5 1058 if (iPWG4JetCorr) {
1059 if (!LoadLibrary("PWG4JetCorrel", mode, kTRUE)) return kFALSE;
1060 }
121e4bd5 1061 if (iPWG4omega3pi) {
1062 if (!LoadLibrary("PWG4omega3pi", mode, kTRUE)) return kFALSE;
1063 }
53c63663 1064 if (iPWG4GammaConv) {
1065 if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
1066 }
c38e3b95 1067
1068 ::Info("AnalysisTrainPWG4Jets.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
1069 return kTRUE;
1070}
1071
1072//______________________________________________________________________________
1073Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
1074{
1075// Load a module library in a given mode. Reports success.
1076 Int_t imode = -1;
1077 Int_t result;
1078 TString smodule(module);
1079 if (!strcmp(mode, "LOCAL")) imode = 0;
1080 if (!strcmp(mode, "PROOF")) imode = 1;
1081 if (!strcmp(mode, "GRID")) imode = 2;
1082 TString mod(module);
1083 if (!mod.Length()) {
1084 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Empty module name");
1085 return kFALSE;
1086 }
1087 // If a library is specified, just load it
1088 if (smodule.EndsWith(".so")) {
1089 mod.Remove(mod.Index(".so"));
1090 result = gSystem->Load(mod);
1091 if (result < 0) {
1092 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load library %s", module);
1093 return kFALSE;
1094 }
1095 if (rec) anaLibs += Form("%s.so ",mod.Data());
e84da0a5 1096 if (rec) anaLibsExtra += Form("%s.so ",mod.Data());
c38e3b95 1097 return kTRUE;
1098 }
1099 // Check if the library is already loaded
1100 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
1101 return kTRUE;
1102 switch (imode) {
1103 case 0:
1104 case 2:
1105 if (kUsePAR) {
1106 result = SetupPar(module);
1107 if (rec) anaPars += Form("%s.par ", module);
1108 } else {
1109 result = gSystem->Load(Form("lib%s.so", module));
1110 if (rec) anaLibs += Form("lib%s.so ", module);
1111 }
1112 break;
1113 case 1:
1114 if(!gSystem->AccessPathName(module)){
1115 ::Info("AnalysisTrainPWG4Jets.C::LoadLibrary", "Removing directory %s",module);
1116 gSystem->Exec(Form("rm -rf %s",module));
1117 }
1118 result = gProof->UploadPackage(module);
1119 if (result<0) {
1120 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
1121 if (result<0) {
1122 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
1123 return kFALSE;
1124 }
1125 }
1126 result = gProof->EnablePackage(module);
1127 break;
1128 default:
1129 return kFALSE;
1130 }
1131 if (result < 0) {
1132 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load module %s", module);
1133 return kFALSE;
1134 }
1135 return kTRUE;
1136}
1137
1138
1139
1140//______________________________________________________________________________
1141Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
1142{
1143// Load a module library in a given mode. Reports success.
1144 Int_t imode = -1;
1145 Int_t result = -1;
1146 if (!strcmp(mode, "LOCAL")) imode = 0;
1147 if (!strcmp(mode, "PROOF")) imode = 1;
1148 if (!strcmp(mode, "GRID")) imode = 2;
1149 TString ssource(source);
1150 TString basename = gSystem->BaseName(ssource.Data());
1151 if (!ssource.Length()) {
1152 ::Error("AnalysisTrainPWG4Jets.C::LoadSource", "Empty task name");
1153 return kFALSE;
1154 }
4d62ae1a 1155 // we have a source code so compile it
c38e3b95 1156 if (ssource.EndsWith(".cxx")) {
1157 // need to copy it here other wise the path is also used on grid...
1158 ssource.Remove(ssource.Index(".cxx"));
1159 basename.Remove(basename.Index(".cxx"));
1160 Printf("LoadSources:: Copying... path %s{cxx,h}",ssource.Data());
1161 gSystem->Exec(Form("cp %s.cxx . ",ssource.Data()));
1162 gSystem->Exec(Form("cp %s.h . ",ssource.Data()));
1163 // Path to code
1164 // only needed for local compilation, in grid and proof mode
1165 // the task headers are uploaded
1166 // path.Remove(path.Index(gSystem->BaseName(path.Data())));
1167 // Printf("LoadSources:: Including path %s",path.Data());
1168 // if(path.Length()>0)gROOT->ProcessLine(Form(".include %s",path.Data()));
1169 Printf("LoadSources:: Loading... path %s",basename.Data());
1170 switch (imode) {
1171 case 0:
b53f2e4f 1172 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1173 break;
1174 case 1:
b53f2e4f 1175 result = gProof->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1176 break;
1177 case 2:
b53f2e4f 1178 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1179 if (rec){
1180 // what we want to compile
1181 anaSources += Form("%s.cxx ",basename.Data());
1182 // what we need as input...
1183 anaLibs += Form("%s.cxx %s.h ",basename.Data(),basename.Data());
1184 }
1185 break;
1186 default:
1187 return kFALSE;
1188 }
1189 }
1190 if (result < 0) {
1191 ::Error("AnalysisTrainPWG4Jets.C::LoadSources", "Could not load source %s", source);
1192 return kFALSE;
1193 }
1194 return kTRUE;
1195}
1196
1197
1198//______________________________________________________________________________
1199TChain *CreateChain(const char *mode, const char *plugin_mode)
1200{
1201// Create the input chain
1202 Int_t imode = -1;
1203 if (!strcmp(mode, "LOCAL")) imode = 0;
1204 if (!strcmp(mode, "PROOF")) imode = 1;
1205 if (!strcmp(mode, "GRID")) imode = 2;
1206 TChain *chain = NULL;
1207 // Local chain
1208 switch (imode) {
1209 case 0:
1210 if (iAODanalysis) {
1211 if (!kLocalXMLDataset.Length()) {
1212 // Local AOD
1213 chain = new TChain("aodTree");
1214 TString line;
1215 ifstream in;
1216 in.open(kLocalDataList.Data());
1217 while (in.good()) {
1218 in >> line;
1219 if (line.Length() == 0) continue;
1220 // cout << " line = " << line << endl;
1221 chain->Add(line.Data());
1222 }
1223 } else {
1224 // Interactive AOD
1225 chain = CreateChainSingle(kLocalXMLDataset, "aodTree");
1226 }
1227 } else {
1228 if (!kLocalXMLDataset.Length()) {
1229 // Local ESD
1230 chain = new TChain("esdTree");
1231 TString line;
1232 ifstream in;
1233 in.open(kLocalDataList.Data());
1234 while (in.good()) {
1235 in >> line;
1236 if (line.Length() == 0) continue;
1237 cout << " line = " << line << endl;
1238 chain->Add(line.Data());
1239 }
1240 } else {
1241 // Interactive ESD
1242 chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
1243 }
1244 }
1245 break;
1246 case 1:
1247 break;
1248 case 2:
1249 if (kPluginUse) {
1250// AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
1251// AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
1252 } else {
1253 TString treeName = "esdTree";
1254 if (iAODanalysis) treeName = "aodTree";
1255 chain = CreateChainSingle("wn.xml", treeName);
1256 }
1257 break;
1258 default:
1259 }
1260 if (chain && chain->GetNtrees()) return chain;
1261 return NULL;
1262}
1263
1264//______________________________________________________________________________
1265TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
1266{
1267 printf("*******************************\n");
1268 printf("*** Getting the ESD Chain ***\n");
1269 printf("*******************************\n");
1270 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
1271
1272 if (!myCollection) {
1273 ::Error("AnalysisTrainPWG4Jets.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
1274 return NULL ;
1275 }
1276
1277 TChain* chain = new TChain(treeName);
1278 myCollection->Reset() ;
1279 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
1280 chain->ls();
1281 return chain;
1282}
1283
1284//______________________________________________________________________________
1285Int_t SetupPar(char* pararchivename)
1286{
1287 if (!pararchivename || !strlen(pararchivename)) return -1;
1288 char processline[1024];
1289 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
1290 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
1291 ::Info("AnalysisTrainPWG4Jets.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
1292 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
1293 Form("%s.par",pararchivename));
1294 } else {
1295 ::Error("AnalysisTrainPWG4Jets.C::SetupPar", "Cannot find %s.par", pararchivename);
1296 return -1;
1297 }
1298 }
1299 if (kPluginUse && kSaveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, kTrainName.Data()));
1300 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
1301
1302 TString ocwd = gSystem->WorkingDirectory();
1303 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
1304
1305 // check for BUILD.sh and execute
1306 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
1307 printf("*******************************\n");
1308 printf("*** Building PAR archive ***\n");
1309 printf("*******************************\n");
1310 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
1311 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
1312 return -1;
1313 }
1314 }
1315
1316 // check for SETUP.C and execute
1317 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
1318 printf("*******************************\n");
1319 printf("*** Setup PAR archive ***\n");
1320 printf("*******************************\n");
1321 gROOT->Macro("PROOF-INF/SETUP.C");
1322 }
1323 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
1324 return 0;
1325}
1326
1327//______________________________________________________________________________
1328AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
1329{
1330// Check if user has a valid token, otherwise make one. This has limitations.
1331// One can always follow the standard procedure of calling alien-token-init then
1332// source /tmp/gclient_env_$UID in the current shell.
1333 if (!AliAnalysisGrid::CreateToken()) return NULL;
1334 AliAnalysisAlien *plugin = new AliAnalysisAlien();
1335// Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
1336 plugin->SetRunMode(plugin_mode);
1337 if (kPluginUseProductionMode) plugin->SetProductionMode();
1338 plugin->SetJobTag(kJobTag);
1339 plugin->SetNtestFiles(2);
1340// plugin->SetPreferedSE("ALICE::NIHAM::File");
1341// Set versions of used packages
e84da0a5 1342 plugin->SetAPIVersion("V1.1x");
1343 // plugin->SetAPIVersion("V1.0x");
1344// plugin->SetAPIVersion("V2.4");
c38e3b95 1345 plugin->SetROOTVersion(kPluginRootVersion);
1346 plugin->SetAliROOTVersion(kPluginAliRootVersion);
1347// Declare input data to be processed.
1348// Method 1: Create automatically XML collections using alien 'find' command.
1349// Define production directory LFN
1350 plugin->SetGridDataDir(kGridDatadir.Data());
1351// Set data search pattern
1352 if (iAODanalysis) plugin->SetDataPattern(" *AliAOD.root");
1353 else plugin->SetDataPattern(Form(" %s/*/*ESD.tag.root",kGridPassPattern.Data()));
1354// ...then add run numbers to be considered
1355// plugin->SetRunRange(kGridRunRange[0], kGridRunRange[1]);
1356 for (Int_t i=kGridRunRange[0]; i<=kGridRunRange[1]; i++) {
1357 Printf("AnalysisTrainPWG4Jets Adding run number %s", Form(kGridRunPattern.Data(),i));
1358 plugin->AddRunNumber(Form(kGridRunPattern.Data(),i));
1359 }
1360
1361 if(kGridLocalRunList.Length()>0){
1362 ifstream in1;
1363 in1.open(kGridLocalRunList.Data());
1364 int iRun;
9a5c5b1e 1365
1366 /*
e84da0a5 1367 char c;
1368 char cLine[250];
1369 while(!in1.eof()){
1370 c = in1.get();
1371 if ( (c >= '0') && (c <= '9') )
1372 {
1373 in1.putback (c);
1374 in1>>iRun;
1375 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1376 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
1377 }
1378 else
1379 {
1380 in1.putback (c);
1381 in1.getline(cLine,250);
9a5c5b1e 1382
1383 }
1384 }
1385 */
1386
1387 // just use run numbers, negatives will be excluded
1388 while(in1>>iRun){
1389 if(iRun>0){
1390 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1391 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
1392 }
1393 else{
1394 Printf("AnalysisTrainPWG4Jets Skipping run number from File %d", iRun);
e84da0a5 1395 }
c38e3b95 1396 }
1397 }
1398
1399// Method 2: Declare existing data files (raw collections, xml collections, root file)
1400// If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
1401// XML collections added via this method can be combined with the first method if
1402// the content is compatible (using or not tags)
1403// plugin->AddDataFile("tag.xml");
1404// plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
1405// Define alien work directory where all files will be copied. Relative to alien $HOME.
3878a941 1406 TString alien_workdir = "";
1407
1408 if (iAODanalysis) alien_workdir += "analysisAOD";
1409 else alien_workdir += "analysisESD";
1410 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
1411 plugin->SetGridWorkingDir(alien_workdir.Data());
1412
c38e3b95 1413 // Declare alien output directory. Relative to working directory.
1414 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1415 plugin->SetGridOutputDir(kGridOutdir);
1416
1417 // Add external packages
1418 if (iJETAN||iDIJETAN) {
1419 plugin->AddExternalPackage("boost::v1_38_0");
1420 plugin->AddExternalPackage("cgal::v3.3.1");
1421 plugin->AddExternalPackage("fastjet::v2.4.0");
1422 }
1423
1424
1425 // set extra libs before par file compilation
1426 anaLibs += kGridExtraFiles;
1427 anaLibs = anaLibs.Strip();
e84da0a5 1428 Printf("anaLibs %s",anaLibs.Data());
1429 Printf("anaLibsExtra %s",anaLibsExtra.Data());
1430
1431 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs.Data());
1432 if (anaLibsExtra.Length()) plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
c38e3b95 1433
1434 TString ana_sources = "";
1435 TString ana_add = "";
1436 if (kUsePAR && anaPars.Length()) {
1437 printf("%s\n", anaPars.Data());
1438 TObjArray *arr;
1439 TObjString *objstr;
1440 arr = anaPars.Tokenize(" ");
1441 TIter next(arr);
1442 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
1443 delete arr;
1444 }
1445
1446// Declare the analysis source files names separated by blancs. To be compiled runtime
1447// using ACLiC on the worker nodes.
1448 ana_sources = anaSources.Strip();
1449// Declare all libraries (other than the default ones for the framework. These will be
1450// loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
1451
1452 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
1453 plugin->SetExecutableCommand(kPluginExecutableCommand.Data());
4721d8c5 1454 // Declare the output file names separated by blancs.
1455 // (can be like: file.root or file.root@ALICE::Niham::File)
c38e3b95 1456 plugin->SetMergeExcludes(kGridMergeExclude);
1457 plugin->SetMaxMergeFiles(kGridMaxMergeFiles);
1458 plugin->SetNrunsPerMaster(kGridRunsPerMaster);
9a5c5b1e 1459 plugin->SetMergeViaJDL(kPluginMergeViaJDL);
4721d8c5 1460 // Use fastread option
9a5c5b1e 1461 plugin->SetFastReadOption(kPluginFastReadOption);
4721d8c5 1462 // UseOverwrite mode
9a5c5b1e 1463 plugin->SetOverwriteMode(kPluginOverwriteMode);
4721d8c5 1464 // Optionally define the files to be archived.
1465 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
dc6a7461 1466 plugin->SetOutputToRunNo(kPluginOutputToRunNumber); // write the output to subdirs named after run number
c38e3b95 1467
1468 // Put default output files to archive
1469 TString listhists = "";
1470 TString listaods = "";
1471 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1472 TIter next(mgr->GetOutputs());
1473 AliAnalysisDataContainer *output;
1474 while ((output=(AliAnalysisDataContainer*)next())) {
1475 const char *filename = output->GetFileName();
1476 if (!(strcmp(filename, "default"))) {
53c63663 1477 if (!mgr->GetOutputEventHandler()) continue;
c38e3b95 1478 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
e84da0a5 1479 if (listaods.Length()) listaods += " ";
c38e3b95 1480 listaods += filename;
c38e3b95 1481 } else {
e84da0a5 1482 if(!listhists.Contains(filename)){
1483 if (listhists.Length()) listhists += " ";
c38e3b95 1484 listhists += filename;
1485 }
1486 }
1487 }
53c63663 1488
53c63663 1489 if (mgr->GetExtraFiles().Length()) {
e84da0a5 1490 if (listaods.Length()) listaods += " ";
53c63663 1491 listaods += mgr->GetExtraFiles();
c38e3b95 1492 }
53c63663 1493
1494 // if we do not fill the aod we do not need to store it
4721d8c5 1495 // kGridMergeExclude = listaods;
e84da0a5 1496
4721d8c5 1497 if(kSaveAOD!=0){
1498 TString outputFiles = "";
1499 outputFiles += mgr->GetExtraFiles();
1500 if (listhists.Length()) outputFiles += " ";
1501 outputFiles += listhists;
e84da0a5 1502 plugin->SetDefaultOutputs(kFALSE);
4721d8c5 1503 Printf("%s:%d Starting with the files %s",(char*)__FILE__,__LINE__,outputFiles.Data());
1504 // remove
1505 // no harm done when we try to remove something that is not there :)
1506 if(!(kSaveAOD&(1<<0))){
1507 outputFiles.ReplaceAll("AliAOD.root ","");
1508 listaods.ReplaceAll("AliAOD.root ","");
1509 }
1510 if(!(kSaveAOD&(1<<1))){
1511 if(kDeltaAODJetName.Length())outputFiles.ReplaceAll(kDeltaAODJetName.Data(),"");
1512 if(kDeltaAODJetName.Length())listaods.ReplaceAll(kDeltaAODJetName.Data(),"");
1513
1514 }
1515 if(!(kSaveAOD&(1<<2))){
1516 if(kDeltaAODPartCorrName.Length())outputFiles.ReplaceAll(kDeltaAODPartCorrName.Data(),"");
1517 if(kDeltaAODPartCorrName.Length())listaods.ReplaceAll(kDeltaAODPartCorrName.Data(),"");
1518 }
1519 if(!(kSaveAOD&(1<<3))){
1520 if(kDeltaAODJCORRANName.Length())outputFiles.ReplaceAll(kDeltaAODJCORRANName.Data(),"");
1521 if(kDeltaAODJCORRANName.Length())listaods.ReplaceAll(kDeltaAODJCORRANName.Data(),"");
1522 }
1523
1524 //
1525 Printf("%s:%d Saving the files %s",(char*)__FILE__,__LINE__,outputFiles.Data());
1526 plugin->SetOutputFiles(outputFiles.Data());
e84da0a5 1527 }
53c63663 1528
4721d8c5 1529 TString outputArchive;
1530 outputArchive = Form("log_archive.zip:stdout,stderr@%s",kGridOutputStorages.Data());
e84da0a5 1531 listaods.ReplaceAll(" ", ",");
1532 listhists.ReplaceAll(" ", ",");
4721d8c5 1533 if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), kGridOutputStorages.Data());
1534 if (listaods.Length()) listaods = Form("aod_archive.zip:%s@%s", listaods.Data(), kGridOutputStorages.Data());
53c63663 1535
c38e3b95 1536 if (!listhists.Length() && !listaods.Length()) {
1537 ::Fatal("AnalysisTrainPWG4Jets", "No task output !");
1538 }
4721d8c5 1539
c38e3b95 1540 if (listaods.Length()) {
1541 outputArchive += " ";
1542 outputArchive += listaods;
1543 }
1544 if (listhists.Length()) {
1545 outputArchive += " ";
1546 outputArchive += listhists;
1547 }
1548 plugin->SetOutputArchive(outputArchive);
4721d8c5 1549
1550
c38e3b95 1551// Optionally set a name for the generated analysis macro (default MyAnalysis.C)
1552 plugin->SetAnalysisMacro(Form("%s.C", kTrainName.Data()));
1553// Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
1554 plugin->SetSplitMaxInputFileNumber(kGridFilesPerJob);
1555// Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1556// plugin->SetMaxInitFailed(5);
1557// Optionally resubmit threshold.
1558// plugin->SetMasterResubmitThreshold(90);
1559// Optionally set time to live (default 30000 sec)
1560 plugin->SetTTL(30000);
1561// Optionally set input format (default xml-single)
1562 plugin->SetInputFormat("xml-single");
1563// Optionally modify the name of the generated JDL (default analysis.jdl)
1564 plugin->SetJDLName(Form("%s.jdl", kTrainName.Data()));
1565// Optionally modify the executable name (default analysis.sh)
1566 plugin->SetExecutable(Form("%s.sh", kTrainName.Data()));
1567// Optionally modify job price (default 1)
1568 plugin->SetPrice(1);
1569// Optionally modify split mode (default 'se')
1570 plugin->SetSplitMode("se");
1571 return plugin;
1572}
1573
1574//______________________________________________________________________________
1575void WriteConfig()
1576{
1577// Write train configuration in a file. The file name has the format:
1578// train_[trainName]_ddMonthyyyy_time.C
1579 if (kUseDate) {
1580 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
1581 ifstream fdate("date.tmp");
1582 if (!fdate.is_open()) {
1583 ::Error("AnalysisTrainPWG4Jets.C::Export","Could not generate file name");
1584 return;
1585 }
1586 const char date[64];
1587 fdate.getline(date,64);
1588 fdate.close();
1589 gSystem->Exec("rm date.tmp");
1590 kTrainName = Form("train_%s_%s", kTrainName.Data(), date);
1591 } else {
1592 kTrainName = Form("train_%s", kTrainName.Data());
1593 }
1594 TString cdir = gSystem->WorkingDirectory();
1595 gSystem->MakeDirectory(kTrainName);
1596 gSystem->ChangeDirectory(kTrainName);
1597 ofstream out;
1598 out.open(Form("%sConfig.C",kTrainName.Data()), ios::out);
1599 if (out.bad()) {
1600 ::Error("AnalysisTrainPWG4Jets.C::Export", "Cannot open ConfigTrain.C for writing");
1601 return;
1602 }
1603 out << "{" << endl;
1604 out << " kTrainName = " << "\"" << kTrainName.Data() << "\";" << endl;
1605 out << " kProofCluster = " << "\"" << kProofCluster.Data() << "\";" << endl;
1606 out << " kProofUseAFPAR = " << kProofUseAFPAR << ";" << endl;
1607 if (kProofUseAFPAR)
1608 out << " kProofAFversion = " << kProofAFversion.Data() << ";" << endl;
1609 out << " kProofDataSet = " << "\"" << kProofDataSet.Data() << "\";" << endl;
1610 out << " kPluginUse = " << kPluginUse << ";" << endl;
1611 out << " kUsePAR = " << kUsePAR << ";" << endl;
1612 out << " kUseCPAR = " << kUseCPAR << ";" << endl;
1613 out << " kPluginRootVersion = " << "\"" << kPluginRootVersion.Data() << "\";" << endl;
1614 out << " kPluginAliRootVersion = " << "\"" << kPluginAliRootVersion.Data() << "\";" << endl;
1615 out << " kGridDatadir = " << "\"" << kGridDatadir.Data() << "\";" << endl;
1616 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1617 out << " kGridOutdir = " << "\"" << kGridOutdir.Data() << "\";" << endl;
1618 out << " kGridMaxMergeFiles = " << kGridMaxMergeFiles << ";" << endl;
1619 out << " kGridMergeExclude = " << "\"" << kGridMergeExclude.Data() << "\";" << endl;
1620 out << " kGridRunsPerMaster = " << kGridRunsPerMaster << ";" << endl;
1621 out << " kGridFilesPerJob = " << kGridFilesPerJob << ";" << endl;
1622 out << " kGridRunRange[0] = " << kGridRunRange[0] << ";" << endl;
1623 out << " kGridRunRange[1] = " << kGridRunRange[1] << ";" << endl;
1624 out << " kUseDebug = " << kUseDebug << ";" << endl;
1625 out << " kUseMC = " << kUseMC << ";" << endl;
1626 out << " kUseESDTags = " << kUseESDTags << ";" << endl;
1627 out << " kUseKinefilter = " << kUseKinefilter << ";" << endl;
1628 out << " kUseTR = " << kUseTR << ";" << endl;
1629 out << " kUseAODTags = " << kUseAODTags << ";" << endl;
1630 out << " kSaveTrain = " << "kFALSE;" << endl << endl;
1631 out << " // Analysis modules" << endl;
1632 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
1633 out << " iAODhandler = " << iAODhandler << ";" << endl;
1634 out << " iESDfilter = " << iESDfilter << ";" << endl;
1635 out << " iJETAN = " << iJETAN << ";" << endl;
1636 out << "// Configuration fot the wagons" << endl;
1637 out << "}" << endl;
1638 ::Info("AnalysisTrainPWG4Jets.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", kTrainName.Data()));
1639 gSystem->ChangeDirectory(cdir);
1640}
1641
1642//______________________________________________________________________________
1643Bool_t LoadConfig(const char *filename)
1644{
1645// Read train configuration from file
1646 if (gSystem->AccessPathName(filename)) {
1647 ::Error("AnalysisTrainPWG4Jets.C::LoadConfig", "Config file name not found");
1648 return kFALSE;
1649 }
1650 gROOT->ProcessLine(Form(".x %s", filename));
1651 ::Info("AnalysisTrainPWG4Jets.C::LoadConfig", "Train configuration loaded from file %s", filename);
1652 return kTRUE;
1653}
1654
1655Bool_t PatchJDL(){
1656 Printf(">>> Patching JDL");
1657 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1658 AliAnalysisAlien* gridHandler = (AliAnalysisAlien*)mgr->GetGridHandler();
1659 TGridJDL *jdl = gridHandler->GetGridJDL();
1660 if(iJETAN)jdl->AddToPackages("fastjet","v2.4.0");
1661 gridHandler->WriteJDL(kFALSE);
0971dabc 1662 Printf("<<< Patching JDL");
c38e3b95 1663 return kTRUE;
1664}
1665
1666Bool_t PatchAnalysisMacro(){
4721d8c5 1667 Printf(">>> Patching AnalysisMacro");
1668 gSystem->Exec(Form("mv %s.C %s.C_tmp",kTrainName.Data(),kTrainName.Data()));
c38e3b95 1669
1670 ifstream in1;
1671 in1.open(Form("%s.C_tmp", kTrainName.Data()));
1672 char cLine[250];
1673 TString st;
1674 while(in1.getline(cLine,250)){
1675 st += cLine;
1676 st += "\n";
1677 }
4721d8c5 1678 Int_t index= -1;
c38e3b95 1679 index = st.Index("gSystem->Load(\"libPhysics\");");
1680 index += strlen("gSystem->Load(\"libPhysics\");");
4721d8c5 1681 /*
c38e3b95 1682 TObjArray *arr;
1683 TObjString *objstr;
1684 arr = anaLibs.Tokenize(" ");
1685 TIter next(arr);
4721d8c5 1686
c38e3b95 1687 add += "\n\n // added by CKB \n";
1688 while ((objstr=(TObjString*)next())){
e84da0a5 1689 if(objstr->GetString().Contains("PWG3"))continue;
c38e3b95 1690 if(objstr->GetString().EndsWith(".so"))add += Form("gSystem->Load(\"%s\");\n",objstr->GetString().Data());
1691 }
1692 delete arr;
4721d8c5 1693 */
3878a941 1694 // add += Form("AliLog::SetGlobalLogLevel(%d);\n",AliLog::GetGlobalLogLevel());
4721d8c5 1695 TString add = "";
1696
1697 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1698 add += "\n\n // added by CKB \n";
1699 add += "\n gSystem->AddIncludePath(\"./\") \n";
1700 if(gGrid&&kPluginAliRootVersion.Length()==0){
1701 add += "\n // Dirty hack for TRD reference data \n";
1702 add += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1703 add += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1704 add += "\"); \n";
c38e3b95 1705 }
4721d8c5 1706 add += "// BKC \n\n";
1707 st.Insert(index,add.Data());
e84da0a5 1708
1709 if(kUseDebug){
1710 st.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
1711 }
1712
4721d8c5 1713 if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
1714 index = st.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1715 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1716 st.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1717 }
c166d299 1718
c38e3b95 1719 ofstream out;
1720 out.open(Form("%s.C", kTrainName.Data()));
1721 if (out.bad()) {
1722 return kFALSE;
1723 }
1724 out << st << endl;
1725 Printf("<<< Patching AnalysisMacro");
4721d8c5 1726
1727
1728
1729
1730
1731 Printf(">>> Patching Merge Macro");
1732 gSystem->Exec(Form("mv %s_merge.C %s_merge.C_tmp",kTrainName.Data(),kTrainName.Data()));
1733
1734 ifstream in2;
1735 in2.open(Form("%s_merge.C_tmp", kTrainName.Data()));
1736 TString st2;
1737 while(in2.getline(cLine,250)){
1738 st2 += cLine;
1739 st2 += "\n";
1740 }
1741 index = st2.Index("gSystem->Load(\"libPhysics\");");
1742 index += strlen("gSystem->Load(\"libPhysics\");");
1743 TString add2 = "";
1744 add2 += "\n gSystem->AddIncludePath(\"./\") \n";
1745 if(gGrid&&kPluginAliRootVersion.Length()==0){
1746 add2 += "\n // Dirty hack for TRD reference data \n";
1747 add2 += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1748 add2 += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1749 add2 += "\"); \n";
1750 }
1751 add2 += "// BKC \n\n";
1752 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1753 st2.Insert(index,add.Data());
1754
1755
1756 if(kUseDebug){
1757 st2.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
1758 }
1759
1760 if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
1761 index = st2.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1762 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1763 st2.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1764 }
1765
1766 // do not exclude the extra files from merign, this is done explicitly in this train script
1767 index = st2.Index("mergeExcludes +="); // uncommen $ALICE_ROOT include for par files
1768 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1769 st2.Insert(index,"// CKB comment out, handled explicitly by the train macro \n //");
1770
1771
1772 ofstream out2;
1773 out2.open(Form("%s_merge.C", kTrainName.Data()));
1774 if (out2.bad()) {
1775 return kFALSE;
1776 }
1777 out2 << st2 << endl;
1778 Printf("<<< Patching Merging Macro");
1779
1780
1781
c38e3b95 1782 return kTRUE;
1783
1784}