GEMC  2.3
Geant4 Monte-Carlo Framework
parameter_factory.cc
Go to the documentation of this file.
1 // GEMC headers
2 #include "parameter_factory.h"
3 #include "mysql_parameters.h"
4 #include "text_parameters.h"
5 #include "string_utilities.h"
6 #include "utils.h"
7 
8 
9 parametersFactory *getParameterFactory(map<string, parameterFactoryInMap> *parametersFactoryMap, string parametersMethod)
10 {
11 
12  if(parametersFactoryMap->find(parametersMethod) == parametersFactoryMap->end())
13  {
14  cout << " ** WARNING: " << parametersMethod << " NOT FOUND IN parameter Factory Map." << endl;
15  return NULL;
16  }
17 
18  return (*parametersFactoryMap)[parametersMethod]();
19 }
20 
21 map<string, parameterFactoryInMap> registerParameterFactories()
22 {
23  map<string, parameterFactoryInMap> parameterFactoryMap;
24 
25  // mysql factory
26  parameterFactoryMap["MYSQL"] = &mysql_parameters::createParametersFactory;
27 
28  // text factory
29  parameterFactoryMap["TEXT"] = &text_parameters::createParametersFactory;
30 
31  return parameterFactoryMap;
32 }
33 
34 
35 map<string, string> getParametersMap(map<string, double> dataMap)
36 {
37  map<string, string> parmap;
38 
39  for(map<string, double>::iterator it = dataMap.begin(); it != dataMap.end(); it++)
40  {
41  string key = "parameter " + it->first;
42  parmap[key] = stringify(it->second);
43  }
44 
45  return parmap;
46 }
47 
48 
49 map<string, double> loadAllParameters(map<string, parameterFactoryInMap> parameterFactoryMap, goptions go, runConditions rc)
50 {
51  double verbosity = go.optMap["PARAMETER_VERBOSITY"].arg;
52  map<string, double> gParameters;
53 
54  // getting parameters factories one by one
55  for(map<string, parameterFactoryInMap>::iterator it = parameterFactoryMap.begin(); it != parameterFactoryMap.end(); it++)
56  {
57  // building parameters from this factory
58  parametersFactory *thisFactory = getParameterFactory(&parameterFactoryMap, it->first);
59 
60  // initialize factory
61  thisFactory->initFactory(it->first);
62 
63  // loading parameters
64  map<string, double> thisPMap = thisFactory->loadParameters(go, rc);
65 
66  // merging these detectors to hallMap
67  for(map<string, double>::iterator ipar = thisPMap.begin(); ipar != thisPMap.end(); ipar++)
68  {
69  // big warning if parameter already exist
70  // detector is NOT loaded if already existing
71  if(gParameters.find(ipar->first) != gParameters.end() && verbosity)
72  {
73  cout << " ** WARNING! Parameter " << ipar->first << " in factory " << it->first << " exists already! " << endl;
74  }
75  // loading parameter if not present yet
76  else
77  gParameters[ipar->first] = ipar->second;
78  }
79 
80  // done with the factory, deleting factory pointer
81  delete thisFactory;
82  }
83 
84  return gParameters;
85 }
86 
88 {
89  string pvalue = gt.data[1];
90  string punits = gt.data[2];
91  return get_number(pvalue + "*" + punits);
92 }
93 
94 void log_value(gtable gt, string factory)
95 {
96  cout << " > gemc " << factory << " Parameters: \"" + gt.data[0] + "\" loaded with value " + gt.data[1] + gt.data[2] + ". Description: " + gt.data[3] << endl;
97 }
98 
99 
100 
101 
102 
map< string, parameterFactoryInMap > registerParameterFactories()
double get_par_value(gtable gt)
parametersFactory * getParameterFactory(map< string, parameterFactoryInMap > *parametersFactoryMap, string parametersMethod)
vector< string > data
Definition: utils.h:76
Definition: utils.h:65
double verbosity
map< string, double > loadAllParameters(map< string, parameterFactoryInMap > parameterFactoryMap, goptions go, runConditions rc)
double get_number(string v, int warn_no_unit)
Returns number with dimension from string, i.e. 100*cm.
map< string, string > getParametersMap(map< string, double > dataMap)
string stringify(double x)
map< string, aopt > optMap
Options map.
Definition: options.h:75
static parametersFactory * createParametersFactory()
static parametersFactory * createParametersFactory()
void initFactory(string ft)
virtual map< string, double > loadParameters(goptions, runConditions)=0
void log_value(gtable gt, string factory)