DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TRMonReqApplication.cpp
Go to the documentation of this file.
1
25
27
32#include "confmodel/Service.hpp"
33
34#include "logging/Logging.hpp"
35#include "oks/kernel.hpp"
36
37#include <fmt/core.h>
38#include <string>
39#include <vector>
40
41namespace dunedaq {
42namespace appmodel {
43
44std::vector<const confmodel::DaqModule*>
46{
47
48 ConfigObjectFactory obj_fac(this);
49
50 std::vector<const confmodel::DaqModule*> modules;
51
52 // Containers for module specific config objects for output/input
53 std::vector<const conffwk::ConfigObject*> trmrOutputObjs;
54
55 // -- First, we process expected Queue and Network connections and create their objects.
56
57 // Process the queue rules looking for the TriggerDecisionToken queue between DataWriterModule and TRMonRequestor
58 const QueueDescriptor* tdtQDesc = nullptr;
59 for (auto rule : get_queue_rules()) {
60 auto destination_class = rule->get_destination_class();
61 if (destination_class == "TRMonRequestorModule") {
62 tdtQDesc = rule->get_descriptor();
63 }
64 }
65 if (tdtQDesc == nullptr) { // BadConf if no descriptor between DataWriterModule and TRMonRequestor
66 throw(BadConf(ERS_HERE, "Could not find queue descriptor rule for TriggerDecisionTokens!"));
67 }
68 // Create queue connection config object
69 auto tdtQueueObj = obj_fac.create_queue_obj(tdtQDesc, UID());
70
71 // Process the network rules looking for the TriggerRecord input for the DataWriter
72 const NetworkConnectionDescriptor* dwNetDesc = nullptr;
73 for (auto rule : get_network_rules()) {
74 auto descriptor = rule->get_descriptor();
75 auto data_type = descriptor->get_data_type();
76 if (data_type == "TriggerRecord") {
77 dwNetDesc = rule->get_descriptor();
78 }
79 }
80 if (dwNetDesc == nullptr) { // BadConf if no descriptor for TriggerRecords into DW
81 throw(BadConf(ERS_HERE, "Could not find network descriptor rule for input TriggerRecords!"));
82 }
83 // Create network connection config object
84 auto dwInputObj = obj_fac.create_net_obj(dwNetDesc, "");
85
86 // Process special Network rules!
87 // Looking for DataRequest rules from ReadoutAppplications in current Session
88 auto sessionApps = session->enabled_applications();
89 std::vector<conffwk::ConfigObject> trmonreqNetObjs;
90 for (auto app : sessionApps) {
91 auto smartapp = app->cast<appmodel::SmartDaqApplication>();
92 auto dfapp = app->cast<appmodel::DFApplication>();
93 if (smartapp == nullptr || dfapp == nullptr) {
94 continue;
95 }
96
97 auto dfNRules = smartapp->get_network_rules();
98 for (auto rule : dfNRules) {
99 auto descriptor = rule->get_descriptor();
100 auto data_type = descriptor->get_data_type();
101 if (data_type == "TRMonRequest") {
102 trmonreqNetObjs.emplace_back(obj_fac.create_net_obj(descriptor, smartapp->UID()));
103 } // If network rule has TRMonRequest type of data
104 } // Loop over Apps network rules
105 } // loop over Session specific Apps
106
107 // Get pointers to objects here, after vector has been filled so they don't move on us
108 for (auto& obj : trmonreqNetObjs) {
109 trmrOutputObjs.push_back(&obj);
110 }
111
112 // -- Second, we create the Module objects and assign their configs, with the precreated
113 // -- connection config objects above.
114
115 // Get TRB Config Object
116 auto trmrConf = get_trmonreq();
117 if (trmrConf == nullptr) {
118 throw(BadConf(ERS_HERE, "No TRMonRequestor configuration given"));
119 }
120 auto trmrConfObj = trmrConf->config_object();
121 // Prepare TRMR Module Object and assign its Config Object.
122 std::string trmrUid(UID() + "-trmr");
123 conffwk::ConfigObject trmrObj = obj_fac.create("TRMonRequestorModule", trmrUid);
124 trmrObj.set_obj("configuration", &trmrConfObj);
125 trmrObj.set_objs("inputs", { &tdtQueueObj });
126 trmrObj.set_objs("outputs", trmrOutputObjs);
127 trmrObj.set_obj("trigger_record_destination", &dwInputObj);
128 // Push TRMR Module Object from confdb
129 modules.push_back(obj_fac.get_dal<TRMonRequestorModule>(trmrUid));
130
131 // Get DataWriterModule Config Object (only one for now, maybe more later?)
132 auto dwrConf = get_data_writer();
133 if (dwrConf == nullptr) {
134 throw(BadConf(ERS_HERE, "No DataWriterModule configuration given"));
135 }
136
137 auto dwrConfObj = dwrConf->config_object();
138
139 // Prepare DataWriterModule Module Object and assign its Config Object.
140 std::string dwrUid(fmt::format("{}-dw", UID()));
141 conffwk::ConfigObject dwrObj = obj_fac.create("DataWriterModule", dwrUid);
142 dwrObj.set_by_val("writer_identifier", fmt::format("{}_dw", UID()));
143 dwrObj.set_obj("configuration", &dwrConfObj);
144 dwrObj.set_objs("inputs", { &dwInputObj });
145 dwrObj.set_objs("outputs", { &tdtQueueObj });
146 // Push DataWriterModule Module Object from confdb
147 modules.push_back(obj_fac.get_dal<DataWriterModule>(dwrUid));
148
149 return modules;
150}
151
152} // namespace appmodel
153} // namespace dunedaq
#define ERS_HERE
conffwk::ConfigObject create_net_obj(const NetworkConnectionDescriptor *ndesc, std::string uid) const
Helper function that gets a network connection config.
const T * get_dal(std::string uid) const
conffwk::ConfigObject create_queue_obj(const QueueDescriptor *qdesc, std::string uid="") const
conffwk::ConfigObject create(const std::string &class_name, const std::string &id) const
const std::vector< const dunedaq::appmodel::NetworkConnectionRule * > & get_network_rules() const
Get "network_rules" relationship value.
const std::vector< const dunedaq::appmodel::QueueConnectionRule * > & get_queue_rules() const
Get "queue_rules" relationship value.
std::vector< const dunedaq::confmodel::DaqModule * > generate_modules(const confmodel::Session *) const override
const dunedaq::appmodel::TRMonRequestorConf * get_trmonreq() const
Get "trmonreq" relationship value. Configuration of the TRMonRequestor to be generated by get_modules...
const dunedaq::appmodel::DataWriterConf * get_data_writer() const
Get "data_writer" relationship value.
void set_by_val(const std::string &name, T value)
Set attribute value.
void set_objs(const std::string &name, const std::vector< const ConfigObject * > &o, bool skip_non_null_check=false)
Set relationship multi-value.
void set_obj(const std::string &name, const ConfigObject *o, bool skip_non_null_check=false)
Set relationship single-value.
const TARGET * cast() const noexcept
Casts object to different class.
const std::string & UID() const noexcept
conffwk entry point
The DUNE-DAQ namespace.
msgpack::object obj