gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
Gambit::Models::ModelFunctorClaw Class Reference

Models object that performs initialisation and checking operations on a primary_model_functor list. More...

#include <models.hpp>

Collaboration diagram for Gambit::Models::ModelFunctorClaw:

Public Member Functions

 ModelFunctorClaw ()
 Constructor. More...
 
 ~ModelFunctorClaw ()
 Destructor. More...
 
primodel_vec getPrimaryModelFunctorsToActivate (std::set< str >, const primodel_vec &)
 Model activation function. More...
 
void checkPrimaryModelFunctorUsage (const activemodel_map &) const
 Active model functor "usefulness" checker. More...
 
void declare_model (const str &, const str &)
 Add a new model to the model database. More...
 
void add_friend (const str &model, const str &newfriend)
 Add a friend, and all its friends and ancestors, to a model's list of friends. More...
 
bool model_exists (const str &) const
 Indicate whether a model is recognised by GAMBIT or not. More...
 
str list_models () const
 List all the models recognised by GAMBIT. More...
 
void verify_model (const str &) const
 Verify that a string matches a model recognised by GAMBIT, crash otherwise. More...
 
const std::set< str > & get_allmodels () const
 Return set of all models recognised by GAMBIT. More...
 
std::set< strget_activemodels () const
 Return the set of active models;. More...
 
std::vector< strget_lineage (const str &) const
 Retrieve the lineage for a given model. More...
 
std::set< strget_friends (const str &model) const
 Retrieve the friends for a given model. More...
 
std::set< strget_best_friends (const str &model) const
 Retrieve the best friends for a given model. More...
 
std::vector< strget_descendants (const str &) const
 Retrieve the descendants for a given model. More...
 
str get_parent (const str &) const
 Retrieve the parent model for a given model. More...
 
bool descended_from (const str &, const str &) const
 Check if model 1 is descended from model 2. More...
 
bool ancestor_of (const str &, const str &) const
 Check if model 1 is an ancestor of model 2. More...
 
bool downstream_of (const str &, const str &) const
 Check if model 1 exists somewhere downstream of (and can be therefore be interpreted as a) model 2. More...
 
bool upstream_of (const str &, const str &) const
 Check if model 1 exists somewhere upstream of model 2, allowing model 2 to be interpreted as model 1. More...
 

Private Types

typedef bool(* LineageFunction) (const str, const ModelFunctorClaw *)
 Function pointer type. More...
 

Private Attributes

std::set< stractivemodels
 Internal record of the active models. More...
 
Private lineage/ancestry/friends databases
std::set< strallmodelnames
 
std::map< str, strmyParentsDB
 
std::map< str, std::vector< str > > myLineageDB
 
std::map< str, std::vector< str > > myDescendantsDB
 
std::map< str, LineageFunctionmyIsDescendantOfDB
 
std::map< str, std::set< str > > myFriendsDB
 
std::map< str, std::set< str > > myBestFriendsDB
 

Detailed Description

Models object that performs initialisation and checking operations on a primary_model_functor list.

Definition at line 55 of file models.hpp.

Member Typedef Documentation

◆ LineageFunction

typedef bool(* Gambit::Models::ModelFunctorClaw::LineageFunction) (const str, const ModelFunctorClaw *)
private

Function pointer type.

Definition at line 61 of file models.hpp.

Constructor & Destructor Documentation

◆ ModelFunctorClaw()

Gambit::Models::ModelFunctorClaw::ModelFunctorClaw ( )
inline

Constructor.

Definition at line 80 of file models.hpp.

80 {}

◆ ~ModelFunctorClaw()

Gambit::Models::ModelFunctorClaw::~ModelFunctorClaw ( )
inline

Member Function Documentation

◆ add_friend()

void Gambit::Models::ModelFunctorClaw::add_friend ( const str model,
const str newfriend 
)

Add a friend, and all its friends and ancestors, to a model's list of friends.

Definition at line 189 of file models.cpp.

References Gambit::Models::PARENT::lineage, list_models(), LOCAL_INFO, Gambit::model_error(), model_exists(), myBestFriendsDB, myFriendsDB, and myLineageDB.

