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

#include <odbxx.h>

Collaboration diagram for midas::odb:

Classes

class  iterator
 

Public Types

enum  odb_source { ONLINE = 0 , STRING , FILE }
 

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 &path, 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)
 
std::string node_to_string (const MJsonNode *node)
 
midas::odbodb_from_json (const MJsonNode *node, std::string name, int tid, 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_remote (const std::string &str)
 
void odb_from_xml_string (const std::string &str, const std::string &subkey)
 
void odb_from_json_string (const std::string &str, const std::string &subkey)
 
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 odb::odb_source get_odb_source ()
 
static void set_odb_source (odb::odb_source s)
 
static void set_odb_source (odb::odb_source s, std::string str)
 
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 thread_local odb_source s_odb_source = odb::ONLINE
 
static thread_local std::string s_odb_source_str = std::string("")
 
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 410 of file odbxx.h.

Member Enumeration Documentation

◆ odb_source

Enumerator
ONLINE 
STRING 
FILE 

Definition at line 413 of file odbxx.h.

413 {
414 ONLINE = 0,
415 STRING,
416 FILE
417 };

Constructor & Destructor Documentation

◆ odb() [1/10]

midas::odb::odb ( )
inline

Definition at line 542 of file odbxx.h.

542 :
548 m_tid{0},
549 m_data{nullptr},
550 m_name{},
551 m_num_values{0},
552 m_last_index{-1},
553 m_hKey{},
554 m_parent{} {}
int m_num_values
Definition odbxx.h:467
int m_tid
Definition odbxx.h:461
u_odb * m_data
Definition odbxx.h:463
int m_last_index
Definition odbxx.h:469
std::bitset< 9 > m_flags
Definition odbxx.h:459
HNDLE m_hKey
Definition odbxx.h:471
std::string m_name
Definition odbxx.h:465
midas::odb * m_parent
Definition odbxx.h:475
@ AUTO_REFRESH_WRITE
Definition odbxx.h:395
@ TRIGGER_HOTLINK
Definition odbxx.h:402
@ AUTO_REFRESH_READ
Definition odbxx.h:394
@ AUTO_ENLARGE_ARRAY
Definition odbxx.h:398
@ AUTO_CREATE
Definition odbxx.h:397

◆ ~odb()

midas::odb::~odb ( )
inline

Definition at line 557 of file odbxx.h.

557 {
558 delete[] m_data;
559 }

◆ odb() [2/10]

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

Definition at line 364 of file odbxx.cxx.

364 : odb() {
365 m_tid = o.m_tid;
366 m_name = o.m_name;
367 m_num_values = o.m_num_values;
368 m_hKey = o.m_hKey;
369 m_watch_callback = o.m_watch_callback;
371 for (int i = 0; i < m_num_values; i++) {
373 m_data[i].set_parent(this);
374 if (m_tid == TID_STRING || m_tid == TID_LINK) {
375 // set_string() creates a copy of our string
376 m_data[i].set_string(o.m_data[i]);
377 } else if (m_tid == TID_KEY) {
378 // recursive call to create a copy of the odb object
380 midas::odb *pc = new midas::odb(*po);
381 pc->set_parent(this);
382 m_data[i].set(pc);
383 } else {
384 // simply pass basic types
385 m_data[i] = o.m_data[i];
386 m_data[i].set_parent(this);
387 }
388 }
389 }
std::function< void(midas::odb &)> m_watch_callback
Definition odbxx.h:473
void set_tid(int tid)
Definition odbxx.h:105
void set_string(std::string s)
Definition odbxx.h:172
void set(T v)
Definition odbxx.h:142
void set_parent(odb *o)
Definition odbxx.h:102
odb * get_podb()
Definition odbxx.h:369
#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 569 of file odbxx.h.

569 :odb() {
570 m_num_values = 1;
571 m_data = new u_odb[1]{v};
572 m_tid = m_data[0].get_tid();
573 m_data[0].set_parent(this);
574 }
int get_tid()
Definition odbxx.h:107
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 577 of file odbxx.h.

577 : odb() {
578 m_tid = TID_KEY;
579 m_num_values = list.size();
580 m_data = new u_odb[m_num_values];
581 int i = 0;
582 for (auto &element: list) {
583 // check if name exists already
584 for (int j=0 ; j<i ; j++) {
585 if (strcasecmp(element.first, m_data[j].get_odb().get_name().c_str()) == 0) {
586 if (element.first == m_data[j].get_odb().get_name().c_str()) {
587 mthrow("ODB key with name \"" + m_data[j].get_odb().get_name() + "\" exists already");
588 } else {
589 mthrow("ODB key \"" + std::string(element.first) + "\" exists already as \"" +
590 m_data[j].get_odb().get_name() + "\" (only case differs)");
591 }
592 }
593 }
594 auto o = new midas::odb(element.second);
595 o->set_name(element.first);
596 o->set_parent(this);
598 m_data[i].set_parent(this);
599 m_data[i].set(o);
600 i++;
601 }
602 }
std::string get_name()
Definition odbxx.h:1455
odb & get_odb()
Definition odbxx.h:375
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 606 of file odbxx.h.

606 : odb() {
607 m_num_values = list.size();
608 m_data = new u_odb[m_num_values]{};
609 int i = 0;
610 for (auto &element : list) {
611 u_odb u(element);
612 m_data[i].set_tid(u.get_tid());
613 m_data[i].set_parent(this);
615 i++;
616 }
617 m_tid = m_data[0].get_tid();
618 }
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 622 of file odbxx.h.

622 : odb() {
624 m_data = new u_odb[m_num_values]{};
625 for (int i = 0; i < (int)SIZE; i++) {
626 u_odb u(arr[i]);
627 m_data[i].set_tid(u.get_tid());
628 m_data[i].set_parent(this);
629 m_data[i].set(arr[i]);
630 }
631 m_tid = m_data[0].get_tid();
632 }
#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 636 of file odbxx.h.

636 : odb() {
638 m_data = new u_odb[m_num_values]{};
639 for (int i = 0; i < (int)SIZE; i++) {
640 std::string * mystring = new std::string(arr[i]);
641 u_odb u(mystring);
642 m_data[i].set_tid(u.get_tid());
643 m_data[i].set_parent(this);
644 m_data[i].set(arr[i]);
645 }
646 m_tid = m_data[0].get_tid();
647 }
Here is the call graph for this function:

◆ odb() [8/10]

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

Definition at line 650 of file odbxx.h.

650 : odb() {
651 if (path[0] == '/') {
652 // ODB path
653 if (s_odb_source == ONLINE) {
654 if (init_via_xml) {
655 if (!exists(path))
656 odb::create(path.c_str(), TID_KEY);
658 } else {
659 if (!read_key(path))
660 // create subdir if key does not exist
661 odb::create(path.c_str(), TID_KEY);
662
663 if (!read_key(path))
664 mthrow("ODB key \"" + path + "\" not found in ODB");
665
666 if (m_tid != TID_KEY)
667 read();
668 }
669 } else if (s_odb_source == STRING) {
670
671 if (s_odb_source_str.substr(0, 19) == "<?xml version=\"1.0\"")
673 else if (s_odb_source_str.substr(0, 1) == "{")
675 else
676 mthrow("Unknown string format: \"" + s_odb_source_str + "\"");
677
678 } else if (s_odb_source == FILE) {
679
680 // create odb from file
681 std::ifstream file(s_odb_source_str);
682 if (!file)
683 mthrow("File \"" + s_odb_source_str + "\" not found");
684 std::ostringstream ss;
685 ss << file.rdbuf();
686 file.close();
687
688 if (s_odb_source_str.find(".xml") != std::string::npos ||
689 s_odb_source_str.find(".XML") != std::string::npos)
690 odb_from_xml_string(ss.str(), path);
691 else if (s_odb_source_str.find(".json") != std::string::npos ||
692 s_odb_source_str.find(".JSON") != std::string::npos)
693 odb_from_json_string(ss.str(), path);
694 else
695 mthrow("File type of \"" +s_odb_source_str + "\" is not supported");
696
697 } else
698 mthrow("Unknown ODB source: " + std::to_string(s_odb_source));
699
700 } else {
701 // simple string
702
703 // Construct object from initializer_list
704 m_num_values = 1;
705 m_data = new u_odb[1]{new std::string{path}};
706 m_tid = m_data[0].get_tid();
707 m_data[0].set_parent(this);
708 }
709 }
static bool exists(const std::string &name)
Definition odbxx.cxx:75
bool read_key(const std::string &path)
Definition odbxx.cxx:710
static thread_local odb_source s_odb_source
Definition odbxx.h:447
void odb_from_xml_remote(const std::string &str)
Definition odbxx.cxx:159
static thread_local std::string s_odb_source_str
Definition odbxx.h:448
void odb_from_xml_string(const std::string &str, const std::string &subkey)
Definition odbxx.cxx:198
void read()
Definition odbxx.cxx:855
void odb_from_json_string(const std::string &str, const std::string &subkey)
Definition odbxx.cxx:259
static int create(const char *name, int type=TID_KEY)
Definition odbxx.cxx:139
Here is the call graph for this function:

◆ odb() [9/10]

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

Definition at line 712 of file odbxx.h.

712 : odb(std::string(s)) {
713 }
std::string s()
Definition odbxx.h:1458

◆ odb() [10/10]

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

Definition at line 716 of file odbxx.h.

716 : odb() {
717 m_num_values = list.size();
718 m_data = new u_odb[m_num_values]{};
719 int i = 0;
720 for (auto &element : list) {
722 m_data[i].set_parent(this);
724 i++;
725 }
726 m_tid = m_data[0].get_tid();
727 }
Here is the call graph for this function:

Member Function Documentation

◆ begin()

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

Definition at line 1003 of file odbxx.h.

1003{ 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 1430 of file odbxx.cxx.

1430 {
1431 init_hdb();
1432
1433 if (!name.empty())
1434 m_name = name;
1435 std::string path(p);
1436
1437 if (path.empty())
1438 mthrow("odb::connect() cannot be called with an empty ODB path");
1439
1440 if (path[0] != '/')
1441 mthrow("odb::connect(\"" + path + "\"): path must start with leading \"/\"");
1442
1443 if (path.back() != '/')
1444 path += "/";
1445
1446 path += m_name;
1447
1448 HNDLE hKey;
1449 int status = db_find_key(s_hDB, 0, path.c_str(), &hKey);
1450 bool key_exists = (status == DB_SUCCESS);
1451 bool created = false;
1452
1454 // Recurse down to delete keys as needed.
1455 // We need to do this recursively BEFORE calling read/read_key for the first time
1456 // to ensure that subdirectories get handled correctly.
1458 }
1459
1460 if (!key_exists || write_defaults) {
1462 } else {
1463 read_key(path);
1464 }
1465
1466 // correct wrong parent ODB from initializer_list
1467 for (int i = 0; i < m_num_values; i++)
1468 m_data[i].set_parent(this);
1469
1470 if (m_tid == TID_KEY) {
1471 for (int i = 0; i < m_num_values; i++)
1472 m_data[i].get_odb().connect(get_full_path(), m_data[i].get_odb().get_name(), write_defaults);
1473 } else if (created || write_defaults) {
1474 write();
1475 } else {
1476 read();
1477 }
1478 }
std::string get_full_path()
Definition odbxx.cxx:419
static HNDLE s_hDB
Definition odbxx.h:450
static void init_hdb()
Definition odbxx.cxx:49
bool write_key(std::string &path, bool write_defaults)
Definition odbxx.cxx:796
void set_parent(midas::odb *p)
Definition odbxx.h:536
#define DB_SUCCESS
Definition midas.h:631
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4084
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:1306
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 1481 of file odbxx.cxx.

1481 {
1482
1483 if (str.empty())
1484 mthrow("odb::connect() cannot be called with an empty ODB path");
1485
1486 if (str[0] != '/')
1487 mthrow("odb::connect(\"" + str + "\"): path must start with leading \"/\"");
1488
1489 if (str == "/")
1490 mthrow("odb::connect(\"" + str + "\"): root ODB tree is not allowed");
1491
1492 if (str.back() == '/')
1493 str = str.substr(0, str.size()-1);
1494
1495 // separate ODB path and key nam
1496 std::string name;
1497 std::string path;
1498 name = str.substr(str.find_last_of('/') + 1);
1499 path = str.substr(0, str.find_last_of('/') + 1);
1500
1502 }
void connect(const std::string &path, const std::string &name, bool write_defaults, bool delete_keys_not_in_defaults=false)
Definition odbxx.cxx:1430
char str[256]
Definition odbhist.cxx:33
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 1509 of file odbxx.cxx.

1509 {
1510 // Store the order the user specified.
1511 // Need to do this recursively before calling connect(), as the first
1512 // read() in that function merges user keys and existing keys.
1513 std::map<std::string, std::vector<std::string> > user_order;
1515
1516 // Main connect() that adds/deletes/updates keys as needed.
1517 connect(path, false, true);
1518
1519 // Fix order in ODB (and memory)
1521 }
void recurse_fix_order(midas::odb &default_odb, std::map< std::string, std::vector< std::string > > &user_order)
Definition odbxx.cxx:1353
void recurse_get_defaults_order(std::string path, midas::odb &default_odb, std::map< std::string, std::vector< std::string > > &retval)
Definition odbxx.cxx:1343
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 139 of file odbxx.cxx.

139 {
140 init_hdb();
141 int status = -1;
142 if (is_connected_odb())
145 mthrow("Cannot create key " + std::string(name) + ", db_create_key() status = " + std::to_string(status));
146 return status;
147 }
static bool is_connected_odb()
Definition odbxx.h:1427
#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:3313
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 391 of file odbxx.cxx.

391 {
392 d.m_tid = s.m_tid;
393 d.m_name = s.m_name;
394 d.m_num_values = s.m_num_values;
395 d.m_hKey = s.m_hKey;
396 d.m_watch_callback = s.m_watch_callback;
397 d.m_data = new midas::u_odb[d.m_num_values]{};
398 for (int i = 0; i < d.m_num_values; i++) {
399 d.m_data[i].set_tid(d.m_tid);
400 d.m_data[i].set_parent(&d);
401 if (d.m_tid == TID_STRING || d.m_tid == TID_LINK) {
402 // set_string() creates a copy of our string
403 d.m_data[i].set_string(s.m_data[i]);
404 } else if (d.m_tid == TID_KEY) {
405 // recursive call to create a copy of the odb object
407 midas::odb *pc = new midas::odb(*po);
408 pc->set_parent(&d);
409 d.m_data[i].set(pc);
410 } else {
411 // simply pass basic types
412 d.m_data[i] = s.m_data[i];
413 d.m_data[i].set_parent(this);
414 }
415 }
416 }
double d
Definition system.cxx:1313
Here is the call graph for this function:

◆ delete_key() [1/2]

void midas::odb::delete_key ( )

Definition at line 1523 of file odbxx.cxx.

1523 {
1524 init_hdb();
1525
1527
1528 if (this->is_write_protect())
1529 mthrow("Cannot modify write protected key \"" + m_name + "\"");
1530
1531
1532 // delete key in ODB
1534 if (status != DB_SUCCESS && status != DB_INVALID_HANDLE)
1535 mthrow("db_delete_key for ODB key \"" + m_name +
1536 "\" returnd error code " + std::to_string(status));
1537
1538 if (s_debug)
1539 std::cout << "Deleted ODB key \"" + m_name + "\"" << std::endl;
1540
1541 // invalidate this object
1542 delete[] m_data;
1543 m_data = nullptr;
1544 m_num_values = 0;
1545 m_tid = 0;
1546 m_hKey = 0;
1547
1548 // set flag that this object has been deleted
1549 set_deleted(true);
1550 }
#define FALSE
Definition cfortran.h:309
static bool s_debug
Definition odbxx.h:452
void set_deleted(bool f)
Definition odbxx.h:529
bool is_write_protect() const
Definition odbxx.h:1373
#define DB_INVALID_HANDLE
Definition midas.h:635
INT db_delete_key(HNDLE hDB, HNDLE hKey, BOOL follow_links)
Definition odb.cxx:3861
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 84 of file odbxx.cxx.

84 {
85 init_hdb();
87 return false;
88 HNDLE hkey;
89 auto status = db_find_key(s_hDB, 0, name.c_str(), &hkey);
90 if (status != DB_SUCCESS) {
91 if (s_debug)
92 std::cout << "Delete key " + name << " not found in ODB" << std::endl;
93 return status;
94 }
95 if (s_debug)
96 std::cout << "Delete ODB key " + name << std::endl;
97 return db_delete_key(s_hDB, hkey, false);
98 }
Here is the call graph for this function:

◆ detect_type()

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

Definition at line 730 of file odbxx.h.

730 {
731 if (std::is_same<T, uint8_t>::value)
732 return TID_UINT8;
733 else if (std::is_same<T, int8_t>::value)
734 return TID_INT8;
735 else if (std::is_same<T, uint16_t>::value)
736 return TID_UINT16;
737 else if (std::is_same<T, int16_t>::value)
738 return TID_INT16;
739 else if (std::is_same<T, uint32_t>::value)
740 return TID_UINT32;
741 else if (std::is_same<T, unsigned long>::value && sizeof(long) == 4)
742 return TID_UINT32;
743 else if (std::is_same<T, int32_t>::value)
744 return TID_INT32;
745 else if (std::is_same<T, long>::value && sizeof(long) == 4)
746 return TID_INT32;
747 else if (std::is_same<T, uint64_t>::value)
748 return TID_UINT64;
749 else if (std::is_same<T, unsigned long>::value && sizeof(long) == 8)
750 return TID_UINT64;
751 else if (std::is_same<T, int64_t>::value)
752 return TID_INT64;
753 else if (std::is_same<T, long>::value && sizeof(long) == 8)
754 return TID_INT64;
755 else if (std::is_same<T, bool>::value)
756 return TID_BOOL;
757 else if (std::is_same<T, float>::value)
758 return TID_FLOAT;
759 else if (std::is_same<T, double>::value)
760 return TID_DOUBLE;
761 else
762 return TID_STRING;
763 }
#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 484 of file odbxx.cxx.

484 {
485 std::string s;
486 s = "{\n";
487 dump(s, 1);
488 s += "\n}";
489 return s;
490 }
std::string dump()
Definition odbxx.cxx:484
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 526 of file odbxx.cxx.

526 {
527 if (m_name != "root")
528 for (int i = 0; i < indent; i++)
529 s += " ";
530 if (m_tid == TID_KEY) {
531 if (m_name == "root")
532 indent--;
533 else {
534 s += "\"" + m_name + "\": {\n";
535 }
536 for (int i = 0; i < m_num_values; i++) {
537 std::string v;
538 m_data[i].get_odb().dump(v, indent + 1);
539 s += v;
540 if (i < m_num_values - 1)
541 s += ",\n";
542 else
543 s += "\n";
544 }
545 if (m_name != "root") {
546 for (int i = 0; i < indent; i++)
547 s += " ";
548 s += "}";
549 }
550 } else {
551 KEY key;
553 s += "\"" + m_name + "/key\": ";
554 s += "{ \"type\": " + std::to_string(m_tid) + ", ";
555 s += "\"access_mode\": " + std::to_string(key.access_mode) + ", ";
556 s += "\"last_written\": " + std::to_string(key.last_written) + "},\n";
557 for (int i = 0; i < indent; i++)
558 s += " ";
559 s += "\"" + m_name + "\": ";
560 if (m_num_values > 1)
561 s += "[";
562 std::string v;
563 get(v, m_tid == TID_STRING || m_tid == TID_LINK);
564 s += v;
565 if (m_num_values > 1)
566 s += "]";
567 }
568 }
T get()
Definition odbxx.h:492
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
Definition odb.cxx:6024
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 1004 of file odbxx.h.

1004{ return iterator(m_data + m_num_values); }

◆ exists()

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

Definition at line 75 of file odbxx.cxx.

75 {
76 init_hdb();
78 return false;
79 HNDLE hkey;
80 return db_find_key(s_hDB, 0, name.c_str(), &hkey) == DB_SUCCESS;
81 }
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 1367 of file odbxx.cxx.

1367 {
1368 // Fix the order of ODB keys to match that specified in target_order.
1369 // The in-ODB representation is simple, as we can just use db_reorder_key()
1370 // on anything that's in the wrong place.
1371 // The in-memory representation is a little trickier, but we just copy raw
1372 // memory into a temporary array, so we don't have to delete/recreate the
1373 // u_odb objects.
1374 std::vector<std::string> curr_order;
1375
1376 if (get_subkeys(curr_order) <= 0) {
1377 // Not a TID_KEY (or no keys)
1378 return;
1379 }
1380
1381 if (target_order.size() != curr_order.size() || (int)target_order.size() != m_num_values) {
1382 return;
1383 }
1384
1385 HNDLE hKey = get_hkey();
1386 bool force_order = false;
1387
1388 // Temporary location where we'll store in-memory u_odb objects in th
1389 // correct order.
1390 u_odb* new_m_data = new u_odb[m_num_values];
1391
1392 for (int i = 0; i < m_num_values; i++) {
1393 if (force_order || curr_order[i] != target_order[i]) {
1394 force_order = true;
1395 HNDLE hSubKey;
1396
1397 // Fix the order in the ODB
1400 }
1401
1402 // Fix the order in memory
1403 auto curr_it = std::find(curr_order.begin(), curr_order.end(), target_order[i]);
1404
1405 if (curr_it == curr_order.end()) {
1406 // Logic error - bail to avoid doing any damage to the in-memory version.
1407 delete[] new_m_data;
1408 return;
1409 }
1410
1411 int curr_idx = curr_it - curr_order.begin();
1413 }
1414
1415 // Final update of the in-memory version so they are in the correct order
1416 for (int i = 0; i < m_num_values; i++) {
1417 m_data[i] = new_m_data[i];
1418
1419 // Nullify pointers that point to the same object in
1420 // m_data and new_m_data, so the underlying object doesn't
1421 // get destroyed when we delete new_m_data.
1422 new_m_data[i].set_string_ptr(nullptr);
1423 new_m_data[i].set_odb(nullptr);
1424 }
1425
1426 delete[] new_m_data;
1427 }
HNDLE get_hkey()
Definition odbxx.h:1450
int get_subkeys(std::vector< std::string > &name)
Definition odbxx.cxx:685
void set_string_ptr(std::string *s)
Definition odbxx.h:179
INT db_reorder_key(HNDLE hDB, HNDLE hKey, INT idx)
Definition odb.cxx:6366
Here is the call graph for this function:

◆ get() [1/3]

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

Definition at line 492 of file odbxx.h.

492 {
493 if (m_num_values > 1)
494 mthrow("ODB key \"" + get_full_path() +
495 "[0..." + std::to_string(m_num_values - 1) +
496 "]\" contains array. Please assign to std::vector.");
498 read();
499 return (T) m_data[0];
500 }
bool is_auto_refresh_read() const
Definition odbxx.h:1346
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 342 of file odbxx.cxx.

342 {
343 if (refresh && is_auto_refresh_read())
344 read();
345
346 // put value into quotes
347 s = "";
348 std::string sd;
349 for (int i = 0; i < m_num_values; i++) {
350 m_data[i].get(sd);
351 if (quotes)
352 s += "\"";
353 s += sd;
354 if (quotes)
355 s += "\"";
356 if (i < m_num_values - 1)
357 s += ",";
358 }
359 }
Here is the call graph for this function:

◆ get() [3/3]

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

Definition at line 504 of file odbxx.h.

504 {
505 if (m_num_values > 1)
506 mthrow("ODB key \"" + get_full_path() + "\" contains array. Please assign to std::vector.");
508 read();
509 v = (T) m_data[0];
510 }
Here is the call graph for this function:

◆ get_debug()

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

Definition at line 1387 of file odbxx.h.

1387{ return s_debug; }

◆ get_flags()

uint32_t midas::odb::get_flags ( )
inlineprivate

Definition at line 526 of file odbxx.h.

526{ 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 419 of file odbxx.cxx.

419 {
420 if (m_name[0] == '/')
421 return m_name;
422 if (m_parent)
423 return m_parent->get_full_path() + "/" + m_name;
424
425 if (!is_connected_odb() || m_hKey == -1)
426 return m_name;
427
428 std::string str = db_get_path(s_hDB, m_hKey);
429 if (str == "/") // change "/" to ""
430 str = "";
431 return str;
432 }
INT db_get_path(HNDLE hDB, HNDLE hKey, char *path, INT buf_size)
Definition odb.cxx:4995
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 1450 of file odbxx.h.

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

◆ get_last_index()

int midas::odb::get_last_index ( )
inline

Definition at line 999 of file odbxx.h.

999{ return m_last_index; }

◆ get_last_written()

unsigned int midas::odb::get_last_written ( )

Definition at line 1583 of file odbxx.cxx.

1583 {
1584 init_hdb();
1585
1586 // set mode in ODB
1587 KEY key;
1588 int status = db_get_key(s_hDB, m_hKey, &key);
1589
1591 mthrow("db_get_key for ODB key \"" + get_full_path() +
1592 "\" returnd error code " + std::to_string(status));
1593
1594 return (unsigned int) (key.last_written);
1595 }
Here is the call graph for this function:

◆ get_mdata()

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

Definition at line 516 of file odbxx.h.

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

◆ get_mode()

int midas::odb::get_mode ( )

Definition at line 1569 of file odbxx.cxx.

1569 {
1570 init_hdb();
1571
1572 // set mode in ODB
1573 KEY key;
1574 int status = db_get_key(s_hDB, m_hKey, &key);
1575
1577 mthrow("db_get_key for ODB key \"" + get_full_path() +
1578 "\" returnd error code " + std::to_string(status));
1579
1580 return key.access_mode;
1581 }
Here is the call graph for this function:

◆ get_name()

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

Definition at line 1455 of file odbxx.h.

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

◆ get_num_values()

int midas::odb::get_num_values ( )
inline

Definition at line 1454 of file odbxx.h.

1454{ return m_num_values; }

◆ get_odb_source()

static odb::odb_source midas::odb::get_odb_source ( )
inlinestatic

Definition at line 1400 of file odbxx.h.

1400{ return s_odb_source; }

◆ get_parent()

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

Definition at line 537 of file odbxx.h.

537{ return m_parent; }

◆ get_parent_path()

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

Definition at line 435 of file odbxx.cxx.

435 {
436 std::string s = get_full_path();
437 std::size_t i = s.find_last_of("/");
438 s = s.substr(0, i);
439 return s;
440 }
Here is the call graph for this function:

◆ get_subkey()

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

Definition at line 621 of file odbxx.cxx.

621 {
622 if (m_tid == 0) {
623 if (is_auto_create()) {
624 m_tid = TID_KEY;
625 int status = db_create_key(s_hDB, 0, m_name.c_str(), m_tid);
627 mthrow("Cannot create ODB key \"" + m_name + "\", status" + std::to_string(status));
628 db_find_key(s_hDB, 0, m_name.c_str(), &m_hKey);
629 if (s_debug) {
630 if (m_name[0] == '/')
631 std::cout << "Created ODB key \"" + m_name + "\"" << std::endl;
632 else
633 std::cout << "Created ODB key \"" + get_full_path() + "\"" << std::endl;
634 }
635 // strip path from name
636 if (m_name.find_last_of('/') != std::string::npos)
637 m_name = m_name.substr(m_name.find_last_of('/') + 1);
638 } else
639 mthrow("Invalid key \"" + m_name + "\" does not have subkeys");
640
641 }
642 if (m_tid != TID_KEY)
643 mthrow("ODB key \"" + get_full_path() + "\" does not have subkeys");
644
645 std::string first = str;
646 std::string tail{};
647 if (str.find('/') != std::string::npos) {
648 first = str.substr(0, str.find('/'));
649 tail = str.substr(str.find('/') + 1);
650 }
651
652 int i;
653 for (i = 0; i < m_num_values; i++)
654 if (equal_ustring(first.c_str(), m_data[i].get_odb().get_name().c_str()))
655 break;
656 if (i == m_num_values) {
657 if (is_auto_create()) {
658 if (m_num_values == 0) {
659 m_num_values = 1;
660 m_data = new u_odb[1]{};
661 i = 0;
662 } else {
663 // resize array
665 i = m_num_values - 1;
666 }
667 midas::odb *o = new midas::odb();
669 m_data[i].set_parent(this);
670 o->set_name(get_full_path() + "/" + str);
671 o->set_tid(0); // tid is currently undefined
672 o->set_flags(get_flags());
673 o->set_parent(this);
674 m_data[i].set(o);
675 } else
676 mthrow("ODB key \"" + get_full_path() + "\" does not contain subkey \"" + first + "\"");
677 }
678 if (!tail.empty())
679 return m_data[i].get_odb().get_subkey(tail);
680
681 return *m_data[i].get_podb();
682 }
bool is_auto_create() const
Definition odbxx.h:1361
void resize_mdata(int size)
Definition odbxx.cxx:318
odb & get_subkey(std::string str)
Definition odbxx.cxx:621
uint32_t get_flags()
Definition odbxx.h:526
#define DB_CREATED
Definition midas.h:632
BOOL equal_ustring(const char *str1, const char *str2)
Definition odb.cxx:3206
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 685 of file odbxx.cxx.

685 {
686 if (m_tid != TID_KEY)
687 return 0;
688 if (m_hKey == 0 || m_hKey == -1)
689 mthrow("get_sub-keys called with invalid m_hKey for ODB key \"" + m_name + "\"");
690
691 // count number of subkeys in ODB
692 std::vector<HNDLE> hlist;
693 int n = 0;
694 for (int i = 0;; i++) {
695 HNDLE h;
696 int status = db_enum_key(s_hDB, m_hKey, i, &h);
697 if (status != DB_SUCCESS)
698 break;
699 KEY key;
700 db_get_key(s_hDB, h, &key);
701 hlist.push_back(h);
702 name.push_back(key.name);
703 n = i + 1;
704 }
705
706 return n;
707 }
INT db_enum_key(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
Definition odb.cxx:5591
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 1453 of file odbxx.h.

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

◆ init_hdb()

void midas::odb::init_hdb ( )
staticprivate

Definition at line 49 of file odbxx.cxx.

49 {
51 mthrow("Operation only possible if connected to an online ODB");
52
53 if (s_hDB == 0)
55 if (s_hDB == 0)
56 mthrow("Please call cm_connect_experiment() before accessing the ODB");
57 s_connected_odb = true;
58 }
static bool s_connected_odb
Definition odbxx.h:454
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
Definition midas.cxx:3025
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 1361 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 1367 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 1346 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 1352 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 1427 of file odbxx.h.

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

◆ is_deleted()

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

Definition at line 528 of file odbxx.h.

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

◆ is_dirty()

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

Definition at line 1358 of file odbxx.h.

1358{ return m_flags[odb_flags::DIRTY]; }
@ DIRTY
Definition odbxx.h:399

◆ is_preserve_string_size()

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

Definition at line 1340 of file odbxx.h.

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

◆ is_subkey()

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

Definition at line 597 of file odbxx.cxx.

597 {
598 if (m_tid != TID_KEY)
599 return false;
600
601 std::string first = str;
602 std::string tail{};
603 if (str.find('/') != std::string::npos) {
604 first = str.substr(0, str.find('/'));
605 tail = str.substr(str.find('/') + 1);
606 }
607
608 int i;
609 for (i = 0; i < m_num_values; i++)
610 if (m_data[i].get_odb().get_name() == first)
611 break;
612 if (i == m_num_values)
613 return false;
614
615 if (!tail.empty())
616 return m_data[i].get_odb().is_subkey(tail);
617
618 return true;
619 }
bool is_subkey(std::string str)
Definition odbxx.cxx:597
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 1379 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 1373 of file odbxx.h.

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

◆ items()

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

Definition at line 1456 of file odbxx.h.

1456{ return *this; }

◆ load()

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

Definition at line 101 of file odbxx.cxx.

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

◆ node_to_string()

std::string midas::odb::node_to_string ( const MJsonNode *  node)
inline

Definition at line 1239 of file odbxx.h.

1239 {
1240 std::string value;
1241
1242 switch (node->GetType()) {
1243 case MJSON_STRING:
1244 value = node->GetString();
1245 break;
1246 case MJSON_INT:
1247 value = std::to_string(node->GetInt());
1248 break;
1249 case MJSON_NUMBER:
1250 value = std::to_string(node->GetDouble());
1251 break;
1252 case MJSON_BOOL:
1253 value = std::to_string(node->GetBool());
1254 break;
1255 default:
1256 mthrow("Invalid MJSON type \"" + std::to_string(node->GetType()) + "\"");
1257 }
1258
1259 return value;
1260 };
double value[100]
Definition odbhist.cxx:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ odb_from_json()

midas::odb * midas::odb::odb_from_json ( const MJsonNode *  node,
std::string  name,
int  tid,
odb o 
)
inline

Definition at line 1263 of file odbxx.h.

1263 {
1264 int type = node->GetType();
1265
1266 if (type == MJSON_OBJECT) { // subdir
1267 const MJsonStringVector* names = node->GetObjectNames();
1268 const MJsonNodeVector* nodes = node->GetObjectNodes();
1269 if (names == nullptr || nodes==nullptr || names->size() != nodes->size())
1270 mthrow("Invalid JSON format");
1271
1272 if (o == nullptr)
1273 o = new midas::odb();
1274 o->set_tid(TID_KEY);
1275 o->set_name(name);
1276 o->set_hkey(0);
1277
1278 // count subkeys
1279 int n=0;
1280 for (int i=0 ; i<(int)names->size() ; i++) {
1281 const char *name = (*names)[i].c_str();
1282
1283 if (strchr(name, '/'))// skip special entries
1284 continue;
1285 n++;
1286 }
1287 o->set_num_values(n);
1288
1289 for (int i=n=0 ; i<(int)names->size() ; i++) {
1290 const char *name = (*names)[i].c_str();
1291
1292 if (strchr(name, '/'))// skip special entries
1293 continue;
1294
1295 int t = 0;
1296 auto key = node->FindObjectNode((std::string(name) + "/key").c_str());
1297 if (key)
1298 t = key->FindObjectNode("type")->GetInt();
1299 else
1300 t = TID_KEY;
1301
1302 midas::odb *os = odb_from_json((*nodes)[i], (*names)[i].c_str(), t, nullptr);
1303 os->set_parent(o);
1304 o->set_odb(os, n);
1305 n++;
1306 }
1307
1308 o->set_num_values(n);
1309
1310 } else { // key
1311
1312 if (o == nullptr)
1313 o = new midas::odb();
1314
1315 o->set_name(name);
1316 o->set_tid(tid);
1317 o->set_hkey(0);
1318
1319 if (node->GetType() == MJSON_ARRAY) {
1320 const MJsonNodeVector* a = node->GetArray();
1321 o->set_num_values(a->size());
1322 for (int i=0 ; i<(int)a->size() ; i++) {
1323 MJsonNode *n = (*a)[i];
1324 auto value = node_to_string(n);
1325 o->set(value, i);
1326 }
1327 } else {
1328 auto value = node_to_string(node);
1329 o->set(value);
1330 }
1331 }
1332
1333 return o;
1334 };
midas::odb * odb_from_json(const MJsonNode *node, std::string name, int tid, odb *o)
Definition odbxx.h:1263
std::string node_to_string(const MJsonNode *node)
Definition odbxx.h:1239
Here is the call graph for this function:
Here is the caller graph for this function:

◆ odb_from_json_string()

void midas::odb::odb_from_json_string ( const std::string &  str,
const std::string &  subkey 
)

Definition at line 259 of file odbxx.cxx.

259 {
260
261 MJsonNode* node = MJsonNode::Parse(str.c_str());
262 if (node->GetType() == MJSON_ERROR)
263 mthrow("Error parsing JSON: " + node->GetError());
264
265 // node->Dump();
266
267 if (subkey == "/") {
268 odb_from_json(node, "root", TID_KEY, this);
269 } else {
270
271 // split path into vector of subdirectories
272 auto dirs = split(subkey);
273
274 int tid = TID_KEY;
275
276 // traverse subdirectories
277 std::string root_name = "root";
278 for (std::string subdir : dirs) {
279 const MJsonStringVector* names = node->GetObjectNames();
280 const MJsonNodeVector* nodes = node->GetObjectNodes();
281
282 int i;
283 for (i=0; i<(int)names->size(); i++) {
284 const char *name = (*names)[i].c_str();
285 MJsonNode *subnode = (*nodes)[i];
286 if (strchr(name, '/')) // skip special entries
287 continue;
288 if (node->GetType() == MJSON_OBJECT)
289 if (name == subdir) {
290 auto key = node->FindObjectNode((std::string(name) + "/key").c_str());
291 if (key)
292 tid = key->FindObjectNode("type")->GetInt();
293 else
294 tid = TID_KEY;
295
296 node = subnode;
297 root_name = subdir;
298 break;
299 }
300 }
301 if (i == (int)names->size())
302 mthrow("Subdirectory \"" + subdir + "\" not found in JSON");
303 }
304
305 odb_from_json(node, root_name, tid, this);
306 }
307
308
309 this->set_auto_create(false);
310 this->set_auto_refresh_read(false);
311 this->set_auto_refresh_write(false);
312 this->set_auto_enlarge_array(false);
313 this->set_write_protect(true);
314 this->set_trigger_hotlink(false);
315 }
void set_auto_refresh_read(bool f)
Definition odbxx.h:1347
void set_auto_enlarge_array(bool f)
Definition odbxx.h:1368
void set_trigger_hotlink(bool f)
Definition odbxx.h:1380
void set_auto_refresh_write(bool f)
Definition odbxx.h:1353
void set_auto_create(bool f)
Definition odbxx.h:1362
void set_write_protect(bool f)
Definition odbxx.h:1374
std::vector< std::string > split(std::string input, char delimiter='/')
Definition odbxx.cxx:241
Here is the call graph for this function:
Here is the caller graph for this function:

◆ odb_from_xml()

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

Definition at line 1186 of file odbxx.h.

1186 {
1187 std::string type(mxml_get_name(node));
1188
1189 unsigned int tid = 0;
1190 if (type == "dir" || type == "odb")
1191 tid = TID_KEY;
1192 else {
1193 for (tid = 0; tid < TID_LAST; tid++) {
1195 break;
1196 }
1197 }
1198 if (tid == TID_LAST)
1199 mthrow("Wrong key type in XML file");
1200
1201 if (o == nullptr)
1202 o = new midas::odb();
1203 o->set_tid(tid);
1204 if (type == "odb") {
1205 o->set_name("root");
1206 o->set_hkey(0);
1207 } else {
1208 o->set_name(mxml_get_attribute(node, "name"));
1209 if (mxml_get_attribute(node, "handle") == nullptr)
1210 mthrow("No \"handle\" attribute found in XML data");
1211 o->set_hkey(std::stoi(std::string(mxml_get_attribute(node, "handle"))));
1212 }
1213
1214 if (type == "key") {
1215 std::string value(mxml_get_value(node));
1216 o->set(value);
1217 } else if (type == "keyarray") {
1218 int n = std::atoi(mxml_get_attribute(node, "num_values"));
1219 o->set_num_values(n);
1220 for (int i=0 ; i<n ; i++) {
1221 std::string value(mxml_get_value(mxml_subnode(node, i)));
1222 o->set(value, i);
1223 }
1224 } else if (type == "dir" || type == "odb") {
1226 o->set_num_values(n);
1227 for (int i = 0; i < n; i++) {
1229 os->set_parent(o);
1230 o->set_odb(os, i);
1231 }
1232 } else
1233 mthrow("Unexpected XML element " + std::string(mxml_get_name(node)));
1234
1235 return o;
1236 };
midas::odb * odb_from_xml(PMXML_NODE node, odb *o)
Definition odbxx.h:1186
#define TID_LAST
Definition midas.h:354
const char * rpc_tid_name(INT id)
Definition midas.cxx:11786
Here is the call graph for this function:
Here is the caller graph for this function:

◆ odb_from_xml_remote()

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

Definition at line 159 of file odbxx.cxx.

159 {
160 init_hdb();
161
162 HNDLE hKey;
163 int status = db_find_key(s_hDB, 0, str.c_str(), &hKey);
164 if (status != DB_SUCCESS)
165 mthrow("ODB key \"" + str + "\" not found in ODB");
166
167 int bsize = 1000000;
168 char *buffer = (char *)malloc(bsize);
169 do {
170 int size = bsize;
171 status = db_copy_xml(s_hDB, hKey, buffer, &size, false);
172 if (status == DB_TRUNCATED) {
173 bsize *= 2;
174 buffer = (char *)realloc(buffer, bsize);
175 }
176 } while (status == DB_TRUNCATED);
177
178 if (status != DB_SUCCESS)
179 mthrow("Cannot retrieve XML data, status = " + std::to_string(status));
180
181 if (s_debug)
182 std::cout << "Retrieved XML tree for \"" + str + "\"" << std::endl;
183
184 char error[256] = "";
185 PMXML_NODE tree = mxml_parse_buffer(buffer, error, sizeof(error), NULL);
186 if (error[0]) {
187 std::cout << "MXML error, buffer =\n" << buffer << std::endl;
188 mthrow("MXML error: " + std::string(error));
189 }
190 free(buffer);
191
192 odb_from_xml(&tree->child[2], this);
193 m_hKey = hKey;
194
196 }
int size()
Definition odbxx.cxx:443
#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:9042
Here is the call graph for this function:
Here is the caller graph for this function:

◆ odb_from_xml_string()

void midas::odb::odb_from_xml_string ( const std::string &  str,
const std::string &  subkey 
)

Definition at line 198 of file odbxx.cxx.

198 {
199 char error[256] = "";
200 PMXML_NODE tree = mxml_parse_buffer(str.c_str(), error, sizeof(error), NULL);
201 if (error[0]) {
202 std::cout << "MXML error, buffer =\n" << str << std::endl;
203 mthrow("MXML error: " + std::string(error));
204 }
205
207 if (subkey == "/")
208 root = &tree->child[2];
209 else {
210 // convert ODB path to XPATH
211 std::stringstream ss(subkey);
212 std::string dir, xpath;
213 while (std::getline(ss, dir, '/'))
214 if (!dir.empty())
215 xpath += "/dir[@name=\"" + dir + "\"]";
216
217 // std::string query("/dir[@name=\"Buffer sizes\"]");
218 root = mxml_find_node(&tree->child[2], xpath.c_str());
219 if (root == nullptr) {
220 // try with last element being a key
221 size_t pos = xpath.rfind("dir");
222 if (pos != std::string::npos)
223 xpath.replace(pos, 3, "key");
224 root = mxml_find_node(&tree->child[2], xpath.c_str());
225 if (root == nullptr)
226 mthrow("ODB key \"" + subkey + "\" not found in ODB");
227 }
228 }
229
230 odb_from_xml(root, this);
232
233 this->set_auto_create(false);
234 this->set_auto_refresh_read(false);
235 this->set_auto_refresh_write(false);
236 this->set_auto_enlarge_array(false);
237 this->set_write_protect(true);
238 this->set_trigger_hotlink(false);
239 }
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 872 of file odbxx.h.

872 {
873 std::string s;
874 if (m_tid == TID_KEY)
875 print(s, 0);
876 else
877 get(s); // forward to get(std::string)
878 return s;
879 }
std::string print()
Definition odbxx.cxx:476
Here is the call graph for this function:

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

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

Definition at line 892 of file odbxx.h.

892 {
894 read();
895 std::vector<std::string> v(m_num_values);
896 for (int i = 0; i < m_num_values; i++)
897 v[i] = m_data[i].get();
898 return v;
899 }
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 883 of file odbxx.h.

883 {
885 read();
886 std::vector<T> v(m_num_values);
887 for (int i = 0; i < m_num_values; i++)
888 v[i] = m_data[i];
889 return v;
890 }
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 914 of file odbxx.h.

914 {
915 if (m_tid == 0)
916 mthrow("Element \"" + m_name + "\" not found");
917 return get<T>(); // forward to get<T>()
918 }
Here is the call graph for this function:

◆ operator()()

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

Definition at line 976 of file odbxx.h.

976 {
977 if (m_tid == 0) {
978 if (m_num_values == 0) {
979 // initialize this
980 m_num_values = 1;
981 m_tid = detect_type(v);
982 m_data = new u_odb[1]{};
983 m_data[0].set_tid(m_tid);
984 m_data[0].set_parent(this);
985 m_data[0].set(v);
986 if (this->is_auto_refresh_write())
987 write();
988 } else {
989 for (int i = 0; i < m_num_values; i++)
990 m_data[i].set(v);
991 if (this->is_auto_refresh_write())
992 write();
993 }
994 }
995 return *this;
996 }
bool is_auto_refresh_write() const
Definition odbxx.h:1352
int detect_type(const T &)
Definition odbxx.h:730
#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 1052 of file odbxx.h.

1052 {
1053 if (m_num_values > 1)
1054 mthrow("ODB key \"" + get_full_path() +
1055 "\" contains array which cannot be used in basic arithmetic operation.");
1057 read();
1058 T s = (T) m_data[0];
1059 return s * i;
1060 }
Here is the call graph for this function:

◆ operator*=()

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

Definition at line 1137 of file odbxx.h.

1137 {
1139 read();
1140 for (int i = 0; i < m_num_values; i++)
1141 m_data[i].mult(d, false);
1142 if (this->is_auto_refresh_write())
1143 write();
1144 return *this;
1145 }
Here is the call graph for this function:

◆ operator+()

template<typename T >
T midas::odb::operator+ ( 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.");
1012 if (std::is_same<T, midas::odb>::value) {
1013 if (is_auto_refresh_read()) {
1014 read();
1015 i.read();
1016 }
1017 // adding two midas::odb objects is best done in double
1018 double s1 = static_cast<double>(m_data[0]);
1019 double s2 = static_cast<double>(i.m_data[0]);
1020 return s1 + s2;
1021 } else {
1023 read();
1024 T s = (T) m_data[0];
1025 return s + i;
1026 }
1027 }
Here is the call graph for this function:

◆ operator++() [1/2]

odb & midas::odb::operator++ ( )
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(1, false);
1078 if (this->is_auto_refresh_write())
1079 write();
1080 return *this;
1081 }
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 1083 of file odbxx.h.

1083 {
1084 // create temporary object
1085 odb o(this);
1087 read();
1088 for (int i = 0; i < m_num_values; i++)
1089 m_data[i].add(1, false);
1090 if (this->is_auto_refresh_write())
1091 write();
1092 return o;
1093 }
Here is the call graph for this function:

◆ operator+=()

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

Definition at line 1117 of file odbxx.h.

1117 {
1119 read();
1120 for (int i = 0; i < m_num_values; i++)
1121 m_data[i].add(d, false);
1122 if (this->is_auto_refresh_write())
1123 write();
1124 return *this;
1125 }
Here is the call graph for this function:

◆ operator-()

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

Definition at line 1030 of file odbxx.h.

1030 {
1031 if (m_num_values > 1)
1032 mthrow("ODB key \"" + get_full_path() +
1033 "\" contains array which cannot be used in basic arithmetic operation.");
1034 if (std::is_same<T, midas::odb>::value) {
1035 if (is_auto_refresh_read()) {
1036 read();
1037 i.read();
1038 }
1039 // subtracting two midas::odb objects is best done in double
1040 double s1 = static_cast<double>(m_data[0]);
1041 double s2 = static_cast<double>(i.m_data[0]);
1042 return s1 - s2;
1043 } else {
1045 read();
1046 T s = (T) m_data[0];
1047 return s - i;
1048 }
1049 }
Here is the call graph for this function:

◆ operator--() [1/2]

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

Definition at line 1095 of file odbxx.h.

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

◆ operator--() [2/2]

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

Definition at line 1105 of file odbxx.h.

1105 {
1106 // create temporary object
1107 odb o(this);
1109 read();
1110 for (int i = 0; i < m_num_values; i++)
1111 m_data[i].add(-1, false);
1112 if (this->is_auto_refresh_write())
1113 write();
1114 return o;
1115 }
Here is the call graph for this function:

◆ operator-=()

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

Definition at line 1127 of file odbxx.h.

1127 {
1129 read();
1130 for (int i = 0; i < m_num_values; i++)
1131 m_data[i].add(-d, false);
1132 if (this->is_auto_refresh_write())
1133 write();
1134 return *this;
1135 }
Here is the call graph for this function:

◆ operator/()

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

Definition at line 1063 of file odbxx.h.

1063 {
1064 if (m_num_values > 1)
1065 mthrow("ODB key \"" + get_full_path() +
1066 "\" contains array which cannot be used in basic arithmetic operation.");
1068 read();
1069 T s = (T) m_data[0];
1070 return s / i;
1071 }
Here is the call graph for this function:

◆ operator/=()

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

Definition at line 1147 of file odbxx.h.

1147 {
1149 read();
1150 if (d == 0)
1151 mthrow("Division by zero");
1152 for (int i = 0; i < m_num_values; i++)
1153 m_data[i].mult(1 / d, false);
1154 if (this->is_auto_refresh_write())
1155 write();
1156 return *this;
1157 }
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 840 of file odbxx.h.

840 {
841
842 if (this->is_write_protect())
843 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
844
845 if (m_num_values == 0) {
846 // initialize this
848 m_tid = detect_type(arr[0]);
849 m_data = new u_odb[m_num_values]{};
850 for (int i = 0; i < m_num_values; i++) {
852 m_data[i].set_parent(this);
853 }
854
855 } else {
856
857 // resize internal array if different
858 if (SIZE != m_num_values) {
860 }
861 }
862
863 for (int i = 0; i < m_num_values; i++)
864 m_data[i].set(arr[i]);
865
866 if (this->is_auto_refresh_write())
867 write();
868 return arr;
869 }
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 794 of file odbxx.h.

794 {
795
796 if (this->is_write_protect())
797 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
798
799 if (m_num_values == 0) {
800 // initialize this
801 m_num_values = v.size();
802 if (std::is_same<T, bool>::value) {
803 // Special logic for vector<bool>, which may not be a true
804 // container: it's often optimized to be a bitfield, with
805 // references to elements being masked bits rather than bools.
806 // So T is a bool here, but typeof(v[0]) may not be bool!
807 // "Fake container optimization" only applies to vector<bool>,
808 // not array<bool> or any other vector<T>.
809 m_tid = TID_BOOL;
810 } else {
811 // Every other type can be detected using ref to first element.
812 m_tid = detect_type(v[0]);
813 }
814
815 m_data = new u_odb[m_num_values]{};
816 for (int i = 0; i < m_num_values; i++) {
818 m_data[i].set_parent(this);
819 }
820
821 } else {
822
823 // resize internal array if different
824 if ((int)v.size() != m_num_values) {
825 resize_mdata(v.size());
826 }
827 }
828
829 for (int i = 0; i < m_num_values; i++)
830 m_data[i].set(v[i]);
831
832 if (this->is_auto_refresh_write())
833 write();
834
835 return v;
836 }
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 767 of file odbxx.h.

767 {
768
769 if (this->is_write_protect())
770 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
771
772 if (m_num_values == 0) {
773 // initialize this
774 m_num_values = 1;
775 m_tid = detect_type(v);
776 m_data = new u_odb[1]{};
777 m_data[0].set_tid(m_tid);
778 m_data[0].set_parent(this);
779 m_data[0].set(v);
780 if (this->is_auto_refresh_write())
781 write();
782 } else {
783 for (int i = 0; i < m_num_values; i++)
784 m_data[i].set(v);
785
786 if (this->is_auto_refresh_write())
787 write();
788 }
789 return v;
790 }
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 970 of file odbxx.h.

970 {
971 return get_subkey(std::string(str));
972 }
Here is the call graph for this function:

◆ operator[]() [2/3]

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

Definition at line 932 of file odbxx.h.

932 {
933 if (this->is_write_protect())
934 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
935
936 if (index < 0)
937 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) + "]\"");
938
939 if (index == 0 && m_num_values == 0) {
940 // initialize this
941 m_num_values = 1;
942 m_tid = 0;
943 m_data = new u_odb[1]{};
944 m_data[0].set_tid(m_tid);
945 m_data[0].set_parent(this);
946 m_last_index = 0;
947 return m_data[0];
948 } else if (index >= m_num_values) {
949 if (is_auto_enlarge_array()) {
951 if (this->is_auto_refresh_write())
952 write(index, 0);
953 } else {
954 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)");
955 }
956 }
957
959 read(index);
960
962 return m_data[index];
963 }
bool is_auto_enlarge_array() const
Definition odbxx.h:1367
Here is the call graph for this function:

