ParameterTable.h
Go to the documentation of this file.
1 #ifndef PARAMETERTABLE_H
2 #define PARAMETERTABLE_H
3 // This lives in boost/containers/flat_map.hpp in versions of boost
4 // less ancient than the one in the Minerva software
5 #include <boost/interprocess/containers/flat_map.hpp>
6 #include <vector>
7 #include <map>
8 #include <string>
9 
10 namespace NeutrinoFluxReweight{
11 
12  /*! \typedef typedef std::pair<std::string, double> Parameter;
13  The name and value of a single parameter used in cv reweighting, many universes uncertainty calculations, or both.
14  */
15  typedef std::pair<std::string, double> Parameter;
16 
17 
18  /*! \class ParameterTable
19  * \brief A list/table of parameter names and values.
20  *
21  * The memory overhead of std::map turns out to be large for our
22  * case, so we use a boost::flat_map instead. This uses an ordered
23  * vector, so memory overhead is small. Insertion is slow, though,
24  * so we start out by putting all our parameters in a vector. At the
25  * first request for parameter or the entire map, we sort the
26  * vector, copy it into the map and free the vector. This is
27  * efficient when there is a "filling" phase when no reads are done,
28  * and a "reading" phase, when no more fills are done.
29  */
31  public:
33  : m_vectorMode(true)
34  {}
35 
36  //! add a parameter to the table or, if already there, reset its value
37  void setParameter(Parameter p);
38  //! get a parameter by name. throw an exception of a well defined type if we don't have it
39  Parameter getParameter(const std::string& name) const;
40  //! get the value of a parameter. throw an exception of a well defined type if we don't have it
41  double getParameterValue(const std::string& name) const;
42  //! is the named parameter in the table?
43  bool hasParameter(const std::string& name) const;
44 
45  const boost::interprocess::flat_map<std::string, double>& getMap() const { mapify(); return table; }
46  protected:
47 
48  //! Move the parameters from the vector to the map
49  void mapify() const;
50  mutable boost::interprocess::flat_map<std::string, double> table;
51  mutable std::vector<std::pair<std::string, double> > m_vector;
52  mutable bool m_vectorMode;
53  };
54 
55 }
56 #endif
static QCString name
Definition: declinfo.cpp:673
A list/table of parameter names and values.
const boost::interprocess::flat_map< std::string, double > & getMap() const
Parameter getParameter(const std::string &name) const
get a parameter by name. throw an exception of a well defined type if we don&#39;t have it ...
std::string string
Definition: nybbler.cc:12
double getParameterValue(const std::string &name) const
get the value of a parameter. throw an exception of a well defined type if we don&#39;t have it ...
bool hasParameter(const std::string &name) const
is the named parameter in the table?
std::pair< std::string, double > Parameter
void mapify() const
Move the parameters from the vector to the map.
p
Definition: test.py:223
std::vector< std::pair< std::string, double > > m_vector
boost::interprocess::flat_map< std::string, double > table
void setParameter(Parameter p)
add a parameter to the table or, if already there, reset its value