1 #include "otsdaq/FECore/FEVInterfacesManager.h"
2 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
3 #include "otsdaq/FECore/MakeInterface.h"
4 #include "otsdaq/Macros/CoutMacros.h"
5 #include "otsdaq/MessageFacility/MessageFacility.h"
7 #include "artdaq-core/Utilities/configureMessageFacility.hh"
8 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
9 #include "fhiclcpp/make_ParameterSet.h"
10 #include "messagefacility/MessageLogger/MessageLogger.h"
19 FEVInterfacesManager::FEVInterfacesManager(
21 const std::string& supervisorConfigurationPath)
22 :
Configurable(theXDAQContextConfigTree, supervisorConfigurationPath)
26 __CFG_COUT__ <<
"Constructed." << __E__;
30 FEVInterfacesManager::~FEVInterfacesManager(
void)
33 __CFG_COUT__ <<
"Destructed." << __E__;
40 void FEVInterfacesManager::destroy(
void)
42 for(
auto& it : theFEInterfaces_)
45 theFEInterfaces_.clear();
46 theFENamesByPriority_.clear();
50 void FEVInterfacesManager::createInterfaces(
void)
52 const std::string COL_NAME_feGroupLink =
"LinkToFEInterfaceTable";
53 const std::string COL_NAME_feTypeLink =
"LinkToFETypeTable";
54 const std::string COL_NAME_fePlugin =
"FEInterfacePluginName";
56 __CFG_COUT__ <<
"Path: " << theConfigurationPath_ +
"/" + COL_NAME_feGroupLink
63 theXDAQContextConfigTree_.getBackNode(theConfigurationPath_, 1);
66 auto fes = appNode.
getNode(
"LinkToSupervisorTable")
67 .
getNode(
"LinkToFEInterfaceTable")
73 Configurable::getSelfNode().
getNode(COL_NAME_feGroupLink);
75 std::vector<std::pair<std::string, ConfigurationTree>> feChildren =
79 theFENamesByPriority_ =
83 for(
const auto& interface : feChildren)
87 if(!interface.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
93 __CFG_COUT_INFO__ <<
"Ignoring FE Status since Status column is missing!"
98 <<
"Interface Plugin Name: "
99 << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>()
101 __CFG_COUT__ <<
"Interface Name: " << interface.first << __E__;
102 __CFG_COUT__ <<
"XDAQContext Node: " << theXDAQContextConfigTree_ << __E__;
103 __CFG_COUT__ <<
"Path to configuration: "
104 << (theConfigurationPath_ +
"/" + COL_NAME_feGroupLink +
"/" +
105 interface.first +
"/" + COL_NAME_feTypeLink)
110 theFEInterfaces_[interface.first] = makeInterface(
111 interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>(),
113 theXDAQContextConfigTree_,
114 (theConfigurationPath_ +
"/" + COL_NAME_feGroupLink +
"/" +
115 interface.first +
"/" + COL_NAME_feTypeLink));
119 theFEInterfaces_[interface.first]->VStateMachine::parentSupervisor_ =
121 theFEInterfaces_[interface.first]->parentInterfaceManager_ =
this;
123 catch(
const cet::exception& e)
126 <<
"Failed to instantiate plugin named '" << interface.first
128 << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>()
129 <<
"' due to the following error: \n"
130 << e.what() << __E__;
131 __COUT_ERR__ << ss.str();
134 catch(
const std::runtime_error& e)
137 <<
"Failed to instantiate plugin named '" << interface.first
139 << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>()
140 <<
"' due to the following error: \n"
141 << e.what() << __E__;
142 __COUT_ERR__ << ss.str();
148 <<
"Failed to instantiate plugin named '" << interface.first
150 << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>()
151 <<
"' due to an unknown error." << __E__;
156 catch(
const std::exception& e)
158 ss <<
"Exception message: " << e.what();
163 __COUT_ERR__ << ss.str();
168 __CFG_COUT__ <<
"Done creating interfaces" << __E__;
178 std::string progress =
"";
179 unsigned int cnt = 0;
182 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
185 const std::string& name = theFENamesByPriority_[i];
188 if(feProgress.size())
190 ((cnt++) ?
"," :
"") + StringMacros::encodeURIComponent(feProgress);
205 const std::string transitionName =
"Configuring";
207 __CFG_COUT__ << transitionName <<
" FEVInterfacesManager " << __E__;
210 if(VStateMachine::getIterationIndex() == 0 &&
211 VStateMachine::getSubIterationIndex() == 0)
216 preStateMachineExecutionLoop();
217 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
220 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
221 i != subIterationWorkStateMachineIndex_)
224 const std::string& name = theFENamesByPriority_[i];
229 if(stateMachinesIterationDone_[name])
232 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
233 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
234 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
236 preStateMachineExecution(i, transitionName);
238 postStateMachineExecution(i);
241 if(!fe->VStateMachine::getSubIterationWork() &&
242 !fe->VStateMachine::getIterationWork())
247 fe->startSlowControlsWorkLoop();
249 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
250 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
251 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
254 postStateMachineExecutionLoop();
256 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
260 void FEVInterfacesManager::halt(
void)
262 const std::string transitionName =
"Halting";
265 preStateMachineExecutionLoop();
266 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
269 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
270 i != subIterationWorkStateMachineIndex_)
273 const std::string& name = theFENamesByPriority_[i];
277 if(stateMachinesIterationDone_[name])
280 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
281 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
282 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
284 preStateMachineExecution(i, transitionName);
294 <<
"An error occurred while halting the front-end workloop for '" << name
295 <<
",' ignoring." << __E__;
301 fe->stopSlowControlsWorkLoop();
305 __CFG_COUT_WARN__ <<
"An error occurred while halting the Slow Controls "
306 "front-end workloop for '"
307 << name <<
",' ignoring." << __E__;
317 __CFG_COUT_WARN__ <<
"An error occurred while halting the front-end '" << name
318 <<
",' ignoring." << __E__;
321 postStateMachineExecution(i);
323 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
324 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
325 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
327 postStateMachineExecutionLoop();
329 if(!VStateMachine::getSubIterationWork() && !VStateMachine::getIterationWork())
332 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
336 void FEVInterfacesManager::pause(
void)
338 const std::string transitionName =
"Pausing";
341 preStateMachineExecutionLoop();
342 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
345 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
346 i != subIterationWorkStateMachineIndex_)
349 const std::string& name = theFENamesByPriority_[i];
353 if(stateMachinesIterationDone_[name])
356 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
357 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
358 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
360 preStateMachineExecution(i, transitionName);
363 postStateMachineExecution(i);
365 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
366 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
367 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
369 postStateMachineExecutionLoop();
371 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
375 void FEVInterfacesManager::resume(
void)
377 const std::string transitionName =
"Resuming";
380 preStateMachineExecutionLoop();
381 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
384 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
385 i != subIterationWorkStateMachineIndex_)
388 const std::string& name = theFENamesByPriority_[i];
392 if(stateMachinesIterationDone_[name])
395 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
396 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
397 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
399 preStateMachineExecution(i, transitionName);
402 if(postStateMachineExecution(i))
405 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
406 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
407 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
409 postStateMachineExecutionLoop();
411 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
416 void FEVInterfacesManager::start(std::string runNumber)
418 const std::string transitionName =
"Starting";
421 preStateMachineExecutionLoop();
422 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
425 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
426 i != subIterationWorkStateMachineIndex_)
429 const std::string& name = theFENamesByPriority_[i];
433 if(stateMachinesIterationDone_[name])
436 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
437 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
438 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
440 preStateMachineExecution(i, transitionName);
441 fe->start(runNumber);
443 if(postStateMachineExecution(i))
446 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
447 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
448 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
450 postStateMachineExecutionLoop();
452 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
457 void FEVInterfacesManager::stop(
void)
459 const std::string transitionName =
"Starting";
462 preStateMachineExecutionLoop();
463 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
466 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
467 i != subIterationWorkStateMachineIndex_)
470 const std::string& name = theFENamesByPriority_[i];
474 if(stateMachinesIterationDone_[name])
477 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
478 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
479 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
481 preStateMachineExecution(i, transitionName);
484 postStateMachineExecution(i);
486 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
487 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
488 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
490 postStateMachineExecutionLoop();
492 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
502 return theFEInterfaces_.at(interfaceID).get();
506 __CFG_SS__ <<
"Interface ID '" << interfaceID
507 <<
"' not found in configured interfaces." << __E__;
515 const std::string& interfaceID)
const
519 return *(theFEInterfaces_.at(interfaceID));
523 __CFG_SS__ <<
"Interface ID '" << interfaceID
524 <<
"' not found in configured interfaces." << __E__;
544 const std::string& interfaceID)
553 const std::string& interfaceID)
575 std::string retList =
"";
577 for(
const auto& it : theFEInterfaces_)
579 __CFG_COUT__ <<
"FE name = " << it.first << __E__;
581 retList += it.second->getInterfaceType() +
":" + supervisorLid +
":" +
582 it.second->getInterfaceUID() +
"\n";
605 const std::string& interfaceID,
606 const std::string& macroName,
607 const std::string& macroString,
608 const bool enableSavingOutput,
609 const std::string& outputFilePath,
610 const std::string& outputFileRadix,
611 const std::string& inputArgs)
613 if(requester !=
"iterator")
615 __CFG_SS__ <<
"Invalid requester '" << requester <<
"'" << __E__;
619 __CFG_COUT__ <<
"Starting multi-dimensional Macro '" << macroName
620 <<
"' for interface '" << interfaceID <<
".'" << __E__;
622 __CFG_COUTV__(macroString);
624 __CFG_COUTV__(inputArgs);
630 if(macroMultiDimensionalStatusMap_.find(interfaceID) !=
631 macroMultiDimensionalStatusMap_.end())
633 __SS__ <<
"Failed to start multi-dimensional Macro '" << macroName
634 <<
"' for interface '" << interfaceID
635 <<
"' - this interface already has an active Macro launch!" << __E__;
638 macroMultiDimensionalStatusMap_.emplace(std::make_pair(interfaceID,
"Active"));
644 const std::string interfaceID,
645 const std::string macroName,
646 const std::string macroString,
647 const bool enableSavingOutput,
648 const std::string outputFilePath,
649 const std::string outputFileRadix,
650 const std::string inputArgsStr) {
652 std::string mfSubject_ =
"threadMultiD-" + macroName;
653 __GEN_COUT__ <<
"Thread started." << __E__;
655 std::string statusResult =
"Done";
669 FILE* outputFilePointer = 0;
670 if(enableSavingOutput)
672 std::string filename = outputFilePath +
"/" + outputFileRadix +
673 macroName +
"_" + std::to_string(time(0)) +
675 __GEN_COUT__ <<
"Opening file... " << filename << __E__;
677 outputFilePointer = fopen(filename.c_str(),
"w");
678 if(!outputFilePointer)
680 __GEN_SS__ <<
"Failed to open output file: " << filename << __E__;
687 __GEN_COUTV__(inputArgsStr);
707 std::vector<
unsigned long > dimensionIterations,
708 dimensionIterationCnt;
710 using longParamMap_t = std::map<
713 std::pair<
long ,
long >>>;
715 std::vector<longParamMap_t> longDimensionParameters;
720 std::map<std::string , uint64_t > variableMap;
725 for(
const auto& inputArgName : macro.namesOfInputArguments_)
727 std::pair<std::string /*name*/, uint64_t /*value*/>(inputArgName,
729 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
731 std::pair<std::string /*name*/, uint64_t /*value*/>(outputArgName,
738 dimensionIterations.push_back(2);
739 dimensionIterations.push_back(4);
741 longDimensionParameters.push_back(longParamMap_t());
742 longDimensionParameters.push_back(longParamMap_t());
744 longDimensionParameters.back().emplace(std::make_pair(
748 std::make_pair(3 , 4 ))));
751 std::vector<std::string> dimensionArgs;
753 inputArgsStr, dimensionArgs, {
';'} );
755 __GEN_COUTV__(dimensionArgs.size());
758 if(dimensionArgs.size() == 0)
763 dimensionIterations.push_back(1);
764 longDimensionParameters.push_back(longParamMap_t());
767 for(
unsigned int d = 0; d < dimensionArgs.size(); ++d)
772 std::vector<std::string> args;
774 dimensionArgs[d], args, {
','} );
782 __GEN_SS__ <<
"Invalid dimensional arguments! "
783 <<
"Need number of iterations at dimension " << d
788 unsigned long numOfIterations;
790 __GEN_COUT__ <<
"Dimension " << d
791 <<
" numOfIterations=" << numOfIterations << __E__;
795 dimensionIterations.push_back(numOfIterations);
796 longDimensionParameters.push_back(longParamMap_t());
800 for(
unsigned int a = 1; a < args.size(); ++a)
802 std::vector<std::string> argPieces;
804 args[a], argPieces, {
':'} );
810 if(argPieces.size() != 3)
812 __GEN_SS__ <<
"Invalid argument pieces! Should be size "
814 << argPieces.size() << __E__;
821 if((argPieces[1].size() &&
822 (argPieces[1][argPieces[1].size() - 1] ==
'f' ||
823 argPieces[1].find(
'.') != std::string::npos)) ||
824 (argPieces[2].size() &&
825 (argPieces[2][argPieces[2].size() - 1] ==
'f' ||
826 argPieces[2].find(
'.') != std::string::npos)))
830 double startValue = strtod(argPieces[1].c_str(), 0);
831 double stepSize = strtod(argPieces[2].c_str(), 0);
833 __GEN_COUTV__(startValue);
834 __GEN_COUTV__(stepSize);
837 <<
"Error! Only integer aruments allowed for Macros. "
838 <<
"Double style arugment found: " << argPieces[0]
839 <<
"' := " << startValue <<
", " << stepSize << __E__;
863 __GEN_COUTV__(startValue);
864 __GEN_COUTV__(stepSize);
866 __GEN_COUT__ <<
"Creating long argument '" << argPieces[0]
867 <<
"' := " << startValue <<
", " << stepSize
870 longDimensionParameters.back().emplace(std::make_pair(
874 std::make_pair(startValue ,
882 if(dimensionIterations.size() != longDimensionParameters.size())
884 __GEN_SS__ <<
"Impossible vector size mismatch! "
885 << dimensionIterations.size() <<
" - "
886 << longDimensionParameters.size() << __E__;
892 std::stringstream outSS;
894 outSS <<
"\n==========================\n" << __E__;
895 outSS <<
"Macro '" << macro.macroName_
896 <<
"' multi-dimensional scan..." << __E__;
898 outSS <<
"\t" << dimensionIterations.size()
899 <<
" dimensions defined." << __E__;
900 for(
unsigned int i = 0; i < dimensionIterations.size(); ++i)
903 <<
"dimension[" << i <<
"] has "
904 << dimensionIterations[i] <<
" iterations and "
905 << (longDimensionParameters[i].size()) <<
" arguments."
908 for(
auto& param : longDimensionParameters[i])
910 <<
"'" << param.first <<
"' of type long with "
911 <<
"initial value and step value [decimal] = "
912 <<
"\t" << param.second.second.first <<
" & "
913 << param.second.second.second << __E__;
916 outSS <<
"\nInput argument names:" << __E__;
917 for(
const auto& inputArgName : macro.namesOfInputArguments_)
918 outSS <<
"\t" << inputArgName << __E__;
919 outSS <<
"\nOutput argument names:" << __E__;
920 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
921 outSS <<
"\t" << outputArgName << __E__;
923 outSS <<
"\n==========================\n" << __E__;
927 __GEN_COUT__ <<
"\n" << outSS.str();
928 if(outputFilePointer)
929 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
932 unsigned int iterationCount = 0;
940 std::function<void(
const unsigned int
942 localRecurse = [&dimensionIterations,
943 &dimensionIterationCnt,
945 &longDimensionParameters,
950 &localRecurse](
const unsigned int dimension) {
952 std::string mfSubject_ =
"multiD-" + std::to_string(dimension) +
953 "-" + macro.macroName_;
954 __GEN_COUTV__(dimension);
956 if(dimension >= dimensionIterations.size())
958 __GEN_COUT__ <<
"Iteration count: " << iterationCount++
960 __GEN_COUT__ <<
"Launching Macro '" << macro.macroName_
971 for(
unsigned int j = 0; j < dimensionIterations.size();
974 for(
auto& longParam : longDimensionParameters[j])
977 <<
"Assigning argIn '" << longParam.first
978 <<
"' to current long value '"
979 << longParam.second.first
980 <<
"' from dimension " << j <<
" parameter."
982 variableMap.at(longParam.first) =
983 longParam.second.first;
991 std::stringstream outSS;
993 outSS <<
"\n---------------\n" << __E__;
994 outSS <<
"Macro '" << macro.macroName_
995 <<
"' execution..." << __E__;
997 <<
"iteration " << iterationCount << __E__;
998 for(
unsigned int i = 0;
999 i < dimensionIterationCnt.size();
1002 <<
"dimension[" << i
1003 <<
"] index := " << dimensionIterationCnt[i]
1008 <<
"Input arguments (count: "
1009 << macro.namesOfInputArguments_.size()
1011 for(
auto& argIn : macro.namesOfInputArguments_)
1012 outSS <<
"\t\t" << argIn <<
" = "
1013 << variableMap.at(argIn) << __E__;
1018 __GEN_COUT__ <<
"\n" << outSS.str();
1019 if(outputFilePointer)
1020 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1026 __GEN_COUT__ <<
"Macro complete!" << __E__;
1030 std::stringstream outSS;
1034 <<
"Output arguments (count: "
1035 << macro.namesOfOutputArguments_.size()
1037 for(
auto& argOut : macro.namesOfOutputArguments_)
1038 outSS <<
"\t\t" << argOut <<
" = "
1039 << variableMap.at(argOut) << __E__;
1043 __GEN_COUT__ <<
"\n" << outSS.str();
1044 if(outputFilePointer)
1045 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1052 if(dimension >= dimensionIterationCnt.size())
1053 dimensionIterationCnt.push_back(0);
1056 __GEN_COUT__ <<
"\n"
1057 <<
"======================================" << __E__
1058 <<
"dimension[" << dimension
1059 <<
"] number of iterations := "
1060 << dimensionIterations[dimension] << __E__;
1065 for(
auto& longPair : longDimensionParameters[dimension])
1067 longPair.second.first =
1068 longPair.second.second.first;
1070 <<
"arg '" << longPair.first
1071 <<
"' current value: " << longPair.second.first
1078 for(dimensionIterationCnt[dimension] =
1080 dimensionIterationCnt[dimension] <
1081 dimensionIterations[dimension];
1082 ++dimensionIterationCnt[dimension])
1084 __GEN_COUT__ <<
"dimension[" << dimension <<
"] index := "
1085 << dimensionIterationCnt[dimension] << __E__;
1087 localRecurse(dimension + 1);
1092 for(
auto& longPair : longDimensionParameters[dimension])
1094 longPair.second.first +=
1095 longPair.second.second.second;
1097 <<
"arg '" << longPair.first
1098 <<
"' current value: " << longPair.second.first
1105 __GEN_COUT__ <<
"Completed dimension[" << dimension
1106 <<
"] number of iterations := "
1107 << dimensionIterationCnt[dimension] <<
" of "
1108 << dimensionIterations[dimension] << __E__;
1115 if(outputFilePointer)
1116 fclose(outputFilePointer);
1118 catch(
const std::runtime_error& e)
1120 __SS__ <<
"Error executing multi-dimensional Macro: " << e.what()
1122 statusResult = ss.str();
1126 __SS__ <<
"Unknown error executing multi-dimensional Macro. " << __E__;
1131 catch(
const std::exception& e)
1133 ss <<
"Exception message: " << e.what();
1138 statusResult = ss.str();
1141 __COUTV__(statusResult);
1146 feMgr->macroMultiDimensionalStatusMap_[interfaceID] = statusResult;
1159 __CFG_COUT__ <<
"Started multi-dimensional Macro '" << macroName
1160 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1182 const std::string& requester,
1183 const std::string& interfaceID,
1184 const std::string& feMacroName,
1185 const bool enableSavingOutput,
1186 const std::string& outputFilePath,
1187 const std::string& outputFileRadix,
1188 const std::string& inputArgs)
1190 if(requester !=
"iterator")
1192 __CFG_SS__ <<
"Invalid requester '" << requester <<
"'" << __E__;
1196 __CFG_COUT__ <<
"Starting multi-dimensional FE Macro '" << feMacroName
1197 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1198 __CFG_COUTV__(inputArgs);
1204 if(macroMultiDimensionalStatusMap_.find(interfaceID) !=
1205 macroMultiDimensionalStatusMap_.end())
1207 __SS__ <<
"Failed to start multi-dimensional FE Macro '" << feMacroName
1208 <<
"' for interface '" << interfaceID
1209 <<
"' - this interface already has an active FE Macro launch!"
1213 macroMultiDimensionalStatusMap_.emplace(std::make_pair(interfaceID,
"Active"));
1219 const std::string interfaceID,
1220 const std::string feMacroName,
1221 const bool enableSavingOutput,
1222 const std::string outputFilePath,
1223 const std::string outputFileRadix,
1224 const std::string inputArgsStr) {
1226 std::string mfSubject_ =
"threadMultiD-" + feMacroName;
1227 __GEN_COUT__ <<
"Thread started." << __E__;
1229 std::string statusResult =
"Done";
1238 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1239 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1241 __GEN_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '"
1242 << interfaceID <<
"' was not found!" << __E__;
1249 FILE* outputFilePointer = 0;
1250 if(enableSavingOutput)
1252 std::string filename = outputFilePath +
"/" + outputFileRadix +
1253 feMacroName +
"_" + std::to_string(time(0)) +
1255 __GEN_COUT__ <<
"Opening file... " << filename << __E__;
1257 outputFilePointer = fopen(filename.c_str(),
"w");
1258 if(!outputFilePointer)
1260 __GEN_SS__ <<
"Failed to open output file: " << filename << __E__;
1267 __GEN_COUTV__(inputArgsStr);
1287 std::vector<
unsigned long > dimensionIterations,
1288 dimensionIterationCnt;
1290 using longParamMap_t = std::map<
1293 std::pair<
long ,
long >>>;
1294 using doubleParamMap_t =
1295 std::map<std::string ,
1299 using stringParamMap_t =
1300 std::map<std::string , std::string >;
1302 std::vector<longParamMap_t> longDimensionParameters;
1303 std::vector<doubleParamMap_t> doubleDimensionParameters;
1304 std::vector<stringParamMap_t> stringDimensionParameters;
1306 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
1307 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
1309 for(
unsigned int i = 0; i < feMacro.namesOfInputArguments_.size(); ++i)
1310 argsIn.push_back(std::make_pair(
1311 feMacro.namesOfInputArguments_[i],
1313 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1316 feMacro.namesOfOutputArguments_[i],
1323 argsIn.push_back(std::make_pair(
"myOtherArg",
"3"));
1325 dimensionIterations.push_back(2);
1326 dimensionIterations.push_back(4);
1328 longDimensionParameters.push_back(longParamMap_t());
1329 longDimensionParameters.push_back(longParamMap_t());
1331 doubleDimensionParameters.push_back(doubleParamMap_t());
1332 doubleDimensionParameters.push_back(doubleParamMap_t());
1334 longDimensionParameters.back().emplace(std::make_pair(
1338 std::make_pair(3 , 4 ))));
1341 std::vector<std::string> dimensionArgs;
1343 inputArgsStr, dimensionArgs, {
';'} );
1345 __GEN_COUTV__(dimensionArgs.size());
1348 if(dimensionArgs.size() == 0)
1353 dimensionIterations.push_back(1);
1354 longDimensionParameters.push_back(longParamMap_t());
1355 doubleDimensionParameters.push_back(doubleParamMap_t());
1356 stringDimensionParameters.push_back(stringParamMap_t());
1359 for(
unsigned int d = 0; d < dimensionArgs.size(); ++d)
1364 std::vector<std::string> args;
1366 dimensionArgs[d], args, {
','} );
1372 if(args.size() == 0)
1374 __GEN_SS__ <<
"Invalid dimensional arguments! "
1375 <<
"Need number of iterations at dimension " << d
1380 unsigned long numOfIterations;
1382 __GEN_COUT__ <<
"Dimension " << d
1383 <<
" numOfIterations=" << numOfIterations << __E__;
1387 dimensionIterations.push_back(numOfIterations);
1388 longDimensionParameters.push_back(longParamMap_t());
1389 doubleDimensionParameters.push_back(doubleParamMap_t());
1390 stringDimensionParameters.push_back(stringParamMap_t());
1394 for(
unsigned int a = 1; a < args.size(); ++a)
1396 std::vector<std::string> argPieces;
1398 args[a], argPieces, {
':'} );
1404 if(argPieces.size() != 3)
1406 __GEN_SS__ <<
"Invalid argument pieces! Should be size "
1408 << argPieces.size() << __E__;
1416 TableViewColumnInfo::DATATYPE_STRING_DEFAULT)
1420 __GEN_COUT__ <<
"Creating string argument '"
1421 << argPieces[0] <<
"' := " << argPieces[1]
1424 stringDimensionParameters.back().emplace(
1425 std::make_pair(argPieces[0], argPieces[1]));
1427 else if((argPieces[1].size() &&
1428 (argPieces[1][argPieces[1].size() - 1] ==
'f' ||
1429 argPieces[1].find(
'.') != std::string::npos)) ||
1430 (argPieces[2].size() &&
1431 (argPieces[2][argPieces[2].size() - 1] ==
'f' ||
1432 argPieces[2].find(
'.') != std::string::npos)))
1437 double startValue = strtod(argPieces[1].c_str(), 0);
1438 double stepSize = strtod(argPieces[2].c_str(), 0);
1440 __GEN_COUTV__(startValue);
1441 __GEN_COUTV__(stepSize);
1443 __GEN_COUT__ <<
"Creating double argument '"
1444 << argPieces[0] <<
"' := " << startValue
1445 <<
", " << stepSize << __E__;
1447 doubleDimensionParameters.back().emplace(std::make_pair(
1451 std::make_pair(startValue ,
1459 long int startValue;
1465 __GEN_COUTV__(startValue);
1466 __GEN_COUTV__(stepSize);
1468 __GEN_COUT__ <<
"Creating long argument '" << argPieces[0]
1469 <<
"' := " << startValue <<
", " << stepSize
1472 longDimensionParameters.back().emplace(std::make_pair(
1476 std::make_pair(startValue ,
1484 if(dimensionIterations.size() != longDimensionParameters.size() ||
1485 dimensionIterations.size() != doubleDimensionParameters.size() ||
1486 dimensionIterations.size() != stringDimensionParameters.size())
1488 __GEN_SS__ <<
"Impossible vector size mismatch! "
1489 << dimensionIterations.size() <<
" - "
1490 << longDimensionParameters.size() <<
" - "
1491 << doubleDimensionParameters.size() <<
" - "
1492 << stringDimensionParameters.size() << __E__;
1498 std::stringstream outSS;
1500 outSS <<
"\n==========================\n" << __E__;
1501 outSS <<
"FEMacro '" << feMacro.feMacroName_
1502 <<
"' multi-dimensional scan..." << __E__;
1504 outSS <<
"\t" << dimensionIterations.size()
1505 <<
" dimensions defined." << __E__;
1506 for(
unsigned int i = 0; i < dimensionIterations.size(); ++i)
1509 <<
"dimension[" << i <<
"] has "
1510 << dimensionIterations[i] <<
" iterations and "
1511 << (longDimensionParameters[i].size() +
1512 doubleDimensionParameters[i].size() +
1513 stringDimensionParameters[i].size())
1514 <<
" arguments." << __E__;
1516 for(
auto& param : longDimensionParameters[i])
1518 <<
"'" << param.first <<
"' of type long with "
1519 <<
"initial value and step value [decimal] = "
1520 <<
"\t" << param.second.second.first <<
" & "
1521 << param.second.second.second << __E__;
1523 for(
auto& param : doubleDimensionParameters[i])
1525 <<
"'" << param.first <<
"' of type double with "
1526 <<
"initial value and step value = "
1527 <<
"\t" << param.second.second.first <<
" & "
1528 << param.second.second.second << __E__;
1530 for(
auto& param : stringDimensionParameters[i])
1532 <<
"'" << param.first <<
"' of type string with "
1534 <<
"\t" << param.second << __E__;
1537 outSS <<
"\nHere are the identified input arguments:" << __E__;
1538 for(
unsigned int i = 0; i < feMacro.namesOfInputArguments_.size();
1540 outSS <<
"\t" << feMacro.namesOfInputArguments_[i] << __E__;
1541 outSS <<
"\nHere are the identified input arguments:" << __E__;
1542 for(
unsigned int i = 0;
1543 i < feMacro.namesOfOutputArguments_.size();
1545 outSS <<
"\t" << feMacro.namesOfOutputArguments_[i] << __E__;
1547 outSS <<
"\n==========================\n" << __E__;
1551 __GEN_COUT__ <<
"\n" << outSS.str();
1552 if(outputFilePointer)
1553 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1556 unsigned int iterationCount = 0;
1564 std::function<void(
const unsigned int
1566 localRecurse = [&dimensionIterations,
1567 &dimensionIterationCnt,
1569 &longDimensionParameters,
1570 &doubleDimensionParameters,
1571 &stringDimensionParameters,
1577 &localRecurse](
const unsigned int dimension) {
1579 std::string mfSubject_ =
"multiD-" + std::to_string(dimension) +
1580 "-" + feMacro.feMacroName_;
1581 __GEN_COUTV__(dimension);
1583 if(dimension >= dimensionIterations.size())
1585 __GEN_COUT__ <<
"Iteration count: " << iterationCount++
1587 __GEN_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_
1588 <<
"' ..." << __E__;
1599 for(
unsigned int i = 0; i < argsIn.size(); ++i)
1601 foundAsLong =
false;
1602 for(
unsigned int j = 0; j < dimensionIterations.size();
1606 longDimensionParameters[j].find(argsIn[i].first);
1607 if(longIt == longDimensionParameters[j].end())
1611 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1612 <<
"' to current long value '"
1613 << longIt->second.first
1614 <<
"' from dimension " << j
1615 <<
" parameter." << __E__;
1617 std::to_string(longIt->second.first);
1627 for(
unsigned int j = 0; j < dimensionIterations.size();
1630 auto doubleIt = doubleDimensionParameters[j].find(
1632 if(doubleIt == doubleDimensionParameters[j].end())
1636 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1637 <<
"' to current double value '"
1638 << doubleIt->second.first
1639 <<
"' from dimension " << j
1640 <<
" parameter." << __E__;
1642 std::to_string(doubleIt->second.first);
1652 for(
unsigned int j = 0; j < dimensionIterations.size();
1655 auto stringIt = stringDimensionParameters[j].find(
1657 if(stringIt == stringDimensionParameters[j].end())
1661 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1662 <<
"' to current string value '"
1664 <<
"' from dimension " << j
1665 <<
" parameter." << __E__;
1666 argsIn[i].second = stringIt->second;
1676 __GEN_SS__ <<
"ArgIn '" << argsIn[i].first
1677 <<
"' was not assigned a value "
1678 <<
"by any dimensional loop parameter sets. "
1679 "This is illegal. FEMacro '"
1680 << feMacro.feMacroName_ <<
"' requires '"
1682 <<
"' as an input argument. Either remove the "
1683 "input argument from this FEMacro, "
1684 <<
"or define a value as a dimensional loop "
1691 (fe->*(feMacro.macroFunction_))(feMacro, argsIn, argsOut);
1693 __GEN_COUT__ <<
"FE Macro complete!" << __E__;
1697 std::stringstream outSS;
1699 outSS <<
"\n---------------\n" << __E__;
1700 outSS <<
"FEMacro '" << feMacro.feMacroName_
1701 <<
"' execution..." << __E__;
1703 <<
"iteration " << iterationCount << __E__;
1704 for(
unsigned int i = 0;
1705 i < dimensionIterationCnt.size();
1708 <<
"dimension[" << i
1709 <<
"] index := " << dimensionIterationCnt[i]
1714 <<
"Input arguments (count: " << argsIn.size()
1716 for(
auto& argIn : argsIn)
1717 outSS <<
"\t\t" << argIn.first <<
" = "
1718 << argIn.second << __E__;
1722 <<
"Output arguments (count: " << argsOut.size()
1724 for(
auto& argOut : argsOut)
1725 outSS <<
"\t\t" << argOut.first <<
" = "
1726 << argOut.second << __E__;
1730 __GEN_COUT__ <<
"\n" << outSS.str();
1731 if(outputFilePointer)
1732 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1739 if(dimension >= dimensionIterationCnt.size())
1740 dimensionIterationCnt.push_back(0);
1743 __GEN_COUT__ <<
"\n"
1744 <<
"======================================" << __E__
1745 <<
"dimension[" << dimension
1746 <<
"] number of iterations := "
1747 << dimensionIterations[dimension] << __E__;
1752 for(
auto& longPair : longDimensionParameters[dimension])
1754 longPair.second.first =
1755 longPair.second.second.first;
1757 <<
"arg '" << longPair.first
1758 <<
"' current value: " << longPair.second.first
1762 for(
auto& doublePair : doubleDimensionParameters[dimension])
1764 doublePair.second.first =
1765 doublePair.second.second.first;
1767 <<
"arg '" << doublePair.first
1768 <<
"' current value: " << doublePair.second.first
1774 for(dimensionIterationCnt[dimension] =
1776 dimensionIterationCnt[dimension] <
1777 dimensionIterations[dimension];
1778 ++dimensionIterationCnt[dimension])
1780 __GEN_COUT__ <<
"dimension[" << dimension <<
"] index := "
1781 << dimensionIterationCnt[dimension] << __E__;
1783 localRecurse(dimension + 1);
1788 for(
auto& longPair : longDimensionParameters[dimension])
1790 longPair.second.first +=
1791 longPair.second.second.second;
1793 <<
"arg '" << longPair.first
1794 <<
"' current value: " << longPair.second.first
1798 for(
auto& doublePair :
1799 doubleDimensionParameters[dimension])
1801 doublePair.second.first +=
1802 doublePair.second.second.second;
1805 <<
"arg '" << doublePair.first
1806 <<
"' current value: " << doublePair.second.first
1812 __GEN_COUT__ <<
"Completed dimension[" << dimension
1813 <<
"] number of iterations := "
1814 << dimensionIterationCnt[dimension] <<
" of "
1815 << dimensionIterations[dimension] << __E__;
1822 if(outputFilePointer)
1823 fclose(outputFilePointer);
1825 catch(
const std::runtime_error& e)
1827 __SS__ <<
"Error executing multi-dimensional FE Macro: " << e.what()
1829 statusResult = ss.str();
1833 __SS__ <<
"Unknown error executing multi-dimensional FE Macro. " << __E__;
1838 catch(
const std::exception& e)
1840 ss <<
"Exception message: " << e.what();
1845 statusResult = ss.str();
1848 __COUTV__(statusResult);
1853 feMgr->macroMultiDimensionalStatusMap_[interfaceID] = statusResult;
1865 __CFG_COUT__ <<
"Started multi-dimensional FE Macro '" << feMacroName
1866 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1877 bool FEVInterfacesManager::checkMacroMultiDimensional(
const std::string& interfaceID,
1878 const std::string& macroName)
1884 auto statusIt = macroMultiDimensionalStatusMap_.find(interfaceID);
1885 if(statusIt == macroMultiDimensionalStatusMap_.end())
1887 __CFG_SS__ <<
"Status missing for multi-dimensional launch of Macro '"
1888 << macroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
1891 else if(statusIt->second ==
"Done")
1893 __CFG_COUT__ <<
"Completed multi-dimensional launch of Macro '" << macroName
1894 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1897 macroMultiDimensionalStatusMap_.erase(statusIt);
1900 else if(statusIt->second ==
"Active")
1902 __CFG_COUT__ <<
"Still running multi-dimensional launch of Macro '" << macroName
1903 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1908 __CFG_SS__ <<
"Error occured during multi-dimensional launch of Macro '" << macroName
1909 <<
"' for interface '" << interfaceID <<
"':" << statusIt->second << __E__;
1927 const std::string& interfaceID,
1928 const std::string& feMacroName,
1929 const std::string& inputArgs,
1930 std::string& outputArgs)
1932 __CFG_COUTV__(callingInterfaceID);
1938 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1939 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1941 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID
1942 <<
"' was not found!" << __E__;
1943 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1949 std::set<std::string> allowedFEsSet;
1955 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID
1956 <<
"' does not allow access to calling interfaceID '"
1957 << callingInterfaceID
1958 <<
"!' Did the interface add the calling interfaceID "
1959 <<
"to the access list when registering the front-end macro." << __E__;
1960 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1969 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1970 outputArgs += (i ?
"," :
"") + feMacro.namesOfOutputArguments_[i];
1972 __CFG_COUTV__(outputArgs);
1974 runFEMacro(interfaceID, feMacro, inputArgs, outputArgs);
1976 __CFG_COUTV__(outputArgs);
1992 const std::string& macroObjectString,
1993 const std::string& inputArgs,
1994 std::string& outputArgs)
2005 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
2007 std::istringstream inputStream(inputArgs);
2008 std::string splitVal, argName, argValue;
2009 while(getline(inputStream, splitVal,
';'))
2011 std::istringstream pairInputStream(splitVal);
2012 getline(pairInputStream, argName,
',');
2013 getline(pairInputStream, argValue,
',');
2014 argsIn.push_back(std::make_pair(argName, argValue));
2019 if(macro.namesOfInputArguments_.size() != argsIn.size())
2021 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2022 <<
"' was attempted on interfaceID '" << interfaceID
2023 <<
"' with a mismatch in"
2024 <<
" number of input arguments. " << argsIn.size() <<
" were given. "
2025 << macro.namesOfInputArguments_.size() <<
" expected." << __E__;
2028 for(
unsigned int i = 0; i < argsIn.size(); ++i)
2029 if(macro.namesOfInputArguments_.find(argsIn[i].first) ==
2030 macro.namesOfInputArguments_.end())
2032 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2033 <<
"' was attempted on interfaceID '" << interfaceID
2034 <<
"' with a mismatch in"
2035 <<
" a name of an input argument. " << argsIn[i].first
2036 <<
" was given. Expected: "
2044 std::vector<std::string> returnStrings;
2045 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
2048 std::istringstream inputStream(outputArgs);
2049 std::string argName;
2050 while(getline(inputStream, argName,
','))
2052 __CFG_COUT__ <<
"argName " << argName << __E__;
2054 returnStrings.push_back(
"DEFAULT");
2056 argName, returnStrings[returnStrings.size() - 1]));
2065 if(macro.namesOfOutputArguments_.size() != argsOut.size())
2067 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2068 <<
"' was attempted on interfaceID '" << interfaceID
2069 <<
"' with a mismatch in"
2070 <<
" number of output arguments. " << argsOut.size() <<
" were given. "
2071 << macro.namesOfOutputArguments_.size() <<
" expected." << __E__;
2075 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2076 if(macro.namesOfOutputArguments_.find(argsOut[i].first) ==
2077 macro.namesOfOutputArguments_.end())
2079 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2080 <<
"' was attempted on interfaceID '" << interfaceID
2081 <<
"' with a mismatch in"
2082 <<
" a name of an output argument. " << argsOut[i].first
2083 <<
" were given. Expected: "
2090 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
2092 std::map<std::string , uint64_t > variableMap;
2094 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
2095 variableMap.emplace(
2096 std::pair<std::string /*name*/, uint64_t /*value*/>(outputArgName, 0));
2097 for(
const auto& inputArgName : macro.namesOfInputArguments_)
2098 variableMap.emplace(
2099 std::pair<std::string /*name*/, uint64_t /*value*/>(inputArgName, 0));
2101 for(
auto& argIn : argsIn)
2103 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
2109 __CFG_COUT__ <<
"MacroMaker Macro complete!" << __E__;
2111 __CFG_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
2112 for(
auto& arg : argsOut)
2114 std::stringstream numberSs;
2115 numberSs << std::dec << variableMap.at(arg.first) <<
" (0x" << std::hex
2116 << variableMap.at(arg.first) <<
")" << std::dec;
2117 arg.second = numberSs.str();
2118 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
2123 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2127 outputArgs += argsOut[i].first +
"," + argsOut[i].second;
2130 __CFG_COUT__ <<
"outputArgs = " << outputArgs << __E__;
2146 const std::string& feMacroName,
2147 const std::string& inputArgs,
2148 std::string& outputArgs)
2154 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
2155 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
2157 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID
2158 <<
"' was not found!" << __E__;
2159 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2163 runFEMacro(interfaceID, FEMacroIt->second, inputArgs, outputArgs);
2180 const std::string& inputArgs,
2181 std::string& outputArgs)
2185 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
2187 std::istringstream inputStream(inputArgs);
2188 std::string splitVal, argName, argValue;
2189 while(getline(inputStream, splitVal,
';'))
2191 std::istringstream pairInputStream(splitVal);
2192 getline(pairInputStream, argName,
',');
2193 getline(pairInputStream, argValue,
',');
2200 if(feMacro.namesOfInputArguments_.size() != argsIn.size())
2202 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2203 << interfaceID <<
"' was attempted with a mismatch in"
2204 <<
" number of input arguments. " << argsIn.size() <<
" were given. "
2205 << feMacro.namesOfInputArguments_.size() <<
" expected." << __E__;
2206 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2209 for(
unsigned int i = 0; i < argsIn.size(); ++i)
2210 if(argsIn[i].first != feMacro.namesOfInputArguments_[i])
2212 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2213 << interfaceID <<
"' was attempted with a mismatch in"
2214 <<
" a name of an input argument. " << argsIn[i].first
2215 <<
" was given. " << feMacro.namesOfInputArguments_[i]
2216 <<
" expected." << __E__;
2217 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2222 std::vector<std::string> returnStrings;
2223 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
2226 std::istringstream inputStream(outputArgs);
2227 std::string argName;
2228 while(getline(inputStream, argName,
','))
2230 __CFG_COUT__ <<
"argName " << argName << __E__;
2232 returnStrings.push_back(
"DEFAULT");
2235 returnStrings[returnStrings.size() - 1]));
2238 __CFG_COUT__ << (uint64_t) & (returnStrings[returnStrings.size() - 1])
2244 if(feMacro.namesOfOutputArguments_.size() != argsOut.size())
2246 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2247 << interfaceID <<
"' was attempted with a mismatch in"
2248 <<
" number of output arguments. " << argsOut.size() <<
" were given. "
2249 << feMacro.namesOfOutputArguments_.size() <<
" expected." << __E__;
2250 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2253 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2254 if(argsOut[i].first != feMacro.namesOfOutputArguments_[i])
2256 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2257 << interfaceID <<
"' was attempted with a mismatch in"
2258 <<
" a name of an output argument. " << argsOut[i].first
2259 <<
" were given. " << feMacro.namesOfOutputArguments_[i]
2260 <<
" expected." << __E__;
2261 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2265 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
2266 for(
auto& argIn : argsIn)
2267 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
2275 __COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_ <<
"' ..." << __E__;
2276 __CFG_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_ <<
"' ..." << __E__;
2281 __CFG_COUT__ <<
"FE Macro complete!" << __E__;
2283 __CFG_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
2284 for(
const auto& arg : argsOut)
2285 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
2288 if(feMacro.namesOfOutputArguments_.size() != argsOut.size())
2290 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2292 <<
"' was attempted but the FE macro "
2293 "manipulated the output arguments vector. It is illegal "
2294 "to add or remove output vector name/value pairs."
2296 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2302 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2314 std::stringstream outNumberSs;
2315 outNumberSs << std::dec << tmpNumber <<
" (0x" << std::hex << tmpNumber
2317 outputArgs += argsOut[i].first +
"," + outNumberSs.str();
2326 argsOut[i].first +
"," + StringMacros::encodeURIComponent(argsOut[i].second);
2329 __CFG_COUTT__ <<
"outputArgs = " << outputArgs << __E__;
2343 const std::string& supervisorLid)
2345 std::string retList =
"";
2347 __CFG_COUTV__(theFEInterfaces_.size());
2349 for(
const auto& it : theFEInterfaces_)
2351 __CFG_COUTT__ <<
"FE interface UID = " << it.first << __E__;
2353 retList += supervisorName +
";" + supervisorLid +
";" +
2354 it.second->getInterfaceType() +
";" + it.second->getInterfaceUID();
2356 for(
const auto& macroPair : it.second->getMapOfFEMacroFunctions())
2358 __CFG_COUTT__ <<
"FE Macro name = " << macroPair.first << __E__;
2360 ";" + macroPair.first +
";" + macroPair.second.requiredUserPermissions_;
2362 ";" + StringMacros::encodeURIComponent(macroPair.second.feMacroTooltip_);
2365 ";" + std::to_string(macroPair.second.namesOfInputArguments_.size());
2366 for(
const auto& name : macroPair.second.namesOfInputArguments_)
2367 retList +=
";" + StringMacros::encodeURIComponent(name);
2370 ";" + std::to_string(macroPair.second.namesOfOutputArguments_.size());
2371 for(
const auto& name : macroPair.second.namesOfOutputArguments_)
2372 retList +=
";" + StringMacros::encodeURIComponent(name);
2386 for(
const auto& FEInterface : theFEInterfaces_)
2388 isActive = FEInterface.second->WorkLoop::isActive();
2390 __CFG_COUT__ << FEInterface.second->getInterfaceUID() <<
" of type "
2391 << FEInterface.second->getInterfaceType() <<
": \t"
2392 <<
"workLoop_->isActive() " << (isActive ?
"yes" :
"no") << __E__;
2405 void FEVInterfacesManager::preStateMachineExecutionLoop(
void)
2407 VStateMachine::clearIterationWork();
2408 VStateMachine::clearSubIterationWork();
2410 stateMachinesIterationWorkCount_ = 0;
2412 __CFG_COUT__ <<
"Number of front ends to transition: " << theFENamesByPriority_.size()
2415 if(VStateMachine::getIterationIndex() == 0 &&
2416 VStateMachine::getSubIterationIndex() == 0)
2420 subIterationWorkStateMachineIndex_ = -1;
2422 stateMachinesIterationDone_.clear();
2423 for(
const auto& FEPair : theFEInterfaces_)
2424 stateMachinesIterationDone_[FEPair.first] =
false;
2427 __CFG_COUT__ <<
"Iteration " << VStateMachine::getIterationIndex() <<
"."
2428 << VStateMachine::getSubIterationIndex() <<
"("
2429 << (int)subIterationWorkStateMachineIndex_ <<
")" << __E__;
2433 void FEVInterfacesManager::preStateMachineExecution(
unsigned int i,
2434 const std::string& transitionName)
2436 if(i >= theFENamesByPriority_.size())
2438 __CFG_SS__ <<
"FE Interface " << i <<
" not found!" << __E__;
2442 const std::string& name = theFENamesByPriority_[i];
2446 fe->VStateMachine::setTransitionName(transitionName);
2447 fe->VStateMachine::setIterationIndex(VStateMachine::getIterationIndex());
2448 fe->VStateMachine::setSubIterationIndex(VStateMachine::getSubIterationIndex());
2450 fe->VStateMachine::clearIterationWork();
2451 fe->VStateMachine::clearSubIterationWork();
2453 __CFG_COUT__ <<
"theStateMachineImplementation Iteration "
2454 << fe->VStateMachine::getIterationIndex() <<
"."
2455 << fe->VStateMachine::getSubIterationIndex() << __E__;
2461 bool FEVInterfacesManager::postStateMachineExecution(
unsigned int i)
2463 if(i >= theFENamesByPriority_.size())
2465 __CFG_SS__ <<
"FE Interface index " << i <<
" not found!" << __E__;
2469 const std::string& name = theFENamesByPriority_[i];
2474 if(fe->VStateMachine::getSubIterationWork())
2476 subIterationWorkStateMachineIndex_ = i;
2477 VStateMachine::indicateSubIterationWork();
2479 __CFG_COUT__ <<
"FE Interface '" << name
2480 <<
"' is flagged for another sub-iteration..." << __E__;
2485 subIterationWorkStateMachineIndex_ = -1;
2487 bool& stateMachineDone = stateMachinesIterationDone_[name];
2488 stateMachineDone = !fe->VStateMachine::getIterationWork();
2490 if(!stateMachineDone)
2492 __CFG_COUT__ <<
"FE Interface '" << name
2493 <<
"' is flagged for another iteration..." << __E__;
2494 VStateMachine::indicateIterationWork();
2496 ++stateMachinesIterationWorkCount_;
2501 fe->VStateMachine::setTransitionName(
"");
2506 void FEVInterfacesManager::postStateMachineExecutionLoop(
void)
2508 if(VStateMachine::getSubIterationWork())
2509 __CFG_COUT__ <<
"FE Interface state machine implementation "
2510 << subIterationWorkStateMachineIndex_
2511 <<
" is flagged for another sub-iteration..." << __E__;
2512 else if(VStateMachine::getIterationWork())
2513 __CFG_COUT__ << stateMachinesIterationWorkCount_
2514 <<
" FE Interface state machine implementation(s) flagged for "
2515 "another iteration..."
2518 __CFG_COUT__ <<
"Done transitioning all state machine implementations..."
std::vector< std::string > getChildrenNames(bool byPriority=false, bool onlyStatusTrue=false) const
ConfigurationTree getNode(const std::string &nodeName, bool doNotThrowOnBrokenUIDLinks=false) const
navigating between nodes
const std::string & getValueAsString(bool returnLinkTableValue=false) const
std::vector< std::pair< std::string, ConfigurationTree > > getChildren(std::map< std::string, std::string > filterMap=std::map< std::string, std::string >(), bool byPriority=false, bool onlyStatusTrue=false) const
void runMacro(FEVInterface::macroStruct_t ¯o, std::map< std::string, uint64_t > &variableMap)
runMacro
virtual void configureSlowControls(void)
end State Machine handlers
virtual void configure(void)
std::pair< const std::string, std::string > frontEndMacroArg_t
end Slow Controls
virtual void universalRead(char *address, char *returnValue)=0
throw std::runtime_error exception on error/timeout
const FEVInterface & getFEInterface(const std::string &interfaceID) const
getFEInterface
std::string getFEMacrosString(const std::string &supervisorName, const std::string &supervisorLid)
used by MacroMaker
std::mutex macroMultiDimensionalDoneMutex_
multi-dimensional FE Macro helpers
FEVInterface * getFEInterfaceP(const std::string &interfaceID)
getFEInterfaceP
void runFEMacro(const std::string &interfaceID, const FEVInterface::frontEndMacroStruct_t &feMacro, const std::string &inputArgs, std::string &outputArgs)
used by MacroMaker and FE calling indirectly
unsigned int getInterfaceUniversalAddressSize(const std::string &interfaceID)
used by MacroMaker
void startFEMacroMultiDimensional(const std::string &requester, const std::string &interfaceID, const std::string &feMacroName, const bool enableSavingOutput, const std::string &outputFilePath, const std::string &outputFileRadix, const std::string &inputArgs)
used by iterator calling (i.e. FESupervisor)
void universalWrite(const std::string &interfaceID, char *address, char *writeValue)
used by MacroMaker
bool allFEWorkloopsAreDone(void)
used by Iterator, e.g.
virtual void configure(void) override
State Machine Methods.
void runFEMacroByFE(const std::string &callingInterfaceID, const std::string &interfaceID, const std::string &feMacroName, const std::string &inputArgs, std::string &outputArgs)
used by FE calling (i.e. FESupervisor)
unsigned int getInterfaceUniversalDataSize(const std::string &interfaceID)
used by MacroMaker
void universalRead(const std::string &interfaceID, char *address, char *returnValue)
used by MacroMaker
virtual std::string getStatusProgressDetail(void) override
overriding VStateMachine::getStatusProgressDetail
void startMacroMultiDimensional(const std::string &requester, const std::string &interfaceID, const std::string ¯oName, const std::string ¯oString, const bool enableSavingOutput, const std::string &outputFilePath, const std::string &outputFileRadix, const std::string &inputArgs)
used by iterator calling (i.e. FESupervisor)
void runMacro(const std::string &interfaceID, const std::string ¯oObjectString, const std::string &inputArgs, std::string &outputArgs)
used by MacroMaker
std::string getFEListString(const std::string &supervisorLid)
used by MacroMaker
virtual std::string getStatusProgressDetail(void)
Status.
CoreSupervisorBase * parentSupervisor_
< members fully define a front-end macro function
const frontEndMacroFunction_t macroFunction_
Note: must be called using this instance.
static std::string getTimestampString(const std::string &linuxTimeInSeconds)
static void getVectorFromString(const std::string &inputString, std::vector< std::string > &listToReturn, const std::set< char > &delimiter={',', '|', '&'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'}, std::vector< char > *listOfDelimiters=0, bool decodeURIComponents=false)
static void getSetFromString(const std::string &inputString, std::set< std::string > &setToReturn, const std::set< char > &delimiter={',', '|', '&'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'})
static std::string setToString(const std::set< T > &setToReturn, const std::string &delimeter=", ")
setToString ~
static std::string vectorToString(const std::vector< T > &setToReturn, const std::string &delimeter=", ")
vectorToString ~
static bool inWildCardSet(const std::string &needle, const std::set< std::string > &haystack)
static std::string decodeURIComponent(const std::string &data)
static bool getNumber(const std::string &s, T &retValue)