MIDAS
Loading...
Searching...
No Matches
midas::odb Class Reference

#include <odbxx.h>

Collaboration diagram for midas::odb:

Classes

class  iterator
 

Public Member Functions

 odb ()
 
 ~odb ()
 
 odb (const odb &o)
 
odb operator= (odb &&o)=delete
 
template<typename T >
 odb (T v)
 
 odb (std::initializer_list< std::pair< const char *, midas::odb > > list)
 
template<typename T >
 odb (std::initializer_list< T > list)
 
template<typename T , size_t SIZE>
 odb (const std::array< T, SIZE > &arr)
 
template<size_t SIZE>
 odb (const std::array< std::string, SIZE > &arr)
 
 odb (const std::string &str, bool init_via_xml=false)
 
 odb (const char *s)
 
 odb (std::initializer_list< const char * > list)
 
template<typename T >
int detect_type (const T &)
 
template<typename T >
const T & operator= (const T &v)
 
template<typename T >
const std::vector< T > & operator= (const std::vector< T > &v)
 
template<typename T , size_t SIZE>
const std::array< T, SIZE > & operator= (const std::array< T, SIZE > &arr)
 
 operator std::string ()
 
template<typename T >
 operator std::vector< T > ()
 
 operator std::vector< std::string > ()
 
template<typename T , typename std::enable_if< std::is_same< T, uint8_t >::value||std::is_same< T, int8_t >::value||std::is_same< T, uint16_t >::value||std::is_same< T, int16_t >::value||std::is_same< T, uint32_t >::value||std::is_same< T, int32_t >::value||std::is_same< T, uint64_t >::value||std::is_same< T, int64_t >::value||std::is_same< T, bool >::value||std::is_same< T, float >::value||std::is_same< T, double >::value, T >::type * = nullptr>
 operator T ()
 
u_odboperator[] (int index)
 
odboperator[] (std::string str)
 
odboperator[] (const char *str)
 
template<typename T >
odboperator() (T v)
 
int get_last_index ()
 
void set_last_index (int i)
 
iterator begin () const
 
iterator end () const
 
template<typename T >
operator+ (T i)
 
template<typename T >
operator- (T i)
 
template<typename T >
operator* (const T i)
 
template<typename T >
operator/ (const T i)
 
odboperator++ ()
 
odb operator++ (int)
 
odboperator-- ()
 
odb operator-- (int)
 
odboperator+= (double d)
 
odboperator-= (double d)
 
odboperator*= (double d)
 
odboperator/= (double d)
 
midas::odbodb_from_xml (PMXML_NODE node, odb *o)
 
void deep_copy (odb &d, const odb &s)
 
bool is_preserve_string_size () const
 
void set_preserve_string_size (bool f)
 
bool is_auto_refresh_read () const
 
void set_auto_refresh_read (bool f)
 
bool is_auto_refresh_write () const
 
void set_auto_refresh_write (bool f)
 
bool is_dirty () const
 
void set_dirty (bool f)
 
bool is_auto_create () const
 
void set_auto_create (bool f)
 
bool is_auto_enlarge_array () const
 
void set_auto_enlarge_array (bool f)
 
bool is_write_protect () const
 
void set_write_protect (bool f)
 
bool is_trigger_hotlink () const
 
void set_trigger_hotlink (bool f)
 
void odb_from_xml (const std::string &str)
 
void connect (const std::string &path, const std::string &name, bool write_defaults, bool delete_keys_not_in_defaults=false)
 
void connect (std::string str, bool write_defaults=false, bool delete_keys_not_in_defaults=false)
 
void connect_and_fix_structure (std::string path)
 
void read ()
 
void read (int index)
 
void write (int str_size=0)
 
void write (int index, int str_size)
 
std::string print ()
 
std::string dump ()
 
void print (std::string &s, int indent=0)
 
void dump (std::string &s, int indent=0)
 
void save (const std::string &filename)
 
void delete_key ()
 
int size ()
 
void resize (int size)
 
void resize (int size, bool b)
 
void watch (std::function< void(midas::odb &)> f)
 
void unwatch ()
 
void set (std::string str)
 
void set (std::string s, int i)
 
void set_odb (odb *o, int i)
 
void set_string_size (std::string s, int size)
 
bool is_subkey (std::string str)
 
HNDLE get_hkey ()
 
std::string get_full_path ()
 
std::string get_parent_path ()
 
int get_tid ()
 
int get_num_values ()
 
std::string get_name ()
 
odbitems ()
 
std::string s ()
 
void fix_order (std::vector< std::string > target_subkey_order)
 
void set_mode (int mode)
 
int get_mode ()
 
unsigned int get_last_written ()
 

Static Public Member Functions

static void set_debug (bool flag)
 
static bool get_debug ()
 
static int create (const char *name, int type=TID_KEY)
 
static bool exists (const std::string &name)
 
static int delete_key (const std::string &name)
 
static void load (const std::string &filename, const std::string &odb_path)
 
static bool is_connected_odb ()
 

Private Member Functions

void set_flags_recursively (uint32_t f)
 
void resize_mdata (int size)
 
template<typename T >
get ()
 
template<typename T >
void get (T &v)
 
void get (std::string &s, bool quotes=false, bool refresh=true)
 
u_odbget_mdata (int index=0)
 
odbget_subkey (std::string str)
 
int get_subkeys (std::vector< std::string > &name)
 
bool read_key (const std::string &path)
 
bool write_key (std::string &path, bool write_defaults)
 
void set_hkey (HNDLE hKey)
 
void set_flags (uint32_t f)
 
uint32_t get_flags ()
 
bool is_deleted () const
 
void set_deleted (bool f)
 
void set_tid (int tid)
 
void set_num_values (int n)
 
void set_name (std::string s)
 
void set_parent (midas::odb *p)
 
midas::odbget_parent ()
 

Static Private Member Functions

static void init_hdb ()
 
static midas::odbsearch_hkey (midas::odb *po, int hKey)
 
static void watch_callback (int hDB, int hKey, int index, void *info)
 
static void unwatch_all ()
 

Private Attributes

std::bitset< 9 > m_flags
 
int m_tid
 
u_odbm_data
 
std::string m_name
 
int m_num_values
 
int m_last_index
 
HNDLE m_hKey
 
std::function< void(midas::odb &)> m_watch_callback
 
midas::odbm_parent
 

Static Private Attributes

static HNDLE s_hDB = 0
 
static bool s_debug = false
 
static bool s_connected_odb = false
 
static std::vector< midas::odbm_watch
 

Friends

std::ostream & operator<< (std::ostream &output, odb &o)
 
template<typename T >
bool operator== (const midas::odb &o, const T &d)
 
template<typename T >
bool operator== (const T &d, const midas::odb &o)
 
template<typename T >
bool operator!= (const midas::odb &o, const T &d)
 
template<typename T >
bool operator!= (const T &d, const midas::odb &o)
 
template<typename T >
bool operator< (const midas::odb &o, const T &d)
 
template<typename T >
bool operator< (const T &d, const midas::odb &o)
 
template<typename T >
bool operator<= (const midas::odb &o, const T &d)
 
template<typename T >
bool operator<= (const T &d, const midas::odb &o)
 
template<typename T >
bool operator> (const midas::odb &o, const T &d)
 
template<typename T >
bool operator> (const T &d, const midas::odb &o)
 
template<typename T >
bool operator>= (const midas::odb &o, const T &d)
 
template<typename T >
bool operator>= (const T &d, const midas::odb &o)
 

Detailed Description

Definition at line 408 of file odbxx.h.

Constructor & Destructor Documentation

◆ odb() [1/10]

midas::odb::odb ( )
inline

Definition at line 530 of file odbxx.h.

530 :
536 m_tid{0},
537 m_data{nullptr},
538 m_name{},
539 m_num_values{0},
540 m_last_index{-1},
541 m_hKey{},
542 m_parent{} {}
int m_num_values
Definition odbxx.h:455
int m_tid
Definition odbxx.h:449
u_odb * m_data
Definition odbxx.h:451
int m_last_index
Definition odbxx.h:457
std::bitset< 9 > m_flags
Definition odbxx.h:447
HNDLE m_hKey
Definition odbxx.h:459
std::string m_name
Definition odbxx.h:453
midas::odb * m_parent
Definition odbxx.h:463
@ AUTO_REFRESH_WRITE
Definition odbxx.h:393
@ TRIGGER_HOTLINK
Definition odbxx.h:400
@ AUTO_REFRESH_READ
Definition odbxx.h:392
@ AUTO_ENLARGE_ARRAY
Definition odbxx.h:396
@ AUTO_CREATE
Definition odbxx.h:395

◆ ~odb()

midas::odb::~odb ( )
inline

Definition at line 545 of file odbxx.h.

545 {
546 delete[] m_data;
547 }

◆ odb() [2/10]

midas::odb::odb ( const odb o)

Definition at line 236 of file odbxx.cxx.

236 : odb() {
237 m_tid = o.m_tid;
238 m_name = o.m_name;
239 m_num_values = o.m_num_values;
240 m_hKey = o.m_hKey;
241 m_watch_callback = o.m_watch_callback;
243 for (int i = 0; i < m_num_values; i++) {
245 m_data[i].set_parent(this);
246 if (m_tid == TID_STRING || m_tid == TID_LINK) {
247 // set_string() creates a copy of our string
248 m_data[i].set_string(o.m_data[i]);
249 } else if (m_tid == TID_KEY) {
250 // recursive call to create a copy of the odb object
252 midas::odb *pc = new midas::odb(*po);
253 pc->set_parent(this);
254 m_data[i].set(pc);
255 } else {
256 // simply pass basic types
257 m_data[i] = o.m_data[i];
258 m_data[i].set_parent(this);
259 }
260 }
261 }
std::function< void(midas::odb &)> m_watch_callback
Definition odbxx.h:461
void set_tid(int tid)
Definition odbxx.h:103
void set_string(std::string s)
Definition odbxx.h:170
void set(T v)
Definition odbxx.h:140
void set_parent(odb *o)
Definition odbxx.h:100
odb * get_podb()
Definition odbxx.h:367
#define TID_KEY
Definition midas.h:349
#define TID_LINK
Definition midas.h:350
#define TID_STRING
Definition midas.h:346
INT i
Definition mdump.cxx:32
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

◆ odb() [3/10]

template<typename T >
midas::odb::odb ( v)
inline

Definition at line 557 of file odbxx.h.

557 :odb() {
558 m_num_values = 1;
559 m_data = new u_odb[1]{v};
560 m_tid = m_data[0].get_tid();
561 m_data[0].set_parent(this);
562 }
int get_tid()
Definition odbxx.h:105
Here is the call graph for this function:

◆ odb() [4/10]

midas::odb::odb ( std::initializer_list< std::pair< const char *, midas::odb > >  list)
inline

Definition at line 565 of file odbxx.h.

565 : odb() {
566 m_tid = TID_KEY;
567 m_num_values = list.size();
568 m_data = new u_odb[m_num_values];
569 int i = 0;
570 for (auto &element: list) {
571 // check if name exists already
572 for (int j=0 ; j<i ; j++) {
573 if (strcasecmp(element.first, m_data[j].get_odb().get_name().c_str()) == 0) {
574 if (element.first == m_data[j].get_odb().get_name().c_str()) {
575 mthrow("ODB key with name \"" + m_data[j].get_odb().get_name() + "\" exists already");
576 } else {
577 mthrow("ODB key \"" + std::string(element.first) + "\" exists already as \"" +
578 m_data[j].get_odb().get_name() + "\" (only case differs)");
579 }
580 }
581 }
582 auto o = new midas::odb(element.second);
583 o->set_name(element.first);
584 o->set_parent(this);
586 m_data[i].set_parent(this);
587 m_data[i].set(o);
588 i++;
589 }
590 }
std::string get_name()
Definition odbxx.h:1278
odb & get_odb()
Definition odbxx.h:373
INT element
Definition mchart.cxx:40
#define mthrow(arg)
Definition mexcept.h:24
INT j
Definition odbhist.cxx:40
static te_expr * list(state *s)
Definition tinyexpr.c:567
Here is the call graph for this function:

◆ odb() [5/10]

template<typename T >
midas::odb::odb ( std::initializer_list< T >  list)
inline

Definition at line 594 of file odbxx.h.

594 : odb() {
595 m_num_values = list.size();
596 m_data = new u_odb[m_num_values]{};
597 int i = 0;
598 for (auto &element : list) {
599 u_odb u(element);
600 m_data[i].set_tid(u.get_tid());
601 m_data[i].set_parent(this);
603 i++;
604 }
605 m_tid = m_data[0].get_tid();
606 }
Here is the call graph for this function:

◆ odb() [6/10]

template<typename T , size_t SIZE>
midas::odb::odb ( const std::array< T, SIZE > &  arr)
inline

Definition at line 610 of file odbxx.h.

