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);
213 unsigned int FEVInterfacesManager::getMinReadyForEventGenerationStartIteration(
void)
const
215 unsigned int maxIteration = 0;
216 for(
const auto& fePair : theFEInterfaces_)
218 unsigned int val = fePair.second->getMinReadyForEventGenerationStartIteration();
219 if(val > maxIteration)
228 const std::string transitionName =
"Configuring";
230 __CFG_COUT__ << transitionName <<
" FEVInterfacesManager " << __E__;
233 if(VStateMachine::getIterationIndex() == 0 &&
234 VStateMachine::getSubIterationIndex() == 0)
239 preStateMachineExecutionLoop();
240 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
243 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
244 i != subIterationWorkStateMachineIndex_)
247 const std::string& name = theFENamesByPriority_[i];
252 if(stateMachinesIterationDone_[name])
255 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
257 preStateMachineExecution(i, transitionName);
259 postStateMachineExecution(i);
262 if(!fe->VStateMachine::getSubIterationWork() &&
263 !fe->VStateMachine::getIterationWork())
268 fe->startSlowControlsWorkLoop();
270 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
273 postStateMachineExecutionLoop();
275 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
279 void FEVInterfacesManager::halt(
void)
281 const std::string transitionName =
"Halting";
284 preStateMachineExecutionLoop();
285 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
288 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
289 i != subIterationWorkStateMachineIndex_)
292 const std::string& name = theFENamesByPriority_[i];
296 if(stateMachinesIterationDone_[name])
299 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
300 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
301 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
303 preStateMachineExecution(i, transitionName);
313 <<
"An error occurred while halting the front-end workloop for '" << name
314 <<
",' ignoring." << __E__;
320 fe->stopSlowControlsWorkLoop();
324 __CFG_COUT_WARN__ <<
"An error occurred while halting the Slow Controls "
325 "front-end workloop for '"
326 << name <<
",' ignoring." << __E__;
336 __CFG_COUT_WARN__ <<
"An error occurred while halting the front-end '" << name
337 <<
",' ignoring." << __E__;
340 postStateMachineExecution(i);
342 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
343 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
344 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
346 postStateMachineExecutionLoop();
348 if(!VStateMachine::getSubIterationWork() && !VStateMachine::getIterationWork())
351 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
355 void FEVInterfacesManager::pause(
void)
357 const std::string transitionName =
"Pausing";
360 preStateMachineExecutionLoop();
361 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
364 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
365 i != subIterationWorkStateMachineIndex_)
368 const std::string& name = theFENamesByPriority_[i];
372 if(stateMachinesIterationDone_[name])
375 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
376 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
377 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
379 preStateMachineExecution(i, transitionName);
382 postStateMachineExecution(i);
384 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
385 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
386 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
388 postStateMachineExecutionLoop();
390 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
394 void FEVInterfacesManager::resume(
void)
396 const std::string transitionName =
"Resuming";
399 preStateMachineExecutionLoop();
400 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
403 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
404 i != subIterationWorkStateMachineIndex_)
407 const std::string& name = theFENamesByPriority_[i];
411 if(stateMachinesIterationDone_[name])
414 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
415 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
416 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
418 preStateMachineExecution(i, transitionName);
421 if(postStateMachineExecution(i))
424 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
425 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
426 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
428 postStateMachineExecutionLoop();
430 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
435 void FEVInterfacesManager::start(std::string runNumber)
437 const std::string transitionName =
"Starting";
440 preStateMachineExecutionLoop();
441 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
444 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
445 i != subIterationWorkStateMachineIndex_)
448 const std::string& name = theFENamesByPriority_[i];
452 if(stateMachinesIterationDone_[name])
455 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
456 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
457 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
459 preStateMachineExecution(i, transitionName);
460 fe->start(runNumber);
462 if(postStateMachineExecution(i))
465 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
466 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
467 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
469 postStateMachineExecutionLoop();
471 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
476 void FEVInterfacesManager::stop(
void)
478 const std::string transitionName =
"Starting";
481 preStateMachineExecutionLoop();
482 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
485 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 &&
486 i != subIterationWorkStateMachineIndex_)
489 const std::string& name = theFENamesByPriority_[i];
493 if(stateMachinesIterationDone_[name])
496 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
497 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
498 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
500 preStateMachineExecution(i, transitionName);
503 postStateMachineExecution(i);
505 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
506 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
507 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
509 postStateMachineExecutionLoop();
511 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
521 return theFEInterfaces_.at(interfaceID).get();
525 __CFG_SS__ <<
"Interface ID '" << interfaceID
526 <<
"' not found in configured interfaces." << __E__;
534 const std::string& interfaceID)
const
538 return *(theFEInterfaces_.at(interfaceID));
542 __CFG_SS__ <<
"Interface ID '" << interfaceID
543 <<
"' not found in configured interfaces." << __E__;
563 const std::string& interfaceID)
572 const std::string& interfaceID)
594 std::string retList =
"";
596 for(
const auto& it : theFEInterfaces_)
598 __CFG_COUT__ <<
"FE name = " << it.first << __E__;
600 retList += it.second->getInterfaceType() +
":" + supervisorLid +
":" +
601 it.second->getInterfaceUID() +
"\n";
624 const std::string& interfaceID,
625 const std::string& macroName,
626 const std::string& macroString,
627 const bool enableSavingOutput,
628 const std::string& outputFilePath,
629 const std::string& outputFileRadix,
630 const std::string& inputArgs)
632 if(requester !=
"iterator")
634 __CFG_SS__ <<
"Invalid requester '" << requester <<
"'" << __E__;
638 __CFG_COUT__ <<
"Starting multi-dimensional Macro '" << macroName
639 <<
"' for interface '" << interfaceID <<
".'" << __E__;
641 __CFG_COUTV__(macroString);
643 __CFG_COUTV__(inputArgs);
649 if(macroMultiDimensionalStatusMap_.find(interfaceID) !=
650 macroMultiDimensionalStatusMap_.end())
652 __SS__ <<
"Failed to start multi-dimensional Macro '" << macroName
653 <<
"' for interface '" << interfaceID
654 <<
"' - this interface already has an active Macro launch!" << __E__;
657 macroMultiDimensionalStatusMap_.emplace(std::make_pair(interfaceID,
"Active"));
663 const std::string interfaceID,
664 const std::string macroName,
665 const std::string macroString,
666 const bool enableSavingOutput,
667 const std::string outputFilePath,
668 const std::string outputFileRadix,
669 const std::string inputArgsStr) {
671 std::string mfSubject_ =
"threadMultiD-" + macroName;
672 __GEN_COUT__ <<
"Thread started." << __E__;
674 std::string statusResult =
"Done";
688 FILE* outputFilePointer = 0;
689 if(enableSavingOutput)
691 std::string filename = outputFilePath +
"/" + outputFileRadix +
692 macroName +
"_" + std::to_string(time(0)) +
694 __GEN_COUT__ <<
"Opening file... " << filename << __E__;
696 outputFilePointer = fopen(filename.c_str(),
"w");
697 if(!outputFilePointer)
699 __GEN_SS__ <<
"Failed to open output file: " << filename << __E__;
706 __GEN_COUTV__(inputArgsStr);
726 std::vector<
unsigned long > dimensionIterations,
727 dimensionIterationCnt;
729 using longParamMap_t = std::map<
732 std::pair<
long ,
long >>>;
734 std::vector<longParamMap_t> longDimensionParameters;
739 std::map<std::string , uint64_t > variableMap;
744 for(
const auto& inputArgName : macro.namesOfInputArguments_)
746 std::pair<std::string /*name*/, uint64_t /*value*/>(inputArgName,
748 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
750 std::pair<std::string /*name*/, uint64_t /*value*/>(outputArgName,
757 dimensionIterations.push_back(2);
758 dimensionIterations.push_back(4);
760 longDimensionParameters.push_back(longParamMap_t());
761 longDimensionParameters.push_back(longParamMap_t());
763 longDimensionParameters.back().emplace(std::make_pair(
767 std::make_pair(3 , 4 ))));
770 std::vector<std::string> dimensionArgs;
772 inputArgsStr, dimensionArgs, {
';'} );
774 __GEN_COUTV__(dimensionArgs.size());
777 if(dimensionArgs.size() == 0)
782 dimensionIterations.push_back(1);
783 longDimensionParameters.push_back(longParamMap_t());
786 for(
unsigned int d = 0; d < dimensionArgs.size(); ++d)
791 std::vector<std::string> args;
793 dimensionArgs[d], args, {
','} );
801 __GEN_SS__ <<
"Invalid dimensional arguments! "
802 <<
"Need number of iterations at dimension " << d
807 unsigned long numOfIterations;
809 __GEN_COUT__ <<
"Dimension " << d
810 <<
" numOfIterations=" << numOfIterations << __E__;
814 dimensionIterations.push_back(numOfIterations);
815 longDimensionParameters.push_back(longParamMap_t());
819 for(
unsigned int a = 1; a < args.size(); ++a)
821 std::vector<std::string> argPieces;
823 args[a], argPieces, {
':'} );
829 if(argPieces.size() != 3)
831 __GEN_SS__ <<
"Invalid argument pieces! Should be size "
833 << argPieces.size() << __E__;
840 if((argPieces[1].size() &&
841 (argPieces[1][argPieces[1].size() - 1] ==
'f' ||
842 argPieces[1].find(
'.') != std::string::npos)) ||
843 (argPieces[2].size() &&
844 (argPieces[2][argPieces[2].size() - 1] ==
'f' ||
845 argPieces[2].find(
'.') != std::string::npos)))
849 double startValue = strtod(argPieces[1].c_str(), 0);
850 double stepSize = strtod(argPieces[2].c_str(), 0);
852 __GEN_COUTV__(startValue);
853 __GEN_COUTV__(stepSize);
856 <<
"Error! Only integer aruments allowed for Macros. "
857 <<
"Double style arugment found: " << argPieces[0]
858 <<
"' := " << startValue <<
", " << stepSize << __E__;
882 __GEN_COUTV__(startValue);
883 __GEN_COUTV__(stepSize);
885 __GEN_COUT__ <<
"Creating long argument '" << argPieces[0]
886 <<
"' := " << startValue <<
", " << stepSize
889 longDimensionParameters.back().emplace(std::make_pair(
893 std::make_pair(startValue ,
901 if(dimensionIterations.size() != longDimensionParameters.size())
903 __GEN_SS__ <<
"Impossible vector size mismatch! "
904 << dimensionIterations.size() <<
" - "
905 << longDimensionParameters.size() << __E__;
911 std::stringstream outSS;
913 outSS <<
"\n==========================\n" << __E__;
914 outSS <<
"Macro '" << macro.macroName_
915 <<
"' multi-dimensional scan..." << __E__;
917 outSS <<
"\t" << dimensionIterations.size()
918 <<
" dimensions defined." << __E__;
919 for(
unsigned int i = 0; i < dimensionIterations.size(); ++i)
922 <<
"dimension[" << i <<
"] has "
923 << dimensionIterations[i] <<
" iterations and "
924 << (longDimensionParameters[i].size()) <<
" arguments."
927 for(
auto& param : longDimensionParameters[i])
929 <<
"'" << param.first <<
"' of type long with "
930 <<
"initial value and step value [decimal] = "
931 <<
"\t" << param.second.second.first <<
" & "
932 << param.second.second.second << __E__;
935 outSS <<
"\nInput argument names:" << __E__;
936 for(
const auto& inputArgName : macro.namesOfInputArguments_)
937 outSS <<
"\t" << inputArgName << __E__;
938 outSS <<
"\nOutput argument names:" << __E__;
939 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
940 outSS <<
"\t" << outputArgName << __E__;
942 outSS <<
"\n==========================\n" << __E__;
946 __GEN_COUT__ <<
"\n" << outSS.str();
947 if(outputFilePointer)
948 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
951 unsigned int iterationCount = 0;
959 std::function<void(
const unsigned int
961 localRecurse = [&dimensionIterations,
962 &dimensionIterationCnt,
964 &longDimensionParameters,
969 &localRecurse](
const unsigned int dimension) {
971 std::string mfSubject_ =
"multiD-" + std::to_string(dimension) +
972 "-" + macro.macroName_;
973 __GEN_COUTV__(dimension);
975 if(dimension >= dimensionIterations.size())
977 __GEN_COUT__ <<
"Iteration count: " << iterationCount++
979 __GEN_COUT__ <<
"Launching Macro '" << macro.macroName_
990 for(
unsigned int j = 0; j < dimensionIterations.size();
993 for(
auto& longParam : longDimensionParameters[j])
996 <<
"Assigning argIn '" << longParam.first
997 <<
"' to current long value '"
998 << longParam.second.first
999 <<
"' from dimension " << j <<
" parameter."
1001 variableMap.at(longParam.first) =
1002 longParam.second.first;
1010 std::stringstream outSS;
1012 outSS <<
"\n---------------\n" << __E__;
1013 outSS <<
"Macro '" << macro.macroName_
1014 <<
"' execution..." << __E__;
1016 <<
"iteration " << iterationCount << __E__;
1017 for(
unsigned int i = 0;
1018 i < dimensionIterationCnt.size();
1021 <<
"dimension[" << i
1022 <<
"] index := " << dimensionIterationCnt[i]
1027 <<
"Input arguments (count: "
1028 << macro.namesOfInputArguments_.size()
1030 for(
auto& argIn : macro.namesOfInputArguments_)
1031 outSS <<
"\t\t" << argIn <<
" = "
1032 << variableMap.at(argIn) << __E__;
1037 __GEN_COUT__ <<
"\n" << outSS.str();
1038 if(outputFilePointer)
1039 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1045 __GEN_COUT__ <<
"Macro complete!" << __E__;
1049 std::stringstream outSS;
1053 <<
"Output arguments (count: "
1054 << macro.namesOfOutputArguments_.size()
1056 for(
auto& argOut : macro.namesOfOutputArguments_)
1057 outSS <<
"\t\t" << argOut <<
" = "
1058 << variableMap.at(argOut) << __E__;
1062 __GEN_COUT__ <<
"\n" << outSS.str();
1063 if(outputFilePointer)
1064 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1071 if(dimension >= dimensionIterationCnt.size())
1072 dimensionIterationCnt.push_back(0);
1075 __GEN_COUT__ <<
"\n"
1076 <<
"======================================" << __E__
1077 <<
"dimension[" << dimension
1078 <<
"] number of iterations := "
1079 << dimensionIterations[dimension] << __E__;
1083 for(
auto& longPair : longDimensionParameters[dimension])
1085 longPair.second.first =
1086 longPair.second.second.first;
1088 <<
"arg '" << longPair.first
1089 <<
"' current value: " << longPair.second.first
1095 for(dimensionIterationCnt[dimension] =
1097 dimensionIterationCnt[dimension] <
1098 dimensionIterations[dimension];
1099 ++dimensionIterationCnt[dimension])
1101 __GEN_COUT__ <<
"dimension[" << dimension <<
"] index := "
1102 << dimensionIterationCnt[dimension] << __E__;
1104 localRecurse(dimension + 1);
1108 for(
auto& longPair : longDimensionParameters[dimension])
1110 longPair.second.first +=
1111 longPair.second.second.second;
1113 <<
"arg '" << longPair.first
1114 <<
"' current value: " << longPair.second.first
1120 __GEN_COUT__ <<
"Completed dimension[" << dimension
1121 <<
"] number of iterations := "
1122 << dimensionIterationCnt[dimension] <<
" of "
1123 << dimensionIterations[dimension] << __E__;
1130 if(outputFilePointer)
1131 fclose(outputFilePointer);
1133 catch(
const std::runtime_error& e)
1135 __SS__ <<
"Error executing multi-dimensional Macro: " << e.what()
1137 statusResult = ss.str();
1141 __SS__ <<
"Unknown error executing multi-dimensional Macro. " << __E__;
1146 catch(
const std::exception& e)
1148 ss <<
"Exception message: " << e.what();
1153 statusResult = ss.str();
1156 __COUTV__(statusResult);
1161 feMgr->macroMultiDimensionalStatusMap_[interfaceID] = statusResult;
1174 __CFG_COUT__ <<
"Started multi-dimensional Macro '" << macroName
1175 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1197 const std::string& requester,
1198 const std::string& interfaceID,
1199 const std::string& feMacroName,
1200 const bool enableSavingOutput,
1201 const std::string& outputFilePath,
1202 const std::string& outputFileRadix,
1203 const std::string& inputArgs)
1205 if(requester !=
"iterator")
1207 __CFG_SS__ <<
"Invalid requester '" << requester <<
"'" << __E__;
1211 __CFG_COUT__ <<
"Starting multi-dimensional FE Macro '" << feMacroName
1212 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1213 __CFG_COUTV__(inputArgs);
1219 if(macroMultiDimensionalStatusMap_.find(interfaceID) !=
1220 macroMultiDimensionalStatusMap_.end())
1222 __SS__ <<
"Failed to start multi-dimensional FE Macro '" << feMacroName
1223 <<
"' for interface '" << interfaceID
1224 <<
"' - this interface already has an active FE Macro launch!"
1228 macroMultiDimensionalStatusMap_.emplace(std::make_pair(interfaceID,
"Active"));
1234 const std::string interfaceID,
1235 const std::string feMacroName,
1236 const bool enableSavingOutput,
1237 const std::string outputFilePath,
1238 const std::string outputFileRadix,
1239 const std::string inputArgsStr) {
1241 std::string mfSubject_ =
"threadMultiD-" + feMacroName;
1242 __GEN_COUT__ <<
"Thread started." << __E__;
1244 std::string statusResult =
"Done";
1253 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1254 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1256 __GEN_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '"
1257 << interfaceID <<
"' was not found!" << __E__;
1264 FILE* outputFilePointer = 0;
1265 if(enableSavingOutput)
1267 std::string filename = outputFilePath +
"/" + outputFileRadix +
1268 feMacroName +
"_" + std::to_string(time(0)) +
1270 __GEN_COUT__ <<
"Opening file... " << filename << __E__;
1272 outputFilePointer = fopen(filename.c_str(),
"w");
1273 if(!outputFilePointer)
1275 __GEN_SS__ <<
"Failed to open output file: " << filename << __E__;
1282 __GEN_COUTV__(inputArgsStr);
1302 std::vector<
unsigned long > dimensionIterations,
1303 dimensionIterationCnt;
1305 using longParamMap_t = std::map<
1308 std::pair<
long ,
long >>>;
1309 using doubleParamMap_t =
1310 std::map<std::string ,
1314 using stringParamMap_t =
1315 std::map<std::string , std::string >;
1317 std::vector<longParamMap_t> longDimensionParameters;
1318 std::vector<doubleParamMap_t> doubleDimensionParameters;
1319 std::vector<stringParamMap_t> stringDimensionParameters;
1321 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
1322 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
1324 for(
unsigned int i = 0; i < feMacro.namesOfInputArguments_.size(); ++i)
1325 argsIn.push_back(std::make_pair(
1326 feMacro.namesOfInputArguments_[i],
1328 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1331 feMacro.namesOfOutputArguments_[i],
1338 argsIn.push_back(std::make_pair(
"myOtherArg",
"3"));
1340 dimensionIterations.push_back(2);
1341 dimensionIterations.push_back(4);
1343 longDimensionParameters.push_back(longParamMap_t());
1344 longDimensionParameters.push_back(longParamMap_t());
1346 doubleDimensionParameters.push_back(doubleParamMap_t());
1347 doubleDimensionParameters.push_back(doubleParamMap_t());
1349 longDimensionParameters.back().emplace(std::make_pair(
1353 std::make_pair(3 , 4 ))));
1356 std::vector<std::string> dimensionArgs;
1358 inputArgsStr, dimensionArgs, {
';'} );
1360 __GEN_COUTV__(dimensionArgs.size());
1363 if(dimensionArgs.size() == 0)
1368 dimensionIterations.push_back(1);
1369 longDimensionParameters.push_back(longParamMap_t());
1370 doubleDimensionParameters.push_back(doubleParamMap_t());
1371 stringDimensionParameters.push_back(stringParamMap_t());
1374 for(
unsigned int d = 0; d < dimensionArgs.size(); ++d)
1379 std::vector<std::string> args;
1381 dimensionArgs[d], args, {
','} );
1387 if(args.size() == 0)
1389 __GEN_SS__ <<
"Invalid dimensional arguments! "
1390 <<
"Need number of iterations at dimension " << d
1395 unsigned long numOfIterations;
1397 __GEN_COUT__ <<
"Dimension " << d
1398 <<
" numOfIterations=" << numOfIterations << __E__;
1402 dimensionIterations.push_back(numOfIterations);
1403 longDimensionParameters.push_back(longParamMap_t());
1404 doubleDimensionParameters.push_back(doubleParamMap_t());
1405 stringDimensionParameters.push_back(stringParamMap_t());
1409 for(
unsigned int a = 1; a < args.size(); ++a)
1411 std::vector<std::string> argPieces;
1413 args[a], argPieces, {
':'} );
1419 if(argPieces.size() != 3)
1421 __GEN_SS__ <<
"Invalid argument pieces! Should be size "
1423 << argPieces.size() << __E__;
1431 TableViewColumnInfo::DATATYPE_STRING_DEFAULT ||
1433 TableViewColumnInfo::DATATYPE_STRING_ALT_DEFAULT)
1437 __GEN_COUT__ <<
"Creating string argument '"
1438 << argPieces[0] <<
"' := " << argPieces[1]
1441 stringDimensionParameters.back().emplace(
1442 std::make_pair(argPieces[0], argPieces[1]));
1444 else if((argPieces[1].size() &&
1445 (argPieces[1][argPieces[1].size() - 1] ==
'f' ||
1446 argPieces[1].find(
'.') != std::string::npos)) ||
1447 (argPieces[2].size() &&
1448 (argPieces[2][argPieces[2].size() - 1] ==
'f' ||
1449 argPieces[2].find(
'.') != std::string::npos)))
1454 double startValue = strtod(argPieces[1].c_str(), 0);
1455 double stepSize = strtod(argPieces[2].c_str(), 0);
1457 __GEN_COUTV__(startValue);
1458 __GEN_COUTV__(stepSize);
1460 __GEN_COUT__ <<
"Creating double argument '"
1461 << argPieces[0] <<
"' := " << startValue
1462 <<
", " << stepSize << __E__;
1464 doubleDimensionParameters.back().emplace(std::make_pair(
1468 std::make_pair(startValue ,
1476 long int startValue;
1482 __GEN_COUTV__(startValue);
1483 __GEN_COUTV__(stepSize);
1485 __GEN_COUT__ <<
"Creating long argument '" << argPieces[0]
1486 <<
"' := " << startValue <<
", " << stepSize
1489 longDimensionParameters.back().emplace(std::make_pair(
1493 std::make_pair(startValue ,
1501 if(dimensionIterations.size() != longDimensionParameters.size() ||
1502 dimensionIterations.size() != doubleDimensionParameters.size() ||
1503 dimensionIterations.size() != stringDimensionParameters.size())
1505 __GEN_SS__ <<
"Impossible vector size mismatch! "
1506 << dimensionIterations.size() <<
" - "
1507 << longDimensionParameters.size() <<
" - "
1508 << doubleDimensionParameters.size() <<
" - "
1509 << stringDimensionParameters.size() << __E__;
1515 std::stringstream outSS;
1517 outSS <<
"\n==========================\n" << __E__;
1518 outSS <<
"FEMacro '" << feMacro.feMacroName_
1519 <<
"' multi-dimensional scan..." << __E__;
1521 outSS <<
"\t" << dimensionIterations.size()
1522 <<
" dimensions defined." << __E__;
1523 for(
unsigned int i = 0; i < dimensionIterations.size(); ++i)
1526 <<
"dimension[" << i <<
"] has "
1527 << dimensionIterations[i] <<
" iterations and "
1528 << (longDimensionParameters[i].size() +
1529 doubleDimensionParameters[i].size() +
1530 stringDimensionParameters[i].size())
1531 <<
" arguments." << __E__;
1533 for(
auto& param : longDimensionParameters[i])
1535 <<
"'" << param.first <<
"' of type long with "
1536 <<
"initial value and step value [decimal] = "
1537 <<
"\t" << param.second.second.first <<
" & "
1538 << param.second.second.second << __E__;
1540 for(
auto& param : doubleDimensionParameters[i])
1542 <<
"'" << param.first <<
"' of type double with "
1543 <<
"initial value and step value = "
1544 <<
"\t" << param.second.second.first <<
" & "
1545 << param.second.second.second << __E__;
1547 for(
auto& param : stringDimensionParameters[i])
1549 <<
"'" << param.first <<
"' of type string with "
1551 <<
"\t" << param.second << __E__;
1554 outSS <<
"\nHere are the identified input arguments:" << __E__;
1555 for(
unsigned int i = 0; i < feMacro.namesOfInputArguments_.size();
1557 outSS <<
"\t" << feMacro.namesOfInputArguments_[i] << __E__;
1558 outSS <<
"\nHere are the identified input arguments:" << __E__;
1559 for(
unsigned int i = 0;
1560 i < feMacro.namesOfOutputArguments_.size();
1562 outSS <<
"\t" << feMacro.namesOfOutputArguments_[i] << __E__;
1564 outSS <<
"\n==========================\n" << __E__;
1568 __GEN_COUT__ <<
"\n" << outSS.str();
1569 if(outputFilePointer)
1570 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1573 unsigned int iterationCount = 0;
1581 std::function<void(
const unsigned int
1583 localRecurse = [&dimensionIterations,
1584 &dimensionIterationCnt,
1586 &longDimensionParameters,
1587 &doubleDimensionParameters,
1588 &stringDimensionParameters,
1594 &localRecurse](
const unsigned int dimension) {
1596 std::string mfSubject_ =
"multiD-" + std::to_string(dimension) +
1597 "-" + feMacro.feMacroName_;
1598 __GEN_COUTV__(dimension);
1600 if(dimension >= dimensionIterations.size())
1602 __GEN_COUT__ <<
"Iteration count: " << iterationCount++
1604 __GEN_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_
1605 <<
"' ..." << __E__;
1616 for(
unsigned int i = 0; i < argsIn.size(); ++i)
1618 foundAsLong =
false;
1619 for(
unsigned int j = 0; j < dimensionIterations.size();
1623 longDimensionParameters[j].find(argsIn[i].first);
1624 if(longIt == longDimensionParameters[j].end())
1628 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1629 <<
"' to current long value '"
1630 << longIt->second.first
1631 <<
"' from dimension " << j
1632 <<
" parameter." << __E__;
1634 std::to_string(longIt->second.first);
1644 for(
unsigned int j = 0; j < dimensionIterations.size();
1647 auto doubleIt = doubleDimensionParameters[j].find(
1649 if(doubleIt == doubleDimensionParameters[j].end())
1653 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1654 <<
"' to current double value '"
1655 << doubleIt->second.first
1656 <<
"' from dimension " << j
1657 <<
" parameter." << __E__;
1659 std::to_string(doubleIt->second.first);
1669 for(
unsigned int j = 0; j < dimensionIterations.size();
1672 auto stringIt = stringDimensionParameters[j].find(
1674 if(stringIt == stringDimensionParameters[j].end())
1678 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first
1679 <<
"' to current string value '"
1681 <<
"' from dimension " << j
1682 <<
" parameter." << __E__;
1683 argsIn[i].second = stringIt->second;
1693 __GEN_SS__ <<
"ArgIn '" << argsIn[i].first
1694 <<
"' was not assigned a value "
1695 <<
"by any dimensional loop parameter sets. "
1696 "This is illegal. FEMacro '"
1697 << feMacro.feMacroName_ <<
"' requires '"
1699 <<
"' as an input argument. Either remove the "
1700 "input argument from this FEMacro, "
1701 <<
"or define a value as a dimensional loop "
1708 (fe->*(feMacro.macroFunction_))(feMacro, argsIn, argsOut);
1710 __GEN_COUT__ <<
"FE Macro complete!" << __E__;
1714 std::stringstream outSS;
1716 outSS <<
"\n---------------\n" << __E__;
1717 outSS <<
"FEMacro '" << feMacro.feMacroName_
1718 <<
"' execution..." << __E__;
1720 <<
"iteration " << iterationCount << __E__;
1721 for(
unsigned int i = 0;
1722 i < dimensionIterationCnt.size();
1725 <<
"dimension[" << i
1726 <<
"] index := " << dimensionIterationCnt[i]
1731 <<
"Input arguments (count: " << argsIn.size()
1733 for(
auto& argIn : argsIn)
1734 outSS <<
"\t\t" << argIn.first <<
" = "
1735 << argIn.second << __E__;
1739 <<
"Output arguments (count: " << argsOut.size()
1741 for(
auto& argOut : argsOut)
1742 outSS <<
"\t\t" << argOut.first <<
" = "
1743 << argOut.second << __E__;
1747 __GEN_COUT__ <<
"\n" << outSS.str();
1748 if(outputFilePointer)
1749 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1756 if(dimension >= dimensionIterationCnt.size())
1757 dimensionIterationCnt.push_back(0);
1760 __GEN_COUT__ <<
"\n"
1761 <<
"======================================" << __E__
1762 <<
"dimension[" << dimension
1763 <<
"] number of iterations := "
1764 << dimensionIterations[dimension] << __E__;
1769 for(
auto& longPair : longDimensionParameters[dimension])
1771 longPair.second.first =
1772 longPair.second.second.first;
1774 <<
"arg '" << longPair.first
1775 <<
"' current value: " << longPair.second.first
1779 for(
auto& doublePair : doubleDimensionParameters[dimension])
1781 doublePair.second.first =
1782 doublePair.second.second.first;
1784 <<
"arg '" << doublePair.first
1785 <<
"' current value: " << doublePair.second.first
1791 for(dimensionIterationCnt[dimension] =
1793 dimensionIterationCnt[dimension] <
1794 dimensionIterations[dimension];
1795 ++dimensionIterationCnt[dimension])
1797 __GEN_COUT__ <<
"dimension[" << dimension <<
"] index := "
1798 << dimensionIterationCnt[dimension] << __E__;
1800 localRecurse(dimension + 1);
1805 for(
auto& longPair : longDimensionParameters[dimension])
1807 longPair.second.first +=
1808 longPair.second.second.second;
1810 <<
"arg '" << longPair.first
1811 <<
"' current value: " << longPair.second.first
1815 for(
auto& doublePair :
1816 doubleDimensionParameters[dimension])
1818 doublePair.second.first +=
1819 doublePair.second.second.second;
1822 <<
"arg '" << doublePair.first
1823 <<
"' current value: " << doublePair.second.first
1829 __GEN_COUT__ <<
"Completed dimension[" << dimension
1830 <<
"] number of iterations := "
1831 << dimensionIterationCnt[dimension] <<
" of "
1832 << dimensionIterations[dimension] << __E__;
1839 if(outputFilePointer)
1840 fclose(outputFilePointer);
1842 catch(
const std::runtime_error& e)
1844 __SS__ <<
"Error executing multi-dimensional FE Macro: " << e.what()
1846 statusResult = ss.str();
1850 __SS__ <<
"Unknown error executing multi-dimensional FE Macro. " << __E__;
1855 catch(
const std::exception& e)
1857 ss <<
"Exception message: " << e.what();
1862 statusResult = ss.str();
1865 __COUTV__(statusResult);
1870 feMgr->macroMultiDimensionalStatusMap_[interfaceID] = statusResult;
1882 __CFG_COUT__ <<
"Started multi-dimensional FE Macro '" << feMacroName
1883 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1894 bool FEVInterfacesManager::checkMacroMultiDimensional(
const std::string& interfaceID,
1895 const std::string& macroName)
1901 auto statusIt = macroMultiDimensionalStatusMap_.find(interfaceID);
1902 if(statusIt == macroMultiDimensionalStatusMap_.end())
1904 __CFG_SS__ <<
"Status missing for multi-dimensional launch of Macro '"
1905 << macroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
1908 else if(statusIt->second ==
"Done")
1910 __CFG_COUT__ <<
"Completed multi-dimensional launch of Macro '" << macroName
1911 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1914 macroMultiDimensionalStatusMap_.erase(statusIt);
1917 else if(statusIt->second ==
"Active")
1919 __CFG_COUT__ <<
"Still running multi-dimensional launch of Macro '" << macroName
1920 <<
"' for interface '" << interfaceID <<
".'" << __E__;
1925 __CFG_SS__ <<
"Error occured during multi-dimensional launch of Macro '" << macroName
1926 <<
"' for interface '" << interfaceID <<
"':" << statusIt->second << __E__;
1944 const std::string& interfaceID,
1945 const std::string& feMacroName,
1946 const std::string& inputArgs,
1947 std::string& outputArgs)
1949 __CFG_COUTV__(callingInterfaceID);
1955 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1956 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1958 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID
1959 <<
"' was not found!" << __E__;
1960 ss <<
"\nHere is the list of available FE Macros:\n";
1961 for(
const auto& feMacro : fe->getMapOfFEMacroFunctions())
1962 ss << feMacro.first <<
"... ";
1964 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1970 std::set<std::string> allowedFEsSet;
1976 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID
1977 <<
"' does not allow access to calling interfaceID '"
1978 << callingInterfaceID
1979 <<
"!' Did the interface add the calling interfaceID "
1980 <<
"to the access list when registering the front-end macro." << __E__;
1981 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1990 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1991 outputArgs += (i ?
"," :
"") + feMacro.namesOfOutputArguments_[i];
1993 __CFG_COUTV__(outputArgs);
1995 runFEMacro(interfaceID, feMacro, inputArgs, outputArgs);
1997 __CFG_COUTV__(outputArgs);
2013 const std::string& macroObjectString,
2014 const std::string& inputArgs,
2015 std::string& outputArgs)
2026 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
2028 std::istringstream inputStream(inputArgs);
2029 std::string splitVal, argName, argValue;
2030 while(getline(inputStream, splitVal,
';'))
2032 std::istringstream pairInputStream(splitVal);
2033 getline(pairInputStream, argName,
',');
2034 getline(pairInputStream, argValue,
',');
2035 argsIn.push_back(std::make_pair(argName, argValue));
2040 if(macro.namesOfInputArguments_.size() != argsIn.size())
2042 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2043 <<
"' was attempted on interfaceID '" << interfaceID
2044 <<
"' with a mismatch in"
2045 <<
" number of input arguments. " << argsIn.size() <<
" were given. "
2046 << macro.namesOfInputArguments_.size() <<
" expected." << __E__;
2049 for(
unsigned int i = 0; i < argsIn.size(); ++i)
2050 if(macro.namesOfInputArguments_.find(argsIn[i].first) ==
2051 macro.namesOfInputArguments_.end())
2053 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2054 <<
"' was attempted on interfaceID '" << interfaceID
2055 <<
"' with a mismatch in"
2056 <<
" a name of an input argument. " << argsIn[i].first
2057 <<
" was given. Expected: "
2065 std::vector<std::string> returnStrings;
2066 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
2069 std::istringstream inputStream(outputArgs);
2070 std::string argName;
2071 while(getline(inputStream, argName,
','))
2073 __CFG_COUT__ <<
"argName " << argName << __E__;
2075 returnStrings.push_back(
"DEFAULT");
2076 argsOut.push_back(FEVInterface::frontEndMacroArg_t(
2077 argName, returnStrings[returnStrings.size() - 1]));
2086 if(macro.namesOfOutputArguments_.size() != argsOut.size())
2088 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2089 <<
"' was attempted on interfaceID '" << interfaceID
2090 <<
"' with a mismatch in"
2091 <<
" number of output arguments. " << argsOut.size() <<
" were given. "
2092 << macro.namesOfOutputArguments_.size() <<
" expected." << __E__;
2096 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2097 if(macro.namesOfOutputArguments_.find(argsOut[i].first) ==
2098 macro.namesOfOutputArguments_.end())
2100 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_
2101 <<
"' was attempted on interfaceID '" << interfaceID
2102 <<
"' with a mismatch in"
2103 <<
" a name of an output argument. " << argsOut[i].first
2104 <<
" were given. Expected: "
2111 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
2113 std::map<std::string , uint64_t > variableMap;
2115 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
2116 variableMap.emplace(
2117 std::pair<std::string /*name*/, uint64_t /*value*/>(outputArgName, 0));
2118 for(
const auto& inputArgName : macro.namesOfInputArguments_)
2119 variableMap.emplace(
2120 std::pair<std::string /*name*/, uint64_t /*value*/>(inputArgName, 0));
2122 for(
auto& argIn : argsIn)
2124 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
2130 __CFG_COUT__ <<
"MacroMaker Macro complete!" << __E__;
2132 __CFG_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
2133 for(
auto& arg : argsOut)
2135 std::stringstream numberSs;
2136 numberSs << std::dec << variableMap.at(arg.first) <<
" (0x" << std::hex
2137 << variableMap.at(arg.first) <<
")" << std::dec;
2138 arg.second = numberSs.str();
2139 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
2144 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2148 outputArgs += argsOut[i].first +
"," + argsOut[i].second;
2151 __CFG_COUT__ <<
"outputArgs = " << outputArgs << __E__;
2167 const std::string& feMacroName,
2168 const std::string& inputArgs,
2169 std::string& outputArgs)
2175 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
2176 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
2178 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID
2179 <<
"' was not found!" << __E__;
2180 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2184 runFEMacro(interfaceID, FEMacroIt->second, inputArgs, outputArgs);
2201 const std::string& inputArgs,
2202 std::string& outputArgs)
2204 __CFG_COUTV__(inputArgs);
2208 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
2210 std::istringstream inputStream(inputArgs);
2211 std::string splitVal, argName, argValue;
2212 while(getline(inputStream, splitVal,
';'))
2214 std::istringstream pairInputStream(splitVal);
2215 getline(pairInputStream, argName,
',');
2216 getline(pairInputStream, argValue,
',');
2223 if(feMacro.namesOfInputArguments_.size() != argsIn.size())
2225 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2226 << interfaceID <<
"' was attempted with a mismatch in"
2227 <<
" number of input arguments. " << argsIn.size() <<
" were given. "
2228 << feMacro.namesOfInputArguments_.size() <<
" expected." << __E__;
2229 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2233 for(
unsigned int i = 0; i < argsIn.size(); ++i)
2234 if(argsIn[i].first.substr(0, argsIn[i].first.find(
'(')) !=
2235 feMacro.namesOfInputArguments_[i].substr(
2236 0, feMacro.namesOfInputArguments_[i].find(
'(')))
2238 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2239 << interfaceID <<
"' was attempted with a mismatch in"
2240 <<
" a name of an input argument. '" << argsIn[i].first
2241 <<
"' was given. '" << feMacro.namesOfInputArguments_[i]
2242 <<
"' expected." << __E__;
2243 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2248 std::vector<std::string> returnStrings;
2249 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
2251 const std::string ARG_OUT_DEFAULT =
"DEFAULT";
2254 std::istringstream inputStream(outputArgs);
2255 std::string argName;
2256 while(getline(inputStream, argName,
','))
2258 __CFG_COUTT__ <<
"argName " << argName << __E__;
2260 returnStrings.push_back(ARG_OUT_DEFAULT);
2261 argsOut.push_back(FEVInterface::frontEndMacroArg_t(
2263 returnStrings[returnStrings.size() - 1]));
2266 __CFG_COUTT__ << (uint64_t) & (returnStrings[returnStrings.size() - 1])
2272 if(feMacro.namesOfOutputArguments_.size() != argsOut.size())
2274 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2275 << interfaceID <<
"' was attempted with a mismatch in"
2276 <<
" number of output arguments. " << argsOut.size() <<
" were given. "
2277 << feMacro.namesOfOutputArguments_.size() <<
" expected." << __E__;
2278 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2281 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2282 if(argsOut[i].first != feMacro.namesOfOutputArguments_[i])
2284 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2285 << interfaceID <<
"' was attempted with a mismatch in"
2286 <<
" a name of an output argument. " << argsOut[i].first
2287 <<
" were given. " << feMacro.namesOfOutputArguments_[i]
2288 <<
" expected." << __E__;
2289 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2294 const uint16_t BUILT_IN_ARGOUT_COUNT = 1;
2296 returnStrings.push_back(ARG_OUT_DEFAULT);
2297 argsOut.push_back(FEVInterface::frontEndMacroArg_t(
2298 PLOTLY_PLOT, returnStrings[returnStrings.size() - 1]));
2301 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
2302 for(
auto& argIn : argsIn)
2303 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
2305 __CFG_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_ <<
"' ..." << __E__;
2309 __CFG_COUT__ <<
"FE Macro complete!" << __E__;
2311 __CFG_COUT__ <<
"# of output args = " << argsOut.size() <<
" including "
2312 << BUILT_IN_ARGOUT_COUNT <<
" built-in args." << __E__;
2313 for(
const auto& arg : argsOut)
2314 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
2317 if(feMacro.namesOfOutputArguments_.size() != argsOut.size() - BUILT_IN_ARGOUT_COUNT)
2319 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
2321 <<
"' was attempted but the FE macro "
2322 "manipulated the output arguments vector. It is illegal "
2323 "to add or remove output vector name/value pairs."
2325 __CFG_COUT_ERR__ <<
"\n" << ss.str();
2332 for(
unsigned int i = 0; i < argsOut.size(); ++i)
2334 if(i >= argsOut.size() -
2335 BUILT_IN_ARGOUT_COUNT &&
2336 argsOut[i].second == ARG_OUT_DEFAULT)
2351 std::stringstream outNumberSs;
2352 outNumberSs << std::dec << tmpNumber <<
" (0x" << std::hex << tmpNumber
2354 outputArgs += StringMacros::encodeURIComponent(argsOut[i].first) +
"," +
2363 outputArgs += StringMacros::encodeURIComponent(argsOut[i].first) +
"," +
2364 StringMacros::encodeURIComponent(argsOut[i].second);
2367 __CFG_COUTT__ <<
"outputArgs = " << outputArgs << __E__;
2381 const std::string& supervisorLid)
2383 std::string retList =
"";
2385 __CFG_COUTV__(theFEInterfaces_.size());
2387 for(
const auto& it : theFEInterfaces_)
2389 __CFG_COUTT__ <<
"FE interface UID = " << it.first << __E__;
2391 retList += supervisorName +
";" + supervisorLid +
";" +
2392 it.second->getInterfaceType() +
";" + it.second->getInterfaceUID();
2394 for(
const auto& macroPair : it.second->getMapOfFEMacroFunctions())
2396 __CFG_COUTT__ <<
"FE Macro name = " << macroPair.first << __E__;
2398 ";" + macroPair.first +
";" + macroPair.second.requiredUserPermissions_;
2400 ";" + StringMacros::encodeURIComponent(macroPair.second.feMacroTooltip_);
2403 ";" + std::to_string(macroPair.second.namesOfInputArguments_.size());
2404 for(
const auto& name : macroPair.second.namesOfInputArguments_)
2405 retList +=
";" + StringMacros::encodeURIComponent(name);
2408 ";" + std::to_string(macroPair.second.namesOfOutputArguments_.size());
2409 for(
const auto& name : macroPair.second.namesOfOutputArguments_)
2410 retList +=
";" + StringMacros::encodeURIComponent(name);
2424 for(
const auto& FEInterface : theFEInterfaces_)
2426 isActive = FEInterface.second->WorkLoop::isActive();
2428 __CFG_COUT__ << FEInterface.second->getInterfaceUID() <<
" of type "
2429 << FEInterface.second->getInterfaceType() <<
": \t"
2430 <<
"workLoop_->isActive() " << (isActive ?
"yes" :
"no") << __E__;
2443 void FEVInterfacesManager::preStateMachineExecutionLoop(
void)
2445 VStateMachine::clearIterationWork();
2446 VStateMachine::clearSubIterationWork();
2448 stateMachinesIterationWorkCount_ = 0;
2450 __CFG_COUT__ <<
"Number of front ends to transition: " << theFENamesByPriority_.size()
2453 if(VStateMachine::getIterationIndex() == 0 &&
2454 VStateMachine::getSubIterationIndex() == 0)
2458 subIterationWorkStateMachineIndex_ = -1;
2460 stateMachinesIterationDone_.clear();
2461 for(
const auto& FEPair : theFEInterfaces_)
2462 stateMachinesIterationDone_[FEPair.first] =
false;
2465 __CFG_COUT__ <<
"Iteration " << VStateMachine::getIterationIndex() <<
"."
2466 << VStateMachine::getSubIterationIndex() <<
"("
2467 << (int)subIterationWorkStateMachineIndex_ <<
")" << __E__;
2471 void FEVInterfacesManager::preStateMachineExecution(
unsigned int i,
2472 const std::string& transitionName)
2474 if(i >= theFENamesByPriority_.size())
2476 __CFG_SS__ <<
"FE Interface " << i <<
" not found!" << __E__;
2480 const std::string& name = theFENamesByPriority_[i];
2484 fe->VStateMachine::setTransitionName(transitionName);
2485 fe->VStateMachine::setIterationIndex(VStateMachine::getIterationIndex());
2486 fe->VStateMachine::setSubIterationIndex(VStateMachine::getSubIterationIndex());
2487 fe->VStateMachine::setSystemMinReadyForEventGenerationStartIteration(
2488 VStateMachine::getSystemMinReadyForEventGenerationStartIteration());
2490 fe->VStateMachine::clearIterationWork();
2491 fe->VStateMachine::clearSubIterationWork();
2493 __CFG_COUT__ <<
"theStateMachineImplementation Iteration "
2494 << fe->VStateMachine::getIterationIndex() <<
"."
2495 << fe->VStateMachine::getSubIterationIndex() << __E__;
2501 bool FEVInterfacesManager::postStateMachineExecution(
unsigned int i)
2503 if(i >= theFENamesByPriority_.size())
2505 __CFG_SS__ <<
"FE Interface index " << i <<
" not found!" << __E__;
2509 const std::string& name = theFENamesByPriority_[i];
2514 if(fe->VStateMachine::getSubIterationWork())
2516 subIterationWorkStateMachineIndex_ = i;
2517 VStateMachine::indicateSubIterationWork();
2519 __CFG_COUT__ <<
"FE Interface '" << name
2520 <<
"' is flagged for another sub-iteration..." << __E__;
2525 subIterationWorkStateMachineIndex_ = -1;
2527 bool& stateMachineDone = stateMachinesIterationDone_[name];
2528 stateMachineDone = !fe->VStateMachine::getIterationWork();
2530 if(!stateMachineDone)
2532 __CFG_COUT__ <<
"FE Interface '" << name
2533 <<
"' is flagged for another iteration..." << __E__;
2534 VStateMachine::indicateIterationWork();
2536 ++stateMachinesIterationWorkCount_;
2541 fe->VStateMachine::setTransitionName(
"");
2546 void FEVInterfacesManager::postStateMachineExecutionLoop(
void)
2548 if(VStateMachine::getSubIterationWork())
2549 __CFG_COUT__ <<
"FE Interface state machine implementation "
2550 << subIterationWorkStateMachineIndex_
2551 <<
" is flagged for another sub-iteration..." << __E__;
2552 else if(VStateMachine::getIterationWork())
2553 __CFG_COUT__ << stateMachinesIterationWorkCount_
2554 <<
" FE Interface state machine implementation(s) flagged for "
2555 "another iteration..."
2558 __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)