Midas C++ API - db_xxx functions
This page contains the full API reference for the low-level db_xxx ODB functions.
For the concepts and day-to-day use, see ODB: overview.
For explanations and examples of using the ODB from code, see ODB: programming.
ODB Functions (db_xxx)
Functions
db_add_open_record
INT db_add_open_record(HNDLE hDB, HNDLE hKey, WORD access_mode)
Defined in include/midas.h:1899
db_allow_write_locked
INT db_allow_write_locked(DATABASE* p, const char* caller_name)
Declared in include/msystem.h:551, defined in src/odb.cxx:3305
db_check_client
INT db_check_client(HNDLE hDB, HNDLE hKeyClient)
Check if a client with a /system/client/xxx entry has a valid entry in the ODB client table. If not, remove that client from the /system/client tree.
Parameters:
-
hDB(HNDLE) –Handle to online database -
hKeyClient(HNDLE) –Handle to client key
Returns:
-
INT–
Declared in include/msystem.h:556, defined in src/odb.cxx:3829
db_check_record
INT db_check_record(HNDLE hDB, HNDLE hKey, const char *key_name, const char *rec_str, BOOL correct)
This function ensures that a certain ODB subtree matches a given C structure, by comparing the init_str with the current ODB structure. If the record does not exist at all, it is created with the default values in init_str. If it does exist but does not match the variables in init_str, the function returns an error if correct=FALSE or calls db_create_record() if correct=TRUE.
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
key_name(const char *) –Name of key to search, can contain directories. -
rec_str(const char *) –ASCII representation of ODB record in the format -
correct(BOOL) –If TRUE, correct ODB record if necessary
Returns:
-
INT–
Declared in include/midas.h:1886, defined in src/odb.cxx:13906
db_cleanup
void db_cleanup(const char *who, DWORD actual_time, BOOL wrong_interval)
void db_update_last_activity(DWORD actual_time);
Declared in include/msystem.h:553, defined in src/odb.cxx:3597
db_cleanup2
void db_cleanup2(const char* client_name, int ignore_timeout, DWORD actual_time, const char *who)
check online databases
Declared in include/msystem.h:554, defined in src/odb.cxx:3667
db_close_all_databases
INT db_close_all_databases()
Defined in include/midas.h:1830
db_close_all_records
INT db_close_all_records()
Release local memory for open records. This routines is called by db_close_all_databases() and cm_disconnect_experiment()
Returns:
-
INT–
Declared in include/msystem.h:544, defined in src/odb.cxx:14449
db_close_database
INT db_close_database(HNDLE database_handle)
Close a database
Parameters:
-
database_handle(HNDLE) –ODB handle obtained via cm_get_experiment_database().
Returns:
-
INT–
Declared in include/midas.h:1829, defined in src/odb.cxx:2876
db_close_record
INT db_close_record(HNDLE hdb, HNDLE hkey)
Close a record previously opend with db_open_record.
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hkey(HNDLE) –Handle for key where search starts, zero for root.
Returns:
-
INT–
Declared in include/midas.h:1889, defined in src/odb.cxx:14408
db_copy
INT db_copy(HNDLE hDB, HNDLE hKey, char *buffer, INT * buffer_size, const char *path)
Copy an ODB subtree in ASCII format to a buffer
This function converts the binary ODB contents to an ASCII. The function db_paste() can be used to convert the ASCII representation back to binary ODB contents. The functions db_load() and db_save() internally use db_copy() and db_paste(). This function converts the binary ODB contents to an ASCII representation of the form: - For single value:
[ODB path]
key name = type : value
- For strings:
key name = STRING : [size] string contents
- For arrayes (type can be BYTE, SBYTE, CHAR, WORD, SHORT, DWORD, INT, BOOL, FLOAT, DOUBLE, STRING or LINK):
key name = type[size] :
[0] value0
[1] value1
[2] value2
...
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
buffer(char *) –ASCII buffer which receives ODB contents. -
buffer_size(INT *) –Size of buffer, returns remaining space in buffer. -
path(const char *) –Internal use only, must be empty ("").
Returns:
-
INT–
Declared in include/midas.h:1908, defined in src/odb.cxx:8938
db_copy_json_index
int db_copy_json_index(HNDLE hDB, HNDLE hKey, int index, char **buffer, int *buffer_size, int *buffer_end, std::vector<char> &odbbuf)
Copy an ODB array element in JSON format to a buffer
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key -
index(int) –Array index -
buffer(char **) –returns pointer to ASCII buffer with ODB contents -
buffer_size(int *) –returns size of ASCII buffer -
buffer_end(int *) –returns number of bytes contained in buffer -
odbbuf(std::vector<char> &)
Returns:
-
int–
Declared in include/msystem.h:564, defined in src/odb.cxx:11048
db_copy_json_jcopy
INT db_copy_json_jcopy(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end, int save_keys, int follow_links, int recurse)
Copy an ODB subtree in JSON format to a buffer
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
buffer(char **) –returns pointer to ASCII buffer with ODB contents -
buffer_size(int *) –returns size of ASCII buffer -
buffer_end(int *) –returns number of bytes contained in buffer -
save_keys(int) -
follow_links(int) -
recurse(int)
Returns:
-
INT–
Declared in include/midas.h:1920, defined in src/odb.cxx:11429
db_copy_json_ls
INT db_copy_json_ls(HNDLE hDB, HNDLE hKey, char **buffer, int* buffer_size, int* buffer_end)
json encoder using the "ls" format, for getting the contents of a single ODB subdirectory
Declared in include/midas.h:1925, defined in src/odb.cxx:11335
db_copy_json_save
INT db_copy_json_save(HNDLE hDB, HNDLE hKey, char **buffer, int* buffer_size, int* buffer_end)
json encoder using the "ODB save" encoding, for use with "ODB load" and db_paste_json()
Declared in include/midas.h:1923, defined in src/odb.cxx:11394
db_copy_json_values
INT db_copy_json_values(HNDLE hDB, HNDLE hKey, char **buffer, int* buffer_size, int* buffer_end, int omit_names, int omit_last_written, time_t omit_old_timestamp, int preserve_case)
json encoder using the "get_values" format, for resolving links and normalized ODB path names (converted to lower-case)
Declared in include/midas.h:1927, defined in src/odb.cxx:11360
db_copy_xml
INT db_copy_xml(HNDLE hDB, HNDLE hKey, char *buffer, int *buffer_size, bool header)
Copy an ODB subtree in XML format to a buffer
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
buffer(char *) –ASCII buffer which receives ODB contents. -
buffer_size(int *) –Size of buffer, returns remaining space in buffer. -
header(bool)
Returns:
-
INT–
Declared in include/midas.h:1914, defined in src/odb.cxx:9763
db_create_key
INT db_create_key(HNDLE hdb, HNDLE key_handle, const char *key_name, DWORD type)
Create a new key in a database
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –Key handle to start with, 0 for root -
key_name(const char *) –Name of key in the form "/key/key/key" -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types)
Returns:
-
INT–
Declared in include/midas.h:1833, defined in src/odb.cxx:4078
db_create_link
INT db_create_link(HNDLE hdb, HNDLE key_handle, const char *link_name, const char *destination)
Create a link to a key or set the destination of and existing link.
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –Key handle to start with, 0 for root -
link_name(const char *) –Name of key in the form "/key/key/key" -
destination(const char *) –Destination of link in the form "/key/key/key"
Returns:
-
INT–
Declared in include/midas.h:1834, defined in src/odb.cxx:4374
db_create_record
INT db_create_record(HNDLE hdb, HNDLE hkey, const char *name, const char *init_str)
Create a record. If a part of the record exists alreay, merge it with the init_str (use values from the init_str only when they are not in the existing record).
This functions creates a ODB sub-tree according to an ASCII representation of that tree. See db_copy() for a description. It can be used to create a sub-tree which exactly matches a C structure. The sub-tree can then later mapped to the C structure ("hot-link") via the function db_open_record().
If a sub-tree exists already which exactly matches the ASCII representation, it is not modified. If part of the tree exists, it is merged with the ASCII representation where the ODB values have priority, only values not present in the ODB are created with the default values of the ASCII representation. It is therefore recommended that before creating an ODB hot-link the function db_create_record() is called to insure that the ODB tree and the C structure contain exactly the same values in the same order.
Following example creates a record under /Equipment/Trigger/Settings, opens a hot-link between that record and a local C structure trigger_settings and registers a callback function trigger_update() which gets called each time the record is changed.
struct {
INT level1;
INT level2;
} trigger_settings;
char *trigger_settings_str =
"[Settings]\n\
level1 = INT : 0\n\
level2 = INT : 0";
void trigger_update(INT hDB, INT hkey, void *info)
{
printf("New levels: %d %d\n",
trigger_settings.level1,
trigger_settings.level2);
}
main()
{
HNDLE hDB, hkey;
char[128] info;
...
cm_get_experiment_database(&hDB, NULL);
db_create_record(hDB, 0, "/Equipment/Trigger", trigger_settings_str);
db_find_key(hDB, 0,"/Equipment/Trigger/Settings", &hkey);
db_open_record(hDB, hkey, &trigger_settings,
sizeof(trigger_settings), MODE_READ, trigger_update, info);
...
}
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hkey(HNDLE) –Handle for key where search starts, zero for root. -
name(const char *) –Name of key to search, can contain directories. -
init_str(const char *) –Initialization string in the format of the db_copy/db_save functions.
Returns:
-
INT–
Declared in include/midas.h:1885, defined in src/odb.cxx:13734
db_delete
INT db_delete(HNDLE database_handle, HNDLE hKeyRoot, const char* name)
Declared in include/midas.h:1856, defined in src/odb.cxx:4687
db_delete_client_info
INT db_delete_client_info(HNDLE hDB, int pid)
Delete client info from database
Parameters:
-
hDB(HNDLE) –Database handle -
pid(int) –PID of entry to delete, zero for this process.
Returns:
-
INT–
Declared in include/midas.h:1947, defined in src/odb.cxx:3562
db_delete_key
Note: this function has 2 different signatures.
db_delete_key
INT db_delete_key(HNDLE database_handle, HNDLE key_handle, BOOL follow_links)
Delete a subtree in a database starting from a key (including this key).
...
status = db_find_link(hDB, 0, str, &hkey);
if (status != DB_SUCCESS)
{
cm_msg(MINFO,"my_delete"," "Cannot find key %s", str);
return;
}
status = db_delete_key(hDB, hkey);
if (status != DB_SUCCESS)
{
cm_msg(MERROR,"my_delete"," "Cannot delete key %s", str);
return;
}
...
Parameters:
-
database_handle(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –for key where search starts, zero for root. -
follow_links(BOOL) –Follow links when TRUE.
Returns:
-
INT–
Declared in include/midas.h:1854, defined in src/odb.cxx:4621
db_delete_key
INT db_delete_key(HNDLE database_handle, HNDLE key_handle)
Declared in include/midas.h:1855, defined in src/odb.cxx:4654
db_enum
Note: this function has 2 different signatures.
db_enum
INT db_enum(HNDLE hdb, HNDLE key_handle, std::vector<HNDLE>* sub_handles, std::vector<KEY>* sub_keys, bool follow_links = true)
Defined in include/midas.h:1857
db_enum
INT db_enum(HNDLE hdb, HNDLE root_handle, const char* odb_path, std::vector<HNDLE>* sub_handles, std::vector<KEY>* sub_keys, bool follow_links = true)
Defined in include/midas.h:1858
db_enum_key
INT db_enum_key(HNDLE hdb, HNDLE key_handle, INT index, HNDLE * subkey_handle)
Enumerate subkeys from a key, follow links.
hkey must correspond to a valid ODB directory. The index is usually incremented in a loop until the last key is reached. Information about the sub-keys can be obtained with db_get_key(). If a returned key is of type TID_KEY, it contains itself sub-keys. To scan a whole ODB sub-tree, the function db_scan_tree() can be used.
INT i;
HNDLE hkey, hsubkey;
KEY key;
db_find_key(hdb, 0, "/Runinfo", &hkey);
for (i=0 ; ; i++)
{
db_enum_key(hdb, hkey, i, &hsubkey);
if (!hSubkey)
break; // end of list reached
// print key name
db_get_key(hdb, hkey, &key);
printf("%s\n", key.name);
}
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –Handle for key where search starts, zero for root. -
index(INT) –Subkey index, sould be initially 0, then incremented in each call until subhKey becomes zero and the function returns DB_NO_MORE_SUBKEYS -
subkey_handle(HNDLE *) –Handle of subkey which can be used in db_get_key() and db_get_data()
Returns:
-
INT–
Declared in include/midas.h:1859, defined in src/odb.cxx:6108
db_enum_link
INT db_enum_link(HNDLE hdb, HNDLE key_handle, INT index, HNDLE * subkey_handle)
Defined in include/midas.h:1860
db_find_key
INT db_find_key(HNDLE hdb, HNDLE hkey, const char *name, HNDLE * hsubkey)
Returns key handle for a key with a specific name.
Keys can be accessed by their name including the directory or by a handle. A key handle is an internal offset to the shared memory where the ODB lives and allows a much faster access to a key than via its name.
The function db_find_key() must be used to convert a key name to a handle. Most other database functions use this key handle in various operations.
HNDLE hkey, hsubkey;
// use full name, start from root
db_find_key(hDB, 0, "/Runinfo/Run number", &hkey);
// start from subdirectory
db_find_key(hDB, 0, "/Runinfo", &hkey);
db_find_key(hdb, hkey, "Run number", &hsubkey);
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hkey(HNDLE) –Handle for key where search starts, zero for root. -
name(const char *) –Name of key to search, can contain directories. -
hsubkey(HNDLE *) –Returned handle of key, zero if key cannot be found.
Returns:
-
INT–
Declared in include/midas.h:1842, defined in src/odb.cxx:4944
db_find_keys
INT db_find_keys(HNDLE hDB, HNDLE hKey, const char *odbpath, std::vector<HNDLE> &hKeyVector)
INT EXPRT db_find_key1(HNDLE hdb, HNDLE hkey, const char *name, HNDLE * hsubkey); INT EXPRT db_find_link1(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE * subhKey);
Defined in include/midas.h:1846
db_find_link
INT db_find_link(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE * subhKey)
Defined in include/midas.h:1843
db_get_data
INT db_get_data(HNDLE hdb, HNDLE key_handle, void *data, INT * buf_size, DWORD type)
Get key data from a handle
The function returns single values or whole arrays which are contained in an ODB key. Since the data buffer is of type void, no type checking can be performed by the compiler. Therefore the type has to be explicitly supplied, which is checked against the type stored in the ODB.
HNLDE hkey;
INT run_number, size;
// get key handle for run number
db_find_key(hDB, 0, "/Runinfo/Run number", &hkey);
// return run number
size = sizeof(run_number);
db_get_data(hDB, hkey, &run_number, &size,TID_INT32);
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –Handle for key where search starts, zero for root. -
data(void *) –Pointer to the return data. -
buf_size(INT *) –Size of data buffer. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types).
Returns:
-
INT–
Declared in include/midas.h:1868, defined in src/odb.cxx:7335
db_get_data1
INT db_get_data1(HNDLE hDB, HNDLE hKey, void *data, INT * buf_size, DWORD type, INT * num_values)
Defined in include/midas.h:1872
db_get_data_index
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT * buf_size, INT index, DWORD type)
returns a single value of keys containing arrays of values.
The function returns a single value of keys containing arrays of values.
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
data(void *) –Size of data buffer. -
buf_size(INT *) –Return size of the record. -
index(INT) –Index of array [0..n-1]. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types).
Returns:
-
INT–
Declared in include/midas.h:1873, defined in src/odb.cxx:7579
db_get_data_index_vec
INT db_get_data_index_vec(HNDLE hdb, HNDLE hKey, std::vector<char> *data, INT index, DWORD type)
Declared in include/midas.h:1874, defined in src/odb.cxx:7687
db_get_data_vec
INT db_get_data_vec(HNDLE hdb, HNDLE key_handle, std::vector<char> *data, DWORD type)
printf("db_get_data_vec(std::vector<char>)!\n");
Declared in include/midas.h:1869, defined in src/odb.cxx:7396
db_get_key
INT db_get_key(HNDLE hdb, HNDLE key_handle, KEY * key)
Get key structure from a handle.
KEY structure has following format:
typedef struct {
DWORD type; // TID_xxx type
INT num_values; // number of values
char name[NAME_LENGTH]; // name of variable
INT data; // Address of variable (offset)
INT total_size; // Total size of data block
INT item_size; // Size of single data item
WORD access_mode; // Access mode
WORD notify_count; // Notify counter
INT next_key; // Address of next key
INT parent_keylist; // keylist to which this key belongs
INT last_written; // Time of last write action
} KEY;
Most of these values are used for internal purposes, the values which are of public interest are type, name, num_values, item_size and total_size. For keys which contain a single value, num_values equals to one and total_size equals to item_size. For keys which contain an array of strings (TID_STRING), item_size equals to the length of one string.
KEY key;
HNDLE hkey;
db_find_key(hDB, 0, "/Runinfo/Run number", &hkey);
db_get_key(hDB, hkey, &key);
printf("The run number is of type %s\n", rpc_tid_name(key.type));
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –Handle for key where search starts, zero for root. If Key is a link to an array element, this link is resolved. In this case function returns the key of the link destination and num_values is set to 1. -
key(KEY *) –Pointer to KEY stucture.
Returns:
-
INT–
Declared in include/midas.h:1862, defined in src/odb.cxx:6816
db_get_key_info
INT db_get_key_info(HNDLE hDB, HNDLE hKey, char *name, INT name_size, INT * type, INT * num_values, INT * item_size)
Get key info (separate values instead of structure)
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle of key to operate on -
name(char *) –Key name -
name_size(INT) –Size of the give name (done with sizeof()) -
type(INT *) –Key type (seeMidas_Data_Types). -
num_values(INT *) –Number of values in key. -
item_size(INT *) –Size of individual key value (used for strings)
Returns:
-
INT–
Declared in include/midas.h:1864, defined in src/odb.cxx:6988
db_get_key_time
INT db_get_key_time(HNDLE hdb, HNDLE key_handle, DWORD * delta)
Get time when key was last modified
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –Handle of key to operate on -
delta(DWORD *) –Seconds since last update
Returns:
-
INT–
Declared in include/midas.h:1865, defined in src/odb.cxx:6929
db_get_link
INT db_get_link(HNDLE hdb, HNDLE key_handle, KEY * key)
Same as db_get_key, but it does not follow links
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –Handle for key where search starts, zero for root. -
key(KEY *) –Pointer to KEY stucture.
Returns:
-
INT–
Declared in include/midas.h:1863, defined in src/odb.cxx:6869
db_get_link_data
INT db_get_link_data(HNDLE hdb, HNDLE key_handle, void *data, INT * buf_size, DWORD type)
Same as db_get_data, but do not follow a link to an array index
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –Handle for key where search starts, zero for root. -
data(void *) –Pointer to the return data. -
buf_size(INT *) –Size of data buffer. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types).
Returns:
-
INT–
Declared in include/midas.h:1870, defined in src/odb.cxx:7470
db_get_next_link
INT db_get_next_link(HNDLE hdb, HNDLE key_handle, HNDLE * subkey_handle)
Defined in include/midas.h:1861
db_get_open_records
INT db_get_open_records(HNDLE hDB, HNDLE hKey, char *str, INT buf_size, BOOL fix)
Defined in include/midas.h:1897
db_get_parent
INT db_get_parent(HNDLE hDB, HNDLE hKey, HNDLE * parenthKey)
Defined in include/midas.h:1847
db_get_path
Note: this function has 2 different signatures.
db_get_path
INT db_get_path(HNDLE hDB, HNDLE hKey, char *path, INT buf_size)
Defined in include/midas.h:1851
db_get_path
std::string db_get_path(HNDLE hDB, HNDLE hKey)
Defined in include/midas.h:1852
db_get_record
INT db_get_record(HNDLE hdb, HNDLE hKey, void *data, INT * buf_size, INT align)
Copy a set of keys to local memory.
An ODB sub-tree can be mapped to a C structure automatically via a hot-link using the function db_open_record() or manually with this function. Problems might occur if the ODB sub-tree contains values which don't match the C structure. Although the structure size is checked against the sub-tree size, no checking can be done if the type and order of the values in the structure are the same than those in the ODB sub-tree. Therefore it is recommended to use the function db_create_record() before db_get_record() is used which ensures that both are equivalent.
struct {
INT level1;
INT level2;
} trigger_settings;
char *trigger_settings_str =
"[Settings]\n\
level1 = INT : 0\n\
level2 = INT : 0";
main()
{
HNDLE hDB, hkey;
INT size;
...
cm_get_experiment_database(&hDB, NULL);
db_create_record(hDB, 0, "/Equipment/Trigger", trigger_settings_str);
db_find_key(hDB, 0, "/Equipment/Trigger/Settings", &hkey);
size = sizeof(trigger_settings);
db_get_record(hDB, hkey, &trigger_settings, &size, 0);
...
}
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
data(void *) –Pointer to the retrieved data. -
buf_size(INT *) –Size of data structure, must be obtained via sizeof(RECORD-NAME). -
align(INT) –Byte alignment calculated by the stub and passed to the rpc side to align data according to local machine. Must be zero when called from user level.
Returns:
-
INT–
Declared in include/midas.h:1890, defined in src/odb.cxx:12639
db_get_record1
INT db_get_record1(HNDLE hdb, HNDLE hKey, void *data, INT * buf_size, INT align, const char *rec_str)
Same as db_get_record() but if there is a record mismatch between ODB structure and C record, it is automatically corrected by calling db_check_record()
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
data(void *) –Pointer to the retrieved data. -
buf_size(INT *) –Size of data structure, must be obtained via sizeof(RECORD-NAME). -
align(INT) –Byte alignment calculated by the stub and passed to the rpc side to align data according to local machine. Must be zero when called from user level. -
rec_str(const char *) –ASCII representation of ODB record in the format
Returns:
-
INT–
Declared in include/midas.h:1891, defined in src/odb.cxx:12737
db_get_record2
INT db_get_record2(HNDLE hdb, HNDLE hKey, void *data, INT * buf_size, INT align, const char *rec_str, BOOL correct)
Copy a set of keys to local memory.
An ODB sub-tree can be mapped to a C structure automatically via a hot-link using the function db_open_record1() or manually with this function. For correct operation, the description string must match the C data structure. If the contents of ODB sub-tree does not exactly match the description string, db_get_record2() will try to read as much as it can and return DB_TRUNCATED to inform the user that there was a mismatch somewhere. To ensure that the ODB sub-tree matches the desciption string, call db_create_record() or db_check_record() before calling db_get_record2(). Unlike db_get_record() and db_get_record1(), this function will not complain about data strucure mismatches. It will ignore all extra entries in the ODB sub-tree and it will set to zero the C-structure data fields that do not have corresponding ODB entries.
struct {
INT level1;
INT level2;
} trigger_settings;
const char *trigger_settings_str =
"[Settings]\n\
level1 = INT : 0\n\
level2 = INT : 0";
main()
{
HNDLE hDB, hkey;
INT size;
...
cm_get_experiment_database(&hDB, NULL);
db_create_record(hDB, 0, "/Equipment/Trigger", trigger_settings_str);
db_find_key(hDB, 0, "/Equipment/Trigger/Settings", &hkey);
size = sizeof(trigger_settings);
db_get_record2(hDB, hkey, &trigger_settings, &size, 0, trigger_settings_str);
...
}
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
data(void *) –Pointer to the retrieved data. -
buf_size(INT *) –Size of data structure, must be obtained via sizeof(data). -
align(INT) –Byte alignment calculated by the stub and passed to the rpc side to align data according to local machine. Must be zero when called from user level. -
rec_str(const char *) –Description of the data structure, see db_create_record() -
correct(BOOL) –Must be set to zero
Returns:
-
INT–
Declared in include/midas.h:1892, defined in src/odb.cxx:13100
db_get_record_size
INT db_get_record_size(HNDLE hdb, HNDLE hKey, INT align, INT * buf_size)
Calculates the size of a record.
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
align(INT) –Byte alignment calculated by the stub and passed to the rpc side to align data according to local machine. Must be zero when called from user level -
buf_size(INT *) –Size of record structure
Returns:
-
INT–
Declared in include/midas.h:1893, defined in src/odb.cxx:12543
db_get_value
INT db_get_value(HNDLE hdb, HNDLE hKeyRoot, const char *key_name, void *data, INT * size, DWORD type, BOOL create)
Get value of a single key.
The function returns single values or whole arrays which are contained in an ODB key. Since the data buffer is of type void, no type checking can be performed by the compiler. Therefore the type has to be explicitly supplied, which is checked against the type stored in the ODB. key_name can contain the full path of a key (like: "/Equipment/Trigger/Settings/Level1") while hkey is zero which refers to the root, or hkey can refer to a sub-directory (like: /Equipment/Trigger) and key_name is interpreted relative to that directory like "Settings/Level1".
INT level1, size;
size = sizeof(level1);
db_get_value(hDB, 0, "/Equipment/Trigger/Settings/Level1",
&level1, &size, TID_INT32, 0);
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKeyRoot(HNDLE) –Handle for key where search starts, zero for root. -
key_name(const char *) –Name of key to search, can contain directories. -
data(void *) –Address of data. -
size(INT *) –Maximum buffer size on input, number of written bytes on return. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types) -
create(BOOL) –If TRUE, create key if not existing
Returns:
-
INT–
Declared in include/midas.h:1837, defined in src/odb.cxx:5873
db_get_value_string
INT db_get_value_string(HNDLE hdb, HNDLE hKeyRoot, const char *key_name, int index, std::string* s, BOOL create = FALSE, int create_string_length = 0)
Declared in include/midas.h:1840, defined in src/odb.cxx:14870
db_get_watchdog_info
INT db_get_watchdog_info(HNDLE hDB, const char *client_name, DWORD * timeout, DWORD * last)
Return watchdog information about specific client
Parameters:
-
hDB(HNDLE) –ODB handle -
client_name(const char *) –ODB client name -
timeout(DWORD *) –Timeout for this application in seconds -
last(DWORD *) –Last time watchdog was called in msec
Returns:
-
INT–
Declared in include/midas.h:1945, defined in src/odb.cxx:3784
db_load
INT db_load(HNDLE hdb, HNDLE key_handle, const char *filename, BOOL bRemote)
Load a branch of a database from an .ODB file.
This function is used by the ODBEdit command load. For a description of the ASCII format, see db_copy(). Data can be loaded relative to the root of the ODB (hkey equal zero) or relative to a certain key.
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –Handle for key where search starts, zero for root. -
filename(const char *) –Filename of .ODB file. -
bRemote(BOOL) –If TRUE, the file is loaded by the server process on the back-end, if FALSE, it is loaded from the current process
Returns:
-
INT–
Declared in include/midas.h:1906, defined in src/odb.cxx:8847
db_load_json
INT db_load_json(HNDLE hdb, HNDLE key_handle, const char *filename)
Declared in include/midas.h:1917, defined in src/json_paste.cxx:15
db_lock_database
INT db_lock_database(HNDLE database_handle)
Lock a database for exclusive access via system semaphore calls.
Parameters:
-
database_handle(HNDLE) –Handle to the database to lock
Returns:
-
INT–
Declared in include/msystem.h:538, defined in src/odb.cxx:3179
db_merge_data
INT db_merge_data(HNDLE hDB, HNDLE hKeyRoot, const char *name, void *data, INT data_size, INT num_values, INT type)
Defined in include/midas.h:1883
db_notify_clients_array
INT db_notify_clients_array(HNDLE hdb, HNDLE hKey[], INT n)
Defined in include/midas.h:1877
db_open_database
INT db_open_database(const char *database_name, INT database_size, HNDLE * hdb, const char *client_name)
Open an online database
Parameters:
-
database_name(const char *) –Database name. -
database_size(INT) –Initial size of database if not existing -
hdb(HNDLE *) –ODB handle obtained via cm_get_experiment_database(). -
client_name(const char *) –Name of this application
Returns:
-
INT–
Declared in include/midas.h:1828, defined in src/odb.cxx:2506
db_open_record
INT db_open_record(HNDLE hdb, HNDLE hkey, void *ptr, INT rec_size, WORD access, void (*dispatcher) (INT, INT, void *), void *info)
Open a record. Create a local copy and maintain an automatic update.
This function opens a hot-link between an ODB sub-tree and a local structure. The sub-tree is copied to the structure automatically every time it is modified by someone else. Additionally, a callback function can be declared which is called after the structure has been updated. The callback function receives the database handle and the key handle as parameters.
Problems might occur if the ODB sub-tree contains values which don't match the C structure. Although the structure size is checked against the sub-tree size, no checking can be done if the type and order of the values in the structure are the same than those in the ODB sub-tree. Therefore it is recommended to use the function db_create_record() before db_open_record() is used which ensures that both are equivalent.
The access mode might either be MODE_READ or MODE_WRITE. In read mode, the ODB sub-tree is automatically copied to the local structure when modified by other clients. In write mode, the local structure is copied to the ODB sub-tree if it has been modified locally. This update has to be manually scheduled by calling db_send_changed_records() periodically in the main loop. The system keeps a copy of the local structure to determine if its contents has been changed.
If MODE_ALLOC is or'ed with the access mode, the memory for the structure is allocated internally. The structure pointer must contain a pointer to a pointer to the structure. The internal memory is released when db_close_record() is called. - To open a record in write mode.
struct {
INT level1;
INT level2;
} trigger_settings;
char *trigger_settings_str =
"[Settings]\n\
level1 = INT : 0\n\
level2 = INT : 0";
main()
{
HNDLE hDB, hkey, i=0;
...
cm_get_experiment_database(&hDB, NULL);
db_create_record(hDB, 0, "/Equipment/Trigger", trigger_settings_str);
db_find_key(hDB, 0,"/Equipment/Trigger/Settings", &hkey);
db_open_record(hDB, hkey, &trigger_settings, sizeof(trigger_settings)
, MODE_WRITE, NULL);
do
{
trigger_settings.level1 = i++;
db_send_changed_records()
status = cm_yield(1000);
} while (status != RPC_SHUTDOWN && status != SS_ABORT);
...
}
argument list composed of: HNDLE hDB, HNDLE hKey, void *info
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hkey(HNDLE) –Handle for key where search starts, zero for root. -
ptr(void *) –If access_mode includes MODE_ALLOC: Address of pointer which points to the record data after the call if access_mode includes not MODE_ALLOC: Address of record if ptr==NULL, only the dispatcher is called. -
rec_size(INT) –Record size in bytes -
access(WORD) –Mode for opening record, either MODE_READ or MODE_WRITE. May be or'ed with MODE_ALLOC to let db_open_record allocate the memory for the record. -
dispatcher(void (*) (INT, INT, void *)) -
info(void *) –Additional info passed to the dispatcher.
Returns:
-
INT–
Declared in include/midas.h:1887, defined in src/odb.cxx:14225
db_open_record1
INT db_open_record1(HNDLE hdb, HNDLE hkey, void *ptr, INT rec_size, WORD access, void (*dispatcher) (INT, INT, void *), void *info, const char *rec_str)
Open a record. Create a local copy and maintain an automatic update.
This function is same as db_open_record(), except that it calls db_check_record(), db_get_record1() and db_create_record() to ensure that the ODB structure matches
Parameters are the same as for db_open_record():
argument list composed of: HNDLE hDB, HNDLE hKey, void *info
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hkey(HNDLE) –Handle for key where search starts, zero for root. -
ptr(void *) –If access_mode includes MODE_ALLOC: Address of pointer which points to the record data after the call if access_mode includes not MODE_ALLOC: Address of record if ptr==NULL, only the dispatcher is called. -
rec_size(INT) –Record size in bytes -
access(WORD) –Mode for opening record, either MODE_READ or MODE_WRITE. May be or'ed with MODE_ALLOC to let db_open_record allocate the memory for the record. -
dispatcher(void (*) (INT, INT, void *)) -
info(void *) –Additional info passed to the dispatcher. -
rec_str(const char *) –ASCII representation of ODB record in the format
Returns:
-
INT–
Declared in include/midas.h:1888, defined in src/odb.cxx:14376
db_paste
INT db_paste(HNDLE hDB, HNDLE hKeyRoot, const char *buffer)
Copy an ODB subtree in ASCII format from a buffer
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKeyRoot(HNDLE) –Handle for key where search starts, zero for root. -
buffer(const char *) –NULL-terminated buffer
Returns:
-
INT–
Declared in include/midas.h:1909, defined in src/odb.cxx:9213
db_paste_json
INT db_paste_json(HNDLE hDB, HNDLE hKey, const char *buffer)
Declared in include/midas.h:1929, defined in src/json_paste.cxx:687
db_paste_json_node
INT db_paste_json_node(HNDLE hDB, HNDLE hKey, int index, const MJsonNode* json_node)
Declared in include/midas.h:1930, defined in src/json_paste.cxx:700
db_paste_xml
INT db_paste_xml(HNDLE hDB, HNDLE hKeyRoot, const char *buffer)
Paste an ODB subtree in XML format from a buffer
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKeyRoot(HNDLE) –Handle for key where search starts, zero for root. -
buffer(const char *) –NULL-terminated buffer
Returns:
-
INT–
Declared in include/midas.h:1910, defined in src/odb.cxx:9724
db_protect_database
INT db_protect_database(HNDLE database_handle)
Protect a database for read/write access outside of the db_xxx functions
Parameters:
-
database_handle(HNDLE) –ODB handle obtained via cm_get_experiment_database().
Returns:
-
INT–
Declared in include/midas.h:1831, defined in src/odb.cxx:3937
db_remove_open_record
INT db_remove_open_record(HNDLE hDB, HNDLE hKey, BOOL lock)
Defined in include/midas.h:1900
db_rename_key
INT db_rename_key(HNDLE hDB, HNDLE hKey, const char *name)
Defined in include/midas.h:1866
db_reorder_key
INT db_reorder_key(HNDLE hDB, HNDLE hKey, INT index)
Defined in include/midas.h:1867
db_resize_string
INT db_resize_string(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, int num_values, int max_string_size)
Change size of string arrays.
This function can change the number of elements and the string element length of an array of strings.
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKeyRoot(HNDLE) -
key_name(const char *) –Odb key name, if NULL, will resize ODB entry pointed to by hKey -
num_values(int) –New number of array elements, if 0, remains unchanged -
max_string_size(int) –New max string length for array elements, if 0, remains unchanged -
hKey–Handle for key where search starts, zero for root.
Returns:
-
INT–
Declared in include/midas.h:1838, defined in src/odb.cxx:14961
db_save
INT db_save(HNDLE hdb, HNDLE key_handle, const char *filename, BOOL bRemote)
Save a branch of a database to an .ODB file
This function is used by the ODBEdit command save. For a description of the ASCII format, see db_copy(). Data of the whole ODB can be saved (hkey equal zero) or only a sub-tree.
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
key_handle(HNDLE) –Handle for key where search starts, zero for root. -
filename(const char *) –Filename of .ODB file. -
bRemote(BOOL) –Flag for saving database on remote server.
Returns:
-
INT–
Declared in include/midas.h:1907, defined in src/odb.cxx:9971
db_save_json
INT db_save_json(HNDLE hDB, HNDLE hKey, const char *file_name, int flags = JSFLAG_SAVE_KEYS|JSFLAG_RECURSE)
Save a branch of a database to an .json file
This function is used by the ODBEdit command save to write the contents of the ODB into a JSON file. Data of the whole ODB can be saved (hkey equal zero) or only a sub-tree.
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
file_name(const char *) –Filename of .json file. -
flags(int, default:JSFLAG_SAVE_KEYS|JSFLAG_RECURSE)
Returns:
-
INT–
Declared in include/midas.h:1916, defined in src/odb.cxx:11448
db_save_string
INT db_save_string(HNDLE hDB, HNDLE hKey, const char *file_name, const char *string_name, BOOL append)
Defined in include/midas.h:1912
db_save_struct
INT db_save_struct(HNDLE hDB, HNDLE hKey, const char *file_name, const char *struct_name, BOOL append)
Save a branch of a database to a C structure .H file
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
file_name(const char *) –Filename of .ODB file. -
struct_name(const char *) –Name of structure. If struct_name == NULL, the name of the key is used. -
append(BOOL) –If TRUE, append to end of existing file
Returns:
-
INT–
Declared in include/midas.h:1911, defined in src/odb.cxx:11551
db_save_xml
INT db_save_xml(HNDLE hDB, HNDLE hKey, const char *file_name)
Save a branch of a database to an .xml file
This function is used by the ODBEdit command save to write the contents of the ODB into a XML file. Data of the whole ODB can be saved (hkey equal zero) or only a sub-tree.
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
file_name(const char *) –Filename of .XML file.
Returns:
-
INT–
Declared in include/midas.h:1913, defined in src/odb.cxx:10211
db_scan_tree
INT db_scan_tree(HNDLE hDB, HNDLE hKey, int level, INT(*callback) (HNDLE, HNDLE, KEY *, INT, void *), void *info)
Defined in include/midas.h:1848
db_scan_tree_link
INT db_scan_tree_link(HNDLE hDB, HNDLE hKey, int level, void (*callback) (HNDLE, HNDLE, KEY *, INT, void *), void *info)
Defined in include/midas.h:1849
db_scl
MJsonNode*db_scl(HNDLE hDB)
Declared in include/midas.h:1933, defined in src/odb.cxx:15047
db_send_changed_records
INT db_send_changed_records()
Send all records to the ODB which were changed locally since the last call to this function.
This function is valid if used in conjunction with db_open_record() under the condition the record is open as MODE_WRITE access code.
- Full example dbchange.c which can be compiled as follow
gcc -DOS_LINUX -I/midas/include -o dbchange dbchange.c
/midas/linux/lib/libmidas.a -lutil}
\begin{verbatim}
//------- dbchange.c
#include "midas.h"
#include "msystem.h"
//-------- BOF dbchange.c
typedef struct {
INT my_number;
float my_rate;
} MY_STATISTICS;
MY_STATISTICS myrec;
#define MY_STATISTICS(_name) char *_name[] = {\
"My Number = INT : 0",\
"My Rate = FLOAT : 0",\
"",\
NULL }
HNDLE hDB, hKey;
// Main
int main(unsigned int argc,char **argv)
{
char host_name[HOST_NAME_LENGTH];
char expt_name[HOST_NAME_LENGTH];
INT lastnumber, status, msg;
BOOL debug=FALSE;
char i, ch;
DWORD update_time, mainlast_time;
MY_STATISTICS (my_stat);
// set default
host_name[0] = 0;
expt_name[0] = 0;
// get default
cm_get_environment(host_name, sizeof(host_name), expt_name, sizeof(expt_name));
// get parameters
for (i=1 ; i<argc ; i++)
{
if (argv[i][0] == '-' && argv[i][1] == 'd')
debug = TRUE;
else if (argv[i][0] == '-')
{
if (i+1 >= argc || argv[i+1][0] == '-')
goto usage;
if (strncmp(argv[i],"-e",2) == 0)
strcpy(expt_name, argv[++i]);
else if (strncmp(argv[i],"-h",2)==0)
strcpy(host_name, argv[++i]);
}
else
{
usage:
printf("usage: dbchange [-h <Hostname>] [-e <Experiment>]\n");
return 0;
}
}
// connect to experiment
status = cm_connect_experiment(host_name, expt_name, "dbchange", 0);
if (status != CM_SUCCESS)
return 1;
// Connect to DB
cm_get_experiment_database(&hDB, &hKey);
// Create a default structure in ODB
db_create_record(hDB, 0, "My statistics", strcomb1(my_stat).c_str());
// Retrieve key for that strucutre in ODB
if (db_find_key(hDB, 0, "My statistics", &hKey) != DB_SUCCESS)
{
cm_msg(MERROR, "mychange", "cannot find My statistics");
goto error;
}
// Hot link this structure in Write mode
status = db_open_record(hDB, hKey, &myrec, sizeof(MY_STATISTICS), MODE_WRITE, NULL, NULL);
if (status != DB_SUCCESS)
{
cm_msg(MERROR, "mychange", "cannot open My statistics record");
goto error;
}
// initialize ss_getchar()
ss_getchar(0);
// Main loop
do
{
// Update local structure
if ((ss_millitime() - update_time) > 100)
{
myrec.my_number += 1;
if (myrec.my_number - lastnumber) {
myrec.my_rate = 1000.f * (float) (myrec.my_number - lastnumber)
/ (float) (ss_millitime() - update_time);
}
update_time = ss_millitime();
lastnumber = myrec.my_number;
}
// Publish local structure to ODB (db_send_changed_record)
if ((ss_millitime() - mainlast_time) > 5000)
{
db_send_changed_records(); // <------- Call
mainlast_time = ss_millitime();
}
// Check for keyboard interaction
ch = 0;
while (ss_kbhit())
{
ch = ss_getchar(0);
if (ch == -1)
ch = getchar();
if ((char) ch == '!')
break;
}
msg = cm_yield(20);
} while (msg != RPC_SHUTDOWN && msg != SS_ABORT && ch != '!');
error:
cm_disconnect_experiment();
return 1;
}
//-------- EOF dbchange.c
Returns:
-
INT–
Declared in include/midas.h:1896, defined in src/odb.cxx:14712
db_set_data
INT db_set_data(HNDLE hdb, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Set key data from a handle. Adjust number of values if previous data has different size.
HNLDE hkey;
INT run_number;
// get key handle for run number
db_find_key(hDB, 0, "/Runinfo/Run number", &hkey);
// set run number
db_set_data(hDB, hkey, &run_number, sizeof(run_number),TID_INT32);
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
data(const void *) –Buffer from which data gets copied to. -
buf_size(INT) –Size of data buffer. -
num_values(INT) –Number of data values (for arrays). -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types).
Returns:
-
INT–
Declared in include/midas.h:1875, defined in src/odb.cxx:7946
db_set_data1
INT db_set_data1(HNDLE hdb, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Same as db_set_data(), but do not notify hot-linked clients
Declared in include/midas.h:1876, defined in src/odb.cxx:8044
db_set_data_index
INT db_set_data_index(HNDLE hDB, HNDLE hKey, const void *data, INT size, INT index, DWORD type)
Set key data for a key which contains an array of values.
This function sets individual values of a key containing an array. If the index is larger than the array size, the array is extended and the intermediate values are set to zero.
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
data(const void *) –Pointer to single value of data. -
size(INT) -
index(INT) –Size of single data element. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types). -
data_size
Returns:
-
INT–
Declared in include/midas.h:1879, defined in src/odb.cxx:8376
db_set_data_index1
INT db_set_data_index1(HNDLE hDB, HNDLE hKey, const void *data, INT size, INT index, DWORD type, BOOL bNotify)
Defined in include/midas.h:1881
db_set_link_data
INT db_set_link_data(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Same as db_set_data, but it does not follow a link to an array index
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
data(const void *) –Buffer from which data gets copied to. -
buf_size(INT) –Size of data buffer. -
num_values(INT) –Number of data values (for arrays). -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types).
Returns:
-
INT–
Declared in include/midas.h:1878, defined in src/odb.cxx:8156
db_set_link_data_index
INT db_set_link_data_index(HNDLE hDB, HNDLE hKey, const void *data, INT size, INT index, DWORD type)
Same as db_set_data_index, but does not follow links.
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
data(const void *) –Pointer to single value of data. -
size(INT) -
index(INT) –Size of single data element. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types). -
data_size
Returns:
-
INT–
Declared in include/midas.h:1880, defined in src/odb.cxx:8481
db_set_lock_timeout
INT db_set_lock_timeout(HNDLE database_handle, int timeout_millisec)
return zero if no ODB is open or we run remotely
Declared in include/msystem.h:541, defined in src/odb.cxx:3434
db_set_mode
INT db_set_mode(HNDLE hdb, HNDLE key_handle, WORD mode, BOOL recurse)
Defined in include/midas.h:1884
db_set_num_values
INT db_set_num_values(HNDLE hDB, HNDLE hKey, INT num_values)
Defined in include/midas.h:1882
db_set_record
INT db_set_record(HNDLE hdb, HNDLE hKey, void *data, INT buf_size, INT align)
Copy a set of keys from local memory to the database.
An ODB sub-tree can be mapped to a C structure automatically via a hot-link using the function db_open_record() or manually with this function. Problems might occur if the ODB sub-tree contains values which don't match the C structure. Although the structure size is checked against the sub-tree size, no checking can be done if the type and order of the values in the structure are the same than those in the ODB sub-tree. Therefore it is recommended to use the function db_create_record() before using this function.
...
memset(&lazyst,0,size);
if (db_find_key(hDB, pLch->hKey, "Statistics",&hKeyst) == DB_SUCCESS)
status = db_set_record(hDB, hKeyst, &lazyst, size, 0);
else
cm_msg(MERROR,"task","record %s/statistics not found", pLch->name)
...
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key where search starts, zero for root. -
data(void *) –Pointer where data is stored. -
buf_size(INT) –Size of data structure, must be obtained via sizeof(RECORD-NAME). -
align(INT) –Byte alignment calculated by the stub and passed to the rpc side to align data according to local machine. Must be zero when called from user level.
Returns:
-
INT–
Declared in include/midas.h:1894, defined in src/odb.cxx:13223
db_set_record2
INT db_set_record2(HNDLE hdb, HNDLE hKey, void *data, INT buf_size, INT align, const char *rec_str)
Defined in include/midas.h:1895
db_set_value
INT db_set_value(HNDLE hdb, HNDLE hKeyRoot, const char *key_name, const void *data, INT size, INT num_values, DWORD type)
Set value of a single key.
The function sets a single value or a whole array to a ODB key. Since the data buffer is of type void, no type checking can be performed by the compiler. Therefore the type has to be explicitly supplied, which is checked against the type stored in the ODB. key_name can contain the full path of a key (like: "/Equipment/Trigger/Settings/Level1") while hkey is zero which refers to the root, or hkey can refer to a sub-directory (like /Equipment/Trigger) and key_name is interpreted relative to that directory like "Settings/Level1".
INT level1;
db_set_value(hDB, 0, "/Equipment/Trigger/Settings/Level1",
&level1, sizeof(level1), 1, TID_INT32);
Parameters:
-
hdb(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKeyRoot(HNDLE) –Handle for key where search starts, zero for root. -
key_name(const char *) –Name of key to search, can contain directories. -
data(const void *) –Address of data. -
size(INT) –Size of data (in bytes). -
num_values(INT) –Number of data elements. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types)
Returns:
-
INT–
Declared in include/midas.h:1835, defined in src/odb.cxx:5716
db_set_value_index
INT db_set_value_index(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT index, DWORD type, BOOL truncate)
Set single value of an array.
The function sets a single value of an ODB key which is an array. key_name can contain the full path of a key (like: "/Equipment/Trigger/Settings/Level1") while hkey is zero which refers to the root, or hkey can refer to a sub-directory (like /Equipment/Trigger) and key_name is interpreted relative to that directory like "Settings/Level1".
INT level1;
db_set_value_index(hDB, 0, "/Equipment/Trigger/Settings/Level1",
&level1, sizeof(level1), 15, TID_INT32, FALSE);
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKeyRoot(HNDLE) –Handle for key where search starts, zero for root. -
key_name(const char *) –Name of key to search, can contain directories. -
data(const void *) –Address of data. -
data_size(INT) –Size of data (in bytes). -
index(INT) –Array index of value. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types) -
truncate(BOOL) –Truncate array to current index if TRUE
Returns:
-
INT–\<same as db_set_data_index>
Declared in include/midas.h:1836, defined in src/odb.cxx:5823
db_set_value_string
INT db_set_value_string(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const std::string* s)
Declared in include/midas.h:1841, defined in src/odb.cxx:14941
db_set_watchdog_params
void db_set_watchdog_params(DWORD timeout)
set watchdog flag of all open databases
Declared in include/msystem.h:555, defined in src/odb.cxx:3746
db_sor
MJsonNode*db_sor(HNDLE hDB, const char* path)
printf("db_sor(%s)\n", root_path);
Declared in include/midas.h:1932, defined in src/odb.cxx:15097
db_sprintf
Note: this function has 2 different signatures.
db_sprintf
INT db_sprintf(char *string, const void *data, INT data_size, INT index, DWORD type)
Convert a database value to a string according to its type.
This function is a convenient way to convert a binary ODB value into a string depending on its type if is not known at compile time. If it is known, the normal sprintf() function can be used.
...
for (j=0 ; j<key.num_values ; j++)
{
db_sprintf(pbuf, pdata, key.item_size, j, key.type);
strcat(pbuf, "\n");
}
...
Parameters:
-
string(char *) –output ASCII string of data. must be at least MAX_STRING_LENGTH bytes long. -
data(const void *) –Value data. -
data_size(INT) –Size of single data element. -
index(INT) –Index for array data. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types).
Returns:
-
INT–
Declared in include/midas.h:1936, defined in src/odb.cxx:11768
db_sprintf
std::string db_sprintf(const void *data, INT data_size, INT index, DWORD type)
Convert a database value to a string according to its type.
This function is a convenient way to convert a binary ODB value into a string depending on its type if is not known at compile time. If it is known, the normal sprintf() function can be used.
...
for (j=0 ; j<key.num_values ; j++)
{
std::string s = db_sprintf(pdata, key.item_size, j, key.type);
}
...
Parameters:
-
data(const void *) –Value data. -
data_size(INT) –Size of single data element. -
index(INT) –Index for array data. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types).
Returns:
-
std::string–string output ASCII string of data.
Declared in include/midas.h:1941, defined in src/odb.cxx:12012
db_sprintff
Note: this function has 2 different signatures.
db_sprintff
INT db_sprintff(char *string, const char *format, const void *data, INT data_size, INT index, DWORD type)
Same as db_sprintf, but with additional format parameter
Parameters:
-
string(char *) –output ASCII string of data. -
format(const char *) –Format specifier passed to sprintf() -
data(const void *) –Value data. -
data_size(INT) –Size of single data element. -
index(INT) –Index for array data. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types).
Returns:
-
INT–
Declared in include/midas.h:1938, defined in src/odb.cxx:11844
db_sprintff
std::string db_sprintff(const char *format, const void *data, INT data_size, INT index, DWORD type)
Same as db_sprintf, but with additional format parameter
Parameters:
-
format(const char *) –Format specifier passed to sprintf() -
data(const void *) –Value data. -
data_size(INT) –Size of single data element. -
index(INT) –Index for array data. -
type(DWORD) –Type of key, one of TID_xxx (seeMidas_Data_Types). -
string–output ASCII string of data.
Returns:
-
std::string–
Declared in include/midas.h:1942, defined in src/odb.cxx:12088
db_sprintfh
Note: this function has 2 different signatures.
db_sprintfh
INT db_sprintfh(char *string, const void *data, INT data_size, INT index, DWORD type)
Convert a database value to a string according to its type in hex format
Parameters:
-
string(char *) [out] –ASCII string of data -
data(const void *) [in] –Value data -
data_size(INT) [in] –Size of single data element -
index(INT) [in] –Index for array data -
type(DWORD) [in] –Valye type, one of TID_xxx
Returns:
-
DB_SUCCESS–Successful completion
Declared in include/midas.h:1940, defined in src/odb.cxx:11908
db_sprintfh
std::string db_sprintfh(const void *data, INT data_size, INT index, DWORD type)
Defined in include/midas.h:1943
db_sscanf
INT db_sscanf(const char *string, void *data, INT * data_size, INT index, DWORD type)
Defined in include/midas.h:1944
db_unlock_database
INT db_unlock_database(HNDLE database_handle)
Unlock a database via system semaphore calls.
Parameters:
-
database_handle(HNDLE) –Handle to the database to unlock
Returns:
-
INT–
Declared in include/msystem.h:539, defined in src/odb.cxx:3334
db_unwatch
INT db_unwatch(HNDLE hDB, HNDLE hKey)
Remove watch callback from a key previously watched with db_watch.
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key, zero for root.
Returns:
-
INT–
Declared in include/midas.h:1903, defined in src/odb.cxx:14823
db_unwatch_all
INT db_unwatch_all()
Closes all watched variables. This routines is called by db_close_all_databases() and cm_disconnect_experiment()
Returns:
-
INT–
Declared in include/midas.h:1904, defined in src/odb.cxx:14853
db_update_last_activity
INT db_update_last_activity(DWORD millitime)
Update last activity time
Declared in include/midas.h:1946, defined in src/odb.cxx:3462
db_update_record_local
INT db_update_record_local(INT hDB, INT hKeyRoot, INT hKey, int index)
db_open_record() and db_watch() event handler
Parameters:
-
hDB(INT) –ODB handle obtained via cm_get_experiment_database(). -
hKeyRoot(INT) -
hKey(INT) –Handle for key which changed. -
index(int) –Index for array keys.
Returns:
-
INT–
Declared in include/msystem.h:542, defined in src/odb.cxx:14487
db_update_record_mserver
INT db_update_record_mserver(INT hDB, INT hKeyRoot, INT hKey, int index, int client_socket)
Relay db_open_record() and db_watch() notification to the remote client.
Parameters:
-
hDB(INT) –ODB handle obtained via cm_get_experiment_database(). -
hKeyRoot(INT) -
hKey(INT) –Handle for key which changed. -
index(int) –Index for array keys. -
client_socket(int) -
s–client socket.
Returns:
-
INT–
Declared in include/msystem.h:543, defined in src/odb.cxx:14534
db_watch
INT db_watch(HNDLE hDB, HNDLE hKey, void (*dispatcher) (INT, INT, INT, void *info), void *info)
Watch an ODB subtree. The callback function gets called whenever a key in the watched subtree changes. The callback function receives 4 parameters: the database handle, the key handle of the entry that changed (could be a child if you're watching a directory), the index that changed (if it was part of an array), a user-specified 'info' parameter.
argument list composed of: HNDLE hDB, HNDLE hKey, INT idx, void* info
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key at top of subtree to watch, zero for root. -
dispatcher(void (*) (INT, INT, INT, void *info)) -
info(void *)
Returns:
-
INT–
Declared in include/midas.h:1902, defined in src/odb.cxx:14748
ends_with_ustring
BOOL ends_with_ustring(const char *str, const char *suffix)
Declared in include/midas.h:1772, defined in src/odb.cxx:3992
equal_ustring
BOOL equal_ustring(const char *str1, const char *str2)
Declared in include/midas.h:1771, defined in src/odb.cxx:3971
json_write_anything
int json_write_anything(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end, int level, int must_be_subdir, int flags, time_t timestamp, std::vector<char> &odbbuf)
ODB error handling: must write valid JSON
Declared in include/msystem.h:561, defined in src/odb.cxx:11286
json_write_json
void json_write_json(char **buffer, int* buffer_size, int* buffer_end, int level, const char* s)
internal json functions
Declared in include/msystem.h:559, defined in src/odb.cxx:10260
json_write_string
void json_write_string(char **buffer, int* buffer_size, int* buffer_end, int level, const char* s)
Declared in include/msystem.h:560, defined in src/odb.cxx:10294
strarrayindex
void strarrayindex(char* odbpath, int* index1, int* index2)
utility function to extract array indexes
Declared in include/midas.h:1775, defined in src/odb.cxx:4043
strcomb
char *strcomb(const char **list)
Defined in include/midas.h:1950
strcomb1
std::string strcomb1(const char **list)
Defined in include/midas.h:1951
strmatch
BOOL strmatch(char* pattern, char*str)
utility function to match string against wildcard pattern
Declared in include/midas.h:1774, defined in src/odb.cxx:4005
Macros
HAVE_DB_GET_VALUE_STRING_CREATE_STRING_LENGTH
#define HAVE_DB_GET_VALUE_STRING_CREATE_STRING_LENGTH 1
Defined in include/midas.h:1839
Other db_xxx functions
db_copy_json_array
Note: this function has 2 different signatures.
db_copy_json_array
int db_copy_json_array(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end, std::vector<char> &odbbuf)
Defined in include/msystem.h:563
db_copy_json_array
int db_copy_json_array(HNDLE hDB, HNDLE hKey, const KEY* pkey, char **buffer, int* buffer_size, int* buffer_end, std::vector<char> &odbbuf)
Copy an ODB array in JSON format to a buffer
Parameters:
-
hDB(HNDLE) –ODB handle obtained via cm_get_experiment_database(). -
hKey(HNDLE) –Handle for key -
pkey(const KEY*) -
buffer(char **) –returns pointer to ASCII buffer with ODB contents -
buffer_size(int*) –returns size of ASCII buffer -
buffer_end(int*) –returns number of bytes contained in buffer -
odbbuf(std::vector<char> &)
Returns:
-
int–
Defined in src/odb.cxx:10916