◆ operator[]() [3/3]

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

Definition at line 966 of file odbxx.h.

966 {
967 return get_subkey(str);
968 }
Here is the call graph for this function:

◆ print() [1/2]

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

Definition at line 476 of file odbxx.cxx.

476 {
477 std::string s;
478 s = "{\n";
479 print(s, 1);
480 s += "\n}";
481 return s;
482 }
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 493 of file odbxx.cxx.

493 {
494 for (int i = 0; i < indent; i++)
495 s += " ";
496 if (m_tid == TID_KEY) {
497 s += "\"" + m_name + "\": {\n";
498 for (int i = 0; i < m_num_values; i++) {
499 std::string v;
500 // recursive call
501 m_data[i].get_odb().print(v, indent + 1);
502 s += v;
503 if (i < m_num_values - 1)
504 s += ",\n";
505 else
506 s += "\n";
507 }
508 for (int i = 0; i < indent; i++)
509 s += " ";
510 s += "}";
511 } else {
512 s += "\"" + m_name + "\": ";
513 if (m_num_values > 1)
514 s += "[";
515 std::string v;
516 get(v, m_tid == TID_STRING || m_tid == TID_LINK);
517 if (m_tid == TID_LINK)
518 s += " -> ";
519 s += v;
520 if (m_num_values > 1)
521 s += "]";
522 }
523 }
Here is the call graph for this function:

