8 #ifndef _Belle2_AbstractDBObject_hh
9 #define _Belle2_AbstractDBObject_hh
11 #include <daq/slc/base/FieldProperty.h>
13 #include <daq/slc/base/Serializable.h>
33 const std::string& getPath()
const {
return m_path; }
34 void setPath(
const std::string& path) { m_path = path; }
35 int getId()
const {
return m_id; }
36 void setId(
int id) { m_id = id; }
37 const std::string& getName()
const {
return m_name; }
38 void setName(
const std::string& name) { m_name = name; }
39 int getIndex()
const {
return m_index; }
40 void setIndex(
int index) { m_index = index; }
41 DBField::NameList& getFieldNames() {
return m_name_v; }
42 const DBField::NameList& getFieldNames()
const {
return m_name_v; }
44 bool hasField(
const std::string& name)
const;
45 bool hasValue(
const std::string& name)
const;
46 bool hasText(
const std::string& name)
const;
47 bool hasObject(
const std::string& name)
const;
49 void setValue(
const std::string& name,
const std::string& value);
50 void setText(
const std::string& name,
const std::string& value) { addText(name, value); }
53 bool getBool(
const std::string& name,
int index = 0)
const;
54 char getChar(
const std::string& name,
int index = 0)
const;
55 short getShort(
const std::string& name,
int index = 0)
const;
56 int getInt(
const std::string& name,
int index = 0)
const;
57 long long getLong(
const std::string& name,
int index = 0)
const;
58 float getFloat(
const std::string& name,
int index = 0)
const;
59 double getDouble(
const std::string& name,
int index = 0)
const;
60 void addBool(
const std::string& name,
bool value);
61 void addChar(
const std::string& name,
char value);
62 void addShort(
const std::string& name,
short value);
63 void addInt(
const std::string& name,
int value);
64 void addLong(
const std::string& name,
long long value);
65 void addFloat(
const std::string& name,
float value);
66 void addDouble(
const std::string& name,
double value);
67 void setBool(
const std::string& name,
bool value,
int index = 0);
68 void setChar(
const std::string& name,
int value,
int index = 0);
69 void setShort(
const std::string& name,
int value,
int index = 0);
70 void setInt(
const std::string& name,
int value,
int index = 0);
71 void setLong(
const std::string& name,
long long value,
int index = 0);
72 void setFloat(
const std::string& name,
float value,
int index = 0);
73 void setDouble(
const std::string& name,
double value,
int index = 0);
74 const std::string getValueText(
const std::string& name)
const;
77 virtual const void* getValue(
const std::string& name)
const = 0;
78 virtual const std::string& getText(
const std::string& name)
const = 0;
79 virtual void addText(
const std::string& name,
const std::string& value) = 0;
80 virtual void addValue(
const std::string& name,
const void* value,
81 DBField::Type type,
int length) = 0;
82 virtual void setValue(
const std::string& name,
const void* value,
int index) = 0;
83 virtual void setValueText(
const std::string& name,
const std::string& value);
93 DBField::NameList m_name_v;
94 DBField::PropertyList m_pro_m;
98 T getD(
const std::string& name,
int index = 0)
const
100 const void* value = getValue(name);
102 throw (std::out_of_range(name +
" not found"));
104 DBField::Type type(getProperty(name).getType());
105 if (type == DBField::INT)
return (T)(((
int*)value)[index]);
106 if (type == DBField::FLOAT)
return (T)(((
float*)value)[index]);
107 if (type == DBField::DOUBLE)
return (T)(((
double*)value)[index]);
108 if (type == DBField::SHORT)
return (T)(((
short*)value)[index]);
109 if (type == DBField::CHAR)
return (T)(((
char*)value)[index]);
110 if (type == DBField::LONG)
return (T)(((
long*)value)[index]);
111 return ((T*)value)[index];
116 inline bool AbstractDBObject::getBool(
const std::string& name,
int index)
const
118 return getD<bool>(name, index);
121 inline char AbstractDBObject::getChar(
const std::string& name,
int index)
const
123 return getD<char>(name, index);
126 inline short AbstractDBObject::getShort(
const std::string& name,
int index)
const
128 return getD<short>(name, index);
131 inline int AbstractDBObject::getInt(
const std::string& name,
int index)
const
133 return getD<int>(name, index);
136 inline long long AbstractDBObject::getLong(
const std::string& name,
int index)
const
138 return getD<long long>(name, index);
141 inline float AbstractDBObject::getFloat(
const std::string& name,
int index)
const
143 return getD<float>(name, index);
146 inline double AbstractDBObject::getDouble(
const std::string& name,
int index)
const
148 return getD<double>(name, index);
151 inline void AbstractDBObject::setBool(
const std::string& name,
bool value,
int index)
153 setValue(name, &value, index);
156 inline void AbstractDBObject::setChar(
const std::string& name,
int value,
int index)
158 setValue(name, &value, index);
161 inline void AbstractDBObject::setShort(
const std::string& name,
int value,
int index)
163 setValue(name, &value, index);
166 inline void AbstractDBObject::setInt(
const std::string& name,
int value,
int index)
168 setValue(name, &value, index);
171 inline void AbstractDBObject::setLong(
const std::string& name,
long long value,
int index)
173 setValue(name, &value, index);
176 inline void AbstractDBObject::setFloat(
const std::string& name,
float value,
int index)
178 setValue(name, &value, index);
181 inline void AbstractDBObject::setDouble(
const std::string& name,
double value,
int index)
183 setValue(name, &value, index);
186 inline void AbstractDBObject::addBool(
const std::string& name,
bool value)
188 addValue(name, &value, DBField::BOOL, 0);
191 inline void AbstractDBObject::addChar(
const std::string& name,
char value)
193 addValue(name, &value, DBField::CHAR, 0);
196 inline void AbstractDBObject::addShort(
const std::string& name,
short value)
198 addValue(name, &value, DBField::SHORT, 0);
201 inline void AbstractDBObject::addInt(
const std::string& name,
int value)
203 addValue(name, &value, DBField::INT, 0);
206 inline void AbstractDBObject::addLong(
const std::string& name,
long long value)
208 addValue(name, &value, DBField::LONG, 0);
211 inline void AbstractDBObject::addFloat(
const std::string& name,
float value)
213 addValue(name, &value, DBField::FLOAT, 0);
216 inline void AbstractDBObject::addDouble(
const std::string& name,
double value)
218 addValue(name, &value, DBField::DOUBLE, 0);
Abstract base class for different kinds of events.