Referenced by Gambit::copy_parameters(), and ~ModelFunctorClaw().

190  {
191  // If the new friend actually doesn't exist yet, die.
192  if (not model_exists(newfriend))
193  {
194  str errmsg = "Requested friend model \""+newfriend + "\" for model \""+model;
195  errmsg += "\nis not in the GAMBIT database. Recognised models are:\n" + list_models();
196  model_error().raise(LOCAL_INFO,errmsg);
197  }
198  // Add the new friend as a best friend.
199  myBestFriendsDB[model].insert(newfriend);
200  // Add the new friend's whole lineage vector as regular friends.
201  std::set<str> temp1, temp2, lineage(myLineageDB[newfriend].begin(), myLineageDB[newfriend].end());
202  set_union(myFriendsDB[model].begin(), myFriendsDB[model].end(), lineage.begin(), lineage.end(), inserter(temp1, temp1.begin()));
203  // Also inherit the new friend's friends as regular friends.
204  set_union(temp1.begin(), temp1.end(), myFriendsDB[newfriend].begin(), myFriendsDB[newfriend].end(), inserter(temp2, temp2.begin()));
205  myFriendsDB[model] = temp2;
206  }
std::map< str, std::set< str > > myBestFriendsDB
Definition: models.hpp:74
std::map< str, std::set< str > > myFriendsDB
Definition: models.hpp:73
str list_models() const
List all the models recognised by GAMBIT.
Definition: models.cpp:215
#define LOCAL_INFO
Definition: local_info.hpp:34
const std::vector< std::string > lineage
Definition: orphan.hpp:35
std::string str
Definition: models.hpp:49
std::map< str, std::vector< str > > myLineageDB
Definition: models.hpp:70
bool model_exists(const str &) const
Indicate whether a model is recognised by GAMBIT or not.
Definition: models.cpp:209
error & model_error()
Model errors.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ancestor_of()

bool Gambit::Models::ModelFunctorClaw::ancestor_of ( const str model1,
const str model2 
) const

Check if model 1 is an ancestor of model 2.

Definition at line 280 of file models.cpp.

References descended_from().

Referenced by ~ModelFunctorClaw().

281  {
282  return descended_from(model2, model1);
283  }
bool descended_from(const str &, const str &) const
Check if model 1 is descended from model 2.
Definition: models.cpp:268
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkPrimaryModelFunctorUsage()

void Gambit::Models::ModelFunctorClaw::checkPrimaryModelFunctorUsage ( const activemodel_map activeModelFunctors) const

Active model functor "usefulness" checker.

Checks that all the active primary model functors are actually used for something in the dependency tree. If not throws an error to warn the user.

Definition at line 113 of file models.cpp.

References LOCAL_INFO, Gambit::model_error(), and Gambit::functor::status().

Referenced by main(), and ~ModelFunctorClaw().

114  {
115  std::vector<std::string> unusedmodels;
116  std::string modelname;
117  primary_model_functor* functorPtr;
118  // Loop through functor list and check that their statuses have all been
119  // set to 2 ("active"). If not, it means that some of them were not
120  // activated by the dependency resolver and thus are not used for
121  // computing anything.
122  for(activemodel_it it = activeModelFunctors.begin();
123  it != activeModelFunctors.end(); it++)
124  {
125  modelname = it->first;
126  functorPtr = it->second;
127 
128  if ( functorPtr->status()!=2 )
129  {
130  unusedmodels.push_back( modelname );
131  }
132  }
133 
134  // If we found unused models throw an error
135  if ( unusedmodels.size() > 0 )
136  {
137  str errmsg = "Some models selected for scanning are not required by any of\n";
138  errmsg += "the requested observables/likelihoods! Please switch these \n";
139  errmsg += "off in the inifile or add a target that actually uses them. \n";
140  errmsg += "List of unused models: \n";
141  for (std::vector<std::string>::iterator it = unusedmodels.begin(); it != unusedmodels.end(); ++it)
142  {
143  errmsg += (*it + "\n");
144  }
145  model_error().raise(LOCAL_INFO,errmsg);
146  }
147 
148  }
#define LOCAL_INFO
Definition: local_info.hpp:34
std::string str
Definition: models.hpp:49
std::map< std::string, primary_model_functor * >::const_iterator activemodel_it
Definition: models.cpp:41
error & model_error()
Model errors.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ declare_model()

