Belle II Software development
BeamabortGeo.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
18namespace Belle2 {
27 class BeamabortGeo: 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 BEAMABORT 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 std::vector<double> getParArray(const std::string& name) const
65 {
66 std::map<std::string, std::vector<double>>::const_iterator it = m_par_arrays.find(name);
67 if (it != m_par_arrays.end()) return (*it).second;
68 B2FATAL("Requested parameter from BEAMABORT database not found: " << name);
69 }
70
76 std::vector<double> getParArray(const std::string& name, std::vector<double> def) const
77 {
78 std::map<std::string, std::vector<double>>::const_iterator it = m_par_arrays.find(name);
79 if (it != m_par_arrays.end()) return (*it).second;
80 return def;
81 }
82
88 void addParameter(const std::string& name, double val)
89 {
90 if (m_params.insert(std::pair<std::string, double>(name, val)).second) return;
91 else {
92 m_params.find(name)->second = val;
93 }
94 }
95
101 void addArray(const std::string& name, std::vector<double> arr)
102 {
103 if (m_par_arrays.insert(std::pair<std::string, std::vector<double>>(name, arr)).second) return;
104 else {
105 m_par_arrays.find(name)->second = arr;
106 }
107 }
108
112 const std::map<std::string, double>& getParameters() const { return m_params;}
113
117 const std::map<std::string, std::vector<double>>& getParArrays() const { return m_par_arrays;}
118
122 void print() const
123 {
124 for (std::pair<std::string, double> element : m_params) {
125 std::cout << element.first << " " << element.second << std::endl;
126 }
127 }
128
133 void initialize(const GearDir& content);
134
135 private:
136
139 protected:
140
141 std::map<std::string, double> m_params;
142 std::map<std::string, std::vector<double>> m_par_arrays;
144 };
145
147} // end namespace Belle2
Geometry parameters of Beamabort.
Definition: BeamabortGeo.h:27
std::vector< double > getParArray(const std::string &name) const
Get parameter value array.
Definition: BeamabortGeo.h:64
ClassDef(BeamabortGeo, 1)
ClassDef.
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: BeamabortGeo.h:53
std::map< std::string, std::vector< double > > m_par_arrays
map of numeric parameter arrays
Definition: BeamabortGeo.h:142
std::vector< double > getParArray(const std::string &name, std::vector< double > def) const
Get parameter value array with giving default array in case parameter doesn't exist in DB.
Definition: BeamabortGeo.h:76
BeamabortGeo()
Default constructor.
Definition: BeamabortGeo.h:34
void addParameter(const std::string &name, double val)
Add parameter to map of parameters.
Definition: BeamabortGeo.h:88
std::map< std::string, double > m_params
map of numeric parameters
Definition: BeamabortGeo.h:141
const std::map< std::string, double > & getParameters() const
Get map of all parameters.
Definition: BeamabortGeo.h:112
void addArray(const std::string &name, std::vector< double > arr)
Add parameter array to map of parameters.
Definition: BeamabortGeo.h:101
double getParameter(const std::string &name) const
Get parameter value.
Definition: BeamabortGeo.h:41
void initialize(const GearDir &content)
Initialze from the gearbox (xml file)
Definition: BeamabortGeo.cc:13
void print() const
Print all parameters.
Definition: BeamabortGeo.h:122
const std::map< std::string, std::vector< double > > & getParArrays() const
Get map of all parameter arrays.
Definition: BeamabortGeo.h:117
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
Abstract base class for different kinds of events.