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]->setParentPointers(
122 __CFG_COUTV__(interface.first);
127 theFEInterfaces_[interface.first]->VStateMachine::parentSupervisor_);
128 __CFG_COUTTV__(theFEInterfaces_[interface.first]
129 ->VStateMachine::parentSupervisor_->getContextUID());
130 __CFG_COUTTV__(theFEInterfaces_[interface.first]
131 ->VStateMachine::parentSupervisor_->getSupervisorUID());
133 catch(
const cet::exception& e)
136 <<
"Failed to instantiate plugin named '" << interface.first
138 << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>()
139 <<
"' due to the following error: \n"
140 << e.what() << __E__;
141 __COUT_ERR__ << ss.str();
144 catch(
const std::runtime_error& e)
147 <<
"Failed to instantiate plugin named '" << interface.first
149 << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>()
150 <<
"' due to the following error: \n"
151 << e.what() << __E__;
152 __COUT_ERR__ << ss.str();
158 <<
"Failed to instantiate plugin named '" << interface.first
160 << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>()
161 <<
"' due to an unknown error." << __E__;
166 catch(
const std::exception& e)
168 ss <<
"Exception message: " << e.what();
173 __COUT_ERR__ << ss.str();
178 __CFG_COUT__ <<
"Done creating interfaces" << __E__;
188 std::string progress =
"";
189 unsigned int cnt = 0;
192 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
195 const std::string& name = theFENamesByPriority_[i];
198 if(feProgress.size())
200 ((cnt++) ?
"," :
"") + StringMacros::encodeURIComponent(feProgress);
215 const std::string transitionName =
"Configuring";
217 __CFG_COUT__ << transitionName <<
" FEVInterfacesManager " << __E__;
220 if(VStateMachine::getIterationIndex() == 0 &&
221 VStateMachine::getSubIterationIndex() == 0)
226 preStateMachineExecutionLoop();
227 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
230 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
231 i != subIterationWorkStateMachineIndex_)
234 const std::string& name = theFENamesByPriority_[i];
239 if(stateMachinesIterationDone_[name])
242 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
244 preStateMachineExecution(i, transitionName);
246 postStateMachineExecution(i);
249 if(!fe->VStateMachine::getSubIterationWork() &&
250 !fe->VStateMachine::getIterationWork())
255 fe->startSlowControlsWorkLoop();
257 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
260 postStateMachineExecutionLoop();
262 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
266 void FEVInterfacesManager::halt(
void)
268 const std::string transitionName =
"Halting";
271 preStateMachineExecutionLoop();
272 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
275 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
276 i != subIterationWorkStateMachineIndex_)
279 const std::string& name = theFENamesByPriority_[i];
283 if(stateMachinesIterationDone_[name])
286 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
287 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
288 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
290 preStateMachineExecution(i, transitionName);
300 <<
"An error occurred while halting the front-end workloop for '" << name
301 <<
",' ignoring." << __E__;
307 fe->stopSlowControlsWorkLoop();
311 __CFG_COUT_WARN__ <<
"An error occurred while halting the Slow Controls "
312 "front-end workloop for '"
313 << name <<
",' ignoring." << __E__;
323 __CFG_COUT_WARN__ <<
"An error occurred while halting the front-end '" << name
324 <<
",' ignoring." << __E__;
327 postStateMachineExecution(i);
329 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
330 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
331 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
333 postStateMachineExecutionLoop();
335 if(!VStateMachine::getSubIterationWork() && !VStateMachine::getIterationWork())
338 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
342 void FEVInterfacesManager::pause(
void)
344 const std::string transitionName =
"Pausing";
347 preStateMachineExecutionLoop();
348 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
351 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
352 i != subIterationWorkStateMachineIndex_)
355 const std::string& name = theFENamesByPriority_[i];
359 if(stateMachinesIterationDone_[name])
362 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
363 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
364 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
366 preStateMachineExecution(i, transitionName);
369 postStateMachineExecution(i);
371 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
372 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
373 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
375 postStateMachineExecutionLoop();
377 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
381 void FEVInterfacesManager::resume(
void)
383 const std::string transitionName =
"Resuming";
386 preStateMachineExecutionLoop();
387 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
390 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
391 i != subIterationWorkStateMachineIndex_)
394 const std::string& name = theFENamesByPriority_[i];
398 if(stateMachinesIterationDone_[name])
401 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
402 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
403 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
405 preStateMachineExecution(i, transitionName);
408 if(postStateMachineExecution(i))
411 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
412 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
413 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
415 postStateMachineExecutionLoop();
417 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
422 void FEVInterfacesManager::start(std::string runNumber)
424 const std::string transitionName =
"Starting";
427 preStateMachineExecutionLoop();
428 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
431 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
432 i != subIterationWorkStateMachineIndex_)
435 const std::string& name = theFENamesByPriority_[i];
439 if(stateMachinesIterationDone_[name])
442 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
443 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
444 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
446 preStateMachineExecution(i, transitionName);
447 fe->start(runNumber);
449 if(postStateMachineExecution(i))
452 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
453 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
454 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
456 postStateMachineExecutionLoop();
458 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
463 void FEVInterfacesManager::stop(
void)
465 const std::string transitionName =
"Starting";
468 preStateMachineExecutionLoop();
469 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
472 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
473 i != subIterationWorkStateMachineIndex_)
476 const std::string& name = theFENamesByPriority_[i];
480 if(stateMachinesIterationDone_[name])
483 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
484 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
485 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
487 preStateMachineExecution(i, transitionName);
490 postStateMachineExecution(i);
492 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
493 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
494 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
496 postStateMachineExecutionLoop();
498 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
508 return theFEInterfaces_.at(interfaceID).get();
512 __CFG_SS__ <<
"Interface ID '" << interfaceID
513 <<
"' not found in configured interfaces." << __E__;
521 const std::string& interfaceID)
const
525 return *(theFEInterfaces_.at(interfaceID));
529 __CFG_SS__ <<
"Interface ID '" << interfaceID
530 <<
"' not found in configured interfaces." << __E__;
550 const std::string& interfaceID)
559 const std::string& interfaceID)
581 std::string retList =
"";
583 for(
const auto& it : theFEInterfaces_)
585 __CFG_COUT__ <<
"FE name = " << it.first << __E__;
587 retList += it.second->getInterfaceType() +
":" + supervisorLid +
":" +
588 it.second->getInterfaceUID() +
"\n";
611 const std::string& interfaceID,
612 const std::string& macroName,
613 const std::string& macroString,
614 const bool enableSavingOutput,
615 const std::string& outputFilePath,
616 const std::string& outputFileRadix,
617 const std::string& inputArgs)
619 if(requester !=
"iterator")
621 __CFG_SS__ <<
"Invalid requester '" << requester <<
"'" << __E__;
625 __CFG_COUT__ <<
"Starting multi-dimensional Macro '" << macroName
626 <<
"' for interface '" << interfaceID <<
".'" << __E__;
628 __CFG_COUTV__(macroString);
630 __CFG_COUTV__(inputArgs);
636 if(macroMultiDimensionalStatusMap_.find(interfaceID) !=
637 macroMultiDimensionalStatusMap_.end())
639 __SS__ <<
"Failed to start multi-dimensional Macro '" << macroName
640 <<
"' for interface '" << interfaceID
641 <<
"' - this interface already has an active Macro launch!" << __E__;
644 macroMultiDimensionalStatusMap_.emplace(std::make_pair(interfaceID,
"Active"));
650 const std::string interfaceID,
651 const std::string macroName,
652 const std::string macroString,
653 const bool enableSavingOutput,
654 const std::string outputFilePath,
655 const std::string outputFileRadix,
656 const std::string inputArgsStr) {
658 std::string mfSubject_ =
"threadMultiD-" + macroName;
659 __GEN_COUT__ <<
"Thread started." << __E__;
661 std::string statusResult =
"Done";
675 FILE* outputFilePointer = 0;
676 if(enableSavingOutput)
678 std::string filename = outputFilePath +
"/" + outputFileRadix +
679 macroName +
"_" + std::to_string(time(0)) +
681 __GEN_COUT__ <<
"Opening file... " << filename << __E__;
683 outputFilePointer = fopen(filename.c_str(),
"w");
684 if(!outputFilePointer)
686 __GEN_SS__ <<
"Failed to open output file: " << filename << __E__;
693 __GEN_COUTV__(inputArgsStr);
713 std::vector<
unsigned long > dimensionIterations,
714 dimensionIterationCnt;
716 using longParamMap_t = std::map<
719 std::pair<
long ,
long >>>;
721 std::vector<longParamMap_t> longDimensionParameters;
726 std::map<std::string , uint64_t > variableMap;
731 for(
const auto& inputArgName : macro.namesOfInputArguments_)
733 std::pair<std::string /*name*/, uint64_t /*value*/>(inputArgName,
735 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
737 std::pair<std::string /*name*/, uint64_t /*value*/>(outputArgName,
744 dimensionIterations.push_back(2);
745 dimensionIterations.push_back(4);
747 longDimensionParameters.push_back(longParamMap_t());
748 longDimensionParameters.push_back(longParamMap_t());
750 longDimensionParameters.back().emplace(std::make_pair(
754 std::make_pair(3 , 4 ))));
757 std::vector<std::string> dimensionArgs;
759 inputArgsStr, dimensionArgs, {
';'} );
761 __GEN_COUTV__(dimensionArgs.size());
764 if(dimensionArgs.size() == 0)
769 dimensionIterations.push_back(1);
770 longDimensionParameters.push_back(longParamMap_t());
773 for(
unsigned int d = 0; d < dimensionArgs.size(); ++d)
778 std::vector<std::string> args;
780 dimensionArgs[d], args, {
','} );
788 __GEN_SS__ <<
"Invalid dimensional arguments! "
789 <<
"Need number of iterations at dimension " << d
794 unsigned long numOfIterations;
796 __GEN_COUT__ <<
"Dimension " << d
797 <<
" numOfIterations=" << numOfIterations << __E__;
801 dimensionIterations.push_back(numOfIterations);
802 longDimensionParameters.push_back(longParamMap_t());
806 for(
unsigned int a = 1; a < args.size(); ++a)
808 std::vector<std::string> argPieces;
810 args[a], argPieces, {
':'} );
816 if(argPieces.size() != 3)
818 __GEN_SS__ <<
"Invalid argument pieces! Should be size "
820 << argPieces.size() << __E__;
827 if((argPieces[1].size() &&
828 (argPieces[1][argPieces[1].size() - 1] ==
'f' ||
829 argPieces[1].find(
'.') != std::string::npos)) ||
830 (argPieces[2].size() &&
831 (argPieces[2][argPieces[2].size() - 1] ==
'f' ||
832 argPieces[2].find(
'.') != std::string::npos)))
836 double startValue = strtod(argPieces[1].c_str(), 0);
837 double stepSize = strtod(argPieces[2].c_str(), 0);
839 __GEN_COUTV__(startValue);
840 __GEN_COUTV__(stepSize);
843 <<
"Error! Only integer aruments allowed for Macros. "
844 <<
"Double style arugment found: " << argPieces[0]
845 <<
"' := " << startValue <<
", " << stepSize << __E__;
869 __GEN_COUTV__(startValue);
870 __GEN_COUTV__(stepSize);
872 __GEN_COUT__ <<
"Creating long argument '" << argPieces[0]
873 <<
"' := " << startValue <<
", " << stepSize
876 longDimensionParameters.back().emplace(std::make_pair(
880 std::make_pair(startValue ,
888 if(dimensionIterations.size() != longDimensionParameters.size())
890 __GEN_SS__ <<
"Impossible vector size mismatch! "
891 << dimensionIterations.size() <<
" - "
892 << longDimensionParameters.size() << __E__;
898 std::stringstream outSS;
900 outSS <<
"\n==========================\n" << __E__;
901 outSS <<
"Macro '" << macro.macroName_
902 <<
"' multi-dimensional scan..." << __E__;
904 outSS <<
"\t" << dimensionIterations.size()
905 <<
" dimensions defined." << __E__;
906 for(
unsigned int i = 0; i < dimensionIterations.size(); ++i)
909 <<
"dimension[" << i <<
"] has "
910 << dimensionIterations[i] <<
" iterations and "
911 << (longDimensionParameters[i].size()) <<
" arguments."
914 for(
auto& param : longDimensionParameters[i])
916 <<
"'" << param.first <<
"' of type long with "
917 <<
"initial value and step value [decimal] = "
918 <<
"\t" << param.second.second.first <<
" & "
919 << param.second.second.second << __E__;
922 outSS <<
"\nInput argument names:" << __E__;
923 for(
const auto& inputArgName : macro.namesOfInputArguments_)
924 outSS <<
"\t" << inputArgName << __E__;
925 outSS <<
"\nOutput argument names:" << __E__;
926 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
927 outSS <<
"\t" << outputArgName << __E__;
929 outSS <<
"\n==========================\n" << __E__;
933 __GEN_COUT__ <<
"\n" << outSS.str();
934 if(outputFilePointer)
935 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
938 unsigned int iterationCount = 0;
946 std::function<void(
const unsigned int
948 localRecurse = [&dimensionIterations,
949 &dimensionIterationCnt,
951 &longDimensionParameters,
956 &localRecurse](
const unsigned int dimension) {
958 std::string mfSubject_ =
"multiD-" + std::to_string(dimension) +
959 "-" + macro.macroName_;
960 __GEN_COUTV__(dimension);
962 if(dimension >= dimensionIterations.size())
964 __GEN_COUT__ <<
"Iteration count: " << iterationCount++
966 __GEN_COUT__ <<
"Launching Macro '" << macro.macroName_
977 for(
unsigned int j = 0; j < dimensionIterations.size();
980 for(
auto& longParam : longDimensionParameters[j])
983 <<
"Assigning argIn '" << longParam.first
984 <<
"' to current long value '"
985 << longParam.second.first
986 <<
"' from dimension " << j <<
" parameter."
988 variableMap.at(longParam.first) =
989 longParam.second.first;
997 std::stringstream outSS;
999 outSS <<
"\n---------------\n" << __E__;
1000 outSS <<
"Macro '" << macro.macroName_
1001 <<
"' execution..." << __E__;
1003 <<
"iteration " << iterationCount << __E__;
1004 for(
unsigned int i = 0;
1005 i < dimensionIterationCnt.size();
1008 <<
"dimension[" << i
1009 <<
"] index := " << dimensionIterationCnt[i]
1014 <<
"Input arguments (count: "
1015 << macro.namesOfInputArguments_.size()
1017 for(
auto& argIn : macro.namesOfInputArguments_)
1018 outSS <<
"\t\t" << argIn <<
" = "
1019 << variableMap.at(argIn) << __E__;
1024 __GEN_COUT__ <<
"\n" << outSS.str();
1025 if(outputFilePointer)
1026 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1032 __GEN_COUT__ <<
"Macro complete!" << __E__;
1036 std::stringstream outSS;
1040 <<
"Output arguments (count: "
1041 << macro.namesOfOutputArguments_.size()
1043 for(
auto& argOut : macro.namesOfOutputArguments_)
1044 outSS <<
"\t\t" << argOut <<
" = "
1045 << variableMap.at(argOut) << __E__;
1049 __GEN_COUT__ <<
"\n" << outSS.str();
1050 if(outputFilePointer)
1051 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1058 if(dimension >= dimensionIterationCnt.size())
1059 dimensionIterationCnt.push_back(0);
1062 __GEN_COUT__ <<
"\n"
1063 <<
"======================================" << __E__
1064 <<
"dimension[" << dimension
1065 <<
"] number of iterations := "
1066 << dimensionIterations[dimension] << __E__;
1070 for(
auto& longPair : longDimensionParameters[dimension])
1072 longPair.second.first =
1073 longPair.second.second.first;
1075 <<
"arg '" << longPair.first
1076 <<
"' current value: " << longPair.second.first
1082 for(dimensionIterationCnt[dimension] =
1084 dimensionIterationCnt[dimension] <
1085 dimensionIterations[dimension];
1086 ++dimensionIterationCnt[dimension])
1088 __GEN_COUT__ <<
"dimension[" << dimension <<
"] index := "
1089 << dimensionIterationCnt[dimension] << __E__;
1091 localRecurse(dimension + 1);
1095 for(
auto& longPair : longDimensionParameters[dimension])
1097 longPair.second.first +=
1098 longPair.second.second.second;
1100 <<
"arg '" << longPair.first
1101 <<
"' current value: " << longPair.second.first
1107 __GEN_COUT__ <<
"Completed dimension[" << dimension
1108 <<
"] number of iterations := "
1109 << dimensionIterationCnt[dimension] <<
" of "
1110 << dimensionIterations[dimension] << __E__;
1117 if(outputFilePointer)
1118 fclose(outputFilePointer);
1120 catch(
const std::runtime_error& e)
1122 __SS__ <<
"Error executing multi-dimensional Macro: " << e.what()
1124 statusResult = ss.str();
1128 __SS__ <<
"Unknown error executing multi-dimensional Macro. " << __E__;
1133 catch(
const std::exception& e)
1135 ss <<
"Exception message: " << e.what();
1140 statusResult = ss.str();
1143 __COUTV__(statusResult);
1148 feMgr->macroMultiDimensionalStatusMap_[interfaceID] = statusResult;
1161 __CFG_COUT__ <<
"Started multi-dimensional Macro '" << macroName
1162 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1184 const std::string& requester,
1185 const std::string& interfaceID,
1186 const std::string& feMacroName,
1187 const bool enableSavingOutput,
1188 const std::string& outputFilePath,
1189 const std::string& outputFileRadix,
1190 const std::string& inputArgs)
1192 if(requester !=
"iterator")
1194 __CFG_SS__ <<
"Invalid requester '" << requester <<
"'" << __E__;
1198 __CFG_COUT__ <<
"Starting multi-dimensional FE Macro '" << feMacroName
1199 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1200 __CFG_COUTV__(inputArgs);
1206 if(macroMultiDimensionalStatusMap_.find(interfaceID) !=
1207 macroMultiDimensionalStatusMap_.end())
1209 __SS__ <<
"Failed to start multi-dimensional FE Macro '" << feMacroName
1210 <<
"' for interface '" << interfaceID
1211 <<
"' - this interface already has an active FE Macro launch!"
1215 macroMultiDimensionalStatusMap_.emplace(std::make_pair(interfaceID,
"Active"));
1221 const std::string interfaceID,
1222 const std::string feMacroName,
1223 const bool enableSavingOutput,
1224 const std::string outputFilePath,
1225 const std::string outputFileRadix,
1226 const std::string inputArgsStr) {
1228 std::string mfSubject_ =
"threadMultiD-" + feMacroName;
1229 __GEN_COUT__ <<
"Thread started." << __E__;
1231 std::string statusResult =
"Done";
1240 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1241 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1243 __GEN_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '"
1244 << interfaceID <<
"' was not found!" << __E__;
1251 FILE* outputFilePointer = 0;
1252 if(enableSavingOutput)
1254 std::string filename = outputFilePath +
"/" + outputFileRadix +
1255 feMacroName +
"_" + std::to_string(time(0)) +
1257 __GEN_COUT__ <<
"Opening file... " << filename << __E__;
1259 outputFilePointer = fopen(filename.c_str(),
"w");
1260 if(!outputFilePointer)
1262 __GEN_SS__ <<
"Failed to open output file: " << filename << __E__;
1269 __GEN_COUTV__(inputArgsStr);
1289 std::vector<
unsigned long > dimensionIterations,
1290 dimensionIterationCnt;
1292 using longParamMap_t = std::map<
1295 std::pair<
long ,
long >>>;
1296 using doubleParamMap_t =
1297 std::map<std::string ,
1301 using stringParamMap_t =
1302 std::map<std::string , std::string >;
1304 std::vector<longParamMap_t> longDimensionParameters;
1305 std::vector<doubleParamMap_t> doubleDimensionParameters;
1306 std::vector<stringParamMap_t> stringDimensionParameters;
1308 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
1309 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
1311 for(
unsigned int i = 0; i < feMacro.namesOfInputArguments_.size(); ++i)
1312 argsIn.push_back(std::make_pair(
1313 feMacro.namesOfInputArguments_[i],
1315 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1318 feMacro.namesOfOutputArguments_[i],
1325 argsIn.push_back(std::make_pair(
"myOtherArg",
"3"));
1327 dimensionIterations.push_back(2);
1328 dimensionIterations.push_back(4);
1330 longDimensionParameters.push_back(longParamMap_t());
1331 longDimensionParameters.push_back(longParamMap_t());
1333 doubleDimensionParameters.push_back(doubleParamMap_t());
1334 doubleDimensionParameters.push_back(doubleParamMap_t());
1336 longDimensionParameters.back().emplace(std::make_pair(
1340 std::make_pair(3 , 4 ))));
1343 std::vector<std::string> dimensionArgs;
1345 inputArgsStr, dimensionArgs, {
';'} );
1347 __GEN_COUTV__(dimensionArgs.size());
1350 if(dimensionArgs.size() == 0)
1355 dimensionIterations.push_back(1);
1356 longDimensionParameters.push_back(longParamMap_t());
1357 doubleDimensionParameters.push_back(doubleParamMap_t());
1358 stringDimensionParameters.push_back(stringParamMap_t());
1361 for(
unsigned int d = 0; d < dimensionArgs.size(); ++d)
1366 std::vector<std::string> args;
1368 dimensionArgs[d], args, {
','} );
1374 if(args.size() == 0)
1376 __GEN_SS__ <<
"Invalid dimensional arguments! "
1377 <<
"Need number of iterations at dimension " << d
1382 unsigned long numOfIterations;
1384 __GEN_COUT__ <<
"Dimension " << d
1385 <<
" numOfIterations=" << numOfIterations << __E__;
1389 dimensionIterations.push_back(numOfIterations);
1390 longDimensionParameters.push_back(longParamMap_t());
1391 doubleDimensionParameters.push_back(doubleParamMap_t());
1392 stringDimensionParameters.push_back(stringParamMap_t());
1396 for(
unsigned int a = 1; a < args.size(); ++a)
1398 std::vector<std::string> argPieces;
1400 args[a], argPieces, {
':'} );
1406 if(argPieces.size() != 3)
1408 __GEN_SS__ <<
"Invalid argument pieces! Should be size "
1410 << argPieces.size() << __E__;
1418 TableViewColumnInfo::DATATYPE_STRING_DEFAULT ||
1420 TableViewColumnInfo::DATATYPE_STRING_ALT_DEFAULT)
1424 __GEN_COUT__ <<
"Creating string argument '"
1425 << argPieces[0] <<
"' := " << argPieces[1]
1428 stringDimensionParameters.back().emplace(
1429 std::make_pair(argPieces[0], argPieces[1]));
1431 else if((argPieces[1].size() &&
1432 (argPieces[1][argPieces[1].size() - 1] ==
'f' ||
1433 argPieces[1].find(
'.') != std::string::npos)) ||
1434 (argPieces[2].size() &&
1435 (argPieces[2][argPieces[2].size() - 1] ==
'f' ||
1436 argPieces[2].find(
'.') != std::string::npos)))
1441 double startValue = strtod(argPieces[1].c_str(), 0);
1442 double stepSize = strtod(argPieces[2].c_str(), 0);
1444 __GEN_COUTV__(startValue);
1445 __GEN_COUTV__(stepSize);
1447 __GEN_COUT__ <<
"Creating double argument '"
1448 << argPieces[0] <<
"' := " << startValue
1449 <<
", " << stepSize << __E__;
1451 doubleDimensionParameters.back().emplace(std::make_pair(
1455 std::make_pair(startValue ,
1463 long int startValue;
1469 __GEN_COUTV__(startValue);
1470 __GEN_COUTV__(stepSize);
1472 __GEN_COUT__ <<
"Creating long argument '" << argPieces[0]
1473 <<
"' := " << startValue <<
", " << stepSize
1476 longDimensionParameters.back().emplace(std::make_pair(
1480 std::make_pair(startValue ,
1488 if(dimensionIterations.size() != longDimensionParameters.size() ||
1489 dimensionIterations.size() != doubleDimensionParameters.size() ||
1490 dimensionIterations.size() != stringDimensionParameters.size())
1492 __GEN_SS__ <<
"Impossible vector size mismatch! "
1493 << dimensionIterations.size() <<
" - "
1494 << longDimensionParameters.size() <<
" - "
1495 << doubleDimensionParameters.size() <<
" - "
1496 << stringDimensionParameters.size() << __E__;
1502 std::stringstream outSS;
1504 outSS <<
"\n==========================\n" << __E__;
1505 outSS <<
"FEMacro '" << feMacro.feMacroName_
1506 <<
"' multi-dimensional scan..." << __E__;
1508 outSS <<
"\t" << dimensionIterations.size()
1509 <<
" dimensions defined." << __E__;
1510 for(
unsigned int i = 0; i < dimensionIterations.size(); ++i)
1513 <<
"dimension[" << i <<
"] has "
1514 << dimensionIterations[i] <<
" iterations and "
1515 << (longDimensionParameters[i].size() +
1516 doubleDimensionParameters[i].size() +
1517 stringDimensionParameters[i].size())
1518 <<
" arguments." << __E__;
1520 for(
auto& param : longDimensionParameters[i])
1522 <<
"'" << param.first <<
"' of type long with "
1523 <<
"initial value and step value [decimal] = "
1524 <<
"\t" << param.second.second.first <<
" & "
1525 << param.second.second.second << __E__;
1527 for(
auto& param : doubleDimensionParameters[i])
1529 <<
"'" << param.first <<
"' of type double with "
1530 <<
"initial value and step value = "
1531 <<
"\t" << param.second.second.first <<
" & "
1532 << param.second.second.second << __E__;
1534 for(
auto& param : stringDimensionParameters[i])
1536 <<
"'" << param.first <<
"' of type string with "
1538 <<
"\t" << param.second << __E__;
1541 outSS <<
"\nHere are the identified input arguments:" << __E__;
1542 for(
unsigned int i = 0; i < feMacro.namesOfInputArguments_.size();
1544 outSS <<
"\t" << feMacro.namesOfInputArguments_[i] << __E__;
1545 outSS <<
"\nHere are the identified input arguments:" << __E__;
1546 for(
unsigned int i = 0;
1547 i < feMacro.namesOfOutputArguments_.size();
1549 outSS <<
"\t" << feMacro.namesOfOutputArguments_[i] << __E__;
1551 outSS <<
"\n==========================\n" << __E__;
1555 __GEN_COUT__ <<
"\n" << outSS.str();
1556 if(outputFilePointer)
1557 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1560 unsigned int iterationCount = 0;
1568 std::function<void(
const unsigned int
1570 localRecurse = [&dimensionIterations,
1571 &dimensionIterationCnt,
1573 &longDimensionParameters,
1574 &doubleDimensionParameters,
1575 &stringDimensionParameters,
1581 &localRecurse](
const unsigned int dimension) {
1583 std::string mfSubject_ =
"multiD-" + std::to_string(dimension) +
1584 "-" + feMacro.feMacroName_;
1585 __GEN_COUTV__(dimension);
1587 if(dimension >= dimensionIterations.size())
1589 __GEN_COUT__ <<
"Iteration count: " << iterationCount++
1591 __GEN_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_
1592 <<
"' ..." << __E__;
1603 for(
unsigned int i = 0; i < argsIn.size(); ++i)
1605 foundAsLong =
false;
1606 for(
unsigned int j = 0; j < dimensionIterations.size();
1610 longDimensionParameters[j].find(argsIn[i].first);
1611 if(longIt == longDimensionParameters[j].end())
1615 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1616 <<
"' to current long value '"
1617 << longIt->second.first
1618 <<
"' from dimension " << j
1619 <<
" parameter." << __E__;
1621 std::to_string(longIt->second.first);
1631 for(
unsigned int j = 0; j < dimensionIterations.size();
1634 auto doubleIt = doubleDimensionParameters[j].find(
1636 if(doubleIt == doubleDimensionParameters[j].end())
1640 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1641 <<
"' to current double value '"
1642 << doubleIt->second.first
1643 <<
"' from dimension " << j
1644 <<
" parameter." << __E__;
1646 std::to_string(doubleIt->second.first);
1656 for(
unsigned int j = 0; j < dimensionIterations.size();
1659 auto stringIt = stringDimensionParameters[j].find(
1661 if(stringIt == stringDimensionParameters[j].end())
1665 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1666 <<
"' to current string value '"
1668 <<
"' from dimension " << j
1669 <<
" parameter." << __E__;
1670 argsIn[i].second = stringIt->second;
1680 __GEN_SS__ <<
"ArgIn '" << argsIn[i].first
1681 <<
"' was not assigned a value "
1682 <<
"by any dimensional loop parameter sets. "
1683 "This is illegal. FEMacro '"
1684 << feMacro.feMacroName_ <<
"' requires '"
1686 <<
"' as an input argument. Either remove the "
1687 "input argument from this FEMacro, "
1688 <<
"or define a value as a dimensional loop "
1695 (fe->*(feMacro.macroFunction_))(feMacro, argsIn, argsOut);
1697 __GEN_COUT__ <<
"FE Macro complete!" << __E__;
1701 std::stringstream outSS;
1703 outSS <<
"\n---------------\n" << __E__;
1704 outSS <<
"FEMacro '" << feMacro.feMacroName_
1705 <<
"' execution..." << __E__;
1707 <<
"iteration " << iterationCount << __E__;
1708 for(
unsigned int i = 0;
1709 i < dimensionIterationCnt.size();
1712 <<
"dimension[" << i
1713 <<
"] index := " << dimensionIterationCnt[i]
1718 <<
"Input arguments (count: " << argsIn.size()
1720 for(
auto& argIn : argsIn)
1721 outSS <<
"\t\t" << argIn.first <<
" = "
1722 << argIn.second << __E__;
1726 <<
"Output arguments (count: " << argsOut.size()
1728 for(
auto& argOut : argsOut)
1729 outSS <<
"\t\t" << argOut.first <<
" = "
1730 << argOut.second << __E__;
1734 __GEN_COUT__ <<
"\n" << outSS.str();
1735 if(outputFilePointer)
1736 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1743 if(dimension >= dimensionIterationCnt.size())
1744 dimensionIterationCnt.push_back(0);
1747 __GEN_COUT__ <<
"\n"
1748 <<
"======================================" << __E__
1749 <<
"dimension[" << dimension
1750 <<
"] number of iterations := "
1751 << dimensionIterations[dimension] << __E__;
1756 for(
auto& longPair : longDimensionParameters[dimension])
1758 longPair.second.first =
1759 longPair.second.second.first;
1761 <<
"arg '" << longPair.first
1762 <<
"' current value: " << longPair.second.first
1766 for(
auto& doublePair : doubleDimensionParameters[dimension])
1768 doublePair.second.first =
1769 doublePair.second.second.first;
1771 <<
"arg '" << doublePair.first
1772 <<
"' current value: " << doublePair.second.first
1778 for(dimensionIterationCnt[dimension] =
1780 dimensionIterationCnt[dimension] <
1781 dimensionIterations[dimension];
1782 ++dimensionIterationCnt[dimension])
1784 __GEN_COUT__ <<
"dimension[" << dimension <<
"] index := "
1785 << dimensionIterationCnt[dimension] << __E__;
1787 localRecurse(dimension + 1);
1792 for(
auto& longPair : longDimensionParameters[dimension])
1794 longPair.second.first +=
1795 longPair.second.second.second;
1797 <<
"arg '" << longPair.first
1798 <<
"' current value: " << longPair.second.first
1802 for(
auto& doublePair :
1803 doubleDimensionParameters[dimension])
1805 doublePair.second.first +=
1806 doublePair.second.second.second;
1809 <<
"arg '" << doublePair.first
1810 <<
"' current value: " << doublePair.second.first
1816 __GEN_COUT__ <<
"Completed dimension[" << dimension
1817 <<
"] number of iterations := "
1818 << dimensionIterationCnt[dimension] <<
" of "
1819 << dimensionIterations[dimension] << __E__;
1826 if(outputFilePointer)
1827 fclose(outputFilePointer);
1829 catch(
const std::runtime_error& e)
1831 __SS__ <<
"Error executing multi-dimensional FE Macro: " << e.what()
1833 statusResult = ss.str();
1837 __SS__ <<
"Unknown error executing multi-dimensional FE Macro. " << __E__;
1842 catch(
const std::exception& e)
1844 ss <<
"Exception message: " << e.what();
1849 statusResult = ss.str();
1852 __COUTV__(statusResult);
1857 feMgr->macroMultiDimensionalStatusMap_[interfaceID] = statusResult;
1869 __CFG_COUT__ <<
"Started multi-dimensional FE Macro '" << feMacroName
1870 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1881 bool FEVInterfacesManager::checkMacroMultiDimensional(
const std::string& interfaceID,
1882 const std::string& macroName)
1888 auto statusIt = macroMultiDimensionalStatusMap_.find(interfaceID);
1889 if(statusIt == macroMultiDimensionalStatusMap_.end())
1891 __CFG_SS__ <<
"Status missing for multi-dimensional launch of Macro '"
1892 << macroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
1895 else if(statusIt->second ==
"Done")
1897 __CFG_COUT__ <<
"Completed multi-dimensional launch of Macro '" << macroName
1898 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1901 macroMultiDimensionalStatusMap_.erase(statusIt);
1904 else if(statusIt->second ==
"Active")
1906 __CFG_COUT__ <<
"Still running multi-dimensional launch of Macro '" << macroName
1907 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1912 __CFG_SS__ <<
"Error occured during multi-dimensional launch of Macro '" << macroName
1913 <<
"' for interface '" << interfaceID <<
"':" << statusIt->second << __E__;
1931 const std::string& interfaceID,
1932 const std::string& feMacroName,
1933 const std::string& inputArgs,
1934 std::string& outputArgs)
1936 __CFG_COUTV__(callingInterfaceID);
1942 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1943 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1945 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID
1946 <<
"' was not found!" << __E__;
1947 ss <<
"\nHere is the list of available FE Macros:\n";
1948 for(
const auto& feMacro : fe->getMapOfFEMacroFunctions())
1949 ss << feMacro.first <<
"... ";
1951 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1957 std::set<std::string> allowedFEsSet;
1963 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID
1964 <<
"' does not allow access to calling interfaceID '"
1965 << callingInterfaceID
1966 <<
"!' Did the interface add the calling interfaceID "
1967 <<
"to the access list when registering the front-end macro." << __E__;
1968 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1977 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1978 outputArgs += (i ?
"," :
"") + feMacro.namesOfOutputArguments_[i];
1980 __CFG_COUTV__(outputArgs);
1982 runFEMacro(interfaceID, feMacro, inputArgs, outputArgs);
1984 __CFG_COUTV__(outputArgs);
2000 const std::string& macroObjectString,
2001 const std::string& inputArgs,
2002 std::string& outputArgs)
2013 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
2015 std::istringstream inputStream(inputArgs);
2016 std::string splitVal, argName, argValue;
2017 while(getline(inputStream, splitVal,
';'))
2019 std::istringstream pairInputStream(splitVal);
2020 getline(pairInputStream, argName,
',');
2021 getline(pairInputStream, argValue,
',');
2022 argsIn.push_back(std::make_pair(argName, argValue));
2027 if(macro.namesOfInputArguments_.size() != argsIn.size())
2029 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2030 <<
"' was attempted on interfaceID '" << interfaceID
2031 <<
"' with a mismatch in"
2032 <<
" number of input arguments. " << argsIn.size() <<
" were given. "
2033 << macro.namesOfInputArguments_.size() <<
" expected." << __E__;
2036 for(
unsigned int i = 0; i < argsIn.size(); ++i)
2037 if(macro.namesOfInputArguments_.find(argsIn[i].first) ==
2038 macro.namesOfInputArguments_.end())
2040 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2041 <<
"' was attempted on interfaceID '" << interfaceID
2042 <<
"' with a mismatch in"
2043 <<
" a name of an input argument. " << argsIn[i].first
2044 <<
" was given. Expected: "
2052 std::vector<std::string> returnStrings;
2053 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
2056 std::istringstream inputStream(outputArgs);
2057 std::string argName;
2058 while(getline(inputStream, argName,
','))
2060 __CFG_COUT__ <<
"argName " << argName << __E__;
2062 returnStrings.push_back(
"DEFAULT");
2063 argsOut.push_back(FEVInterface::frontEndMacroArg_t(
2064 argName, returnStrings[returnStrings.size() - 1]));
2073 if(macro.namesOfOutputArguments_.size() != argsOut.size())
2075 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2076 <<
"' was attempted on interfaceID '" << interfaceID
2077 <<
"' with a mismatch in"
2078 <<
" number of output arguments. " << argsOut.size() <<
" were given. "
2079 << macro.namesOfOutputArguments_.size() <<
" expected." << __E__;
2083 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2084 if(macro.namesOfOutputArguments_.find(argsOut[i].first) ==
2085 macro.namesOfOutputArguments_.end())
2087 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2088 <<
"' was attempted on interfaceID '" << interfaceID
2089 <<
"' with a mismatch in"
2090 <<
" a name of an output argument. " << argsOut[i].first
2091 <<
" were given. Expected: "
2098 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
2100 std::map<std::string , uint64_t > variableMap;
2102 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
2103 variableMap.emplace(
2104 std::pair<std::string /*name*/, uint64_t /*value*/>(outputArgName, 0));
2105 for(
const auto& inputArgName : macro.namesOfInputArguments_)
2106 variableMap.emplace(
2107 std::pair<std::string /*name*/, uint64_t /*value*/>(inputArgName, 0));
2109 for(
auto& argIn : argsIn)
2111 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
2117 __CFG_COUT__ <<
"MacroMaker Macro complete!" << __E__;
2119 __CFG_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
2120 for(
auto& arg : argsOut)
2122 std::stringstream numberSs;
2123 numberSs << std::dec << variableMap.at(arg.first) <<
" (0x" << std::hex
2124 << variableMap.at(arg.first) <<
")" << std::dec;
2125 arg.second = numberSs.str();
2126 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
2131 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2135 outputArgs += argsOut[i].first +
"," + argsOut[i].second;
2138 __CFG_COUT__ <<
"outputArgs = " << outputArgs << __E__;
2154 const std::string& feMacroName,
2155 const std::string& inputArgs,
2156 std::string& outputArgs)
2162 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
2163 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
2165 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID
2166 <<
"' was not found!" << __E__;
2167 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2171 runFEMacro(interfaceID, FEMacroIt->second, inputArgs, outputArgs);
2188 const std::string& inputArgs,
2189 std::string& outputArgs)
2191 __CFG_COUTV__(inputArgs);
2195 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
2197 std::istringstream inputStream(inputArgs);
2198 std::string splitVal, argName, argValue;
2199 while(getline(inputStream, splitVal,
';'))
2201 std::istringstream pairInputStream(splitVal);
2202 getline(pairInputStream, argName,
',');
2203 getline(pairInputStream, argValue,
',');
2210 if(feMacro.namesOfInputArguments_.size() != argsIn.size())
2212 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2213 << interfaceID <<
"' was attempted with a mismatch in"
2214 <<
" number of input arguments. " << argsIn.size() <<
" were given. "
2215 << feMacro.namesOfInputArguments_.size() <<
" expected." << __E__;
2216 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2220 for(
unsigned int i = 0; i < argsIn.size(); ++i)
2221 if(argsIn[i].first.substr(0, argsIn[i].first.find(
'(')) !=
2222 feMacro.namesOfInputArguments_[i].substr(
2223 0, feMacro.namesOfInputArguments_[i].find(
'(')))
2225 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2226 << interfaceID <<
"' was attempted with a mismatch in"
2227 <<
" a name of an input argument. '" << argsIn[i].first
2228 <<
"' was given. '" << feMacro.namesOfInputArguments_[i]
2229 <<
"' expected." << __E__;
2230 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2235 std::vector<std::string> returnStrings;
2236 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
2238 const std::string ARG_OUT_DEFAULT =
"DEFAULT";
2241 std::istringstream inputStream(outputArgs);
2242 std::string argName;
2243 while(getline(inputStream, argName,
','))
2245 __CFG_COUTT__ <<
"argName " << argName << __E__;
2247 returnStrings.push_back(ARG_OUT_DEFAULT);
2248 argsOut.push_back(FEVInterface::frontEndMacroArg_t(
2250 returnStrings[returnStrings.size() - 1]));
2253 __CFG_COUTT__ << (uint64_t) & (returnStrings[returnStrings.size() - 1])
2259 if(feMacro.namesOfOutputArguments_.size() != argsOut.size())
2261 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2262 << interfaceID <<
"' was attempted with a mismatch in"
2263 <<
" number of output arguments. " << argsOut.size() <<
" were given. "
2264 << feMacro.namesOfOutputArguments_.size() <<
" expected." << __E__;
2265 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2268 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2269 if(argsOut[i].first != feMacro.namesOfOutputArguments_[i])
2271 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2272 << interfaceID <<
"' was attempted with a mismatch in"
2273 <<
" a name of an output argument. " << argsOut[i].first
2274 <<
" were given. " << feMacro.namesOfOutputArguments_[i]
2275 <<
" expected." << __E__;
2276 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2281 const uint16_t BUILT_IN_ARGOUT_COUNT = 1;
2283 returnStrings.push_back(ARG_OUT_DEFAULT);
2284 argsOut.push_back(FEVInterface::frontEndMacroArg_t(
2285 PLOTLY_PLOT, returnStrings[returnStrings.size() - 1]));
2288 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
2289 for(
auto& argIn : argsIn)
2290 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
2292 __CFG_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_ <<
"' ..." << __E__;
2296 __CFG_COUT__ <<
"FE Macro complete!" << __E__;
2298 __CFG_COUT__ <<
"# of output args = " << argsOut.size() <<
" including "
2299 << BUILT_IN_ARGOUT_COUNT <<
" built-in args." << __E__;
2300 for(
const auto& arg : argsOut)
2301 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
2304 if(feMacro.namesOfOutputArguments_.size() != argsOut.size() - BUILT_IN_ARGOUT_COUNT)
2306 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2308 <<
"' was attempted but the FE macro "
2309 "manipulated the output arguments vector. It is illegal "
2310 "to add or remove output vector name/value pairs."
2312 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2319 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2321 if(i >= argsOut.size() -
2322 BUILT_IN_ARGOUT_COUNT &&
2323 argsOut[i].second == ARG_OUT_DEFAULT)
2338 std::stringstream outNumberSs;
2339 outNumberSs << std::dec << tmpNumber <<
" (0x" << std::hex << tmpNumber
2341 outputArgs += argsOut[i].first +
"," + outNumberSs.str();
2350 argsOut[i].first +
"," + StringMacros::encodeURIComponent(argsOut[i].second);
2353 __CFG_COUTT__ <<
"outputArgs = " << outputArgs << __E__;
2367 const std::string& supervisorLid)
2369 std::string retList =
"";
2371 __CFG_COUTV__(theFEInterfaces_.size());
2373 for(
const auto& it : theFEInterfaces_)
2375 __CFG_COUTT__ <<
"FE interface UID = " << it.first << __E__;
2377 retList += supervisorName +
";" + supervisorLid +
";" +
2378 it.second->getInterfaceType() +
";" + it.second->getInterfaceUID();
2380 for(
const auto& macroPair : it.second->getMapOfFEMacroFunctions())
2382 __CFG_COUTT__ <<
"FE Macro name = " << macroPair.first << __E__;
2384 ";" + macroPair.first +
";" + macroPair.second.requiredUserPermissions_;
2386 ";" + StringMacros::encodeURIComponent(macroPair.second.feMacroTooltip_);
2389 ";" + std::to_string(macroPair.second.namesOfInputArguments_.size());
2390 for(
const auto& name : macroPair.second.namesOfInputArguments_)
2391 retList +=
";" + StringMacros::encodeURIComponent(name);
2394 ";" + std::to_string(macroPair.second.namesOfOutputArguments_.size());
2395 for(
const auto& name : macroPair.second.namesOfOutputArguments_)
2396 retList +=
";" + StringMacros::encodeURIComponent(name);
2410 for(
const auto& FEInterface : theFEInterfaces_)
2412 isActive = FEInterface.second->WorkLoop::isActive();
2414 __CFG_COUT__ << FEInterface.second->getInterfaceUID() <<
" of type "
2415 << FEInterface.second->getInterfaceType() <<
": \t"
2416 <<
"workLoop_->isActive() " << (isActive ?
"yes" :
"no") << __E__;
2429 void FEVInterfacesManager::preStateMachineExecutionLoop(
void)
2431 VStateMachine::clearIterationWork();
2432 VStateMachine::clearSubIterationWork();
2434 stateMachinesIterationWorkCount_ = 0;
2436 __CFG_COUT__ <<
"Number of front ends to transition: " << theFENamesByPriority_.size()
2439 if(VStateMachine::getIterationIndex() == 0 &&
2440 VStateMachine::getSubIterationIndex() == 0)
2444 subIterationWorkStateMachineIndex_ = -1;
2446 stateMachinesIterationDone_.clear();
2447 for(
const auto& FEPair : theFEInterfaces_)
2448 stateMachinesIterationDone_[FEPair.first] =
false;
2451 __CFG_COUT__ <<
"Iteration " << VStateMachine::getIterationIndex() <<
"."
2452 << VStateMachine::getSubIterationIndex() <<
"("
2453 << (int)subIterationWorkStateMachineIndex_ <<
")" << __E__;
2457 void FEVInterfacesManager::preStateMachineExecution(
unsigned int i,
2458 const std::string& transitionName)
2460 if(i >= theFENamesByPriority_.size())
2462 __CFG_SS__ <<
"FE Interface " << i <<
" not found!" << __E__;
2466 const std::string& name = theFENamesByPriority_[i];
2470 fe->VStateMachine::setTransitionName(transitionName);
2471 fe->VStateMachine::setIterationIndex(VStateMachine::getIterationIndex());
2472 fe->VStateMachine::setSubIterationIndex(VStateMachine::getSubIterationIndex());
2474 fe->VStateMachine::clearIterationWork();
2475 fe->VStateMachine::clearSubIterationWork();
2477 __CFG_COUT__ <<
"theStateMachineImplementation Iteration "
2478 << fe->VStateMachine::getIterationIndex() <<
"."
2479 << fe->VStateMachine::getSubIterationIndex() << __E__;
2485 bool FEVInterfacesManager::postStateMachineExecution(
unsigned int i)
2487 if(i >= theFENamesByPriority_.size())
2489 __CFG_SS__ <<
"FE Interface index " << i <<
" not found!" << __E__;
2493 const std::string& name = theFENamesByPriority_[i];
2498 if(fe->VStateMachine::getSubIterationWork())
2500 subIterationWorkStateMachineIndex_ = i;
2501 VStateMachine::indicateSubIterationWork();
2503 __CFG_COUT__ <<
"FE Interface '" << name
2504 <<
"' is flagged for another sub-iteration..." << __E__;
2509 subIterationWorkStateMachineIndex_ = -1;
2511 bool& stateMachineDone = stateMachinesIterationDone_[name];
2512 stateMachineDone = !fe->VStateMachine::getIterationWork();
2514 if(!stateMachineDone)
2516 __CFG_COUT__ <<
"FE Interface '" << name
2517 <<
"' is flagged for another iteration..." << __E__;
2518 VStateMachine::indicateIterationWork();
2520 ++stateMachinesIterationWorkCount_;
2525 fe->VStateMachine::setTransitionName(
"");
2530 void FEVInterfacesManager::postStateMachineExecutionLoop(
void)
2532 if(VStateMachine::getSubIterationWork())
2533 __CFG_COUT__ <<
"FE Interface state machine implementation "
2534 << subIterationWorkStateMachineIndex_
2535 <<
" is flagged for another sub-iteration..." << __E__;
2536 else if(VStateMachine::getIterationWork())
2537 __CFG_COUT__ << stateMachinesIterationWorkCount_
2538 <<
" FE Interface state machine implementation(s) flagged for "
2539 "another iteration..."
2542 __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)
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_
defines used also by OtsConfigurationWizardSupervisor
< 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)