RunOpt.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab
9 
10  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13  @ Jan 29, 2013 - CA
14  Added in preparartion for v2.8.0, when use of env. vars was phased out.
15 
16 */
17 //____________________________________________________________________________
18 
19 #include <iostream>
20 #include <cstdlib>
21 
22 #include <TMath.h>
23 #include <TBits.h>
24 
27 #include "Framework/Utils/RunOpt.h"
31 
32 using std::cout;
33 using std::endl;
34 
35 namespace genie {
36 
37  static const string gDefaultTune = "G18_02a_00_000";
38 
39 //____________________________________________________________________________
40 ostream & operator << (ostream & stream, const RunOpt & opt)
41 {
42  opt.Print(stream);
43  return stream;
44 }
45 //____________________________________________________________________________
47 //____________________________________________________________________________
48 RunOpt::RunOpt() : fTune(0)
49 {
50  fInstance = 0;
51 
52  this->Init();
53 }
54 //____________________________________________________________________________
56 {
57  if ( fTune ) delete fTune ;
58  if ( fUnphysEventMask ) delete fUnphysEventMask ;
59  fInstance = 0;
60 }
61 //____________________________________________________________________________
63 {
64  if(fInstance == 0) {
65  static RunOpt::Cleaner cleaner;
67  fInstance = new RunOpt;
68  }
69  return fInstance;
70 }
71 //____________________________________________________________________________
72 void RunOpt::Init(void)
73 {
74  fTune = 0 ;
76  fCacheFile = "";
77  fMesgThresholds = "";
78  fUnphysEventMask = new TBits(GHepFlags::NFlags());
79 //fUnphysEventMask->ResetAllBits(true);
80  for(unsigned int i = 0; i < GHepFlags::NFlags(); i++) {
81  fUnphysEventMask->SetBitNumber(i, true);
82  }
85  fEventGeneratorList = "Default";
86  fXMLPath = "";
87 }
88 //____________________________________________________________________________
89 void RunOpt::SetTuneName(string tuneName)
90 {
91  if ( tuneName == "Default" || tuneName == "" ) tuneName = gDefaultTune;
92  if ( fTune ) {
93  LOG("RunOpt",pNOTICE) << "RunOpt::SetTune() already had " << fTune->Name()
94  << ", now being re-set to " << tuneName;
95  delete fTune;
96  }
97  fTune = new TuneId( tuneName ) ;
98 }
99 //____________________________________________________________________________
101 {
102  LOG("RunOpt",pINFO) << "Building tune "<<Tune()->Name();
103  Tune()->Build() ;
105 }
106 //____________________________________________________________________________
107 void RunOpt::ReadFromCommandLine(int argc, char ** argv)
108 {
109  LOG("RunOpt",pDEBUG) << "Reading "<<argc-1<<" command line arguments.";
110  CmdLnArgParser parser(argc,argv);
111 
112  if( parser.OptionExists("enable-bare-xsec-pre-calc") ) {
113  fEnableBareXSecPreCalc = true;
114  } else
115  if( parser.OptionExists("disable-bare-xsec-pre-calc") ) {
116  fEnableBareXSecPreCalc = false;
117  }
118 
119  if( parser.OptionExists("cache-file") ) {
120  fCacheFile = parser.ArgAsString("cache-file");
121  }
122 
123  if( parser.OptionExists("message-thresholds") ) {
124  fMesgThresholds = parser.ArgAsString("message-thresholds");
125  }
126 
127  if( parser.OptionExists("event-record-print-level") ) {
128  fEventRecordPrintLevel = parser.ArgAsInt("event-record-print-level");
129  }
130 
131  if( parser.OptionExists("mc-job-status-refresh-rate") ) {
132  fMCJobStatusRefreshRate = TMath::Max(
133  1, parser.ArgAsInt("mc-job-status-refresh-rate"));
134  }
135 
136  if( parser.OptionExists("event-generator-list") ) {
137  SetEventGeneratorList(parser.ArgAsString("event-generator-list"));
138  }
139 
140  if (parser.OptionExists("xml-path")) {
141  fXMLPath = parser.ArgAsString("xml-path");
142  }
143 
144  if( parser.OptionExists("tune") ) {
145  SetTuneName( parser.ArgAsString("tune") ) ;
146  }
147  else {
148  SetTuneName( "Default" );
149  }// else ( parser.OptionExists("tune") )
150 
151  if( parser.OptionExists("unphysical-event-mask") ) {
152  const char * bitfield =
153  parser.ArgAsString("unphysical-event-mask").c_str();
154  unsigned int n = GHepFlags::NFlags();
155  unsigned int i = 0;
156  while (i < n) {
157  bool flag = (bitfield[i]=='1');
158  fUnphysEventMask->SetBitNumber(n-1-i,flag);
159  i++;
160  } //i
161  }
162 
163 }
164 //____________________________________________________________________________
165 void RunOpt::Print(ostream & stream) const
166 {
167  stream << "Global running options:";
168  if ( fTune ) stream << "\n GENIE tune: " << *fTune;
169  stream << "\n Event generator list: " << fEventGeneratorList;
170  stream << "\n User-specified message thresholds : " << fMesgThresholds;
171  stream << "\n Cache file : " << fCacheFile;
172  stream << "\n Unphysical event mask (bits: "
173  << GHepFlags::NFlags()-1 << " -> 0) : " << *fUnphysEventMask;
174  stream << "\n Event record print level : " << fEventRecordPrintLevel;
175  stream << "\n MC job status file refresh rate: " << fMCJobStatusRefreshRate;
176  stream << "\n Pre-calculate all free-nucleon cross-sections? : "
177  << ((fEnableBareXSecPreCalc) ? "Yes" : "No");
178 
179  if (fXMLPath.size()) {
180  stream << "\n XMLPath over-ride : "<<fXMLPath;
181  }
182 
183  stream << "\n";
184 }
185 //___________________________________________________________________________
186 
187 } // genie namespace
TuneId * Tune(void) const
Definition: RunOpt.h:45
string Name(void) const
Definition: TuneId.h:47
static RunOpt * fInstance
Definition: RunOpt.h:84
string ArgAsString(char opt)
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
string fMesgThresholds
List of files (delimited with : if more than one) with custom mesg stream thresholds.
Definition: RunOpt.h:75
void ReadFromCommandLine(int argc, char **argv)
Definition: RunOpt.cxx:107
string fCacheFile
Name of cache file, is cache is to be re-used.
Definition: RunOpt.h:74
static XSecSplineList * Instance()
int fEventRecordPrintLevel
GHEP event r ecord print level.
Definition: RunOpt.h:77
void SetCurrentTune(const string &tune)
static const string gDefaultTune
Definition: RunOpt.cxx:37
void SetEventGeneratorList(string evgenlist)
Definition: RunOpt.h:60
void Init(void)
Definition: RunOpt.cxx:72
Some common run-time GENIE options.
Definition: RunOpt.h:36
TBits * fUnphysEventMask
Unphysical event mask.
Definition: RunOpt.h:76
static unsigned int NFlags(void)
Definition: GHepFlags.h:77
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
int fMCJobStatusRefreshRate
MC job status file refresh rate.
Definition: RunOpt.h:78
TuneId * fTune
GENIE comprehensive neutrino interaction model tune.
Definition: RunOpt.h:72
#define pINFO
Definition: Messenger.h:63
void BuildTune()
build tune and inform XSecSplineList
Definition: RunOpt.cxx:100
bool fEnableBareXSecPreCalc
Definition: RunOpt.h:79
string fEventGeneratorList
Name of event generator list to be loaded by the event generation drivers.
Definition: RunOpt.h:73
virtual ~RunOpt()
Definition: RunOpt.cxx:55
OStream cout
Definition: OStream.cxx:6
static RunOpt * Instance(void)
Definition: RunOpt.cxx:62
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
GENIE tune ID.
Definition: TuneId.h:38
Command line argument parser.
#define pNOTICE
Definition: Messenger.h:62
void Build(const string &name="")
Definition: TuneId.cxx:125
void DummyMethodAndSilentCompiler()
Definition: RunOpt.h:93
bool OptionExists(char opt)
was option set?
void Print(ostream &stream) const
Definition: RunOpt.cxx:165
void SetTuneName(string tuneName="Default")
Definition: RunOpt.cxx:89
string fXMLPath
An path to look for XML in. Higher priority than GXMLPATH.
Definition: RunOpt.h:81
#define pDEBUG
Definition: Messenger.h:64