void Gambit::Models::ModelFunctorClaw::declare_model ( const str model,
const str parent 
)

Add a new model to the model database.

Definition at line 151 of file models.cpp.

References allmodelnames, descended_from(), list_models(), LOCAL_INFO, Gambit::model_error(), model_exists(), myBestFriendsDB, myDescendantsDB, myFriendsDB, myLineageDB, and myParentsDB.

Referenced by Gambit::add_model(), and ~ModelFunctorClaw().

152  {
153  // Register the new model.
154  allmodelnames.insert(model);
155  if (parent != "PARENT")
156  {
157  // If the parent actually doesn't exist yet, die.
158  if (not model_exists(parent))
159  {
160  str errmsg = "Requested parent model \""+parent+ "\" for model \""+model;
161  errmsg += "\nis not in the GAMBIT database. Recognised models are:\n" + list_models();
162  model_error().raise(LOCAL_INFO,errmsg);
163  }
164  // Add the parent to the parents database.
165  myParentsDB[model] = parent;
166  // Inherit friends from the model's parent.
167  myFriendsDB[model] = myFriendsDB[parent];
168  // Inherit lineage from the model's parent.
169  myLineageDB[model] = myLineageDB[parent];
170  }
171  else
172  {
173  // Seed empty friend sets and inheritance vector.
174  myFriendsDB[model] = std::set<str>();
175  myBestFriendsDB[model] = std::set<str>();
176  myLineageDB[model] = std::vector<str>();
177  }
178  // Add the new model to its own lineage vector.
179  myLineageDB[model].push_back(model);
180  // Register the model in each of its parents' descendents vectors.
181  for (std::set<str>::iterator parent = allmodelnames.begin(); parent != allmodelnames.end(); ++parent)
182  {
183  // If this model descends from parent, add it to the parent's descendents vector
184  if (descended_from(model,*parent)) myDescendantsDB[*parent].push_back(model);
185  }
186  }
std::map< str, std::set< str > > myBestFriendsDB
Definition: models.hpp:74
std::map< str, std::set< str > > myFriendsDB
Definition: models.hpp:73
str list_models() const
List all the models recognised by GAMBIT.
Definition: models.cpp:215
std::map< str, str > myParentsDB
Definition: models.hpp:69
#define LOCAL_INFO
Definition: local_info.hpp:34
std::set< str > allmodelnames
Definition: models.hpp:68
std::string str
Definition: models.hpp:49
std::map< str, std::vector< str > > myLineageDB
Definition: models.hpp:70
bool model_exists(const str &) const
Indicate whether a model is recognised by GAMBIT or not.
Definition: models.cpp:209
bool descended_from(const str &, const str &) const
Check if model 1 is descended from model 2.
Definition: models.cpp:268
std::map< str, std::vector< str > > myDescendantsDB
Definition: models.hpp:71
error & model_error()
Model errors.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ descended_from()

bool Gambit::Models::ModelFunctorClaw::descended_from ( const str model1,
const str model2 
) const

Check if model 1 is descended from model 2.

Definition at line 268 of file models.cpp.

References Gambit::Models::PARENT::lineage, myLineageDB, and verify_model().

Referenced by ancestor_of(), declare_model(), downstream_of(), and ~ModelFunctorClaw().

269  {
270  verify_model(model1);
271  auto lineage = myLineageDB.at(model1);
272  for (std::vector<str>::const_iterator it = lineage.begin(); it != lineage.end(); ++it)
273  {
274  if (model2==*it) return true;
275  }
276  return false;
277  }
void verify_model(const str &) const
Verify that a string matches a model recognised by GAMBIT, crash otherwise.
Definition: models.cpp:226
const std::vector< std::string > lineage
Definition: orphan.hpp:35
std::map< str, std::vector< str > > myLineageDB
Definition: models.hpp:70
Here is the call graph for this function:
Here is the caller graph for this function:

◆ downstream_of()