◆ read() [1/2]

void midas::odb::read ( )

Definition at line 855 of file odbxx.cxx.

855 {
856 if (!is_connected_odb())
857 return;
858
859 // check if deleted
860 if (is_deleted())
861 mthrow("ODB key \"" + m_name + "\" cannot be pulled because it has been deleted");
862
863 if (m_hKey == 0)
864 return; // needed to print un-connected objects
865
866 if (m_tid == 0)
867 mthrow("Read of invalid ODB key \"" + m_name + "\"");
868
869 if (m_hKey == -1) {
870 // connect un-connected object (crated via XML)
871 std::string path = get_full_path();
872
873 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
874 if (status != DB_SUCCESS)
875 mthrow("Cannot connect key \"" + path + "\" to ODB");
876 }
877
878 int status{};
879 if (m_tid == TID_STRING) {
880 KEY key;
882 char *str = (char *) malloc(key.total_size);
883 int size = key.total_size;
885 for (int i = 0; i < m_num_values; i++)
886 m_data[i].set(str + i * key.item_size);
887 free(str);
888 } else if (m_tid == TID_KEY) {
889 std::vector<std::string> name;
890 int n = get_subkeys(name);
891 if (n != m_num_values) {
892 // if subdirs have changed, rebuild it
893 delete[] m_data;
894 m_num_values = n;
896 for (int i = 0; i < m_num_values; i++) {
897 std::string k(get_full_path());
898 k += "/" + name[i];
899 midas::odb *o = new midas::odb(k.c_str());
900 o->set_parent(this);
902 m_data[i].set_parent(this);
903 m_data[i].set(o);
904 }
905 }
906 for (int i = 0; i < m_num_values; i++)
907 m_data[i].get_odb().read();
909 } else {
910 // resize local array if number of values has changed
911 KEY key;
913 if (key.num_values != m_num_values) {
914 delete[] m_data;
917 for (int i = 0; i < m_num_values; i++) {
919 m_data[i].set_parent(this);
920 }
921 }
922
924 void *buffer = malloc(size);
925 void *p = buffer;
927 for (int i = 0; i < m_num_values; i++) {
928 if (m_tid == TID_UINT8)
929 m_data[i].set(*static_cast<uint8_t *>(p));
930 else if (m_tid == TID_INT8)
931 m_data[i].set(*static_cast<int8_t *>(p));
932 else if (m_tid == TID_UINT16)
933 m_data[i].set(*static_cast<uint16_t *>(p));
934 else if (m_tid == TID_INT16)
935 m_data[i].set(*static_cast<int16_t *>(p));
936 else if (m_tid == TID_UINT32)
937 m_data[i].set(*static_cast<uint32_t *>(p));
938 else if (m_tid == TID_INT32)
939 m_data[i].set(*static_cast<int32_t *>(p));
940 else if (m_tid == TID_UINT64)
941 m_data[i].set(*static_cast<uint64_t *>(p));
942 else if (m_tid == TID_INT64)
943 m_data[i].set(*static_cast<int64_t *>(p));
944 else if (m_tid == TID_BOOL)
945 m_data[i].set(*static_cast<bool *>(p));
946 else if (m_tid == TID_FLOAT)
947 m_data[i].set(*static_cast<float *>(p));
948 else if (m_tid == TID_DOUBLE)
949 m_data[i].set(*static_cast<double *>(p));
950 else if (m_tid == TID_STRING)
951 m_data[i].set(std::string(static_cast<const char *>(p)));
952 else if (m_tid == TID_LINK)
953 m_data[i].set(std::string(static_cast<const char *>(p)));
954 else
955 mthrow("Invalid type ID " + std::to_string(m_tid));
956
957 p = static_cast<char *>(p) + rpc_tid_size(m_tid);
958 }
959 free(buffer);
960 }
961
962 if (status != DB_SUCCESS)
963 mthrow("db_get_data for ODB key \"" + get_full_path() +
964 "\" failed with status " + std::to_string(status));
965 if (s_debug) {
966 if (m_tid == TID_KEY) {
967 std::cout << "Get ODB key \"" + get_full_path() + "[0..." +
968 std::to_string(m_num_values - 1) + "]\"" << std::endl;
969 } else {
970 std::string s;
971 get(s, false, false);
972 if (m_num_values > 1) {
973 if (m_tid == TID_STRING || m_tid == TID_LINK)
974 std::cout << "Get ODB key \"" + get_full_path() + "[0..." +
975 std::to_string(m_num_values - 1) + "]\": [\"" + s + "\"]" << std::endl;
976 else
977 std::cout << "Get ODB key \"" + get_full_path() + "[0..." +
978 std::to_string(m_num_values - 1) + "]\": [" + s + "]" << std::endl;
979 } else {
980 if (m_tid == TID_STRING || m_tid == TID_LINK)
981 std::cout << "Get ODB key \"" + get_full_path() + "\": \"" + s + "\"" << std::endl;
982 else
983 std::cout << "Get ODB key \"" + get_full_path() + "\": " + s << std::endl;
984 }
985 }
986 }
987 }
bool is_deleted() const
Definition odbxx.h:528
INT db_get_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
Definition odb.cxx:6544
INT rpc_tid_size(INT id)
Definition midas.cxx:11779
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 990 of file odbxx.cxx.

