gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
spec_head.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
24 
25 #ifndef __spec_hpp__
26 #define __spec_hpp__
27 
30 
31 // Particle database access
32 #define PDB Models::ParticleDB()
33 
34 namespace Gambit
35 {
36 
38  template <class>
39  class Spec;
40 
44  class DummyModel {};
45  class DummyInput {};
47 
49  template< typename T >
50  struct always_false {
51  enum { value = false };
52  };
53 
58  template <class T>
59  struct SpecTraits
60  {
61  static_assert(always_false<T>::value, "Failed to find appropriate specialisation of SpecTraits! Did you define one along with your SubSpectrum wrapper? If so, please be sure that the template parameter matches the name of your wrapper class.");
62  };
63 
66  {
67  typedef DummyModel Model;
68  typedef DummyInput Input;
69  };
70 
72  template<class,class> class SetMaps;
73  template<class,class> class FptrFinder;
74  template<class,class> class CallFcn;
75 
78  template<class Contents>
80  {
81  public:
83  {
84  Contents contents;
85  contents.verify_contents(spec);
86  }
87  };
88 
89  // CRTP used to allow access to some special data members of the derived class.
90  // Various inherited classes are just used to factor out code, some of which
91  // doesn't need to be templated.
92  template <class DerivedSpec>
93  class Spec : public SubSpectrum
94  {
95  template <class,class>
96  friend class FptrFinder;
97 
98  public:
99  typedef DerivedSpec D;
100  typedef Spec<D> Self;
101 
106  typedef typename SpecTraits<D>::Model Model;
107  typedef typename SpecTraits<D>::Input Input;
108 
111 
112  std::string getName() const { return SpecTraits<D>::name(); };
113 
114  /* Getters and checker declarations for parameter retrieval with zero, one, and two indices */
115  bool has(const Par::Tags, const str&, const SpecOverrideOptions=use_overrides, const SafeBool=SafeBool(true)) const;
116  double get(const Par::Tags, const str&, const SpecOverrideOptions=use_overrides, const SafeBool=SafeBool(true)) const;
117  bool has(const Par::Tags, const str&, const int, const SpecOverrideOptions=use_overrides, const SafeBool=SafeBool(true)) const;
118  double get(const Par::Tags, const str&, const int, const SpecOverrideOptions=use_overrides, const SafeBool=SafeBool(true)) const;
119  bool has(const Par::Tags, const str&, const int, const int, const SpecOverrideOptions=use_overrides) const;
120  double get(const Par::Tags, const str&, const int, const int, const SpecOverrideOptions=use_overrides) const;
121 
122  /* Setter declarations, for setting parameters in a derived model object,
123  and for overriding model object values with values stored outside
124  the model object (for when values cannot be inserted back into the
125  model object)
126  Note; these are NON-CONST */
127  void set(const Par::Tags, const double, const str&, const SafeBool=SafeBool(true));
128  void set(const Par::Tags, const double, const str&, const int, const SafeBool=SafeBool(true));
129  void set(const Par::Tags, const double, const str&, const int, const int);
130 
133  static const std::map<Par::Tags,MapCollection<MTget>> fill_getter_maps()
134  {
135  std::map<Par::Tags,MapCollection<MTget>> tmp;
136  return tmp;
137  }
138  static const std::map<Par::Tags,MapCollection<MTset>> fill_setter_maps()
139  {
140  std::map<Par::Tags,MapCollection<MTset>> tmp;
141  return tmp;
142  }
143 
146  static int index_offset() { return 0; }
147 
148 
149  private:
151  static int get_index_offset() { return D::index_offset(); }
152 
155 
156  static void getter_maps_fill_tags(std::map<Par::Tags,MapCollection<MTget>>& in)
157  {
158  std::vector<Par::Tags> all = Par::get_all();
159  for(std::vector<Par::Tags>::iterator it = all.begin(); it!=all.end(); ++it)
160  {
161  in[*it]; // insert tag key if missing
162  }
163  }
164  static void setter_maps_fill_tags(std::map<Par::Tags,MapCollection<MTset>>& in)
165  {
166  std::vector<Par::Tags> all = Par::get_all();
167  for(std::vector<Par::Tags>::iterator it = all.begin(); it!=all.end(); ++it)
168  {
169  in[*it]; // insert tag key if missing
170  }
171  }
172 
174 
180  static const std::map<Par::Tags,MapCollection<MTget>> final_fill_getter_maps()
181  {
182  // Fill from (possibly overriden) derived class filler function
183  std::map<Par::Tags,MapCollection<MTget>> tmp = D::fill_getter_maps();
184  // Add in any missing tags
185  getter_maps_fill_tags(tmp);
186  return tmp;
187  }
188  static const std::map<Par::Tags,MapCollection<MTset>> final_fill_setter_maps()
189  {
190  // Fill from (possibly overriden) derived class filler function
191  std::map<Par::Tags,MapCollection<MTset>> tmp = D::fill_setter_maps();
192  // Add in any missing tags
193  setter_maps_fill_tags(tmp);
194  return tmp;
195  }
196 
198 
199  public:
200 
205  Spec() { static VerifyContents<Contents> runonce(*this); };
206 
208  virtual ~Spec() {};
209 
212  virtual std::unique_ptr<SubSpectrum> clone() const
213  {
214  return std::unique_ptr<SubSpectrum>(
215  new DerivedSpec(static_cast<DerivedSpec const &>(*this))
216  );
217  }
218 
223 
228  Model& get_Model() { return dummymodel; }
229  Input& get_Input() { return dummyinput; }
230  const Model& get_Model() const { return dummymodel; }
231  const Input& get_Input() const { return dummyinput; }
232 
234  Model& model() { return static_cast<DerivedSpec*>(this)->get_Model(); }
236  const Model& model() const { return static_cast<const DerivedSpec*>(this)->get_Model(); }
237 
239  Input& input() { return static_cast<DerivedSpec*>(this)->get_Input(); }
241  const Input& input() const { return static_cast<const DerivedSpec*>(this)->get_Input(); }
242 
244 
247 
248  typedef std::map<Par::Tags,MapCollection<MTget>> GetterMaps;
249  typedef std::map<Par::Tags,MapCollection<MTset>> SetterMaps;
250  static const GetterMaps getter_maps;
251  static const SetterMaps setter_maps;
252 
253  };
254 
256  template <class D>
258 
259  template <class D>
261 
262 } // end namespace Gambit
263 
264 // Undef the various helper macros to avoid contaminating other files
265 #undef PDB
266 
267 #endif
Mini helper class to specify behaviour of getters w.r.t. overrides in a type-safe way...
VerifyContents(const SubSpectrum &spec)
Definition: spec_head.hpp:82
Need to forward declare Spec class.
Definition: spec_head.hpp:39
static const GetterMaps getter_maps
Initialise maps (uses filler overrides from DerivedSpec if defined)
Definition: spec_head.hpp:250
Fully unspecialised MapTypes declaration.
DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry DecayTable::Entry double
static const std::map< Par::Tags, MapCollection< MTget > > final_fill_getter_maps()
Definition: spec_head.hpp:180
Spec< D > Self
Definition: spec_head.hpp:100
Input & input()
Get struct containing any extra data input on SubSpectrum object creation.
Definition: spec_head.hpp:239
Model & model()
Get model object on which to call function pointers.
Definition: spec_head.hpp:234
const Input & get_Input() const
Definition: spec_head.hpp:231
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
Simpler helper class to run the verify_contents function only once, the first time a particular wrapp...
Definition: spec_head.hpp:79
SpecTraits< D >::Model Model
Definition: spec_head.hpp:106
SpecTraits< D >::Input Input
Definition: spec_head.hpp:107
std::vector< Tags > get_all()
std::map< Par::Tags, MapCollection< MTset > > SetterMaps
Definition: spec_head.hpp:249
Spec()
Constructor This uses the "Contents" class to verify (once, not every construction) that this wrapper...
Definition: spec_head.hpp:205
DummyModel dummymodel
Default "null" versions of get_Model and get_Input, to be used if wrapper does not override them...
Definition: spec_head.hpp:226
MapTypes< D, MapTag::Set > MTset
Definition: spec_head.hpp:110
DummyInput dummyinput
Definition: spec_head.hpp:227
virtual ~Spec()
Virtual destructor.
Definition: spec_head.hpp:208
std::string getName() const
Main public interface functions.
Definition: spec_head.hpp:112
static int get_index_offset()
Function to retrieve the possibly overridden index offset from the derived class via CRTP...
Definition: spec_head.hpp:151
static const std::map< Par::Tags, MapCollection< MTget > > fill_getter_maps()
Definition: spec_head.hpp:133
const Input & input() const
Return it as const if we are a const object.
Definition: spec_head.hpp:241
const Model & model() const
Return it as const if we are a const object.
Definition: spec_head.hpp:236
DerivedSpec D
Definition: spec_head.hpp:99
static const SetterMaps setter_maps
Definition: spec_head.hpp:251
virtual std::unique_ptr< SubSpectrum > clone() const
CRTP-style polymorphic clone function Now derived classes will not need to re-implement the clone fun...
Definition: spec_head.hpp:212
Model & get_Model()
Definition: spec_head.hpp:228
Helper class for calling function pointers found by FptrFinder.
MapTypes< D, MapTag::Get > MTget
Definition: spec_head.hpp:109
static const std::map< Par::Tags, MapCollection< MTset > > fill_setter_maps()
Definition: spec_head.hpp:138
static void getter_maps_fill_tags(std::map< Par::Tags, MapCollection< MTget >> &in)
Definition: spec_head.hpp:156
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
Abstract class for accessing general spectrum information.
Base class for definining the required contents of SubSpectrum wrapper objects.
Dummy classes to satisfy template parameters for Spec class in cases when those objects are not neede...
Definition: spec_head.hpp:44
SpecTraits< D >::Contents Contents
Note: Wrapper need to define a specialisation of SpecTraits, which typedefs Model and Input...
Definition: spec_head.hpp:105
Input & get_Input()
Definition: spec_head.hpp:229
static int index_offset()
Get integer offset convention used by internal model class (needed by getters which take indices) By ...
Definition: spec_head.hpp:146
Forward declaration of FptrFinder.
DS5_MSPCTM DS_INTDOF int
Forward declare base traits class which communicates Model and Input typedefs from the wrapper class ...
Definition: spec_head.hpp:59
Virtual base class for interacting with spectrum generator output.
Definition: subspectrum.hpp:87
static const std::map< Par::Tags, MapCollection< MTset > > final_fill_setter_maps()
Definition: spec_head.hpp:188
Default values for traits. Specialisations of SpecTraits should inherit from this, and then override the traits that they want to customise.
Definition: spec_head.hpp:65
Helper for the static_assert below.
Definition: spec_head.hpp:50
const Model & get_Model() const
Definition: spec_head.hpp:230
static void setter_maps_fill_tags(std::map< Par::Tags, MapCollection< MTset >> &in)
Definition: spec_head.hpp:164
TODO: see if we can use this one:
Definition: Analysis.hpp:33
std::map< Par::Tags, MapCollection< MTget > > GetterMaps
Will need a map of map collections for both the getters and setters, containing the map collections f...
Definition: spec_head.hpp:248