bool Gambit::Models::ModelFunctorClaw::downstream_of ( const str model1,
const str model2 
) const

Check if model 1 exists somewhere downstream of (and can be therefore be interpreted as a) model 2.

Definition at line 286 of file models.cpp.

References descended_from(), and myFriendsDB.

Referenced by Gambit::functor::allowed_parent_or_friend_exists(), Gambit::functor::contains_anything_interpretable_as_member_of(), Gambit::functor::find_friend_or_parent_model_in_map(), Gambit::functor::in_allowed_combo(), Gambit::module_functor_common::notifyOfModel(), upstream_of(), and ~ModelFunctorClaw().

287  {
288  if (descended_from(model1, model2)) return true;
289  if (myFriendsDB.find(model1) != myFriendsDB.end())
290  {
291  std::set<str> friends = myFriendsDB.at(model1);
292  return friends.find(model2) != friends.end();
293  }
294  return false;
295  }
std::map< str, std::set< str > > myFriendsDB
Definition: models.hpp:73
bool descended_from(const str &, const str &) const
Check if model 1 is descended from model 2.
Definition: models.cpp:268
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_activemodels()

std::set< str > Gambit::Models::ModelFunctorClaw::get_activemodels ( ) const

Return the set of active models;.

Retrieve the internally stored vector of activated models.

Definition at line 106 of file models.cpp.

References activemodels.

Referenced by Gambit::DRes::DependencyResolver::closestCandidateForModel(), Gambit::DRes::DependencyResolver::makeFunctorsModelCompatible(), Gambit::DRes::DependencyResolver::resolveDependency(), Gambit::DRes::DependencyResolver::solveRequirement(), and ~ModelFunctorClaw().

106 { return activemodels; }
std::set< str > activemodels
Internal record of the active models.
Definition: models.hpp:64
Here is the caller graph for this function:

◆ get_allmodels()

const std::set< str > & Gambit::Models::ModelFunctorClaw::get_allmodels ( ) const

Return set of all models recognised by GAMBIT.

Definition at line 103 of file models.cpp.

References allmodelnames.

Referenced by ~ModelFunctorClaw().

103 { return allmodelnames; }
std::set< str > allmodelnames
Definition: models.hpp:68
Here is the caller graph for this function:

◆ get_best_friends()

std::set< str > Gambit::Models::ModelFunctorClaw::get_best_friends ( const str model) const

Retrieve the best friends for a given model.

Definition at line 262 of file models.cpp.

References myBestFriendsDB.

Referenced by Gambit::ModelHierarchy::makeGraph(), and ~ModelFunctorClaw().

263  {
264  return myBestFriendsDB.find(model) == myBestFriendsDB.end() ? std::set<str>() : myBestFriendsDB.at(model);
265  }
std::map< str, std::set< str > > myBestFriendsDB
Definition: models.hpp:74
Here is the caller graph for this function:

◆ get_descendants()

std::vector< str > Gambit::Models::ModelFunctorClaw::get_descendants ( const str model) const

Retrieve the descendants for a given model.

Definition at line 238 of file models.cpp.

References myDescendantsDB.

Referenced by Gambit::gambit_core::check_databases(), and ~ModelFunctorClaw().

239  {
240  return myDescendantsDB.find(model) == myDescendantsDB.end() ? std::vector<str>() : myDescendantsDB.at(model);
241  }
std::map< str, std::vector< str > > myDescendantsDB
Definition: models.hpp:71
Here is the caller graph for this function:

◆ get_friends()

std::set< str > Gambit::Models::ModelFunctorClaw::get_friends ( const str model) const

Retrieve the friends for a given model.

Definition at line 256 of file models.cpp.

References myFriendsDB.

Referenced by ~ModelFunctorClaw().

257  {
258  return myFriendsDB.find(model) == myFriendsDB.end() ? std::set<str>() : myFriendsDB.at(model);
259  }
std::map< str, std::set< str > > myFriendsDB
Definition: models.hpp:73
Here is the caller graph for this function:

◆ get_lineage()

std::vector< str > Gambit::Models::ModelFunctorClaw::get_lineage ( const str model) const

Retrieve the lineage for a given model.

Definition at line 250 of file models.cpp.