610 : odb() {
612 m_data = new u_odb[m_num_values]{};
613 for (int i = 0; i < (int)SIZE; i++) {
614 u_odb u(arr[i]);
615 m_data[i].set_tid(u.get_tid());
616 m_data[i].set_parent(this);
617 m_data[i].set(arr[i]);
618 }
619 m_tid = m_data[0].get_tid();
620 }
#define SIZE
Here is the call graph for this function:

◆ odb() [7/10]

template<size_t SIZE>
midas::odb::odb ( const std::array< std::string, SIZE > &  arr)
inline

Definition at line 624 of file odbxx.h.

624 : odb() {
626 m_data = new u_odb[m_num_values]{};
627 for (int i = 0; i < (int)SIZE; i++) {
628 std::string * mystring = new std::string(arr[i]);
629 u_odb u(mystring);
630 m_data[i].set_tid(u.get_tid());
631 m_data[i].set_parent(this);
632 m_data[i].set(arr[i]);
633 }
634 m_tid = m_data[0].get_tid();
635 }
Here is the call graph for this function:

◆ odb() [8/10]

midas::odb::odb ( const std::string &  str,
bool  init_via_xml = false 
)
inline

Definition at line 638 of file odbxx.h.

638 : odb() {
639 if (str[0] == '/') {
640 // ODB path
641 if (init_via_xml) {
642 if (!exists(str))
643 odb::create(str.c_str(), TID_KEY);
645 } else {
646 if (!read_key(str))
647 // create subdir if key does not exist
648 odb::create(str.c_str(), TID_KEY);
649
650 if (!read_key(str))
651 mthrow("ODB key \"" + str + "\" not found in ODB");
652
653 if (m_tid != TID_KEY)
654 read();
655 }
656 } else {
657 // simple string
658
659 // Construct object from initializer_list
660 m_num_values = 1;
661 m_data = new u_odb[1]{new std::string{str}};
662 m_tid = m_data[0].get_tid();
663 m_data[0].set_parent(this);
664 }
665 }
static bool exists(const std::string &name)
Definition odbxx.cxx:66
bool read_key(const std::string &path)
Definition odbxx.cxx:571
void read()
Definition odbxx.cxx:716
static int create(const char *name, int type=TID_KEY)
Definition odbxx.cxx:130
midas::odb * odb_from_xml(PMXML_NODE node, odb *o)
Definition odbxx.h:1142
char str[256]
Definition odbhist.cxx:33
Here is the call graph for this function:

◆ odb() [9/10]

midas::odb::odb ( const char s)
inline

Definition at line 668 of file odbxx.h.

668 : odb(std::string(s)) {
669 }
std::string s()
Definition odbxx.h:1281

◆ odb() [10/10]

midas::odb::odb ( std::initializer_list< const char * >  list)
inline

Definition at line 672 of file odbxx.h.

672 : odb() {
673 m_num_values = list.size();
674 m_data = new u_odb[m_num_values]{};
675 int i = 0;
676 for (auto &element : list) {
678 m_data[i].set_parent(this);
680 i++;
681 }
682 m_tid = m_data[0].get_tid();
683 }
Here is the call graph for this function:

Member Function Documentation

◆ begin()

iterator midas::odb::begin ( ) const
inline

Definition at line 959 of file odbxx.h.

959{ return iterator(m_data); }

◆ connect() [1/2]

void midas::odb::connect ( const std::string &  path,
const std::string &  name,
bool  write_defaults,
bool  delete_keys_not_in_defaults = false 
)

Definition at line 1291 of file odbxx.cxx.

1291 {
1292 init_hdb();
1293
1294 if (!name.empty())
1295 m_name = name;
1296 std::string path(p);
1297
1298 if (path.empty())
1299 mthrow("odb::connect() cannot be called with an empty ODB path");
1300
1301 if (path[0] != '/')
1302 mthrow("odb::connect(\"" + path + "\"): path must start with leading \"/\"");
1303
1304 if (path.back() != '/')
1305 path += "/";
1306
1307 path += m_name;
1308
1309 HNDLE hKey;
1310 int status = db_find_key(s_hDB, 0, path.c_str(), &hKey);
1311 bool key_exists = (status == DB_SUCCESS);
1312 bool created = false;
1313
1315 // Recurse down to delete keys as needed.
1316 // We need to do this recursively BEFORE calling read/read_key for the first time
1317 // to ensure that subdirectories get handled correctly.
1319 }
1320
1321 if (!key_exists || write_defaults) {
1323 } else {
1324 read_key(path);
1325 }
1326
1327 // correct wrong parent ODB from initializer_list
1328 for (int i = 0; i < m_num_values; i++)
1329 m_data[i].set_parent(this);
1330
1331 if (m_tid == TID_KEY) {
1332 for (int i = 0; i < m_num_values; i++)
1333 m_data[i].get_odb().connect(get_full_path(), m_data[i].get_odb().get_name(), write_defaults);
1334 } else if (created || write_defaults) {
1335 write();
1336 } else {
1337 read();
1338 }
1339 }
std::string get_full_path()
Definition odbxx.cxx:291
static HNDLE s_hDB
Definition odbxx.h:438
static void init_hdb()
Definition odbxx.cxx:43
bool write_key(std::string &path, bool write_defaults)
Definition odbxx.cxx:657
void set_parent(midas::odb *p)
Definition odbxx.h:524
#define DB_SUCCESS
Definition midas.h:631
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4079
HNDLE hKey
INT HNDLE
Definition midas.h:132
#define write(n, a, f, d)
#define name(x)
Definition midas_macro.h:24
void recurse_del_keys_not_in_defaults(std::string path, HNDLE hDB, HNDLE hKey, midas::odb &default_odb)
Definition odbxx.cxx:1167
DWORD status
Definition odbhist.cxx:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect() [2/2]

void midas::odb::connect ( std::string  str,
bool  write_defaults = false,
bool  delete_keys_not_in_defaults = false 
)

Definition at line 1342 of file odbxx.cxx.

1342 {
1343
1344 if (str.empty())
1345 mthrow("odb::connect() cannot be called with an empty ODB path");
1346
1347 if (str[0] != '/')
1348 mthrow("odb::connect(\"" + str + "\"): path must start with leading \"/\"");
1349
1350 if (str == "/")
1351 mthrow("odb::connect(\"" + str + "\"): root ODB tree is not allowed");
1352
1353 if (str.back() == '/')
1354 str = str.substr(0, str.size()-1);
1355
1356 // separate ODB path and key nam
1357 std::string name;
1358 std::string path;
1359 name = str.substr(str.find_last_of('/') + 1);
1360 path = str.substr(0, str.find_last_of('/') + 1);
1361
1363 }
void connect(const std::string &path, const std::string &name, bool write_defaults, bool delete_keys_not_in_defaults=false)
Definition odbxx.cxx:1291
Here is the call graph for this function:

◆ connect_and_fix_structure()

void midas::odb::connect_and_fix_structure ( std::string  path)

Definition at line 1370 of file odbxx.cxx.

1370 {
1371 // Store the order the user specified.
1372 // Need to do this recursively before calling connect(), as the first
1373 // read() in that function merges user keys and existing keys.
1374 std::map<std::string, std::vector<std::string> > user_order;
1376
1377 // Main connect() that adds/deletes/updates keys as needed.
1378 connect(path, false, true);
1379
1380 // Fix order in ODB (and memory)
1382 }
void recurse_fix_order(midas::odb &default_odb, std::map< std::string, std::vector< std::string > > &user_order)
Definition odbxx.cxx:1214
void recurse_get_defaults_order(std::string path, midas::odb &default_odb, std::map< std::string, std::vector< std::string > > &retval)
Definition odbxx.cxx:1204
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create()

int midas::odb::create ( const char name,
int  type = TID_KEY 
)
static

Definition at line 130 of file odbxx.cxx.

130 {
131 init_hdb();
132 int status = -1;
133 if (is_connected_odb())
136 mthrow("Cannot create key " + std::string(name) + ", db_create_key() status = " + std::to_string(status));
137 return status;
138 }
static bool is_connected_odb()
Definition odbxx.h:1250
#define DB_KEY_EXIST
Definition midas.h:641
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
Definition odb.cxx:3308
INT type
Definition mana.cxx:269
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deep_copy()

void midas::odb::deep_copy ( odb d,
const odb s 
)

Definition at line 263 of file odbxx.cxx.

263 {
264 d.m_tid = s.m_tid;
265 d.m_name = s.m_name;
266 d.m_num_values = s.m_num_values;
267 d.m_hKey = s.m_hKey;
268 d.m_watch_callback = s.m_watch_callback;
269 d.m_data = new midas::u_odb[d.m_num_values]{};
270 for (int i = 0; i < d.m_num_values; i++) {
271 d.m_data[i].set_tid(d.m_tid);
272 d.m_data[i].set_parent(&d);
273 if (d.m_tid == TID_STRING || d.m_tid == TID_LINK) {
274 // set_string() creates a copy of our string
275 d.m_data[i].set_string(s.m_data[i]);
276 } else if (d.m_tid == TID_KEY) {
277 // recursive call to create a copy of the odb object
279 midas::odb *pc = new midas::odb(*po);
280 pc->set_parent(&d);
281 d.m_data[i].set(pc);
282 } else {
283 // simply pass basic types
284 d.m_data[i] = s.m_data[i];
285 d.m_data[i].set_parent(this);
286 }
287 }
288 }
double d
Definition system.cxx:1311
Here is the call graph for this function:

◆ delete_key() [1/2]

void midas::odb::delete_key ( )

Definition at line 1384 of file odbxx.cxx.

1384 {
1385 init_hdb();
1386
1388
1389 if (this->is_write_protect())
1390 mthrow("Cannot modify write protected key \"" + m_name + "\"");
1391
1392
1393 // delete key in ODB
1395 if (status != DB_SUCCESS && status != DB_INVALID_HANDLE)
1396 mthrow("db_delete_key for ODB key \"" + m_name +
1397 "\" returnd error code " + std::to_string(status));
1398
1399 if (s_debug)
1400 std::cout << "Deleted ODB key \"" + m_name + "\"" << std::endl;
1401
1402 // invalidate this object
1403 delete[] m_data;
1404 m_data = nullptr;
1405 m_num_values = 0;
1406 m_tid = 0;
1407 m_hKey = 0;
1408
1409 // set flag that this object has been deleted
1410 set_deleted(true);
1411 }
#define FALSE
Definition cfortran.h:309
static bool s_debug
Definition odbxx.h:440
void set_deleted(bool f)
Definition odbxx.h:517
bool is_write_protect() const
Definition odbxx.h:1226
#define DB_INVALID_HANDLE
Definition midas.h:635
INT db_delete_key(HNDLE hDB, HNDLE hKey, BOOL follow_links)
Definition odb.cxx:3856
Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_key() [2/2]

int midas::odb::delete_key ( const std::string &  name)
static

Definition at line 75 of file odbxx.cxx.

75 {
76 init_hdb();
78 return false;
79 HNDLE hkey;
80 auto status = db_find_key(s_hDB, 0, name.c_str(), &hkey);
81 if (status != DB_SUCCESS) {
82 if (s_debug)
83 std::cout << "Delete key " + name << " not found in ODB" << std::endl;
84 return status;
85 }
86 if (s_debug)
87 std::cout << "Delete ODB key " + name << std::endl;
88 return db_delete_key(s_hDB, hkey, false);
89 }
Here is the call graph for this function:

◆ detect_type()

template<typename T >
int midas::odb::detect_type ( const T &  )
inline

Definition at line 686 of file odbxx.h.

686 {
687 if (std::is_same<T, uint8_t>::value)
688 return TID_UINT8;
689 else if (std::is_same<T, int8_t>::value)
690 return TID_INT8;
691 else if (std::is_same<T, uint16_t>::value)
692 return TID_UINT16;
693 else if (std::is_same<T, int16_t>::value)
694 return TID_INT16;
695 else if (std::is_same<T, uint32_t>::value)
696 return TID_UINT32;
697 else if (std::is_same<T, unsigned long>::value && sizeof(long) == 4)
698 return TID_UINT32;
699 else if (std::is_same<T, int32_t>::value)
700 return TID_INT32;
701 else if (std::is_same<T, long>::value && sizeof(long) == 4)
702 return TID_INT32;
703 else if (std::is_same<T, uint64_t>::value)
704 return TID_UINT64;
705 else if (std::is_same<T, unsigned long>::value && sizeof(long) == 8)
706 return TID_UINT64;
707 else if (std::is_same<T, int64_t>::value)
708 return TID_INT64;
709 else if (std::is_same<T, long>::value && sizeof(long) == 8)
710 return TID_INT64;
711 else if (std::is_same<T, bool>::value)
712 return TID_BOOL;
713 else if (std::is_same<T, float>::value)
714 return TID_FLOAT;
715 else if (std::is_same<T, double>::value)
716 return TID_DOUBLE;
717 else
718 return TID_STRING;
719 }
#define TID_DOUBLE
Definition midas.h:343
#define TID_BOOL
Definition midas.h:340
#define TID_UINT64
Definition midas.h:352
#define TID_INT64
Definition midas.h:351
#define TID_INT32
Definition midas.h:339
#define TID_UINT8
Definition midas.h:328
#define TID_INT8
Definition midas.h:330
#define TID_UINT32
Definition midas.h:337
#define TID_UINT16
Definition midas.h:333
#define TID_INT16
Definition midas.h:335
#define TID_FLOAT
Definition midas.h:341
Here is the caller graph for this function:

◆ dump() [1/2]

std::string midas::odb::dump ( )

Definition at line 356 of file odbxx.cxx.

356 {
357 std::string s;
358 s = "{\n";
359 dump(s, 1);
360 s += "\n}";
361 return s;
362 }
std::string dump()
Definition odbxx.cxx:356
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dump() [2/2]

void midas::odb::dump ( std::string &  s,
int  indent = 0 
)

Definition at line 398 of file odbxx.cxx.

398 {
399 for (int i = 0; i < indent; i++)
400 s += " ";
401 if (m_tid == TID_KEY) {
402 s += "\"" + m_name + "\": {\n";
403 for (int i = 0; i < m_num_values; i++) {
404 std::string v;
405 m_data[i].get_odb().dump(v, indent + 1);
406 s += v;
407 if (i < m_num_values - 1)
408 s += ",\n";
409 else
410 s += "\n";
411 }
412 for (int i = 0; i < indent; i++)
413 s += " ";
414 s += "}";
415 } else {
416 KEY key;
418 s += "\"" + m_name + "/key\": ";
419 s += "{ \"type\": " + std::to_string(m_tid) + ", ";
420 s += "\"access_mode\": " + std::to_string(key.access_mode) + ", ";
421 s += "\"last_written\": " + std::to_string(key.last_written) + "},\n";
422 for (int i = 0; i < indent; i++)
423 s += " ";
424 s += "\"" + m_name + "\": ";
425 if (m_num_values > 1)
426 s += "[";
427 std::string v;
428 get(v, m_tid == TID_STRING || m_tid == TID_LINK);
429 s += v;
430 if (m_num_values > 1)
431 s += "]";
432 }
433 }
T get()
Definition odbxx.h:480
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
Definition odb.cxx:6019
KEY key
Definition mdump.cxx:34
static std::string indent(int x, const char *p=" ")
Definition midas.h:1026
WORD access_mode
Definition midas.h:1033
INT last_written
Definition midas.h:1037
Here is the call graph for this function:

◆ end()

iterator midas::odb::end ( ) const
inline

Definition at line 960 of file odbxx.h.

960{ return iterator(m_data + m_num_values); }

◆ exists()

bool midas::odb::exists ( const std::string &  name)
static

Definition at line 66 of file odbxx.cxx.

