Belle II Software  release-08-01-10
IRGeoBase.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <map>
12 #include <string>
13 #include <TObject.h>
14 #include <framework/gearbox/GearDir.h>
15 #include <framework/logging/Logger.h>
16 #include <iostream>
17 
18 namespace Belle2 {
27  class IRGeoBase: public TObject {
28 
29  public:
30 
35  {}
36 
41  double getParameter(const std::string& name) const
42  {
43  std::map<std::string, double>::const_iterator it = m_params.find(name);
44  if (it != m_params.end()) return (*it).second;
45  B2FATAL("Requested parameter from IR database not found: " << name);
46  }
47 
53  double getParameter(const std::string& name, double def) const
54  {
55  std::map<std::string, double>::const_iterator it = m_params.find(name);
56  if (it != m_params.end()) return (*it).second;
57  return def;
58  }
59 
64  const std::string& getParameterStr(const std::string& name) const
65  {
66  std::map<std::string, std::string>::const_iterator it = m_strparams.find(name);
67  if (it != m_strparams.end()) return (*it).second;
68  B2FATAL("Requested parameter from IR database not found: " << name);
69  }
70 
76  const std::string& getParameterStr(const std::string& name, const std::string& def) const
77  {
78  std::map<std::string, std::string>::const_iterator it = m_strparams.find(name);
79  if (it != m_strparams.end()) return (*it).second;
80  return def;
81  }
82 
86  const std::map<std::string, double>& getParameters() const { return m_params;}
87 
91  const std::map<std::string, std::string>& getParametersStr() const { return m_strparams;}
92 
98  void addParameter(const std::string& name, double val)
99  {
100  if (m_params.insert(std::pair<std::string, double>(name, val)).second) return;
101  else {
102  m_params.find(name)->second = val;
103  }
104  }
105 
111  void addParameter(const std::string& name, const std::string& val)
112  {
113  if (m_strparams.insert(std::pair<std::string, std::string>(name, val)).second) return;
114  else {
115  m_strparams.find(name)->second = val;
116  }
117  }
118 
124  void addParameters(const GearDir& content, const std::string& section)
125  {
126 
127  for (const GearDir& slot : content.getNodes("sec")) {
128  std::string name = slot.getString("@name");
129  std::string unt = slot.getString("@unit");
130  double value;
131  if (unt.find("rad") != std::string::npos) value = slot.getAngle();
132  else value = slot.getLength();
133  addParameter(section + "." + name, value);
134  }
135  if (content.exists("Material")) addParameter(section + ".Material", content.getString("Material"));
136  if (content.exists("HeadMaterial")) addParameter(section + ".HeadMaterial", content.getString("HeadMaterial"));
137  if (content.exists("Intersect")) addParameter(section + ".Intersect", content.getString("Intersect"));
138  if (content.exists("Subtract")) addParameter(section + ".Subtract", content.getString("Subtract"));
139  if (content.exists("MotherVolume")) addParameter(section + ".MotherVolume", content.getString("MotherVolume"));
140  if (content.exists("N")) addParameter(section + ".N", double(content.getInt("N")));
141  if (content.exists("@type")) addParameter(section + ".type", content.getString("@type"));
142  };
143 
147  void print() const
148  {
149  for (std::pair<std::string, double> element : m_params) {
150  std::cout << element.first << " " << element.second << std::endl;
151  }
152 
153  for (std::pair<std::string, std::string> element : m_strparams) {
154  std::cout << element.first << " " << element.second << std::endl;
155  }
156  }
157 
158 
159  protected:
160 
161  std::map<std::string, double> m_params;
162  std::map<std::string, std::string> m_strparams;
165  };
166 
168 } // end namespace Belle2
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
Base class for IR geometry parameters.
Definition: IRGeoBase.h:27
ClassDef(IRGeoBase, 1)
ClassDef.
void addParameters(const GearDir &content, const std::string &section)
Add parameters from Gearbox.
Definition: IRGeoBase.h:124
double getParameter(const std::string &name, double def) const
Get parameter value with giving default value in case parameter doesn't exist in DB.
Definition: IRGeoBase.h:53
const std::map< std::string, std::string > & getParametersStr() const
Get map of all string parameters.
Definition: IRGeoBase.h:91
void addParameter(const std::string &name, const std::string &val)
Add string parameter to map of parameters.
Definition: IRGeoBase.h:111
void addParameter(const std::string &name, double val)
Add parameter to map of parameters.
Definition: IRGeoBase.h:98
const std::string & getParameterStr(const std::string &name, const std::string &def) const
Get string parameter with giving default value in case of non-existence.
Definition: IRGeoBase.h:76
const std::map< std::string, double > & getParameters() const
Get map of all parameters.
Definition: IRGeoBase.h:86
std::map< std::string, double > m_params
map of numeric parameters
Definition: IRGeoBase.h:161
IRGeoBase()
Default constructor.
Definition: IRGeoBase.h:34
double getParameter(const std::string &name) const
Get parameter value.
Definition: IRGeoBase.h:41
std::map< std::string, std::string > m_strparams
map of string parameters
Definition: IRGeoBase.h:162
const std::string & getParameterStr(const std::string &name) const
Get string parameter.
Definition: IRGeoBase.h:64
void print() const
Print all parameters.
Definition: IRGeoBase.h:147
Abstract base class for different kinds of events.