References myLineageDB.

Referenced by Gambit::gambit_core::check_databases(), and ~ModelFunctorClaw().

251  {
252  return myLineageDB.find(model) == myLineageDB.end() ? std::vector<str>() : myLineageDB.at(model);
253  }
std::map< str, std::vector< str > > myLineageDB
Definition: models.hpp:70
Here is the caller graph for this function:

◆ get_parent()

str Gambit::Models::ModelFunctorClaw::get_parent ( const str model) const

Retrieve the parent model for a given model.

Retrieve the parents for a given model.

Definition at line 244 of file models.cpp.

References myParentsDB.

Referenced by Gambit::gambit_core::check_databases(), Gambit::DRes::DependencyResolver::closestCandidateForModel(), Gambit::ModelHierarchy::makeGraph(), Gambit::gambit_core::model_diagnostic(), Gambit::DRes::DependencyResolver::resolveDependency(), Gambit::DRes::DependencyResolver::solveRequirement(), and ~ModelFunctorClaw().

245  {
246  return myParentsDB.find(model) == myParentsDB.end() ? "none" : myParentsDB.at(model);
247  }
std::map< str, str > myParentsDB
Definition: models.hpp:69
Here is the caller graph for this function:

◆ getPrimaryModelFunctorsToActivate()

primodel_vec Gambit::Models::ModelFunctorClaw::getPrimaryModelFunctorsToActivate ( std::set< str selectedmodels,
const primodel_vec primaryModelFunctors 
)

Model activation function.

ModelFunctorClaw function definitions Models object the performs initialisation and checking operations on a primary_model_functor list.

Returns a vector of primary_model_functors to be activated, according to the model(s) being scanned

Model activation function Returns a vector of primary_model_functors to be activated, according to the model(s) being scanned

Definition at line 52 of file models.cpp.

References activemodels, LOCAL_INFO, and Gambit::model_error().

Referenced by ~ModelFunctorClaw().

53  {
54  // Holder for result
55  primodel_vec result;
56  // Iterator to elements of 'selectedmodels'
57  std::set<str>::iterator el;
58 
59  // Loop through functor list and activate functor if it matches a member of 'selectedmodels'.
60  for (primodel_vec::const_iterator
61  it = primaryModelFunctors.begin();
62  it != primaryModelFunctors.end();
63  ++it)
64  {
65  // Check if this functor originates from one of the selected models
66  el = std::find(selectedmodels.begin(), selectedmodels.end(), (*it)->origin());
67  if(el != selectedmodels.end())
68  {
69  // If yes, activate this functor. Default is inactivated.
70  (*it)->setStatus(1); // 1 means "available".
71  (*it)->setPrintRequirement(true); // Tell printer to output this functor
72  // Initialise ModelParameters object it contains
73  (*it)->calculate();
74  // Add it to the vector of primary model functors to make active (to be returned)
75  result.push_back(*it);
76  // Add it to the internal list of active models
77  activemodels.insert(*el);
78  // Remove it from the input 'selectedmodels' list
79  selectedmodels.erase(el);
80  }
81  }
82 
83  // Check that all requested models have been activated
84  if( selectedmodels.size() != 0 )
85  {
86  // Report error
87  str errmsg = "Error! Some of the requested models could not be activated for \n";
88  errmsg += "scanning! Probably they have not been defined, or you spelled \n";
89  errmsg += "their name wrong in the ini file. \n";
90  errmsg += "Models that cannot be activated: \n";
91  for (std::set<str>::iterator m = selectedmodels.begin(); m != selectedmodels.end(); ++m)
92  {
93  errmsg += (" " + *m + "\n");
94  }
95  model_error().raise(LOCAL_INFO,errmsg);
96  }
97 
98  return result;
99 
100  }
std::vector< primary_model_functor * > primodel_vec
Definition: models.hpp:50
#define LOCAL_INFO
Definition: local_info.hpp:34
std::set< str > activemodels
Internal record of the active models.
Definition: models.hpp:64
std::string str
Definition: models.hpp:49
error & model_error()
Model errors.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_models()

str Gambit::Models::ModelFunctorClaw::list_models ( ) const

