MIDAS
Loading...
Searching...
No Matches
odbxx.cxx
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: odbxx.cxx
4 Created by: Stefan Ritt
5
6 Contents: Object oriented interface to ODB implementation file
7
8\********************************************************************/
9
10#include <string>
11#include <iostream>
12#include <fstream>
13#include <sstream>
14#include <map>
15#include <stdexcept>
16#include <algorithm>
17#include <initializer_list>
18#include <cstring>
19#include <bitset>
20#include <functional>
21
22#include "midas.h"
23#include "odbxx.h"
24#include "mexcept.h"
25#include "mstrlcpy.h"
26#include "mjson.h"
27
28// #include "mleak.hxx" // un-comment for memory leak debugging
29
30/*------------------------------------------------------------------*/
31
32namespace midas {
33
34 //----------------------------------------------------------------
35
36 // initialize static variables
37 HNDLE odb::s_hDB = 0;
38 bool odb::s_debug = false;
39 bool odb::s_connected_odb = false;
40 std::vector<midas::odb *> g_watchlist = {};
41
42 //---- static initializers ---------------------------------------
44 std::string odb::s_odb_source_str = std::string("");
45
46 // static functions ----------------------------------------------
47
48 // initialize s_hDB, internal use only
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 }
59
60 // search for a key with a specific hKey, needed for callbacks
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 }
73
74 // check if a key exists in the ODB
75 bool odb::exists(const std::string &name) {
76 init_hdb();
78 return false;
79 HNDLE hkey;
80 return db_find_key(s_hDB, 0, name.c_str(), &hkey) == DB_SUCCESS;
81 }
82
83 // delete a key in the ODB
84 int odb::delete_key(const std::string &name) {
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 }
99
100 // load file into ODB
101 void odb::load(const std::string &filename, const std::string &odb_path) {
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 }
121
122 // global callback function for db_watch()
123 void odb::watch_callback(int hDB, int hKey, int index, void *info) {
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 }
137
138 // create ODB key
139 int odb::create(const char *name, int type) {
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 }
148
149 // private functions ---------------------------------------------
150
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 }
158
159 void odb::odb_from_xml_remote(const std::string &str) {
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 }
197
198 void odb::odb_from_xml_string(const std::string &str, const std::string &subkey) {
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 }
240
241 std::vector<std::string> split(std::string input, char delimiter = '/') {
242 std::vector<std::string> result;
243 std::string item;
244
245 if (!input.empty() && input.front() == '/')
246 input.erase(0, 1);
247 if (!input.empty() && input.back() == '/')
248 input.pop_back();
249
250 std::stringstream ss(input);
251
252 while (std::getline(ss, item, delimiter)) {
253 result.push_back(item);
254 }
255
256 return result;
257 }
258
259 void odb::odb_from_json_string(const std::string &str, const std::string &subkey) {
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<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 == 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 }
316
317 // resize internal m_data array, keeping old values
318 void odb::resize_mdata(int size) {
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 }
340
341 // get function for strings
342 void odb::get(std::string &s, bool quotes, bool refresh) {
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 }
360
361 // public functions ----------------------------------------------
362
363 // Deep copy constructor
364 odb::odb(const odb &o) : 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 }
390
391 void odb::deep_copy(odb &d, const odb &s) {
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 }
417
418 // return full path from ODB
419 std::string odb::get_full_path() {
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 }
433
434 // return parent object
435 std::string odb::get_parent_path() {
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 }
441
442 // return size of ODB key
443 int odb::size() {
444 return m_num_values;
445 }
446
447 // Resize an ODB key
448 void odb::resize(int size) {
450 if (this->is_auto_refresh_write()) {
451 int status = db_set_num_values(s_hDB, m_hKey, size);
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 }
457
458 // Resize an ODB key with default value
459 void odb::resize(int size, bool b) {
462 if (this->is_auto_refresh_write()) {
463 int status = db_set_num_values(s_hDB, m_hKey, size);
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 }
475
476 std::string odb::print() {
477 std::string s;
478 s = "{\n";
479 print(s, 1);
480 s += "\n}";
481 return s;
482 }
483
484 std::string odb::dump() {
485 std::string s;
486 s = "{\n";
487 dump(s, 1);
488 s += "\n}";
489 return s;
490 }
491
492 // print current object with all sub-objects nicely indented
493 void odb::print(std::string &s, int indent) {
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 }
524
525 // dump current object in the same way as odbedit saves as json
526 void odb::dump(std::string &s, int indent) {
527 for (int i = 0; i < indent; i++)
528 s += " ";
529 if (m_tid == TID_KEY) {
530 s += "\"" + m_name + "\": {\n";
531 for (int i = 0; i < m_num_values; i++) {
532 std::string v;
533 m_data[i].get_odb().dump(v, indent + 1);
534 s += v;
535 if (i < m_num_values - 1)
536 s += ",\n";
537 else
538 s += "\n";
539 }
540 for (int i = 0; i < indent; i++)
541 s += " ";
542 s += "}";
543 } else {
544 KEY key;
546 s += "\"" + m_name + "/key\": ";
547 s += "{ \"type\": " + std::to_string(m_tid) + ", ";
548 s += "\"access_mode\": " + std::to_string(key.access_mode) + ", ";
549 s += "\"last_written\": " + std::to_string(key.last_written) + "},\n";
550 for (int i = 0; i < indent; i++)
551 s += " ";
552 s += "\"" + m_name + "\": ";
553 if (m_num_values > 1)
554 s += "[";
555 std::string v;
556 get(v, m_tid == TID_STRING || m_tid == TID_LINK);
557 s += v;
558 if (m_num_values > 1)
559 s += "]";
560 }
561 }
562
563 // save ODB tree into file in JSON format
564 void odb::save(const std::string &filename) {
565 std::string buffer;
566
567 std::string header = "{\n";
568 header += " \"/MIDAS version\" : \"2.1\",\n";
569 header += " \"/filename\" : \"" + filename + "\",\n";
570 header += " \"/ODB path\" : \"" + get_full_path() + "\",\n\n";
571
572 odb::dump(buffer, 1);
573
574 buffer += "\n}\n";
575
576 std::ofstream f(filename);
577 if (!f.is_open())
578 mthrow("Cannot open file \"" + filename);
579
580 f << header << buffer;
581 f.close();
582 }
583
584
585 // check if key contains a certain subkey
586 bool odb::is_subkey(std::string str) {
587 if (m_tid != TID_KEY)
588 return false;
589
590 std::string first = str;
591 std::string tail{};
592 if (str.find('/') != std::string::npos) {
593 first = str.substr(0, str.find('/'));
594 tail = str.substr(str.find('/') + 1);
595 }
596
597 int i;
598 for (i = 0; i < m_num_values; i++)
599 if (m_data[i].get_odb().get_name() == first)
600 break;
601 if (i == m_num_values)
602 return false;
603
604 if (!tail.empty())
605 return m_data[i].get_odb().is_subkey(tail);
606
607 return true;
608 }
609
610 odb &odb::get_subkey(std::string str) {
611 if (m_tid == 0) {
612 if (is_auto_create()) {
613 m_tid = TID_KEY;
614 int status = db_create_key(s_hDB, 0, m_name.c_str(), m_tid);
616 mthrow("Cannot create ODB key \"" + m_name + "\", status" + std::to_string(status));
617 db_find_key(s_hDB, 0, m_name.c_str(), &m_hKey);
618 if (s_debug) {
619 if (m_name[0] == '/')
620 std::cout << "Created ODB key \"" + m_name + "\"" << std::endl;
621 else
622 std::cout << "Created ODB key \"" + get_full_path() + "\"" << std::endl;
623 }
624 // strip path from name
625 if (m_name.find_last_of('/') != std::string::npos)
626 m_name = m_name.substr(m_name.find_last_of('/') + 1);
627 } else
628 mthrow("Invalid key \"" + m_name + "\" does not have subkeys");
629
630 }
631 if (m_tid != TID_KEY)
632 mthrow("ODB key \"" + get_full_path() + "\" does not have subkeys");
633
634 std::string first = str;
635 std::string tail{};
636 if (str.find('/') != std::string::npos) {
637 first = str.substr(0, str.find('/'));
638 tail = str.substr(str.find('/') + 1);
639 }
640
641 int i;
642 for (i = 0; i < m_num_values; i++)
643 if (equal_ustring(first.c_str(), m_data[i].get_odb().get_name().c_str()))
644 break;
645 if (i == m_num_values) {
646 if (is_auto_create()) {
647 if (m_num_values == 0) {
648 m_num_values = 1;
649 m_data = new u_odb[1]{};
650 i = 0;
651 } else {
652 // resize array
654 i = m_num_values - 1;
655 }
656 midas::odb *o = new midas::odb();
658 m_data[i].set_parent(this);
659 o->set_name(get_full_path() + "/" + str);
660 o->set_tid(0); // tid is currently undefined
661 o->set_flags(get_flags());
662 o->set_parent(this);
663 m_data[i].set(o);
664 } else
665 mthrow("ODB key \"" + get_full_path() + "\" does not contain subkey \"" + first + "\"");
666 }
667 if (!tail.empty())
668 return m_data[i].get_odb().get_subkey(tail);
669
670 return *m_data[i].get_podb();
671 }
672
673 // get number of subkeys in ODB, return number and vector of names
674 int odb::get_subkeys(std::vector<std::string> &name) {
675 if (m_tid != TID_KEY)
676 return 0;
677 if (m_hKey == 0 || m_hKey == -1)
678 mthrow("get_sub-keys called with invalid m_hKey for ODB key \"" + m_name + "\"");
679
680 // count number of subkeys in ODB
681 std::vector<HNDLE> hlist;
682 int n = 0;
683 for (int i = 0;; i++) {
684 HNDLE h;
685 int status = db_enum_key(s_hDB, m_hKey, i, &h);
686 if (status != DB_SUCCESS)
687 break;
688 KEY key;
689 db_get_key(s_hDB, h, &key);
690 hlist.push_back(h);
691 name.push_back(key.name);
692 n = i + 1;
693 }
694
695 return n;
696 }
697
698 // obtain key definition from ODB and allocate local data array
699 bool odb::read_key(const std::string &path) {
700 init_hdb();
701
702 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
703 if (status != DB_SUCCESS)
704 return false;
705
706 KEY key;
708 if (status != DB_SUCCESS)
709 mthrow("db_get_key for ODB key \"" + path +
710 "\" failed with status " + std::to_string(status));
711
712 // check for correct type if given as parameter
713 if (m_tid > 0 && m_tid != (int) key.type)
714 mthrow("ODB key \"" + get_full_path() +
715 "\" has different type than specified");
716
717 if (s_debug)
718 std::cout << "Get definition for ODB key \"" + get_full_path() + "\"" << std::endl;
719
720 m_tid = key.type;
721 m_name = key.name;
722 if (m_tid == TID_KEY) {
723
724 // merge ODB keys with local keys
725 for (int i = 0; i < m_num_values; i++) {
726 std::string p(path);
727 if (p.back() != '/')
728 p += "/";
729 p += m_data[i].get_odb().get_name();
730 HNDLE h;
731 status = db_find_key(s_hDB, 0, p.c_str(), &h);
732 if (status != DB_SUCCESS) {
733 // if key does not exist in ODB write it
734 m_data[i].get_odb().write_key(p, true);
735 m_data[i].get_odb().write();
736 } else {
737 // check key type
738 KEY key;
739 status = db_get_key(s_hDB, h, &key);
740 if (status != DB_SUCCESS)
741 mthrow("db_get_key for ODB key \"" + get_full_path() +
742 "\" failed with status " + std::to_string(status));
743 if (m_data[i].get_odb().get_tid() != (int)key.type) {
744 // write key if different
745 m_data[i].get_odb().write_key(p, true);
746 m_data[i].get_odb().write();
747 }
748 if (m_data[i].get_odb().get_tid() == TID_KEY) {
749 // update subkey structure
750 m_data[i].get_odb().read_key(p);
751 }
752 }
753 }
754
755 // read back everything from ODB
756 std::vector<std::string> name;
758 delete[] m_data;
760 for (int i = 0; i < m_num_values; i++) {
761 std::string p(path);
762 if (p.back() != '/')
763 p += "/";
764 p += name[i];
765 midas::odb *o = new midas::odb(p.c_str());
766 o->set_parent(this);
768 m_data[i].set_parent(this);
769 m_data[i].set(o);
770 }
771 } else {
773 delete[] m_data;
775 for (int i = 0; i < m_num_values; i++) {
777 m_data[i].set_parent(this);
778 }
779 }
780
781 return true;
782 }
783
784 // create key in ODB if it does not exist, otherwise check key type
785 bool odb::write_key(std::string &path, bool force_write) {
786 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
787 if (status != DB_SUCCESS) {
788 if (m_tid == 0) // auto-create subdir
789 m_tid = TID_KEY;
790 if (m_tid > 0 && m_tid < TID_LAST) {
791 status = db_create_key(s_hDB, 0, path.c_str(), m_tid);
792 if (status != DB_SUCCESS)
793 mthrow("ODB key \"" + path + "\" cannot be created");
794 status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
795 if (status != DB_SUCCESS)
796 mthrow("ODB key \"" + path + "\" not found after creation");
797 if (s_debug) {
798 if (path[0] == '/')
799 std::cout << "Created ODB key \"" + path + "\"" << std::endl;
800 else
801 std::cout << "Created ODB key \"" + get_full_path() + "\"" << std::endl;
802 }
803 } else
804 mthrow("ODB key \"" + path + "\" cannot be found");
805 return true;
806 } else {
807 KEY key;
809 if (status != DB_SUCCESS)
810 mthrow("db_get_key for ODB key \"" + path +
811 "\" failed with status " + std::to_string(status));
812 if (m_tid == 0)
813 m_tid = key.type;
814
815 // check for correct type
816 if (m_tid > 0 && m_tid != (int) key.type) {
817 if (force_write) {
818 // delete and recreate key
819 status = db_delete_key(s_hDB, m_hKey, false);
820 if (status != DB_SUCCESS)
821 mthrow("db_delete_key for ODB key \"" + path +
822 "\" failed with status " + std::to_string(status));
823 status = db_create_key(s_hDB, 0, path.c_str(), m_tid);
824 if (status != DB_SUCCESS)
825 mthrow("ODB key \"" + path + "\" cannot be created");
826 status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
827 if (status != DB_SUCCESS)
828 mthrow("ODB key \"" + path + "\" not found after creation");
829 if (s_debug)
830 std::cout << "Re-created ODB key \"" + get_full_path() << "\" with different type" << std::endl;
831 } else
832 // abort
833 mthrow("ODB key \"" + get_full_path() +
834 "\" has differnt type than specified");
835 } else if (s_debug)
836 std::cout << "Validated ODB key \"" + get_full_path() + "\"" << std::endl;
837
838 return false;
839 }
840 }
841
842
843 // retrieve data from ODB and assign it to this object
844 void odb::read() {
845 if (!is_connected_odb())
846 return;
847
848 // check if deleted
849 if (is_deleted())
850 mthrow("ODB key \"" + m_name + "\" cannot be pulled because it has been deleted");
851
852 if (m_hKey == 0)
853 return; // needed to print un-connected objects
854
855 if (m_tid == 0)
856 mthrow("Read of invalid ODB key \"" + m_name + "\"");
857
858 if (m_hKey == -1) {
859 // connect un-connected object (crated via XML)
860 std::string path = get_full_path();
861
862 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
863 if (status != DB_SUCCESS)
864 mthrow("Cannot connect key \"" + path + "\" to ODB");
865 }
866
867 int status{};
868 if (m_tid == TID_STRING) {
869 KEY key;
871 char *str = (char *) malloc(key.total_size);
872 int size = key.total_size;
874 for (int i = 0; i < m_num_values; i++)
875 m_data[i].set(str + i * key.item_size);
876 free(str);
877 } else if (m_tid == TID_KEY) {
878 std::vector<std::string> name;
879 int n = get_subkeys(name);
880 if (n != m_num_values) {
881 // if subdirs have changed, rebuild it
882 delete[] m_data;
883 m_num_values = n;
885 for (int i = 0; i < m_num_values; i++) {
886 std::string k(get_full_path());
887 k += "/" + name[i];
888 midas::odb *o = new midas::odb(k.c_str());
889 o->set_parent(this);
891 m_data[i].set_parent(this);
892 m_data[i].set(o);
893 }
894 }
895 for (int i = 0; i < m_num_values; i++)
896 m_data[i].get_odb().read();
898 } else {
899 // resize local array if number of values has changed
900 KEY key;
902 if (key.num_values != m_num_values) {
903 delete[] m_data;
906 for (int i = 0; i < m_num_values; i++) {
908 m_data[i].set_parent(this);
909 }
910 }
911
913 void *buffer = malloc(size);
914 void *p = buffer;
916 for (int i = 0; i < m_num_values; i++) {
917 if (m_tid == TID_UINT8)
918 m_data[i].set(*static_cast<uint8_t *>(p));
919 else if (m_tid == TID_INT8)
920 m_data[i].set(*static_cast<int8_t *>(p));
921 else if (m_tid == TID_UINT16)
922 m_data[i].set(*static_cast<uint16_t *>(p));
923 else if (m_tid == TID_INT16)
924 m_data[i].set(*static_cast<int16_t *>(p));
925 else if (m_tid == TID_UINT32)
926 m_data[i].set(*static_cast<uint32_t *>(p));
927 else if (m_tid == TID_INT32)
928 m_data[i].set(*static_cast<int32_t *>(p));
929 else if (m_tid == TID_UINT64)
930 m_data[i].set(*static_cast<uint64_t *>(p));
931 else if (m_tid == TID_INT64)
932 m_data[i].set(*static_cast<int64_t *>(p));
933 else if (m_tid == TID_BOOL)
934 m_data[i].set(*static_cast<bool *>(p));
935 else if (m_tid == TID_FLOAT)
936 m_data[i].set(*static_cast<float *>(p));
937 else if (m_tid == TID_DOUBLE)
938 m_data[i].set(*static_cast<double *>(p));
939 else if (m_tid == TID_STRING)
940 m_data[i].set(std::string(static_cast<const char *>(p)));
941 else if (m_tid == TID_LINK)
942 m_data[i].set(std::string(static_cast<const char *>(p)));
943 else
944 mthrow("Invalid type ID " + std::to_string(m_tid));
945
946 p = static_cast<char *>(p) + rpc_tid_size(m_tid);
947 }
948 free(buffer);
949 }
950
951 if (status != DB_SUCCESS)
952 mthrow("db_get_data for ODB key \"" + get_full_path() +
953 "\" failed with status " + std::to_string(status));
954 if (s_debug) {
955 if (m_tid == TID_KEY) {
956 std::cout << "Get ODB key \"" + get_full_path() + "[0..." +
957 std::to_string(m_num_values - 1) + "]\"" << std::endl;
958 } else {
959 std::string s;
960 get(s, false, false);
961 if (m_num_values > 1) {
962 if (m_tid == TID_STRING || m_tid == TID_LINK)
963 std::cout << "Get ODB key \"" + get_full_path() + "[0..." +
964 std::to_string(m_num_values - 1) + "]\": [\"" + s + "\"]" << std::endl;
965 else
966 std::cout << "Get ODB key \"" + get_full_path() + "[0..." +
967 std::to_string(m_num_values - 1) + "]\": [" + s + "]" << std::endl;
968 } else {
969 if (m_tid == TID_STRING || m_tid == TID_LINK)
970 std::cout << "Get ODB key \"" + get_full_path() + "\": \"" + s + "\"" << std::endl;
971 else
972 std::cout << "Get ODB key \"" + get_full_path() + "\": " + s << std::endl;
973 }
974 }
975 }
976 }
977
978 // retrieve individual member of array
979 void odb::read(int index) {
980 if (!is_connected_odb())
981 return;
982
983 if (m_hKey == 0 || m_hKey == -1)
984 return; // needed to print un-connected objects
985
986 if (m_tid == 0)
987 mthrow("Pull of invalid ODB key \"" + m_name + "\"");
988
989 int status{};
990 if (m_tid == TID_STRING || m_tid == TID_LINK) {
991 KEY key;
993 char *str = (char *) malloc(key.item_size);
994 int size = key.item_size;
997 free(str);
998 } else if (m_tid == TID_KEY) {
1001 } else {
1002 int size = rpc_tid_size(m_tid);
1003 void *buffer = malloc(size);
1004 void *p = buffer;
1006 if (m_tid == TID_UINT8)
1007 m_data[index].set(*static_cast<uint8_t *>(p));
1008 else if (m_tid == TID_INT8)
1009 m_data[index].set(*static_cast<int8_t *>(p));
1010 else if (m_tid == TID_UINT16)
1011 m_data[index].set(*static_cast<uint16_t *>(p));
1012 else if (m_tid == TID_INT16)
1013 m_data[index].set(*static_cast<int16_t *>(p));
1014 else if (m_tid == TID_UINT32)
1015 m_data[index].set(*static_cast<uint32_t *>(p));
1016 else if (m_tid == TID_INT32)
1017 m_data[index].set(*static_cast<int32_t *>(p));
1018 else if (m_tid == TID_UINT64)
1019 m_data[index].set(*static_cast<uint64_t *>(p));
1020 else if (m_tid == TID_INT64)
1021 m_data[index].set(*static_cast<int64_t *>(p));
1022 else if (m_tid == TID_BOOL)
1023 m_data[index].set(*static_cast<bool *>(p));
1024 else if (m_tid == TID_FLOAT)
1025 m_data[index].set(*static_cast<float *>(p));
1026 else if (m_tid == TID_DOUBLE)
1027 m_data[index].set(*static_cast<double *>(p));
1028 else if (m_tid == TID_STRING)
1029 m_data[index].set(std::string(static_cast<const char *>(p)));
1030 else if (m_tid == TID_LINK)
1031 m_data[index].set(std::string(static_cast<const char *>(p)));
1032 else
1033 mthrow("Invalid type ID " + std::to_string(m_tid));
1034
1035 free(buffer);
1036 }
1037
1038 if (status != DB_SUCCESS)
1039 mthrow("db_get_data for ODB key \"" + get_full_path() +
1040 "\" failed with status " + std::to_string(status));
1041 if (s_debug) {
1042 std::string s;
1043 m_data[index].get(s);
1044 if (m_tid == TID_STRING || m_tid == TID_LINK)
1045 std::cout << "Get ODB key \"" + get_full_path() + "[" +
1046 std::to_string(index) + "]\": [\"" + s + "\"]" << std::endl;
1047 else
1048 std::cout << "Get ODB key \"" + get_full_path() + "[" +
1049 std::to_string(index) + "]\": [" + s + "]" << std::endl;
1050 }
1051 }
1052
1053 // push individual member of an array
1054 void odb::write(int index, int str_size) {
1055 if (!is_connected_odb())
1056 return;
1057
1058 if (m_hKey == -1) {
1059 // connect un-connected object (crated via XML)
1060 std::string path = get_full_path();
1061
1062 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
1063 if (status != DB_SUCCESS)
1064 mthrow("Cannot connect key \"" + path + "\" to ODB");
1065
1066 } else if (m_hKey == 0) {
1067 if (is_auto_create()) {
1068 std::string to_create = m_name[0] == '/' ? m_name : get_full_path();
1069 int status = db_create_key(s_hDB, 0, to_create.c_str(), m_tid);
1071 mthrow("Cannot create ODB key \"" + to_create + "\", status =" + std::to_string(status));
1072 db_find_key(s_hDB, 0, to_create.c_str(), &m_hKey);
1073 if (s_debug) {
1074 std::cout << "Created ODB key \"" + to_create + "\"" << std::endl;
1075 }
1076 // strip path from name
1077 if (m_name.find_last_of('/') != std::string::npos)
1078 m_name = m_name.substr(m_name.find_last_of('/') + 1);
1079 } else
1080 mthrow("Write of un-connected ODB key \"" + m_name + "\" not possible");
1081 }
1082
1083 // don't write keys
1084 if (m_tid == TID_KEY)
1085 return;
1086
1087 int status{};
1088 if (m_tid == TID_STRING || m_tid == TID_LINK) {
1089 KEY key;
1091 std::string s;
1092 m_data[index].get(s);
1093 if (m_num_values == 1) {
1094 int size = key.item_size;
1095 if (key.item_size == 0 || !is_preserve_string_size())
1096 size = s.size() + 1;
1097 if (str_size > 0)
1098 size = str_size;
1099 char *ss = (char *)malloc(size+1);
1100 mstrlcpy(ss, s.c_str(), size);
1101 if (is_trigger_hotlink())
1103 else
1105 free(ss);
1106 } else {
1107 if (key.item_size == 0)
1108 key.item_size = s.size() + 1;
1109 if (str_size > 0) {
1110 if (key.item_size > 0 && key.item_size != str_size) {
1111 std::cout << "ODB string size mismatch for \"" << get_full_path() <<
1112 "\" (" << key.item_size << " vs " << str_size << "). ODB key recreated."
1113 << std::endl;
1114 if (is_trigger_hotlink())
1115 status = db_set_data(s_hDB, m_hKey, s.c_str(), str_size, 1, m_tid);
1116 else
1117 status = db_set_data1(s_hDB, m_hKey, s.c_str(), str_size, 1, m_tid);
1118 }
1120 }
1122 }
1123 if (s_debug) {
1124 if (m_num_values > 1)
1125 std::cout << "Set ODB key \"" + get_full_path() + "[" + std::to_string(index) + "]\" = \"" + s
1126 + "\"" << std::endl;
1127 else
1128 std::cout << "Set ODB key \"" + get_full_path() + "\" = \"" + s + "\""<< std::endl;
1129 }
1130 } else {
1131 u_odb u = m_data[index];
1132 if (m_tid == TID_BOOL) {
1133 u.set_parent(nullptr);
1134 BOOL b = static_cast<bool>(u); // "bool" is only 1 Byte, BOOL is 4 Bytes
1136 } else {
1138 }
1139 if (s_debug) {
1140 std::string s;
1141 u.get(s);
1142 if (m_num_values > 1)
1143 std::cout << "Set ODB key \"" + get_full_path() + "[" + std::to_string(index) + "]\" = " + s
1144 << std::endl;
1145 else
1146 std::cout << "Set ODB key \"" + get_full_path() + "\" = " + s << std::endl;
1147 }
1148 }
1149 if (status != DB_SUCCESS)
1150 mthrow("db_set_data_index for ODB key \"" + get_full_path() +
1151 "\" failed with status " + std::to_string(status));
1152 }
1153
1154 // write all members of an array to the ODB
1156
1157 // check if deleted
1158 if (is_deleted())
1159 mthrow("ODB key \"" + m_name + "\" cannot be written because it has been deleted");
1160
1161 // write subkeys
1162 if (m_tid == TID_KEY) {
1163 for (int i = 0; i < m_num_values; i++)
1164 m_data[i].get_odb().write();
1165 return;
1166 }
1167
1168 if (m_tid == 0 && m_data[0].get_tid() != 0)
1169 m_tid = m_data[0].get_tid();
1170
1172 mthrow("Invalid TID for ODB key \"" + get_full_path() + "\"");
1173
1174 if ((m_hKey == 0 || m_hKey == -1) && !is_auto_create())
1175 mthrow("Writing ODB key \"" + m_name +
1176 "\" is not possible because of invalid key handle");
1177
1178 // if index operator [] returned previously a certain index, write only this one
1179 if (m_last_index != -1) {
1181 m_last_index = -1;
1182 return;
1183 }
1184
1185 if (m_num_values == 1) {
1186 write(0, str_size);
1187 return;
1188 }
1189
1190 if (m_hKey == -1) {
1191 // connect un-connected object (crated via XML)
1192 std::string path = get_full_path();
1193
1194 int status = db_find_key(s_hDB, 0, path.c_str(), &m_hKey);
1195 if (status != DB_SUCCESS)
1196 mthrow("Cannot connect key \"" + path + "\" to ODB");
1197
1198 } else if (m_hKey == 0) {
1199 if (is_auto_create()) {
1200 std::string to_create = m_name[0] == '/' ? m_name : get_full_path();
1201 int status = db_create_key(s_hDB, 0, to_create.c_str(), m_tid);
1203 mthrow("Cannot create ODB key \"" + to_create + "\", status" + std::to_string(status));
1204 db_find_key(s_hDB, 0, to_create.c_str(), &m_hKey);
1205 if (s_debug) {
1206 std::cout << "Created ODB key \"" + to_create + "\"" << std::endl;
1207 }
1208 // strip path from name
1209 if (m_name.find_last_of('/') != std::string::npos)
1210 m_name = m_name.substr(m_name.find_last_of('/') + 1);
1211 } else
1212 mthrow("Write of un-connected ODB key \"" + m_name + "\" not possible");
1213 }
1214
1215 int status{};
1216 if (m_tid == TID_STRING || m_tid == TID_LINK) {
1218 KEY key;
1220 if (key.item_size == 0 || key.total_size == 0) {
1221 int size = 1;
1222 for (int i = 0; i < m_num_values; i++) {
1223 std::string d;
1224 m_data[i].get(d);
1225 if ((int) d.size() + 1 > size)
1226 size = d.size() + 1;
1227 }
1228 // round up to multiples of 32
1229 size = (((size - 1) / 32) + 1) * 32;
1230 key.item_size = size;
1232 }
1233 char *str = (char *) calloc(m_num_values, key.item_size);
1234 for (int i = 0; i < m_num_values; i++) {
1235 std::string d;
1236 m_data[i].get(d);
1237 strncpy(str + i * key.item_size, d.c_str(), key.item_size);
1238 }
1239 if (is_trigger_hotlink())
1241 else
1243 free(str);
1244 if (s_debug) {
1245 std::string s;
1246 get(s, true, false);
1247 std::cout << "Set ODB key \"" + get_full_path() +
1248 "[0..." + std::to_string(m_num_values - 1) + "]\" = [" + s + "]" << std::endl;
1249 }
1250 } else {
1251 std::string s;
1252 m_data[0].get(s);
1253 if (is_trigger_hotlink())
1254 status = db_set_data(s_hDB, m_hKey, s.c_str(), s.length() + 1, 1, m_tid);
1255 else
1256 status = db_set_data1(s_hDB, m_hKey, s.c_str(), s.length() + 1, 1, m_tid);
1257 if (s_debug)
1258 std::cout << "Set ODB key \"" + get_full_path() + "\" = " + s << std::endl;
1259 }
1260 } else {
1262 uint8_t *buffer = (uint8_t *) malloc(size);
1263 uint8_t *p = buffer;
1264 for (int i = 0; i < m_num_values; i++) {
1265 if (m_tid == TID_BOOL) {
1266 // bool has 1 Byte, BOOL has 4 Bytes
1267 BOOL b = static_cast<bool>(m_data[i]);
1268 memcpy(p, &b, rpc_tid_size(m_tid));
1269 } else {
1270 memcpy(p, (void*)&m_data[i], rpc_tid_size(m_tid));
1271 }
1272 p += rpc_tid_size(m_tid);
1273 }
1274 if (is_trigger_hotlink())
1276 else
1278 free(buffer);
1279 if (s_debug) {
1280 std::string s;
1281 get(s, false, false);
1282 if (m_num_values > 1)
1283 std::cout << "Set ODB key \"" + get_full_path() + "[0..." + std::to_string(m_num_values - 1) +
1284 "]\" = [" + s + "]" << std::endl;
1285 else
1286 std::cout << "Set ODB key \"" + get_full_path() + "\" = " + s << std::endl;
1287 }
1288 }
1289
1290 if (status != DB_SUCCESS)
1291 mthrow("db_set_data for ODB key \"" + get_full_path() +
1292 "\" failed with status " + std::to_string(status));
1293 }
1294
1296 // Delete any subkeys that are not in the list of defaults.
1297 KEY key;
1298 db_get_key(hDB, hKey, &key);
1299
1300 if (key.type == TID_KEY) {
1301 std::vector<std::string> to_delete;
1302
1303 for (int i = 0;; i++) {
1304 HNDLE hSubKey;
1305 int status = db_enum_key(hDB, hKey, i, &hSubKey);
1306 if (status != DB_SUCCESS)
1307 break;
1308
1309 KEY subKey;
1311 std::string full_path = path + "/" + subKey.name;
1312
1313 if (!default_odb.is_subkey(subKey.name)) {
1314 to_delete.push_back(subKey.name);
1315
1316 if (default_odb.get_debug()) {
1317 std::cout << "Deleting " << full_path << " as not in list of defaults" << std::endl;
1318 }
1319 } else if (key.type == TID_KEY) {
1321 }
1322 }
1323
1324 for (auto name : to_delete) {
1325 HNDLE hSubKey;
1326 db_find_key(hDB, hKey, name.c_str(), &hSubKey);
1328 }
1329 }
1330 }
1331
1332 void recurse_get_defaults_order(std::string path, midas::odb& default_odb, std::map<std::string, std::vector<std::string> >& retval) {
1333 for (midas::odb& sub : default_odb) {
1334 if (sub.get_tid() == TID_KEY) {
1335 recurse_get_defaults_order(path + "/" + sub.get_name(), sub, retval);
1336 }
1337
1338 retval[path].push_back(sub.get_name());
1339 }
1340 }
1341
1342 void recurse_fix_order(midas::odb& default_odb, std::map<std::string, std::vector<std::string> >& user_order) {
1343 std::string path = default_odb.get_full_path();
1344
1345 if (user_order.find(path) != user_order.end()) {
1346 default_odb.fix_order(user_order[path]);
1347 }
1348
1349 for (midas::odb& it : default_odb) {
1350 if (it.get_tid() == TID_KEY) {
1352 }
1353 }
1354 }
1355
1356 void odb::fix_order(std::vector<std::string> target_order) {
1357 // Fix the order of ODB keys to match that specified in target_order.
1358 // The in-ODB representation is simple, as we can just use db_reorder_key()
1359 // on anything that's in the wrong place.
1360 // The in-memory representation is a little trickier, but we just copy raw
1361 // memory into a temporary array, so we don't have to delete/recreate the
1362 // u_odb objects.
1363 std::vector<std::string> curr_order;
1364
1365 if (get_subkeys(curr_order) <= 0) {
1366 // Not a TID_KEY (or no keys)
1367 return;
1368 }
1369
1370 if (target_order.size() != curr_order.size() || (int)target_order.size() != m_num_values) {
1371 return;
1372 }
1373
1374 HNDLE hKey = get_hkey();
1375 bool force_order = false;
1376
1377 // Temporary location where we'll store in-memory u_odb objects in th
1378 // correct order.
1380
1381 for (int i = 0; i < m_num_values; i++) {
1382 if (force_order || curr_order[i] != target_order[i]) {
1383 force_order = true;
1384 HNDLE hSubKey;
1385
1386 // Fix the order in the ODB
1389 }
1390
1391 // Fix the order in memory
1392 auto curr_it = std::find(curr_order.begin(), curr_order.end(), target_order[i]);
1393
1394 if (curr_it == curr_order.end()) {
1395 // Logic error - bail to avoid doing any damage to the in-memory version.
1396 delete[] new_m_data;
1397 return;
1398 }
1399
1400 int curr_idx = curr_it - curr_order.begin();
1402 }
1403
1404 // Final update of the in-memory version so they are in the correct order
1405 for (int i = 0; i < m_num_values; i++) {
1406 m_data[i] = new_m_data[i];
1407
1408 // Nullify pointers that point to the same object in
1409 // m_data and new_m_data, so the underlying object doesn't
1410 // get destroyed when we delete new_m_data.
1411 new_m_data[i].set_string_ptr(nullptr);
1412 new_m_data[i].set_odb(nullptr);
1413 }
1414
1415 delete[] new_m_data;
1416 }
1417
1418 // connect function with separated path and key name
1419 void odb::connect(const std::string &p, const std::string &name, bool write_defaults, bool delete_keys_not_in_defaults) {
1420 init_hdb();
1421
1422 if (!name.empty())
1423 m_name = name;
1424 std::string path(p);
1425
1426 if (path.empty())
1427 mthrow("odb::connect() cannot be called with an empty ODB path");
1428
1429 if (path[0] != '/')
1430 mthrow("odb::connect(\"" + path + "\"): path must start with leading \"/\"");
1431
1432 if (path.back() != '/')
1433 path += "/";
1434
1435 path += m_name;
1436
1437 HNDLE hKey;
1438 int status = db_find_key(s_hDB, 0, path.c_str(), &hKey);
1439 bool key_exists = (status == DB_SUCCESS);
1440 bool created = false;
1441
1443 // Recurse down to delete keys as needed.
1444 // We need to do this recursively BEFORE calling read/read_key for the first time
1445 // to ensure that subdirectories get handled correctly.
1447 }
1448
1449 if (!key_exists || write_defaults) {
1451 } else {
1452 read_key(path);
1453 }
1454
1455 // correct wrong parent ODB from initializer_list
1456 for (int i = 0; i < m_num_values; i++)
1457 m_data[i].set_parent(this);
1458
1459 if (m_tid == TID_KEY) {
1460 for (int i = 0; i < m_num_values; i++)
1461 m_data[i].get_odb().connect(get_full_path(), m_data[i].get_odb().get_name(), write_defaults);
1462 } else if (created || write_defaults) {
1463 write();
1464 } else {
1465 read();
1466 }
1467 }
1468
1469 // send key definitions and data with optional subkeys to certain path in ODB
1471
1472 if (str.empty())
1473 mthrow("odb::connect() cannot be called with an empty ODB path");
1474
1475 if (str[0] != '/')
1476 mthrow("odb::connect(\"" + str + "\"): path must start with leading \"/\"");
1477
1478 if (str == "/")
1479 mthrow("odb::connect(\"" + str + "\"): root ODB tree is not allowed");
1480
1481 if (str.back() == '/')
1482 str = str.substr(0, str.size()-1);
1483
1484 // separate ODB path and key nam
1485 std::string name;
1486 std::string path;
1487 name = str.substr(str.find_last_of('/') + 1);
1488 path = str.substr(0, str.find_last_of('/') + 1);
1489
1491 }
1492
1493 // shorthand for the same behavior as db_check_record:
1494 // - keep values of keys that already exist with the correct type
1495 // - add keys that user provided but aren't in ODB already
1496 // - delete keys that are in ODB but not in user's settings
1497 // - re-order ODB keys to match user's order
1498 void odb::connect_and_fix_structure(std::string path) {
1499 // Store the order the user specified.
1500 // Need to do this recursively before calling connect(), as the first
1501 // read() in that function merges user keys and existing keys.
1502 std::map<std::string, std::vector<std::string> > user_order;
1504
1505 // Main connect() that adds/deletes/updates keys as needed.
1506 connect(path, false, true);
1507
1508 // Fix order in ODB (and memory)
1510 }
1511
1513 init_hdb();
1514
1516
1517 if (this->is_write_protect())
1518 mthrow("Cannot modify write protected key \"" + m_name + "\"");
1519
1520
1521 // delete key in ODB
1523 if (status != DB_SUCCESS && status != DB_INVALID_HANDLE)
1524 mthrow("db_delete_key for ODB key \"" + m_name +
1525 "\" returnd error code " + std::to_string(status));
1526
1527 if (s_debug)
1528 std::cout << "Deleted ODB key \"" + m_name + "\"" << std::endl;
1529
1530 // invalidate this object
1531 delete[] m_data;
1532 m_data = nullptr;
1533 m_num_values = 0;
1534 m_tid = 0;
1535 m_hKey = 0;
1536
1537 // set flag that this object has been deleted
1538 set_deleted(true);
1539 }
1540
1542 // set mode of ODB key
1543 // default is MODE_READ | MODE_WRITE | MODE_DELETE
1544
1545 init_hdb();
1546
1547 // set mode in ODB
1549
1551 mthrow("db_set_mode for ODB key \"" + get_full_path() +
1552 "\" returnd error code " + std::to_string(status));
1553
1554 if (s_debug)
1555 std::cout << "Set mode of ODB key \"" + get_full_path() + "\" to " << mode << std::endl;
1556 }
1557
1559 init_hdb();
1560
1561 // set mode in ODB
1562 KEY key;
1563 int status = db_get_key(s_hDB, m_hKey, &key);
1564
1566 mthrow("db_get_key for ODB key \"" + get_full_path() +
1567 "\" returnd error code " + std::to_string(status));
1568
1569 return key.access_mode;
1570 }
1571
1572 unsigned int odb::get_last_written() {
1573 init_hdb();
1574
1575 // set mode in ODB
1576 KEY key;
1577 int status = db_get_key(s_hDB, m_hKey, &key);
1578
1580 mthrow("db_get_key for ODB key \"" + get_full_path() +
1581 "\" returnd error code " + std::to_string(status));
1582
1583 return (unsigned int) (key.last_written);
1584 }
1585
1586 void odb::watch(std::function<void(midas::odb &)> f) {
1587 if (m_hKey == 0 || m_hKey == -1)
1588 mthrow("watch() called for ODB key \"" + m_name +
1589 "\" which is not connected to ODB");
1590
1591 // create a deep copy of current object in case it
1592 // goes out of scope
1593 midas::odb* ow = new midas::odb(*this);
1594
1595 ow->m_watch_callback = f;
1597
1598 // put object into watchlist
1599 g_watchlist.push_back(ow);
1600 }
1601
1603 {
1604 for (int i=0 ; i<(int) g_watchlist.size() ; i++) {
1605 if (g_watchlist[i]->get_hkey() == this->get_hkey()) {
1606 db_unwatch(s_hDB, g_watchlist[i]->get_hkey());
1607 delete g_watchlist[i];
1608 g_watchlist.erase(g_watchlist.begin() + i);
1609 i--;
1610 }
1611 }
1612 }
1613
1615 {
1616 for (int i=0 ; i<(int) g_watchlist.size() ; i++) {
1618 delete g_watchlist[i];
1619 }
1620 g_watchlist.clear();
1621 }
1622
1623 void odb::set(std::string s)
1624 {
1625 if (this->is_write_protect())
1626 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1627
1628 if (m_tid == TID_BOOL)
1629 s = (s == "y" || s == "1") ? "1" : "0";
1630
1631 m_num_values = 1;
1632 m_data = new u_odb[1];
1633 m_data[0].set_parent(this);
1634 m_data[0].set_tid(m_tid);
1635 m_data[0].set(s);
1636 }
1637
1638 void odb::set(std::string s, int i)
1639 {
1640 if (this->is_write_protect())
1641 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1642
1643 if (m_tid == TID_BOOL)
1644 s = (s == "y" || s == "1") ? "1" : "0";
1645
1646 if (m_data == nullptr)
1647 m_data = new u_odb[m_num_values];
1648 m_data[i].set_parent(this);
1650 m_data[i].set(s);
1651 }
1652
1653 void odb::set_string_size(std::string s, int size)
1654 {
1655 if (this->is_write_protect())
1656 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1657
1658 m_num_values = 1;
1659 m_tid = TID_STRING;
1660 m_data = new u_odb[1];
1661 m_data[0].set_parent(this);
1662 m_data[0].set_tid(m_tid);
1665 }
1666
1667 void odb::set_odb(odb *o, int i)
1668 {
1669 if (this->is_write_protect())
1670 mthrow("Cannot modify write protected key \"" + get_full_path() + "\"");
1671
1672 if (m_data == nullptr)
1673 m_data = new u_odb[m_num_values];
1674 m_data[i].set_parent(this);
1676 m_data[i].set_odb(o);
1677 }
1678
1679 //-----------------------------------------------
1680
1681 //---- u_odb implementations calling functions from odb
1682
1684 if (m_tid == TID_STRING || m_tid == TID_LINK)
1685 delete m_string;
1686 else if (m_tid == TID_KEY)
1687 delete m_odb;
1688 }
1689
1690 // get function for strings
1691 void u_odb::get(std::string &s) {
1692 if (m_tid == TID_UINT8)
1693 s = std::to_string(m_uint8);
1694 else if (m_tid == TID_INT8)
1695 s = std::to_string(m_int8);
1696 else if (m_tid == TID_UINT16)
1697 s = std::to_string(m_uint16);
1698 else if (m_tid == TID_INT16)
1699 s = std::to_string(m_int16);
1700 else if (m_tid == TID_UINT32)
1701 s = std::to_string(m_uint32);
1702 else if (m_tid == TID_INT32)
1703 s = std::to_string(m_int32);
1704 else if (m_tid == TID_UINT64)
1705 s = std::to_string(m_uint64);
1706 else if (m_tid == TID_INT64)
1707 s = std::to_string(m_int64);
1708 else if (m_tid == TID_BOOL)
1709 s = std::string(m_bool ? "true" : "false");
1710 else if (m_tid == TID_FLOAT)
1711 s = std::to_string(m_float);
1712 else if (m_tid == TID_DOUBLE)
1713 s = std::to_string(m_double);
1714 else if (m_tid == TID_STRING)
1715 s = *m_string;
1716 else if (m_tid == TID_LINK)
1717 s = *m_string;
1718 else if (m_tid == TID_KEY)
1719 m_odb->print(s, 0);
1720 else if (m_tid == 0)
1721 mthrow("Subkey \"" + m_parent_odb->get_name() + "\" not found");
1722 else
1723 mthrow("Invalid type ID " + std::to_string(m_tid));
1724 }
1725
1726 //---- u_odb assignment and arithmetic operators overloads which call odb::write()
1727
1728 // overload assignment operators
1730 if (m_tid == 0)
1731 m_tid = TID_UINT8;
1732 set(v);
1735 return v;
1736 }
1738 if (m_tid == 0)
1739 m_tid = TID_INT8;
1740 set(v);
1743 return v;
1744 }
1746 if (m_tid == 0)
1747 m_tid = TID_UINT16;
1748 set(v);
1751 return v;
1752 }
1754 if (m_tid == 0)
1755 m_tid = TID_INT16;
1756 set(v);
1759 return v;
1760 }
1762 if (m_tid == 0)
1763 m_tid = TID_UINT32;
1764 set(v);
1767 return v;
1768 }
1770 if (m_tid == 0)
1771 m_tid = TID_INT32;
1772 set(v);
1775 return v;
1776 }
1778 if (m_tid == 0)
1779 m_tid = TID_UINT64;
1780 set(v);
1783 return v;
1784 }
1786 if (m_tid == 0)
1787 m_tid = TID_INT64;
1788 set(v);
1791 return v;
1792 }
1793 bool u_odb::operator=(bool v) {
1794 if (m_tid == 0)
1795 m_tid = TID_BOOL;
1796 set(v);
1799 return v;
1800 }
1801 float u_odb::operator=(float v) {
1802 if (m_tid == 0)
1803 m_tid = TID_FLOAT;
1804 set(v);
1807 return v;
1808 }
1809 double u_odb::operator=(double v) {
1810 if (m_tid == 0)
1811 m_tid = TID_DOUBLE;
1812 set(v);
1815 return v;
1816 }
1817 const char * u_odb::operator=(const char * v) {
1818 if (m_tid == 0)
1819 m_tid = TID_STRING;
1820 set(v);
1823 return v;
1824 }
1825
1826 std::string * u_odb::operator=(std::string * v){
1827 if (m_tid == 0)
1828 m_tid = TID_STRING;
1829 set(*v);
1832 return v;
1833 }
1834
1835 std::string u_odb::operator=(std::string v){
1836 if (m_tid == 0)
1837 m_tid = TID_STRING;
1838 set(v);
1841 return v;
1842 }
1843
1844 void u_odb::set_string_size(std::string v, int size) {
1845 m_tid = TID_STRING;
1846 set(v);
1848 m_parent_odb->write(size);
1849 }
1850
1851 // overload all standard conversion operators
1852 u_odb::operator uint8_t() {
1853 if (m_parent_odb)
1854 m_parent_odb->set_last_index(-1);
1855 return get<uint8_t>();
1856 }
1857 u_odb::operator int8_t() {
1858 if (m_parent_odb)
1859 m_parent_odb->set_last_index(-1);
1860 return get<int8_t>();
1861 }
1862 u_odb::operator uint16_t() {
1863 if (m_parent_odb)
1864 m_parent_odb->set_last_index(-1);
1865 return get<uint16_t>();
1866 }
1867 u_odb::operator int16_t() {
1868 if (m_parent_odb)
1869 m_parent_odb->set_last_index(-1);
1870 return get<int16_t>();
1871 }
1872 u_odb::operator uint32_t() {
1873 if (m_parent_odb)
1874 m_parent_odb->set_last_index(-1);
1875 return get<uint32_t>();
1876 }
1877 u_odb::operator int32_t() {
1878 if (m_parent_odb)
1879 m_parent_odb->set_last_index(-1);
1880 return get<int32_t>();
1881 }
1882 u_odb::operator uint64_t() {
1883 if (m_parent_odb)
1884 m_parent_odb->set_last_index(-1);
1885 return get<uint64_t>();
1886 }
1887 u_odb::operator int64_t() {
1888 if (m_parent_odb)
1889 m_parent_odb->set_last_index(-1);
1890 return get<int64_t>();
1891 }
1892 u_odb::operator bool() {
1893 if (m_parent_odb)
1894 m_parent_odb->set_last_index(-1);
1895 return get<bool>();
1896 }
1897 u_odb::operator float() {
1898 if (m_parent_odb)
1899 m_parent_odb->set_last_index(-1);
1900 return get<float>();
1901 }
1902 u_odb::operator double() {
1903 if (m_parent_odb)
1904 m_parent_odb->set_last_index(-1);
1905 return get<double>();
1906 }
1907 u_odb::operator std::string() {
1908 if (m_parent_odb)
1909 m_parent_odb->set_last_index(-1);
1910 std::string s;
1911 get(s);
1912 return s;
1913 }
1914 u_odb::operator const char *() {
1915 if (m_parent_odb)
1916 m_parent_odb->set_last_index(-1);
1917 if (m_tid != TID_STRING && m_tid != TID_LINK)
1918 mthrow("Only ODB string keys can be converted to \"const char *\"");
1919 return m_string->c_str();
1920 }
1921 u_odb::operator midas::odb&() {
1922 if (m_parent_odb)
1923 m_parent_odb->set_last_index(-1);
1924 if (m_tid != TID_KEY)
1925 mthrow("Only ODB directories can be converted to \"midas::odb &\"");
1926 return *m_odb;
1927 }
1928
1929
1930 void u_odb::add(double inc, bool write) {
1931 if (m_tid == TID_UINT8)
1932 m_uint8 += inc;
1933 else if (m_tid == TID_INT8)
1934 m_int8 += inc;
1935 else if (m_tid == TID_UINT16)
1936 m_uint16 += inc;
1937 else if (m_tid == TID_INT16)
1938 m_int16 += inc;
1939 else if (m_tid == TID_UINT32)
1940 m_uint32 += inc;
1941 else if (m_tid == TID_INT32)
1942 m_int32 += inc;
1943 else if (m_tid == TID_FLOAT)
1944 m_float += static_cast<float>(inc);
1945 else if (m_tid == TID_DOUBLE)
1946 m_double += inc;
1947 else
1948 mthrow("Invalid arithmetic operation for ODB key \"" +
1949 m_parent_odb->get_full_path() + "\"");
1952 }
1953
1954 void u_odb::mult(double f, bool write) {
1955 int tid = m_parent_odb->get_tid();
1956 if (tid == TID_UINT8)
1957 m_uint8 *= f;
1958 else if (tid == TID_INT8)
1959 m_int8 *= f;
1960 else if (tid == TID_UINT16)
1961 m_uint16 *= f;
1962 else if (tid == TID_INT16)
1963 m_int16 *= f;
1964 else if (tid == TID_UINT32)
1965 m_uint32 *= f;
1966 else if (tid == TID_INT32)
1967 m_int32 *= f;
1968 else if (tid == TID_FLOAT)
1969 m_float *= f;
1970 else if (tid == TID_DOUBLE)
1971 m_double *= f;
1972 else
1973 mthrow("Invalid operation for ODB key \"" +
1974 m_parent_odb->get_full_path() + "\"");
1977 }
1978
1979}; // namespace midas
#define FALSE
Definition cfortran.h:309
void set_string_size(std::string s, int size)
Definition odbxx.cxx:1653
std::string get_parent_path()
Definition odbxx.cxx:435
std::string get_full_path()
Definition odbxx.cxx:419
void set(std::string str)
Definition odbxx.cxx:1623
int m_num_values
Definition odbxx.h:467
static bool exists(const std::string &name)
Definition odbxx.cxx:75
std::string get_name()
Definition odbxx.h:1440
void write(int str_size=0)
Definition odbxx.cxx:1155
int m_tid
Definition odbxx.h:461
void set_mode(int mode)
Definition odbxx.cxx:1541
void set_auto_refresh_read(bool f)
Definition odbxx.h:1346
void set_auto_enlarge_array(bool f)
Definition odbxx.h:1367
void delete_key()
Definition odbxx.cxx:1512
void set_odb(odb *o, int i)
Definition odbxx.cxx:1667
u_odb * m_data
Definition odbxx.h:463
void deep_copy(odb &d, const odb &s)
Definition odbxx.cxx:391
bool is_deleted() const
Definition odbxx.h:528
bool is_auto_refresh_read() const
Definition odbxx.h:1345
static void unwatch_all()
Definition odbxx.cxx:1614
static HNDLE s_hDB
Definition odbxx.h:450
HNDLE get_hkey()
Definition odbxx.h:1435
std::function< void(midas::odb &)> m_watch_callback
Definition odbxx.h:473
bool is_auto_create() const
Definition odbxx.h:1360
bool is_preserve_string_size() const
Definition odbxx.h:1339
static void watch_callback(int hDB, int hKey, int index, void *info)
Definition odbxx.cxx:123
void unwatch()
Definition odbxx.cxx:1602
T get()
Definition odbxx.h:492
int get_tid()
Definition odbxx.h:1438
bool is_auto_refresh_write() const
Definition odbxx.h:1351
bool read_key(const std::string &path)
Definition odbxx.cxx:699
static std::string s_odb_source_str
Definition odbxx.h:448
void resize(int size)
Definition odbxx.cxx:448
void set_preserve_string_size(bool f)
Definition odbxx.h:1340
void set_trigger_hotlink(bool f)
Definition odbxx.h:1379
int size()
Definition odbxx.cxx:443
void set_auto_refresh_write(bool f)
Definition odbxx.h:1352
int get_mode()
Definition odbxx.cxx:1558
void odb_from_xml_remote(const std::string &str)
Definition odbxx.cxx:159
void set_auto_create(bool f)
Definition odbxx.h:1361
void odb_from_xml_string(const std::string &str, const std::string &subkey)
Definition odbxx.cxx:198
void read()
Definition odbxx.cxx:844
void resize_mdata(int size)
Definition odbxx.cxx:318
odb & get_subkey(std::string str)
Definition odbxx.cxx:610
void odb_from_json_string(const std::string &str, const std::string &subkey)
Definition odbxx.cxx:259
void set_flags_recursively(uint32_t f)
Definition odbxx.cxx:151
unsigned int get_last_written()
Definition odbxx.cxx:1572
midas::odb * odb_from_json(const MJsonNode *node, std::string name, int tid, odb *o)
Definition odbxx.h:1262
int get_subkeys(std::vector< std::string > &name)
Definition odbxx.cxx:674
void watch(std::function< void(midas::odb &)> f)
Definition odbxx.cxx:1586
std::string s()
Definition odbxx.h:1443
void save(const std::string &filename)
Definition odbxx.cxx:564
void set_last_index(int i)
Definition odbxx.h:999
static int create(const char *name, int type=TID_KEY)
Definition odbxx.cxx:139
bool is_subkey(std::string str)
Definition odbxx.cxx:586
static bool s_debug
Definition odbxx.h:452
void fix_order(std::vector< std::string > target_subkey_order)
Definition odbxx.cxx:1356
static odb_source s_odb_source
Definition odbxx.h:447
std::string dump()
Definition odbxx.cxx:484
int m_last_index
Definition odbxx.h:469
void connect_and_fix_structure(std::string path)
Definition odbxx.cxx:1498
static bool s_connected_odb
Definition odbxx.h:454
static void init_hdb()
Definition odbxx.cxx:49
uint32_t get_flags()
Definition odbxx.h:526
bool is_trigger_hotlink() const
Definition odbxx.h:1378
bool write_key(std::string &path, bool write_defaults)
Definition odbxx.cxx:785
std::string print()
Definition odbxx.cxx:476
static midas::odb * search_hkey(midas::odb *po, int hKey)
Definition odbxx.cxx:61
static bool is_connected_odb()
Definition odbxx.h:1412
std::bitset< 9 > m_flags
Definition odbxx.h:459
void set_deleted(bool f)
Definition odbxx.h:529
static void load(const std::string &filename, const std::string &odb_path)
Definition odbxx.cxx:101
midas::odb * odb_from_xml(PMXML_NODE node, odb *o)
Definition odbxx.h:1185
void set_parent(midas::odb *p)
Definition odbxx.h:536
HNDLE m_hKey
Definition odbxx.h:471
void set_write_protect(bool f)
Definition odbxx.h:1373
std::string m_name
Definition odbxx.h:465
bool is_write_protect() const
Definition odbxx.h:1372
void connect(const std::string &path, const std::string &name, bool write_defaults, bool delete_keys_not_in_defaults=false)
Definition odbxx.cxx:1419
midas::odb * m_parent
Definition odbxx.h:475
uint8_t m_uint8
Definition odbxx.h:52
bool m_bool
Definition odbxx.h:60
uint8_t operator=(uint8_t v)
Definition odbxx.cxx:1729
void set_tid(int tid)
Definition odbxx.h:105
void mult(double f, bool push=true)
Definition odbxx.cxx:1954
void set_string(std::string s)
Definition odbxx.h:172
int8_t m_int8
Definition odbxx.h:53
uint64_t m_uint64
Definition odbxx.h:58
int32_t m_int32
Definition odbxx.h:57
int64_t m_int64
Definition odbxx.h:59
void set(T v)
Definition odbxx.h:142
double m_double
Definition odbxx.h:62
odb * m_parent_odb
Definition odbxx.h:68
void set_odb(odb *v)
Definition odbxx.h:189
int m_tid
Definition odbxx.h:67
void add(double inc, bool push=true)
Definition odbxx.cxx:1930
void set_parent(odb *o)
Definition odbxx.h:102
uint16_t m_uint16
Definition odbxx.h:54
odb * get_podb()
Definition odbxx.h:369
void set_string_size(std::string s, int size)
Definition odbxx.cxx:1844
int16_t m_int16
Definition odbxx.h:55
odb & get_odb()
Definition odbxx.h:375
std::string s()
Definition odbxx.h:361
std::string * m_string
Definition odbxx.h:63
void set_string_ptr(std::string *s)
Definition odbxx.h:179
odb * m_odb
Definition odbxx.h:64
float m_float
Definition odbxx.h:61
uint32_t m_uint32
Definition odbxx.h:56
int get_tid()
Definition odbxx.h:107
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
Definition midas.cxx:3011
#define DB_KEY_EXIST
Definition midas.h:641
#define DB_INVALID_HANDLE
Definition midas.h:635
#define DB_SUCCESS
Definition midas.h:631
#define DB_NO_KEY
Definition midas.h:642
#define DB_CREATED
Definition midas.h:632
#define DB_TRUNCATED
Definition midas.h:644
#define TID_DOUBLE
Definition midas.h:343
#define TID_KEY
Definition midas.h:349
#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_LINK
Definition midas.h:350
#define TID_STRING
Definition midas.h:346
#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
#define TID_LAST
Definition midas.h:354
BOOL equal_ustring(const char *str1, const char *str2)
Definition odb.cxx:3201
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT idx, DWORD type)
Definition odb.cxx:6893
INT db_delete_key(HNDLE hDB, HNDLE hKey, BOOL follow_links)
Definition odb.cxx:3856
INT db_reorder_key(HNDLE hDB, HNDLE hKey, INT idx)
Definition odb.cxx:6361
INT db_get_path(HNDLE hDB, HNDLE hKey, char *path, INT buf_size)
Definition odb.cxx:4990
INT db_get_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
Definition odb.cxx:6539
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
Definition odb.cxx:3308
INT db_copy_xml(HNDLE hDB, HNDLE hKey, char *buffer, int *buffer_size, bool header)
Definition odb.cxx:9037
INT db_unwatch(HNDLE hDB, HNDLE hKey)
Definition odb.cxx:13888
INT db_set_mode(HNDLE hDB, HNDLE hKey, WORD mode, BOOL recurse)
Definition odb.cxx:8027
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
Definition odb.cxx:6019
INT db_load(HNDLE hDB, HNDLE hKeyRoot, const char *filename, BOOL bRemote)
Definition odb.cxx:8126
INT db_watch(HNDLE hDB, HNDLE hKey, void(*dispatcher)(INT, INT, INT, void *), void *info)
Definition odb.cxx:13814
INT db_set_data(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Definition odb.cxx:7215
INT db_set_data1(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Definition odb.cxx:7313
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4079
INT db_set_data_index1(HNDLE hDB, HNDLE hKey, const void *data, INT data_size, INT idx, DWORD type, BOOL bNotify)
Definition odb.cxx:7828
INT db_enum_key(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
Definition odb.cxx:5586
INT db_set_num_values(HNDLE hDB, HNDLE hKey, INT num_values)
Definition odb.cxx:7502
INT rpc_tid_size(INT id)
Definition midas.cxx:11765
void ** info
Definition fesimdaq.cxx:41
HNDLE hKey
DWORD n[4]
Definition mana.cxx:247
INT index
Definition mana.cxx:271
INT type
Definition mana.cxx:269
HNDLE hDB
main ODB handle
Definition mana.cxx:207
KEY key
Definition mdump.cxx:34
INT i
Definition mdump.cxx:32
#define mthrow(arg)
Definition mexcept.h:24
INT HNDLE
Definition midas.h:132
DWORD BOOL
Definition midas.h:105
#define TRUE
Definition midas.h:182
#define write(n, a, f, d)
#define name(x)
Definition midas_macro.h:24
#define set(var, value)
static std::string indent(int x, const char *p=" ")
std::vector< std::string > split(std::string input, char delimiter='/')
Definition odbxx.cxx:241
void recurse_fix_order(midas::odb &default_odb, std::map< std::string, std::vector< std::string > > &user_order)
Definition odbxx.cxx:1342
void recurse_get_defaults_order(std::string path, midas::odb &default_odb, std::map< std::string, std::vector< std::string > > &retval)
Definition odbxx.cxx:1332
std::vector< midas::odb * > g_watchlist
Definition odbxx.cxx:40
void recurse_del_keys_not_in_defaults(std::string path, HNDLE hDB, HNDLE hKey, midas::odb &default_odb)
Definition odbxx.cxx:1295
INT k
Definition odbhist.cxx:40
char str[256]
Definition odbhist.cxx:33
DWORD status
Definition odbhist.cxx:39
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Definition midas.h:1026
INT num_values
Definition midas.h:1028
DWORD type
Definition midas.h:1027
INT total_size
Definition midas.h:1031
WORD access_mode
Definition midas.h:1033
INT last_written
Definition midas.h:1037
char name[NAME_LENGTH]
Definition midas.h:1029
INT item_size
Definition midas.h:1032
double d
Definition system.cxx:1311
static double sub(double a, double b)
Definition tinyexpr.c:244