66 {
67 init_hdb();
69 return false;
70 HNDLE hkey;
71 return db_find_key(s_hDB, 0, name.c_str(), &hkey) == DB_SUCCESS;
72 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fix_order()

void midas::odb::fix_order ( std::vector< std::string >  target_subkey_order)

Definition at line 1228 of file odbxx.cxx.

1228 {
1229 // Fix the order of ODB keys to match that specified in target_order.
1230 // The in-ODB representation is simple, as we can just use db_reorder_key()
1231 // on anything that's in the wrong place.
1232 // The in-memory representation is a little trickier, but we just copy raw
1233 // memory into a temporary array, so we don't have to delete/recreate the
1234 // u_odb objects.
1235 std::vector<std::string> curr_order;
1236
1237 if (get_subkeys(curr_order) <= 0) {
1238 // Not a TID_KEY (or no keys)
1239 return;
1240 }
1241
1242 if (target_order.size() != curr_order.size() || (int)target_order.size() != m_num_values) {
1243 return;
1244 }
1245
1246 HNDLE hKey = get_hkey();
1247 bool force_order = false;
1248
1249 // Temporary location where we'll store in-memory u_odb objects in th
1250 // correct order.
1251 u_odb* new_m_data = new u_odb[m_num_values];
1252
1253 for (int i = 0; i < m_num_values; i++) {
1254 if (force_order || curr_order[i] != target_order[i]) {
1255 force_order = true;
1256 HNDLE hSubKey;
1257
1258 // Fix the order in the ODB
1261 }
1262
1263 // Fix the order in memory
1264 auto curr_it = std::find(curr_order.begin(), curr_order.end(), target_order[i]);
1265
1266 if (curr_it == curr_order.end()) {
1267 // Logic error - bail to avoid doing any damage to the in-memory version.
1268 delete[] new_m_data;
1269 return;
1270 }
1271
1272 int curr_idx = curr_it - curr_order.begin();
1274 }
1275
1276 // Final update of the in-memory version so they are in the correct order
1277 for (int i = 0; i < m_num_values; i++) {
1278 m_data[i] = new_m_data[i];
1279
1280 // Nullify pointers that point to the same object in
1281 // m_data and new_m_data, so the underlying object doesn't
1282 // get destroyed when we delete new_m_data.
1283 new_m_data[i].set_string_ptr(nullptr);
1284 new_m_data[i].set_odb(nullptr);
1285 }
1286
1287 delete[] new_m_data;
1288 }
HNDLE get_hkey()
Definition odbxx.h:1273
int get_subkeys(std::vector< std::string > &name)
Definition odbxx.cxx:546
void set_string_ptr(std::string *s)
Definition odbxx.h:177
INT db_reorder_key(HNDLE hDB, HNDLE hKey, INT idx)
Definition odb.cxx:6361
Here is the call graph for this function:

◆ get() [1/3]

template<typename T >
T midas::odb::get ( )
inlineprivate

Definition at line 480 of file odbxx.h.

480 {
481 if (m_num_values > 1)
482 mthrow("ODB key \"" + get_full_path() +
483 "[0..." + std::to_string(m_num_values - 1) +
484 "]\" contains array. Please assign to std::vector.");
486 read();
487 return (T) m_data[0];
488 }
bool is_auto_refresh_read() const
Definition odbxx.h:1199
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get() [2/3]

void midas::odb::get ( std::string &  s,
bool  quotes = false,
bool  refresh = true 
)
private

Definition at line 214 of file odbxx.cxx.

214 {
215 if (refresh && is_auto_refresh_read())
216 read();
217
218 // put value into quotes
219 s = "";
220 std::string sd;
221 for (int i = 0; i < m_num_values; i++) {
222 m_data[i].get(sd);
223 if (quotes)
224 s += "\"";
225 s += sd;
226 if (quotes)
227 s += "\"";
228 if (i < m_num_values - 1)
229 s += ",";
230 }
231 }
Here is the call graph for this function:

◆ get() [3/3]

template<typename T >
void midas::odb::get ( T &  v)
inlineprivate

Definition at line 492 of file odbxx.h.

492 {
493 if (m_num_values > 1)
494 mthrow("ODB key \"" + get_full_path() + "\" contains array. Please assign to std::vector.");
496 read();
497 v = (T) m_data[0];
498 }
Here is the call graph for this function:

◆ get_debug()

static bool midas::odb::get_debug ( )
inlinestatic

Definition at line 1240 of file odbxx.h.

1240{ return s_debug; }

◆ get_flags()

uint32_t midas::odb::get_flags ( )
inlineprivate

Definition at line 514 of file odbxx.h.

514{ return static_cast<uint32_t>(m_flags.to_ulong()); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_full_path()

std::string midas::odb::get_full_path ( )

Definition at line 291 of file odbxx.cxx.

291 {
292 if (m_name[0] == '/')
293 return m_name;
294 if (m_parent)
295 return m_parent->get_full_path() + "/" + m_name;
296
297 if (!is_connected_odb() || m_hKey == -1)
298 return m_name;
299
300 std::string str = db_get_path(s_hDB, m_hKey);
301 if (str == "/") // change "/" to ""
302 str = "";
303 return str;
304 }
INT db_get_path(HNDLE hDB, HNDLE hKey, char *path, INT buf_size)
Definition odb.cxx:4990
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_hkey()

HNDLE midas::odb::get_hkey ( )
inline

Definition at line 1273 of file odbxx.h.

1273{ return m_hKey; }
Here is the caller graph for this function:

◆ get_last_index()

int midas::odb::get_last_index ( )
inline

Definition at line 955 of file odbxx.h.

955{ return m_last_index; }

◆ get_last_written()

unsigned int midas::odb::get_last_written ( )

Definition at line 1444 of file odbxx.cxx.

1444 {
1445 init_hdb();
1446
1447 // set mode in ODB
1448 KEY key;
1449 int status = db_get_key(s_hDB, m_hKey, &key);
1450
1452 mthrow("db_get_key for ODB key \"" + get_full_path() +
1453 "\" returnd error code " + std::to_string(status));
1454
1455 return (unsigned int) (key.last_written);
1456 }
Here is the call graph for this function:

◆ get_mdata()

u_odb & midas::odb::get_mdata ( int  index = 0)
inlineprivate

Definition at line 504 of file odbxx.h.

504{ return m_data[index]; }
INT index
Definition mana.cxx:271

◆ get_mode()

int midas::odb::get_mode ( )

Definition at line 1430 of file odbxx.cxx.

1430 {
1431 init_hdb();
1432
1433 // set mode in ODB
1434 KEY key;
1435 int status = db_get_key(s_hDB, m_hKey, &key);
1436
1438 mthrow("db_get_key for ODB key \"" + get_full_path() +
1439 "\" returnd error code " + std::to_string(status));
1440
1441 return key.access_mode;
1442 }
Here is the call graph for this function:

◆ get_name()

std::string midas::odb::get_name ( )
inline

Definition at line 1278 of file odbxx.h.

1278{ return m_name; }
Here is the caller graph for this function:

◆ get_num_values()

int midas::odb::get_num_values ( )
inline

Definition at line 1277 of file odbxx.h.

1277{ return m_num_values; }

◆ get_parent()

midas::odb * midas::odb::get_parent ( )
inlineprivate

Definition at line 525 of file odbxx.h.

525{ return m_parent; }

◆ get_parent_path()

std::string midas::odb::get_parent_path ( )

Definition at line 307 of file odbxx.cxx.

307 {
308 std::string s = get_full_path();
309 std::size_t i = s.find_last_of("/");
310 s = s.substr(0, i);
311 return s;
312 }
Here is the call graph for this function:

◆ get_subkey()

odb & midas::odb::get_subkey ( std::string  str)
private

Definition at line 482 of file odbxx.cxx.

482 {
483 if (m_tid == 0) {
484 if (is_auto_create()) {
485 m_tid = TID_KEY;
486 int status = db_create_key(s_hDB, 0, m_name.c_str(), m_tid);
488 mthrow("Cannot create ODB key \"" + m_name + "\", status" + std::to_string(status));
489 db_find_key(s_hDB, 0, m_name.c_str(), &m_hKey);
490 if (s_debug) {
491 if (m_name[0] == '/')
492 std::cout << "Created ODB key \"" + m_name + "\"" << std::endl;
493 else
494 std::cout << "Created ODB key \"" + get_full_path() + "\"" << std::endl;
495 }
496 // strip path from name
497 if (m_name.find_last_of('/') != std::string::npos)
498 m_name = m_name.substr(m_name.find_last_of('/') + 1);
499 } else
500 mthrow("Invalid key \"" + m_name + "\" does not have subkeys");
501
502 }
503 if (m_tid != TID_KEY)
504 mthrow("ODB key \"" + get_full_path() + "\" does not have subkeys");
505
506 std::string first = str;
507 std::string tail{};
508 if (str.find('/') != std::string::npos) {
509 first = str.substr(0, str.find('/'));
510 tail = str.substr(str.find('/') + 1);
511 }
512
513 int i;
514 for (i = 0; i < m_num_values; i++)
515 if (equal_ustring(first.c_str(), m_data[i].get_odb().get_name().c_str()))
516 break;
517 if (i == m_num_values) {
518 if (is_auto_create()) {
519 if (m_num_values == 0) {
520 m_num_values = 1;
521 m_data = new u_odb[1]{};
522 i = 0;
523 } else {
524 // resize array
526 i = m_num_values - 1;
527 }
528 midas::odb *o = new midas::odb();
530 m_data[i].set_parent(this);
531 o->set_name(get_full_path() + "/" + str);
532 o->set_tid(0); // tid is currently undefined
533 o->set_flags(get_flags());
534 o->set_parent(this);
535 m_data[i].set(o);
536 } else
537 mthrow("ODB key \"" + get_full_path() + "\" does not contain subkey \"" + first + "\"");
538 }
539 if (!tail.empty())
540 return m_data[i].get_odb().get_subkey(tail);
541
542 return *m_data[i].get_podb();
543 }
bool is_auto_create() const
Definition odbxx.h:1214
void resize_mdata(int size)
Definition odbxx.cxx:190
odb & get_subkey(std::string str)
Definition odbxx.cxx:482
uint32_t get_flags()
Definition odbxx.h:514
#define DB_CREATED
Definition midas.h:632
BOOL equal_ustring(const char *str1, const char *str2)
Definition odb.cxx:3201
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_subkeys()

int midas::odb::get_subkeys ( std::vector< std::string > &  name)
private

Definition at line 546 of file odbxx.cxx.

546 {
547 if (m_tid != TID_KEY)
548 return 0;
549 if (m_hKey == 0 || m_hKey == -1)
550 mthrow("get_sub-keys called with invalid m_hKey for ODB key \"" + m_name + "\"");
551
552 // count number of subkeys in ODB
553 std::vector<HNDLE> hlist;
554 int n = 0;
555 for (int i = 0;; i++) {
556 HNDLE h;
557 int status = db_enum_key(s_hDB, m_hKey, i, &h);
558 if (status != DB_SUCCESS)
559 break;
560 KEY key;
561 db_get_key(s_hDB, h, &key);
562 hlist.push_back(h);
563 name.push_back(key.name);
564 n = i + 1;
565 }
566
567 return n;
568 }
INT db_enum_key(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
Definition odb.cxx:5586
DWORD n[4]
Definition mana.cxx:247
char name[NAME_LENGTH]
Definition midas.h:1029
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tid()

int midas::odb::get_tid ( )
inline

Definition at line 1276 of file odbxx.h.

1276{ return m_tid; }
Here is the caller graph for this function:

◆ init_hdb()

void midas::odb::init_hdb ( )
staticprivate

Definition at line 43 of file odbxx.cxx.

43 {
44 if (s_hDB == 0)
46 if (s_hDB == 0)
47 mthrow("Please call cm_connect_experiment() before accessing the ODB");
48 s_connected_odb = true;
49 }
static bool s_connected_odb
Definition odbxx.h:442
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
Definition midas.cxx:3011
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_auto_create()

bool midas::odb::is_auto_create ( ) const
inline

Definition at line 1214 of file odbxx.h.

Here is the caller graph for this function:

◆ is_auto_enlarge_array()

bool midas::odb::is_auto_enlarge_array ( ) const
inline

Definition at line 1220 of file odbxx.h.

Here is the caller graph for this function:

◆ is_auto_refresh_read()

bool midas::odb::is_auto_refresh_read ( ) const
inline

Definition at line 1199 of file odbxx.h.

Here is the caller graph for this function:

◆ is_auto_refresh_write()

bool midas::odb::is_auto_refresh_write ( ) const
inline

Definition at line 1205 of file odbxx.h.

Here is the caller graph for this function:

◆ is_connected_odb()

static bool midas::odb::is_connected_odb ( )
inlinestatic

Definition at line 1250 of file odbxx.h.

1250{ return s_connected_odb; }
Here is the caller graph for this function:

◆ is_deleted()

bool midas::odb::is_deleted ( ) const
inlineprivate

Definition at line 516 of file odbxx.h.

516{ return m_flags[odb_flags::DELETED]; }
@ DELETED
Definition odbxx.h:398
Here is the caller graph for this function:

◆ is_dirty()

bool midas::odb::is_dirty ( ) const
inline

Definition at line 1211 of file odbxx.h.

1211{ return m_flags[odb_flags::DIRTY]; }
@ DIRTY
Definition odbxx.h:397

◆ is_preserve_string_size()

bool midas::odb::is_preserve_string_size ( ) const
inline

Definition at line 1193 of file odbxx.h.

@ PRESERVE_STRING_SIZE
Definition odbxx.h:394
Here is the caller graph for this function:

◆ is_subkey()

bool midas::odb::is_subkey ( std::string  str)

Definition at line 458 of file odbxx.cxx.

458 {
459 if (m_tid != TID_KEY)
460 return false;
461
462 std::string first = str;
463 std::string tail{};
464 if (str.find('/') != std::string::npos) {
465 first = str.substr(0, str.find('/'));
466 tail = str.substr(str.find('/') + 1);
467 }
468
469 int i;
470 for (i = 0; i < m_num_values; i++)
471 if (m_data[i].get_odb().get_name() == first)
472 break;
473 if (i == m_num_values)
474 return false;
475
476 if (!tail.empty())
477 return m_data[i].get_odb().is_subkey(tail);
478
479 return true;
480 }
bool is_subkey(std::string str)
Definition odbxx.cxx:458
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_trigger_hotlink()

bool midas::odb::is_trigger_hotlink ( ) const
inline

Definition at line 1232 of file odbxx.h.

Here is the caller graph for this function:

◆ is_write_protect()

bool midas::odb::is_write_protect ( ) const
inline

Definition at line 1226 of file odbxx.h.

@ WRITE_PROTECT
Definition odbxx.h:399
Here is the caller graph for this function:

◆ items()

odb & midas::odb::items ( )
inline

Definition at line 1279 of file odbxx.h.

1279{ return *this; }

◆ load()

void midas::odb::load ( const std::string &  filename,
const std::string &  odb_path 
)
static

Definition at line 92 of file odbxx.cxx.

92 {
93 init_hdb();
95 mthrow("Cannot connect to ODB");
96
97 HNDLE hkey;
98 auto status = db_find_key(s_hDB, 0, odb_path.c_str(), &hkey);
99 if (status == DB_NO_KEY)
100 db_create_key(s_hDB, 0, odb_path.c_str(), TID_KEY);
101 status = db_find_key(s_hDB, 0, odb_path.c_str(), &hkey);
102 if (status != DB_SUCCESS)
103 mthrow("ODB path " + odb_path + " not found in ODB");
104
105 KEY key;
107 if (key.type != TID_KEY)
108 mthrow("ODB path " + odb_path + " does not point to a directory");
109
110 db_load(s_hDB, hkey, filename.c_str(), false);
111 }
#define DB_NO_KEY
Definition midas.h:642
INT db_load(HNDLE hDB, HNDLE hKeyRoot, const char *filename, BOOL bRemote)
Definition odb.cxx:8126
DWORD type
Definition midas.h:1027
Here is the call graph for this function:

◆ odb_from_xml() [1/2]

void midas::odb::odb_from_xml ( const std::string &  str)

Definition at line 150 of file odbxx.cxx.

150 {
151 init_hdb();
152
153 HNDLE hKey;
154 int status = db_find_key(s_hDB, 0, str.c_str(), &hKey);
155 if (status != DB_SUCCESS)
156 mthrow("ODB key \"" + str + "\" not found in ODB");
157
158 int bsize = 1000000;
159 char *buffer = (char *)malloc(bsize);
160 do {
161 int size = bsize;
162 status = db_copy_xml(s_hDB, hKey, buffer, &size, false);
163 if (status == DB_TRUNCATED) {
164 bsize *= 2;
165 buffer = (char *)realloc(buffer, bsize);
166 }
167 } while (status == DB_TRUNCATED);
168
169 if (status != DB_SUCCESS)
170 mthrow("Cannot retrieve XML data, status = " + std::to_string(status));
171
172 if (s_debug)
173 std::cout << "Retrieved XML tree for \"" + str + "\"" << std::endl;
174
175 char error[256] = "";
176 PMXML_NODE tree = mxml_parse_buffer(buffer, error, sizeof(error), NULL);
177 if (error[0]) {
178 std::cout << "MXML error, buffer =\n" << buffer << std::endl;
179 mthrow("MXML error: " + std::string(error));
180 }
181 free(buffer);
182
183 odb_from_xml(&tree->child[2], this);
184 m_hKey = hKey;
185
187 }
int size()
Definition odbxx.cxx:315
#define DB_TRUNCATED
Definition midas.h:644
INT db_copy_xml(HNDLE hDB, HNDLE hKey, char *buffer, int *buffer_size, bool header)
Definition odb.cxx:9037
Here is the call graph for this function:

◆ odb_from_xml() [2/2]

midas::odb * midas::odb::odb_from_xml ( PMXML_NODE  node,
odb o 
)
inline

Definition at line 1142 of file odbxx.h.

1142 {
1143 std::string type(mxml_get_name(node));
1144
1145 unsigned int tid = 0;
1146 if (type == "dir")
1147 tid = TID_KEY;
1148 else {
1149 for (tid = 0; tid < TID_LAST; tid++) {
1151 break;
1152 }
1153 }
1154 if (tid == TID_LAST)
1155 mthrow("Wrong key type in XML file");
1156
1157 if (o == nullptr)
1158 o = new midas::odb();
1159 o->set_tid(tid);
1160 o->set_name(mxml_get_attribute(node, "name"));
1161 if (mxml_get_attribute(node, "handle") == nullptr)
1162 mthrow("No \"handle\" attribute found in XML data");
1163 o->set_hkey(std::stoi(std::string(mxml_get_attribute(node, "handle"))));
1164
1165 if (type == "key") {
1166 std::string value(mxml_get_value(node));
1167 o->set(value);
1168 } else if (type == "keyarray") {
1169 int n = std::atoi(mxml_get_attribute(node, "num_values"));
1170 o->set_num_values(n);
1171 for (int i=0 ; i<n ; i++) {
1172 std::string value(mxml_get_value(mxml_subnode(node, i)));
1173 o->set(value, i);
1174 }
1175 } else if (type == "dir") {
1177 o->set_num_values(n);
1178 for (int i = 0; i < n; i++) {
1180 os->set_parent(o);
1181 o->set_odb(os, i);
1182 }
1183 } else
1184 mthrow("Unexpected XML element " + std::string(mxml_get_name(node)));
1185
1186 return o;
1187 };
#define TID_LAST
Definition midas.h:354
const char * rpc_tid_name(INT id)
Definition midas.cxx:11764
double value[100]
Definition odbhist.cxx:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator std::string()

midas::odb::operator std::string ( )
inline

Definition at line 828 of file odbxx.h.

828 {
829 std::string s;
830 if (m_tid == TID_KEY)
831 print(s, 0);
832 else
833 get(s); // forward to get(std::string)
834 return s;
835 }
std::string print()
Definition odbxx.cxx:348
Here is the call graph for this function:

◆ operator std::vector< std::string >()

midas::odb::operator std::vector< std::string > ( )
inline

Definition at line 848 of file odbxx.h.

848 {
850 read();
851 std::vector<std::string> v(m_num_values);
852 for (int i = 0; i < m_num_values; i++)
853 v[i] = m_data[i].get();
854 return v;
855 }
Here is the call graph for this function:

◆ operator std::vector< T >()

template<typename T >
midas::odb::operator std::vector< T > ( )
inline

Definition at line 839 of file odbxx.h.

839 {
841 read();
842 std::vector<T> v(m_num_values);
843 for (int i = 0; i < m_num_values; i++)
844 v[i] = m_data[i];
845 return v;
846 }
Here is the call graph for this function:

◆ operator T()

template<typename T , typename std::enable_if< std::is_same< T, uint8_t >::value||std::is_same< T, int8_t >::value||std::is_same< T, uint16_t >::value||std::is_same< T, int16_t >::value||std::is_same< T, uint32_t >::value||std::is_same< T, int32_t >::value||std::is_same< T, uint64_t >::value||std::is_same< T, int64_t >::value||std::is_same< T, bool >::value||std::is_same< T, float >::value||std::is_same< T, double >::value, T >::type * = nullptr>
midas::odb::operator T ( )
inline

Definition at line 870 of file odbxx.h.

870 {
871 if (m_tid == 0)
872 mthrow("Element \"" + m_name + "\" not found");
873 return get<T>(); // forward to get<T>()
874 }
Here is the call graph for this function:

◆ operator()()

template<typename T >
odb & midas::odb::operator() ( v)
inline

Definition at line 932 of file odbxx.h.

932 {
933 if (m_tid == 0) {
934 if (m_num_values == 0) {
935 // initialize this
936 m_num_values = 1;
937 m_tid = detect_type(v);
938 m_data = new u_odb[1]{};
939 m_data[0].set_tid(m_tid);
940 m_data[0].set_parent(this);
941 m_data[0].set(v);
942 if (this->is_auto_refresh_write())
943 write();
944 } else {
945 for (int i = 0; i < m_num_values; i++)
946 m_data[i].set(v);
947 if (this->is_auto_refresh_write())
948 write();
949 }
950 }
951 return *this;
952 }
bool is_auto_refresh_write() const
Definition odbxx.h:1205
int detect_type(const T &)
Definition odbxx.h:686
#define set(var, value)
Here is the call graph for this function:

◆ operator*()

template<typename T >
T midas::odb::operator* ( const i)
inline

Definition at line 1008 of file odbxx.h.

1008 {
1009 if (m_num_values > 1)
1010 mthrow("ODB key \"" + get_full_path() +
1011 "\" contains array which cannot be used in basic arithmetic operation.");
1013 read();
1014 T s = (T) m_data[0];
1015 return s * i;
1016 }
Here is the call graph for this function:

◆ operator*=()

odb & midas::odb::operator*= ( double  d)
inline

Definition at line 1093 of file odbxx.h.

1093 {
1095 read();
1096 for (int i = 0; i < m_num_values; i++)
1097 m_data[i].mult(d, false);
1098 if (this->is_auto_refresh_write())
1099 write();
1100 return *this;
1101 }
Here is the call graph for this function:

◆ operator+()

template<typename T >
T midas::odb::operator+ ( i)
inline

Definition at line 964 of file odbxx.h.

964 {
965 if (m_num_values > 1)
966 mthrow("ODB key \"" + get_full_path() +
967 "\" contains array which cannot be used in basic arithmetic operation.");
968 if (std::is_same<T, midas::odb>::value) {
969 if (is_auto_refresh_read()) {
970 read();
971 i.read();
972 }
973 // adding two midas::odb objects is best done in double
974 double s1 = static_cast<double>(m_data[0]);
975 double s2 = static_cast<double>(i.m_data[0]);
976 return s1 + s2;
977 } else {
979 read();
980 T s = (T) m_data[0];
981 return s + i;
982 }
983 }
Here is the call graph for this function:

◆ operator++() [1/2]

odb & midas::odb::operator++ ( )
inline

Definition at line 1029 of file odbxx.h.

1029 {
1031 read();
1032 for (int i = 0; i < m_num_values; i++)
1033 m_data[i].add(1, false);
1034 if (this->is_auto_refresh_write())
1035 write();
1036 return *this;
1037 }
INT add
Definition odbhist.cxx:40
Here is the call graph for this function:

◆ operator++() [2/2]

odb midas::odb::operator++ ( int  )
inline

Definition at line 1039 of file odbxx.h.

1039 {
1040 // create temporary object
1041 odb o(this);
1043 read();
1044 for (int i = 0; i < m_num_values; i++)
1045 m_data[i].add(1, false);
1046 if (this->is_auto_refresh_write())
1047 write();
1048 return o;
1049 }
Here is the call graph for this function:

◆ operator+=()

odb & midas::odb::operator+= ( double  d)
inline

Definition at line 1073 of file odbxx.h.

1073 {
1075 read();
1076 for (int i = 0; i < m_num_values; i++)
1077 m_data[i].add(d, false);
1078 if (this->is_auto_refresh_write())
1079 write();
1080 return *this;
1081 }
Here is the call graph for this function:

◆ operator-()

template<typename T >
T midas::odb::operator- ( i)
inline

Definition at line 986 of file odbxx.h.

986 {
987 if (m_num_values > 1)
988 mthrow("ODB key \"" + get_full_path() +
989 "\" contains array which cannot be used in basic arithmetic operation.");
990 if (std::is_same<T, midas::odb>::value) {
991 if (is_auto_refresh_read()) {
992 read();
993 i.read();
994 }
995 // subtracting two midas::odb objects is best done in double
996 double s1 = static_cast<double>(m_data[0]);
997 double s2 = static_cast<double>(i.m_data[0]);
998 return s1 - s2;
999 } else {
1001 read();
1002 T s = (T) m_data[0];
1003 return s - i;
1004 }
1005 }
Here is the call graph for this function:

◆ operator--() [1/2]

odb & midas::odb::operator-- ( )
inline

Definition at line 1051 of file odbxx.h.

1051 {
1053 read();
1054 for (int i = 0; i < m_num_values; i++)
1055 m_data[i].add(-1, false);
1056 if (this->is_auto_refresh_write())
1057 write();
1058 return *this;
1059 }
Here is the call graph for this function:

◆ operator--() [2/2]

odb midas::odb::operator-- ( int  )
inline

Definition at line 1061 of file odbxx.h.

1061 {
1062 // create temporary object
1063 odb o(this);
1065 read();
1066 for (int i = 0; i < m_num_values; i++)
1067 m_data[i].add(-1, false);
1068 if (this->is_auto_refresh_write())
1069 write();
1070 return o;
1071 }
Here is the call graph for this function:

◆ operator-=()

odb & midas::odb::operator-= ( double  d)
inline

Definition at line 1083 of file odbxx.h.

1083 {
1085 read();
1086 for (int i = 0; i < m_num_values; i++)
1087 m_data[i].add(-d, false);
1088 if (this->is_auto_refresh_write())
1089 write();
1090 return *this;
1091 }
Here is the call graph for this function:

◆ operator/()

template<typename T >
T midas::odb::operator/ ( const i)
inline

Definition at line 1019 of file odbxx.h.

1019 {
1020 if (m_num_values > 1)
1021 mthrow("ODB key \"" + get_full_path() +
1022 "\" contains array which cannot be used in basic arithmetic operation.");
1024 read();
1025 T s = (T) m_data[0];
1026 return s / i;
1027 }
Here is the call graph for this function:

◆ operator/=()

odb & midas::odb::operator/= ( double  d)
inline

Definition at line 1103 of file odbxx.h.

1103 {
1105 read();
1106 if (d == 0)
1107 mthrow("Division by zero");
1108 for (int i = 0; i < m_num_values; i++)
1109 m_data[i].mult(1 / d, false);
1110 if (this->is_auto_refresh_write())
1111 write();
1112 return *this;
1113 }
Here is the call graph for this function:

◆ operator=() [1/4]

template<typename T , size_t SIZE>
const std::array< T, SIZE > & midas::odb::operator= ( const std::array< T, SIZE > &  arr)
inline

Definition at line 796 of file odbxx.h.

796 {
797
798 if (this->is_write_protect())
799 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
800
801 if (m_num_values == 0) {
802 // initialize this
804 m_tid = detect_type(arr[0]);
805 m_data = new u_odb[m_num_values]{};
806 for (int i = 0; i < m_num_values; i++) {
808 m_data[i].set_parent(this);
809 }
810
811 } else {
812
813 // resize internal array if different
814 if (SIZE != m_num_values) {
816 }
817 }
818
819 for (int i = 0; i < m_num_values; i++)
820 m_data[i].set(arr[i]);
821
822 if (this->is_auto_refresh_write())
823 write();
824 return arr;
825 }
Here is the call graph for this function:

◆ operator=() [2/4]

template<typename T >
const std::vector< T > & midas::odb::operator= ( const std::vector< T > &  v)
inline

Definition at line 750 of file odbxx.h.

750 {
751
752 if (this->is_write_protect())
753 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
754
755 if (m_num_values == 0) {
756 // initialize this
757 m_num_values = v.size();
758 if (std::is_same<T, bool>::value) {
759 // Special logic for vector<bool>, which may not be a true
760 // container: it's often optimized to be a bitfield, with
761 // references to elements being masked bits rather than bools.
762 // So T is a bool here, but typeof(v[0]) may not be bool!
763 // "Fake container optimization" only applies to vector<bool>,
764 // not array<bool> or any other vector<T>.
765 m_tid = TID_BOOL;
766 } else {
767 // Every other type can be detected using ref to first element.
768 m_tid = detect_type(v[0]);
769 }
770
771 m_data = new u_odb[m_num_values]{};
772 for (int i = 0; i < m_num_values; i++) {
774 m_data[i].set_parent(this);
775 }
776
777 } else {
778
779 // resize internal array if different
780 if ((int)v.size() != m_num_values) {
781 resize_mdata(v.size());
782 }
783 }
784
785 for (int i = 0; i < m_num_values; i++)
786 m_data[i].set(v[i]);
787
788 if (this->is_auto_refresh_write())
789 write();
790
791 return v;
792 }
Here is the call graph for this function:

◆ operator=() [3/4]

template<typename T >
const T & midas::odb::operator= ( const T &  v)
inline

Definition at line 723 of file odbxx.h.

723 {
724
725 if (this->is_write_protect())
726 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
727
728 if (m_num_values == 0) {
729 // initialize this
730 m_num_values = 1;
731 m_tid = detect_type(v);
732 m_data = new u_odb[1]{};
733 m_data[0].set_tid(m_tid);
734 m_data[0].set_parent(this);
735 m_data[0].set(v);
736 if (this->is_auto_refresh_write())
737 write();
738 } else {
739 for (int i = 0; i < m_num_values; i++)
740 m_data[i].set(v);
741
742 if (this->is_auto_refresh_write())
743 write();
744 }
745 return v;
746 }
Here is the call graph for this function:

◆ operator=() [4/4]

odb midas::odb::operator= ( odb &&  o)
delete

◆ operator[]() [1/3]

odb & midas::odb::operator[] ( const char str)
inline

Definition at line 926 of file odbxx.h.

926 {
927 return get_subkey(std::string(str));
928 }
Here is the call graph for this function:

◆ operator[]() [2/3]

u_odb & midas::odb::operator[] ( int  index)
inline

Definition at line 888 of file odbxx.h.

888 {
889 if (this->is_write_protect())
890 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
891
892 if (index < 0)
893 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) + "]\"");
894
895 if (index == 0 && m_num_values == 0) {
896 // initialize this
897 m_num_values = 1;
898 m_tid = 0;
899 m_data = new u_odb[1]{};
900 m_data[0].set_tid(m_tid);
901 m_data[0].set_parent(this);
902 m_last_index = 0;
903 return m_data[0];
904 } else if (index >= m_num_values) {
905 if (is_auto_enlarge_array()) {
907 if (this->is_auto_refresh_write())
908 write(index, 0);
909 } else {
910 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)");
911 }
912 }
913
915 read(index);
916
918 return m_data[index];
919 }
bool is_auto_enlarge_array() const
Definition odbxx.h:1220
Here is the call graph for this function:

