Belle II Software  release-05-02-19
DBRecord.cc
1 #include "daq/slc/database/DBRecord.h"
2 
3 #include "daq/slc/base/StringUtil.h"
4 
5 #include <cstdlib>
6 
7 using namespace Belle2;
8 
9 const std::string DBRecord::get(const std::string& name) const
10 {
11  if (m_value_m.find(name) != m_value_m.end()) return m_value_m[name];
12  else return "";
13 }
14 
15 const std::string DBRecord::get(int i) const
16 {
17  if (i >= 0 && i < (int)m_name_v.size())
18  return m_value_m[m_name_v[i]];
19  else return "";
20 }
21 
22 unsigned long long int DBRecord::getULLInt(const std::string& name) const
23 {
24  return std::strtoull(get(name).c_str(), NULL, 10);
25 }
26 
27 int DBRecord::getInt(const std::string& name) const
28 {
29  return atoi(get(name).c_str());
30 }
31 
32 int DBRecord::getInt(int i) const
33 {
34  return atoi(get(i).c_str());
35 }
36 
37 bool DBRecord::getBool(const std::string& name) const
38 {
39  return get(name) == "t";
40 }
41 
42 bool DBRecord::getBool(int i) const
43 {
44  return get(i) == "t";
45 }
46 
47 float DBRecord::getFloat(const std::string& name) const
48 {
49  return atof(get(name).c_str());
50 }
51 
52 float DBRecord::getFloat(int i) const
53 {
54  return atof(get(i).c_str());
55 }
56 
57 std::vector<std::string> DBRecord::getArray(const std::string& name) const
58 {
59  std::string value = StringUtil::replace(StringUtil::replace(get(name), "}", ""), "{", "");
60  return StringUtil::split(value, ',');
61 }
62 
63 std::vector<std::string> DBRecord::getArray(int i) const
64 {
65  std::string value = StringUtil::replace(StringUtil::replace(get(i), "}", ""), "{", "");
66  return StringUtil::split(value, ',');
67 }
68 
69 std::vector<int> DBRecord::getIntArray(const std::string& name) const
70 {
71  std::vector<int> value_i_v;
72  std::vector<std::string> value_v = getArray(name);
73  for (size_t i = 0; i < value_v.size(); i++) {
74  value_i_v.push_back(atoi(value_v[i].c_str()));
75  }
76  return value_i_v;
77 }
78 
79 std::vector<int> DBRecord::getIntArray(int i) const
80 {
81  std::vector<int> value_i_v;
82  std::vector<std::string> value_v = getArray(i);
83  for (size_t i = 0; i < value_v.size(); i++) {
84  value_i_v.push_back(atoi(value_v[i].c_str()));
85  }
86  return value_i_v;
87 }
88 
89 std::vector<float> DBRecord::getFloatArray(const std::string& name) const
90 {
91  std::vector<float> value_i_v;
92  std::vector<std::string> value_v = getArray(name);
93  for (size_t i = 0; i < value_v.size(); i++) {
94  value_i_v.push_back(atof(value_v[i].c_str()));
95  }
96  return value_i_v;
97 }
98 
99 std::vector<float> DBRecord::getFloatArray(int i) const
100 {
101  std::vector<float> value_i_v;
102  std::vector<std::string> value_v = getArray(i);
103  for (size_t i = 0; i < value_v.size(); i++) {
104  value_i_v.push_back(atof(value_v[i].c_str()));
105  }
106  return value_i_v;
107 }
108 
109 void DBRecord::add(std::string name, std::string value)
110 {
111  m_name_v.push_back(name);
112  m_value_m.insert(DBFieldList::value_type(name, value));
113 }
114 
115 const std::string DBRecord::getFieldName(int i) const
116 {
117  if (i >= 0 && i < (int) m_name_v.size()) return m_name_v[i];
118  return "";
119 }
120 
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19