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