◆ operator[]() [3/3]

odb & midas::odb::operator[] ( std::string  str)
inline

Definition at line 922 of file odbxx.h.

922 {
923 return get_subkey(str);
924 }
Here is the call graph for this function:

◆ print() [1/2]

std::string midas::odb::print ( )

Definition at line 348 of file odbxx.cxx.

348 {
349 std::string s;
350 s = "{\n";
351 print(s, 1);
352 s += "\n}";
353 return s;
354 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print() [2/2]

void midas::odb::print ( std::string &  s,
int  indent = 0 
)

Definition at line 365 of file odbxx.cxx.

365 {
366 for (int i = 0; i < indent; i++)
367 s += " ";
368 if (m_tid == TID_KEY) {
369 s += "\"" + m_name + "\": {\n";
370 for (int i = 0; i < m_num_values; i++) {
371 std::string v;
372 // recursive call
373 m_data[i].get_odb().print(v, indent + 1);
374 s += v;
375 if (i < m_num_values - 1)
376 s += ",\n";
377 else
378 s += "\n";
379 }
380 for (int i = 0; i < indent; i++)
381 s += " ";
382 s += "}";
383 } else {
384 s += "\"" + m_name + "\": ";
385 if (m_num_values > 1)
386 s += "[";
387 std::string v;
388 get(v, m_tid == TID_STRING || m_tid == TID_LINK);
389 if (m_tid == TID_LINK)
390 s += " -> ";
391 s += v;
392 if (m_num_values > 1)
393 s += "]";
394 }
395 }
Here is the call graph for this function:

◆ read() [1/2]

void midas::odb::read ( )

Definition at line 716 of file odbxx.cxx.

716 {
717 if (!is_connected_odb())
718 return;
719
720 // check if deleted
721 if (is_deleted())
722 mthrow("ODB key \"" + m_name + "\" cannot be pulled because it has been deleted");
723
724 if (m_hKey == 0)
725 return; // needed to print un-connected objects
726
727 if (m_tid == 0)
728 mthrow("Read of invalid ODB key \"" + m_name + "\"");
729
730 if (m_hKey == -1) {
731 // connect un-connected object (crated via XML)
732 std::string path = get_full_path();
733
734 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
735 if (status != DB_SUCCESS)
736 mthrow("Cannot connect key \"" + path + "\" to ODB");
737 }
738
739 int status{};
740 if (m_tid == TID_STRING) {
741 KEY key;
743 char *str = (char *) malloc(key.total_size);
744 int size = key.total_size;
746 for (int i = 0; i < m_num_values; i++)
747 m_data[i].set(str + i * key.item_size);
748 free(str);
749 } else if (m_tid == TID_KEY) {
750 std::vector<std::string> name;
751 int n = get_subkeys(name);
752 if (n != m_num_values) {
753 // if subdirs have changed, rebuild it
754 delete[] m_data;
755 m_num_values = n;
757 for (int i = 0; i < m_num_values; i++) {
758 std::string k(get_full_path());
759 k += "/" + name[i];
760 midas::odb *o = new midas::odb(k.c_str());
761 o->set_parent(this);
763 m_data[i].set_parent(this);
764 m_data[i].set(o);
765 }
766 }
767 for (int i = 0; i < m_num_values; i++)
768 m_data[i].get_odb().read();
770 } else {
771 // resize local array if number of values has changed
772 KEY key;
774 if (key.num_values != m_num_values) {
775 delete[] m_data;
778 for (int i = 0; i < m_num_values; i++) {
780 m_data[i].set_parent(this);
781 }
782 }
783
785 void *buffer = malloc(size);
786 void *p = buffer;
788 for (int i = 0; i < m_num_values; i++) {
789 if (m_tid == TID_UINT8)
790 m_data[i].set(*static_cast<uint8_t *>(p));
791 else if (m_tid == TID_INT8)
792 m_data[i].set(*static_cast<int8_t *>(p));
793 else if (m_tid == TID_UINT16)
794 m_data[i].set(*static_cast<uint16_t *>(p));
795 else if (m_tid == TID_INT16)
796 m_data[i].set(*static_cast<int16_t *>(p));
797 else if (m_tid == TID_UINT32)
798 m_data[i].set(*static_cast<uint32_t *>(p));
799 else if (m_tid == TID_INT32)
800 m_data[i].set(*static_cast<int32_t *>(p));
801 else if (m_tid == TID_UINT64)
802 m_data[i].set(*static_cast<uint64_t *>(p));
803 else if (m_tid == TID_INT64)
804 m_data[i].set(*static_cast<int64_t *>(p));
805 else if (m_tid == TID_BOOL)
806 m_data[i].set(*static_cast<bool *>(p));
807 else if (m_tid == TID_FLOAT)
808 m_data[i].set(*static_cast<float *>(p));
809 else if (m_tid == TID_DOUBLE)
810 m_data[i].set(*static_cast<double *>(p));
811 else if (m_tid == TID_STRING)
812 m_data[i].set(std::string(static_cast<const char *>(p)));
813 else if (m_tid == TID_LINK)
814 m_data[i].set(std::string(static_cast<const char *>(p)));
815 else
816 mthrow("Invalid type ID " + std::to_string(m_tid));
817
818 p = static_cast<char *>(p) + rpc_tid_size(m_tid);
819 }
820 free(buffer);
821 }
822
823 if (status != DB_SUCCESS)
824 mthrow("db_get_data for ODB key \"" + get_full_path() +
825 "\" failed with status " + std::to_string(status));
826 if (s_debug) {
827 if (m_tid == TID_KEY) {
828 std::cout << "Get ODB key \"" + get_full_path() + "[0..." +
829 std::to_string(m_num_values - 1) + "]\"" << std::endl;
830 } else {
831 std::string s;
832 get(s, false, false);
833 if (m_num_values > 1) {
834 if (m_tid == TID_STRING || m_tid == TID_LINK)
835 std::cout << "Get ODB key \"" + get_full_path() + "[0..." +
836 std::to_string(m_num_values - 1) + "]\": [\"" + s + "\"]" << std::endl;
837 else
838 std::cout << "Get ODB key \"" + get_full_path() + "[0..." +
839 std::to_string(m_num_values - 1) + "]\": [" + s + "]" << std::endl;
840 } else {
841 if (m_tid == TID_STRING || m_tid == TID_LINK)
842 std::cout << "Get ODB key \"" + get_full_path() + "\": \"" + s + "\"" << std::endl;
843 else
844 std::cout << "Get ODB key \"" + get_full_path() + "\": " + s << std::endl;
845 }
846 }
847 }
848 }
bool is_deleted() const
Definition odbxx.h:516
INT db_get_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
Definition odb.cxx:6539
INT rpc_tid_size(INT id)
Definition midas.cxx:11757
INT k
Definition odbhist.cxx:40
INT num_values
Definition midas.h:1028
INT total_size
Definition midas.h:1031
INT item_size
Definition midas.h:1032
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read() [2/2]

void midas::odb::read ( int  index)

Definition at line 851 of file odbxx.cxx.

851 {
852 if (!is_connected_odb())
853 return;
854
855 if (m_hKey == 0 || m_hKey == -1)
856 return; // needed to print un-connected objects
857
858 if (m_tid == 0)
859 mthrow("Pull of invalid ODB key \"" + m_name + "\"");
860
861 int status{};
862 if (m_tid == TID_STRING || m_tid == TID_LINK) {
863 KEY key;
865 char *str = (char *) malloc(key.item_size);
866 int size = key.item_size;
869 free(str);
870 } else if (m_tid == TID_KEY) {
873 } else {
874 int size = rpc_tid_size(m_tid);
875 void *buffer = malloc(size);
876 void *p = buffer;
878 if (m_tid == TID_UINT8)
879 m_data[index].set(*static_cast<uint8_t *>(p));
880 else if (m_tid == TID_INT8)
881 m_data[index].set(*static_cast<int8_t *>(p));
882 else if (m_tid == TID_UINT16)
883 m_data[index].set(*static_cast<uint16_t *>(p));
884 else if (m_tid == TID_INT16)
885 m_data[index].set(*static_cast<int16_t *>(p));
886 else if (m_tid == TID_UINT32)
887 m_data[index].set(*static_cast<uint32_t *>(p));
888 else if (m_tid == TID_INT32)
889 m_data[index].set(*static_cast<int32_t *>(p));
890 else if (m_tid == TID_UINT64)
891 m_data[index].set(*static_cast<uint64_t *>(p));
892 else if (m_tid == TID_INT64)
893 m_data[index].set(*static_cast<int64_t *>(p));
894 else if (m_tid == TID_BOOL)
895 m_data[index].set(*static_cast<bool *>(p));
896 else if (m_tid == TID_FLOAT)
897 m_data[index].set(*static_cast<float *>(p));
898 else if (m_tid == TID_DOUBLE)
899 m_data[index].set(*static_cast<double *>(p));
900 else if (m_tid == TID_STRING)
901 m_data[index].set(std::string(static_cast<const char *>(p)));
902 else if (m_tid == TID_LINK)
903 m_data[index].set(std::string(static_cast<const char *>(p)));
904 else
905 mthrow("Invalid type ID " + std::to_string(m_tid));
906
907 free(buffer);
908 }
909
910 if (status != DB_SUCCESS)
911 mthrow("db_get_data for ODB key \"" + get_full_path() +
912 "\" failed with status " + std::to_string(status));
913 if (s_debug) {
914 std::string s;
915 m_data[index].get(s);
916 if (m_tid == TID_STRING || m_tid == TID_LINK)
917 std::cout << "Get ODB key \"" + get_full_path() + "[" +
918 std::to_string(index) + "]\": [\"" + s + "\"]" << std::endl;
919 else
920 std::cout << "Get ODB key \"" + get_full_path() + "[" +
921 std::to_string(index) + "]\": [" + s + "]" << std::endl;
922 }
923 }
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT idx, DWORD type)
Definition odb.cxx:6893
Here is the call graph for this function:

