AliPhysics  ff1d528 (ff1d528)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BaseConfig.C
Go to the documentation of this file.
1 
10 //====================================================================
16 {
17  virtual Bool_t UseABSO() const { return true; }
18  virtual Bool_t UseACORDE() const { return false; }
19  virtual Bool_t UseDIPO() const { return true; }
20  virtual Bool_t UseEMCAL() const { return true; }
21  virtual Bool_t UseFMD() const { return true; }
22  virtual Bool_t UseFRAME() const { return true; }
23  virtual Bool_t UseHALL() const { return true; }
24  virtual Bool_t UseITS() const { return true; }
25  virtual Bool_t UseMAG() const { return true; }
26  virtual Bool_t UseMUON() const { return true; }
27  virtual Bool_t UsePHOS() const { return true; }
28  virtual Bool_t UsePIPE() const { return true; }
29  virtual Bool_t UsePMD() const { return true; }
30  virtual Bool_t UseHMPID() const { return true; }
31  virtual Bool_t UseSHIL() const { return true; }
32  virtual Bool_t UseT0() const { return true; }
33  virtual Bool_t UseTOF() const { return true; }
34  virtual Bool_t UseTPC() const { return true; }
35  virtual Bool_t UseTRD() const { return true; }
36  virtual Bool_t UseVZERO() const { return true; }
37  virtual Bool_t UseZDC() const { return true; }
38  virtual void Print()
39  {
40  Printf("ABSO: %3s", UseABSO() ? "yes" : "no");
41  Printf("ACORDE: %3s", UseACORDE() ? "yes" : "no");
42  Printf("DIPO: %3s", UseDIPO() ? "yes" : "no");
43  Printf("EMCAL: %3s", UseEMCAL() ? "yes" : "no");
44  Printf("FMD: %3s", UseFMD() ? "yes" : "no");
45  Printf("FRAME: %3s", UseFRAME() ? "yes" : "no");
46  Printf("HALL: %3s", UseHALL() ? "yes" : "no");
47  Printf("ITS: %3s", UseITS() ? "yes" : "no");
48  Printf("MAG: %3s", UseMAG() ? "yes" : "no");
49  Printf("MUON: %3s", UseMUON() ? "yes" : "no");
50  Printf("PHOS: %3s", UsePHOS() ? "yes" : "no");
51  Printf("PIPE: %3s", UsePIPE() ? "yes" : "no");
52  Printf("PMD: %3s", UsePMD() ? "yes" : "no");
53  Printf("HMPID: %3s", UseHMPID() ? "yes" : "no");
54  Printf("SHIL: %3s", UseSHIL() ? "yes" : "no");
55  Printf("T0: %3s", UseT0() ? "yes" : "no");
56  Printf("TOF: %3s", UseTOF() ? "yes" : "no");
57  Printf("TPC: %3s", UseTPC() ? "yes" : "no");
58  Printf("TRD: %3s", UseTRD() ? "yes" : "no");
59  Printf("VZERO: %3s", UseVZERO() ? "yes" : "no");
60  Printf("ZDC: %3s", UseZDC() ? "yes" : "no");
61  }
67  void GetRecoString(TString& enable) const
68  {
69  if (UseITS()) Append2Str(enable, "ITS");
70  if (UseTPC()) Append2Str(enable, "TPC");
71  if (UseTRD()) Append2Str(enable, "TRD");
72  if (UseTOF()) Append2Str(enable, "TOF");
73  if (UsePHOS()) Append2Str(enable, "PHOS");
74  if (UseHMPID()) Append2Str(enable, "HMPID");
75  if (UseEMCAL()) Append2Str(enable, "EMCAL");
76  if (UseMUON()) Append2Str(enable, "MUON");
77  if (UseFMD()) Append2Str(enable, "FMD");
78  if (UseZDC()) Append2Str(enable, "ZDC");
79  if (UsePMD()) Append2Str(enable, "PMD");
80  if (UseT0()) Append2Str(enable, "T0");
81  if (UseVZERO()) Append2Str(enable, "VZERO");
82  }
89  void GetSDigitString(TString& sDigits) const
90  {
91  if (UseTRD()) Append2Str(sDigits, "TRD");
92  if (UseTOF()) Append2Str(sDigits, "TOF");
93  if (UsePHOS()) Append2Str(sDigits, "PHOS");
94  if (UseHMPID()) Append2Str(sDigits, "HMPID");
95  if (UseEMCAL()) Append2Str(sDigits, "EMCAL");
96  if (UseMUON()) Append2Str(sDigits, "MUON");
97  if (UseFMD()) Append2Str(sDigits, "FMD");
98  if (UseZDC()) Append2Str(sDigits, "ZDC");
99  if (UsePMD()) Append2Str(sDigits, "PMD");
100  if (UseT0()) Append2Str(sDigits, "T0");
101  if (UseVZERO()) Append2Str(sDigits, "VZERO");
102  }
109  void GetHits2DigitsString(TString& fromHits) const
110  {
111  if (UseITS()) Append2Str(fromHits, "ITS");
112  if (UseTPC()) Append2Str(fromHits, "TPC");
113  }
120  static void Append2Str(TString& str, const char* append)
121  {
122  if (!str.IsNull()) str.Append(" ");
123  str.Append(append);
124  }
133  virtual const char* GeometrySource() const
134  {
135  return 0;
136  }
137 };
140 
141 //====================================================================
146 {
152  virtual const char* Prefix() const { return ""; }
158  virtual void Init(Bool_t forSim)
159  {
160  ::Fatal("VirtualOCDBConfig", "Dummy init called - redefine!");
161  }
168  void AddStore(const char* key,
169  Bool_t ideal)
170  {
171  AliCDBManager* cdb = AliCDBManager::Instance();
172  const char* prefix = Prefix();
173  TString path = Form("alien://Folder=/alice/simulation/%s/%s",
174  prefix, !ideal ? "Residual" : "Ideal");
175  ::Info("AddStore", "%s -> %s", key, path.Data());
176  cdb->SetSpecificStorage(key, path);
177  }
178 };
179 
182 
183 //====================================================================
189 {
192  virtual ~VirtualEGCfg() {}
193  virtual Bool_t IsLego() const { return false; }
201  static const char* DeduceRunType()
202  {
203  if (grp->IsPP()) return "pythia";
204  else if (grp->IsPA() || grp->IsAP()) return "dpmjet";
205  else if (grp->IsAA()) return "hijing";
206  return "hijing";
207  }
208 
209  static void LoadLibrary(const TString& name,
210  const TString& cls="")
211  {
212  // If we're looking for a specific class, check that first, and
213  // if available, do nothing;
214  if (!cls.IsNull() && gROOT->GetClass(cls)) return;
215 
216  // Now check the list of loaded and linekd libraries
217  TString libs(gSystem->GetLibraries("", "SD"));
218 
219  // IF already in the list, do nothing
220  if (libs.Contains(name)) return;
221 
222  // Otherwise load the library
223  gSystem->Load(name);
224  }
229  static void LoadGen(const TString& runType) {
230  LoadLibrary("liblhapdf","AliStructFuncType"); // Parton density functions
231  LoadLibrary("libEGPythia6","TPythia6"); // TGenerator interface
232  if (!runType.EqualTo("hydjet", TString::kIgnoreCase))
233  LoadPythia(false);
234  }
235 
242  static void LoadPythia(Bool_t gen=true, const char* vers="6.4.21")
243  {
244  if (gen) LoadGen("");
245  char m = vers[0];
246  if (gROOT->GetClass(Form("AliPythia6%c", m))) return;
247 
248  TString v(vers);
249  v.ReplaceAll(".", "_");
250  LoadLibrary("libmicrocern");
251  LoadLibrary(Form("libpythia%s",v.Data()));
252  LoadLibrary(Form("libAliPythia%c", m));
253  }
257  static void LoadHijing()
258  {
259  LoadPythia();
260  if (gROOT->GetClass("THijing")) return;
261  LoadLibrary("libhijing");
262  LoadLibrary("libTHijing");
263  AliPDG::AddParticlesToPdgDataBase();
264  }
268  static void LoadHydjet()
269  {
270  LoadLibrary("libTUHKMgen","TUHKMgen");
271  }
272  static void LoadEposLHC()
273  {
274  LoadLibrary("libEPOSLHC","TEposLHC");
275  }
276  static void LoadEpos()
277  {
278  LoadLibrary("libEPOS","TEpos");
279  }
280  static void LoadTherminator()
281  {
282  LoadLibrary("libTTherminator","TTherminator");
283  }
287  static void LoadDpmjet()
288  {
289  LoadPythia();
290  if (gROOT->GetClass("TDPMjet")) return;
291  LoadLibrary("libdpmjet");
292  LoadLibrary("libTDPMjet");
293  }
297  static void LoadAmpt()
298  {
299  LoadPythia();
300  if (gROOT->GetClass("TAmpt")) return;
301  LoadLibrary("libampt");
302  LoadLibrary("libTAmpt");
303  }
315  AliGenerator* MakeGenerator(const TString& rt,
316  Float_t b1,
317  Float_t b2,
318  Bool_t smear=true)
319  {
320  if (rt.IsNull()) {
321  ::Fatal("MakeGenerator", "No EG spec given");
322  return 0;
323  }
324 
325  TString runType = rt;
326  runType.ToLower();
327 
328  AliGenerator* g = CreateGenerator(runType,b1,b2);
329  if (g && smear) {
330  // Origin and sigmaZ will be supplied from OCDB.
331  // We need to set the XY smearing though
332  // Numbers from Ruben
333  g->SetSigma(0.0025, 0.0029, 0);
334  g->SetVertexSmear(AliGenerator::kPerEvent);
335  }
336 
337  return g;
338  }
346  TVirtualMCDecayer* MakeDecayer(const TString& rt)
347  {
348  if (rt.IsNull()) {
349  ::Fatal("MakeGenerator", "No EG spec given");
350  return 0;
351  }
352 
353  TString runType = rt;
354  rt.ToLower();
355 
356  TVirtualMCDecayer* decayer = CreateDecayer(runType);
357 
358  if (decayer) decayer->Init();
359  return decayer;
360  }
361 protected:
371  virtual AliGenerator* CreateGenerator(const TString& runType,
372  Float_t b1,
373  Float_t b2) = 0;
381  virtual TVirtualMCDecayer* CreateDecayer(const TString& runType) = 0;
382 
383 };
386 
387 //====================================================================
393 {
394 
395 
407  const char* xmlFile = "wn.xml",
408  Int_t stage = 0,
409  const char* cdb = "raw://")
410  {
411  // --- Load configuration script ---------------------------------
412  LoadConfig();
413 
414  // --- Set-up for CDB access through Grid ------------------------
415  TString cdbString(cdb);
416  if (cdbString.Contains("raw://")) {
417  TGrid::Connect("alien://");
418  if (!gGrid || !gGrid->IsConnected()) {
419  ::Error("Run", "No grid connection");
420  return false;
421  }
422  }
423 
424  // --- Some environment variables --------------------------------
425  // Temp dir is here, and compilation is here too
426  gSystem->Setenv("TMPDIR", gSystem->pwd());
427  gSystem->SetBuildDir(gSystem->pwd(), kTRUE);
428 
429  // --- Now load common libraries ---------------------------------
431 
432  // --- Now create and configure manager --------------------------
434  "Production train");
435  mgr->SetRunFromPath(grp->run);
436 
437  // --- Create ESD input handler ------------------------------------
438  AliESDInputHandlerRP *esdHandler = new AliESDInputHandlerRP();
439  mgr->SetInputEventHandler(esdHandler);
440  if (UseFriends()) {
441  esdHandler->SetReadFriends(kTRUE);
442  esdHandler->SetActiveBranches("ESDfriend");
443  }
444 
445  // --- Monte Carlo handler -----------------------------------------
446  if (UseMC()) {
447  AliMCEventHandler* mcHandler = new AliMCEventHandler();
448  mgr->SetMCtruthEventHandler(mcHandler);
449  mcHandler->SetPreReadMode(1);
450  mcHandler->SetReadTR(true);
451  }
452  // --- AOD output handler ----------------------------------------
453  if (MakeAOD()) {
454  AliAODHandler* aodHandler = new AliAODHandler();
455  aodHandler->SetOutputFileName("AliAOD.root");
456  mgr->SetOutputEventHandler(aodHandler);
457  }
458 
459  // --- Call user routine for adding tasks ------------------------
460  if (!AddTasks()) return false;
461 
462  // --- Check if we are to merge ----------------------------------
463  if (stage > 0)
464  return Merge(xmlfile, stage);
465 
466  // --- Otherwise run the train -----------------------------------
467  TChain* chain = CreateChain();
468  if (!chain) return false;
469 
470  TStopwatch timer;
471  timer.Start();
472  if (!mgr->InitAnalysis()) {
473  ::Error("Run", "Failed to initialize the train");
474  return false;
475  }
476 
477  mgr->PrintStatus();
478  mgr->SetSkipTerminate(kTRUE);
479  mgr->StartAnalysis("local", chain);
480  timer.Print();
481 
482  }
491  Bool_t Merge(const char* dir, Int_t stage)
492  {
493 
494  TStopwatch timer;
495  timer.Start();
496  TString outputDir = dir;
497  Bool_t final = outputDir.Contains("Stage");
498  TCollection* outputFiles = GetFilesToMerge(stage, final);
499  if (!outputFiles) {
500  ::Warning("Merge", "Nothing to merge");
501  return true;
502  }
503  TIter iter(outputFiles);
504  TObjString* str = 0;
505  Bool_t merged = kTRUE;
506  while((str = static_cast<TObjString*>(iter()))) {
507  TString& outputFile = str->GetString();
508  // Skip already merged outputs
509  if (!gSystem->AccessPathName(outputFile)) {
510  ::Warning("Merge","Output file <%s> found. Not merging again.",
511  outputFile.Data());
512  continue;
513  }
514  merged = AliAnalysisAlien::MergeOutput(outputFile,
515  outputDir,
516  10,
517  stage);
518  if (merged) continue;
519 
520  ::Error("Merge", "Cannot merge %s\n", outputFile.Data());
521  }
522  // --- possible merge file information files ---------------------
523  if (MergeFileInfo()) {
524  TString infolog = "fileinfo.log";
525  AliAnalysisAlien::MergeInfo(infolog, dir);
526  }
527 
528  // --- If not final stage, get out here --------------------------
529  if (!final) {
530  ValidateOutput();
531  timer.Print();
532  return true;
533  }
534 
535  // --- set up and run termiante ----------------------------------
536  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
537  mgr->SetSkipTerminate(kFALSE);
538  if (!mgr->InitAnalysis()) {
539  ::Error("Merge", "Failed to initialize the train");
540  return false;
541  }
542 
543  mgr->PrintStatus();
544  mgr->StartAnalysis("gridterminate", (TTree*)0);
545  ValidateOutput();
546  timer.Print();
547 
548  return true;
549  }
550 
558  Bool_t LoadLibrary(const char *module)
559  {
560  // Load a module library in a given mode. Reports success.
561  Int_t result = 0;
562  TString mod(module);
563  ::Info("LoadLibrary", "Loading %s", module);
564  gROOT->IncreaseDirLevel();
565 
566  if (mod.IsNull()) {
567  ::Error("LoadLibrary", "Empty module name");
568  gROOT->DecreaseDirLevel();
569  return kFALSE;
570  }
571 
572  // If a library is specified, just load it
573  if (mod.EndsWith(".so")) {
574  mod.Remove(mod.Index(".so"));
575  ::Info("LoadLibrary", "Loading .so: %s", mod.Data());
576  result = gSystem->Load(mod);
577  if (result < 0) {
578  ::Error("oadLibrary", "Could not load library %s", module);
579  }
580  gROOT->DecreaseDirLevel();
581  return (result >= 0);
582  }
583  // Check if the library is already loaded
584  if (strlen(gSystem->GetLibraries(module, "", kFALSE)) > 0) {
585  ::Info("LoadLibrary", "Module %s.so already loaded", module);
586  gROOT->DecreaseDirLevel();
587  return kTRUE;
588  }
589 
590  ::Info("LoadLibrary", "Trying to load lib%s.so", module);
591  result = gSystem->Load(Form("lib%s", module));
592  if (result < 0)
593  ::Error("LoadLibrary", "Could not load module %s", module);
594  ::Info("LoadLibrary", "Module %s, successfully loaded", module);
595  gROOT->DecreaseDirLevel();
596  return (result >= 0);
597  }
604  {
605  // Load common analysis libraries.
606  if (!gSystem->Getenv("ALICE_PHYSICS")) {
607  ::Error("LoadBaseLibraries",
608  "Analysis trains requires that analysis libraries are "
609  "compiled with a local AliRoot");
610  return false;
611  }
612 
613  Bool_t success = true;
614  // Load framework classes. Par option ignored here.
615  success &= LoadLibrary("libSTEERBase.so");
616  success &= LoadLibrary("libESD.so");
617  success &= LoadLibrary("libAOD.so");
618  success &= LoadLibrary("libANALYSIS.so");
619  success &= LoadLibrary("libOADB.so");
620  success &= LoadLibrary("libANALYSISalice.so");
621  success &= LoadLibrary("libESDfilter.so");
622  success &= LoadLibrary("libCORRFW.so");
623  success &= LoadLibrary("libPWGPP.so");
624  gROOT->ProcessLine(".include $ALICE_PHYSICS/include");
625  if (success) {
626  ::Info("LoadBaseLibraries",
627  "Load common libraries: SUCCESS");
628  ::Info("LoadBaseLibraries",
629  "Include path for Aclic compilation:\n%s",
630  gSystem->GetIncludePath());
631  } else {
632  ::Info("LoadBaseLibraries",
633  "Load common libraries: FAILED");
634  }
635  return success;
636  }
643  {
644  if (gSystem->AccessPathName("AliESDs.root")) {
645  ::Error("CreateChain",
646  "File: AliESDs.root not in ./data dir");
647  return 0;
648  }
649 
650  // Create the input chain
651  TChain* chain = new TChain("esdTree");
652  chain->Add("AliESDs.root");
653  if (!chain->GetNtrees()) {
654  delete chain;
655  chain = 0;
656  }
657 
658  return chain;
659  }
665  {
666  std::ofstream out;
667  out.open("outputs_valid", ios::out);
668  out.close();
669  }
670 
678  virtual void LoadConfig() {};
684  virtual const char* GetName() const { return "dummy"; }
690  virtual Bool_t UseFriends() const { return false; }
696  virtual Bool_t UseMC() const { return false; }
702  virtual Bool_t MakeAOD() const { return false; }
709  virtual Bool_t AddTasks() const { return true; }
715  virtual Bool_t MergeFileInfo() const { return false; }
724  virtual TCollection* GetFilesToMerge(Int_t stage, Bool_t final) const
725  {
726  return 0;
727  }
728 };
729 
730 
731 
732 
733 //====================================================================
739 {
740  Info("", "Defined base classes for configuration");
741 }
742 //
743 // EOF
744 //
745 
virtual Bool_t UseFRAME() const
Definition: BaseConfig.C:22
UInt_t run
Definition: GRP.C:102
return jsonbuilder str().c_str()
virtual const char * Prefix() const
Definition: BaseConfig.C:152
virtual Bool_t UseMAG() const
Definition: BaseConfig.C:25
virtual Bool_t LoadBaseLibraries()
Definition: BaseConfig.C:603
virtual const char * GeometrySource() const
Definition: BaseConfig.C:133
virtual Bool_t UseSHIL() const
Definition: BaseConfig.C:31
virtual TCollection * GetFilesToMerge(Int_t stage, Bool_t final) const
Definition: BaseConfig.C:724
static void LoadTherminator()
Definition: BaseConfig.C:280
virtual Bool_t UsePMD() const
Definition: BaseConfig.C:29
void ValidateOutput()
Definition: BaseConfig.C:664
virtual Bool_t UsePIPE() const
Definition: BaseConfig.C:28
virtual void Print()
Definition: BaseConfig.C:38
virtual Bool_t UseDIPO() const
Definition: BaseConfig.C:19
virtual Bool_t UseHALL() const
Definition: BaseConfig.C:23
Bool_t Run(UInt_t run, const char *xmlFile="wn.xml", Int_t stage=0, const char *cdb="raw://")
Definition: BaseConfig.C:406
static const char * DeduceRunType()
Definition: BaseConfig.C:201
virtual Bool_t UseMC() const
Definition: BaseConfig.C:696
Bool_t LoadLibrary(const char *module)
Definition: BaseConfig.C:558
Bool_t IsPA() const
Definition: GRP.C:147
void BaseConfig()
Definition: BaseConfig.C:738
TSystem * gSystem
TVirtualMCDecayer * MakeDecayer(const TString &rt)
Definition: BaseConfig.C:346
virtual Bool_t IsLego() const
Definition: BaseConfig.C:193
virtual void Init(Bool_t forSim)
Definition: BaseConfig.C:158
virtual Bool_t UseFMD() const
Definition: BaseConfig.C:21
static void LoadAmpt()
Definition: BaseConfig.C:297
void GetRecoString(TString &enable) const
Definition: BaseConfig.C:67
virtual Bool_t UseT0() const
Definition: BaseConfig.C:32
virtual Bool_t UseABSO() const
Definition: BaseConfig.C:17
virtual Bool_t UsePHOS() const
Definition: BaseConfig.C:27
virtual Bool_t UseMUON() const
Definition: BaseConfig.C:26
Bool_t IsAA() const
Definition: GRP.C:159
VirtualOCDBCfg * ocdbCfg
Definition: BaseConfig.C:181
int Int_t
Definition: External.C:63
virtual Bool_t UseACORDE() const
Definition: BaseConfig.C:18
unsigned int UInt_t
Definition: External.C:33
float Float_t
Definition: External.C:68
virtual Bool_t MergeFileInfo() const
Definition: BaseConfig.C:715
virtual Bool_t UseTPC() const
Definition: BaseConfig.C:34
void AddStore(const char *key, Bool_t ideal)
Definition: BaseConfig.C:168
static void LoadGen(const TString &runType)
Definition: BaseConfig.C:229
virtual ~VirtualEGCfg()
Definition: BaseConfig.C:192
VirtualEGCfg * egCfg
Definition: BaseConfig.C:385
virtual Bool_t MakeAOD() const
Definition: BaseConfig.C:702
void GetHits2DigitsString(TString &fromHits) const
Definition: BaseConfig.C:109
TString runType
Definition: BaseConfig.C:190
static void LoadDpmjet()
Definition: BaseConfig.C:287
virtual Bool_t UseFriends() const
Definition: BaseConfig.C:690
static void LoadEposLHC()
Definition: BaseConfig.C:272
virtual Bool_t UseITS() const
Definition: BaseConfig.C:24
GRPData * grp
Definition: GRP.C:361
Bool_t IsPP() const
Definition: GRP.C:141
Bool_t Merge(const char *dir, Int_t stage)
Definition: BaseConfig.C:491
virtual Bool_t UseTRD() const
Definition: BaseConfig.C:35
virtual Bool_t UseVZERO() const
Definition: BaseConfig.C:36
virtual const char * GetName() const
Definition: BaseConfig.C:684
virtual Bool_t UseZDC() const
Definition: BaseConfig.C:37
VirtualDetCfg * detCfg
Definition: BaseConfig.C:139
virtual Bool_t UseEMCAL() const
Definition: BaseConfig.C:20
virtual AliGenerator * CreateGenerator(const TString &runType, Float_t b1, Float_t b2)=0
static void LoadLibrary(const TString &name, const TString &cls="")
Definition: BaseConfig.C:209
virtual void LoadConfig()
Definition: BaseConfig.C:678
static void LoadPythia(Bool_t gen=true, const char *vers="6.4.21")
Definition: BaseConfig.C:242
virtual Bool_t AddTasks() const
Definition: BaseConfig.C:709
bool Bool_t
Definition: External.C:53
static void LoadHijing()
Definition: BaseConfig.C:257
static void Append2Str(TString &str, const char *append)
Definition: BaseConfig.C:120
static void LoadEpos()
Definition: BaseConfig.C:276
Bool_t IsAP() const
Definition: GRP.C:153
virtual TVirtualMCDecayer * CreateDecayer(const TString &runType)=0
virtual Bool_t UseTOF() const
Definition: BaseConfig.C:33
static void LoadHydjet()
Definition: BaseConfig.C:268
virtual Bool_t UseHMPID() const
Definition: BaseConfig.C:30
void GetSDigitString(TString &sDigits) const
Definition: BaseConfig.C:89
TChain * CreateChain()
Definition: BaseConfig.C:642
AliGenerator * MakeGenerator(const TString &rt, Float_t b1, Float_t b2, Bool_t smear=true)
Definition: BaseConfig.C:315