gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
type_equivalency.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
19 
20 #include "yaml-cpp/yaml.h"
21 
24 #include "gambit/Backends/backend_singleton.hpp"
25 #include "gambit/cmake/cmake_variables.hpp"
26 
27 namespace Gambit
28 {
29 
30  namespace Utils
31  {
32 
35  {
37  s = strip_leading_namespace(s, "Gambit");
38  // Loop over all the default versions of BOSSed backends and replace any corresponding leading namespace.
39  for (auto it = Backends::backendInfo().default_safe_versions.begin(); it != Backends::backendInfo().default_safe_versions.end(); ++it)
40  {
41  s = Utils::replace_leading_namespace(s, it->first+"_default", it->first+"_"+it->second);
42  }
43  return s;
44  }
45 
48  filename(GAMBIT_DIR "/config/resolution_type_equivalency_classes.yaml")
49  {
50  // Read yaml configuration file
51  std::vector<YAML::Node> yaml_entries;
52  try
53  {
54  yaml_entries = YAML::LoadAllFromFile(filename);
55  }
56  catch (YAML::Exception &e)
57  {
58  std::ostringstream msg;
59  msg << "Could not read resolution type equivalency class file \""<<filename<<"\"!" << endl;
60  msg << "Please check that file exists and contains valid YAML." << endl;
61  msg << "("<<e.what()<<")";
62  utils_error().raise(LOCAL_INFO,msg.str());
63  }
64  // Iterate over the entries in the configuration file and add them to the set of equivalency classes
65  for (auto it = yaml_entries.begin(); it != yaml_entries.end(); ++it)
66  {
67  add(it->as< std::vector<str> >());
68  }
69  }
70 
74  {
75  bool already_added = false;
76  std::set<std::set<str> > equivalency_classes_copy = equivalency_classes;
77  for (std::set<std::set<str> >::const_iterator it = equivalency_classes_copy.begin(); it != equivalency_classes_copy.end(); ++it)
78  {
79  std::set<str>::const_iterator loc1 = it->find(t1);
80  std::set<str>::const_iterator loc2 = it->find(t2);
81  std::set<str>::const_iterator end = it->end();
82  if (loc1 != end and loc2 == end)
83  {
84  std::set<str> temp = *it;
85  temp.insert(fix_type(t2));
86  equivalency_classes.erase(*it);
87  equivalency_classes.insert(temp);
88  already_added = true;
89  }
90  if (loc2 != end and loc1 == end)
91  {
92  std::set<str> temp = *it;
93  temp.insert(fix_type(t1));
94  equivalency_classes.erase(*it);
95  equivalency_classes.insert(temp);
96  already_added = true;
97  }
98  if (loc1 != end and loc2 != end)
99  {
100  already_added = true;
101  }
102  if (already_added) break;
103  }
104  if (not already_added)
105  {
106  str types[] = {fix_type(t1),fix_type(t2)};
107  equivalency_classes.insert(std::set<str>(types,types+2));
108  }
109  }
110  void type_equivalency::add(str t1, str t2, str t3) { add(t1,t2); add(t1,t3); }
111  void type_equivalency::add(str t1, str t2, str t3, str t4) { add(t1,t2); add(t1,t3); add(t1,t4); }
112  void type_equivalency::add(str t1, str t2, str t3, str t4, str t5) { add(t1,t2); add(t1,t3); add(t1,t4); add(t1,t5); }
113  void type_equivalency::add(str t1, str t2, str t3, str t4, str t5, str t6) { add(t1,t2); add(t1,t3); add(t1,t4); add(t1,t5); add(t1,t6); }
114  void type_equivalency::add(std::vector<str> v) { for (auto it = v.begin()+1; it != v.end(); ++it) { add(v[0],*it); } }
116 
117  }
118 
119 }
EXPORT_SYMBOLS str replace_leading_namespace(str s, str ns, str ns_new)
Replaces a namespace at the start of a string, or after "const".
EXPORT_SYMBOLS error & utils_error()
Utility errors.
#define LOCAL_INFO
Definition: local_info.hpp:34
General small utility functions.
std::set< std::set< str > > equivalency_classes
}@ The total set of equivalency classes
EXPORT_SYMBOLS void strip_whitespace_except_after_const(str &)
Strip all whitespace except that following "const", in which case the whitespace is replaced by a sin...
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
EXPORT_SYMBOLS str strip_leading_namespace(str s, str ns)
Strips namespace from the start of a string, or after "const".
void add(str, str)
Define a new equivalency relation {.
Simple container used for storing info about which types have been defined as equivalent for depencen...
str fix_type(str)
Clean out whitespace and strip Gambit and default BOSSed class namespaces.
TODO: see if we can use this one:
Definition: Analysis.hpp:33