◆ read_key()

bool midas::odb::read_key ( const std::string &  path)
private

Definition at line 571 of file odbxx.cxx.

571 {
572 init_hdb();
573
574 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
575 if (status != DB_SUCCESS)
576 return false;
577
578 KEY key;
580 if (status != DB_SUCCESS)
581 mthrow("db_get_key for ODB key \"" + path +
582 "\" failed with status " + std::to_string(status));
583
584 // check for correct type if given as parameter
585 if (m_tid > 0 && m_tid != (int) key.type)
586 mthrow("ODB key \"" + get_full_path() +
587 "\" has different type than specified");
588
589 if (s_debug)
590 std::cout << "Get definition for ODB key \"" + get_full_path() + "\"" << std::endl;
591
592 m_tid = key.type;
593 m_name = key.name;
594 if (m_tid == TID_KEY) {
595
596 // merge ODB keys with local keys
597 for (int i = 0; i < m_num_values; i++) {
598 std::string p(path);
599 if (p.back() != '/')
600 p += "/";
601 p += m_data[i].get_odb().get_name();
602 HNDLE h;
603 status = db_find_key(s_hDB, 0, p.c_str(), &h);
604 if (status != DB_SUCCESS) {
605 // if key does not exist in ODB write it
606 m_data[i].get_odb().write_key(p, true);
607 m_data[i].get_odb().write();
608 } else {
609 // check key type
610 KEY key;
611 status = db_get_key(s_hDB, h, &key);
612 if (status != DB_SUCCESS)
613 mthrow("db_get_key for ODB key \"" + get_full_path() +
614 "\" failed with status " + std::to_string(status));
615 if (m_data[i].get_odb().get_tid() != (int)key.type) {
616 // write key if different
617 m_data[i].get_odb().write_key(p, true);
618 m_data[i].get_odb().write();
619 }
620 if (m_data[i].get_odb().get_tid() == TID_KEY) {
621 // update subkey structure
622 m_data[i].get_odb().read_key(p);
623 }
624 }
625 }
626
627 // read back everything from ODB
628 std::vector<std::string> name;
630 delete[] m_data;
632 for (int i = 0; i < m_num_values; i++) {
633 std::string p(path);
634 if (p.back() != '/')
635 p += "/";
636 p += name[i];
637 midas::odb *o = new midas::odb(p.c_str());
638 o->set_parent(this);
640 m_data[i].set_parent(this);
641 m_data[i].set(o);
642 }
643 } else {
645 delete[] m_data;
647 for (int i = 0; i < m_num_values; i++) {
649 m_data[i].set_parent(this);
650 }
651 }
652
653 return true;
654 }
void write(int str_size=0)
Definition odbxx.cxx:1027
int get_tid()
Definition odbxx.h:1276
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize() [1/2]

void midas::odb::resize ( int  size)

Definition at line 320 of file odbxx.cxx.

320 {
322 if (this->is_auto_refresh_write()) {
324 if (status != DB_SUCCESS)
325 mthrow("db_set_num_values for ODB key \"" + get_full_path() +
326 "\" failed with status " + std::to_string(status));
327 }
328 }
INT db_set_num_values(HNDLE hDB, HNDLE hKey, INT num_values)
Definition odb.cxx:7502
Here is the call graph for this function:

◆ resize() [2/2]

void midas::odb::resize ( int  size,
bool  b 
)

Definition at line 331 of file odbxx.cxx.

331 {
334 if (this->is_auto_refresh_write()) {
336 if (status != DB_SUCCESS)
337 mthrow("db_set_num_values for ODB key \"" + get_full_path() +
338 "\" failed with status " + std::to_string(status));
339 }
340 if (size > old_size) {
341 for (int i=old_size ; i<size ; i++)
342 m_data[i] = b;
343 if (this->is_auto_refresh_write())
344 write();
345 }
346 }
Here is the call graph for this function:

◆ resize_mdata()

void midas::odb::resize_mdata ( int  size)
private

Definition at line 190 of file odbxx.cxx.

190 {
191 auto new_array = new u_odb[size]{};
192 int i;
193 for (i = 0; i < m_num_values && i < size; i++) {
194 new_array[i] = m_data[i];
195 if (m_tid == TID_KEY)
196 m_data[i].set_odb(nullptr); // move odb*
197 if (m_tid == TID_STRING || m_tid == TID_LINK)
198 m_data[i].set_string_ptr(nullptr); // move std::string*
199 }
200 for (; i < size; i++) {
201 if (m_tid == TID_STRING || m_tid == TID_LINK)
202 new_array[i].set_string(""); // allocates new string
203 }
204 delete[] m_data;
207 for (i = 0; i < m_num_values; i++) {
209 m_data[i].set_parent(this);
210 }
211 }
void set_odb(odb *v)
Definition odbxx.h:187
Here is the call graph for this function:
Here is the caller graph for this function:

◆ s()

std::string midas::odb::s ( )
inline

Definition at line 1281 of file odbxx.h.

