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__;
1064 for(
auto& longPair : longDimensionParameters[dimension])
1066 longPair.second.first =
1067 longPair.second.second.first;
1069 <<
"arg '" << longPair.first
1070 <<
"' current value: " << longPair.second.first
1076 for(dimensionIterationCnt[dimension] =
1078 dimensionIterationCnt[dimension] <
1079 dimensionIterations[dimension];
1080 ++dimensionIterationCnt[dimension])
1082 __GEN_COUT__ <<
"dimension[" << dimension <<
"] index := "
1083 << dimensionIterationCnt[dimension] << __E__;
1085 localRecurse(dimension + 1);
1089 for(
auto& longPair : longDimensionParameters[dimension])
1091 longPair.second.first +=
1092 longPair.second.second.second;
1094 <<
"arg '" << longPair.first
1095 <<
"' current value: " << longPair.second.first
1101 __GEN_COUT__ <<
"Completed dimension[" << dimension
1102 <<
"] number of iterations := "
1103 << dimensionIterationCnt[dimension] <<
" of "
1104 << dimensionIterations[dimension] << __E__;
1111 if(outputFilePointer)
1112 fclose(outputFilePointer);
1114 catch(
const std::runtime_error& e)
1116 __SS__ <<
"Error executing multi-dimensional Macro: " << e.what()
1118 statusResult = ss.str();
1122 __SS__ <<
"Unknown error executing multi-dimensional Macro. " << __E__;
1127 catch(
const std::exception& e)
1129 ss <<
"Exception message: " << e.what();
1134 statusResult = ss.str();
1137 __COUTV__(statusResult);
1142 feMgr->macroMultiDimensionalStatusMap_[interfaceID] = statusResult;
1155 __CFG_COUT__ <<
"Started multi-dimensional Macro '" << macroName
1156 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1178 const std::string& requester,
1179 const std::string& interfaceID,
1180 const std::string& feMacroName,
1181 const bool enableSavingOutput,
1182 const std::string& outputFilePath,
1183 const std::string& outputFileRadix,
1184 const std::string& inputArgs)
1186 if(requester !=
"iterator")
1188 __CFG_SS__ <<
"Invalid requester '" << requester <<
"'" << __E__;
1192 __CFG_COUT__ <<
"Starting multi-dimensional FE Macro '" << feMacroName
1193 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1194 __CFG_COUTV__(inputArgs);
1200 if(macroMultiDimensionalStatusMap_.find(interfaceID) !=
1201 macroMultiDimensionalStatusMap_.end())
1203 __SS__ <<
"Failed to start multi-dimensional FE Macro '" << feMacroName
1204 <<
"' for interface '" << interfaceID
1205 <<
"' - this interface already has an active FE Macro launch!"
1209 macroMultiDimensionalStatusMap_.emplace(std::make_pair(interfaceID,
"Active"));
1215 const std::string interfaceID,
1216 const std::string feMacroName,
1217 const bool enableSavingOutput,
1218 const std::string outputFilePath,
1219 const std::string outputFileRadix,
1220 const std::string inputArgsStr) {
1222 std::string mfSubject_ =
"threadMultiD-" + feMacroName;
1223 __GEN_COUT__ <<
"Thread started." << __E__;
1225 std::string statusResult =
"Done";
1234 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1235 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1237 __GEN_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '"
1238 << interfaceID <<
"' was not found!" << __E__;
1245 FILE* outputFilePointer = 0;
1246 if(enableSavingOutput)
1248 std::string filename = outputFilePath +
"/" + outputFileRadix +
1249 feMacroName +
"_" + std::to_string(time(0)) +
1251 __GEN_COUT__ <<
"Opening file... " << filename << __E__;
1253 outputFilePointer = fopen(filename.c_str(),
"w");
1254 if(!outputFilePointer)
1256 __GEN_SS__ <<
"Failed to open output file: " << filename << __E__;
1263 __GEN_COUTV__(inputArgsStr);
1283 std::vector<
unsigned long > dimensionIterations,
1284 dimensionIterationCnt;
1286 using longParamMap_t = std::map<
1289 std::pair<
long ,
long >>>;
1290 using doubleParamMap_t =
1291 std::map<std::string ,
1295 using stringParamMap_t =
1296 std::map<std::string , std::string >;
1298 std::vector<longParamMap_t> longDimensionParameters;
1299 std::vector<doubleParamMap_t> doubleDimensionParameters;
1300 std::vector<stringParamMap_t> stringDimensionParameters;
1302 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
1303 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
1305 for(
unsigned int i = 0; i < feMacro.namesOfInputArguments_.size(); ++i)
1306 argsIn.push_back(std::make_pair(
1307 feMacro.namesOfInputArguments_[i],
1309 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1312 feMacro.namesOfOutputArguments_[i],
1319 argsIn.push_back(std::make_pair(
"myOtherArg",
"3"));
1321 dimensionIterations.push_back(2);
1322 dimensionIterations.push_back(4);
1324 longDimensionParameters.push_back(longParamMap_t());
1325 longDimensionParameters.push_back(longParamMap_t());
1327 doubleDimensionParameters.push_back(doubleParamMap_t());
1328 doubleDimensionParameters.push_back(doubleParamMap_t());
1330 longDimensionParameters.back().emplace(std::make_pair(
1334 std::make_pair(3 , 4 ))));
1337 std::vector<std::string> dimensionArgs;
1339 inputArgsStr, dimensionArgs, {
';'} );
1341 __GEN_COUTV__(dimensionArgs.size());
1344 if(dimensionArgs.size() == 0)
1349 dimensionIterations.push_back(1);
1350 longDimensionParameters.push_back(longParamMap_t());
1351 doubleDimensionParameters.push_back(doubleParamMap_t());
1352 stringDimensionParameters.push_back(stringParamMap_t());
1355 for(
unsigned int d = 0; d < dimensionArgs.size(); ++d)
1360 std::vector<std::string> args;
1362 dimensionArgs[d], args, {
','} );
1368 if(args.size() == 0)
1370 __GEN_SS__ <<
"Invalid dimensional arguments! "
1371 <<
"Need number of iterations at dimension " << d
1376 unsigned long numOfIterations;
1378 __GEN_COUT__ <<
"Dimension " << d
1379 <<
" numOfIterations=" << numOfIterations << __E__;
1383 dimensionIterations.push_back(numOfIterations);
1384 longDimensionParameters.push_back(longParamMap_t());
1385 doubleDimensionParameters.push_back(doubleParamMap_t());
1386 stringDimensionParameters.push_back(stringParamMap_t());
1390 for(
unsigned int a = 1; a < args.size(); ++a)
1392 std::vector<std::string> argPieces;
1394 args[a], argPieces, {
':'} );
1400 if(argPieces.size() != 3)
1402 __GEN_SS__ <<
"Invalid argument pieces! Should be size "
1404 << argPieces.size() << __E__;
1412 TableViewColumnInfo::DATATYPE_STRING_DEFAULT)
1416 __GEN_COUT__ <<
"Creating string argument '"
1417 << argPieces[0] <<
"' := " << argPieces[1]
1420 stringDimensionParameters.back().emplace(
1421 std::make_pair(argPieces[0], argPieces[1]));
1423 else if((argPieces[1].size() &&
1424 (argPieces[1][argPieces[1].size() - 1] ==
'f' ||
1425 argPieces[1].find(
'.') != std::string::npos)) ||
1426 (argPieces[2].size() &&
1427 (argPieces[2][argPieces[2].size() - 1] ==
'f' ||
1428 argPieces[2].find(
'.') != std::string::npos)))
1433 double startValue = strtod(argPieces[1].c_str(), 0);
1434 double stepSize = strtod(argPieces[2].c_str(), 0);
1436 __GEN_COUTV__(startValue);
1437 __GEN_COUTV__(stepSize);
1439 __GEN_COUT__ <<
"Creating double argument '"
1440 << argPieces[0] <<
"' := " << startValue
1441 <<
", " << stepSize << __E__;
1443 doubleDimensionParameters.back().emplace(std::make_pair(
1447 std::make_pair(startValue ,
1455 long int startValue;
1461 __GEN_COUTV__(startValue);
1462 __GEN_COUTV__(stepSize);
1464 __GEN_COUT__ <<
"Creating long argument '" << argPieces[0]
1465 <<
"' := " << startValue <<
", " << stepSize
1468 longDimensionParameters.back().emplace(std::make_pair(
1472 std::make_pair(startValue ,
1480 if(dimensionIterations.size() != longDimensionParameters.size() ||
1481 dimensionIterations.size() != doubleDimensionParameters.size() ||
1482 dimensionIterations.size() != stringDimensionParameters.size())
1484 __GEN_SS__ <<
"Impossible vector size mismatch! "
1485 << dimensionIterations.size() <<
" - "
1486 << longDimensionParameters.size() <<
" - "
1487 << doubleDimensionParameters.size() <<
" - "
1488 << stringDimensionParameters.size() << __E__;
1494 std::stringstream outSS;
1496 outSS <<
"\n==========================\n" << __E__;
1497 outSS <<
"FEMacro '" << feMacro.feMacroName_
1498 <<
"' multi-dimensional scan..." << __E__;
1500 outSS <<
"\t" << dimensionIterations.size()
1501 <<
" dimensions defined." << __E__;
1502 for(
unsigned int i = 0; i < dimensionIterations.size(); ++i)
1505 <<
"dimension[" << i <<
"] has "
1506 << dimensionIterations[i] <<
" iterations and "
1507 << (longDimensionParameters[i].size() +
1508 doubleDimensionParameters[i].size() +
1509 stringDimensionParameters[i].size())
1510 <<
" arguments." << __E__;
1512 for(
auto& param : longDimensionParameters[i])
1514 <<
"'" << param.first <<
"' of type long with "
1515 <<
"initial value and step value [decimal] = "
1516 <<
"\t" << param.second.second.first <<
" & "
1517 << param.second.second.second << __E__;
1519 for(
auto& param : doubleDimensionParameters[i])
1521 <<
"'" << param.first <<
"' of type double with "
1522 <<
"initial value and step value = "
1523 <<
"\t" << param.second.second.first <<
" & "
1524 << param.second.second.second << __E__;
1526 for(
auto& param : stringDimensionParameters[i])
1528 <<
"'" << param.first <<
"' of type string with "
1530 <<
"\t" << param.second << __E__;
1533 outSS <<
"\nHere are the identified input arguments:" << __E__;
1534 for(
unsigned int i = 0; i < feMacro.namesOfInputArguments_.size();
1536 outSS <<
"\t" << feMacro.namesOfInputArguments_[i] << __E__;
1537 outSS <<
"\nHere are the identified input arguments:" << __E__;
1538 for(
unsigned int i = 0;
1539 i < feMacro.namesOfOutputArguments_.size();
1541 outSS <<
"\t" << feMacro.namesOfOutputArguments_[i] << __E__;
1543 outSS <<
"\n==========================\n" << __E__;
1547 __GEN_COUT__ <<
"\n" << outSS.str();
1548 if(outputFilePointer)
1549 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1552 unsigned int iterationCount = 0;
1560 std::function<void(
const unsigned int
1562 localRecurse = [&dimensionIterations,
1563 &dimensionIterationCnt,
1565 &longDimensionParameters,
1566 &doubleDimensionParameters,
1567 &stringDimensionParameters,
1573 &localRecurse](
const unsigned int dimension) {
1575 std::string mfSubject_ =
"multiD-" + std::to_string(dimension) +
1576 "-" + feMacro.feMacroName_;
1577 __GEN_COUTV__(dimension);
1579 if(dimension >= dimensionIterations.size())
1581 __GEN_COUT__ <<
"Iteration count: " << iterationCount++
1583 __GEN_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_
1584 <<
"' ..." << __E__;
1595 for(
unsigned int i = 0; i < argsIn.size(); ++i)
1597 foundAsLong =
false;
1598 for(
unsigned int j = 0; j < dimensionIterations.size();
1602 longDimensionParameters[j].find(argsIn[i].first);
1603 if(longIt == longDimensionParameters[j].end())
1607 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1608 <<
"' to current long value '"
1609 << longIt->second.first
1610 <<
"' from dimension " << j
1611 <<
" parameter." << __E__;
1613 std::to_string(longIt->second.first);
1623 for(
unsigned int j = 0; j < dimensionIterations.size();
1626 auto doubleIt = doubleDimensionParameters[j].find(
1628 if(doubleIt == doubleDimensionParameters[j].end())
1632 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1633 <<
"' to current double value '"
1634 << doubleIt->second.first
1635 <<
"' from dimension " << j
1636 <<
" parameter." << __E__;
1638 std::to_string(doubleIt->second.first);
1648 for(
unsigned int j = 0; j < dimensionIterations.size();
1651 auto stringIt = stringDimensionParameters[j].find(
1653 if(stringIt == stringDimensionParameters[j].end())
1657 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1658 <<
"' to current string value '"
1660 <<
"' from dimension " << j
1661 <<
" parameter." << __E__;
1662 argsIn[i].second = stringIt->second;
1672 __GEN_SS__ <<
"ArgIn '" << argsIn[i].first
1673 <<
"' was not assigned a value "
1674 <<
"by any dimensional loop parameter sets. "
1675 "This is illegal. FEMacro '"
1676 << feMacro.feMacroName_ <<
"' requires '"
1678 <<
"' as an input argument. Either remove the "
1679 "input argument from this FEMacro, "
1680 <<
"or define a value as a dimensional loop "
1687 (fe->*(feMacro.macroFunction_))(feMacro, argsIn, argsOut);
1689 __GEN_COUT__ <<
"FE Macro complete!" << __E__;
1693 std::stringstream outSS;
1695 outSS <<
"\n---------------\n" << __E__;
1696 outSS <<
"FEMacro '" << feMacro.feMacroName_
1697 <<
"' execution..." << __E__;
1699 <<
"iteration " << iterationCount << __E__;
1700 for(
unsigned int i = 0;
1701 i < dimensionIterationCnt.size();
1704 <<
"dimension[" << i
1705 <<
"] index := " << dimensionIterationCnt[i]
1710 <<
"Input arguments (count: " << argsIn.size()
1712 for(
auto& argIn : argsIn)
1713 outSS <<
"\t\t" << argIn.first <<
" = "
1714 << argIn.second << __E__;
1718 <<
"Output arguments (count: " << argsOut.size()
1720 for(
auto& argOut : argsOut)
1721 outSS <<
"\t\t" << argOut.first <<
" = "
1722 << argOut.second << __E__;
1726 __GEN_COUT__ <<
"\n" << outSS.str();
1727 if(outputFilePointer)
1728 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1735 if(dimension >= dimensionIterationCnt.size())
1736 dimensionIterationCnt.push_back(0);
1739 __GEN_COUT__ <<
"\n"
1740 <<
"======================================" << __E__
1741 <<
"dimension[" << dimension
1742 <<
"] number of iterations := "
1743 << dimensionIterations[dimension] << __E__;
1748 for(
auto& longPair : longDimensionParameters[dimension])
1750 longPair.second.first =
1751 longPair.second.second.first;
1753 <<
"arg '" << longPair.first
1754 <<
"' current value: " << longPair.second.first
1758 for(
auto& doublePair : doubleDimensionParameters[dimension])
1760 doublePair.second.first =
1761 doublePair.second.second.first;
1763 <<
"arg '" << doublePair.first
1764 <<
"' current value: " << doublePair.second.first
1770 for(dimensionIterationCnt[dimension] =
1772 dimensionIterationCnt[dimension] <
1773 dimensionIterations[dimension];
1774 ++dimensionIterationCnt[dimension])
1776 __GEN_COUT__ <<
"dimension[" << dimension <<
"] index := "
1777 << dimensionIterationCnt[dimension] << __E__;
1779 localRecurse(dimension + 1);
1784 for(
auto& longPair : longDimensionParameters[dimension])
1786 longPair.second.first +=
1787 longPair.second.second.second;
1789 <<
"arg '" << longPair.first
1790 <<
"' current value: " << longPair.second.first
1794 for(
auto& doublePair :
1795 doubleDimensionParameters[dimension])
1797 doublePair.second.first +=
1798 doublePair.second.second.second;
1801 <<
"arg '" << doublePair.first
1802 <<
"' current value: " << doublePair.second.first
1808 __GEN_COUT__ <<
"Completed dimension[" << dimension
1809 <<
"] number of iterations := "
1810 << dimensionIterationCnt[dimension] <<
" of "
1811 << dimensionIterations[dimension] << __E__;
1818 if(outputFilePointer)
1819 fclose(outputFilePointer);
1821 catch(
const std::runtime_error& e)
1823 __SS__ <<
"Error executing multi-dimensional FE Macro: " << e.what()
1825 statusResult = ss.str();
1829 __SS__ <<
"Unknown error executing multi-dimensional FE Macro. " << __E__;
1834 catch(
const std::exception& e)
1836 ss <<
"Exception message: " << e.what();
1841 statusResult = ss.str();
1844 __COUTV__(statusResult);
1849 feMgr->macroMultiDimensionalStatusMap_[interfaceID] = statusResult;
1861 __CFG_COUT__ <<
"Started multi-dimensional FE Macro '" << feMacroName
1862 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1873 bool FEVInterfacesManager::checkMacroMultiDimensional(
const std::string& interfaceID,
1874 const std::string& macroName)
1880 auto statusIt = macroMultiDimensionalStatusMap_.find(interfaceID);
1881 if(statusIt == macroMultiDimensionalStatusMap_.end())
1883 __CFG_SS__ <<
"Status missing for multi-dimensional launch of Macro '"
1884 << macroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
1887 else if(statusIt->second ==
"Done")
1889 __CFG_COUT__ <<
"Completed multi-dimensional launch of Macro '" << macroName
1890 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1893 macroMultiDimensionalStatusMap_.erase(statusIt);
1896 else if(statusIt->second ==
"Active")
1898 __CFG_COUT__ <<
"Still running multi-dimensional launch of Macro '" << macroName
1899 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1904 __CFG_SS__ <<
"Error occured during multi-dimensional launch of Macro '" << macroName
1905 <<
"' for interface '" << interfaceID <<
"':" << statusIt->second << __E__;
1923 const std::string& interfaceID,
1924 const std::string& feMacroName,
1925 const std::string& inputArgs,
1926 std::string& outputArgs)
1928 __CFG_COUTV__(callingInterfaceID);
1934 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1935 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1937 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID
1938 <<
"' was not found!" << __E__;
1939 ss <<
"\nHere is the list of available FE Macros:\n";
1940 for(
const auto& feMacro : fe->getMapOfFEMacroFunctions())
1941 ss << feMacro.first <<
"... ";
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();
2210 for(
unsigned int i = 0; i < argsIn.size(); ++i)
2211 if(argsIn[i].first.substr(0, argsIn[i].first.find(
'(')) !=
2212 feMacro.namesOfInputArguments_[i].substr(
2213 0, feMacro.namesOfInputArguments_[i].find(
'(')))
2215 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2216 << interfaceID <<
"' was attempted with a mismatch in"
2217 <<
" a name of an input argument. " << argsIn[i].first
2218 <<
" was given. " << feMacro.namesOfInputArguments_[i]
2219 <<
" expected." << __E__;
2220 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2225 std::vector<std::string> returnStrings;
2226 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
2228 const std::string ARG_OUT_DEFAULT =
"DEFAULT";
2231 std::istringstream inputStream(outputArgs);
2232 std::string argName;
2233 while(getline(inputStream, argName,
','))
2235 __CFG_COUT__ <<
"argName " << argName << __E__;
2237 returnStrings.push_back(ARG_OUT_DEFAULT);
2240 returnStrings[returnStrings.size() - 1]));
2243 __CFG_COUT__ << (uint64_t) & (returnStrings[returnStrings.size() - 1])
2249 if(feMacro.namesOfOutputArguments_.size() != argsOut.size())
2251 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2252 << interfaceID <<
"' was attempted with a mismatch in"
2253 <<
" number of output arguments. " << argsOut.size() <<
" were given. "
2254 << feMacro.namesOfOutputArguments_.size() <<
" expected." << __E__;
2255 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2258 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2259 if(argsOut[i].first != feMacro.namesOfOutputArguments_[i])
2261 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2262 << interfaceID <<
"' was attempted with a mismatch in"
2263 <<
" a name of an output argument. " << argsOut[i].first
2264 <<
" were given. " << feMacro.namesOfOutputArguments_[i]
2265 <<
" expected." << __E__;
2266 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2271 const uint16_t BUILT_IN_ARGOUT_COUNT = 1;
2273 returnStrings.push_back(ARG_OUT_DEFAULT);
2275 PLOTLY_PLOT, returnStrings[returnStrings.size() - 1]));
2278 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
2279 for(
auto& argIn : argsIn)
2280 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
2282 __CFG_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_ <<
"' ..." << __E__;
2286 __CFG_COUT__ <<
"FE Macro complete!" << __E__;
2288 __CFG_COUT__ <<
"# of output args = " << argsOut.size() <<
" including "
2289 << BUILT_IN_ARGOUT_COUNT <<
" built-in args." << __E__;
2290 for(
const auto& arg : argsOut)
2291 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
2294 if(feMacro.namesOfOutputArguments_.size() != argsOut.size() - BUILT_IN_ARGOUT_COUNT)
2296 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2298 <<
"' was attempted but the FE macro "
2299 "manipulated the output arguments vector. It is illegal "
2300 "to add or remove output vector name/value pairs."
2302 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2309 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2311 if(i >= argsOut.size() -
2312 BUILT_IN_ARGOUT_COUNT &&
2313 argsOut[i].second == ARG_OUT_DEFAULT)
2328 std::stringstream outNumberSs;
2329 outNumberSs << std::dec << tmpNumber <<
" (0x" << std::hex << tmpNumber
2331 outputArgs += argsOut[i].first +
"," + outNumberSs.str();
2340 argsOut[i].first +
"," + StringMacros::encodeURIComponent(argsOut[i].second);
2343 __CFG_COUTT__ <<
"outputArgs = " << outputArgs << __E__;
2357 const std::string& supervisorLid)
2359 std::string retList =
"";
2361 __CFG_COUTV__(theFEInterfaces_.size());
2363 for(
const auto& it : theFEInterfaces_)
2365 __CFG_COUTT__ <<
"FE interface UID = " << it.first << __E__;
2367 retList += supervisorName +
";" + supervisorLid +
";" +
2368 it.second->getInterfaceType() +
";" + it.second->getInterfaceUID();
2370 for(
const auto& macroPair : it.second->getMapOfFEMacroFunctions())
2372 __CFG_COUTT__ <<
"FE Macro name = " << macroPair.first << __E__;
2374 ";" + macroPair.first +
";" + macroPair.second.requiredUserPermissions_;
2376 ";" + StringMacros::encodeURIComponent(macroPair.second.feMacroTooltip_);
2379 ";" + std::to_string(macroPair.second.namesOfInputArguments_.size());
2380 for(
const auto& name : macroPair.second.namesOfInputArguments_)
2381 retList +=
";" + StringMacros::encodeURIComponent(name);
2384 ";" + std::to_string(macroPair.second.namesOfOutputArguments_.size());
2385 for(
const auto& name : macroPair.second.namesOfOutputArguments_)
2386 retList +=
";" + StringMacros::encodeURIComponent(name);
2400 for(
const auto& FEInterface : theFEInterfaces_)
2402 isActive = FEInterface.second->WorkLoop::isActive();
2404 __CFG_COUT__ << FEInterface.second->getInterfaceUID() <<
" of type "
2405 << FEInterface.second->getInterfaceType() <<
": \t"
2406 <<
"workLoop_->isActive() " << (isActive ?
"yes" :
"no") << __E__;
2419 void FEVInterfacesManager::preStateMachineExecutionLoop(
void)
2421 VStateMachine::clearIterationWork();
2422 VStateMachine::clearSubIterationWork();
2424 stateMachinesIterationWorkCount_ = 0;
2426 __CFG_COUT__ <<
"Number of front ends to transition: " << theFENamesByPriority_.size()
2429 if(VStateMachine::getIterationIndex() == 0 &&
2430 VStateMachine::getSubIterationIndex() == 0)
2434 subIterationWorkStateMachineIndex_ = -1;
2436 stateMachinesIterationDone_.clear();
2437 for(
const auto& FEPair : theFEInterfaces_)
2438 stateMachinesIterationDone_[FEPair.first] =
false;
2441 __CFG_COUT__ <<
"Iteration " << VStateMachine::getIterationIndex() <<
"."
2442 << VStateMachine::getSubIterationIndex() <<
"("
2443 << (int)subIterationWorkStateMachineIndex_ <<
")" << __E__;
2447 void FEVInterfacesManager::preStateMachineExecution(
unsigned int i,
2448 const std::string& transitionName)
2450 if(i >= theFENamesByPriority_.size())
2452 __CFG_SS__ <<
"FE Interface " << i <<
" not found!" << __E__;
2456 const std::string& name = theFENamesByPriority_[i];
2460 fe->VStateMachine::setTransitionName(transitionName);
2461 fe->VStateMachine::setIterationIndex(VStateMachine::getIterationIndex());
2462 fe->VStateMachine::setSubIterationIndex(VStateMachine::getSubIterationIndex());
2464 fe->VStateMachine::clearIterationWork();
2465 fe->VStateMachine::clearSubIterationWork();
2467 __CFG_COUT__ <<
"theStateMachineImplementation Iteration "
2468 << fe->VStateMachine::getIterationIndex() <<
"."
2469 << fe->VStateMachine::getSubIterationIndex() << __E__;
2475 bool FEVInterfacesManager::postStateMachineExecution(
unsigned int i)
2477 if(i >= theFENamesByPriority_.size())
2479 __CFG_SS__ <<
"FE Interface index " << i <<
" not found!" << __E__;
2483 const std::string& name = theFENamesByPriority_[i];
2488 if(fe->VStateMachine::getSubIterationWork())
2490 subIterationWorkStateMachineIndex_ = i;
2491 VStateMachine::indicateSubIterationWork();
2493 __CFG_COUT__ <<
"FE Interface '" << name
2494 <<
"' is flagged for another sub-iteration..." << __E__;
2499 subIterationWorkStateMachineIndex_ = -1;
2501 bool& stateMachineDone = stateMachinesIterationDone_[name];
2502 stateMachineDone = !fe->VStateMachine::getIterationWork();
2504 if(!stateMachineDone)
2506 __CFG_COUT__ <<
"FE Interface '" << name
2507 <<
"' is flagged for another iteration..." << __E__;
2508 VStateMachine::indicateIterationWork();
2510 ++stateMachinesIterationWorkCount_;
2515 fe->VStateMachine::setTransitionName(
"");
2520 void FEVInterfacesManager::postStateMachineExecutionLoop(
void)
2522 if(VStateMachine::getSubIterationWork())
2523 __CFG_COUT__ <<
"FE Interface state machine implementation "
2524 << subIterationWorkStateMachineIndex_
2525 <<
" is flagged for another sub-iteration..." << __E__;
2526 else if(VStateMachine::getIterationWork())
2527 __CFG_COUT__ << stateMachinesIterationWorkCount_
2528 <<
" FE Interface state machine implementation(s) flagged for "
2529 "another iteration..."
2532 __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)