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

40{
41 // parse parameters
42
43 const char * db_name = nullptr;
44 const char * object_id = nullptr;
45 const char * query = "";
46 std::string class_name;
47 bool init_children = false;
48
49 for(int i = 1; i < argc; i++) {
50 const char * cp = argv[i];
51 if(!strcmp(cp, "-h") || !strcmp(cp, "--help")) {
52 usage(argv[0]);
53 return 0;
54 }
55 if(!strcmp(cp, "-t") || !strcmp(cp, "--init-children")) {
56 init_children = true;
57 }
58 else if(!strcmp(cp, "-d") || !strcmp(cp, "--data")) {
59 if(++i == argc || argv[i][0] == '-') { no_param(cp); } else { db_name = argv[i]; }
60 }
61 else if(!strcmp(cp, "-c") || !strcmp(cp, "--class-name")) {
62 if(++i == argc || argv[i][0] == '-') { no_param(cp); } else { class_name = argv[i]; }
63 }
64 else if(!strcmp(cp, "-i") || !strcmp(cp, "--object-id")) {
65 if(++i == argc || argv[i][0] == '-') { no_param(cp); } else { object_id = argv[i]; }
66 }
67 else if(!strcmp(cp, "-q") || !strcmp(cp, "--query")) {
68 if(++i == argc || argv[i][0] == '-') { no_param(cp); } else { query = argv[i]; }
69 }
70 else {
71 std::cerr << "ERROR: bad parameter " << cp << std::endl;
72 usage(argv[0]);
73 return (EXIT_FAILURE);
74 }
75 }
76
77 if(db_name == nullptr) {
78 std::cerr << "ERROR: no database name provided\n";
79 return (EXIT_FAILURE);
80 }
81
82 if(class_name.empty()) {
83 std::cerr << "ERROR: no class name provided\n";
84 return (EXIT_FAILURE);
85 }
86
87 if(*query != 0 && object_id != nullptr) {
88 std::cerr << "ERROR: only one parameter -i or -q can be provided\n";
89 return (EXIT_FAILURE);
90 }
91
92
93std::cout << std::boolalpha;
94
95 try {
97
98 if(!conf.loaded()) {
99 std::cerr << "Can not load database: " << db_name << std::endl;
100 return (EXIT_FAILURE);
101 }
102
103 std::vector< dunedaq::conffwk::ConfigObject > objects;
104
105 if(object_id) {
107 try {
108 conf.get(class_name, object_id, obj, 1);
109 }
110 catch (dunedaq::conffwk::NotFound & ex) {
111 std::cerr << "Can not get object \'" << object_id << "\' of class \'" << class_name << "\':\n" << ex << std::endl;
112 return (EXIT_FAILURE);
113 }
114 objects.push_back(obj);
115 }
116 else {
117 try {
118 conf.get(class_name, objects, query, 1);
119 }
120 catch (dunedaq::conffwk::NotFound & ex) {
121 std::cerr << "Can not get objects of class \'" << class_name << "\':\n" << ex << std::endl;
122 return (EXIT_FAILURE);
123 }
124 }
125
126 struct SortByUId {
127 bool operator() (const dunedaq::conffwk::ConfigObject * o1, const dunedaq::conffwk::ConfigObject * o2) const {
128 return (o1->UID() < o2->UID());
129 };
130 };
131
132 std::set< dunedaq::conffwk::ConfigObject *, SortByUId > sorted_objects;
133
134 for(auto& i : objects)
135 sorted_objects.insert(&i);
136
137 for(auto& i : sorted_objects) {
138 if(class_name == "ListRevModule") {
139 std::cout << *conf.get<dunedaq::listrev::dal::ListRevModule>(*i, init_children) << std::endl;
140 }
141 else if(class_name == "ListReverser") {
142 std::cout << *conf.get<dunedaq::listrev::dal::ListReverser>(*i, init_children) << std::endl;
143 }
144 else if(class_name == "RandomDataListGenerator") {
145 std::cout << *conf.get<dunedaq::listrev::dal::RandomDataListGenerator>(*i, init_children) << std::endl;
146 }
147 else if(class_name == "RandomListGeneratorSet") {
148 std::cout << *conf.get<dunedaq::listrev::dal::RandomListGeneratorSet>(*i, init_children) << std::endl;
149 }
150 else if(class_name == "ReversedListValidator") {
151 std::cout << *conf.get<dunedaq::listrev::dal::ReversedListValidator>(*i, init_children) << std::endl;
152 }
153 else {
154 std::cerr << "ERROR: do not know how to dump object of " << class_name << " class\n";
155 return (EXIT_FAILURE);
156 }
157 }
158 }
159 catch (dunedaq::conffwk::Exception & ex) {
160 std::cerr << "Caught " << ex << std::endl;
161 return (EXIT_FAILURE);
162 }
163
164 return 0;
165}
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 33 of file dump_dunedaq__listrev__dal.cpp.

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

◆ usage()

static void usage ( const char * s)
static

Definition at line 13 of file dump_dunedaq__listrev__dal.cpp.

14{
15 std::cout << s << " -d db-name -c class-name [-q query | -i object-id] [-t]\n"
16 "\n"
17 "Options/Arguments:\n"
18 " -d | --data db-name mandatory name of the database\n"
19 " -c | --class-name class-name mandatory name of class\n"
20 " -q | --query query optional query to select class objects\n"
21 " -i | --object-id object-id optional identity to select one object\n"
22 " -t | --init-children all referenced objects are initialized (is used\n"
23 " for debug purposes and performance measurements)\n"
24 " -h | --help print this message\n"
25 "\n"
26 "Description:\n"
27 " The program prints out object(s) of given class.\n"
28 " If no query or object id is provided, all objects of the class are printed.\n"
29 " It is automatically generated by oksdalgen utility.\n"
30 "\n";
31}