otsdaq  v1_01_04
 All Classes Namespaces Functions
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::TargetColumns IterateConfiguration::targetCols_;
45 
46 
47 
48 //==============================================================================
49 IterateConfiguration::IterateConfiguration(void)
51 {
52 }
53 
54 //==============================================================================
55 IterateConfiguration::~IterateConfiguration(void)
56 {
57 }
58 
59 //==============================================================================
60 void IterateConfiguration::init(ConfigurationManager *configManager)
61 {
62  //do something to validate or refactor table
63  __COUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
64  __COUT__ << configManager->__SELF_NODE__ << std::endl;
65 
66  std::string value;
67  auto childrenMap = configManager->__SELF_NODE__.getChildren();
68  for(auto &childPair: childrenMap)
69  {
70  //do something for each row in table
71  __COUT__ << childPair.first << std::endl;
72  // __COUT__ << childPair.second.getNode(colNames_.colColumnName_) << std::endl;
73  //childPair.second.getNode(colNames_.colColumnName_ ).getValue(value);
74  }
75 }
76 
77 //==============================================================================
78 std::vector<IterateConfiguration::Command> IterateConfiguration::getPlanCommands(
79  ConfigurationManager *configManager, const std::string& plan) const
80 {
81  __COUT__ << configManager->__SELF_NODE__ << std::endl;
82 
83  ConfigurationTree planNode = configManager->__SELF_NODE__.getNode(plan);
84 
85  if(!planNode.getNode(IterateConfiguration::planTableCols_.Status_).getValue<bool>())
86  {
87  __SS__ << "Error! Attempt to access disabled plan (Status=FALSE)." << std::endl;
88  __COUT_ERR__ << ss.str();
89  throw std::runtime_error(ss.str());
90  }
91 
92  std::vector<IterateConfiguration::Command> commands;
93 
94  auto commandChildren = planNode.getNode(
95  IterateConfiguration::iterateTableCols_.PlanLink_).getChildren();
96 
97  for(auto &commandChild: commandChildren)
98  {
99  __COUT__ << "Command \t" << commandChild.first << std::endl;
100 
101  __COUT__ << "\t\tStatus \t" << commandChild.second.getNode(
102  IterateConfiguration::planTableCols_.Status_) << std::endl;
103 
104  __COUT__ << "\t\tType \t" << commandChild.second.getNode(
105  IterateConfiguration::planTableCols_.CommandType_) << std::endl;
106 
107  if(!commandChild.second.getNode(
108  IterateConfiguration::planTableCols_.Status_).getValue<bool>())
109  continue; //skip disabled commands
110 
111  commands.push_back(IterateConfiguration::Command());
112  commands.back().type_ = commandChild.second.getNode(
113  IterateConfiguration::planTableCols_.CommandType_).getValue<std::string>();
114 
115  auto commandSpecificFields = commandChild.second.getNode(
116  IterateConfiguration::planTableCols_.CommandLink_).getChildren();
117 
118  for(unsigned int i=0; i<commandSpecificFields.size()-3; ++i) //ignore last three columns
119  {
120  __COUT__ << "\t\tParameter \t" << commandSpecificFields[i].first << " = \t" <<
121  commandSpecificFields[i].second << std::endl;
122 
123  commands.back().params_.emplace(std::pair<
124  std::string /*param name*/,
125  std::string /*param value*/>(
126  commandSpecificFields[i].first,
127  commandSpecificFields[i].second.getValueAsString()));
128  }
129  }
130 
131  return commands;
132 }
133 
134 DEFINE_OTS_CONFIGURATION(IterateConfiguration)