Line data Source code
1 : /**
2 : * @file print_detailed_config_info.cxx
3 : *
4 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "logging/Logging.hpp"
10 :
11 : #include "conffwk/ConfigObject.hpp"
12 : #include "conffwk/ConfigObjectImpl.hpp"
13 : #include "conffwk/Configuration.hpp"
14 : #include "conffwk/ConfigurationImpl.hpp"
15 : #include "conffwk/Schema.hpp"
16 :
17 : #include "confmodel/Connection.hpp"
18 : #include "confmodel/DaqModule.hpp"
19 : #include "confmodel/Session.hpp"
20 :
21 : #include "appmodel/DFApplication.hpp"
22 : #include "appmodel/DFOApplication.hpp"
23 : #include "appmodel/MLTApplication.hpp"
24 : #include "appmodel/ReadoutApplication.hpp"
25 : #include "appmodel/SmartDaqApplication.hpp"
26 : #include "appmodel/TPStreamWriterApplication.hpp"
27 : #include "appmodel/TriggerApplication.hpp"
28 : #include "appmodel/TPReplayApplication.hpp"
29 :
30 : #include "appmodel/appmodelIssues.hpp"
31 :
32 : #include <string>
33 : using namespace dunedaq;
34 :
35 : // forward declaration
36 : void
37 : print_object_details(conffwk::ConfigObject& config_object_to_print,
38 : const std::string& object_name,
39 : conffwk::Configuration* confdb,
40 : const std::string& spaces,
41 : std::vector<std::string>& list_of_applications);
42 :
43 : // function for handling a ConfigObject data member
44 : void
45 0 : print_member_details_if_needed(conffwk::ConfigObject& parent_config_object,
46 : const std::string& member_name,
47 : conffwk::Configuration* confdb,
48 : const std::string& spaces,
49 : std::vector<std::string>& list_of_applications)
50 : {
51 0 : try {
52 0 : conffwk::ConfigObject member_object;
53 0 : parent_config_object.get(member_name, member_object);
54 0 : if (!member_object.is_null()) {
55 0 : print_object_details(member_object, member_name, confdb, spaces + " ", list_of_applications);
56 : }
57 0 : } catch (conffwk::Exception& exc) {
58 0 : try {
59 0 : std::vector<conffwk::ConfigObject> member_object_list;
60 0 : parent_config_object.get(member_name, member_object_list);
61 0 : for (uint32_t idx = 0; idx < member_object_list.size(); ++idx) {
62 0 : if (!member_object_list[idx].is_null()) {
63 0 : if (member_name != "inputs" && member_name != "outputs") {
64 0 : std::ostringstream oss_name;
65 0 : oss_name << member_name << "[" << idx << "]";
66 0 : print_object_details(member_object_list[idx], oss_name.str(), confdb, spaces + " ", list_of_applications);
67 0 : }
68 : }
69 : }
70 0 : } catch (conffwk::Exception& exc) {
71 0 : }
72 0 : }
73 0 : }
74 :
75 : // function for printing out the details of a specified ConfigObject
76 : void
77 0 : print_object_details(conffwk::ConfigObject& config_object_to_print,
78 : const std::string& object_name,
79 : conffwk::Configuration* confdb,
80 : const std::string& spaces,
81 : std::vector<std::string>& list_of_applications)
82 : {
83 0 : if (object_name != "") {
84 0 : std::cout << spaces << "-----" << std::endl;
85 0 : std::cout << spaces << "\"" << object_name << "\" ";
86 : }
87 0 : config_object_to_print.print_ref(std::cout, *confdb, spaces);
88 0 : dunedaq::conffwk::class_t cd = confdb->get_class_info(config_object_to_print.class_name());
89 0 : for (const auto& attr : cd.p_attributes) {
90 0 : const std::string& attr_name(attr.p_name);
91 0 : print_member_details_if_needed(config_object_to_print, attr_name, confdb, spaces, list_of_applications);
92 0 : if (attr_name == "application_name") {
93 0 : std::string application_name;
94 0 : config_object_to_print.get(attr_name, application_name);
95 0 : if (application_name == "daq_application") {
96 0 : std::cout << "Application name = " << application_name << std::endl;
97 0 : std::cout << "Application UID = " << config_object_to_print.UID() << std::endl;
98 0 : list_of_applications.push_back(config_object_to_print.UID());
99 : }
100 0 : }
101 : }
102 0 : for (const auto& relship : cd.p_relationships) {
103 0 : const std::string& rel_name(relship.p_name);
104 0 : print_member_details_if_needed(config_object_to_print, rel_name, confdb, spaces, list_of_applications);
105 : }
106 0 : }
107 :
108 : int
109 0 : main(int argc, char* argv[])
110 : {
111 0 : if (argc < 3) {
112 0 : std::cout << "Usage: " << argv[0] << " <session> <database-file>\n";
113 0 : return 0;
114 : }
115 :
116 0 : std::string sessionName(argv[1]);
117 :
118 0 : logging::Logging::setup(sessionName, "print_detailed_config_info");
119 :
120 0 : std::string dbfile(argv[2]);
121 0 : conffwk::Configuration* confdb;
122 0 : std::string blah = "oksconflibs:" + dbfile;
123 0 : try {
124 0 : confdb = new conffwk::Configuration(blah);
125 0 : } catch (conffwk::Generic& exc) {
126 0 : std::cout << "Failed to load OKS database: " << exc << std::endl;
127 0 : return 0;
128 0 : }
129 :
130 0 : auto session = confdb->get<confmodel::Session>(sessionName);
131 0 : if (session == nullptr) {
132 0 : std::cout << "Failed to get Session " << sessionName << " from database\n";
133 : return 0;
134 : }
135 :
136 : // 14-Aug-2024, KAB: maybe this has useful information too...?
137 : // session->print(0, true, std::cout);
138 : // std::cout << "=====" << std::endl;
139 :
140 0 : std::cout << "++++++++++" << std::endl;
141 0 : std::cout << "Full-system details without module generation" << std::endl;
142 0 : std::cout << "++++++++++" << std::endl;
143 0 : std::cout << std::endl;
144 :
145 0 : std::vector<std::string> list_of_application_names;
146 0 : conffwk::ConfigObject session_config_object = session->config_object();
147 0 : print_object_details(session_config_object, "", confdb, " ", list_of_application_names);
148 :
149 0 : std::cout << std::endl;
150 0 : std::cout << "++++++++++" << std::endl;
151 0 : std::cout << "Individual application details including module generation" << std::endl;
152 0 : std::cout << "++++++++++" << std::endl;
153 :
154 0 : for (size_t idx = 0; idx < list_of_application_names.size(); ++idx) {
155 0 : std::cout << std::endl;
156 :
157 0 : confdb = nullptr;
158 0 : try {
159 0 : confdb = new conffwk::Configuration(blah);
160 0 : } catch (conffwk::Generic& exc) {
161 0 : std::cout << "Failed to load OKS database: " << exc << std::endl;
162 0 : return 0;
163 0 : }
164 0 : session = confdb->get<confmodel::Session>(sessionName);
165 :
166 0 : auto daqapp = confdb->get<appmodel::SmartDaqApplication>(list_of_application_names[idx]);
167 0 : std::string appName = list_of_application_names[idx];
168 0 : if (daqapp) {
169 0 : std::cout << appName << " is of class " << daqapp->class_name() << std::endl;
170 :
171 0 : auto res = daqapp->cast<confmodel::Resource>();
172 0 : if (res && res->is_disabled(*session)) {
173 0 : std::cout << "Application " << appName << " is disabled" << std::endl;
174 0 : continue;
175 : }
176 :
177 0 : try {
178 0 : daqapp->generate_modules(session);
179 0 : } catch (appmodel::BadConf& exc) {
180 0 : std::cout << "Caught BadConf exception: " << exc << std::endl;
181 0 : exit(-1);
182 0 : }
183 :
184 0 : auto modules = daqapp->get_modules();
185 : // std::cout << "Generated " << modules.size() << " modules" << std::endl;
186 0 : for (auto module : modules) {
187 0 : std::cout << "module " << module->UID() << std::endl;
188 0 : conffwk::ConfigObject module_config_object = module->config_object();
189 0 : std::vector<std::string> dummy_list;
190 0 : print_object_details(module_config_object, "", confdb, " ", dummy_list);
191 0 : std::cout << " input objects " << std::endl;
192 0 : for (auto input : module->get_inputs()) {
193 0 : auto iObj = input->config_object();
194 0 : iObj.print_ref(std::cout, *confdb, " ");
195 0 : }
196 0 : std::cout << " output objects " << std::endl;
197 0 : for (auto output : module->get_outputs()) {
198 0 : auto oObj = output->config_object();
199 0 : oObj.print_ref(std::cout, *confdb, " ");
200 0 : }
201 0 : }
202 0 : } else {
203 0 : std::cout << "Failed to get SmartDaqApplication " << appName << " from database\n";
204 0 : return 0;
205 : }
206 0 : }
207 0 : }
|