List all the models recognised by GAMBIT.

Definition at line 215 of file models.cpp.

References allmodelnames.

Referenced by add_friend(), declare_model(), verify_model(), and ~ModelFunctorClaw().

216  {
217  str temp = "";
218  for (std::set<str>::iterator it = allmodelnames.begin(); it != allmodelnames.end(); ++it)
219  {
220  temp += "\n" + *it;
221  }
222  return temp;
223  }
std::set< str > allmodelnames
Definition: models.hpp:68
std::string str
Definition: models.hpp:49
Here is the caller graph for this function:

◆ model_exists()

bool Gambit::Models::ModelFunctorClaw::model_exists ( const str model) const

◆ upstream_of()

bool Gambit::Models::ModelFunctorClaw::upstream_of ( const str model1,
const str model2 
) const

Check if model 1 exists somewhere upstream of model 2, allowing model 2 to be interpreted as model 1.

Definition at line 298 of file models.cpp.

References downstream_of().

Referenced by ~ModelFunctorClaw().

299  {
300  return downstream_of(model2, model1);
301  }
bool downstream_of(const str &, const str &) const
Check if model 1 exists somewhere downstream of (and can be therefore be interpreted as a) model 2...
Definition: models.cpp:286
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_model()

void Gambit::Models::ModelFunctorClaw::verify_model ( const str model) const

Verify that a string matches a model recognised by GAMBIT, crash otherwise.

Definition at line 226 of file models.cpp.

References list_models(), LOCAL_INFO, Gambit::model_error(), and model_exists().

Referenced by descended_from(), and ~ModelFunctorClaw().

227  {
228  if (not model_exists(model))
229  {
230  str errmsg = "Model \"";
231  errmsg += model + "\" is not in the GAMBIT database.";
232  errmsg += "\nRecognised models are:" + list_models();
233  model_error().raise(LOCAL_INFO,errmsg);
234  }
235  }
str list_models() const
List all the models recognised by GAMBIT.
Definition: models.cpp:215
#define LOCAL_INFO
Definition: local_info.hpp:34
std::string str
Definition: models.hpp:49
bool model_exists(const str &) const
Indicate whether a model is recognised by GAMBIT or not.
Definition: models.cpp:209
error & model_error()
Model errors.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ activemodels

std::set<str> Gambit::Models::ModelFunctorClaw::activemodels
private

Internal record of the active models.

Definition at line 64 of file models.hpp.

Referenced by get_activemodels(), and getPrimaryModelFunctorsToActivate().

◆ allmodelnames

std::set<str> Gambit::Models::ModelFunctorClaw::allmodelnames
private

Definition at line 68 of file models.hpp.

Referenced by declare_model(), get_allmodels(), list_models(), and model_exists().

◆ myBestFriendsDB

std::map<str, std::set<str> > Gambit::Models::ModelFunctorClaw::myBestFriendsDB
private

Definition at line 74 of file models.hpp.

Referenced by add_friend(), declare_model(), and get_best_friends().

◆ myDescendantsDB

std::map<str, std::vector<str> > Gambit::Models::ModelFunctorClaw::myDescendantsDB
private

Definition at line 71 of file models.hpp.

Referenced by declare_model(), and get_descendants().

◆ myFriendsDB

std::map<str, std::set<str> > Gambit::Models::ModelFunctorClaw::myFriendsDB
private

Definition at line 73 of file models.hpp.

Referenced by add_friend(), declare_model(), downstream_of(), and get_friends().

◆ myIsDescendantOfDB

std::map<str, LineageFunction > Gambit::Models::ModelFunctorClaw::myIsDescendantOfDB
private

Definition at line 72 of file models.hpp.

◆ myLineageDB

std::map<str, std::vector<str> > Gambit::Models::ModelFunctorClaw::myLineageDB
private

Definition at line 70 of file models.hpp.

Referenced by add_friend(), declare_model(), descended_from(), and get_lineage().

◆ myParentsDB

std::map<str, str> Gambit::Models::ModelFunctorClaw::myParentsDB
private

Definition at line 69 of file models.hpp.

Referenced by declare_model(), and get_parent().


The documentation for this class was generated from the following files: