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