Line data Source code
1 : /**
2 : * @file TPStreamWriterApplication.cpp
3 : *
4 : * Implementation of TPStreamWriterApplication's generate_modules dal method
5 : *
6 : * This is part of the DUNE DAQ Software Suite, copyright 2023.
7 : * Licensing/copyright details are in the COPYING file that you should have
8 : * received with this code.
9 : */
10 :
11 :
12 : #include "ConfigObjectFactory.hpp"
13 : #include "conffwk/Configuration.hpp"
14 : #include "oks/kernel.hpp"
15 : #include "confmodel/Connection.hpp"
16 : #include "confmodel/Service.hpp"
17 : #include "confmodel/NetworkConnection.hpp"
18 : #include "appmodel/TPStreamWriterApplication.hpp"
19 : #include "appmodel/TPStreamWriterModule.hpp"
20 : #include "appmodel/TPStreamWriterConf.hpp"
21 : #include "appmodel/NetworkConnectionRule.hpp"
22 : #include "appmodel/NetworkConnectionDescriptor.hpp"
23 : #include "appmodel/ReadoutApplication.hpp"
24 : #include "appmodel/SourceIDConf.hpp"
25 : #include "appmodel/appmodelIssues.hpp"
26 : #include "logging/Logging.hpp"
27 :
28 : #include <string>
29 : #include <vector>
30 : #include <iostream>
31 : #include <fmt/core.h>
32 :
33 : namespace dunedaq {
34 : namespace appmodel {
35 :
36 : void
37 0 : TPStreamWriterApplication::generate_modules(const confmodel::Session* /*session*/) const
38 : {
39 0 : std::vector<const confmodel::DaqModule*> modules;
40 :
41 0 : ConfigObjectFactory obj_fac(this);
42 :
43 :
44 0 : auto tpwriterConf = get_tp_writer();
45 0 : if (tpwriterConf == 0) {
46 0 : throw (BadConf(ERS_HERE, "No TPStreamWriterModule configuration given"));
47 : }
48 0 : auto tpwriterConfObj = tpwriterConf->config_object();
49 :
50 0 : const NetworkConnectionDescriptor* tset_in_net_desc = nullptr;
51 0 : for (auto rule : get_network_rules()) {
52 0 : auto endpoint_class = rule->get_endpoint_class();
53 0 : auto data_type = rule->get_descriptor()->get_data_type();
54 0 : if (data_type == "TPSet") {
55 0 : tset_in_net_desc = rule->get_descriptor();
56 : }
57 0 : }
58 0 : if ( tset_in_net_desc== nullptr) {
59 0 : throw (BadConf(ERS_HERE, "No network descriptor given to receive TPSets"));
60 : }
61 : // Create Network Connection
62 0 : conffwk::ConfigObject tset_in_net_obj = obj_fac.create_net_obj(tset_in_net_desc, ".*");
63 :
64 :
65 0 : auto source_id = get_source_id();
66 0 : if (source_id == nullptr) {
67 0 : throw(BadConf(ERS_HERE, "No SourceIDConf given to TPWriterApplication!"));
68 : }
69 :
70 0 : uint tpw_idx = 0;
71 0 : std::string tpwrUid("tpwriter-"+std::to_string(source_id->get_sid()));
72 0 : conffwk::ConfigObject tpwrObj = obj_fac.create("TPStreamWriterModule", tpwrUid);
73 0 : tpwrObj.set_by_val<uint32_t>("source_id", source_id->get_sid());
74 0 : tpwrObj.set_by_val("writer_identifier", fmt::format("{}_tpw_{}", UID(), tpw_idx));
75 0 : tpwrObj.set_obj("configuration", &tpwriterConf->config_object());
76 0 : tpwrObj.set_objs("inputs", {&tset_in_net_obj} );
77 :
78 0 : modules.push_back(obj_fac.get_dal<TPStreamWriterModule>(tpwrUid));
79 :
80 0 : obj_fac.update_modules(modules);
81 0 : }
82 :
83 : } // namespace appmodel
84 : } // namespace dunedaq
|