990 {
991 if (!is_connected_odb())
992 return;
993
994 if (m_hKey == 0 || m_hKey == -1)
995 return; // needed to print un-connected objects
996
997 if (m_tid == 0)
998 mthrow("Pull of invalid ODB key \"" + m_name + "\"");
999
1000 int status{};
1001 if (m_tid == TID_STRING || m_tid == TID_LINK) {
1002 KEY key;
1004 char *str = (char *) malloc(key.item_size);
1005 int size = key.item_size;
1007 m_data[index].set(str);
1008 free(str);
1009 } else if (m_tid == TID_KEY) {
1010 m_data[index].get_odb().read();
1012 } else {
1013 int size = rpc_tid_size(m_tid);
1014 void *buffer = malloc(size);
1015 void *p = buffer;
1017 if (m_tid == TID_UINT8)
1018 m_data[index].set(*static_cast<uint8_t *>(p));
1019 else if (m_tid == TID_INT8)
1020 m_data[index].set(*static_cast<int8_t *>(p));
1021 else if (m_tid == TID_UINT16)
1022 m_data[index].set(*static_cast<uint16_t *>(p));
1023 else if (m_tid == TID_INT16)
1024 m_data[index].set(*static_cast<int16_t *>(p));
1025 else if (m_tid == TID_UINT32)
1026 m_data[index].set(*static_cast<uint32_t *>(p));
1027 else if (m_tid == TID_INT32)
1028 m_data[index].set(*static_cast<int32_t *>(p));
1029 else if (m_tid == TID_UINT64)
1030 m_data[index].set(*static_cast<uint64_t *>(p));
1031 else if (m_tid == TID_INT64)
1032 m_data[index].set(*static_cast<int64_t *>(p));
1033 else if (m_tid == TID_BOOL)
1034 m_data[index].set(*static_cast<bool *>(p));
1035 else if (m_tid == TID_FLOAT)
1036 m_data[index].set(*static_cast<float *>(p));
1037 else if (m_tid == TID_DOUBLE)
1038 m_data[index].set(*static_cast<double *>(p));
1039 else if (m_tid == TID_STRING)
1040 m_data[index].set(std::string(static_cast<const char *>(p)));
1041 else if (m_tid == TID_LINK)
1042 m_data[index].set(std::string(static_cast<const char *>(p)));
1043 else
1044 mthrow("Invalid type ID " + std::to_string(m_tid));
1045
1046 free(buffer);
1047 }
1048
1049 if (status != DB_SUCCESS)
1050 mthrow("db_get_data for ODB key \"" + get_full_path() +
1051 "\" failed with status " + std::to_string(status));
1052 if (s_debug) {
1053 std::string s;
1054 m_data[index].get(s);
1055 if (m_tid == TID_STRING || m_tid == TID_LINK)
1056 std::cout << "Get ODB key \"" + get_full_path() + "[" +
1057 std::to_string(index) + "]\": [\"" + s + "\"]" << std::endl;
1058 else
1059 std::cout << "Get ODB key \"" + get_full_path() + "[" +
1060 std::to_string(index) + "]\": [" + s + "]" << std::endl;
1061 }
1062 }
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT idx, DWORD type)
Definition odb.cxx:6898
Here is the call graph for this function:

