GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gConfigDump.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \program
5 
6 \brief Dump the config for a tune in human readable format
7 
8 
9  Syntax :
10  gconfigdump [-h]
11  [--event-generator-list list_name]
12  [--tune genie_tune]
13 
14  Options :
15  [] Denotes an optional argument.
16  -h
17  Prints-out help on using gconfidump and exits.
18  --event-generator-list
19  List of event generators to load in event generation drivers.
20  [default: "Default"].
21  --tune
22  Specifies a GENIE comprehensive neutrino interaction model tune.
23  [default: "Default"].
24 
25  *** See the User Manual for more details and examples. ***
26 
27 \author Robert Hatcher <rhatcher \at fnal.gov>
28  Fermilab
29 
30 \created September 21, 2021
31 
32 \cpright Copyright (c) 2003-2024, The GENIE Collaboration
33  For the full text of the license visit http://copyright.genie-mc.org
34 
35 */
36 //____________________________________________________________________________
37 
38 #include <cstdlib>
39 #include <cassert>
40 #include <sstream>
41 #include <string>
42 #include <vector>
43 #include <map>
44 
45 //#if defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT)
46 //#include <fenv.h> // for `feenableexcept`
47 //#endif
48 
49 #include <TFile.h>
50 #include <TTree.h>
51 #include <TSystem.h>
52 #include <TFolder.h>
53 #include <TObjString.h>
54 #include <TROOT.h>
55 
58 #include "Framework/Conventions/GBuild.h"
61 
63 
65 #include "Framework/Utils/RunOpt.h"
66 
71 
77 
78 using std::string;
79 using std::vector;
80 using std::map;
81 using std::ostringstream;
82 
83 using namespace genie;
84 using namespace genie::controls;
85 
86 void GetCommandLineArgs (int argc, char ** argv);
87 void Initialize (void);
88 void PrintSyntax (void);
89 
90 
91 //User-specified options:
92 
93 //____________________________________________________________________________
94 int main(int argc, char ** argv)
95 {
96  GetCommandLineArgs(argc,argv);
97  Initialize();
98 
99  // throw on NaNs and Infs...
100 //#if defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT)
101 // feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
102 //#endif
103 
104 /*
105  Registry* rsub = new Registry;
106  rsub->Set("xyz",1234.);
107 
108  RgAlg ralg("Name","Config");
109 
110  Registry* rtop = new Registry;
111  rtop->Set("abc",9876.);
112  //rtop->Set("rsub",rsub);
113  rtop->Set("ralg",ralg);
114 
115  std::cout << *rtop << std::endl;
116  return 0;
117 */
118 
119  const string common_key_root = "Common";
120  // key,file
121  std::map<std::string,std::string> common_list; // e.g. CKM,Param
122  std::set<std::string> common_files;
123 
124 
125  // taken from NtpMCJobConfig
127 
128  //TFolder* fConfig =
129  // gROOT->GetRootFolder()->AddFolder("gconfig","GENIE configs");
130 
131  const vector<string> & vconfkeys = algconf->ConfigKeyList();
132  vector<string>::const_iterator keyiter;
133 
134  for(keyiter = vconfkeys.begin(); keyiter != vconfkeys.end(); ++keyiter) {
135 
136  string key = *keyiter;
137  std::cout << "Registry key: " << key << std::endl;
138 
139  vector<string> vkey = utils::str::Split(key,"/");
140  assert(vkey.size()==2);
141  string alg_name = vkey[0];
142  string param_set = vkey[1];
143 
144  std::cout
145  << "alg_name: " << alg_name << ", param_set: " << param_set; // << std::endl;
146 
147  //if( !(fConfig->FindObject(alg_name.c_str())) ) {
148  // LOG("gconfigdump",pDEBUG) << "Adding new folder for alg: " << alg_name;
149  // fConfig->AddFolder(alg_name.c_str(), "");
150  //}
151  //TFolder * alg_folder = (TFolder *) fConfig->FindObject(alg_name.c_str());
152 
153  //LOG("gconfigdump",pDEBUG) << "Adding folder for param set: " << param_set;
154  //TFolder * config_folder = alg_folder->AddFolder(param_set.c_str(), "");
155 
156  //LOG("gconfigdump",pDEBUG) << "Accessing Registry & converting it to TFolder";
157  Registry * config_registry = algconf->FindRegistry(key);
158  //config_registry->CopyToFolder(config_folder);
159  std::cout << *config_registry;
160 
161  // pick out items that start with Common
162  for ( RgIMapConstIter it = config_registry->GetItemMap().begin();
163  it != config_registry->GetItemMap().end() ; ++it ) {
164  std::string keynm = it->first;
165  if ( keynm.find(common_key_root) == 0 ) {
166  // strip "Common" off key ... leave Param or Decay
167  std::string type = keynm.substr( common_key_root.size() );
168  //
169  std::string cpstr = config_registry->GetStringDef(keynm,"not-found",false);
170  if ( cpstr != "not-found") {
171  vector<std::string> cps = utils::str::Split(cpstr,",");
172  for (size_t i=0; i<cps.size(); ++i) {
173  common_list[cps[i]] = type;
174  common_files.insert(type);
175  }
176  }
177  }
178  }
179 
180  std::cout << std::endl;
181  }
182 
183  std::string xmlpaths = genie::utils::xml::GetXMLPathList();
184  std::cout << "GetXMLPathList returns: "; // << xmlpaths << std::endl;
185  vector<string> xmlpathlist = utils::str::Split(xmlpaths,":");
186  auto xmlpathitr = xmlpathlist.begin();
187  for ( ; xmlpathitr != xmlpathlist.end(); ++xmlpathitr) {
188  std::cout << std::endl << " " << *xmlpathitr;
189  }
190  std::cout << std::endl << std::endl;
191 
192 
193  Registry* common;
194 
195  std::set<std::string>::iterator typeitr = common_files.begin();
196  for ( ; typeitr != common_files.end(); ++typeitr ) {
197  std::string fname = std::string("Common") + *typeitr + std::string(".xml");
198  std::string commonpath = genie::utils::xml::GetXMLFilePath(fname);
199  std::cout << "using file " << commonpath << std::endl;
200 
201 
202  std::map<std::string,std::string>::iterator cpitr = common_list.begin();
203  for ( ; cpitr != common_list.end(); ++cpitr) {
204  if ( cpitr->second != *typeitr ) continue;
205  std::cout << "Common" << cpitr->second << " \"" << cpitr->first << "\"";
206 
207  common = algconf->CommonList(cpitr->second,cpitr->first);
208  if ( ! common ) {
209  std::cout << "\n\tno Common" << cpitr->second << " \"" << cpitr->first << "\"" << std::endl;
210  } else {
211  std::cout << *common;
212  }
213  }
214  std::cout << std::endl;
215  }
216 
217  common = algconf->CommonList("Param","Tunable");
218  if ( ! common ) {
219  std::cout << "no CommonParam \"Tunable\"" << std::endl;
220  } else {
221  std::cout << *common;
222  }
223 
224  std::cout << std::endl << std::endl;
225 
226  // taken from NtpMCJobEnv
227  unsigned int ivar = 0;
228  while ( kMCEnv[ivar] ) {
229  ostringstream entry;
230  string var = kMCEnv[ivar];
231  string value = (gSystem->Getenv(var.c_str()) ?
232  gSystem->Getenv(var.c_str()) : "UNDEFINED");
233 
234  std::cout << "$" << var << " ---> " << value << std::endl;
235  ivar++;
236  }
237 
238 
239 }
240 //____________________________________________________________________________
242 {
243 
244  if ( ! RunOpt::Instance()->Tune() ) {
245  LOG("gconfigdump", pFATAL) << " No TuneId in RunOption";
246  exit(-1);
247  }
249 
250  // Initialization of random number generators, cross-section table,
251  // messenger thresholds, cache file
252  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
254 
255 }
256 
257 //____________________________________________________________________________
258 void GetCommandLineArgs(int argc, char ** argv)
259 {
260  LOG("gconfigdump", pINFO) << "Parsing command line arguments";
261 
262  // Common run options. Set defaults and read.
265 
266  // Parse run options for this app
267 
268  CmdLnArgParser parser(argc,argv);
269 
270  // help?
271  bool help = parser.OptionExists('h');
272  if(help) {
273  PrintSyntax();
274  exit(0);
275  }
276 
277 
278  //
279  // print-out the command line options
280  //
281  LOG("gconfigdump", pNOTICE)
282  << "\n"
283  << utils::print::PrintFramedMesg("gconfigdump job configuration");
284  LOG("gconfigdump", pNOTICE) << "\n";
285 
286  LOG("gconfigdump", pNOTICE) << *RunOpt::Instance();
287 
288 }
289 //____________________________________________________________________________
290 void PrintSyntax(void)
291 {
292  LOG("gconfigdump", pNOTICE)
293  << "\n\n" << "Syntax:" << "\n"
294  << "\n gconfigdump [-h]"
295  << "\n [--event-generator-list list_name]"
296  << "\n [--tune G18_02a_00_000] (or your preferred tune identifier)"
297  << "\n";
298 }
299 //____________________________________________________________________________
string GetXMLPathList(bool add_tune=true)
void ReadFromCommandLine(int argc, char **argv)
Definition: RunOpt.cxx:99
A singleton class holding all configuration registries built while parsing all loaded XML configurati...
Definition: AlgConfigPool.h:40
#define pFATAL
Definition: Messenger.h:56
Registry * CommonList(const string &file_id, const string &set_name) const
int main(int argc, char **argv)
Definition: gAtmoEvGen.cxx:327
map< RgKey, RegistryItemI * >::const_iterator RgIMapConstIter
Definition: Registry.h:49
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static const char * kMCEnv[]
Definition: EnvSnapshot.h:24
string GetXMLFilePath(string basename)
void Initialize(void)
#define pINFO
Definition: Messenger.h:62
const vector< string > & ConfigKeyList(void) const
void BuildTune()
build tune and inform XSecSplineList
Definition: RunOpt.cxx:92
RgStr GetStringDef(RgKey key, RgStr def_opt, bool set_def=true)
Definition: Registry.cxx:540
static RunOpt * Instance(void)
Definition: RunOpt.cxx:54
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f='*')
Definition: PrintUtils.cxx:164
Registry * FindRegistry(string key) const
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
Command line argument parser.
#define pNOTICE
Definition: Messenger.h:61
void GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
void PrintSyntax(void)
void CacheFile(string inpfile)
Definition: AppInit.cxx:117
void EnableBareXSecPreCalc(bool flag)
Definition: RunOpt.h:62
static AlgConfigPool * Instance()