otsdaq  v2_01_00
IterateConfiguration_configuration.cc
1 #include "otsdaq-core/ConfigurationPluginDataFormats/IterateConfiguration.h"
2 #include "otsdaq-core/Macros/ConfigurationPluginMacros.h"
3 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
4 
5 #include <iostream>
6 #include <string>
7 
8 using namespace ots;
9 
10 //instantiate static members
11 
12 const std::string IterateConfiguration::COMMAND_BEGIN_LABEL = "BEGIN_LABEL";
13 const std::string IterateConfiguration::COMMAND_CHOOSE_FSM = "CHOOSE_FSM";
14 const std::string IterateConfiguration::COMMAND_CONFIGURE_ACTIVE_GROUP = "CONFIGURE_ACTIVE_GROUP";
15 const std::string IterateConfiguration::COMMAND_CONFIGURE_ALIAS = "CONFIGURE_ALIAS";
16 const std::string IterateConfiguration::COMMAND_CONFIGURE_GROUP = "CONFIGURE_GROUP";
17 const std::string IterateConfiguration::COMMAND_EXECUTE_FE_MACRO = "EXECUTE_FE_MACRO";
18 const std::string IterateConfiguration::COMMAND_EXECUTE_MACRO = "EXECUTE_MACRO";
19 const std::string IterateConfiguration::COMMAND_MODIFY_ACTIVE_GROUP = "MODIFY_ACTIVE_GROUP";
20 const std::string IterateConfiguration::COMMAND_REPEAT_LABEL = "REPEAT_LABEL";
21 const std::string IterateConfiguration::COMMAND_RUN = "RUN";
22 
23 const std::string IterateConfiguration::ITERATE_TABLE = "IterateConfiguration";
24 const std::string IterateConfiguration::PLAN_TABLE = "IterationPlanConfiguration";
25 const std::string IterateConfiguration::TARGET_TABLE = "IterationTargetConfiguration";
26 
27 const std::map<std::string,std::string> IterateConfiguration::commandToTableMap_ = IterateConfiguration::createCommandToTableMap();
28 
29 IterateConfiguration::PlanTableColumns IterateConfiguration::planTableCols_;
30 IterateConfiguration::IterateTableColumns IterateConfiguration::iterateTableCols_;
31 
32 IterateConfiguration::CommandBeginLabelParams IterateConfiguration::commandBeginLabelParams_;
33 IterateConfiguration::CommandConfigureActiveParams IterateConfiguration::commandConfigureActiveParams_;
34 IterateConfiguration::CommandConfigureAliasParams IterateConfiguration::commandConfigureAliasParams_;
35 IterateConfiguration::CommandConfigureGroupParams IterateConfiguration::commandConfigureGroupParams_;
36 IterateConfiguration::CommandExecuteFEMacroParams IterateConfiguration::commandExecuteFEMacroParams_;
37 IterateConfiguration::CommandExecuteMacroParams IterateConfiguration::commandExecuteMacroParams_;
38 IterateConfiguration::CommandModifyActiveParams IterateConfiguration::commandModifyActiveParams_;
39 IterateConfiguration::CommandRepeatLabelParams IterateConfiguration::commandRepeatLabelParams_;
40 IterateConfiguration::CommandRunParams IterateConfiguration::commandRunParams_;
41 IterateConfiguration::CommandChooseFSMParams IterateConfiguration::commandChooseFSMParams_;
42 
43 IterateConfiguration::TargetParams IterateConfiguration::targetParams_;
44 IterateConfiguration::TargetTableColumns IterateConfiguration::targetCols_;
45 IterateConfiguration::CommandTargetColumns IterateConfiguration::commandTargetCols_;
46 
47 
48 
49 //==============================================================================
50 IterateConfiguration::IterateConfiguration(void)
52 {
53 }
54 
55 //==============================================================================
56 IterateConfiguration::~IterateConfiguration(void)
57 {
58 }
59 
60 //==============================================================================
61 void IterateConfiguration::init(ConfigurationManager *configManager)
62 {
63  //do something to validate or refactor table
64 // __COUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
65 // __COUT__ << configManager->__SELF_NODE__ << std::endl;
66 
67  std::string value;
68  auto childrenMap = configManager->__SELF_NODE__.getChildren();
69  for(auto &childPair: childrenMap)
70  {
71  //do something for each row in table
72  //__COUT__ << childPair.first << std::endl;
73  // __COUT__ << childPair.second.getNode(colNames_.colColumnName_) << std::endl;
74  //childPair.second.getNode(colNames_.colColumnName_ ).getValue(value);
75  }
76 }
77 
78 //==============================================================================
79 std::vector<IterateConfiguration::Command> IterateConfiguration::getPlanCommands(
80  ConfigurationManager *configManager, const std::string& plan) const
81 {
82  __COUT__ << configManager->__SELF_NODE__ << std::endl;
83 
84  ConfigurationTree planNode = configManager->__SELF_NODE__.getNode(plan);
85 
86  if(!planNode.getNode(IterateConfiguration::planTableCols_.Status_).getValue<bool>())
87  {
88  __SS__ << "Error! Attempt to access disabled plan (Status=FALSE)." << std::endl;
89  __COUT_ERR__ << ss.str();
90  throw std::runtime_error(ss.str());
91  }
92 
93  std::vector<IterateConfiguration::Command> commands;
94 
95  auto commandChildren = planNode.getNode(
96  IterateConfiguration::iterateTableCols_.PlanLink_).getChildren();
97 
98  for(auto &commandChild: commandChildren)
99  {
100  __COUT__ << "Command \t" << commandChild.first << std::endl;
101 
102  __COUT__ << "\t\tStatus \t" << commandChild.second.getNode(
103  IterateConfiguration::planTableCols_.Status_) << std::endl;
104 
105  __COUT__ << "\t\tType \t" << commandChild.second.getNode(
106  IterateConfiguration::planTableCols_.CommandType_) << std::endl;
107 
108  if(!commandChild.second.getNode(
109  IterateConfiguration::planTableCols_.Status_).getValue<bool>())
110  continue; //skip disabled commands
111 
112  commands.push_back(IterateConfiguration::Command());
113  commands.back().type_ = commandChild.second.getNode(
114  IterateConfiguration::planTableCols_.CommandType_).getValue<std::string>();
115 
116  if(commandChild.second.getNode(
117  IterateConfiguration::planTableCols_.CommandLink_).isDisconnected())
118  continue; //skip if no command parameters
119 
120  auto commandSpecificFields = commandChild.second.getNode(
121  IterateConfiguration::planTableCols_.CommandLink_).getChildren();
122 
123  for(unsigned int i=0; i<commandSpecificFields.size()-3; ++i) //ignore last three columns
124  {
125  __COUT__ << "\t\tParameter \t" << commandSpecificFields[i].first << " = \t" <<
126  commandSpecificFields[i].second << std::endl;
127 
128  if(commandSpecificFields[i].first ==
129  IterateConfiguration::commandTargetCols_.TargetsLink_)
130  {
131  __COUT__ << "Extracting targets..." << __E__;
132  auto targets = commandSpecificFields[i].second.getChildren();
133  for(auto& target:targets)
134  {
135  __COUT__ << "\t\t\tTarget \t" << target.first << __E__;
136 
137  ConfigurationTree targetNode =
138  target.second.getNode(
139  IterateConfiguration::targetCols_.TargetLink_);
140  if(targetNode.isDisconnected())
141  {
142  __COUT_ERR__ << "Disconnected target!?" << __E__;
143  continue;
144  }
145 
146  __COUT__ << "\t\t = \t" <<
147  "Table:" <<
148  targetNode.getConfigurationName() <<
149  " UID:" <<
150  targetNode.getValueAsString() << std::endl;
151  commands.back().addTarget();
152  commands.back().targets_.back().table_ = targetNode.getConfigurationName();
153  commands.back().targets_.back().UID_ = targetNode.getValueAsString();
154  }
155  }
156  else
157  commands.back().params_.emplace(std::pair<
158  std::string /*param name*/,
159  std::string /*param value*/>(
160  commandSpecificFields[i].first,
161  commandSpecificFields[i].second.getValueAsString()));
162  }
163  }
164 
165  return commands;
166 }
167 
168 DEFINE_OTS_CONFIGURATION(IterateConfiguration)