76 TLOG_DEBUG(6) <<
"Generating modules for application " << this->
UID();
86 if (reader_conf == 0) {
87 throw(BadConf(
ERS_HERE,
"No DataReaderModule configuration given"));
89 std::string reader_class = reader_conf->get_template_for();
94 auto dlh_class = dlh_conf->get_template_for();
98 throw(BadConf(
ERS_HERE,
"TP generation is enabled but there is no TP data handler configuration"));
101 std::string tph_class =
"";
103 tph_class = tph_conf->get_template_for();
115 auto destination_class = rule->get_destination_class();
116 auto data_type = rule->get_descriptor()->get_data_type();
118 if (destination_class ==
"DataHandlerModule" || destination_class == dlh_class || destination_class == tph_class) {
119 if (data_type ==
"DataRequest") {
120 dlh_reqinput_qdesc = rule->get_descriptor();
122 tp_input_qdesc = rule->get_descriptor();
124 }
else if (destination_class ==
"FragmentAggregatorModule") {
125 fa_output_qdesc = rule->get_descriptor();
137 auto endpoint_class = rule->get_endpoint_class();
138 auto data_type = rule->get_descriptor()->get_data_type();
140 if (endpoint_class ==
"FragmentAggregatorModule") {
141 fa_net_desc = rule->get_descriptor();
142 }
else if (data_type ==
"TPSet") {
143 tp_net_desc = rule->get_descriptor();
144 }
else if (data_type ==
"TriggerActivity") {
145 ta_net_desc = rule->get_descriptor();
146 }
else if (data_type ==
"TimeSync") {
147 ts_net_desc = rule->get_descriptor();
153 if (fa_output_qdesc ==
nullptr) {
154 throw(BadConf(
ERS_HERE,
"No fragment output queue descriptor given"));
156 std::vector<const confmodel::Connection*> req_queues;
164 if (raw_data_callback_desc ==
nullptr) {
165 throw(BadConf(
ERS_HERE,
"No Raw Data Callback descriptor given"));
172 std::vector<const confmodel::DaqModule*> modules;
178 std::vector<std::pair<int16_t, const confmodel::DetectorStream*>> all_enabled_det_streams;
179 std::map<uint32_t, const appmodel::DataMoveCallbackConf*> callback_confs_by_sid;
181 std::vector<const conffwk::ConfigObject*> d2d_conn_objs;
182 uint16_t conn_idx = 0;
185 std::set<int16_t> numas;
187 uint16_t receiver_numa = 0;
190 if (helper->is_disabled(d2d_conn)) {
191 TLOG_DEBUG(7) <<
"Ignoring disabled DetectorToDaqConnection " << d2d_conn->UID();
195 d2d_conn_objs.push_back(&d2d_conn->config_object());
197 TLOG_DEBUG(6) <<
"Processing DetectorToDaqConnection " << d2d_conn->UID();
200 if (d2d_conn->senders().empty()) {
201 throw(BadConf(
ERS_HERE,
"DetectorToDaqConnection does not contain sebders or receivers"));
203 if (d2d_conn->receiver() ==
nullptr) {
204 throw(BadConf(
ERS_HERE,
"DetectorToDaqConnection does not contain a receiver"));
208 auto det_senders = d2d_conn->senders();
209 auto det_receiver = d2d_conn->receiver();
213 bool requires_dpdk = (reader_class ==
"DPDKReaderModule" || reader_class ==
"FDFakeReaderModule");
215 if (reader_class ==
"DPDKReaderModule" || reader_class ==
"SocketReaderModule" || reader_class ==
"FDFakeReaderModule") {
218 std::string required_class = requires_dpdk ?
"DPDKReceiver" :
"SocketReceiver";
219 throw(BadConf(
ERS_HERE, fmt::format(
"{} requires {}, found {} of class {}", reader_class, required_class, det_receiver->UID(), det_receiver->class_name())));
224 if (reader_class ==
"DPDKReaderModule" || reader_class ==
"FDFakeReaderModule") {
227 TLOG_DEBUG(7) <<
"receiver numa: " << receiver_numa;
230 bool all_nw_senders =
true;
231 for (
auto s : det_senders) {
236 if (!all_nw_senders) {
237 throw(BadConf(
ERS_HERE,
"Non-network DetDataSener found with NWreceiver"));
241 std::vector<const confmodel::DetectorStream*> enabled_det_streams;
243 for (
auto stream : d2d_conn->streams()) {
246 if (helper->is_disabled(stream)) {
247 TLOG_DEBUG(7) <<
"Ignoring disabled DetectorStream " << stream->UID();
252 all_enabled_det_streams.push_back(std::make_pair(receiver_numa, stream));
253 enabled_det_streams.push_back(stream);
254 numas.insert(receiver_numa);
270 std::string reader_uid(fmt::format(
"datareader-{}-{}", this->
UID(), std::to_string(conn_idx++)));
271 TLOG_DEBUG(6) << fmt::format(
"creating OKS configuration object for Data reader class {} with id {}", reader_class, reader_uid);
272 auto reader_obj = obj_fac.
create(reader_class, reader_uid);
275 reader_obj.
set_obj(
"configuration", &reader_conf->config_object());
276 reader_obj.set_objs(
"connections", d2d_conn_objs);
279 std::vector<const conffwk::ConfigObject*> raw_data_callback_objs;
282 for (
auto& [numa, ds] : all_enabled_det_streams) {
285 raw_data_callback_objs.push_back(&callback_conf->config_object());
286 callback_confs_by_sid[ds->get_source_id()] = callback_conf;
289 reader_obj.set_objs(
"raw_data_callbacks", raw_data_callback_objs);
300 std::vector<std::pair<uint32_t, const confmodel::Connection*>> tp_queues;
305 auto tph_conf_obj = tph_conf->config_object();
308 if ((tpsrc_ids.size() % 3) > 0) {
309 throw(BadConf(
ERS_HERE, fmt::format(
"number of TP source IDs must be a multiple of 3, current amount: {}", tpsrc_ids.size())));
312 for (
auto sid : tpsrc_ids) {
315 std::string tp_uid(
"tphandler-" + std::to_string(sid->get_sid()));
316 auto tph_obj = obj_fac.
create(tph_class, tp_uid);
317 tph_obj.
set_by_val<uint32_t>(
"source_id", sid->get_sid());
318 tph_obj.set_by_val<uint32_t>(
"detector_id", 1);
320 tph_obj.set_obj(
"module_configuration", &tph_conf_obj);
324 tp_queue_obj.
set_by_val<uint32_t>(
"recv_timeout_ms", 50);
325 tp_queue_obj.
set_by_val<uint32_t>(
"send_timeout_ms", 1);
339 tph_obj.
set_objs(
"inputs", { &tp_queue_obj, &tpreq_queue_obj });
340 tph_obj.set_objs(
"outputs", { &tp_net_obj, &ta_net_obj, &frag_queue_obj });
346 std::vector<std::pair<uint32_t, const conffwk::ConfigObject*>> tp_queue_objs;
347 for (
auto q : tp_queues) {
348 tp_queue_objs.push_back(std::make_pair(q.first, &q.second->config_object()));
357 auto lb_conf = dlh_conf->get_latency_buffer();
359 std::map<int16_t, conffwk::ConfigObject> numa_dhlconf_map;
360 for ( int16_t numa : numas ) {
361 auto lb_confobj_numa = obj_fac.
create(lb_conf->class_name(), fmt::format(
"{}-numa{}",lb_conf->UID(), numa));
362 lb_confobj_numa.
set_by_val<uint32_t>(
"size", lb_conf->get_size());
363 lb_confobj_numa.set_by_val<
bool>(
"numa_aware", lb_conf->get_numa_aware());
364 lb_confobj_numa.set_by_val<int16_t>(
"numa_node", numa);
365 lb_confobj_numa.set_by_val<
bool>(
"intrinsic_allocator", lb_conf->get_intrinsic_allocator());
366 lb_confobj_numa.set_by_val<uint32_t>(
"alignment_size", lb_conf->get_alignment_size());
367 lb_confobj_numa.set_by_val<
bool>(
"preallocation", lb_conf->get_preallocation());
369 auto dhl_confobj_numa = obj_fac.
create(dlh_conf->class_name(), fmt::format(
"{}-numa{}",dlh_conf->UID(), numa));
370 dhl_confobj_numa.
set_by_val<std::string>(
"template_for", dlh_conf->get_template_for());
371 dhl_confobj_numa.set_by_val<std::string>(
"input_data_type", dlh_conf->get_input_data_type());
372 dhl_confobj_numa.set_by_val<
bool>(
"generate_timesync", dlh_conf->get_generate_timesync());
373 dhl_confobj_numa.set_by_val<uint64_t>(
"post_processing_delay_ticks", dlh_conf->get_post_processing_delay_ticks());
374 dhl_confobj_numa.set_by_val<std::string>(
"input_data_type", dlh_conf->get_input_data_type());
375 dhl_confobj_numa.set_obj(
"request_handler", &dlh_conf->get_request_handler()->config_object());
376 dhl_confobj_numa.set_obj(
"latency_buffer", &lb_confobj_numa);
377 dhl_confobj_numa.set_obj(
"data_processor", &dlh_conf->get_data_processor()->config_object());
380 numa_dhlconf_map[numa] = dhl_confobj_numa;
384 auto emulation_mode = reader_conf->get_emulation_mode();
385 for (
auto& [numa, ds] : all_enabled_det_streams) {
386 uint32_t sid = ds->get_source_id();
387 TLOG_DEBUG(6) << fmt::format(
"Processing stream {}, id {}, det id {}", ds->UID(), ds->get_source_id(), ds->get_geo_id()->get_detector_id());
388 std::string uid(fmt::format(
"DLH-{}", sid));
389 TLOG_DEBUG(6) << fmt::format(
"creating OKS configuration object for Data Link Handler class {}, if {}", dlh_class, sid);
390 auto dlh_obj = obj_fac.
create(dlh_class, uid);
391 dlh_obj.
set_by_val<uint32_t>(
"source_id", sid);
392 dlh_obj.set_by_val<uint32_t>(
"detector_id", ds->get_geo_id()->get_detector_id());
394 dlh_obj.set_by_val<
bool>(
"emulation_mode", emulation_mode);
395 dlh_obj.set_obj(
"geo_id", &ds->get_geo_id()->config_object());
396 dlh_obj.set_obj(
"module_configuration", &numa_dhlconf_map[numa]);
397 dlh_obj.set_obj(
"raw_data_callback", &callback_confs_by_sid[sid]->
config_object());
399 std::vector<const conffwk::ConfigObject*> dlh_ins, dlh_outs;
407 dlh_ins.push_back(&req_queue_obj);
408 dlh_outs.push_back(&frag_queue_obj);
412 if (dlh_conf->get_generate_timesync()) {
415 dlh_outs.push_back(&ts_net_obj);
419 for (
auto tpq : tp_queue_objs) {
420 if ((sid / 100) == (tpq.first / 10)) {
421 dlh_outs.push_back(tpq.second);
424 dlh_obj.
set_objs(
"inputs", dlh_ins);
425 dlh_obj.set_objs(
"outputs", dlh_outs);
433 if (aggregator_conf == 0) {
434 throw(BadConf(
ERS_HERE,
"No FragmentAggregatorModule configuration given"));
436 std::string faUid(
"fragmentaggregator-" +
UID());
438 TLOG_DEBUG(7) <<
"creating OKS configuration object for Fragment Aggregator class ";
439 auto frag_aggr = obj_fac.
create(
"FragmentAggregatorModule", faUid);
444 std::vector<conffwk::ConfigObject> fragOutObjs;
446 helper->get_netdescriptors(
"Fragment",
"DFApplication")) {
447 std::string dreqNetUid(
descriptor->get_uid_base() + uid);
448 auto frag_conn = obj_fac.
create(
"NetworkConnection", dreqNetUid);
451 frag_conn.set_by_val<std::string>(
"connection_type",
descriptor->get_connection_type());
453 frag_conn.set_by_val<
int>(
"capacity", all_enabled_det_streams.size() * 2);
455 auto serviceObj =
descriptor->get_associated_service()->config_object();
456 frag_conn.set_obj(
"associated_service", &serviceObj);
457 fragOutObjs.push_back(frag_conn);
461 std::vector<const conffwk::ConfigObject*> fa_output_objs;
462 for (
auto& fNet : fragOutObjs) {
463 fa_output_objs.push_back(&fNet);
466 for (
auto& q : req_queues) {
467 fa_output_objs.push_back(&q->config_object());
470 frag_aggr.
set_obj(
"configuration", &aggregator_conf->config_object());
471 frag_aggr.set_objs(
"inputs", { &fa_net_obj, &frag_queue_obj });
472 frag_aggr.set_objs(
"outputs", fa_output_objs);