LCOV - code coverage report
Current view: top level - appmodel/src - CTBApplication.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 173 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 10 0

            Line data    Source code
       1              : /**
       2              :  * @file CTBApplication.cpp
       3              :  *
       4              :  * Implementation of CTBApplication'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 "logging/Logging.hpp"
      13              : #include "oks/kernel.hpp"
      14              : 
      15              : #include "confmodel/DetDataSender.hpp"
      16              : #include "confmodel/DetectorToDaqConnection.hpp"
      17              : 
      18              : #include "ConfigObjectFactory.hpp"
      19              : #include "appmodel/CTBApplication.hpp"
      20              : #include "appmodel/CTBCRTSubsystem.hpp"
      21              : #include "appmodel/CTBConf.hpp"
      22              : #include "appmodel/CTBCountLLT.hpp"
      23              : #include "appmodel/CTBHLT.hpp"
      24              : #include "appmodel/CTBLLT.hpp"
      25              : #include "appmodel/CTBMisc.hpp"
      26              : #include "appmodel/CTBModule.hpp"
      27              : #include "appmodel/CTBMonitorSocket.hpp"
      28              : #include "appmodel/CTBPDSSubsystem.hpp"
      29              : #include "appmodel/CTBPulser.hpp"
      30              : #include "appmodel/CTBRandomTrigger.hpp"
      31              : #include "appmodel/CTBReceiverSocket.hpp"
      32              : #include "appmodel/CTBSocket.hpp"
      33              : #include "appmodel/CTBSockets.hpp"
      34              : #include "appmodel/CTBStatisticsSocket.hpp"
      35              : #include "appmodel/CTBSubsystem.hpp"
      36              : #include "appmodel/CTBTiming.hpp"
      37              : #include "appmodel/CTBTrigger.hpp"
      38              : #include "appmodel/CTBoardConf.hpp"
      39              : #include "appmodel/appmodelIssues.hpp"
      40              : 
      41              : #include "appmodel/DataHandlerConf.hpp"
      42              : #include "appmodel/DataHandlerModule.hpp"
      43              : #include "appmodel/NetworkConnectionDescriptor.hpp"
      44              : #include "appmodel/NetworkConnectionRule.hpp"
      45              : #include "appmodel/QueueConnectionRule.hpp"
      46              : #include "appmodel/QueueDescriptor.hpp"
      47              : #include "appmodel/SourceIDConf.hpp"
      48              : 
      49              : #include <bitset>
      50              : #include <fmt/core.h>
      51              : #include <iostream>
      52              : #include <set>
      53              : #include <string>
      54              : #include <vector>
      55              : 
      56              : using namespace dunedaq;
      57              : using namespace dunedaq::appmodel;
      58              : 
      59              : std::vector<const confmodel::ExcludableEntity*>
      60            0 : CTBApplication::contained_excludable_entities() const
      61              : {
      62            0 :   std::vector<const confmodel::ExcludableEntity*> resources;
      63            0 :   resources.push_back(dynamic_cast<const confmodel::ExcludableEntity*>(get_board()));
      64            0 :   return resources;
      65            0 : }
      66              : 
      67              : void
      68            0 : CTBApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
      69              : {
      70            0 :   std::vector<const confmodel::DaqModule*> modules;
      71              : 
      72            0 :   ConfigObjectFactory obj_fac(this);
      73              : 
      74            0 :   auto dlhConf = get_link_handler();
      75            0 :   auto dlhClass = dlhConf->get_template_for();
      76              : 
      77            0 :   const QueueDescriptor* dlhInputQDesc = nullptr;
      78              : 
      79            0 :   for (auto rule : get_queue_rules()) {
      80            0 :     auto destination_class = rule->get_destination_class();
      81            0 :     auto data_type = rule->get_descriptor()->get_data_type();
      82            0 :     if (destination_class == "DataHandlerModule" || destination_class == dlhClass) {
      83            0 :       dlhInputQDesc = rule->get_descriptor();
      84              :     }
      85            0 :   }
      86              : 
      87            0 :   const NetworkConnectionDescriptor* dlhReqInputNetDesc = nullptr;
      88            0 :   const NetworkConnectionDescriptor* tsNetDesc = nullptr;
      89            0 :   const NetworkConnectionDescriptor* hsiNetDesc = nullptr;
      90              : 
      91            0 :   for (auto rule : get_network_rules()) {
      92            0 :     auto endpoint_class = rule->get_endpoint_class();
      93            0 :     auto data_type = rule->get_descriptor()->get_data_type();
      94              : 
      95            0 :     if (endpoint_class == "DataHandlerModule" || endpoint_class == dlhClass) {
      96            0 :       if (data_type == "TimeSync") {
      97            0 :         tsNetDesc = rule->get_descriptor();
      98              :       }
      99            0 :       if (data_type == "DataRequest") {
     100            0 :         dlhReqInputNetDesc = rule->get_descriptor();
     101              :       }
     102              :     }
     103            0 :     if (data_type == "HSIEvent") {
     104            0 :       hsiNetDesc = rule->get_descriptor();
     105              :     }
     106            0 :   }
     107              : 
     108            0 :   auto ctb_conf = get_generator();
     109            0 :   if (ctb_conf == nullptr) {
     110              :     throw(BadConf(ERS_HERE, "No CTBModule configuration given"));
     111              :   }
     112            0 :   if (dlhInputQDesc == nullptr) {
     113            0 :     throw(BadConf(ERS_HERE, "No DLH data input queue descriptor given"));
     114              :   }
     115            0 :   if (dlhReqInputNetDesc == nullptr) {
     116            0 :     throw(BadConf(ERS_HERE, "No DLH request input network descriptor given"));
     117              :   }
     118            0 :   if (hsiNetDesc == nullptr) {
     119            0 :     throw(BadConf(ERS_HERE, "No HSIEvent output network descriptor given"));
     120              :   }
     121              : 
     122              :   // Process special Network rules!
     123              :   // Looking for Fragment rules from DFAppplications in current Session
     124            0 :   std::vector<conffwk::ConfigObject> fragOutObjs;
     125            0 :   for (auto [uid, descriptor] : helper->get_netdescriptors("Fragment", "DFApplication")) {
     126            0 :     fragOutObjs.emplace_back(obj_fac.create_net_obj(descriptor, uid));
     127            0 :   }
     128              : 
     129              :   // start building the list of outputs
     130            0 :   std::vector<const conffwk::ConfigObject*> fh_output_objs;
     131            0 :   for (auto& fNet : fragOutObjs) {
     132            0 :     fh_output_objs.push_back(&fNet);
     133              :   }
     134              : 
     135            0 :   std::vector<conffwk::ConfigObject> ctb_module_outputs;
     136            0 :   auto sources = get_sources();
     137              : 
     138            0 :   for (const auto& s : sources) {
     139            0 :     if (s.second == nullptr) {
     140            0 :       throw(BadConf(ERS_HERE, "No SourceIDConf given for " + s.first));
     141              :     }
     142              : 
     143            0 :     auto id = s.second->get_sid();
     144              :     // ----------------------------
     145              :     // create DLH
     146              :     // ----------------------------
     147            0 :     auto det_id =
     148              :       1; // TODO Eric Flumerfelt <eflumerf@fnal.gov>, 08-Feb-2024: This is a magic number corresponding to kDAQ
     149            0 :     TLOG() << "creating OKS configuration object for " + s.first + " Data Link Handler class " << dlhClass << ", id "
     150            0 :            << id;
     151            0 :     std::string uid("DLH-" + s.first);
     152            0 :     conffwk::ConfigObject dlhObj = obj_fac.create(dlhClass, uid);
     153            0 :     dlhObj.set_by_val<uint32_t>("source_id", id);
     154            0 :     dlhObj.set_by_val<uint32_t>("detector_id", det_id);
     155            0 :     dlhObj.set_by_val<bool>("post_processing_enabled", false);
     156            0 :     dlhObj.set_obj("module_configuration", &dlhConf->config_object());
     157              : 
     158            0 :     auto net_objc(fh_output_objs);
     159              : 
     160              :     // Time Sync network connection
     161            0 :     if (dlhConf->get_generate_timesync()) {
     162            0 :       std::string tsStreamUid = tsNetDesc->get_uid_base() + std::to_string(id);
     163            0 :       conffwk::ConfigObject tsNetObj = obj_fac.create_net_obj(tsNetDesc, tsStreamUid);
     164            0 :       net_objc.push_back(&tsNetObj);
     165            0 :     }
     166              : 
     167            0 :     dlhObj.set_objs("outputs", net_objc);
     168              : 
     169              :     // create Queues from CTB to DLH
     170            0 :     std::string dataQueueUid(dlhInputQDesc->get_uid_base() + s.first);
     171            0 :     conffwk::ConfigObject queueObj = obj_fac.create_queue_sid_obj(dlhInputQDesc, id);
     172            0 :     queueObj.rename(dataQueueUid);
     173              : 
     174            0 :     ctb_module_outputs.push_back(queueObj);
     175              : 
     176              :     // Create network connections to DLHs
     177            0 :     conffwk::ConfigObject faNetObj = obj_fac.create_net_obj(dlhReqInputNetDesc, UID() + '_' + s.first);
     178              : 
     179            0 :     dlhObj.set_objs("inputs", { &queueObj, &faNetObj });
     180              : 
     181            0 :     modules.push_back(obj_fac.get_dal<appmodel::DataHandlerModule>(uid));
     182              : 
     183            0 :   } // loop over CTB sources
     184              : 
     185            0 :   conffwk::ConfigObject hsiNetObj = obj_fac.create_net_obj(hsiNetDesc, "");
     186            0 :   ctb_module_outputs.push_back(hsiNetObj);
     187              : 
     188            0 :   auto board = get_board();
     189              : 
     190            0 :   conffwk::ConfigObject module_obj = obj_fac.create("CTBModule", "ctb-module");
     191            0 :   module_obj.set_obj("configuration", &ctb_conf->config_object());
     192            0 :   module_obj.set_obj("board", &board->config_object());
     193              : 
     194            0 :   std::vector<const conffwk::ConfigObject*> ctb_module_output_ptrs;
     195            0 :   for (const auto& o : ctb_module_outputs) {
     196            0 :     ctb_module_output_ptrs.push_back(&o);
     197              :   }
     198              : 
     199            0 :   module_obj.set_objs("outputs", ctb_module_output_ptrs);
     200              : 
     201            0 :   auto module = obj_fac.get_dal<appmodel::CTBModule>(module_obj.UID());
     202              : 
     203            0 :   modules.push_back(module);
     204              : 
     205            0 :   obj_fac.update_modules(modules);
     206            0 : }
     207              : 
     208              : std::vector<const confmodel::ExcludableEntity*>
     209            0 : CTBoardConf::contained_excludable_entities() const
     210              : {
     211            0 :   std::vector<const confmodel::ExcludableEntity*> resources;
     212            0 :   resources.push_back(get_misc());
     213              : 
     214            0 :   auto hlts = get_HLTs();
     215            0 :   resources.insert(resources.end(), hlts.begin(), hlts.end());
     216              : 
     217            0 :   auto crt_llts = get_CRT_LLTs();
     218            0 :   resources.insert(resources.end(), crt_llts.begin(), crt_llts.end());
     219              : 
     220            0 :   auto llts = get_beam_LLTs();
     221            0 :   resources.insert(resources.end(), llts.begin(), llts.end());
     222              : 
     223            0 :   return resources;
     224            0 : }
     225              : 
     226              : nlohmann::json
     227            0 : CTBoardConf::get_ctb_json(const dunedaq::confmodel::Session& session, std::optional<std::string> socket_host) const
     228              : {
     229              : 
     230            0 :   nlohmann::json json;
     231            0 :   json["sockets"] = get_sockets()->get_ctb_json(socket_host);
     232            0 :   json["misc"] = get_misc()->get_ctb_json(session);
     233              : 
     234            0 :   nlohmann::json hlt;
     235              : 
     236              :   // constant block that we don't even want to configure
     237            0 :   auto& mask = hlt["command_mask"];
     238            0 :   mask["C"] = "0x0";
     239            0 :   mask["D"] = "0x0";
     240            0 :   mask["E"] = "0x0";
     241            0 :   mask["F"] = "0x0";
     242              : 
     243            0 :   auto hlts = get_HLTs();
     244              : 
     245            0 :   std::list<nlohmann::json> json_hlts;
     246            0 :   for (const auto& hlt : hlts) {
     247            0 :     json_hlts.push_back(hlt->get_ctb_json(session));
     248              :   }
     249              : 
     250            0 :   hlt["trigger"] = nlohmann::json(json_hlts);
     251              : 
     252            0 :   json["HLT"] = hlt;
     253              : 
     254              :   // --------------------------
     255              :   // Subsystems
     256              :   // --------------------------
     257              : 
     258            0 :   auto& subsystems = json["subsystems"];
     259              : 
     260              :   //  ---- Beam ----
     261              : 
     262            0 :   auto& beam_block = subsystems["beam"] = get_beam()->to_json(false, true);
     263            0 :   std::list<nlohmann::json> json_beam_llts;
     264            0 :   auto beam_llts = get_beam_LLTs();
     265            0 :   for (const auto& llt : beam_llts) {
     266            0 :     json_beam_llts.push_back(llt->get_ctb_json(session));
     267              :   }
     268              : 
     269            0 :   beam_block["triggers"] = nlohmann::json(json_beam_llts);
     270              : 
     271              :   //  ---- CRT ----
     272              : 
     273            0 :   auto& crt_block = subsystems["crt"] = get_CRT()->to_json(false, true);
     274            0 :   std::list<nlohmann::json> json_crt_llts;
     275            0 :   auto crt_llts = get_CRT_LLTs();
     276            0 :   for (const auto& llt : crt_llts) {
     277            0 :     json_crt_llts.push_back(llt->get_ctb_json(session));
     278              :   }
     279            0 :   crt_block["triggers"] = nlohmann::json(json_crt_llts);
     280              : 
     281              :   //  ---- PDS ----
     282              : 
     283            0 :   subsystems["pds"] = get_pds()->to_json(false, true);
     284              : 
     285            0 :   nlohmann::json ret;
     286            0 :   ret["ctb"] = json;
     287              : 
     288            0 :   return ret;
     289            0 : }
     290              : 
     291              : std::vector<const confmodel::ExcludableEntity*>
     292            0 : CTBMisc::contained_excludable_entities() const
     293              : {
     294            0 :   return std::vector<const confmodel::ExcludableEntity*>{ get_randomtrigger_1(), get_randomtrigger_2() };
     295              : }
     296              : 
     297              : nlohmann::json
     298            0 : CTBMisc::get_ctb_json(const dunedaq::confmodel::Session& session) const
     299              : {
     300              : 
     301            0 :   nlohmann::json ret;
     302            0 :   ret["randomtrigger_1"] = get_randomtrigger_1()->get_ctb_json(session);
     303            0 :   ret["randomtrigger_2"] = get_randomtrigger_2()->get_ctb_json(session);
     304            0 :   ret["pulser"] = get_pulser()->to_json(false, true);
     305            0 :   ret["timing"] = get_timing()->to_json(false, true);
     306              : 
     307            0 :   static std::string ch_status_flag = "ch_status";
     308            0 :   if (get_ch_status())
     309            0 :     ret[ch_status_flag] = true;
     310              :   else
     311            0 :     ret[ch_status_flag] = false;
     312              : 
     313            0 :   static std::string standalong_flag = "standalone_enable";
     314            0 :   ret[standalong_flag] = false;
     315              : 
     316            0 :   return ret;
     317            0 : }
     318              : 
     319              : nlohmann::json
     320            0 : CTBTrigger::get_ctb_json(const dunedaq::confmodel::Session& session) const
     321              : {
     322              : 
     323            0 :   auto json = this->to_json(false, true);
     324            0 :   static std::string enable_tag = "enable";
     325            0 :   if (this->is_excluded(session)) {
     326            0 :     json[enable_tag] = false;
     327              :   } else {
     328            0 :     json[enable_tag] = true;
     329              :   }
     330              : 
     331            0 :   json["id"] = this->UID();
     332              : 
     333            0 :   return json;
     334            0 : }
     335              : 
     336              : nlohmann::json
     337            0 : CTBSockets::get_ctb_json(std::optional<std::string> socket_host) const
     338              : {
     339              : 
     340            0 :   nlohmann::json json;
     341            0 :   json["receiver"] = get_receiver()->get_ctb_json(socket_host);
     342            0 :   json["monitor"] = get_monitor()->get_ctb_json(socket_host);
     343            0 :   json["statistics"] = get_statistics()->to_json(false, true);
     344            0 :   return json;
     345            0 : }
     346              : 
     347              : nlohmann::json
     348            0 : CTBSocket::get_ctb_json(std::optional<std::string> socket_host) const
     349              : {
     350              : 
     351            0 :   auto json = to_json(false, true);
     352            0 :   if (socket_host) {
     353            0 :     json["host"] = socket_host.value();
     354              :   }
     355            0 :   return json;
     356            0 : }
        

Generated by: LCOV version 2.0-1