DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dump_dunedaq__hsilibs__dal.cpp File Reference
Include dependency graph for dump_dunedaq__hsilibs__dal.cpp:

Go to the source code of this file.

Functions

static void usage (const char *s)
 
static void no_param (const char *s)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 36 of file dump_dunedaq__hsilibs__dal.cpp.

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
90std::cout << std::boolalpha;
91
92 try {
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) {
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}
Represents database objects.
const std::string & UID() const noexcept
Return object identity.
Defines base class for cache of template objects.
Try to access non-existent object or class.
Definition Errors.hpp:47
static void no_param(const char *s)
static void usage()

◆ no_param()

static void no_param ( const char * s)
static

Definition at line 30 of file dump_dunedaq__hsilibs__dal.cpp.

31{
32 std::cerr << "ERROR: the required argument for option \'" << s << "\' is missing\n\n";
33 exit (EXIT_FAILURE);
34}

◆ usage()

static void usage ( const char * s)
static

Definition at line 10 of file dump_dunedaq__hsilibs__dal.cpp.

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}