Skip to content

Commit

Permalink
Retire SmartActionPlan. Validate that ActionPlan instances given to
Browse files Browse the repository at this point in the history
SmartDaqApplication only use DaqModulesGroupByType.
Add ability to serialize ActionPlan step execution.
  • Loading branch information
eflumerf committed Aug 30, 2024
1 parent 8b4afe2 commit 6cf8b50
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
22 changes: 9 additions & 13 deletions src/DAQModuleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "confmodel/DaqModulesGroupById.hpp"
#include "confmodel/DaqModulesGroupByType.hpp"
#include "confmodel/Session.hpp"
#include "confmodel/SmartActionPlan.hpp"

#include "iomanager/IOManager.hpp"

Expand Down Expand Up @@ -56,15 +55,6 @@ DAQModuleManager::initialize(std::shared_ptr<ConfigurationManager> cfgMgr, opmon
for (auto& plan_pair : m_module_configuration->action_plans()) {
auto cmd = plan_pair.first;

auto smartplan = plan_pair.second->cast<confmodel::SmartActionPlan>();
if (smartplan != nullptr) {
// Must be DaqModulesGroupByType
for (auto& step : smartplan->get_steps()) {
for (auto& mod_type : step->get_modules()) {
check_mod_has_cmd(cmd, mod_type);
}
}
} else {
for (auto& step : plan_pair.second->get_steps()) {
auto byType = step->cast<confmodel::DaqModulesGroupByType>();
auto byMod = step->cast<confmodel::DaqModulesGroupById>();
Expand All @@ -80,7 +70,6 @@ DAQModuleManager::initialize(std::shared_ptr<ConfigurationManager> cfgMgr, opmon
throw ActionPlanValidationFailed(ERS_HERE, cmd, "", "Invalid subclass of DaqModulesGroup encountered!");
}
}
}
}
this->m_initialized = true;
}
Expand Down Expand Up @@ -179,7 +168,7 @@ DAQModuleManager::execute_action(const std::string& module_name, const std::stri
void
DAQModuleManager::execute_action_plan_step(std::string const& cmd,
const confmodel::DaqModulesGroup* step,
const dataobj_t& cmd_data)
const dataobj_t& cmd_data, bool execution_mode_is_serial)
{
std::string failed_mod_names("");
std::unordered_map<std::string, std::future<bool>> futures;
Expand All @@ -194,6 +183,8 @@ DAQModuleManager::execute_action_plan_step(std::string const& cmd,
TLOG_DEBUG(1) << "Executing action " << cmd << " on module " << mod_name << " (class " << mod_class << ")";
futures[mod_name] =
std::async(std::launch::async, &DAQModuleManager::execute_action, this, mod_name, cmd, data_obj);
if (execution_mode_is_serial)
futures[mod_name].wait();
}
}
} else if (byMod != nullptr) {
Expand All @@ -203,6 +194,8 @@ DAQModuleManager::execute_action_plan_step(std::string const& cmd,
TLOG_DEBUG(1) << "Executing action " << cmd << " on module " << mod_name << " (class " << mod->class_name() << ")";
futures[mod_name] =
std::async(std::launch::async, &DAQModuleManager::execute_action, this, mod_name, cmd, data_obj);
if (execution_mode_is_serial)
futures[mod_name].wait();
}
} else {
throw CommandDispatchingFailed(ERS_HERE, cmd, "Could not get DaqModulesGroup!");
Expand Down Expand Up @@ -332,9 +325,12 @@ DAQModuleManager::execute(const std::string& cmd, const dataobj_t& cmd_data)
}
#endif
} else {
auto execution_policy = action_plan->get_execution_policy();
auto serial_execution = execution_policy == "modules-in-series";

// We validated the action plans already
for (auto& step : action_plan->get_steps()) {
execute_action_plan_step(cmd, step, cmd_data);
execute_action_plan_step(cmd, step, cmd_data, serial_execution);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DAQModuleManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class DAQModuleManager
void check_cmd_data(const std::string& id, const dataobj_t& cmd_data);
dataobj_t get_dataobj_for_module(const std::string& mod_name, const dataobj_t& cmd_data);
bool execute_action(const std::string& mod_name, const std::string& action, const dataobj_t& data_obj);
void execute_action_plan_step(const std::string& cmd, const confmodel::DaqModulesGroup* step, const dataobj_t& cmd_data);
void execute_action_plan_step(const std::string& cmd, const confmodel::DaqModulesGroup* step, const dataobj_t& cmd_data, bool execution_mode_is_serial);

void check_mod_has_cmd(const std::string& cmd, const std::string& mod_class, const std::string& mod_id = "");

Expand Down
9 changes: 8 additions & 1 deletion src/ModuleConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include "conffwk/Configuration.hpp"
#include "confmodel/DaqApplication.hpp"
#include "confmodel/DaqModule.hpp"
#include "confmodel/DaqModulesGroupByType.hpp"
#include "confmodel/FSMCommand.hpp"
#include "confmodel/NetworkConnection.hpp"
#include "confmodel/Queue.hpp"
#include "confmodel/ResourceSet.hpp"
#include "confmodel/Service.hpp"
#include "confmodel/Session.hpp"
#include "confmodel/SmartActionPlan.hpp"

#include <cerrno>
#include <ifaddrs.h>
Expand Down Expand Up @@ -49,6 +49,13 @@ ModuleConfiguration::ModuleConfiguration(std::shared_ptr<ConfigurationManager> c
throw ActionPlanValidationFailed(
ERS_HERE, cmd, "N/A", "Multiple ActionPlans registered for cmd, conflicting plan is " + plan->UID());
}
for (auto& step : plan->get_steps()) {
auto step_byType = step->cast<confmodel::DaqModulesGroupByType>();
if (step_byType == nullptr) {
throw ActionPlanValidationFailed(
ERS_HERE, cmd, "N/A", "ActionPlans for SmartDaqApplications must use DaqModulesGroupByType");
}
}
m_action_plans[cmd] = plan;
}
} else {
Expand Down

0 comments on commit 6cf8b50

Please sign in to comment.