1281 {
1282 std::string s;
1283 get(s);
1284 return s;
1285 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save()

void midas::odb::save ( const std::string &  filename)

Definition at line 436 of file odbxx.cxx.

436 {
437 std::string buffer;
438
439 std::string header = "{\n";
440 header += " \"/MIDAS version\" : \"2.1\",\n";
441 header += " \"/filename\" : \"" + filename + "\",\n";
442 header += " \"/ODB path\" : \"" + get_full_path() + "\",\n\n";
443
444 odb::dump(buffer, 1);
445
446 buffer += "\n}\n";
447
448 std::ofstream f(filename);
449 if (!f.is_open())
450 mthrow("Cannot open file \"" + filename);
451
452 f << header << buffer;
453 f.close();
454 }
Here is the call graph for this function:

◆ search_hkey()

midas::odb * midas::odb::search_hkey ( midas::odb po,
int  hKey 
)
staticprivate

Definition at line 52 of file odbxx.cxx.

52 {
53 if (po->m_hKey == hKey)
54 return po;
55 if (po->m_tid == TID_KEY) {
56 for (int i = 0; i < po->m_num_values; i++) {
57 midas::odb *pot = search_hkey(po->m_data[i].get_podb(), hKey);
58 if (pot != nullptr)
59 return pot;
60 }
61 }
62 return nullptr;
63 }
static midas::odb * search_hkey(midas::odb *po, int hKey)
Definition odbxx.cxx:52
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set() [1/2]

void midas::odb::set ( std::string  s,
int  i 
)

Definition at line 1510 of file odbxx.cxx.

1511 {
1512 if (this->is_write_protect())
1513 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1514
1515 if (m_tid == TID_BOOL)
1516 s = (s == "y" || s == "1") ? "1" : "0";
1517
1518 if (m_data == nullptr)
1519 m_data = new u_odb[m_num_values];
1520 m_data[i].set_parent(this);
1522 m_data[i].set(s);
1523 }
Here is the call graph for this function:

◆ set() [2/2]

void midas::odb::set ( std::string  str)

Definition at line 1495 of file odbxx.cxx.

1496 {
1497 if (this->is_write_protect())
1498 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1499
1500 if (m_tid == TID_BOOL)
1501 s = (s == "y" || s == "1") ? "1" : "0";
1502
1503 m_num_values = 1;
1504 m_data = new u_odb[1];
1505 m_data[0].set_parent(this);
1506 m_data[0].set_tid(m_tid);
1507 m_data[0].set(s);
1508 }
Here is the call graph for this function:

◆ set_auto_create()

void midas::odb::set_auto_create ( bool  f)
inline

Definition at line 1215 of file odbxx.h.

1215 {
1218 }
void set_flags_recursively(uint32_t f)
Definition odbxx.cxx:142
Here is the call graph for this function:

◆ set_auto_enlarge_array()

void midas::odb::set_auto_enlarge_array ( bool  f)
inline

Definition at line 1221 of file odbxx.h.

Here is the call graph for this function:

◆ set_auto_refresh_read()

void midas::odb::set_auto_refresh_read ( bool  f)
inline

Definition at line 1200 of file odbxx.h.

Here is the call graph for this function:

◆ set_auto_refresh_write()

void midas::odb::set_auto_refresh_write ( bool  f)
inline

Definition at line 1206 of file odbxx.h.

Here is the call graph for this function:

◆ set_debug()

static void midas::odb::set_debug ( bool  flag)
inlinestatic

Definition at line 1239 of file odbxx.h.

1239{ s_debug = flag; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_deleted()

void midas::odb::set_deleted ( bool  f)
inlineprivate

Definition at line 517 of file odbxx.h.

Here is the caller graph for this function:

◆ set_dirty()

void midas::odb::set_dirty ( bool  f)
inline

Definition at line 1212 of file odbxx.h.

1212{ m_flags[odb_flags::DIRTY] = f; }

◆ set_flags()

void midas::odb::set_flags ( uint32_t  f)
inlineprivate

Definition at line 513 of file odbxx.h.

513{ m_flags = f; }

◆ set_flags_recursively()

void midas::odb::set_flags_recursively ( uint32_t  f)
private

Definition at line 142 of file odbxx.cxx.

142 {
143 m_flags = f;
144 if (m_tid == TID_KEY) {
145 for (int i = 0; i < m_num_values; i++)
146 m_data[i].get_odb().set_flags_recursively(f);
147 }
148 }
Here is the caller graph for this function:

◆ set_hkey()

void midas::odb::set_hkey ( HNDLE  hKey)
inlineprivate

Definition at line 511 of file odbxx.h.

511{ m_hKey = hKey; }

◆ set_last_index()

void midas::odb::set_last_index ( int  i)
inline

Definition at line 956 of file odbxx.h.

956{ m_last_index = i; }
Here is the caller graph for this function:

◆ set_mode()

void midas::odb::set_mode ( int  mode)

Definition at line 1413 of file odbxx.cxx.

1413 {
1414 // set mode of ODB key
1415 // default is MODE_READ | MODE_WRITE | MODE_DELETE
1416
1417 init_hdb();
1418
1419 // set mode in ODB
1421
1423 mthrow("db_set_mode for ODB key \"" + get_full_path() +
1424 "\" returnd error code " + std::to_string(status));
1425
1426 if (s_debug)
1427 std::cout << "Set mode of ODB key \"" + get_full_path() + "\" to " << mode << std::endl;
1428 }
INT db_set_mode(HNDLE hDB, HNDLE hKey, WORD mode, BOOL recurse)
Definition odb.cxx:8027
#define TRUE
Definition midas.h:182
Here is the call graph for this function:

◆ set_name()

void midas::odb::set_name ( std::string  s)
inlineprivate

Definition at line 522 of file odbxx.h.

522{ m_name = s; }
Here is the call graph for this function:

◆ set_num_values()

void midas::odb::set_num_values ( int  n)
inlineprivate

Definition at line 520 of file odbxx.h.

520{ m_num_values = n; }

◆ set_odb()

void midas::odb::set_odb ( odb o,
int  i 
)

Definition at line 1539 of file odbxx.cxx.

1540 {
1541 if (this->is_write_protect())
1542 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1543
1544 if (m_data == nullptr)
1545 m_data = new u_odb[m_num_values];
1546 m_data[i].set_parent(this);
1548 m_data[i].set_odb(o);
1549 }
Here is the call graph for this function:

◆ set_parent()

void midas::odb::set_parent ( midas::odb p)
inlineprivate

Definition at line 524 of file odbxx.h.

524{ m_parent = p; }
Here is the caller graph for this function:

◆ set_preserve_string_size()

void midas::odb::set_preserve_string_size ( bool  f)
inline

Definition at line 1194 of file odbxx.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_string_size()

void midas::odb::set_string_size ( std::string  s,
int  size 
)

Definition at line 1525 of file odbxx.cxx.

1526 {
1527 if (this->is_write_protect())
1528 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1529
1530 m_num_values = 1;
1531 m_tid = TID_STRING;
1532 m_data = new u_odb[1];
1533 m_data[0].set_parent(this);
1534 m_data[0].set_tid(m_tid);
1537 }
void set_preserve_string_size(bool f)
Definition odbxx.h:1194
void set_string_size(std::string s, int size)
Definition odbxx.cxx:1716
Here is the call graph for this function:

◆ set_tid()

void midas::odb::set_tid ( int  tid)
inlineprivate

Definition at line 519 of file odbxx.h.

519{ m_tid = tid; }

◆ set_trigger_hotlink()

void midas::odb::set_trigger_hotlink ( bool  f)
inline

Definition at line 1233 of file odbxx.h.

Here is the call graph for this function:

◆ set_write_protect()

void midas::odb::set_write_protect ( bool  f)
inline

Definition at line 1227 of file odbxx.h.

Here is the call graph for this function:

◆ size()

int midas::odb::size ( )

Definition at line 315 of file odbxx.cxx.

315 {
316 return m_num_values;
317 }
Here is the caller graph for this function:

◆ unwatch()

void midas::odb::unwatch ( )

Definition at line 1474 of file odbxx.cxx.

1475 {
1476 for (int i=0 ; i<(int) g_watchlist.size() ; i++) {
1477 if (g_watchlist[i]->get_hkey() == this->get_hkey()) {
1479 delete g_watchlist[i];
1480 g_watchlist.erase(g_watchlist.begin() + i);
1481 i--;
1482 }
1483 }
1484 }
INT db_unwatch(HNDLE hDB, HNDLE hKey)
Definition odb.cxx:13887
std::vector< midas::odb * > g_watchlist
Definition odbxx.cxx:38
Here is the call graph for this function:

◆ unwatch_all()

void midas::odb::unwatch_all ( )
staticprivate

Definition at line 1486 of file odbxx.cxx.

1487 {
1488 for (int i=0 ; i<(int) g_watchlist.size() ; i++) {
1490 delete g_watchlist[i];
1491 }
1492 g_watchlist.clear();
1493 }
Here is the call graph for this function:

◆ watch()

void midas::odb::watch ( std::function< void(midas::odb &)>  f)

Definition at line 1458 of file odbxx.cxx.

1458 {
1459 if (m_hKey == 0 || m_hKey == -1)
1460 mthrow("watch() called for ODB key \"" + m_name +
1461 "\" which is not connected to ODB");
1462
1463 // create a deep copy of current object in case it
1464 // goes out of scope
1465 midas::odb* ow = new midas::odb(*this);
1466
1467 ow->m_watch_callback = f;
1469
1470 // put object into watchlist
1471 g_watchlist.push_back(ow);
1472 }
static void watch_callback(int hDB, int hKey, int index, void *info)
Definition odbxx.cxx:114
INT db_watch(HNDLE hDB, HNDLE hKey, void(*dispatcher)(INT, INT, INT, void *), void *info)
Definition odb.cxx:13813
Here is the call graph for this function:

◆ watch_callback()

void midas::odb::watch_callback ( int  hDB,
int  hKey,
int  index,
void info 
)
staticprivate

Definition at line 114 of file odbxx.cxx.

114 {
115 midas::odb *po = static_cast<midas::odb *>(info);
116 if (po->m_data == nullptr)
117 mthrow("Callback received for a midas::odb object which went out of scope");
119 if (poh == nullptr) {
120 auto s = db_get_path(hDB, hKey);
121 mthrow("New key \"" + s + "\" has been created in ODB after calling watch()");
122 }
123
124 poh->m_last_index = index;
125 po->m_watch_callback(*poh);
126 poh->m_last_index = -1;
127 }
void ** info
Definition fesimdaq.cxx:41
HNDLE hDB
main ODB handle
Definition mana.cxx:207
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [1/2]

void midas::odb::write ( int  index,
int  str_size 
)

Definition at line 926 of file odbxx.cxx.

926 {
927 if (!is_connected_odb())
928 return;
929
930 if (m_hKey == -1) {
931 // connect un-connected object (crated via XML)
932 std::string path = get_full_path();
933
934 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
935 if (status != DB_SUCCESS)
936 mthrow("Cannot connect key \"" + path + "\" to ODB");
937
938 } else if (m_hKey == 0) {
939 if (is_auto_create()) {
940 std::string to_create = m_name[0] == '/' ? m_name : get_full_path();
941 int status = db_create_key(s_hDB, 0, to_create.c_str(), m_tid);
943 mthrow("Cannot create ODB key \"" + to_create + "\", status =" + std::to_string(status));
944 db_find_key(s_hDB, 0, to_create.c_str(), &m_hKey);
945 if (s_debug) {
946 std::cout << "Created ODB key \"" + to_create + "\"" << std::endl;
947 }
948 // strip path from name
949 if (m_name.find_last_of('/') != std::string::npos)
950 m_name = m_name.substr(m_name.find_last_of('/') + 1);
951 } else
952 mthrow("Write of un-connected ODB key \"" + m_name + "\" not possible");
953 }
954
955 // don't write keys
956 if (m_tid == TID_KEY)
957 return;
958
959 int status{};
960 if (m_tid == TID_STRING || m_tid == TID_LINK) {
961 KEY key;
963 std::string s;
964 m_data[index].get(s);
965 if (m_num_values == 1) {
966 int size = key.item_size;
968 size = s.size() + 1;
969 if (str_size > 0)
970 size = str_size;
971 char *ss = (char *)malloc(size+1);
972 mstrlcpy(ss, s.c_str(), size);
973 if (is_trigger_hotlink())
975 else
977 free(ss);
978 } else {
979 if (key.item_size == 0)
980 key.item_size = s.size() + 1;
981 if (str_size > 0) {
982 if (key.item_size > 0 && key.item_size != str_size) {
983 std::cout << "ODB string size mismatch for \"" << get_full_path() <<
984 "\" (" << key.item_size << " vs " << str_size << "). ODB key recreated."
985 << std::endl;
986 if (is_trigger_hotlink())
987 status = db_set_data(s_hDB, m_hKey, s.c_str(), str_size, 1, m_tid);
988 else
989 status = db_set_data1(s_hDB, m_hKey, s.c_str(), str_size, 1, m_tid);
990 }
992 }
994 }
995 if (s_debug) {
996 if (m_num_values > 1)
997 std::cout << "Set ODB key \"" + get_full_path() + "[" + std::to_string(index) + "]\" = \"" + s
998 + "\"" << std::endl;
999 else
1000 std::cout << "Set ODB key \"" + get_full_path() + "\" = \"" + s + "\""<< std::endl;
1001 }
1002 } else {
1003 u_odb u = m_data[index];
1004 if (m_tid == TID_BOOL) {
1005 u.set_parent(nullptr);
1006 BOOL b = static_cast<bool>(u); // "bool" is only 1 Byte, BOOL is 4 Bytes
1008 } else {
1010 }
1011 if (s_debug) {
1012 std::string s;
1013 u.get(s);
1014 if (m_num_values > 1)
1015 std::cout << "Set ODB key \"" + get_full_path() + "[" + std::to_string(index) + "]\" = " + s
1016 << std::endl;
1017 else
1018 std::cout << "Set ODB key \"" + get_full_path() + "\" = " + s << std::endl;
1019 }
1020 }
1021 if (status != DB_SUCCESS)
1022 mthrow("db_set_data_index for ODB key \"" + get_full_path() +
1023 "\" failed with status " + std::to_string(status));
1024 }
bool is_preserve_string_size() const
Definition odbxx.h:1193
bool is_trigger_hotlink() const
Definition odbxx.h:1232
INT db_set_data(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Definition odb.cxx:7215
INT db_set_data1(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Definition odb.cxx:7313
INT db_set_data_index1(HNDLE hDB, HNDLE hKey, const void *data, INT data_size, INT idx, DWORD type, BOOL bNotify)
Definition odb.cxx:7828
DWORD BOOL
Definition midas.h:105
Here is the call graph for this function:

◆ write() [2/2]

void midas::odb::write ( int  str_size = 0)

Definition at line 1027 of file odbxx.cxx.

1027 {
1028
1029 // check if deleted
1030 if (is_deleted())
1031 mthrow("ODB key \"" + m_name + "\" cannot be written because it has been deleted");
1032
1033 // write subkeys
1034 if (m_tid == TID_KEY) {
1035 for (int i = 0; i < m_num_values; i++)
1036 m_data[i].get_odb().write();
1037 return;
1038 }
1039
1040 if (m_tid == 0 && m_data[0].get_tid() != 0)
1041 m_tid = m_data[0].get_tid();
1042
1044 mthrow("Invalid TID for ODB key \"" + get_full_path() + "\"");
1045
1046 if ((m_hKey == 0 || m_hKey == -1) && !is_auto_create())
1047 mthrow("Writing ODB key \"" + m_name +
1048 "\" is not possible because of invalid key handle");
1049
1050 // if index operator [] returned previously a certain index, write only this one
1051 if (m_last_index != -1) {
1053 m_last_index = -1;
1054 return;
1055 }
1056
1057 if (m_num_values == 1) {
1058 write(0, str_size);
1059 return;
1060 }
1061
1062 if (m_hKey == -1) {
1063 // connect un-connected object (crated via XML)
1064 std::string path = get_full_path();
1065
1066 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
1067 if (status != DB_SUCCESS)
1068 mthrow("Cannot connect key \"" + path + "\" to ODB");
1069
1070 } else if (m_hKey == 0) {
1071 if (is_auto_create()) {
1072 std::string to_create = m_name[0] == '/' ? m_name : get_full_path();
1073 int status = db_create_key(s_hDB, 0, to_create.c_str(), m_tid);
1075 mthrow("Cannot create ODB key \"" + to_create + "\", status" + std::to_string(status));
1076 db_find_key(s_hDB, 0, to_create.c_str(), &m_hKey);
1077 if (s_debug) {
1078 std::cout << "Created ODB key \"" + to_create + "\"" << std::endl;
1079 }
1080 // strip path from name
1081 if (m_name.find_last_of('/') != std::string::npos)
1082 m_name = m_name.substr(m_name.find_last_of('/') + 1);
1083 } else
1084 mthrow("Write of un-connected ODB key \"" + m_name + "\" not possible");
1085 }
1086
1087 int status{};
1088 if (m_tid == TID_STRING || m_tid == TID_LINK) {
1090 KEY key;
1092 if (key.item_size == 0 || key.total_size == 0) {
1093 int size = 1;
1094 for (int i = 0; i < m_num_values; i++) {
1095 std::string d;
1096 m_data[i].get(d);
1097 if ((int) d.size() + 1 > size)
1098 size = d.size() + 1;
1099 }
1100 // round up to multiples of 32
1101 size = (((size - 1) / 32) + 1) * 32;
1102 key.item_size = size;
1104 }
1105 char *str = (char *) malloc(key.item_size * m_num_values);
1106 for (int i = 0; i < m_num_values; i++) {
1107 std::string d;
1108 m_data[i].get(d);
1109 strncpy(str + i * key.item_size, d.c_str(), key.item_size);
1110 }
1111 if (is_trigger_hotlink())
1113 else
1115 free(str);
1116 if (s_debug) {
1117 std::string s;
1118 get(s, true, false);
1119 std::cout << "Set ODB key \"" + get_full_path() +
1120 "[0..." + std::to_string(m_num_values - 1) + "]\" = [" + s + "]" << std::endl;
1121 }
1122 } else {
1123 std::string s;
1124 m_data[0].get(s);
1125 if (is_trigger_hotlink())
1126 status = db_set_data(s_hDB, m_hKey, s.c_str(), s.length() + 1, 1, m_tid);
1127 else
1128 status = db_set_data1(s_hDB, m_hKey, s.c_str(), s.length() + 1, 1, m_tid);
1129 if (s_debug)
1130 std::cout << "Set ODB key \"" + get_full_path() + "\" = " + s << std::endl;
1131 }
1132 } else {
1134 uint8_t *buffer = (uint8_t *) malloc(size);
1135 uint8_t *p = buffer;
1136 for (int i = 0; i < m_num_values; i++) {
1137 if (m_tid == TID_BOOL) {
1138 // bool has 1 Byte, BOOL has 4 Bytes
1139 BOOL b = static_cast<bool>(m_data[i]);
1140 memcpy(p, &b, rpc_tid_size(m_tid));
1141 } else {
1142 memcpy(p, (void*)&m_data[i], rpc_tid_size(m_tid));
1143 }
1144 p += rpc_tid_size(m_tid);
1145 }
1146 if (is_trigger_hotlink())
1148 else
1150 free(buffer);
1151 if (s_debug) {
1152 std::string s;
1153 get(s, false, false);
1154 if (m_num_values > 1)
1155 std::cout << "Set ODB key \"" + get_full_path() + "[0..." + std::to_string(m_num_values - 1) +
1156 "]\" = [" + s + "]" << std::endl;
1157 else
1158 std::cout << "Set ODB key \"" + get_full_path() + "\" = " + s << std::endl;
1159 }
1160 }
1161
1162 if (status != DB_SUCCESS)
1163 mthrow("db_set_data for ODB key \"" + get_full_path() +
1164 "\" failed with status " + std::to_string(status));
1165 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_key()

bool midas::odb::write_key ( std::string &  path,
bool  write_defaults 
)
private

Definition at line 657 of file odbxx.cxx.

657 {
658 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
659 if (status != DB_SUCCESS) {
660 if (m_tid == 0) // auto-create subdir
661 m_tid = TID_KEY;
662 if (m_tid > 0 && m_tid < TID_LAST) {
663 status = db_create_key(s_hDB, 0, path.c_str(), m_tid);
664 if (status != DB_SUCCESS)
665 mthrow("ODB key \"" + path + "\" cannot be created");
666 status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
667 if (status != DB_SUCCESS)
668 mthrow("ODB key \"" + path + "\" not found after creation");
669 if (s_debug) {
670 if (path[0] == '/')
671 std::cout << "Created ODB key \"" + path + "\"" << std::endl;
672 else
673 std::cout << "Created ODB key \"" + get_full_path() + "\"" << std::endl;
674 }
675 } else
676 mthrow("ODB key \"" + path + "\" cannot be found");
677 return true;
678 } else {
679 KEY key;
681 if (status != DB_SUCCESS)
682 mthrow("db_get_key for ODB key \"" + path +
683 "\" failed with status " + std::to_string(status));
684 if (m_tid == 0)
685 m_tid = key.type;
686
687 // check for correct type
688 if (m_tid > 0 && m_tid != (int) key.type) {
689 if (force_write) {
690 // delete and recreate key
691 status = db_delete_key(s_hDB, m_hKey, false);
692 if (status != DB_SUCCESS)
693 mthrow("db_delete_key for ODB key \"" + path +
694 "\" failed with status " + std::to_string(status));
695 status = db_create_key(s_hDB, 0, path.c_str(), m_tid);
696 if (status != DB_SUCCESS)
697 mthrow("ODB key \"" + path + "\" cannot be created");
698 status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
699 if (status != DB_SUCCESS)
700 mthrow("ODB key \"" + path + "\" not found after creation");
701 if (s_debug)
702 std::cout << "Re-created ODB key \"" + get_full_path() << "\" with different type" << std::endl;
703 } else
704 // abort
705 mthrow("ODB key \"" + get_full_path() +
706 "\" has differnt type than specified");
707 } else if (s_debug)
708 std::cout << "Validated ODB key \"" + get_full_path() + "\"" << std::endl;
709
710 return false;
711 }
712 }
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator!= [1/2]

template<typename T >
bool operator!= ( const midas::odb o,
const T &  d 
)
friend

Definition at line 1317 of file odbxx.h.

1317 {
1318 T v;
1319 midas::odb oc(o);
1320 oc.get(v);
1321 return v != d;
1322 }

◆ operator!= [2/2]

template<typename T >
bool operator!= ( const T &  d,
const midas::odb o 
)
friend

Definition at line 1325 of file odbxx.h.

1325 {
1326 T v;
1327 midas::odb oc(o);
1328 oc.get(v);
1329 return d != v;
1330 }

◆ operator< [1/2]

template<typename T >
bool operator< ( const midas::odb o,
const T &  d 
)
friend

Definition at line 1333 of file odbxx.h.

1333 {
1334 T v;
1335 midas::odb oc(o);
1336 oc.get(v);
1337 return v < d;
1338 }

◆ operator< [2/2]

template<typename T >
bool operator< ( const T &  d,
const midas::odb o 
)
friend

Definition at line 1341 of file odbxx.h.

1341 {
1342 T v;
1343 midas::odb oc(o);
1344 oc.get(v);
1345 return d < v;
1346 }

◆ operator<<

std::ostream & operator<< ( std::ostream &  output,
odb o 
)
friend

Definition at line 877 of file odbxx.h.

877 {
878 std::string s;
879 if (o.m_tid == TID_KEY)
880 o.print(s, 0);
881 else
882 o.get(s);
883 output << s;
884 return output;
885 };
static void output(code_int code)
Definition mgd.cxx:1647

◆ operator<= [1/2]

template<typename T >
bool operator<= ( const midas::odb o,
const T &  d 
)
friend

Definition at line 1349 of file odbxx.h.

1349 {
1350 T v;
1351 midas::odb oc(o);
1352 oc.get(v);
1353 return v <= d;
1354 }

◆ operator<= [2/2]

template<typename T >
bool operator<= ( const T &  d,
const midas::odb o 
)
friend

Definition at line 1357 of file odbxx.h.

1357 {
1358 T v;
1359 midas::odb oc(o);
1360 oc.get(v);
1361 return d <= v;
1362 }

◆ operator== [1/2]

template<typename T >
bool operator== ( const midas::odb o,
const T &  d 
)
friend

Definition at line 1299 of file odbxx.h.

1299 {
1300 // the operator needs a "const midas::odb" reference,
1301 // so we have to make a non-const copy
1302 T v;
1303 midas::odb oc(o);
1304 oc.get(v);
1305 return v == d;
1306 }

◆ operator== [2/2]

template<typename T >
bool operator== ( const T &  d,
const midas::odb o 
)
friend

Definition at line 1309 of file odbxx.h.

1309 {
1310 T v;
1311 midas::odb oc(o);
1312 oc.get(v);
1313 return d == v;
1314 }

◆ operator> [1/2]

template<typename T >
bool operator> ( const midas::odb o,
const T &  d 
)
friend

Definition at line 1365 of file odbxx.h.

1365 {
1366 T v;
1367 midas::odb oc(o);
1368 oc.get(v);
1369 return v > d;
1370 }

◆ operator> [2/2]

template<typename T >
bool operator> ( const T &  d,
const midas::odb o 
)
friend

Definition at line 1373 of file odbxx.h.

1373 {
1374 T v;
1375 midas::odb oc(o);
1376 oc.get(v);
1377 return d > v;
1378 }

◆ operator>= [1/2]

template<typename T >
bool operator>= ( const midas::odb o,
const T &  d 
)
friend

Definition at line 1381 of file odbxx.h.

1381 {
1382 T v;
1383 midas::odb oc(o);
1384 oc.get(v);
1385 return v >= d;
1386 }

◆ operator>= [2/2]

template<typename T >
bool operator>= ( const T &  d,
const midas::odb o 
)
friend

Definition at line 1389 of file odbxx.h.

1389 {
1390 T v;
1391 midas::odb oc(o);
1392 oc.get(v);
1393 return d >= v;
1394 }

Member Data Documentation

◆ m_data

u_odb* midas::odb::m_data
private

Definition at line 451 of file odbxx.h.

◆ m_flags

std::bitset<9> midas::odb::m_flags
private

Definition at line 447 of file odbxx.h.

◆ m_hKey

HNDLE midas::odb::m_hKey
private

Definition at line 459 of file odbxx.h.

◆ m_last_index

int midas::odb::m_last_index
private

Definition at line 457 of file odbxx.h.

◆ m_name

std::string midas::odb::m_name
private

Definition at line 453 of file odbxx.h.

◆ m_num_values

int midas::odb::m_num_values
private

Definition at line 455 of file odbxx.h.

◆ m_parent

midas::odb* midas::odb::m_parent
private

Definition at line 463 of file odbxx.h.

◆ m_tid

int midas::odb::m_tid
private

Definition at line 449 of file odbxx.h.

◆ m_watch

std::vector<midas::odb> midas::odb::m_watch
staticprivate

Definition at line 444 of file odbxx.h.

◆ m_watch_callback

std::function<void(midas::odb &)> midas::odb::m_watch_callback
private

Definition at line 461 of file odbxx.h.

◆ s_connected_odb

bool midas::odb::s_connected_odb = false
staticprivate

Definition at line 442 of file odbxx.h.

◆ s_debug

bool midas::odb::s_debug = false
staticprivate

Definition at line 440 of file odbxx.h.

◆ s_hDB

HNDLE midas::odb::s_hDB = 0
staticprivate

Definition at line 438 of file odbxx.h.


The documentation for this class was generated from the following files: