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