00001 #include "otsdaq-core/ConfigurationPluginDataFormats/IterateConfiguration.h"
00002 #include "otsdaq-core/Macros/ConfigurationPluginMacros.h"
00003 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00004
00005 #include <iostream>
00006 #include <string>
00007
00008 using namespace ots;
00009
00010
00011
00012 const std::string IterateConfiguration::COMMAND_BEGIN_LABEL = "BEGIN_LABEL";
00013 const std::string IterateConfiguration::COMMAND_CHOOSE_FSM = "CHOOSE_FSM";
00014 const std::string IterateConfiguration::COMMAND_CONFIGURE_ACTIVE_GROUP = "CONFIGURE_ACTIVE_GROUP";
00015 const std::string IterateConfiguration::COMMAND_CONFIGURE_ALIAS = "CONFIGURE_ALIAS";
00016 const std::string IterateConfiguration::COMMAND_CONFIGURE_GROUP = "CONFIGURE_GROUP";
00017 const std::string IterateConfiguration::COMMAND_EXECUTE_FE_MACRO = "EXECUTE_FE_MACRO";
00018 const std::string IterateConfiguration::COMMAND_EXECUTE_MACRO = "EXECUTE_MACRO";
00019 const std::string IterateConfiguration::COMMAND_MODIFY_ACTIVE_GROUP = "MODIFY_ACTIVE_GROUP";
00020 const std::string IterateConfiguration::COMMAND_REPEAT_LABEL = "REPEAT_LABEL";
00021 const std::string IterateConfiguration::COMMAND_RUN = "RUN";
00022
00023 const std::string IterateConfiguration::ITERATE_TABLE = "IterateConfiguration";
00024 const std::string IterateConfiguration::PLAN_TABLE = "IterationPlanConfiguration";
00025 const std::string IterateConfiguration::TARGET_TABLE = "IterationTargetConfiguration";
00026
00027 const std::map<std::string,std::string> IterateConfiguration::commandToTableMap_ = IterateConfiguration::createCommandToTableMap();
00028
00029 IterateConfiguration::PlanTableColumns IterateConfiguration::planTableCols_;
00030 IterateConfiguration::IterateTableColumns IterateConfiguration::iterateTableCols_;
00031
00032 IterateConfiguration::CommandBeginLabelParams IterateConfiguration::commandBeginLabelParams_;
00033 IterateConfiguration::CommandConfigureActiveParams IterateConfiguration::commandConfigureActiveParams_;
00034 IterateConfiguration::CommandConfigureAliasParams IterateConfiguration::commandConfigureAliasParams_;
00035 IterateConfiguration::CommandConfigureGroupParams IterateConfiguration::commandConfigureGroupParams_;
00036 IterateConfiguration::CommandExecuteFEMacroParams IterateConfiguration::commandExecuteFEMacroParams_;
00037 IterateConfiguration::CommandExecuteMacroParams IterateConfiguration::commandExecuteMacroParams_;
00038 IterateConfiguration::CommandModifyActiveParams IterateConfiguration::commandModifyActiveParams_;
00039 IterateConfiguration::CommandRepeatLabelParams IterateConfiguration::commandRepeatLabelParams_;
00040 IterateConfiguration::CommandRunParams IterateConfiguration::commandRunParams_;
00041 IterateConfiguration::CommandChooseFSMParams IterateConfiguration::commandChooseFSMParams_;
00042
00043 IterateConfiguration::TargetParams IterateConfiguration::targetParams_;
00044 IterateConfiguration::TargetTableColumns IterateConfiguration::targetCols_;
00045 IterateConfiguration::CommandTargetColumns IterateConfiguration::commandTargetCols_;
00046
00047
00048
00049
00050 IterateConfiguration::IterateConfiguration(void)
00051 : ConfigurationBase(IterateConfiguration::ITERATE_TABLE)
00052 {
00053 }
00054
00055
00056 IterateConfiguration::~IterateConfiguration(void)
00057 {
00058 }
00059
00060
00061 void IterateConfiguration::init(ConfigurationManager *configManager)
00062 {
00063
00064 __COUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
00065 __COUT__ << configManager->__SELF_NODE__ << std::endl;
00066
00067 std::string value;
00068 auto childrenMap = configManager->__SELF_NODE__.getChildren();
00069 for(auto &childPair: childrenMap)
00070 {
00071
00072 __COUT__ << childPair.first << std::endl;
00073
00074
00075 }
00076 }
00077
00078
00079 std::vector<IterateConfiguration::Command> IterateConfiguration::getPlanCommands(
00080 ConfigurationManager *configManager, const std::string& plan) const
00081 {
00082 __COUT__ << configManager->__SELF_NODE__ << std::endl;
00083
00084 ConfigurationTree planNode = configManager->__SELF_NODE__.getNode(plan);
00085
00086 if(!planNode.getNode(IterateConfiguration::planTableCols_.Status_).getValue<bool>())
00087 {
00088 __SS__ << "Error! Attempt to access disabled plan (Status=FALSE)." << std::endl;
00089 __COUT_ERR__ << ss.str();
00090 throw std::runtime_error(ss.str());
00091 }
00092
00093 std::vector<IterateConfiguration::Command> commands;
00094
00095 auto commandChildren = planNode.getNode(
00096 IterateConfiguration::iterateTableCols_.PlanLink_).getChildren();
00097
00098 for(auto &commandChild: commandChildren)
00099 {
00100 __COUT__ << "Command \t" << commandChild.first << std::endl;
00101
00102 __COUT__ << "\t\tStatus \t" << commandChild.second.getNode(
00103 IterateConfiguration::planTableCols_.Status_) << std::endl;
00104
00105 __COUT__ << "\t\tType \t" << commandChild.second.getNode(
00106 IterateConfiguration::planTableCols_.CommandType_) << std::endl;
00107
00108 if(!commandChild.second.getNode(
00109 IterateConfiguration::planTableCols_.Status_).getValue<bool>())
00110 continue;
00111
00112 commands.push_back(IterateConfiguration::Command());
00113 commands.back().type_ = commandChild.second.getNode(
00114 IterateConfiguration::planTableCols_.CommandType_).getValue<std::string>();
00115
00116 if(commandChild.second.getNode(
00117 IterateConfiguration::planTableCols_.CommandLink_).isDisconnected())
00118 continue;
00119
00120 auto commandSpecificFields = commandChild.second.getNode(
00121 IterateConfiguration::planTableCols_.CommandLink_).getChildren();
00122
00123 for(unsigned int i=0; i<commandSpecificFields.size()-3; ++i)
00124 {
00125 __COUT__ << "\t\tParameter \t" << commandSpecificFields[i].first << " = \t" <<
00126 commandSpecificFields[i].second << std::endl;
00127
00128 if(commandSpecificFields[i].first ==
00129 IterateConfiguration::commandTargetCols_.TargetsLink_)
00130 {
00131 __COUT__ << "Extracting targets..." << __E__;
00132 auto targets = commandSpecificFields[i].second.getChildren();
00133 for(auto& target:targets)
00134 {
00135 __COUT__ << "\t\t\tTarget \t" << target.first << __E__;
00136
00137 ConfigurationTree targetNode =
00138 target.second.getNode(
00139 IterateConfiguration::targetCols_.TargetLink_);
00140 if(targetNode.isDisconnected())
00141 {
00142 __COUT_ERR__ << "Disconnected target!?" << __E__;
00143 continue;
00144 }
00145
00146 __COUT__ << "\t\t = \t" <<
00147 "Table:" <<
00148 targetNode.getConfigurationName() <<
00149 " UID:" <<
00150 targetNode.getValueAsString() << std::endl;
00151 commands.back().addTarget();
00152 commands.back().targets_.back().table_ = targetNode.getConfigurationName();
00153 commands.back().targets_.back().UID_ = targetNode.getValueAsString();
00154 }
00155 }
00156 else
00157 commands.back().params_.emplace(std::pair<
00158 std::string ,
00159 std::string >(
00160 commandSpecificFields[i].first,
00161 commandSpecificFields[i].second.getValueAsString()));
00162 }
00163 }
00164
00165 return commands;
00166 }
00167
00168 DEFINE_OTS_CONFIGURATION(IterateConfiguration)