◆ read_key()

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

Definition at line 710 of file odbxx.cxx.

710 {
711 init_hdb();
712
713 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
714 if (status != DB_SUCCESS)
715 return false;
716
717 KEY key;
719 if (status != DB_SUCCESS)
720 mthrow("db_get_key for ODB key \"" + path +
721 "\" failed with status " + std::to_string(status));
722
723 // check for correct type if given as parameter
724 if (m_tid > 0 && m_tid != (int) key.type)
725 mthrow("ODB key \"" + get_full_path() +
726 "\" has different type than specified");
727
728 if (s_debug)
729 std::cout << "Get definition for ODB key \"" + get_full_path() + "\"" << std::endl;
730
731 m_tid = key.type;
732 m_name = key.name;
733 if (m_tid == TID_KEY) {
734
735 // merge ODB keys with local keys
736 for (int i = 0; i < m_num_values; i++) {
737 std::string p(path);
738 if (p.back() != '/')
739 p += "/";
740 p += m_data[i].get_odb().get_name();
741 HNDLE h;
742 status = db_find_key(s_hDB, 0, p.c_str(), &h);
743 if (status != DB_SUCCESS) {
744 // if key does not exist in ODB write it
745 m_data[i].get_odb().write_key(p, true);
746 m_data[i].get_odb().write();
747 } else {
748 // check key type
749 KEY key;
750 status = db_get_key(s_hDB, h, &key);
751 if (status != DB_SUCCESS)
752 mthrow("db_get_key for ODB key \"" + get_full_path() +
753 "\" failed with status " + std::to_string(status));
754 if (m_data[i].get_odb().get_tid() != (int)key.type) {
755 // write key if different
756 m_data[i].get_odb().write_key(p, true);
757 m_data[i].get_odb().write();
758 }
759 if (m_data[i].get_odb().get_tid() == TID_KEY) {
760 // update subkey structure
761 m_data[i].get_odb().read_key(p);
762 }
763 }
764 }
765
766 // read back everything from ODB
767 std::vector<std::string> name;
769 delete[] m_data;
771 for (int i = 0; i < m_num_values; i++) {
772 std::string p(path);
773 if (p.back() != '/')
774 p += "/";
775 p += name[i];
776 midas::odb *o = new midas::odb(p.c_str());
777 o->set_parent(this);
779 m_data[i].set_parent(this);
780 m_data[i].set(o);
781 }
782 } else {
784 delete[] m_data;
786 for (int i = 0; i < m_num_values; i++) {
788 m_data[i].set_parent(this);
789 }
790 }
791
792 return true;
793 }
void write(int str_size=0)
Definition odbxx.cxx:1166
int get_tid()
Definition odbxx.h:1453
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 448 of file odbxx.cxx.

