LCOV - code coverage report
Current view: top level - appmodel/src - CIBApplication.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 100 0
Test Date: 2026-03-29 15:29:34 Functions: 0.0 % 5 0

            Line data    Source code
       1              : /**
       2              :  * @file CIBApplication.cpp
       3              :  *
       4              :  * Implementation of CIBApplication'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              : #include "conffwk/Configuration.hpp"
      12              : #include "oks/kernel.hpp"
      13              : #include "logging/Logging.hpp"
      14              : 
      15              : #include "confmodel/DetectorToDaqConnection.hpp"
      16              : #include "confmodel/DetDataSender.hpp"
      17              : 
      18              : #include "ConfigObjectFactory.hpp"
      19              : #include "appmodel/appmodelIssues.hpp"
      20              : #include "appmodel/CIBApplication.hpp"
      21              : #include "appmodel/CIBoardConf.hpp"
      22              : #include "appmodel/CIBConf.hpp"
      23              : #include "appmodel/CIBModule.hpp"
      24              : 
      25              : #include "appmodel/DataHandlerConf.hpp"
      26              : #include "appmodel/QueueConnectionRule.hpp"
      27              : #include "appmodel/QueueDescriptor.hpp"
      28              : #include "appmodel/NetworkConnectionDescriptor.hpp"
      29              : #include "appmodel/NetworkConnectionRule.hpp"
      30              : #include "appmodel/SourceIDConf.hpp"
      31              : #include "appmodel/DFApplication.hpp"
      32              : #include "appmodel/DataHandlerModule.hpp"
      33              : 
      34              : #include <string>
      35              : #include <vector>
      36              : #include <bitset>
      37              : #include <iostream>
      38              : #include <fmt/core.h>
      39              : #include <set>
      40              : 
      41              : using namespace dunedaq;
      42              : using namespace dunedaq::appmodel;
      43              : 
      44              : std::vector<const confmodel::Resource*>
      45            0 : CIBApplication::contained_resources() const {
      46            0 :   std::vector<const confmodel::Resource*> resources;
      47            0 :   resources.push_back(dynamic_cast<const confmodel::Resource *>(get_board())); // NOLINT(runtime/rtti)
      48            0 :   return resources;
      49            0 : }
      50              : 
      51              : 
      52              : void
      53            0 : CIBApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
      54              : {
      55            0 :   std::vector<const confmodel::DaqModule*> modules;
      56              : 
      57            0 :   ConfigObjectFactory obj_fac(this);
      58              :   
      59            0 :   auto dlhConf = get_link_handler();
      60            0 :   auto dlhClass = dlhConf->get_template_for();
      61              : 
      62            0 :   const QueueDescriptor* dlhInputQDesc = nullptr;
      63              :     
      64            0 :   for (auto rule : get_queue_rules()) {
      65            0 :     auto destination_class = rule->get_destination_class();
      66            0 :     if (destination_class == "DataHandlerModule" || destination_class == dlhClass) {
      67            0 :       dlhInputQDesc = rule->get_descriptor();
      68              :     }
      69            0 :   }
      70              :   
      71            0 :   const NetworkConnectionDescriptor* dlhReqInputNetDesc = nullptr;
      72            0 :   const NetworkConnectionDescriptor* tsNetDesc = nullptr;
      73            0 :   const NetworkConnectionDescriptor* hsiNetDesc = nullptr;
      74              :   
      75            0 :   for (auto rule : get_network_rules()) {
      76            0 :     auto endpoint_class = rule->get_endpoint_class();
      77            0 :     auto data_type = rule->get_descriptor()->get_data_type();
      78              :     
      79            0 :     if (endpoint_class == "DataHandlerModule" || endpoint_class == dlhClass) {
      80            0 :       if (data_type == "TimeSync") {
      81            0 :         tsNetDesc = rule->get_descriptor();
      82              :       }
      83            0 :       if (data_type == "DataRequest") {
      84            0 :         dlhReqInputNetDesc = rule->get_descriptor();
      85              :       }
      86              :     }
      87            0 :     if (data_type == "HSIEvent") {
      88            0 :       hsiNetDesc = rule->get_descriptor();
      89              :     }
      90            0 :   }
      91              :   
      92            0 :   auto CIB_conf = get_generator();
      93            0 :   if (CIB_conf == nullptr) {
      94              :     throw(BadConf(ERS_HERE, "No CIBModule configuration given"));
      95              :   }
      96            0 :   if (dlhInputQDesc == nullptr) {
      97            0 :     throw(BadConf(ERS_HERE, "No DLH data input queue descriptor given"));
      98              :   }
      99            0 :   if (dlhReqInputNetDesc == nullptr) {
     100            0 :     throw(BadConf(ERS_HERE, "No DLH request input network descriptor given"));
     101              :   }
     102            0 :   if (hsiNetDesc == nullptr) {
     103            0 :     throw(BadConf(ERS_HERE, "No HSIEvent output network descriptor given"));
     104              :   }
     105              : 
     106              :   // Process special Network rules!
     107              :   // Looking for Fragment rules from DFAppplications in current Session
     108            0 :   std::vector<conffwk::ConfigObject> fragOutObjs;
     109            0 :   for (auto [uid, descriptor]:
     110            0 :          helper->get_netdescriptors("Fragment", "DFApplication")) {
     111            0 :     fragOutObjs.emplace_back(obj_fac.create_net_obj(descriptor, uid));
     112            0 :   }    
     113              :   
     114              :   // start building the list of outputs
     115            0 :   std::vector<const conffwk::ConfigObject*> fh_output_objs;
     116            0 :   for (auto& fNet : fragOutObjs) {
     117            0 :     fh_output_objs.push_back(&fNet);
     118              :   }
     119              : 
     120            0 :   std::vector<conffwk::ConfigObject> CIB_module_outputs;
     121            0 :   auto source_id = get_source_id();
     122              : 
     123            0 :   int id = static_cast<int>(source_id->get_sid());
     124              : 
     125              :   // ----------------------------
     126              :   // create DLH
     127              :   // ----------------------------    
     128            0 :   int det_id = 1; // TODO Eric Flumerfelt <eflumerf@fnal.gov>, 08-Feb-2024: This is a magic number corresponding to kDAQ  // NOLINT(readability/todo)
     129            0 :   TLOG() << "creating OKS configuration object for CIB Data Link Handler class " << dlhClass << ", id " << id;
     130            0 :   std::string uid("DLH-CIB");
     131            0 :   conffwk::ConfigObject dlhObj = obj_fac.create( dlhClass, uid );
     132            0 :   dlhObj.set_by_val<uint32_t>("source_id", static_cast<uint32_t>(id)); // NOLINT(build/unsigned)
     133            0 :   dlhObj.set_by_val<uint32_t>("detector_id", static_cast<uint32_t>(det_id)); // NOLINT(build/unsigned)
     134            0 :   dlhObj.set_by_val<bool>("post_processing_enabled", false);
     135            0 :   dlhObj.set_obj("module_configuration", &dlhConf->config_object());
     136              :     
     137            0 :   auto net_objc(fh_output_objs);
     138              :   
     139            0 :   conffwk::ConfigObject tsNetObj;
     140              :   // Time Sync network connection
     141            0 :   if (dlhConf->get_generate_timesync()) {
     142            0 :     std::string tsStreamUid = tsNetDesc->get_uid_base() + std::to_string(id);
     143            0 :     tsNetObj = obj_fac.create_net_obj(tsNetDesc, tsStreamUid);
     144            0 :     net_objc.push_back(&tsNetObj);
     145            0 :   }
     146              : 
     147            0 :   dlhObj.set_objs("outputs", net_objc);
     148              : 
     149              :   // create Queues from CIB to DLH
     150            0 :   std::string dataQueueUid(dlhInputQDesc->get_uid_base() + std::string("CIB"));
     151            0 :   conffwk::ConfigObject queueObj = obj_fac.create_queue_sid_obj(dlhInputQDesc, id); 
     152            0 :   queueObj.rename(dataQueueUid);
     153              :     
     154            0 :   CIB_module_outputs.push_back(queueObj);
     155              : 
     156              :   // Create network connections to DLHs
     157            0 :   conffwk::ConfigObject faNetObj = obj_fac.create_net_obj(dlhReqInputNetDesc, UID());
     158              : 
     159            0 :   dlhObj.set_objs("inputs", { &queueObj, &faNetObj });
     160              : 
     161            0 :   modules.push_back(obj_fac.get_dal<appmodel::DataHandlerModule>(uid));
     162              : 
     163            0 :   conffwk::ConfigObject hsiNetObj = obj_fac.create_net_obj(hsiNetDesc, "");
     164            0 :   CIB_module_outputs.push_back(hsiNetObj);
     165              :   
     166            0 :   auto board = get_board();
     167              :   
     168            0 :   conffwk::ConfigObject module_obj = obj_fac.create( "CIBModule", "CIB-module");
     169            0 :   module_obj.set_obj("configuration", & CIB_conf -> config_object() );
     170            0 :   module_obj.set_obj("board", & board -> config_object() );
     171              :   
     172            0 :   std::vector<const conffwk::ConfigObject*> CIB_module_output_ptrs;
     173            0 :   for ( const auto & o : CIB_module_outputs ) {
     174            0 :     CIB_module_output_ptrs.push_back( & o );
     175              :   }
     176              :   
     177            0 :   module_obj.set_objs("outputs", CIB_module_output_ptrs);
     178              :   
     179            0 :   auto module = obj_fac.get_dal<appmodel::CIBModule>(module_obj.UID());
     180              :   
     181            0 :   modules.push_back(module);
     182              : 
     183            0 :   obj_fac.update_modules(modules);
     184              :   // return modules;
     185            0 : } // NOLINT
     186              : 
     187            0 : nlohmann::json CIBoardConf::get_cib_json(const dunedaq::confmodel::Session &session, std::optional<std::string> socket_host, std::optional<uint16_t> socket_port) const 
     188              : {
     189              : 
     190              :   // shut up compiler!
     191            0 :   (void)session; // unused parameter
     192            0 :   nlohmann::json json;
     193            0 :   json["sockets"] = nlohmann::json::object();
     194            0 :   if (socket_host.has_value()) 
     195              :   {
     196            0 :     json["sockets"]["receiver"] = nlohmann::json::object();
     197            0 :     json["sockets"]["receiver"]["host"] = socket_host.value();
     198            0 :     json["sockets"]["receiver"]["port"] = socket_port.value(); // NOLINT(build/unsigned)
     199              :   }
     200              :   else 
     201              :   {
     202            0 :     json["sockets"]["receiver"] = nlohmann::json::object();
     203            0 :     json["sockets"]["receiver"]["host"] = get_receiver_host();
     204            0 :     json["sockets"]["receiver"]["port"] = get_receiver_port(); // NOLINT(build/unsigned)
     205              :   }
     206              : 
     207            0 :   TLOG() << "JSON frag : [" << json.dump() << "] " ;
     208              : 
     209            0 :   return json;
     210            0 : }
        

Generated by: LCOV version 2.0-1