gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
spec.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
22 
23 #ifndef __SubSpectrum_hpp__
24 #define __SubSpectrum_hpp__
25 
29 
30 namespace Gambit {
31 
33 
35  template <class DerivedSpec>
36  bool Spec<DerivedSpec>::has(const Par::Tags partype, const str& name, const SpecOverrideOptions check_overrides, const SafeBool check_antiparticle) const
37  {
38  //typedef typename DerivedSpec::MTget MTget;
44 
45  bool overrides=true;
46  bool override_only=false;
47  if (check_overrides == use_overrides) { overrides=true; override_only=false; }
48  else if(check_overrides == overrides_only){ overrides=true; override_only=true; }
49  else if(check_overrides == ignore_overrides){overrides=false; override_only=false;}
50 
51  /* Create finder object, tell it what maps to search, and do the search */
52  const OverrideMaps overridecoll = override_maps.at(partype);
53  const MapCollection<MTget> mapcoll = getter_maps.at(partype);
55  SetMaps<Spec<DerivedSpec>,MapTag::Get>(Par::toString.at(partype),this)
56  .omap0( overridecoll.m0 )
57  .omap1( overridecoll.m1 )
58  .map0( mapcoll.map0 )
59  .map1( mapcoll.map1 )
60  .map0W( mapcoll.map0W )
61  .map1W( mapcoll.map1W )
62  .map0M( mapcoll.map0_extraM )
63  .map1M( mapcoll.map1_extraM )
64  .map0I( mapcoll.map0_extraI )
65  .map1I( mapcoll.map1_extraI )
66  .override_only(override_only)
67  .no_overrides(not overrides);
68  return finder.find(name,true,check_antiparticle);
69  }
70 
71  template <class DerivedSpec>
72  double Spec<DerivedSpec>::get(const Par::Tags partype, const str& name, const SpecOverrideOptions check_overrides, const SafeBool check_antiparticle) const
73  {
74  //typedef typename DerivedSpec::MTget MTget;
75 
76  bool overrides=true;
77  bool override_only=false;
78  if (check_overrides == use_overrides) { overrides=true; override_only=false; }
79  else if(check_overrides == overrides_only){ overrides=true; override_only=true; }
80  else if(check_overrides == ignore_overrides){overrides=false; override_only=false;}
81 
82  /* Create finder object, tell it what maps to search, and do the search */
83  const OverrideMaps overridecoll = override_maps.at(partype);
84  const MapCollection<MTget> mapcoll = getter_maps.at(partype);
86  SetMaps<Spec<DerivedSpec>,MapTag::Get>(Par::toString.at(partype),this)
87  .omap0( overridecoll.m0 )
88  .omap1( overridecoll.m1 )
89  .map0( mapcoll.map0 )
90  .map1( mapcoll.map1 )
91  .map0W( mapcoll.map0W )
92  .map1W( mapcoll.map1W )
93  .map0M( mapcoll.map0_extraM )
94  .map1M( mapcoll.map1_extraM )
95  .map0I( mapcoll.map0_extraI )
96  .map1I( mapcoll.map1_extraI )
97  .override_only(override_only)
98  .no_overrides(not overrides);
99  if( finder.find(name,true,check_antiparticle) ){ return finder.callfcn(); }
100  finder.raise_error(LOCAL_INFO);
101  return 0;
102  }
103 
104  template <class DerivedSpec>
105  void Spec<DerivedSpec>::set(const Par::Tags partype, const double set_value, const str& name, const SafeBool check_antiparticle)
106  {
107  typedef typename DerivedSpec::MTset MTset;
108 
109  /* Before trying to set parameter, check if there is an override defined
110  for it, so that we can warn people that the value they are trying to
111  set will be masked by the override */
112  const OverrideMaps overridecoll = override_maps.at(partype);
113  FptrFinder<Spec<DerivedSpec>,MapTag::Set> override_finder =
114  SetMaps<Spec<DerivedSpec>,MapTag::Set>(Par::toString.at(partype),this)
115  .omap0( overridecoll.m0 )
116  .omap1( overridecoll.m1 )
117  .override_only(true); // switch to permit search of only override maps
118  if( override_finder.find(name,true,check_antiparticle) )
119  {
120  std::ostringstream errmsg;
121  errmsg << "Warning from SubSpectrum object while trying to manually set a parameter!" << std::endl;
122  errmsg << "An override entry was detected for "<<Par::toString.at(partype)<<" with string reference '"<<name<<"'. The override value will hide the value I have been instructed to set." <<std::endl;
123  utils_warning().raise(LOCAL_INFO,errmsg.str());
124  }
125  // else no problem
126 
127  /* Create finder object, tell it what maps to search, and do the search */
128  const MapCollection<MTset> mapcoll = setter_maps.at(partype);
130  SetMaps<Spec<DerivedSpec>,MapTag::Set>(Par::toString.at(partype),this)
131  .map0( mapcoll.map0 )
132  .map1( mapcoll.map1 )
133  .map0W( mapcoll.map0W )
134  .map1W( mapcoll.map1W )
135  .map0M( mapcoll.map0_extraM )
136  .map1M( mapcoll.map1_extraM )
137  .map0I( mapcoll.map0_extraI )
138  .map1I( mapcoll.map1_extraI );
139  if( finder.find(name,true,check_antiparticle) ){ finder.callfcn(set_value); }
140  else { finder.raise_error(LOCAL_INFO); }
141  }
144  template <class DerivedSpec>
145  bool Spec<DerivedSpec>::has(const Par::Tags partype, const str& name, const int i, const SpecOverrideOptions check_overrides, const SafeBool check_antiparticle) const
146  {
147  //typedef typename DerivedSpec::MTget MTget;
148 
149  bool overrides=true;
150  bool override_only=false;
151  if (check_overrides == use_overrides) { overrides=true; override_only=false; }
152  else if(check_overrides == overrides_only){ overrides=true; override_only=true; }
153  else if(check_overrides == ignore_overrides){overrides=false; override_only=false;}
154 
155  /* Create finder object, tell it what maps to search, and do the search */
156  const OverrideMaps overridecoll = override_maps.at(partype);
157  const MapCollection<MTget> mapcoll = getter_maps.at(partype);
159  SetMaps<Spec<DerivedSpec>,MapTag::Get>(Par::toString.at(partype),this)
160  .omap0( overridecoll.m0 )
161  .omap1( overridecoll.m1 )
162  .map0( mapcoll.map0 )
163  .map1( mapcoll.map1 )
164  .map0W( mapcoll.map0W )
165  .map1W( mapcoll.map1W )
166  .map0M( mapcoll.map0_extraM )
167  .map1M( mapcoll.map1_extraM )
168  .map0I( mapcoll.map0_extraI )
169  .map1I( mapcoll.map1_extraI )
170  .override_only(override_only)
171  .no_overrides(not overrides);
172  return finder.find(name,i,true,check_antiparticle);
173  }
174 
175  template <class DerivedSpec>
176  double Spec<DerivedSpec>::get(const Par::Tags partype, const str& name, const int i, const SpecOverrideOptions check_overrides, const SafeBool check_antiparticle) const
177  {
178  //typedef typename DerivedSpec::MTget MTget;
179 
180  bool overrides=true;
181  bool override_only=false;
182  if (check_overrides == use_overrides) { overrides=true; override_only=false; }
183  else if(check_overrides == overrides_only){ overrides=true; override_only=true; }
184  else if(check_overrides == ignore_overrides){overrides=false; override_only=false;}
185 
186  /* Create finder object, tell it what maps to search, and do the search */
187  const OverrideMaps overridecoll = override_maps.at(partype);
188  const MapCollection<MTget> mapcoll = getter_maps.at(partype);
190  SetMaps<Spec<DerivedSpec>,MapTag::Get>(Par::toString.at(partype),this)
191  .omap0( overridecoll.m0 )
192  .omap1( overridecoll.m1 )
193  .map0( mapcoll.map0 )
194  .map1( mapcoll.map1 )
195  .map0W( mapcoll.map0W )
196  .map1W( mapcoll.map1W )
197  .map0M( mapcoll.map0_extraM )
198  .map1M( mapcoll.map1_extraM )
199  .map0I( mapcoll.map0_extraI )
200  .map1I( mapcoll.map1_extraI )
201  .override_only(override_only)
202  .no_overrides(not overrides);
203  if( finder.find(name,i,true,check_antiparticle) ){ return finder.callfcn(); }
204  finder.raise_error(LOCAL_INFO);
205  return 0;
206  }
207 
208  template <class DerivedSpec>
209  void Spec<DerivedSpec>::set(const Par::Tags partype, const double set_value, const str& name, const int i, const SafeBool check_antiparticle)
210  {
211  typedef typename DerivedSpec::MTset MTset;
212 
213  /* Before trying to set parameter, check if there is an override defined
214  for it, so that we can warn people that the value they are trying to
215  set will be masked by the override */
216  const OverrideMaps overridecoll = override_maps.at(partype);
217  FptrFinder<Spec<DerivedSpec>,MapTag::Set> override_finder =
218  SetMaps<Spec<DerivedSpec>,MapTag::Set>(Par::toString.at(partype),this)
219  .omap0( overridecoll.m0 )
220  .omap1( overridecoll.m1 )
221  .override_only(true); // switch to permit search of only override maps
222  if( override_finder.find(name,i,true,check_antiparticle) )
223  {
224  std::ostringstream errmsg;
225  errmsg << "Warning from SubSpectrum object while trying to manually set a parameter!" << std::endl;
226  errmsg << "An override entry was detected for "<<Par::toString.at(partype)<<" with string reference '"<<name<<"', index '"<<i<<"'. The override value will hide the value I have been instructed to set." <<std::endl;
227  utils_warning().raise(LOCAL_INFO,errmsg.str());
228  }
229  // else no problem
230 
231  /* Create finder object, tell it what maps to search, and do the search */
232  const MapCollection<MTset> mapcoll = setter_maps.at(partype);
234  SetMaps<Spec<DerivedSpec>,MapTag::Set>(Par::toString.at(partype),this)
235  .map0( mapcoll.map0 )
236  .map1( mapcoll.map1 )
237  .map0W( mapcoll.map0W )
238  .map1W( mapcoll.map1W )
239  .map0M( mapcoll.map0_extraM )
240  .map1M( mapcoll.map1_extraM )
241  .map0I( mapcoll.map0_extraI )
242  .map1I( mapcoll.map1_extraI );
243  if( finder.find(name,i,true,check_antiparticle) ){ finder.callfcn(set_value); }
244  else { finder.raise_error(LOCAL_INFO); }
245  }
246 
249 
250  template <class DerivedSpec>
251  bool Spec<DerivedSpec>::has(const Par::Tags partype, const str& name, const int i, const int j, const SpecOverrideOptions check_overrides) const
252  {
253  //typedef typename DerivedSpec::MTget MTget;
254 
255  bool overrides=true;
256  bool override_only=false;
257  if (check_overrides == use_overrides) { overrides=true; override_only=false; }
258  else if(check_overrides == overrides_only){ overrides=true; override_only=true; }
259  else if(check_overrides == ignore_overrides){overrides=false; override_only=false;}
260 
261  /* Create finder object, tell it what maps to search, and do the search */
262  const OverrideMaps overridecoll = override_maps.at(partype);
263  const MapCollection<MTget> mapcoll = getter_maps.at(partype);
265  SetMaps<Spec<DerivedSpec>,MapTag::Get>(Par::toString.at(partype),this)
266  .omap2( overridecoll.m2 )
267  .map2( mapcoll.map2 )
268  .map2W( mapcoll.map2W )
269  .map2M( mapcoll.map2_extraM )
270  .map2I( mapcoll.map2_extraI )
271  .override_only(override_only)
272  .no_overrides(not overrides);
273  return finder.find(name,i,j);
274  }
275 
276  template <class DerivedSpec>
277  double Spec<DerivedSpec>::get(const Par::Tags partype, const str& name, const int i, const int j, const SpecOverrideOptions check_overrides) const
278  {
279  //typedef typename DerivedSpec::MTget MTget;
280 
281  bool overrides=true;
282  bool override_only=false;
283  if (check_overrides == use_overrides) { overrides=true; override_only=false; }
284  else if(check_overrides == overrides_only){ overrides=true; override_only=true; }
285  else if(check_overrides == ignore_overrides){overrides=false; override_only=false;}
286 
287  /* Create finder object, tell it what maps to search, and do the search */
288  const OverrideMaps overridecoll = override_maps.at(partype);
289  const MapCollection<MTget> mapcoll = getter_maps.at(partype);
291  SetMaps<Spec<DerivedSpec>,MapTag::Get>(Par::toString.at(partype),this)
292  .omap2( overridecoll.m2 )
293  .map2( mapcoll.map2 )
294  .map2W( mapcoll.map2W )
295  .map2M( mapcoll.map2_extraM )
296  .map2I( mapcoll.map2_extraI )
297  .override_only(override_only)
298  .no_overrides(not overrides);
299  if( finder.find(name,i,j) ){ return finder.callfcn(); }
300  finder.raise_error(LOCAL_INFO);
301  return 0;
302  }
303 
304  template <class DerivedSpec>
305  void Spec<DerivedSpec>::set(const Par::Tags partype, const double set_value, const str& name, const int i, const int j)
306  {
307  typedef typename DerivedSpec::MTset MTset;
308 
309  /* Create finder object, tell it what maps to search, and do the search */
310  const MapCollection<MTset> mapcoll = setter_maps.at(partype);
312  SetMaps<Spec<DerivedSpec>,MapTag::Set>(Par::toString.at(partype),this)
313  .map2( mapcoll.map2 )
314  .map2W( mapcoll.map2W )
315  .map2M( mapcoll.map2_extraM )
316  .map2I( mapcoll.map2_extraI );
317  if( finder.find(name,i,j) ){ finder.callfcn(set_value); }
318  else { finder.raise_error(LOCAL_INFO); }
319  }
320 
322 
324 
325 }
326 
327 #endif
Mini helper class to specify behaviour of getters w.r.t. overrides in a type-safe way...
Fully unspecialised MapTypes declaration.
bool find(const std::string &name, bool=true, SafeBool check_antiparticle=SafeBool(true))
Search function for 0-index maps.
MapTypes::fmap1W map1W
Definition: subspectrum.hpp:63
MapTypes::fmap0_extraM map0_extraM
Definition: subspectrum.hpp:65
CallFcn< HostSpec, MTag > callfcn
Caller for whatever function was found HostSpec has to work slightly differently depending on whether...
FptrFinder friend class for implementing named parameter idiom.
Struct to hold collections of function pointer maps to be filled by derived classes.
Definition: subspectrum.hpp:57
MapTypes::fmap1_extraI map1_extraI
Definition: subspectrum.hpp:69
A replacement type for &#39;bool&#39; which does not allow automatic conversion to/from &#39;int&#39; etc...
#define LOCAL_INFO
Definition: local_info.hpp:34
MapTypes::fmap2W map2W
Definition: subspectrum.hpp:64
std::map< str, std::map< int, std::map< int, double > > > m2
Definition: subspectrum.hpp:78
SubSpectrum helper class for seaching through the function pointer maps and calling the requested fun...
MapTypes::fmap0_extraI map0_extraI
Definition: subspectrum.hpp:68
void set(const Par::Tags, const double, const str &, const SafeBool=SafeBool(true))
Definition: spec.hpp:105
EXPORT_SYMBOLS warning & utils_warning()
Utility warnings.
MapTypes::fmap2_extraM map2_extraM
Definition: subspectrum.hpp:67
MapTypes::fmap0 map0
Definition: subspectrum.hpp:59
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
Forward declaration of FptrFinder.
void raise_error(const std::string &origin)
MapTypes::fmap1_extraM map1_extraM
Definition: subspectrum.hpp:66
MapTypes::fmap1 map1
Definition: subspectrum.hpp:60
std::map< str, std::map< int, double > > m1
Definition: subspectrum.hpp:77
double get(const Par::Tags, const str &, const SpecOverrideOptions=use_overrides, const SafeBool=SafeBool(true)) const
Definition: spec.hpp:72
bool has(const Par::Tags, const str &, const SpecOverrideOptions=use_overrides, const SafeBool=SafeBool(true)) const
Spec member function definitions.
Definition: spec.hpp:36
MapTypes::fmap0W map0W
Definition: subspectrum.hpp:62
Definition of struct to hold various override values for a given ParamTag.
Definition: subspectrum.hpp:74
MapTypes::fmap2 map2
Definition: subspectrum.hpp:61
MapTypes::fmap2_extraI map2_extraI
Definition: subspectrum.hpp:70
TODO: see if we can use this one:
Definition: Analysis.hpp:33
std::map< str, double > m0
Definition: subspectrum.hpp:76
Implementation class "behind the scenes" of abstract SubSpectrum interface class. ...