448 {
450 if (this->is_auto_refresh_write()) {
452 if (status != DB_SUCCESS)
453 mthrow("db_set_num_values for ODB key \"" + get_full_path() +
454 "\" failed with status " + std::to_string(status));
455 }
456 }
INT db_set_num_values(HNDLE hDB, HNDLE hKey, INT num_values)
Definition odb.cxx:7507
Here is the call graph for this function:

◆ resize() [2/2]

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

Definition at line 459 of file odbxx.cxx.

459 {
462 if (this->is_auto_refresh_write()) {
464 if (status != DB_SUCCESS)
465 mthrow("db_set_num_values for ODB key \"" + get_full_path() +
466 "\" failed with status " + std::to_string(status));
467 }
468 if (size > old_size) {
469 for (int i=old_size ; i<size ; i++)
470 m_data[i] = b;
471 if (this->is_auto_refresh_write())
472 write();
473 }
474 }
Here is the call graph for this function:

◆ resize_mdata()

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

Definition at line 318 of file odbxx.cxx.

318 {
319 auto new_array = new u_odb[size]{};
320 int i;
321 for (i = 0; i < m_num_values && i < size; i++) {
322 new_array[i] = m_data[i];
323 if (m_tid == TID_KEY)
324 m_data[i].set_odb(nullptr); // move odb*
325 if (m_tid == TID_STRING || m_tid == TID_LINK)
326 m_data[i].set_string_ptr(nullptr); // move std::string*
327 }
328 for (; i < size; i++) {
329 if (m_tid == TID_STRING || m_tid == TID_LINK)
330 new_array[i].set_string(""); // allocates new string
331 }
332 delete[] m_data;
335 for (i = 0; i < m_num_values; i++) {
337 m_data[i].set_parent(this);
338 }
339 }
void set_odb(odb *v)
Definition odbxx.h:189
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 1458 of file odbxx.h.

1458 {
1459 std::string s;
1460 get(s);
1461 return s;
1462 }
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 571 of file odbxx.cxx.

571 {
572 std::string buffer;
573
574 std::string header = "{\n";
575 header += " \"/MIDAS version\" : \"2.1\",\n";
576 header += " \"/filename\" : \"" + filename + "\",\n";
577
578 std::string path = get_full_path();
579 if (path == "")
580 path = "/";
581 header += " \"/ODB path\" : \"" + path + "\",\n\n";
582
583 odb::dump(buffer, 1);
584
585 buffer += "\n}\n";
586
587 std::ofstream f(filename);
588 if (!f.is_open())
589 mthrow("Cannot open file \"" + filename);
590
591 f << header << buffer;
592 f.close();
593 }
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 61 of file odbxx.cxx.

61 {
62 if (po->m_hKey == hKey)
63 return po;
64 if (po->m_tid == TID_KEY) {
65 for (int i = 0; i < po->m_num_values; i++) {
66 midas::odb *pot = search_hkey(po->m_data[i].get_podb(), hKey);
67 if (pot != nullptr)
68 return pot;
69 }
70 }
71 return nullptr;
72 }
static midas::odb * search_hkey(midas::odb *po, int hKey)
Definition odbxx.cxx:61
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 1649 of file odbxx.cxx.

1650 {
1651 if (this->is_write_protect())
1652 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1653
1654 if (m_tid == TID_BOOL)
1655 s = (s == "y" || s == "1") ? "1" : "0";
1656
1657 if (m_data == nullptr)
1658 m_data = new u_odb[m_num_values];
1659 m_data[i].set_parent(this);
1661 m_data[i].set(s);
1662 }
Here is the call graph for this function:

◆ set() [2/2]

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

Definition at line 1634 of file odbxx.cxx.

1635 {
1636 if (this->is_write_protect())
1637 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1638
1639 if (m_tid == TID_BOOL)
1640 s = (s == "y" || s == "1") ? "1" : "0";
1641
1642 m_num_values = 1;
1643 m_data = new u_odb[1];
1644 m_data[0].set_parent(this);
1645 m_data[0].set_tid(m_tid);
1646 m_data[0].set(s);
1647 }
Here is the call graph for this function:

