gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
subspectrum_contents.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
18 
22 
23 namespace Gambit
24 {
26  void SubSpectrumContents::addParameter(const Par::Tags tag, const std::string& name, const std::vector<int>& shape)
27  {
28  parameters.emplace_back(tag,name,shape);
29  }
30 
32  void SubSpectrumContents::setName(const std::string& name)
33  {
34  my_name = name;
35  }
36 
38  std::vector<SpectrumParameter> SubSpectrumContents::all_parameters() const
39  {
40  return parameters;
41  }
42 
44  std::vector<SpectrumParameter> SubSpectrumContents::all_parameters_with_tag(Par::Tags tag) const
45  {
46  std::vector<SpectrumParameter> search_result;
47  for( std::vector<SpectrumParameter>::const_iterator it=parameters.begin(); it!=parameters.end(); ++it )
48  {
49  if(it->tag() == tag) search_result.push_back(*it);
50  }
51  return search_result;
52  }
53 
55  std::vector<SpectrumParameter> SubSpectrumContents::all_parameters_with_tag_and_shape(Par::Tags tag, std::vector<int>& shape) const
56  {
57  std::vector<SpectrumParameter> search_result;
58  for( std::vector<SpectrumParameter>::const_iterator it=parameters.begin(); it!=parameters.end(); ++it )
59  {
60  if(it->tag() == tag and it->shape() == shape) search_result.push_back(*it);
61  }
62  return search_result;
63  }
64 
65 
68  {
69  const std::vector<SpectrumParameter> required_parameters = all_parameters();
70 
71  for(std::vector<SpectrumParameter>::const_iterator it = required_parameters.begin();
72  it != required_parameters.end(); ++it)
73  {
74  const Par::Tags tag = it->tag();
75  const std::string name = it->name();
76  const std::vector<int> shape = it->shape();
77 
78  // Deal with empty shape case
79  if(shape.size()==0)
80  {
81  // ERROR, please use length 1 vector for scalar case
82  std::ostringstream errmsg;
83  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
84  errmsg << "Encountered a required parameter ("<<Par::toString.at(tag)<<", "<<name<<") with shape.size()==0. This is not allowed; if you want this parameter to be considered a scalar, please set the shape to '1', i.e. std::vector<int> shape = initVector(1). Please fix this parameter in the SubSpectrumContents class." << std::endl;
85  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
86  }
87  // Check scalar case
88  else if(shape.size()==1 and shape[0]==1)
89  {
90  if(not spec.has(tag,name))
91  {
92  // ERROR, Required parameter not found
93  std::ostringstream errmsg;
94  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
95  errmsg << "Required scalar-valued parameter ("<<Par::toString.at(tag)<<", "<<name<<") is not accessible via subspectrum->get(Par::"<<Par::toString.at(tag)<<", \""<<name<<"\"). Please fix the relevant SubSpectrum wrapper class so that this parameter can be accessed." << std::endl;
96  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
97  }
98  }
99  // Check vector case
100  else if(shape.size()==1 and shape[0]>1)
101  {
102  if(shape[0]<0)
103  {
104  // ERROR, asked for negative length vector
105  std::ostringstream errmsg;
106  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
107  errmsg << "Encountered a vector-valued required parameter ("<<Par::toString.at(tag)<<", "<<name<<") with negative required length ("<<shape[0]<<")! This is invalid; Please fix this parameter in the SubSpectrumContents class so that the required length is a positive number." << std::endl;
108  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
109  }
110  else
111  {
112  for(int i = 1; i<=shape[0]; ++i) {
113  if(not spec.has(tag,name,i))
114  {
115  // ERROR, Required parameter not found
116  std::ostringstream errmsg;
117  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
118  errmsg << "An entry of the required vector-valued parameter ("<<Par::toString.at(tag)<<", "<<name<<") with required length "<<shape[0]<<" is not accessible via subspectrum->get(Par::"<<Par::toString.at(tag)<<", \""<<name<<"\", "<<i<<"). Please fix the relevant SubSpectrum wrapper class so that this parameter can be accessed. Keep in mind that you may need to override index_offset() to align the expected indices." << std::endl;
119  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
120  }
121  }
122  }
123  }
124  // Check matrix case
125  else if(shape.size()==2)
126  {
127  if(shape[0]<0 or shape[1]<0)
128  {
129  // ERROR, asked for negative matrix dimensions
130  std::ostringstream errmsg;
131  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
132  errmsg << "Encountered a matrix-valued required parameter ("<<Par::toString.at(tag)<<", "<<name<<") with at least one negative required dimension (dims = ["<<shape[0]<<", "<<shape[1]<<"])! This is invalid; Please fix the shape settings for this parameter in the SubSpectrumContents so that they are positive numbers." << std::endl;
133  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
134  }
135  else
136  {
137  for(int i = 1; i<=shape[0]; ++i) {
138  for(int j = 1; j<=shape[0]; ++j) {
139  if(not spec.has(tag,name,i,j))
140  {
141  // ERROR, Required parameter not found
142  std::ostringstream errmsg;
143  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
144  errmsg << "An entry of the required matrix-valued parameter ("<<Par::toString.at(tag)<<", "<<name<<") with required dimensions ("<<shape[0]<<", "<<shape[1]<<") is not accessible via subspectrum->get(Par::"<<Par::toString.at(tag)<<", \""<<name<<"\", "<<i<<", "<<j<<"). Please fix the relevant SubSpectrum wrapper class so that this parameter can be accessed. Keep in mind that you may need to override index_offset() to align the expected indices." << std::endl;
145  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
146  }
147  }
148  }
149  }
150  }
151  // Deal with all other cases
152  else
153  {
154  // ERROR invalid shape
155  std::ostringstream errmsg;
156  errmsg << "Error while verifying contents of SubSpectrum object against SubSpectrumContents object with name \""<<my_name<<"\" !" << std::endl;
157  errmsg << "The specified shape for the required parameter ("<<Par::toString.at(tag)<<", "<<name<<") is invalid. The length of the shape vector is only permitted to be 1 or 2 (received shape vector was "<<shape<<"). Please fix this parameter entry in the SubSpectrumContents class."<<std::endl;
158  utils_error().forced_throw(LOCAL_INFO,errmsg.str());
159  }
160  }
161  // End constructor
162  }
164 
165 }
166 
Define overloadings of the stream operator for various containers.
EXPORT_SYMBOLS error & utils_error()
Utility errors.
#define LOCAL_INFO
Definition: local_info.hpp:34
void setName(const std::string &name)
Set the name of this Contents object (i.e. the name of the model to which this spectrum data applies)...
void addParameter(const Par::Tags tag, const std::string &name, const std::vector< int > &shape=initVector(1))
Add a parameter to the Contents object.
std::string my_name
Name of SubSpectrumContents class (for more helpful error messages)
void verify_contents(const SubSpectrum &spec) const
Function to verify that a SubSpectrum wrapper contains everything that this class says it should...
std::vector< SpectrumParameter > parameters
Vector defining what parameters a wrapper must contain.
std::vector< SpectrumParameter > all_parameters_with_tag(Par::Tags tag) const
Function to retreive all parameters matching a certain tag.
Abstract class for accessing general spectrum information.
Base class for definining the required contents of SubSpectrum wrapper objects.
Virtual base class for interacting with spectrum generator output.
Definition: subspectrum.hpp:87
std::vector< SpectrumParameter > all_parameters_with_tag_and_shape(Par::Tags tag, std::vector< int > &shape) const
Function to retrieve all parameters matching a certain tag and shape.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
virtual bool has(const Par::Tags, const str &, const SpecOverrideOptions=use_overrides, const SafeBool check_antiparticle=SafeBool(true)) const =0
Getters/Setters etc.
std::vector< SpectrumParameter > all_parameters() const
Function to retreive all parameters.