Functions
genie::utils::app_init Namespace Reference

Initialization code commonly occuring in GENIE apps, factored out from existing apps for convenience. Not generic GENIE initialization code. More...

Functions

void RandGen (long int seed)
 
void XSecTable (string inpfile, bool require_table)
 
void MesgThresholds (string inpfile)
 
void CacheFile (string inpfile)
 

Detailed Description

Initialization code commonly occuring in GENIE apps, factored out from existing apps for convenience. Not generic GENIE initialization code.

Author
Costas Andreopoulos <costas.andreopoulos stfc.ac.uk> University of Liverpool & STFC Rutherford Appleton Lab

January 31, 2013

Copyright (c) 2003-2019, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org or see $GENIE/LICENSE

Function Documentation

void genie::utils::app_init::CacheFile ( string  inpfile)

Definition at line 118 of file AppInit.cxx.

References genie::Cache::Instance(), and genie::Cache::OpenCacheFile().

Referenced by Initialize(), and main().

119 {
120  if(inp_file.size() > 0) {
121  Cache::Instance()->OpenCacheFile(inp_file);
122  }
123 }
void genie::utils::app_init::MesgThresholds ( string  inpfile)

Definition at line 100 of file AppInit.cxx.

References compareCafs::files, MECModelEnuComparisons::i, genie::Messenger::Instance(), LOG, m, pWARN, genie::Messenger::SetPrioritiesFromXmlFile(), and genie::utils::str::Split().

Referenced by Initialize(), main(), and supernova::SnovaGen::SnovaGen().

101 {
102  std::vector<std::string> files = genie::utils::str::Split(filelist,":;,");
103  for (size_t i=0; i < files.size(); ++i ) {
104  std::string inp_file = files[i];
105  if(inp_file.size() > 0) {
106  Messenger * m = Messenger::Instance();
107  bool ok = m->SetPrioritiesFromXmlFile(inp_file);
108  if(!ok) {
109  LOG("AppInit", pWARN)
110  << "Could not load customized mesg thresholds from: "
111  << inp_file;
112  }
113  }
114  }
115 
116 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
bool SetPrioritiesFromXmlFile(string filename)
Definition: Messenger.cxx:136
#define pWARN
Definition: Messenger.h:61
A more convenient interface to the log4cpp Message Service.
Definition: Messenger.h:261
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:42
void genie::utils::app_init::RandGen ( long int  seed)

Definition at line 31 of file AppInit.cxx.

References genie::RandomGen::Instance(), and genie::RandomGen::SetSeed().

Referenced by Initialize(), and main().

32 {
33  // Set random number seed, if a value was set at the command-line.
34  if(seed > 0) {
35  RandomGen::Instance()->SetSeed(seed);
36  }
37 }
unsigned int seed
Definition: runWimpSim.h:102
void genie::utils::app_init::XSecTable ( string  inpfile,
bool  require_table 
)

Definition at line 39 of file AppInit.cxx.

References exit(), genie::utils::system::FileExists(), genie::gAbortingInErr, genie::utils::xml::GetXMLFilePath(), genie::XSecSplineList::Instance(), genie::kXmlOK, genie::XSecSplineList::LoadFromXml(), LOG, pFATAL, pWARN, and fabricate::status.

Referenced by Initialize(), main(), and supernova::SnovaGen::SnovaGen().

40 {
41  // Load cross-section splines using file specified at the command-line.
42 
43  XSecSplineList * xspl = XSecSplineList::Instance();
44 
45  // don't try to expand if no filename actually given ...
46  string expandedinpfile = "";
47  string fullinpfile = "";
48  if ( inpfile != "" ) {
49  // expand in case of embedded env var or ~
50  expandedinpfile = gSystem->ExpandPathName(inpfile.c_str());
51  if (utils::system::FileExists(expandedinpfile)) {
52  // use the file as given if possible
53  fullinpfile = expandedinpfile;
54  } else {
55  // look for file in $GXMLPATH, then $GENIE/config
56  // return input name if not found any of those places (thus allowing CWD)
57  fullinpfile = genie::utils::xml::GetXMLFilePath(expandedinpfile);
58  }
59  }
60 
61  // file was specified & exists - load table
62  if (utils::system::FileExists(fullinpfile)) {
63  xspl = XSecSplineList::Instance();
64  XmlParserStatus_t status = xspl->LoadFromXml(fullinpfile);
65  if (status != kXmlOK) {
66  LOG("AppInit", pFATAL)
67  << "Problem reading file: " << expandedinpfile;
68  gAbortingInErr = true;
69  exit(1);
70  }
71  }
72 
73  // file doesn't exist
74  else {
75  // if one was specified, report & exit
76  if (inpfile.size() > 0) {
77  LOG("AppInit", pFATAL)
78  << "Input cross-section file [" << inpfile << "] does not exist!\n"
79  << "looked for " << expandedinpfile << " in $GXMLPATH locations ";
80  gAbortingInErr = true;
81  exit(1);
82  }
83  // if one was not specified, warn and decide whether to exit based on the
84  // input `require_table' flag
85  else {
86  if(!require_table) {
87  LOG("AppInit", pWARN) << "No cross-section file was specified in the application inputs";
88  LOG("AppInit", pWARN) << "If none is loaded, event generation might be inefficient";
89  } else {
90  LOG("AppInit", pFATAL) << "No cross-section file was specified in the application inputs";
91  LOG("AppInit", pFATAL) << "This is mandatory as, otherwise, event generation will be prohibitively inefficient";
92  gAbortingInErr = true;
93  exit(1);
94  }
95  }
96  }
97 
98 }
int status
Definition: fabricate.py:1613
bool FileExists(string filename)
Definition: SystemUtils.cxx:90
#define pFATAL
Definition: Messenger.h:57
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
string GetXMLFilePath(string basename)
#define pWARN
Definition: Messenger.h:61
exit(0)
enum genie::EXmlParseStatus XmlParserStatus_t
bool gAbortingInErr
Definition: Messenger.cxx:56
List of cross section vs energy splines.
XmlParserStatus_t LoadFromXml(const string &filename, bool keep=false)