8#include "daq/slc/database/DBRecord.h"
10#include "daq/slc/base/StringUtil.h"
16const std::string DBRecord::get(
const std::string& name)
const
18 if (m_value_m.find(name) != m_value_m.end())
return m_value_m[name];
22const std::string DBRecord::get(
int i)
const
24 if (i >= 0 && i < (
int)m_name_v.size())
25 return m_value_m[m_name_v[i]];
29unsigned long long int DBRecord::getULLInt(
const std::string& name)
const
31 return std::strtoull(get(name).c_str(), NULL, 10);
34int DBRecord::getInt(
const std::string& name)
const
36 return atoi(get(name).c_str());
39int DBRecord::getInt(
int i)
const
41 return atoi(get(i).c_str());
44bool DBRecord::getBool(
const std::string& name)
const
46 return get(name) ==
"t";
49bool DBRecord::getBool(
int i)
const
54float DBRecord::getFloat(
const std::string& name)
const
56 return atof(get(name).c_str());
59float DBRecord::getFloat(
int i)
const
61 return atof(get(i).c_str());
64std::vector<std::string> DBRecord::getArray(
const std::string& name)
const
66 std::string value = StringUtil::replace(StringUtil::replace(get(name),
"}",
""),
"{",
"");
67 return StringUtil::split(value,
',');
70std::vector<std::string> DBRecord::getArray(
int i)
const
72 std::string value = StringUtil::replace(StringUtil::replace(get(i),
"}",
""),
"{",
"");
73 return StringUtil::split(value,
',');
76std::vector<int> DBRecord::getIntArray(
const std::string& name)
const
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()));
86std::vector<int> DBRecord::getIntArray(
int i)
const
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()));
96std::vector<float> DBRecord::getFloatArray(
const std::string& name)
const
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()));
106std::vector<float> DBRecord::getFloatArray(
int i)
const
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()));
116void DBRecord::add(std::string name, std::string value)
118 m_name_v.push_back(name);
119 m_value_m.insert(DBFieldList::value_type(name, value));
122const std::string DBRecord::getFieldName(
int i)
const
124 if (i >= 0 && i < (
int) m_name_v.size())
return m_name_v[i];
Abstract base class for different kinds of events.