DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dump_dunedaq__appfwk__dal.cpp File Reference
Include dependency graph for dump_dunedaq__appfwk__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 35 of file dump_dunedaq__appfwk__dal.cpp.

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
89std::cout << std::boolalpha;
90
91 try {
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) {
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 == "DummyModule") {
135 std::cout << *conf.get<dunedaq::appfwk::dal::DummyModule>(*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}
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 29 of file dump_dunedaq__appfwk__dal.cpp.

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

◆ usage()

static void usage ( const char * s)
static

Definition at line 9 of file dump_dunedaq__appfwk__dal.cpp.

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}