1 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq/Macros/TablePluginMacros.h"
3 #include "otsdaq/TablePlugins/IterateTable.h"
12 const std::string IterateTable::COMMAND_BEGIN_LABEL =
"BEGIN_LABEL";
13 const std::string IterateTable::COMMAND_CHOOSE_FSM =
"CHOOSE_FSM";
14 const std::string IterateTable::COMMAND_CONFIGURE_ACTIVE_GROUP =
"CONFIGURE_ACTIVE_GROUP";
15 const std::string IterateTable::COMMAND_CONFIGURE_ALIAS =
"CONFIGURE_ALIAS";
16 const std::string IterateTable::COMMAND_CONFIGURE_GROUP =
"CONFIGURE_GROUP";
17 const std::string IterateTable::COMMAND_EXECUTE_FE_MACRO =
"EXECUTE_FE_MACRO";
18 const std::string IterateTable::COMMAND_EXECUTE_MACRO =
"EXECUTE_MACRO";
19 const std::string IterateTable::COMMAND_MODIFY_ACTIVE_GROUP =
"MODIFY_ACTIVE_GROUP";
20 const std::string IterateTable::COMMAND_REPEAT_LABEL =
"REPEAT_LABEL";
21 const std::string IterateTable::COMMAND_RUN =
"RUN";
23 const std::string IterateTable::ITERATE_TABLE =
"IterateTable";
24 const std::string IterateTable::PLAN_TABLE =
"IterationPlanTable";
25 const std::string IterateTable::TARGET_TABLE =
"IterationTargetTable";
27 const std::map<std::string, std::string> IterateTable::commandToTableMap_ = IterateTable::createCommandToTableMap();
53 IterateTable::~IterateTable(
void) {}
77 std::vector<IterateTable::Command> IterateTable::getPlanCommands(
ConfigurationManager* configManager,
const std::string& plan)
const
79 __COUT__ << configManager->__SELF_NODE__ << std::endl;
83 if(!planNode.getNode(IterateTable::planTableCols_.Status_).getValue<
bool>())
85 __SS__ <<
"Error! Attempt to access disabled plan (Status=FALSE)." << std::endl;
86 __COUT_ERR__ << ss.str();
90 std::vector<IterateTable::Command> commands;
92 auto commandChildren = planNode.getNode(IterateTable::iterateTableCols_.PlanLink_).getChildren();
94 for(
auto& commandChild : commandChildren)
96 __COUT__ <<
"Command \t" << commandChild.first << std::endl;
98 __COUT__ <<
"\t\tStatus \t" << commandChild.second.getNode(IterateTable::planTableCols_.Status_) << std::endl;
100 __COUT__ <<
"\t\tType \t" << commandChild.second.getNode(IterateTable::planTableCols_.CommandType_) << std::endl;
102 if(!commandChild.second.getNode(IterateTable::planTableCols_.Status_).getValue<
bool>())
106 commands.back().type_ = commandChild.second.getNode(IterateTable::planTableCols_.CommandType_).getValue<std::string>();
108 if(commandChild.second.getNode(IterateTable::planTableCols_.CommandLink_).isDisconnected())
111 auto commandSpecificFields = commandChild.second.getNode(IterateTable::planTableCols_.CommandLink_).getChildren();
113 for(
unsigned int i = 0; i < commandSpecificFields.size() - 3; ++i)
118 __COUT__ <<
"\t\tParameter \t" << commandSpecificFields[i].first <<
" = \t" << commandSpecificFields[i].second << std::endl;
120 if(commandSpecificFields[i].first == IterateTable::commandTargetCols_.TargetsLink_)
122 __COUT__ <<
"Extracting targets..." << __E__;
123 auto targets = commandSpecificFields[i].second.getChildren();
125 __COUTV__(targets.size());
127 for(
auto& target : targets)
129 __COUT__ <<
"\t\t\tTarget \t" << target.first << __E__;
131 ConfigurationTree targetNode = target.second.getNode(IterateTable::targetCols_.TargetLink_);
132 if(targetNode.isDisconnected())
134 __COUT_ERR__ <<
"Disconnected target!?" << __E__;
138 __COUT__ <<
"\t\t = \t"
139 <<
"Table:" << targetNode.getTableName() <<
" UID:" << targetNode.getUIDAsString() << std::endl;
140 commands.back().addTarget();
141 commands.back().targets_.back().table_ = targetNode.getTableName();
142 commands.back().targets_.back().UID_ = targetNode.getUIDAsString();
145 else if(commandSpecificFields[i].first == IterateTable::commandExecuteMacroParams_.MacroParameterLink_)
148 __COUT__ <<
"Extracting macro parameters..." << __E__;
163 auto dimensionalLoops = commandSpecificFields[i].second.getChildren(
164 std::map<std::string /*relative-path*/, std::string /*value*/>() ,
true );
166 __COUTV__(dimensionalLoops.size());
172 std::string argStr =
"";
176 unsigned long numberOfIterations;
177 bool firstDimension =
true;
179 for(
auto& dimensionalLoop : dimensionalLoops)
181 __COUT__ <<
"\t\t\tDimensionalLoop \t" << dimensionalLoop.first << __E__;
183 numberOfIterations = dimensionalLoop.second.getNode(IterateTable::macroDimLoopCols_.NumberOfIterations_).getValue<
unsigned long>();
185 __COUTV__(numberOfIterations);
187 if(numberOfIterations == 0)
189 __SS__ <<
"Illegal number of iterations value of '" << numberOfIterations <<
".' Must be a positive integer!" << __E__;
197 firstDimension =
false;
198 argStr += std::to_string(numberOfIterations);
200 auto paramLinkNode = dimensionalLoop.second.getNode(IterateTable::macroDimLoopCols_.ParamLink_);
202 if(paramLinkNode.isDisconnected())
204 __COUT__ <<
"Disconnected parameter link, so no parameters for "
210 auto macroParams = paramLinkNode.getChildren();
212 __COUTV__(macroParams.size());
214 for(
auto& macroParam : macroParams)
216 __COUT__ <<
"\t\t\tParam \t" << macroParam.first << __E__;
221 argStr += macroParam.second.getNode(IterateTable::macroParamCols_.Name_).getValue<std::string>();
223 argStr += macroParam.second.getNode(IterateTable::macroParamCols_.Value_).getValue<std::string>();
225 argStr += macroParam.second.getNode(IterateTable::macroParamCols_.Step_).getValue<std::string>();
237 commands.back().params_.emplace(
238 std::pair<std::string /*param name*/, std::string /*param value*/>(IterateTable::commandExecuteMacroParams_.MacroArgumentString_, argStr));
243 commandSpecificFields[i].second.isValueBoolType())
244 commands.back().params_.emplace(std::pair<std::string /*param name*/, std::string /*param value*/>(
245 commandSpecificFields[i].first, commandSpecificFields[i].second.getValue<
bool>() ?
"1" :
"0"));
248 commandSpecificFields[i].second.isValueNumberDataType())
249 commands.back().params_.emplace(std::pair<std::string /*param name*/, std::string /*param value*/>(
250 commandSpecificFields[i].first, commandSpecificFields[i].second.getValueAsString()));
252 commands.back().params_.emplace(std::pair<std::string /*param name*/, std::string /*param value*/>(
253 commandSpecificFields[i].first, commandSpecificFields[i].second.getValue<std::string>()));