Line data Source code
1 : //
2 : // DUNE DAQ modification notice:
3 : // This file has been modified from the original ATLAS config source for the DUNE DAQ project.
4 : // Fork baseline commit: 67a24e731 (2022-10-27).
5 : // Renamed since fork: yes (from test/config_test_object.cpp to test/apps/config_test_object.cxx).
6 : //
7 :
8 : #include <stdlib.h>
9 :
10 : #include <iostream>
11 : #include <string>
12 :
13 : #include "conffwk/Configuration.hpp"
14 : #include "conffwk/ConfigObject.hpp"
15 :
16 : using namespace dunedaq::conffwk;
17 :
18 0 : ERS_DECLARE_ISSUE(
19 : conffwk_test_object,
20 : BadCommandLine,
21 : "bad command line: " << reason,
22 : ((const char*)reason)
23 : )
24 :
25 0 : ERS_DECLARE_ISSUE(
26 : conffwk_test_object,
27 : ConfigException,
28 : "caught dunedaq::conffwk::Exception exception",
29 : )
30 :
31 : static void
32 0 : usage()
33 : {
34 0 : std::cout <<
35 : "Usage: conffwk_test_object -d | --database dbspec\n"
36 : " -c | --class-name class\n"
37 : " -o | --object-id object\n"
38 : "\n"
39 : "Options/Arguments:\n"
40 : " -d dbspec database specification in format plugin-name:parameters\n"
41 : " -c class name of the class to dump\n"
42 : " -o object optional id of the object to dump\n"
43 : "\n"
44 : "Description:\n"
45 0 : " The utility tests object existence.\n\n";
46 :
47 0 : }
48 :
49 : static void
50 0 : no_param(const char * s)
51 : {
52 0 : std::ostringstream text;
53 0 : text << "no parameter for " << s << " provided";
54 0 : ers::fatal(conffwk_test_object::BadCommandLine(ERS_HERE, text.str().c_str()));
55 0 : exit(EXIT_FAILURE);
56 0 : }
57 :
58 :
59 0 : int main(int argc, char *argv[])
60 : {
61 0 : const char * db_name = 0;
62 0 : const char * class_name = 0;
63 0 : const char * object_id = 0;
64 :
65 0 : for(int i = 1; i < argc; i++) {
66 0 : const char * cp = argv[i];
67 :
68 0 : if(!strcmp(cp, "-h") || !strcmp(cp, "--help")) {
69 0 : usage();
70 0 : return 0;
71 : }
72 0 : else if(!strcmp(cp, "-d") || !strcmp(cp, "--database")) {
73 0 : if(++i == argc) { no_param(cp); } else { db_name = argv[i]; }
74 : }
75 0 : else if(!strcmp(cp, "-c") || !strcmp(cp, "--class-name")) {
76 0 : if(++i == argc) { no_param(cp); } else { class_name = argv[i]; }
77 : }
78 0 : else if(!strcmp(cp, "-o") || !strcmp(cp, "--object-id")) {
79 0 : if(++i == argc) { no_param(cp); } else { object_id = argv[i]; }
80 : }
81 : else {
82 0 : std::ostringstream text;
83 0 : text << "unexpected parameter: \'" << cp << "\'; run command with --help to see valid command line options.";
84 0 : ers::fatal(conffwk_test_object::BadCommandLine(ERS_HERE, text.str().c_str()));
85 0 : return (EXIT_FAILURE);
86 0 : }
87 : }
88 :
89 0 : if(!db_name) {
90 0 : ers::fatal(conffwk_test_object::BadCommandLine(ERS_HERE, "no database name given"));
91 0 : return (EXIT_FAILURE);
92 : }
93 :
94 0 : if(!class_name) {
95 0 : ers::fatal(conffwk_test_object::BadCommandLine(ERS_HERE, "no class name given"));
96 0 : return (EXIT_FAILURE);
97 : }
98 :
99 0 : if(!object_id) {
100 0 : ers::fatal(conffwk_test_object::BadCommandLine(ERS_HERE, "no object id given"));
101 0 : return (EXIT_FAILURE);
102 : }
103 :
104 0 : try {
105 0 : Configuration db(db_name);
106 :
107 0 : if(db.test_object(class_name, object_id)) {
108 0 : std::cout << "object \'" << object_id << '@' << class_name << "\' exists" << std::endl;
109 : }
110 : else {
111 0 : std::cout << "object \'" << object_id << '@' << class_name << "\' does not exist" << std::endl;
112 : }
113 :
114 0 : return 0;
115 0 : }
116 0 : catch (dunedaq::conffwk::Exception & ex) {
117 0 : ers::fatal(conffwk_test_object::ConfigException(ERS_HERE, ex));
118 0 : }
119 :
120 0 : return (EXIT_FAILURE);
121 : }
|