Belle II Software  release-05-01-25
IRGeoBase.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Luka Santelj *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <map>
14 #include <string>
15 #include <TObject.h>
16 #include <framework/gearbox/GearDir.h>
17 #include <framework/logging/Logger.h>
18 #include <iostream>
19 
20 namespace Belle2 {
29  class IRGeoBase: public TObject {
30 
31  public:
32 
36  IRGeoBase()
37  {}
38 
43  double getParameter(const std::string& name) const
44  {
45  std::map<std::string, double>::const_iterator it = m_params.find(name);
46  if (it != m_params.end()) return (*it).second;
47  B2FATAL("Requested parameter from IR database not found: " << name);
48  }
49 
55  double getParameter(const std::string& name, double def) const
56  {
57  std::map<std::string, double>::const_iterator it = m_params.find(name);
58  if (it != m_params.end()) return (*it).second;
59  return def;
60  }
61 
66  const std::string& getParameterStr(const std::string& name) const
67  {
68  std::map<std::string, std::string>::const_iterator it = m_strparams.find(name);
69  if (it != m_strparams.end()) return (*it).second;
70  B2FATAL("Requested parameter from IR database not found: " << name);
71  }
72 
77  const std::string& getParameterStr(const std::string& name, const std::string& def) const
78  {
79  std::map<std::string, std::string>::const_iterator it = m_strparams.find(name);
80  if (it != m_strparams.end()) return (*it).second;
81  return def;
82  }
83 
87  const std::map<std::string, double>& getParameters() const { return m_params;}
88 
92  const std::map<std::string, std::string>& getParametersStr() const { return m_strparams;}
93 
99  void addParameter(const std::string& name, double val)
100  {
101  if (m_params.insert(std::pair<std::string, double>(name, val)).second) return;
102  else {
103  m_params.find(name)->second = val;
104  }
105  }
106 
112  void addParameter(const std::string& name, const std::string& val)
113  {
114  if (m_strparams.insert(std::pair<std::string, std::string>(name, val)).second) return;
115  else {
116  m_strparams.find(name)->second = val;
117  }
118  }
119 
125  void addParameters(const GearDir& content, const std::string& section)
126  {
127 
128  for (const GearDir& slot : content.getNodes("sec")) {
129  std::string name = slot.getString("@name");
130  std::string unt = slot.getString("@unit");
131  double value;
132  if (unt.find("rad") != std::string::npos) value = slot.getAngle();
133  else value = slot.getLength();
134  addParameter(section + "." + name, value);
135  }
136  if (content.exists("Material")) addParameter(section + ".Material", content.getString("Material"));
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;
163  ClassDef(IRGeoBase, 1);
165  };
166 
168 } // end namespace Belle2
Belle2::IRGeoBase::getParameters
const std::map< std::string, double > & getParameters() const
Get map of all parameters.
Definition: IRGeoBase.h:95
Belle2::IRGeoBase::getParametersStr
const std::map< std::string, std::string > & getParametersStr() const
Get map of all string parameters.
Definition: IRGeoBase.h:100
Belle2::IRGeoBase::m_params
std::map< std::string, double > m_params
map of numeric parameters
Definition: IRGeoBase.h:169
Belle2::IRGeoBase::getParameter
double getParameter(const std::string &name) const
Get parameter value.
Definition: IRGeoBase.h:51
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::IRGeoBase::print
void print() const
Print all parameters.
Definition: IRGeoBase.h:155
Belle2::IRGeoBase::ClassDef
ClassDef(IRGeoBase, 1)
ClassDef.
Belle2::IRGeoBase::addParameters
void addParameters(const GearDir &content, const std::string &section)
Add parameters from Gearbox.
Definition: IRGeoBase.h:133
Belle2::IRGeoBase::addParameter
void addParameter(const std::string &name, double val)
Add parameter to map of parameters.
Definition: IRGeoBase.h:107
Belle2::IRGeoBase::getParameterStr
const std::string & getParameterStr(const std::string &name) const
Get string parameter.
Definition: IRGeoBase.h:74
Belle2::IRGeoBase::m_strparams
std::map< std::string, std::string > m_strparams
map of string parameters
Definition: IRGeoBase.h:170
Belle2::IRGeoBase::IRGeoBase
IRGeoBase()
Default constructor.
Definition: IRGeoBase.h:44