diff --git a/src/WIECApplication.cpp b/src/WIECApplication.cpp index 1e8e525..a16cc0d 100644 --- a/src/WIECApplication.cpp +++ b/src/WIECApplication.cpp @@ -85,15 +85,17 @@ WIECApplication::generate_modules(std::shared_ptr throw(BadConf(ERS_HERE, fmt::format("WEICApplication requires NWDetDataReceiver, found {} of class {}", det_receiver->UID(), det_receiver->class_name()))); } - // Loop over senders + // Note on how to exclude the senders. + // The hardware interface requires that all the physical links be configured, even if not used for a run. + // Consequently, at the configuration level, we should never remove senders from a detector to daq connection. + // At most, we should exclude them at the level of the session. + // For the same reason, in this code, we create a map of control hosts to senders, without checking if the senders are excluded. + // Once the map is created, if all the senders associated to a control hosts are excluded, then we skip the creation of all related modules. + + // Loop over senders to create the map of control hosts to senders. for (const auto* sender : det_senders) { - if (helper->is_excluded(sender)) { - TLOG() << "Skipping excluded sender: " << sender->UID(); - continue; - } - - // Check the sender type, must me a HermesSender + // Check the sender type, must be a HermesSender const auto* hrms_sender = sender->cast(); if (!hrms_sender ) { throw(BadConf(ERS_HERE, fmt::format("DataSender {} is not a appmodel::HermesDataSender", sender->UID()))); @@ -105,6 +107,20 @@ WIECApplication::generate_modules(std::shared_ptr for( const auto& [ctrlhost, senders] : ctrlhost_sender_map ) { + // If all senders for this control host are excluded, skip creating related modules. + // Of course the opposite logic is faster: check if any sender is included. + bool any_included = false; + for ( const auto* sender : senders ){ + if ( helper->is_included(sender) ) { + any_included = true; + break; + } + } + if (!any_included) { + TLOG_DEBUG(6) << "Skipping control host " << ctrlhost << " whose senders are all excluded."; + continue; + } + // Create WIBModule if ( this->get_wib_module_conf() ) { @@ -119,21 +135,20 @@ WIECApplication::generate_modules(std::shared_ptr // std::cout << std::format("stream {} -> femb {}", stream_id, femb_id) << std::endl; - // Enable the femb if any of the associated streams is enabld - // Senders in this senders list should be enabled, but better safe than sorry. + // Enable the femb if any of the associated streams is enabled enable_fembs[femb_id] |= helper->is_included(det_stream); - } - } + } // loop over streams + } // loop over senders for this control host + std::string wib_uid = fmt::format("wib-ctrl-{}-{}", this->UID(), ctrlhost); conffwk::ConfigObject wib_obj = obj_fac.create("WIBModule", wib_uid); wib_obj.set_by_val("wib_addr", fmt::format("{}://{}:{}", this->get_wib_module_conf()->get_communication_type(), ctrlhost, this->get_wib_module_conf()->get_communication_port())); - wib_obj.set_by_val("enabled_femb0", enable_fembs[0]); - wib_obj.set_by_val("enabled_femb1", enable_fembs[1]); - wib_obj.set_by_val("enabled_femb2", enable_fembs[2]); - wib_obj.set_by_val("enabled_femb3", enable_fembs[3]); + for (int i=0; i<4; ++i) { + wib_obj.set_by_val(fmt::format("enabled_femb{}", i), enable_fembs[i]); + } wib_obj.set_obj("conf", &this->get_wib_module_conf()->get_settings()->config_object()); modules.push_back(config->get(wib_obj)); - } + } // if we have a module configuration for the WIB module // Create Hermes Modules if (this->get_hermes_module_conf()) { @@ -146,17 +161,18 @@ WIECApplication::generate_modules(std::shared_ptr std::vector< const conffwk::ConfigObject * > links_obj; for ( const auto* sndr : senders ){ + // Note that it is OK that some of these senders might be excluded + // The hardware interface in HermesModule requires that all links be configured, even if not used for a run links_obj.push_back(&sndr->config_object()); } hermes_obj.set_objs("links", links_obj); modules.push_back(config->get(hermes_obj)); - } - + } // If we have a module configuration for the Hermes module - } + } // loop over control hosts - } + } // loop over detector to daq connections obj_fac.update_modules(modules); }