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