Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
NeutrinoFluxReweight::ParameterTable Class Reference

A list/table of parameter names and values. More...

#include <ParameterTable.h>

Public Member Functions

 ParameterTable ()
 
void setParameter (Parameter p)
 add a parameter to the table or, if already there, reset its value More...
 
Parameter getParameter (const std::string &name) const
 get a parameter by name. throw an exception of a well defined type if we don't have it More...
 
double getParameterValue (const std::string &name) const
 get the value of a parameter. throw an exception of a well defined type if we don't have it More...
 
bool hasParameter (const std::string &name) const
 is the named parameter in the table? More...
 
const boost::interprocess::flat_map< std::string, double > & getMap () const
 

Protected Member Functions

void mapify () const
 Move the parameters from the vector to the map. More...
 

Protected Attributes

boost::interprocess::flat_map< std::string, double > table
 
std::vector< std::pair< std::string, double > > m_vector
 
bool m_vectorMode
 

Detailed Description

A list/table of parameter names and values.

The memory overhead of std::map turns out to be large for our case, so we use a boost::flat_map instead. This uses an ordered vector, so memory overhead is small. Insertion is slow, though, so we start out by putting all our parameters in a vector. At the first request for parameter or the entire map, we sort the vector, copy it into the map and free the vector. This is efficient when there is a "filling" phase when no reads are done, and a "reading" phase, when no more fills are done.

Definition at line 30 of file ParameterTable.h.

Constructor & Destructor Documentation

NeutrinoFluxReweight::ParameterTable::ParameterTable ( )
inline

Definition at line 32 of file ParameterTable.h.

Member Function Documentation

const boost::interprocess::flat_map<std::string, double>& NeutrinoFluxReweight::ParameterTable::getMap ( ) const
inline

Definition at line 45 of file ParameterTable.h.

45 { mapify(); return table; }
void mapify() const
Move the parameters from the vector to the map.
boost::interprocess::flat_map< std::string, double > table
Parameter NeutrinoFluxReweight::ParameterTable::getParameter ( const std::string name) const

get a parameter by name. throw an exception of a well defined type if we don't have it

Definition at line 17 of file ParameterTable.cpp.

17  {
18  mapify();
19  Parameter pOut;
21 
22  if(it!=table.end()){
23  pOut.first = name;
24  pOut.second = it->second;
25  }
26  else{
27  throw NoParameterFound(name);
28  }
29  return pOut;
30 
31  }
static QCString name
Definition: declinfo.cpp:673
intermediate_table::const_iterator const_iterator
std::pair< std::string, double > Parameter
void mapify() const
Move the parameters from the vector to the map.
boost::interprocess::flat_map< std::string, double > table
double NeutrinoFluxReweight::ParameterTable::getParameterValue ( const std::string name) const

get the value of a parameter. throw an exception of a well defined type if we don't have it

Definition at line 33 of file ParameterTable.cpp.

33  {
34  mapify();
35 
36  double val;
38 
39  if(it!=table.end()){
40  val = it->second;
41  }
42  else{
43  throw NoParameterFound(name);
44  }
45 
46  return val;
47 
48  }
static QCString name
Definition: declinfo.cpp:673
intermediate_table::const_iterator const_iterator
void mapify() const
Move the parameters from the vector to the map.
boost::interprocess::flat_map< std::string, double > table
bool NeutrinoFluxReweight::ParameterTable::hasParameter ( const std::string name) const

is the named parameter in the table?

Definition at line 50 of file ParameterTable.cpp.

50  {
51  mapify();
52  return table.find(name)!=table.end();
53  }
static QCString name
Definition: declinfo.cpp:673
void mapify() const
Move the parameters from the vector to the map.
boost::interprocess::flat_map< std::string, double > table
void NeutrinoFluxReweight::ParameterTable::mapify ( ) const
protected

Move the parameters from the vector to the map.

Definition at line 55 of file ParameterTable.cpp.

56  {
57  // If we're already out of vector mode, there's nothing to do
58  if(!m_vectorMode) return;
59 
60  // Sort the vector, populate the flat_map from it, and then clear
61  // the vector
62  std::sort(m_vector.begin(), m_vector.end());
63  table=boost::interprocess::flat_map<std::string, double>(m_vector.begin(), m_vector.end());
64  m_vector.clear();
65  // Magic to force the memory to be released: clear() doesn't do that
66  std::vector<std::pair<std::string, double> >().swap(m_vector);
67  // We're no longer in vector mode, so we won't run this function
68  // again
69  m_vectorMode=false;
70  }
void swap(Handle< T > &a, Handle< T > &b)
std::vector< std::pair< std::string, double > > m_vector
boost::interprocess::flat_map< std::string, double > table
void NeutrinoFluxReweight::ParameterTable::setParameter ( Parameter  p)

add a parameter to the table or, if already there, reset its value

Definition at line 8 of file ParameterTable.cpp.

8  {
9  if(m_vectorMode){
10  m_vector.push_back(p);
11  }
12  else{
13  table[p.first] = p.second;
14  }
15  }
p
Definition: test.py:223
std::vector< std::pair< std::string, double > > m_vector
boost::interprocess::flat_map< std::string, double > table

Member Data Documentation

std::vector<std::pair<std::string, double> > NeutrinoFluxReweight::ParameterTable::m_vector
mutableprotected

Definition at line 51 of file ParameterTable.h.

bool NeutrinoFluxReweight::ParameterTable::m_vectorMode
mutableprotected

Definition at line 52 of file ParameterTable.h.

boost::interprocess::flat_map<std::string, double> NeutrinoFluxReweight::ParameterTable::table
mutableprotected

Definition at line 50 of file ParameterTable.h.


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