gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
slhaea_helpers.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
27 
28 #ifndef __slha_helpers_hpp__
29 #define __slha_helpers_hpp__
30 
33 
34 #include "SLHAea/slhaea.h"
35 
36 #include <boost/serialization/strong_typedef.hpp>
37 
38 namespace Gambit
39 {
41  typedef SLHAea::Coll SLHAstruct;
42 
46  BOOST_STRONG_TYPEDEF(SLHAstruct, MSSM_SLHAstruct)
47  BOOST_STRONG_TYPEDEF(SLHAstruct, SMslha_SLHAstruct)
48 
49 
50  SLHAstruct read_SLHA(str slha);
51 
53  double SLHAea_get(const SLHAstruct& slha, const str& block, const int index);
54 
56  double SLHAea_get(const SLHAstruct& slha, const str& block, const int index, const double defvalue);
57 
59  void SLHAea_add_block(SLHAstruct&, const str& name, const double scale = -1);
60 
62  void SLHAea_delete_block(SLHAstruct& slha, const std::string& block);
63 
65  bool SLHAea_block_exists(SLHAstruct& slha, const str& block);
67  bool SLHAea_check_block(SLHAstruct& slha, const str& block);
69  bool SLHAea_check_block(SLHAstruct& slha, const str& block, const int index); /*, const bool overwrite)*/
70  bool SLHAea_check_block(SLHAstruct& slha, const str& block, const int index1, const int index2);
71 
73  void SLHAea_add_GAMBIT_SPINFO(SLHAstruct& slha /*modify*/);
74 
77  void SLHAea_add(SLHAstruct& slha /*modify*/, const str& block, const int index, const double value,
78  const str& comment="", const bool overwrite=false);
79  void SLHAea_add(SLHAstruct& slha /*modify*/, const str& block, const int index, const str& value,
80  const str& comment="", const bool overwrite=false);
81  void SLHAea_add(SLHAstruct& slha /*modify*/, const str& block, const int index, const int value,
82  const str& comment="", const bool overwrite=false);
83  // two index version
84  void SLHAea_add(SLHAstruct& slha /*modify*/, const str& block, const int index1, const int index2,
85  const double& value, const str& comment, const bool overwrite=false);
87 
89  template<typename T>
90  void SLHAea_add_matrix(SLHAstruct& slha /*modify*/, const str& block, const std::vector<T>& matrix,
91  const int rows, const int cols, const str& comment="", const bool overwrite=false)
92  {
93  if (SLHAea_check_block(slha, block, 1, overwrite)) return;
94  std::ostringstream commentwhash;
95  if (comment != "") commentwhash << "# " << comment;
96  for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++)
97  {
98  slha[block][""] << i+1 << j+1 << matrix.at(i*rows + j) << commentwhash.str();
99  }
100  return;
101  }
102 
103 
105  template <class T>
106  void SLHAea_overwrite_block(SLHAstruct& slha /*modify*/, const str& block, int index,
107  T value, const str& comment)
108  {
109  if(SLHAea_check_block(slha, block, index))
110  {
111  // entry exists already, delete it
112  slha.at(block).at(index).at(1);
113  auto& line = slha[block][index];
114  line.clear();
115  line << index << value << comment;
116  }
117  else
118  {
119  // Doesn't already exist, add it
120  slha[block][""] << index << value << comment;
121  }
122  }
123 
125  template <class T>
126  void SLHAea_overwrite_block(SLHAstruct& slha /*modify*/, const str& block, int index1, int index2,
127  T value, const str& comment)
128  {
129  //std::vector<int> indices = initVector<int>(index1, index2);
130  if(SLHAea_check_block(slha, block, index1, index2))
131  {
132  // entry exists already, delete it
133  //slha.at(block).at(indices).at(1); // Is this actually a valid way to use SLHAea? I don't see it in their documentation.
134  std::stringstream i,j;
135  i<<index1; j<<index2;
136  SLHAea::Block::key_type key(2);
137  key[0] = i.str();
138  key[1] = j.str();
139  auto& line = slha[block][key];
140  line.clear();
141  line << index1 << index2 << value << comment;
142  }
143  else
144  {
145  // Doesn't exist, add it
146  slha[block][""] << index1 << index2 << value << comment;
147  }
148  }
149 
150 
151 
152 }
153 
154 #endif //defined __slhaea_helpers_hpp__
155 
156 
157 
void SLHAea_add_block(SLHAstruct &, const str &name, const double scale=-1)
Add a new block to an SLHAea object, with or without a scale.
SMslha_SLHAstruct SLHAstruct read_SLHA(str slha)
Read an SLHA file in to an SLHAea object with some error-checking.
General small utility classes, typedefs, etc.
T * matrix(const int xN)
Definition: random_tools.hpp:9
BOOST_STRONG_TYPEDEF(SLHAstruct, MSSM_SLHAstruct) BOOST_STRONG_TYPEDEF(SLHAstruct
Create a strong typedef (different classes underneath, but can be assigned to each other etc...
void SLHAea_add_GAMBIT_SPINFO(SLHAstruct &slha)
Write the SPINFO block with GAMBIT name and version number.
void SLHAea_add(SLHAstruct &slha, const str &block, const int index, const double value, const str &comment="", const bool overwrite=false)
Add an entry to an SLHAea object (if overwrite=false, only if it doesn&#39;t already exist) ...
SLHAea::Coll SLHAstruct
Less confusing name for SLHAea container class.
bool SLHAea_block_exists(SLHAstruct &slha, const str &block)
Check if a block exists in an SLHAea object.
void SLHAea_overwrite_block(SLHAstruct &slha, const str &block, int index, T value, const str &comment)
Check if a line exists in an SLHAea block, then overwrite it if it does. Otherwise add the line...
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
void SLHAea_delete_block(SLHAstruct &slha, const std::string &block)
Delete an entire block from an SLHAea object, if it exists (actually just the first block matching th...
Exception objects required for standalone compilation.
void SLHAea_add_matrix(SLHAstruct &slha, const str &block, const std::vector< T > &matrix, const int rows, const int cols, const str &comment="", const bool overwrite=false)
Add a whole matrix to an SLHAea object if it doesn&#39;t already exist.
double SLHAea_get(const SLHAstruct &slha, const str &block, const int index)
Get an entry from an SLHAea object as a double, with some error checking.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
bool SLHAea_check_block(SLHAstruct &slha, const str &block)
Check if a block exists in an SLHAea object, add it if not.