◆ set_auto_create()

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

Definition at line 1362 of file odbxx.h.

1362 {
1365 }
void set_flags_recursively(uint32_t f)
Definition odbxx.cxx:151
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_auto_enlarge_array()

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

Definition at line 1368 of file odbxx.h.

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

◆ set_auto_refresh_read()

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

Definition at line 1347 of file odbxx.h.

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

◆ set_auto_refresh_write()

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

Definition at line 1353 of file odbxx.h.

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

◆ set_debug()

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

Definition at line 1386 of file odbxx.h.

1386{ 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 529 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 1359 of file odbxx.h.

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

◆ set_flags()

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

Definition at line 525 of file odbxx.h.

525{ m_flags = f; }

◆ set_flags_recursively()

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

Definition at line 151 of file odbxx.cxx.

151 {
152 m_flags = f;
153 if (m_tid == TID_KEY) {
154 for (int i = 0; i < m_num_values; i++)
155 m_data[i].get_odb().set_flags_recursively(f);
156 }
157 }
Here is the caller graph for this function:

◆ set_hkey()

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

Definition at line 523 of file odbxx.h.

523{ m_hKey = hKey; }

◆ set_last_index()

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

Definition at line 1000 of file odbxx.h.

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

◆ set_mode()

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

Definition at line 1552 of file odbxx.cxx.

1552 {
1553 // set mode of ODB key
1554 // default is MODE_READ | MODE_WRITE | MODE_DELETE
1555
1556 init_hdb();
1557
1558 // set mode in ODB
1560
1562 mthrow("db_set_mode for ODB key \"" + get_full_path() +
1563 "\" returnd error code " + std::to_string(status));
1564
1565 if (s_debug)
1566 std::cout << "Set mode of ODB key \"" + get_full_path() + "\" to " << mode << std::endl;
1567 }
INT db_set_mode(HNDLE hDB, HNDLE hKey, WORD mode, BOOL recurse)
Definition odb.cxx:8032
#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 534 of file odbxx.h.

534{ 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 532 of file odbxx.h.

532{ m_num_values = n; }

◆ set_odb()

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

Definition at line 1678 of file odbxx.cxx.

1679 {
1680 if (this->is_write_protect())
1681 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1682
1683 if (m_data == nullptr)
1684 m_data = new u_odb[m_num_values];
1685 m_data[i].set_parent(this);
1687 m_data[i].set_odb(o);
1688 }
Here is the call graph for this function:

◆ set_odb_source() [1/2]

static void midas::odb::set_odb_source ( odb::odb_source  s)
inlinestatic

Definition at line 1401 of file odbxx.h.

1401 {
1402 if (s == STRING)
1403 mthrow1("ODB source STRING requires a string");
1404 if (s == FILE)
1405 mthrow1("ODB source FILE requires a filename");
1406 s_odb_source = s;
1407 }
#define mthrow1(arg)
Definition mexcept.h:27
Here is the call graph for this function:

◆ set_odb_source() [2/2]

static void midas::odb::set_odb_source ( odb::odb_source  s,
std::string  str 
)
inlinestatic

Definition at line 1408 of file odbxx.h.

1408 {
1409 if (s == odb::FILE) {
1410 // check file contents
1411 std::ifstream file(str);
1412 if (!file)
1413 mthrow("File \"" + str + "\" not found");
1414 std::ostringstream ss;
1415 ss << file.rdbuf();
1416 if (str.find(".xml") == std::string::npos &&
1417 str.find(".XML") == std::string::npos &&
1418 str.find(".json") == std::string::npos &&
1419 str.find(".JSON") == std::string::npos)
1420 mthrow("File type of \"" + str + "\" is not supported");
1421 }
1422
1423 s_odb_source = s;
1425 }
Here is the call graph for this function:

◆ set_parent()

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

Definition at line 536 of file odbxx.h.

536{ 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 1341 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 1664 of file odbxx.cxx.

1665 {
1666 if (this->is_write_protect())
1667 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1668
1669 m_num_values = 1;
1670 m_tid = TID_STRING;
1671 m_data = new u_odb[1];
1672 m_data[0].set_parent(this);
1673 m_data[0].set_tid(m_tid);
1676 }
void set_preserve_string_size(bool f)
Definition odbxx.h:1341
void set_string_size(std::string s, int size)
Definition odbxx.cxx:1855
Here is the call graph for this function:

◆ set_tid()

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

Definition at line 531 of file odbxx.h.

531{ m_tid = tid; }

◆ set_trigger_hotlink()

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

Definition at line 1380 of file odbxx.h.

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

◆ set_write_protect()

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

Definition at line 1374 of file odbxx.h.

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

◆ size()

int midas::odb::size ( )

Definition at line 443 of file odbxx.cxx.

443 {
444 return m_num_values;
445 }
Here is the caller graph for this function:

◆ unwatch()

void midas::odb::unwatch ( )

Definition at line 1613 of file odbxx.cxx.

1614 {
1615 for (int i=0 ; i<(int) g_watchlist.size() ; i++) {
1616 if (g_watchlist[i]->get_hkey() == this->get_hkey()) {
1618 delete g_watchlist[i];
1619 g_watchlist.erase(g_watchlist.begin() + i);
1620 i--;
1621 }
1622 }
1623 }
INT db_unwatch(HNDLE hDB, HNDLE hKey)
Definition odb.cxx:13898
std::vector< midas::odb * > g_watchlist
Definition odbxx.cxx:44
Here is the call graph for this function:

◆ unwatch_all()

void midas::odb::unwatch_all ( )
staticprivate

Definition at line 1625 of file odbxx.cxx.

1626 {
1627 for (int i=0 ; i<(int) g_watchlist.size() ; i++) {
1629 delete g_watchlist[i];
1630 }
1631 g_watchlist.clear();
1632 }
Here is the call graph for this function:

◆ watch()

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

Definition at line 1597 of file odbxx.cxx.

1597 {
1598 if (m_hKey == 0 || m_hKey == -1)
1599 mthrow("watch() called for ODB key \"" + m_name +
1600 "\" which is not connected to ODB");
1601
1602 // create a deep copy of current object in case it
1603 // goes out of scope
1604 midas::odb* ow = new midas::odb(*this);
1605
1606 ow->m_watch_callback = f;
1608
1609 // put object into watchlist
1610 g_watchlist.push_back(ow);
1611 }
static void watch_callback(int hDB, int hKey, int index, void *info)
Definition odbxx.cxx:123
INT db_watch(HNDLE hDB, HNDLE hKey, void(*dispatcher)(INT, INT, INT, void *), void *info)
Definition odb.cxx:13823
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 123 of file odbxx.cxx.

123 {
124 midas::odb *po = static_cast<midas::odb *>(info);
125 if (po->m_data == nullptr)
126 mthrow("Callback received for a midas::odb object which went out of scope");
128 if (poh == nullptr) {
129 auto s = db_get_path(hDB, hKey);
130 mthrow("New key \"" + s + "\" has been created in ODB after calling watch()");
131 }
132
133 poh->m_last_index = index;
134 po->m_watch_callback(*poh);
135 poh->m_last_index = -1;
136 }
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 1065 of file odbxx.cxx.

1065 {
1066 if (!is_connected_odb())
1067 return;
1068
1069 if (m_hKey == -1) {
1070 // connect un-connected object (crated via XML)
1071 std::string path = get_full_path();
1072
1073 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
1074 if (status != DB_SUCCESS)
1075 mthrow("Cannot connect key \"" + path + "\" to ODB");
1076
1077 } else if (m_hKey == 0) {
1078 if (is_auto_create()) {
1079 std::string to_create = m_name[0] == '/' ? m_name : get_full_path();
1080 int status = db_create_key(s_hDB, 0, to_create.c_str(), m_tid);
1082 mthrow("Cannot create ODB key \"" + to_create + "\", status =" + std::to_string(status));
1083 db_find_key(s_hDB, 0, to_create.c_str(), &m_hKey);
1084 if (s_debug) {
1085 std::cout << "Created ODB key \"" + to_create + "\"" << std::endl;
1086 }
1087 // strip path from name
1088 if (m_name.find_last_of('/') != std::string::npos)
1089 m_name = m_name.substr(m_name.find_last_of('/') + 1);
1090 } else
1091 mthrow("Write of un-connected ODB key \"" + m_name + "\" not possible");
1092 }
1093
1094 // don't write keys
1095 if (m_tid == TID_KEY)
1096 return;
1097
1098 int status{};
1099 if (m_tid == TID_STRING || m_tid == TID_LINK) {
1100 KEY key;
1102 std::string s;
1103 m_data[index].get(s);
1104 if (m_num_values == 1) {
1105 int size = key.item_size;
1106 if (key.item_size == 0 || !is_preserve_string_size())
1107 size = s.size() + 1;
1108 if (str_size > 0)
1109 size = str_size;
1110 char *ss = (char *)malloc(size+1);
1111 mstrlcpy(ss, s.c_str(), size);
1112 if (is_trigger_hotlink())
1114 else
1116 free(ss);
1117 } else {
1118 if (key.item_size == 0)
1119 key.item_size = s.size() + 1;
1120 if (str_size > 0) {
1121 if (key.item_size > 0 && key.item_size != str_size) {
1122 std::cout << "ODB string size mismatch for \"" << get_full_path() <<
1123 "\" (" << key.item_size << " vs " << str_size << "). ODB key recreated."
1124 << std::endl;
1125 if (is_trigger_hotlink())
1126 status = db_set_data(s_hDB, m_hKey, s.c_str(), str_size, 1, m_tid);
1127 else
1128 status = db_set_data1(s_hDB, m_hKey, s.c_str(), str_size, 1, m_tid);
1129 }
1131 }
1133 }
1134 if (s_debug) {
1135 if (m_num_values > 1)
1136 std::cout << "Set ODB key \"" + get_full_path() + "[" + std::to_string(index) + "]\" = \"" + s
1137 + "\"" << std::endl;
1138 else
1139 std::cout << "Set ODB key \"" + get_full_path() + "\" = \"" + s + "\""<< std::endl;
1140 }
1141 } else {
1142 u_odb u = m_data[index];
1143 if (m_tid == TID_BOOL) {
1144 u.set_parent(nullptr);
1145 BOOL b = static_cast<bool>(u); // "bool" is only 1 Byte, BOOL is 4 Bytes
1147 } else {
1149 }
1150 if (s_debug) {
1151 std::string s;
1152 u.get(s);
1153 if (m_num_values > 1)
1154 std::cout << "Set ODB key \"" + get_full_path() + "[" + std::to_string(index) + "]\" = " + s
1155 << std::endl;
1156 else
1157 std::cout << "Set ODB key \"" + get_full_path() + "\" = " + s << std::endl;
1158 }
1159 }
1160 if (status != DB_SUCCESS)
1161 mthrow("db_set_data_index for ODB key \"" + get_full_path() +
1162 "\" failed with status " + std::to_string(status));
1163 }
bool is_preserve_string_size() const
Definition odbxx.h:1340
bool is_trigger_hotlink() const
Definition odbxx.h:1379
INT db_set_data(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Definition odb.cxx:7220
INT db_set_data1(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Definition odb.cxx:7318
INT db_set_data_index1(HNDLE hDB, HNDLE hKey, const void *data, INT data_size, INT idx, DWORD type, BOOL bNotify)
Definition odb.cxx:7833
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 1166 of file odbxx.cxx.

1166 {
1167
1168 // check if deleted
1169 if (is_deleted())
1170 mthrow("ODB key \"" + m_name + "\" cannot be written because it has been deleted");
1171
1172 // write subkeys
1173 if (m_tid == TID_KEY) {
1174 for (int i = 0; i < m_num_values; i++)
1175 m_data[i].get_odb().write();
1176 return;
1177 }
1178
1179 if (m_tid == 0 && m_data[0].get_tid() != 0)
1180 m_tid = m_data[0].get_tid();
1181
1183 mthrow("Invalid TID for ODB key \"" + get_full_path() + "\"");
1184
1185 if ((m_hKey == 0 || m_hKey == -1) && !is_auto_create())
1186 mthrow("Writing ODB key \"" + m_name +
1187 "\" is not possible because of invalid key handle");
1188
1189 // if index operator [] returned previously a certain index, write only this one
1190 if (m_last_index != -1) {
1192 m_last_index = -1;
1193 return;
1194 }
1195
1196 if (m_num_values == 1) {
1197 write(0, str_size);
1198 return;
1199 }
1200
1201 if (m_hKey == -1) {
1202 // connect un-connected object (crated via XML)
1203 std::string path = get_full_path();
1204
1205 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
1206 if (status != DB_SUCCESS)
1207 mthrow("Cannot connect key \"" + path + "\" to ODB");
1208
1209 } else if (m_hKey == 0) {
1210 if (is_auto_create()) {
1211 std::string to_create = m_name[0] == '/' ? m_name : get_full_path();
1212 int status = db_create_key(s_hDB, 0, to_create.c_str(), m_tid);
1214 mthrow("Cannot create ODB key \"" + to_create + "\", status" + std::to_string(status));
1215 db_find_key(s_hDB, 0, to_create.c_str(), &m_hKey);
1216 if (s_debug) {
1217 std::cout << "Created ODB key \"" + to_create + "\"" << std::endl;
1218 }
1219 // strip path from name
1220 if (m_name.find_last_of('/') != std::string::npos)
1221 m_name = m_name.substr(m_name.find_last_of('/') + 1);
1222 } else
1223 mthrow("Write of un-connected ODB key \"" + m_name + "\" not possible");
1224 }
1225
1226 int status{};
1227 if (m_tid == TID_STRING || m_tid == TID_LINK) {
1229 KEY key;
1231 if (key.item_size == 0 || key.total_size == 0) {
1232 int size = 1;
1233 for (int i = 0; i < m_num_values; i++) {
1234 std::string d;
1235 m_data[i].get(d);
1236 if ((int) d.size() + 1 > size)
1237 size = d.size() + 1;
1238 }
1239 // round up to multiples of 32
1240 size = (((size - 1) / 32) + 1) * 32;
1241 key.item_size = size;
1243 }
1244 char *str = (char *) calloc(m_num_values, key.item_size);
1245 for (int i = 0; i < m_num_values; i++) {
1246 std::string d;
1247 m_data[i].get(d);
1248 strncpy(str + i * key.item_size, d.c_str(), key.item_size);
1249 }
1250 if (is_trigger_hotlink())
1252 else
1254 free(str);
1255 if (s_debug) {
1256 std::string s;
1257 get(s, true, false);
1258 std::cout << "Set ODB key \"" + get_full_path() +
1259 "[0..." + std::to_string(m_num_values - 1) + "]\" = [" + s + "]" << std::endl;
1260 }
1261 } else {
1262 std::string s;
1263 m_data[0].get(s);
1264 if (is_trigger_hotlink())
1265 status = db_set_data(s_hDB, m_hKey, s.c_str(), s.length() + 1, 1, m_tid);
1266 else
1267 status = db_set_data1(s_hDB, m_hKey, s.c_str(), s.length() + 1, 1, m_tid);
1268 if (s_debug)
1269 std::cout << "Set ODB key \"" + get_full_path() + "\" = " + s << std::endl;
1270 }
1271 } else {
1273 uint8_t *buffer = (uint8_t *) malloc(size);
1274 uint8_t *p = buffer;
1275 for (int i = 0; i < m_num_values; i++) {
1276 if (m_tid == TID_BOOL) {
1277 // bool has 1 Byte, BOOL has 4 Bytes
1278 BOOL b = static_cast<bool>(m_data[i]);
1279 memcpy(p, &b, rpc_tid_size(m_tid));
1280 } else {
1281 memcpy(p, (void*)&m_data[i], rpc_tid_size(m_tid));
1282 }
1283 p += rpc_tid_size(m_tid);
1284 }
1285 if (is_trigger_hotlink())
1287 else
1289 free(buffer);
1290 if (s_debug) {
1291 std::string s;
1292 get(s, false, false);
1293 if (m_num_values > 1)
1294 std::cout << "Set ODB key \"" + get_full_path() + "[0..." + std::to_string(m_num_values - 1) +
1295 "]\" = [" + s + "]" << std::endl;
1296 else
1297 std::cout << "Set ODB key \"" + get_full_path() + "\" = " + s << std::endl;
1298 }
1299 }
1300
1301 if (status != DB_SUCCESS)
1302 mthrow("db_set_data for ODB key \"" + get_full_path() +
1303 "\" failed with status " + std::to_string(status));
1304 }
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 796 of file odbxx.cxx.

796 {
797 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
798 if (status != DB_SUCCESS) {
799 if (m_tid == 0) // auto-create subdir
800 m_tid = TID_KEY;
801 if (m_tid > 0 && m_tid < TID_LAST) {
802 status = db_create_key(s_hDB, 0, path.c_str(), m_tid);
803 if (status != DB_SUCCESS)
804 mthrow("ODB key \"" + path + "\" cannot be created");
805 status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
806 if (status != DB_SUCCESS)
807 mthrow("ODB key \"" + path + "\" not found after creation");
808 if (s_debug) {
809 if (path[0] == '/')
810 std::cout << "Created ODB key \"" + path + "\"" << std::endl;
811 else
812 std::cout << "Created ODB key \"" + get_full_path() + "\"" << std::endl;
813 }
814 } else
815 mthrow("ODB key \"" + path + "\" cannot be found");
816 return true;
817 } else {
818 KEY key;
820 if (status != DB_SUCCESS)
821 mthrow("db_get_key for ODB key \"" + path +
822 "\" failed with status " + std::to_string(status));
823 if (m_tid == 0)
824 m_tid = key.type;
825
826 // check for correct type
827 if (m_tid > 0 && m_tid != (int) key.type) {
828 if (force_write) {
829 // delete and recreate key
830 status = db_delete_key(s_hDB, m_hKey, false);
831 if (status != DB_SUCCESS)
832 mthrow("db_delete_key for ODB key \"" + path +
833 "\" failed with status " + std::to_string(status));
834 status = db_create_key(s_hDB, 0, path.c_str(), m_tid);
835 if (status != DB_SUCCESS)
836 mthrow("ODB key \"" + path + "\" cannot be created");
837 status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
838 if (status != DB_SUCCESS)
839 mthrow("ODB key \"" + path + "\" not found after creation");
840 if (s_debug)
841 std::cout << "Re-created ODB key \"" + get_full_path() << "\" with different type" << std::endl;
842 } else
843 // abort
844 mthrow("ODB key \"" + get_full_path() +
845 "\" has differnt type than specified");
846 } else if (s_debug)
847 std::cout << "Validated ODB key \"" + get_full_path() + "\"" << std::endl;
848
849 return false;
850 }
851 }
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 1494 of file odbxx.h.

1494 {
1495 T v;
1496 midas::odb oc(o);
1497 oc.get(v);
1498 return v != d;
1499 }

◆ operator!= [2/2]

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

Definition at line 1502 of file odbxx.h.

1502 {
1503 T v;
1504 midas::odb oc(o);
1505 oc.get(v);
1506 return d != v;
1507 }

◆ operator< [1/2]

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

Definition at line 1510 of file odbxx.h.

1510 {
1511 T v;
1512 midas::odb oc(o);
1513 oc.get(v);
1514 return v < d;
1515 }

◆ operator< [2/2]

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

Definition at line 1518 of file odbxx.h.

1518 {
1519 T v;
1520 midas::odb oc(o);
1521 oc.get(v);
1522 return d < v;
1523 }

◆ operator<<

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

Definition at line 921 of file odbxx.h.

921 {
922 std::string s;
923 if (o.m_tid == TID_KEY)
924 o.print(s, 0);
925 else
926 o.get(s);
927 output << s;
928 return output;
929 };
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 1526 of file odbxx.h.

1526 {
1527 T v;
1528 midas::odb oc(o);
1529 oc.get(v);
1530 return v <= d;
1531 }

◆ operator<= [2/2]

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

Definition at line 1534 of file odbxx.h.

1534 {
1535 T v;
1536 midas::odb oc(o);
1537 oc.get(v);
1538 return d <= v;
1539 }

◆ operator== [1/2]

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

Definition at line 1476 of file odbxx.h.

1476 {
1477 // the operator needs a "const midas::odb" reference,
1478 // so we have to make a non-const copy
1479 T v;
1480 midas::odb oc(o);
1481 oc.get(v);
1482 return v == d;
1483 }

◆ operator== [2/2]

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

Definition at line 1486 of file odbxx.h.

1486 {
1487 T v;
1488 midas::odb oc(o);
1489 oc.get(v);
1490 return d == v;
1491 }

◆ operator> [1/2]

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

Definition at line 1542 of file odbxx.h.

1542 {
1543 T v;
1544 midas::odb oc(o);
1545 oc.get(v);
1546 return v > d;
1547 }

◆ operator> [2/2]

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

Definition at line 1550 of file odbxx.h.

1550 {
1551 T v;
1552 midas::odb oc(o);
1553 oc.get(v);
1554 return d > v;
1555 }

◆ operator>= [1/2]

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

Definition at line 1558 of file odbxx.h.

1558 {
1559 T v;
1560 midas::odb oc(o);
1561 oc.get(v);
1562 return v >= d;
1563 }

◆ operator>= [2/2]

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

Definition at line 1566 of file odbxx.h.

1566 {
1567 T v;
1568 midas::odb oc(o);
1569 oc.get(v);
1570 return d >= v;
1571 }

Member Data Documentation

◆ m_data

u_odb* midas::odb::m_data
private

Definition at line 463 of file odbxx.h.

◆ m_flags

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

Definition at line 459 of file odbxx.h.

◆ m_hKey

HNDLE midas::odb::m_hKey
private

Definition at line 471 of file odbxx.h.

◆ m_last_index

int midas::odb::m_last_index
private

Definition at line 469 of file odbxx.h.

◆ m_name

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

Definition at line 465 of file odbxx.h.

◆ m_num_values

int midas::odb::m_num_values
private

Definition at line 467 of file odbxx.h.

◆ m_parent

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

Definition at line 475 of file odbxx.h.

◆ m_tid

int midas::odb::m_tid
private

Definition at line 461 of file odbxx.h.

◆ m_watch

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

Definition at line 456 of file odbxx.h.

◆ m_watch_callback

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

Definition at line 473 of file odbxx.h.

◆ s_connected_odb

bool midas::odb::s_connected_odb = false
staticprivate

Definition at line 454 of file odbxx.h.

◆ s_debug

bool midas::odb::s_debug = false
staticprivate

Definition at line 452 of file odbxx.h.

◆ s_hDB

HNDLE midas::odb::s_hDB = 0
staticprivate

Definition at line 450 of file odbxx.h.

◆ s_odb_source

thread_local odb::odb_source midas::odb::s_odb_source = odb::ONLINE
staticprivate

Definition at line 447 of file odbxx.h.

◆ s_odb_source_str

thread_local std::string midas::odb::s_odb_source_str = std::string("")
staticprivate

Definition at line 448 of file odbxx.h.


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