FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGenericVMCConfig.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- FairGenericVMCConfigurce file -----
10 // ----- Created 2019.02.19 by R. Karabowicz -----
11 // -------------------------------------------------------------------------
12 #include "FairGenericVMCConfig.h"
13 
14 #include "FairLogger.h"
15 #include "FairRunSim.h"
16 
17 #include <TROOT.h>
18 
20  : fPostInitFlag(false)
21  , fPostInitName("g4ConfigPostInit.C")
22 {}
23 
25 
26 void FairGenericVMCConfig::Setup(const char* mcEngine)
27 {
28  LOG(warning) << "FairGenericVMCConfig::Setup() Using gConfig.C macro DEPRACATED.";
29  LOG(warning) << "Check FairRoot/examples/common/gconfig/ for current YAML implementation.";
30 
31  TString lUserCuts = FairRunSim::Instance()->GetUserCuts();
32  TString lUserConfig = FairRunSim::Instance()->GetUserConfig();
33 
34  TString work = getenv("VMCWORKDIR");
35  TString work_config = work + "/gconfig/";
36  work_config.ReplaceAll("//", "/");
37 
38  TString Lib_config = getenv("GEANT4VMC_MACRO_DIR");
39  Lib_config.ReplaceAll("//", "/");
40  if (!Lib_config.EndsWith("/") && !Lib_config.IsNull()) {
41  Lib_config += "/";
42  }
43 
44  TString config_dir = getenv("CONFIG_DIR");
45  config_dir.ReplaceAll("//", "/");
46 
47  Bool_t AbsPath = kFALSE;
48 
49  TString LibMacro;
50  TString LibFunction;
51  TString ConfigMacro;
52  TString cuts = lUserCuts;
53  //----------------------------------------------Geant4 Config-----------------------------------------
54  if (strcmp(mcEngine, "TGeant4") == 0) {
55  TString g4LibMacro = "g4libs.C";
56  TString g4Macro;
57  if (lUserConfig.IsNull()) {
58  g4Macro = "g4Config.C";
59  lUserConfig = g4Macro;
60  } else {
61  if (lUserConfig.Contains("/")) {
62  AbsPath = kTRUE;
63  }
64  g4Macro = lUserConfig;
65  LOG(info) << "---------------User config is used: " << g4Macro.Data();
66  }
67  if (TString(gSystem->FindFile(config_dir.Data(), g4LibMacro))
68  != TString("")) { // be carfull after this call the string g4LibMacro is empty if not found!!!!
69  LOG(info) << "---User path for Configuration (g4libs.C) is used: " << config_dir.Data();
70  LibMacro = g4LibMacro;
71  } else if (gSystem->AccessPathName((Lib_config + "g4libs.C").Data()) == false) {
72  // Note: file is existing if AccessPathName return false
73  LOG(info) << "---G4VMC macro path for Configuration (g4libs.C) is used: " << Lib_config.Data();
74  LibMacro = Lib_config + "g4libs.C";
75  }
76  LibFunction = "g4libs()";
77  if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), g4Macro)) != TString("")) {
78  LOG(info) << "---User path for Configuration (g4Config.C) is used: " << config_dir.Data();
79  ConfigMacro = g4Macro;
80  } else {
81  if (AbsPath) {
82  ConfigMacro = lUserConfig;
83  } else {
84  ConfigMacro = work_config + lUserConfig;
85  }
86  }
87  //----------------------------------------------Geant3 Config-----------------------------------------
88  } else if (strcmp(mcEngine, "TGeant3") == 0) {
89  TString g3LibMacro = "g3libs.C";
90  TString g3Macro = "g3Config.C";
91  if (lUserConfig.IsNull()) {
92  g3Macro = "g3Config.C";
93  lUserConfig = g3Macro;
94  LOG(info) << "-------------- Standard Config is called ------------------------------------";
95  } else {
96  if (lUserConfig.Contains("/")) {
97  AbsPath = kTRUE;
98  }
99  g3Macro = lUserConfig;
100  LOG(info) << "---------------User config is used: " << g3Macro.Data();
101  }
102  if (TString(gSystem->FindFile(config_dir.Data(), g3LibMacro)) != TString("")) {
103  LOG(info) << "---User path for Configuration (g3libs.C) is used: " << config_dir.Data();
104  LibMacro = g3LibMacro;
105  } else if (gSystem->AccessPathName((work_config + "g3libs.C").Data()) == false) {
106  // Note: file is existing if AccessPathName return false
107  LOG(info) << "---VMCWORKDIR path for Configuration (g3libs.C) is used: " << work_config.Data();
108  LibMacro = work_config + "g3libs.C";
109  }
110  LibFunction = "g3libs()";
111  if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), g3Macro)) != TString("")) {
112  LOG(info) << "---User path for Configuration (g3Config.C) is used: " << config_dir.Data();
113  ConfigMacro = g3Macro;
114  } else {
115  if (AbsPath) {
116  ConfigMacro = lUserConfig;
117  } else {
118  ConfigMacro = work_config + lUserConfig;
119  }
120  }
121  //----------------------------------------------Fluka Config-----------------------------------------
122  } else if (strcmp(mcEngine, "TFluka") == 0) {
123  TString flLibMacro = "fllibs.C";
124  TString flMacro = "flConfig.C";
125  if (lUserConfig.IsNull()) {
126  flMacro = "flConfig.C";
127  lUserConfig = flMacro;
128  } else {
129  if (lUserConfig.Contains("/")) {
130  AbsPath = kTRUE;
131  }
132  flMacro = lUserConfig;
133  LOG(info) << "---------------User config is used: " << flMacro.Data();
134  }
135  if (TString(gSystem->FindFile(config_dir.Data(), flLibMacro)) != TString("")) {
136  LOG(info) << "---User path for Configuration (fllibs.C) is used: " << config_dir.Data();
137  } else {
138  flLibMacro = work_config + "fllibs.C";
139  }
140  LibMacro = flLibMacro;
141  LibFunction = "fllibs()";
142  if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), flMacro)) != TString("")) {
143  LOG(info) << "---User path for Configuration (flConfig.C) is used: " << config_dir.Data();
144  ConfigMacro = flMacro;
145  } else {
146  if (AbsPath) {
147  ConfigMacro = lUserConfig;
148  } else {
149  ConfigMacro = work_config + lUserConfig;
150  }
151  }
152  }
153  //----------------------------------------------SetCuts------------------------------------------------
154  if (TString(gSystem->FindFile(config_dir.Data(), cuts)) != TString("")) {
155  LOG(info) << "---User path for Cuts and Processes (SetCuts.C) is used: " << config_dir.Data();
156  } else {
157  cuts = work_config + lUserCuts;
158  }
159  //--------------------------------------Now load the Config and Cuts------------------------------------
160  if (!LibMacro.IsNull()) {
161  gROOT->LoadMacro(LibMacro.Data());
162  gROOT->ProcessLine(LibFunction.Data());
163  }
164 
165  gROOT->LoadMacro(ConfigMacro.Data());
166  gROOT->ProcessLine("Config()");
167 
168  gROOT->LoadMacro(cuts);
169  gROOT->ProcessLine("SetCuts()");
170 }
171 
172 void FairGenericVMCConfig::SetupPostInit(const char* mcEngine)
173 {
174  if (!fPostInitFlag) {
175  LOG(info) << "FairGenericVMCConfig::SetupPostInit() OFF.";
176  return;
177  }
178 
179  LOG(warning) << "FairGenericVMCConfig::SetupPostInit() Using " << fPostInitName << " macro DEPRACATED.";
180  LOG(warning) << "Check FairRoot/examples/common/gconfig/ for current YAML implementation.";
181 
182  TString work = getenv("VMCWORKDIR");
183  TString work_config = work + "/gconfig/";
184  work_config.ReplaceAll("//", "/");
185 
186  TString config_dir = getenv("CONFIG_DIR");
187  config_dir.ReplaceAll("//", "/");
188 
189  Bool_t AbsPath = kFALSE;
190 
191  TString ConfigMacro;
192  //----------------------------------------------Geant4 Config PostInit-----------------------------------------
193  if (strcmp(mcEngine, "TGeant4") == 0) {
194  TString g4Macro;
195  if (fPostInitName.empty()) {
196  g4Macro = "g4ConfigPostInit.C";
197  fPostInitName = g4Macro;
198  } else {
199  if (fPostInitName.find("/") != std::string::npos) {
200  AbsPath = kTRUE;
201  }
202  g4Macro = fPostInitName;
203  LOG(info) << "---------------User config is used: " << g4Macro.Data();
204  }
205  if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), g4Macro)) != TString("")) {
206  LOG(info) << "---User path for Configuration (" << fPostInitName << ".C) is used: " << config_dir.Data();
207  ConfigMacro = g4Macro;
208  } else {
209  if (AbsPath) {
210  ConfigMacro = fPostInitName;
211  } else {
212  ConfigMacro = work_config + fPostInitName;
213  }
214  }
215  //----------------------------------------------Geant3 Config PostInit-----------------------------------------
216  } else if (strcmp(mcEngine, "TGeant3") == 0) {
217  //----------------------------------------------Fluka Config PostInit-----------------------------------------
218  } else if (strcmp(mcEngine, "TFluka") == 0) {
219  }
220  //--------------------------------------Now load the Config------------------------------------
221  if (ConfigMacro.Length() > 0) {
222  LOG(info) << " SetupPostInit -> \"" << ConfigMacro.Data() << "\"";
223  gROOT->LoadMacro(ConfigMacro.Data());
224  gROOT->ProcessLine("ConfigPostInit()");
225  }
226 }
227 
virtual void Setup(const char *mcEngine)
TString GetUserConfig()
Definition: FairRunSim.h:151
static FairRunSim * Instance()
Definition: FairRunSim.cxx:116
ClassImp(FairEventBuilder)
virtual void SetupPostInit(const char *mcEngine)
TString GetUserCuts()
Definition: FairRunSim.h:154