DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
build
hsilibs
codegen
src
dump_dunedaq__hsilibs__dal.cpp
Go to the documentation of this file.
1
// *** this file is generated by oksdalgen ***
2
3
#include "
conffwk/ConfigObject.hpp
"
4
#include "
conffwk/Configuration.hpp
"
5
6
#include "
hsilibs/dal/HSIController.hpp
"
7
#include "
hsilibs/dal/HSIControllerConf.hpp
"
8
9
10
static
void
usage
(
const
char
* s)
11
{
12
std::cout << s <<
" -d db-name -c class-name [-q query | -i object-id] [-t]\n"
13
"\n"
14
"Options/Arguments:\n"
15
" -d | --data db-name mandatory name of the database\n"
16
" -c | --class-name class-name mandatory name of class\n"
17
" -q | --query query optional query to select class objects\n"
18
" -i | --object-id object-id optional identity to select one object\n"
19
" -t | --init-children all referenced objects are initialized (is used\n"
20
" for debug purposes and performance measurements)\n"
21
" -h | --help print this message\n"
22
"\n"
23
"Description:\n"
24
" The program prints out object(s) of given class.\n"
25
" If no query or object id is provided, all objects of the class are printed.\n"
26
" It is automatically generated by oksdalgen utility.\n"
27
"\n"
;
28
}
29
30
static
void
no_param
(
const
char
* s)
31
{
32
std::cerr <<
"ERROR: the required argument for option \'"
<< s <<
"\' is missing\n\n"
;
33
exit (EXIT_FAILURE);
34
}
35
36
int
main
(
int
argc,
char
*argv[])
37
{
38
// parse parameters
39
40
const
char
* db_name =
nullptr
;
41
const
char
* object_id =
nullptr
;
42
const
char
* query =
""
;
43
std::string class_name;
44
bool
init_children =
false
;
45
46
for
(
int
i = 1; i < argc; i++) {
47
const
char
* cp = argv[i];
48
if
(!strcmp(cp,
"-h"
) || !strcmp(cp,
"--help"
)) {
49
usage
(argv[0]);
50
return
0;
51
}
52
if
(!strcmp(cp,
"-t"
) || !strcmp(cp,
"--init-children"
)) {
53
init_children =
true
;
54
}
55
else
if
(!strcmp(cp,
"-d"
) || !strcmp(cp,
"--data"
)) {
56
if
(++i == argc || argv[i][0] ==
'-'
) {
no_param
(cp); }
else
{ db_name = argv[i]; }
57
}
58
else
if
(!strcmp(cp,
"-c"
) || !strcmp(cp,
"--class-name"
)) {
59
if
(++i == argc || argv[i][0] ==
'-'
) {
no_param
(cp); }
else
{ class_name = argv[i]; }
60
}
61
else
if
(!strcmp(cp,
"-i"
) || !strcmp(cp,
"--object-id"
)) {
62
if
(++i == argc || argv[i][0] ==
'-'
) {
no_param
(cp); }
else
{ object_id = argv[i]; }
63
}
64
else
if
(!strcmp(cp,
"-q"
) || !strcmp(cp,
"--query"
)) {
65
if
(++i == argc || argv[i][0] ==
'-'
) {
no_param
(cp); }
else
{ query = argv[i]; }
66
}
67
else
{
68
std::cerr <<
"ERROR: bad parameter "
<< cp << std::endl;
69
usage
(argv[0]);
70
return
(EXIT_FAILURE);
71
}
72
}
73
74
if
(db_name ==
nullptr
) {
75
std::cerr <<
"ERROR: no database name provided\n"
;
76
return
(EXIT_FAILURE);
77
}
78
79
if
(class_name.empty()) {
80
std::cerr <<
"ERROR: no class name provided\n"
;
81
return
(EXIT_FAILURE);
82
}
83
84
if
(*query != 0 && object_id !=
nullptr
) {
85
std::cerr <<
"ERROR: only one parameter -i or -q can be provided\n"
;
86
return
(EXIT_FAILURE);
87
}
88
89
90
std::cout << std::boolalpha;
91
92
try
{
93
dunedaq::conffwk::Configuration
conf(db_name);
94
95
if
(!conf.
loaded
()) {
96
std::cerr <<
"Can not load database: "
<< db_name << std::endl;
97
return
(EXIT_FAILURE);
98
}
99
100
std::vector< dunedaq::conffwk::ConfigObject > objects;
101
102
if
(object_id) {
103
dunedaq::conffwk::ConfigObject
obj;
104
try
{
105
conf.
get
(class_name, object_id, obj, 1);
106
}
107
catch
(dunedaq::conffwk::NotFound & ex) {
108
std::cerr <<
"Can not get object \'"
<< object_id <<
"\' of class \'"
<< class_name <<
"\':\n"
<< ex << std::endl;
109
return
(EXIT_FAILURE);
110
}
111
objects.push_back(obj);
112
}
113
else
{
114
try
{
115
conf.
get
(class_name, objects, query, 1);
116
}
117
catch
(dunedaq::conffwk::NotFound & ex) {
118
std::cerr <<
"Can not get objects of class \'"
<< class_name <<
"\':\n"
<< ex << std::endl;
119
return
(EXIT_FAILURE);
120
}
121
}
122
123
struct
SortByUId {
124
bool
operator() (
const
dunedaq::conffwk::ConfigObject
* o1,
const
dunedaq::conffwk::ConfigObject
* o2)
const
{
125
return
(o1->
UID
() < o2->
UID
());
126
};
127
};
128
129
std::set< dunedaq::conffwk::ConfigObject *, SortByUId > sorted_objects;
130
131
for
(
auto
& i : objects)
132
sorted_objects.insert(&i);
133
134
for
(
auto
& i : sorted_objects) {
135
if
(class_name ==
"HSIController"
) {
136
std::cout << *conf.
get
<
dunedaq::hsilibs::dal::HSIController
>(*i, init_children) << std::endl;
137
}
138
else
if
(class_name ==
"HSIControllerConf"
) {
139
std::cout << *conf.
get
<
dunedaq::hsilibs::dal::HSIControllerConf
>(*i, init_children) << std::endl;
140
}
141
else
{
142
std::cerr <<
"ERROR: do not know how to dump object of "
<< class_name <<
" class\n"
;
143
return
(EXIT_FAILURE);
144
}
145
}
146
}
147
catch
(dunedaq::conffwk::Exception & ex) {
148
std::cerr <<
"Caught "
<< ex << std::endl;
149
return
(EXIT_FAILURE);
150
}
151
152
return
0;
153
}
ConfigObject.hpp
dunedaq::conffwk::ConfigObject
Represents database objects.
Definition
ConfigObject.hpp:53
dunedaq::conffwk::ConfigObject::UID
const std::string & UID() const noexcept
Return object identity.
Definition
ConfigObject.hpp:225
dunedaq::conffwk::Configuration
Defines base class for cache of template objects.
Definition
Configuration.hpp:228
dunedaq::conffwk::Configuration::get
void get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Get object by class name and object id (multi-thread safe).
Definition
Configuration.cpp:247
dunedaq::conffwk::Configuration::loaded
bool loaded() const noexcept
Check if database is correctly loaded.
Definition
Configuration.cpp:305
dunedaq::hsilibs::dal::HSIControllerConf
Definition
HSIControllerConf.hpp:25
dunedaq::hsilibs::dal::HSIController
Definition
HSIController.hpp:25
Configuration.hpp
conffwk entry point
main
int main(int argc, char *argv[])
Definition
dump_dunedaq__hsilibs__dal.cpp:36
no_param
static void no_param(const char *s)
Definition
dump_dunedaq__hsilibs__dal.cpp:30
HSIControllerConf.hpp
HSIController.hpp
usage
static void usage()
Definition
oks_get_data.cxx:22
Generated on
for DUNE-DAQ by
1.17.0