LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ArtG4tkModelConfig.cc
Go to the documentation of this file.
2 
4 
5 void
7 {
8 
9  // NOTE(JVY): To an extend, this kind of replicate the code in PhysModelConfig service.
10  // However, opted for this way because otherwise one would need to introduce
11  // MULTIPLE RunProducts (configs) in service which would be quite a complication !!!
12  //
13 
14  std::vector<std::string> keys = pset.get_names(); // no longer available: pset.get_keys();
15  std::vector<std::string> modkeys;
16  for (unsigned int i = 0; i < keys.size(); ++i) {
17  if (keys[i] == "DefaultPhysics") {
18  fDefaultPhysics = pset.get<bool>("DefaultPhysics", true);
19  continue;
20  }
21  if (fDefaultPhysics)
22  return;
23  fhicl::ParameterSet mpset = pset.get<fhicl::ParameterSet>(keys[i]);
24  modkeys.clear();
25  modkeys = mpset.get_names(); // no more: get_keys();
26  for (unsigned i1 = 0; i1 < modkeys.size(); ++i1) {
27  std::string modkey = modkeys[i1];
28  for (unsigned int ik = 0; ik < modkey.size(); ++ik)
29  modkey[ik] = std::tolower(modkey[ik]);
30  if (modkey == "underlyingmodels") {
31  fhicl::ParameterSet umpset = mpset.get<fhicl::ParameterSet>(modkeys[i1]);
32  std::vector<std::string> ukeys = umpset.get_names();
33  for (unsigned int iu = 0; iu < ukeys.size(); ++iu) {
34  fhicl::ParameterSet umodel = umpset.get<fhicl::ParameterSet>(ukeys[iu]);
35  std::vector<std::string> umconfig = umodel.get_names();
36  for (unsigned int iukm = 0; iukm < umconfig.size(); ++iukm) {
37  DoFill(ukeys[iu], umconfig[iukm], umodel);
38  }
39  }
40  } else {
41  DoFill(keys[i], modkeys[i1], mpset);
42  }
43  }
44  }
45 
46  return;
47 }
48 
49 void
51  std::string& modkey,
52  fhicl::ParameterSet& mpset)
53 {
54 
55  std::string mkey = modkey;
56  for (unsigned int ik = 0; ik < modkey.size(); ++ik)
57  mkey[ik] = std::tolower(mkey[ik]);
58  if (mkey.find("use") != std::string::npos) {
59  int ivalue = mpset.get<int>(modkey, 0);
60  Insert(key, modkey, ivalue);
61  } else {
62  double value = mpset.get<double>(modkey);
63  Insert(key, modkey, value);
64  }
65 
66  return;
67 }
68 
69 void
70 artg4tk::ArtG4tkModelConfig::Insert(const std::string& model,
71  const std::string& param,
72  const double& value)
73 {
74 
75  // Check if "Default Physics" (no changes to G4's defaults whatsoever)
76  // and store config(s) only if NOT
77  //
78  //
79  if (fDefaultPhysics)
80  return;
81 
82  if (fModelConfig.find(model) == fModelConfig.end()) {
83  fModelConfig.insert(std::pair<std::string, std::vector<std::pair<std::string, double>>>(
84  model, std::vector<std::pair<std::string, double>>()));
85  }
86 
87  std::map<std::string, std::vector<std::pair<std::string, double>>>::iterator itr =
88  fModelConfig.find(model);
89 
90  (itr->second).push_back(std::pair<std::string, double>(param, value));
91 
92  return;
93 }
94 
95 std::vector<std::string>
97 {
98 
99  std::vector<std::string> models;
100 
101  std::map<std::string, std::vector<std::pair<std::string, double>>>::const_iterator itr =
102  fModelConfig.begin();
103  for (; itr != fModelConfig.end(); ++itr) {
104  models.push_back(itr->first);
105  }
106 
107  return models;
108 }
109 
110 const std::vector<std::pair<std::string, double>>*
111 artg4tk::ArtG4tkModelConfig::GetConfig(const std::string& model) const
112 {
113 
114  std::map<std::string, std::vector<std::pair<std::string, double>>>::const_iterator itr =
115  fModelConfig.find(model);
116 
117  if (itr == fModelConfig.end()) {
118  // FIXME !!
119  // Needs to give a WARNING !!!
120  //
121  return NULL;
122  }
123 
124  return &(itr->second);
125 }
intermediate_table::iterator iterator
void DoFill(std::string &, std::string &, fhicl::ParameterSet &)
void Insert(const std::string &, const std::string &, const double &)
std::vector< std::string > GetConfiguredModels() const
intermediate_table::const_iterator const_iterator
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
T get(std::string const &key) const
Definition: ParameterSet.h:314
std::map< std::string, std::vector< std::pair< std::string, double > > > fModelConfig
double value
Definition: spectrum.C:18
const std::vector< std::pair< std::string, double > > * GetConfig(const std::string &) const
std::vector< std::string > get_names() const
void Fill(const fhicl::ParameterSet &)