GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AppInit.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <c.andreopoulos \at cern.ch>
7  University of Liverpool
8 */
9 //____________________________________________________________________________
10 
11 // for exit()
12 #include <cstdlib>
13 
14 #include <TSystem.h>
15 
16 //#include "Framework/Conventions/XmlParserStatus.h"
19 #include "Framework/Utils/Cache.h"
25 
26 using namespace genie;
27 
28 //___________________________________________________________________________
29 
31 {
32  // Set random number seed, if a value was set at the command-line.
33  if(seed > 0) {
35  }
36 }
37 //___________________________________________________________________________
38 void genie::utils::app_init::XSecTable (string inpfile, bool require_table)
39 {
40  // Load cross-section splines using file specified at the command-line.
41 
43 
44  // don't try to expand if no filename actually given ...
45  string expandedinpfile = "";
46  string fullinpfile = "";
47  if ( inpfile != "" ) {
48  // expand in case of embedded env var or ~
49  expandedinpfile = gSystem->ExpandPathName(inpfile.c_str());
50  if (utils::system::FileExists(expandedinpfile)) {
51  // use the file as given if possible
52  fullinpfile = expandedinpfile;
53  } else {
54  // look for file in $GXMLPATH, then $GENIE/config
55  // return input name if not found any of those places (thus allowing CWD)
56  fullinpfile = genie::utils::xml::GetXMLFilePath(expandedinpfile);
57  }
58  }
59 
60  // file was specified & exists - load table
61  if (utils::system::FileExists(fullinpfile)) {
62  xspl = XSecSplineList::Instance();
63  XmlParserStatus_t status = xspl->LoadFromXml(fullinpfile);
64  if (status != kXmlOK) {
65  LOG("AppInit", pFATAL)
66  << "Problem reading file: " << expandedinpfile;
67  gAbortingInErr = true;
68  exit(1);
69  }
70  }
71 
72  // file doesn't exist
73  else {
74  // if one was specified, report & exit
75  if (inpfile.size() > 0) {
76  LOG("AppInit", pFATAL)
77  << "Input cross-section file [" << inpfile << "] does not exist!\n"
78  << "looked for " << expandedinpfile << " in $GXMLPATH locations ";
79  gAbortingInErr = true;
80  exit(1);
81  }
82  // if one was not specified, warn and decide whether to exit based on the
83  // input `require_table' flag
84  else {
85  if(!require_table) {
86  LOG("AppInit", pWARN) << "No cross-section file was specified in the application inputs";
87  LOG("AppInit", pWARN) << "If none is loaded, event generation might be inefficient";
88  } else {
89  LOG("AppInit", pFATAL) << "No cross-section file was specified in the application inputs";
90  LOG("AppInit", pFATAL) << "This is mandatory as, otherwise, event generation will be prohibitively inefficient";
91  gAbortingInErr = true;
92  exit(1);
93  }
94  }
95  }
96 
97 }
98 //___________________________________________________________________________
100 {
101  std::vector<std::string> files = genie::utils::str::Split(filelist,":;,");
102  for (size_t i=0; i < files.size(); ++i ) {
103  std::string inp_file = files[i];
104  if(inp_file.size() > 0) {
106  bool ok = m->SetPrioritiesFromXmlFile(inp_file);
107  if(!ok) {
108  LOG("AppInit", pWARN)
109  << "Could not load customized mesg thresholds from: "
110  << inp_file;
111  }
112  }
113  }
114 
115 }
116 //___________________________________________________________________________
118 {
119  if(inp_file.size() > 0) {
120  Cache::Instance()->OpenCacheFile(inp_file);
121  }
122 }
123 //___________________________________________________________________________
void RandGen(long int seed)
Definition: AppInit.cxx:30
void XSecTable(string inpfile, bool require_table)
Definition: AppInit.cxx:38
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:71
bool FileExists(string filename)
Definition: SystemUtils.cxx:80
#define pFATAL
Definition: Messenger.h:56
static XSecSplineList * Instance()
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void OpenCacheFile(string filename)
cache file
Definition: Cache.cxx:183
bool SetPrioritiesFromXmlFile(string filename)
Definition: Messenger.cxx:114
static Messenger * Instance(void)
Definition: Messenger.cxx:49
string GetXMLFilePath(string basename)
#define pWARN
Definition: Messenger.h:60
A more convenient interface to the log4cpp Message Service.
Definition: Messenger.h:258
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
static Cache * Instance(void)
Definition: Cache.cxx:67
enum genie::EXmlParseStatus XmlParserStatus_t
bool gAbortingInErr
Definition: Messenger.cxx:34
List of cross section vs energy splines.
static constexpr double m
Definition: Units.h:71
XmlParserStatus_t LoadFromXml(const string &filename, bool keep=false)
void CacheFile(string inpfile)
Definition: AppInit.cxx:117
void SetSeed(long int seed)
Definition: RandomGen.cxx:82