24#include <initializer_list>
137 operator std::string();
138 operator const char *();
167 m_string =
new std::string(std::to_string(v));
169 mthrow(
"Invalid type ID " + std::to_string(
m_tid));
185 mthrow(
"Subkey can only be assigned to ODB key");
191 mthrow(
"Subkey can only be assigned to ODB key");
225 mthrow(
"Invalid type ID " + std::to_string(
m_tid));
239 void mult(
double f,
bool push =
true);
279 mthrow(
"Division by zero");
342 mthrow(
"Subkey not found");
344 mthrow(
"Invalid type ID %s" + std::to_string(
m_tid));
366 void get(std::string &
s);
371 mthrow(
"odb_get() called for non-key object");
377 mthrow(
"odb_get() called for non-key object");
496 "]\" contains array. Please assign to std::vector.");
506 mthrow(
"ODB key \"" +
get_full_path() +
"\" contains array. Please assign to std::vector.");
513 void get(std::string &
s,
bool quotes =
false,
bool refresh =
true);
520 bool read_key(
const std::string &path);
577 odb(std::initializer_list<std::pair<const char *, midas::odb>>
list) :
odb() {
584 for (
int j=0 ;
j<
i ;
j++) {
589 mthrow(
"ODB key \"" + std::string(
element.first) +
"\" exists already as \"" +
621 template<
typename T,
size_t SIZE>
635 template<
size_t SIZE>
651 if (path[0] ==
'/') {
664 mthrow(
"ODB key \"" + path +
"\" not found in ODB");
684 std::ostringstream
ss;
730 if (std::is_same<T, uint8_t>::value)
732 else if (std::is_same<T, int8_t>::value)
734 else if (std::is_same<T, uint16_t>::value)
736 else if (std::is_same<T, int16_t>::value)
738 else if (std::is_same<T, uint32_t>::value)
740 else if (std::is_same<T, unsigned long>::value &&
sizeof(
long) == 4)
742 else if (std::is_same<T, int32_t>::value)
744 else if (std::is_same<T, long>::value &&
sizeof(
long) == 4)
746 else if (std::is_same<T, uint64_t>::value)
748 else if (std::is_same<T, unsigned long>::value &&
sizeof(
long) == 8)
750 else if (std::is_same<T, int64_t>::value)
752 else if (std::is_same<T, long>::value &&
sizeof(
long) == 8)
754 else if (std::is_same<T, bool>::value)
756 else if (std::is_same<T, float>::value)
758 else if (std::is_same<T, double>::value)
771 if (m_num_values == 0) {
793 const std::vector<T> &
operator=(
const std::vector<T> &v) {
798 if (m_num_values == 0) {
801 if (std::is_same<T, bool>::value) {
838 template<
typename T,
size_t SIZE>
844 if (m_num_values == 0) {
871 operator std::string() {
882 operator std::vector<T>() {
891 operator std::vector<std::string>() {
901 template<
typename T,
typename std::enable_if<
902 std::is_same<T, uint8_t>::value ||
903 std::is_same<T, int8_t>::value ||
904 std::is_same<T, uint16_t>::value ||
905 std::is_same<T, int16_t>::value ||
906 std::is_same<T, uint32_t>::value ||
907 std::is_same<T, int32_t>::value ||
908 std::is_same<T, uint64_t>::value ||
909 std::is_same<T, int64_t>::value ||
910 std::is_same<T, bool>::value ||
911 std::is_same<T, float>::value ||
912 std::is_same<T, double>::value, T>
::type * =
nullptr>
936 throw std::out_of_range(
"Index \"" + std::to_string(
index) +
"\" out of range for ODB key \"" +
get_full_path() +
"[0..." + std::to_string(
m_num_values - 1) +
"]\"");
953 throw std::out_of_range(
"Index \"" + std::to_string(
index) +
"\" out of range for ODB key \"" +
get_full_path() +
"[0..." + std::to_string(
m_num_values - 1) +
"]\", please consider set_auto_enlarge_array(true)");
974 template <
typename T>
1006 template<
typename T>
1010 "\" contains array which cannot be used in basic arithmetic operation.");
1011 if (std::is_same<T, midas::odb>::value) {
1017 double s1 =
static_cast<double>(
m_data[0]);
1018 double s2 =
static_cast<double>(
i.m_data[0]);
1028 template<
typename T>
1032 "\" contains array which cannot be used in basic arithmetic operation.");
1033 if (std::is_same<T, midas::odb>::value) {
1039 double s1 =
static_cast<double>(
m_data[0]);
1040 double s2 =
static_cast<double>(
i.m_data[0]);
1050 template<
typename T>
1054 "\" contains array which cannot be used in basic arithmetic operation.");
1061 template<
typename T>
1065 "\" contains array which cannot be used in basic arithmetic operation.");
1150 mthrow(
"Division by zero");
1159 template<
typename T>
1161 template<
typename T>
1163 template<
typename T>
1165 template<
typename T>
1167 template<
typename T>
1169 template<
typename T>
1171 template<
typename T>
1173 template<
typename T>
1175 template<
typename T>
1177 template<
typename T>
1179 template<
typename T>
1181 template<
typename T>
1188 unsigned int tid = 0;
1189 if (
type ==
"dir" ||
type ==
"odb")
1192 for (tid = 0; tid <
TID_LAST; tid++) {
1198 mthrow(
"Wrong key type in XML file");
1203 if (
type ==
"odb") {
1204 o->set_name(
"root");
1209 mthrow(
"No \"handle\" attribute found in XML data");
1213 if (
type ==
"key") {
1216 }
else if (
type ==
"keyarray") {
1218 o->set_num_values(
n);
1219 for (
int i=0 ;
i<
n ;
i++) {
1223 }
else if (
type ==
"dir" ||
type ==
"odb") {
1225 o->set_num_values(
n);
1226 for (
int i = 0;
i <
n;
i++) {
1245 mthrow(
"Invalid JSON format");
1255 const char *
name = (*names)[
i].c_str();
1256 const MJsonNode *
node = (*nodes)[
i];
1267 o->set_num_values(
n);
1272 int tid =
key->FindObjectNode(
"type")->GetInt();
1273 const std::string
value =
node->GetString();
1372 static void load(
const std::string &filename,
const std::string &odb_path);
1384 mthrow1(
"ODB source STRING requires a string");
1386 mthrow1(
"ODB source FILE requires a filename");
1400 std::string
print();
1404 void save(
const std::string &filename);
1411 void set(std::string
str);
1412 void set(std::string
s,
int i);
1442 template<
typename T>
1452 template<
typename T>
1460 template<
typename T>
1468 template<
typename T>
1476 template<
typename T>
1484 template<
typename T>
1492 template<
typename T>
1500 template<
typename T>
1508 template<
typename T>
1516 template<
typename T>
1524 template<
typename T>
1532 template<
typename T>
bool operator!=(const iterator &other) const
void set_string_size(std::string s, int size)
std::string get_parent_path()
odb operator=(odb &&o)=delete
odb(std::initializer_list< T > list)
odb & operator*=(double d)
std::string get_full_path()
static bool exists(const std::string &name)
midas::odb * get_parent()
static void set_odb_source(odb::odb_source s, std::string str)
odb & operator+=(double d)
void set_auto_refresh_read(bool f)
void set_auto_enlarge_array(bool f)
odb(const std::array< T, SIZE > &arr)
void set_odb(odb *o, int i)
void deep_copy(odb &d, const odb &s)
static void set_debug(bool flag)
bool is_auto_refresh_read() const
static void unwatch_all()
static void set_odb_source(odb::odb_source s)
std::function< void(midas::odb &)> m_watch_callback
bool is_auto_create() const
bool is_preserve_string_size() const
static void watch_callback(int hDB, int hKey, int index, void *info)
odb(const std::array< std::string, SIZE > &arr)
u_odb & operator[](int index)
odb(std::initializer_list< std::pair< const char *, midas::odb > > list)
bool is_auto_refresh_write() const
u_odb & get_mdata(int index=0)
friend bool operator==(const midas::odb &o, const T &d)
odb & operator[](const char *str)
midas::odb * odb_from_json(const MJsonNode *node, std::string name, odb *o)
bool read_key(const std::string &path)
friend bool operator>=(const midas::odb &o, const T &d)
friend bool operator<=(const midas::odb &o, const T &d)
static std::string s_odb_source_str
friend bool operator<(const midas::odb &o, const T &d)
void set_preserve_string_size(bool f)
void set_trigger_hotlink(bool f)
void set_flags(uint32_t f)
void set_auto_refresh_write(bool f)
void odb_from_xml_remote(const std::string &str)
void set_auto_create(bool f)
void odb_from_xml_string(const std::string &str, const std::string &subkey)
void resize_mdata(int size)
static odb::odb_source get_odb_source()
friend bool operator>(const midas::odb &o, const T &d)
const std::vector< T > & operator=(const std::vector< T > &v)
const T & operator=(const T &v)
odb & get_subkey(std::string str)
void set_hkey(HNDLE hKey)
odb & operator/=(double d)
void odb_from_json_string(const std::string &str, const std::string &subkey)
void set_flags_recursively(uint32_t f)
unsigned int get_last_written()
void set_name(std::string s)
int get_subkeys(std::vector< std::string > &name)
void watch(std::function< void(midas::odb &)> f)
friend std::ostream & operator<<(std::ostream &output, odb &o)
bool is_auto_enlarge_array() const
friend bool operator!=(const midas::odb &o, const T &d)
int detect_type(const T &)
void save(const std::string &filename)
void set_last_index(int i)
static int create(const char *name, int type=TID_KEY)
bool is_subkey(std::string str)
void fix_order(std::vector< std::string > target_subkey_order)
odb(const std::string &path, bool init_via_xml=false)
static odb_source s_odb_source
void connect_and_fix_structure(std::string path)
static bool s_connected_odb
const std::array< T, SIZE > & operator=(const std::array< T, SIZE > &arr)
odb & operator-=(double d)
void set_num_values(int n)
bool is_trigger_hotlink() const
bool write_key(std::string &path, bool write_defaults)
static midas::odb * search_hkey(midas::odb *po, int hKey)
static bool is_connected_odb()
odb(std::initializer_list< const char * > list)
static std::vector< midas::odb > m_watch
odb & operator[](std::string str)
static void load(const std::string &filename, const std::string &odb_path)
midas::odb * odb_from_xml(PMXML_NODE node, odb *o)
void set_parent(midas::odb *p)
void set_write_protect(bool f)
bool is_write_protect() const
void connect(const std::string &path, const std::string &name, bool write_defaults, bool delete_keys_not_in_defaults=false)
u_odb & operator/=(double d)
uint8_t operator=(uint8_t v)
void mult(double f, bool push=true)
void set_string(std::string s)
u_odb & operator+=(double d)
u_odb & operator*=(double d)
friend std::ostream & operator<<(std::ostream &output, u_odb &o)
void set_string_size(std::string s, int size)
u_odb & operator-=(double d)
void set_string_ptr(std::string *s)
BOOL equal_ustring(const char *str1, const char *str2)
const char * rpc_tid_name(INT id)
static void output(code_int code)
#define write(n, a, f, d)
static std::string indent(int x, const char *p=" ")
static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int64_t len)
bool operator>=(const midas::odb &o, const T &d)
bool operator>(const midas::odb &o, const T &d)
bool operator==(const midas::odb &o, const T &d)
bool operator<(const midas::odb &o, const T &d)
bool operator<=(const midas::odb &o, const T &d)
bool operator!=(const midas::odb &o, const T &d)
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
static te_expr * list(state *s)