1 #include "otsdaq/FECore/FEVInterfacesManager.h"
2 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
3 #include "otsdaq/Macros/CoutMacros.h"
4 #include "otsdaq/MessageFacility/MessageFacility.h"
5 #include "otsdaq/PluginMakers/MakeInterface.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(
const ConfigurationTree& theXDAQContextConfigTree,
const std::string& supervisorConfigurationPath)
23 __CFG_COUT__ <<
"Constructed." << __E__;
27 FEVInterfacesManager::~FEVInterfacesManager(
void)
30 __CFG_COUT__ <<
"Destructed." << __E__;
34 void FEVInterfacesManager::init(
void) {}
37 void FEVInterfacesManager::destroy(
void)
39 for(
auto& it : theFEInterfaces_)
42 theFEInterfaces_.clear();
43 theFENamesByPriority_.clear();
47 void FEVInterfacesManager::createInterfaces(
void)
49 const std::string COL_NAME_feGroupLink =
"LinkToFEInterfaceTable";
50 const std::string COL_NAME_feTypeLink =
"LinkToFETypeTable";
51 const std::string COL_NAME_fePlugin =
"FEInterfacePluginName";
53 __CFG_COUT__ <<
"Path: " << theConfigurationPath_ +
"/" + COL_NAME_feGroupLink << __E__;
58 ConfigurationTree appNode = theXDAQContextConfigTree_.getBackNode(theConfigurationPath_, 1);
59 __CFG_COUTV__(appNode.getValueAsString());
61 auto fes = appNode.getNode(
"LinkToSupervisorTable").getNode(
"LinkToFEInterfaceTable").getChildrenNames(
true ,
true );
62 __CFG_COUTV__(StringMacros::vectorToString(fes));
65 ConfigurationTree feGroupLinkNode = Configurable::getSelfNode().getNode(COL_NAME_feGroupLink);
67 std::vector<std::pair<std::string, ConfigurationTree>> feChildren = feGroupLinkNode.getChildren();
70 theFENamesByPriority_ = feGroupLinkNode.getChildrenNames(
true ,
true );
71 __CFG_COUTV__(StringMacros::vectorToString(theFENamesByPriority_));
73 for(
const auto& interface : feChildren)
77 if(!interface.second.getNode(TableViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
82 __CFG_COUT_INFO__ <<
"Ignoring FE Status since Status column is missing!" << __E__;
85 __CFG_COUT__ <<
"Interface Plugin Name: " << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>() << __E__;
86 __CFG_COUT__ <<
"Interface Name: " << interface.first << __E__;
87 __CFG_COUT__ <<
"XDAQContext Node: " << theXDAQContextConfigTree_ << __E__;
88 __CFG_COUT__ <<
"Path to configuration: " << (theConfigurationPath_ +
"/" + COL_NAME_feGroupLink +
"/" + interface.first +
"/" + COL_NAME_feTypeLink)
93 theFEInterfaces_[interface.first] =
94 makeInterface(interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>(),
96 theXDAQContextConfigTree_,
97 (theConfigurationPath_ +
"/" + COL_NAME_feGroupLink +
"/" + interface.first +
"/" + COL_NAME_feTypeLink));
101 theFEInterfaces_[interface.first]->VStateMachine::parentSupervisor_ = VStateMachine::parentSupervisor_;
102 theFEInterfaces_[interface.first]->parentInterfaceManager_ =
this;
104 catch(
const cet::exception& e)
106 __CFG_SS__ <<
"Failed to instantiate plugin named '" << interface.first <<
"' of type '"
107 << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>() <<
"' due to the following error: \n"
108 << e.what() << __E__;
109 __MOUT_ERR__ << ss.str();
112 catch(
const std::runtime_error& e)
114 __CFG_SS__ <<
"Failed to instantiate plugin named '" << interface.first <<
"' of type '"
115 << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>() <<
"' due to the following error: \n"
116 << e.what() << __E__;
117 __MOUT_ERR__ << ss.str();
122 __CFG_SS__ <<
"Failed to instantiate plugin named '" << interface.first <<
"' of type '"
123 << interface.second.getNode(COL_NAME_fePlugin).getValue<std::string>() <<
"' due to an unknown error." << __E__;
124 __MOUT_ERR__ << ss.str();
129 __CFG_COUT__ <<
"Done creating interfaces" << __E__;
137 std::string FEVInterfacesManager::getStatusProgressDetail(
void)
139 std::string progress =
"";
140 unsigned int cnt = 0;
143 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
146 const std::string& name = theFENamesByPriority_[i];
148 std::string feProgress = fe->getStatusProgressDetail();
149 if(feProgress.size())
150 progress += ((cnt++) ?
"," :
"") + StringMacros::encodeURIComponent(feProgress);
157 __CFG_COUTV__(progress);
163 void FEVInterfacesManager::configure(
void)
165 const std::string transitionName =
"Configuring";
167 __CFG_COUT__ << transitionName <<
" FEVInterfacesManager " << __E__;
170 if(VStateMachine::getIterationIndex() == 0 && VStateMachine::getSubIterationIndex() == 0)
175 preStateMachineExecutionLoop();
176 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
179 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 && i != subIterationWorkStateMachineIndex_)
182 const std::string& name = theFENamesByPriority_[i];
185 fe = getFEInterfaceP(name);
187 if(stateMachinesIterationDone_[name])
190 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
191 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
192 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
194 preStateMachineExecution(i, transitionName);
196 postStateMachineExecution(i);
200 fe->configureSlowControls();
201 fe->startSlowControlsWorkLoop();
203 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
204 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
205 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
207 postStateMachineExecutionLoop();
209 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
213 void FEVInterfacesManager::halt(
void)
215 const std::string transitionName =
"Halting";
218 preStateMachineExecutionLoop();
219 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
222 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 && i != subIterationWorkStateMachineIndex_)
225 const std::string& name = theFENamesByPriority_[i];
227 fe = getFEInterfaceP(name);
229 if(stateMachinesIterationDone_[name])
232 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
233 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
234 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
236 preStateMachineExecution(i, transitionName);
245 __CFG_COUT_WARN__ <<
"An error occurred while halting the front-end workloop for '" << name <<
",' ignoring." << __E__;
251 fe->stopSlowControlsWorkLoop();
255 __CFG_COUT_WARN__ <<
"An error occurred while halting the Slow Controls "
256 "front-end workloop for '"
257 << name <<
",' ignoring." << __E__;
267 __CFG_COUT_WARN__ <<
"An error occurred while halting the front-end '" << name <<
",' ignoring." << __E__;
270 postStateMachineExecution(i);
272 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
273 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
274 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
276 postStateMachineExecutionLoop();
281 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
285 void FEVInterfacesManager::pause(
void)
287 const std::string transitionName =
"Pausing";
290 preStateMachineExecutionLoop();
291 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
294 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 && i != subIterationWorkStateMachineIndex_)
297 const std::string& name = theFENamesByPriority_[i];
299 fe = getFEInterfaceP(name);
301 if(stateMachinesIterationDone_[name])
304 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
305 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
306 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
308 preStateMachineExecution(i, transitionName);
311 postStateMachineExecution(i);
313 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
314 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
315 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
317 postStateMachineExecutionLoop();
319 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
323 void FEVInterfacesManager::resume(
void)
325 const std::string transitionName =
"Resuming";
328 preStateMachineExecutionLoop();
329 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
332 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 && i != subIterationWorkStateMachineIndex_)
335 const std::string& name = theFENamesByPriority_[i];
339 if(stateMachinesIterationDone_[name])
342 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
343 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
344 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
346 preStateMachineExecution(i, transitionName);
349 if(postStateMachineExecution(i))
352 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
353 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
354 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
356 postStateMachineExecutionLoop();
358 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
363 void FEVInterfacesManager::start(std::string runNumber)
365 const std::string transitionName =
"Starting";
368 preStateMachineExecutionLoop();
369 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
372 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 && i != subIterationWorkStateMachineIndex_)
375 const std::string& name = theFENamesByPriority_[i];
377 fe = getFEInterfaceP(name);
379 if(stateMachinesIterationDone_[name])
382 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
383 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
384 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
386 preStateMachineExecution(i, transitionName);
387 fe->start(runNumber);
389 if(postStateMachineExecution(i))
392 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
393 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
394 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
396 postStateMachineExecutionLoop();
398 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
403 void FEVInterfacesManager::stop(
void)
405 const std::string transitionName =
"Starting";
408 preStateMachineExecutionLoop();
409 for(
unsigned int i = 0; i < theFENamesByPriority_.size(); ++i)
412 if(subIterationWorkStateMachineIndex_ != (
unsigned int)-1 && i != subIterationWorkStateMachineIndex_)
415 const std::string& name = theFENamesByPriority_[i];
417 fe = getFEInterfaceP(name);
419 if(stateMachinesIterationDone_[name])
422 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
423 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
424 __CFG_COUT__ << transitionName <<
" interface " << name << __E__;
426 preStateMachineExecution(i, transitionName);
429 postStateMachineExecution(i);
431 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
432 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
433 __CFG_COUT__ <<
"Done " << transitionName <<
" interface " << name << __E__;
435 postStateMachineExecutionLoop();
437 __CFG_COUT__ <<
"Done " << transitionName <<
" all interfaces." << __E__;
443 FEVInterface* FEVInterfacesManager::getFEInterfaceP(
const std::string& interfaceID)
447 return theFEInterfaces_.at(interfaceID).get();
451 __CFG_SS__ <<
"Interface ID '" << interfaceID <<
"' not found in configured interfaces." << __E__;
458 const FEVInterface& FEVInterfacesManager::getFEInterface(
const std::string& interfaceID)
const
462 return *(theFEInterfaces_.at(interfaceID));
466 __CFG_SS__ <<
"Interface ID '" << interfaceID <<
"' not found in configured interfaces." << __E__;
475 void FEVInterfacesManager::universalRead(
const std::string& interfaceID,
char* address,
char* returnValue)
477 getFEInterfaceP(interfaceID)->universalRead(address, returnValue);
483 unsigned int FEVInterfacesManager::getInterfaceUniversalAddressSize(
const std::string& interfaceID)
485 return getFEInterfaceP(interfaceID)->getUniversalAddressSize();
491 unsigned int FEVInterfacesManager::getInterfaceUniversalDataSize(
const std::string& interfaceID)
493 return getFEInterfaceP(interfaceID)->getUniversalDataSize();
499 void FEVInterfacesManager::universalWrite(
const std::string& interfaceID,
char* address,
char* writeValue)
501 getFEInterfaceP(interfaceID)->universalWrite(address, writeValue);
509 std::string FEVInterfacesManager::getFEListString(
const std::string& supervisorLid)
511 std::string retList =
"";
513 for(
const auto& it : theFEInterfaces_)
515 __CFG_COUT__ <<
"FE name = " << it.first << __E__;
517 retList += it.second->getInterfaceType() +
":" + supervisorLid +
":" + it.second->getInterfaceUID() +
"\n";
540 const std::string& interfaceID,
541 const std::string& macroName,
542 const std::string& macroString,
543 const bool enableSavingOutput,
544 const std::string& outputFilePath,
545 const std::string& outputFileRadix,
546 const std::string& inputArgs)
548 if(requester !=
"iterator")
550 __CFG_SS__ <<
"Invalid requester '" << requester <<
"'" << __E__;
554 __CFG_COUT__ <<
"Starting multi-dimensional Macro '" << macroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
556 __CFG_COUTV__(macroString);
558 __CFG_COUTV__(inputArgs);
562 std::lock_guard<std::mutex> lock(macroMultiDimensionalDoneMutex_);
564 if(macroMultiDimensionalStatusMap_.find(interfaceID) != macroMultiDimensionalStatusMap_.end())
566 __SS__ <<
"Failed to start multi-dimensional Macro '" << macroName <<
"' for interface '" << interfaceID
567 <<
"' - this interface already has an active Macro launch!" << __E__;
570 macroMultiDimensionalStatusMap_.emplace(std::make_pair(interfaceID,
"Active"));
576 const std::string interfaceID,
577 const std::string macroName,
578 const std::string macroString,
579 const bool enableSavingOutput,
580 const std::string outputFilePath,
581 const std::string outputFileRadix,
582 const std::string inputArgsStr) {
585 std::string mfSubject_ =
"threadMultiD-" + macroName;
586 __GEN_COUT__ <<
"Thread started." << __E__;
588 std::string statusResult =
"Done";
602 FILE* outputFilePointer = 0;
603 if(enableSavingOutput)
605 std::string filename = outputFilePath +
"/" + outputFileRadix + macroName +
"_" + std::to_string(time(0)) +
".txt";
606 __GEN_COUT__ <<
"Opening file... " << filename << __E__;
608 outputFilePointer = fopen(filename.c_str(),
"w");
609 if(!outputFilePointer)
611 __GEN_SS__ <<
"Failed to open output file: " << filename << __E__;
618 __GEN_COUTV__(inputArgsStr);
638 std::vector<
unsigned long > dimensionIterations, dimensionIterationCnt;
640 using longParamMap_t =
641 std::map<std::string , std::pair<
long , std::pair<
long ,
long >>>;
643 std::vector<longParamMap_t> longDimensionParameters;
648 std::map<std::string , uint64_t > variableMap;
653 for(
const auto& inputArgName : macro.namesOfInputArguments_)
655 std::pair<std::string /*name*/, uint64_t /*value*/>(inputArgName, 0));
656 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
658 std::pair<std::string /*name*/, uint64_t /*value*/>(outputArgName, 0));
664 dimensionIterations.push_back(2);
665 dimensionIterations.push_back(4);
667 longDimensionParameters.push_back(longParamMap_t());
668 longDimensionParameters.push_back(longParamMap_t());
670 longDimensionParameters.back().emplace(
671 std::make_pair(
"myOtherArg", std::make_pair(3 , std::make_pair(3 , 4 ))));
674 std::vector<std::string> dimensionArgs;
675 StringMacros::getVectorFromString(inputArgsStr, dimensionArgs, {
';'} );
677 __GEN_COUTV__(dimensionArgs.size());
680 if(dimensionArgs.size() == 0)
685 dimensionIterations.push_back(1);
686 longDimensionParameters.push_back(longParamMap_t());
689 for(
unsigned int d = 0; d < dimensionArgs.size(); ++d)
694 std::vector<std::string> args;
695 StringMacros::getVectorFromString(dimensionArgs[d], args, {
','} );
703 __GEN_SS__ <<
"Invalid dimensional arguments! "
704 <<
"Need number of iterations at dimension " << d << __E__;
708 unsigned long numOfIterations;
709 StringMacros::getNumber(args[0], numOfIterations);
710 __GEN_COUT__ <<
"Dimension " << d <<
" numOfIterations=" << numOfIterations << __E__;
714 dimensionIterations.push_back(numOfIterations);
715 longDimensionParameters.push_back(longParamMap_t());
719 for(
unsigned int a = 1; a < args.size(); ++a)
721 std::vector<std::string> argPieces;
722 StringMacros::getVectorFromString(args[a], argPieces, {
':'} );
724 __GEN_COUTV__(StringMacros::vectorToString(argPieces));
728 if(argPieces.size() != 3)
730 __GEN_SS__ <<
"Invalid argument pieces! Should be size "
732 << argPieces.size() << __E__;
733 ss << StringMacros::vectorToString(argPieces);
739 if((argPieces[1].size() && (argPieces[1][argPieces[1].size() - 1] ==
'f' || argPieces[1].find(
'.') != std::string::npos)) ||
740 (argPieces[2].size() && (argPieces[2][argPieces[2].size() - 1] ==
'f' || argPieces[2].find(
'.') != std::string::npos)))
744 double startValue = strtod(argPieces[1].c_str(), 0);
745 double stepSize = strtod(argPieces[2].c_str(), 0);
747 __GEN_COUTV__(startValue);
748 __GEN_COUTV__(stepSize);
750 __GEN_SS__ <<
"Error! Only integer aruments allowed for Macros. "
751 <<
"Double style arugment found: " << argPieces[0] <<
"' := " << startValue <<
", " << stepSize << __E__;
772 StringMacros::getNumber(argPieces[1], startValue);
773 StringMacros::getNumber(argPieces[2], stepSize);
775 __GEN_COUTV__(startValue);
776 __GEN_COUTV__(stepSize);
778 __GEN_COUT__ <<
"Creating long argument '" << argPieces[0] <<
"' := " << startValue <<
", " << stepSize << __E__;
780 longDimensionParameters.back().emplace(std::make_pair(
782 std::make_pair(startValue , std::make_pair(startValue , stepSize ))));
789 if(dimensionIterations.size() != longDimensionParameters.size())
791 __GEN_SS__ <<
"Impossible vector size mismatch! " << dimensionIterations.size() <<
" - " << longDimensionParameters.size() << __E__;
797 std::stringstream outSS;
799 outSS <<
"\n==========================\n" << __E__;
800 outSS <<
"Macro '" << macro.macroName_ <<
"' multi-dimensional scan..." << __E__;
801 outSS <<
"\t" << StringMacros::getTimestampString() << __E__;
802 outSS <<
"\t" << dimensionIterations.size() <<
" dimensions defined." << __E__;
803 for(
unsigned int i = 0; i < dimensionIterations.size(); ++i)
806 <<
"dimension[" << i <<
"] has " << dimensionIterations[i] <<
" iterations and " << (longDimensionParameters[i].size())
807 <<
" arguments." << __E__;
809 for(
auto& param : longDimensionParameters[i])
811 <<
"'" << param.first <<
"' of type long with "
812 <<
"initial value and step value [decimal] = "
813 <<
"\t" << param.second.second.first <<
" & " << param.second.second.second << __E__;
816 outSS <<
"\nInput argument names:" << __E__;
817 for(
const auto& inputArgName : macro.namesOfInputArguments_)
818 outSS <<
"\t" << inputArgName << __E__;
819 outSS <<
"\nOutput argument names:" << __E__;
820 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
821 outSS <<
"\t" << outputArgName << __E__;
823 outSS <<
"\n==========================\n" << __E__;
827 __GEN_COUT__ <<
"\n" << outSS.str();
828 if(outputFilePointer)
829 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
832 unsigned int iterationCount = 0;
840 std::function<void(
const unsigned int
842 localRecurse = [&dimensionIterations,
843 &dimensionIterationCnt,
845 &longDimensionParameters,
850 &localRecurse](
const unsigned int dimension) {
853 std::string mfSubject_ =
"multiD-" + std::to_string(dimension) +
"-" + macro.macroName_;
854 __GEN_COUTV__(dimension);
856 if(dimension >= dimensionIterations.size())
858 __GEN_COUT__ <<
"Iteration count: " << iterationCount++ << __E__;
859 __GEN_COUT__ <<
"Launching Macro '" << macro.macroName_ <<
"' ..." << __E__;
869 for(
unsigned int j = 0; j < dimensionIterations.size(); ++j)
871 for(
auto& longParam : longDimensionParameters[j])
873 __GEN_COUT__ <<
"Assigning argIn '" << longParam.first <<
"' to current long value '" << longParam.second.first
874 <<
"' from dimension " << j <<
" parameter." << __E__;
875 variableMap.at(longParam.first) = longParam.second.first;
883 std::stringstream outSS;
885 outSS <<
"\n---------------\n" << __E__;
886 outSS <<
"Macro '" << macro.macroName_ <<
"' execution..." << __E__;
888 <<
"iteration " << iterationCount << __E__;
889 for(
unsigned int i = 0; i < dimensionIterationCnt.size(); ++i)
891 <<
"dimension[" << i <<
"] index := " << dimensionIterationCnt[i] << __E__;
895 <<
"Input arguments (count: " << macro.namesOfInputArguments_.size() <<
"):" << __E__;
896 for(
auto& argIn : macro.namesOfInputArguments_)
897 outSS <<
"\t\t" << argIn <<
" = " << variableMap.at(argIn) << __E__;
902 __GEN_COUT__ <<
"\n" << outSS.str();
903 if(outputFilePointer)
904 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
908 fe->runMacro(macro, variableMap);
910 __GEN_COUT__ <<
"Macro complete!" << __E__;
914 std::stringstream outSS;
918 <<
"Output arguments (count: " << macro.namesOfOutputArguments_.size() <<
"):" << __E__;
919 for(
auto& argOut : macro.namesOfOutputArguments_)
920 outSS <<
"\t\t" << argOut <<
" = " << variableMap.at(argOut) << __E__;
924 __GEN_COUT__ <<
"\n" << outSS.str();
925 if(outputFilePointer)
926 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
933 if(dimension >= dimensionIterationCnt.size())
934 dimensionIterationCnt.push_back(0);
938 <<
"======================================" << __E__ <<
"dimension[" << dimension
939 <<
"] number of iterations := " << dimensionIterations[dimension] << __E__;
944 for(
auto& longPair : longDimensionParameters[dimension])
946 longPair.second.first =
947 longPair.second.second.first;
948 __GEN_COUT__ <<
"arg '" << longPair.first <<
"' current value: " << longPair.second.first << __E__;
954 for(dimensionIterationCnt[dimension] = 0;
955 dimensionIterationCnt[dimension] < dimensionIterations[dimension];
956 ++dimensionIterationCnt[dimension])
958 __GEN_COUT__ <<
"dimension[" << dimension <<
"] index := " << dimensionIterationCnt[dimension] << __E__;
960 localRecurse(dimension + 1);
965 for(
auto& longPair : longDimensionParameters[dimension])
967 longPair.second.first +=
968 longPair.second.second.second;
969 __GEN_COUT__ <<
"arg '" << longPair.first <<
"' current value: " << longPair.second.first << __E__;
975 __GEN_COUT__ <<
"Completed dimension[" << dimension <<
"] number of iterations := " << dimensionIterationCnt[dimension] <<
" of "
976 << dimensionIterations[dimension] << __E__;
983 if(outputFilePointer)
984 fclose(outputFilePointer);
986 catch(
const std::runtime_error& e)
988 __SS__ <<
"Error executing multi-dimensional Macro: " << e.what() << __E__;
989 statusResult = ss.str();
993 __SS__ <<
"Unknown error executing multi-dimensional Macro. " << __E__;
994 statusResult = ss.str();
997 __COUTV__(statusResult);
1000 std::lock_guard<std::mutex> lock(feMgr->macroMultiDimensionalDoneMutex_);
1002 feMgr->macroMultiDimensionalStatusMap_[interfaceID] = statusResult;
1016 __CFG_COUT__ <<
"Started multi-dimensional Macro '" << macroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
1037 void FEVInterfacesManager::startFEMacroMultiDimensional(
const std::string& requester,
1038 const std::string& interfaceID,
1039 const std::string& feMacroName,
1040 const bool enableSavingOutput,
1041 const std::string& outputFilePath,
1042 const std::string& outputFileRadix,
1043 const std::string& inputArgs)
1045 if(requester !=
"iterator")
1047 __CFG_SS__ <<
"Invalid requester '" << requester <<
"'" << __E__;
1051 __CFG_COUT__ <<
"Starting multi-dimensional FE Macro '" << feMacroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
1052 __CFG_COUTV__(inputArgs);
1056 std::lock_guard<std::mutex> lock(macroMultiDimensionalDoneMutex_);
1058 if(macroMultiDimensionalStatusMap_.find(interfaceID) != macroMultiDimensionalStatusMap_.end())
1060 __SS__ <<
"Failed to start multi-dimensional FE Macro '" << feMacroName <<
"' for interface '" << interfaceID
1061 <<
"' - this interface already has an active FE Macro launch!" << __E__;
1064 macroMultiDimensionalStatusMap_.emplace(std::make_pair(interfaceID,
"Active"));
1070 const std::string interfaceID,
1071 const std::string feMacroName,
1072 const bool enableSavingOutput,
1073 const std::string outputFilePath,
1074 const std::string outputFileRadix,
1075 const std::string inputArgsStr) {
1078 std::string mfSubject_ =
"threadMultiD-" + feMacroName;
1079 __GEN_COUT__ <<
"Thread started." << __E__;
1081 std::string statusResult =
"Done";
1087 FEVInterface* fe = feMgr->getFEInterfaceP(interfaceID);
1090 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1091 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1093 __GEN_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID <<
"' was not found!" << __E__;
1100 FILE* outputFilePointer = 0;
1101 if(enableSavingOutput)
1103 std::string filename = outputFilePath +
"/" + outputFileRadix + feMacroName +
"_" + std::to_string(time(0)) +
".txt";
1104 __GEN_COUT__ <<
"Opening file... " << filename << __E__;
1106 outputFilePointer = fopen(filename.c_str(),
"w");
1107 if(!outputFilePointer)
1109 __GEN_SS__ <<
"Failed to open output file: " << filename << __E__;
1116 __GEN_COUTV__(inputArgsStr);
1136 std::vector<
unsigned long > dimensionIterations, dimensionIterationCnt;
1138 using longParamMap_t =
1139 std::map<std::string , std::pair<
long , std::pair<
long ,
long >>>;
1140 using doubleParamMap_t =
1141 std::map<std::string , std::pair<
double , std::pair<
double ,
double >>>;
1143 std::vector<longParamMap_t> longDimensionParameters;
1144 std::vector<doubleParamMap_t> doubleDimensionParameters;
1146 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
1147 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
1149 for(
unsigned int i = 0; i < feMacro.namesOfInputArguments_.size(); ++i)
1150 argsIn.push_back(std::make_pair(
1151 feMacro.namesOfInputArguments_[i],
1153 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1154 argsOut.push_back(std::make_pair(
1155 feMacro.namesOfOutputArguments_[i],
1162 argsIn.push_back(std::make_pair(
"myOtherArg",
"3"));
1164 dimensionIterations.push_back(2);
1165 dimensionIterations.push_back(4);
1167 longDimensionParameters.push_back(longParamMap_t());
1168 longDimensionParameters.push_back(longParamMap_t());
1170 doubleDimensionParameters.push_back(doubleParamMap_t());
1171 doubleDimensionParameters.push_back(doubleParamMap_t());
1173 longDimensionParameters.back().emplace(
1174 std::make_pair(
"myOtherArg", std::make_pair(3 , std::make_pair(3 , 4 ))));
1177 std::vector<std::string> dimensionArgs;
1178 StringMacros::getVectorFromString(inputArgsStr, dimensionArgs, {
';'} );
1180 __GEN_COUTV__(dimensionArgs.size());
1183 if(dimensionArgs.size() == 0)
1188 dimensionIterations.push_back(1);
1189 longDimensionParameters.push_back(longParamMap_t());
1190 doubleDimensionParameters.push_back(doubleParamMap_t());
1193 for(
unsigned int d = 0; d < dimensionArgs.size(); ++d)
1198 std::vector<std::string> args;
1199 StringMacros::getVectorFromString(dimensionArgs[d], args, {
','} );
1205 if(args.size() == 0)
1207 __GEN_SS__ <<
"Invalid dimensional arguments! "
1208 <<
"Need number of iterations at dimension " << d << __E__;
1212 unsigned long numOfIterations;
1213 StringMacros::getNumber(args[0], numOfIterations);
1214 __GEN_COUT__ <<
"Dimension " << d <<
" numOfIterations=" << numOfIterations << __E__;
1218 dimensionIterations.push_back(numOfIterations);
1219 longDimensionParameters.push_back(longParamMap_t());
1220 doubleDimensionParameters.push_back(doubleParamMap_t());
1224 for(
unsigned int a = 1; a < args.size(); ++a)
1226 std::vector<std::string> argPieces;
1227 StringMacros::getVectorFromString(args[a], argPieces, {
':'} );
1229 __GEN_COUTV__(StringMacros::vectorToString(argPieces));
1233 if(argPieces.size() != 3)
1235 __GEN_SS__ <<
"Invalid argument pieces! Should be size "
1237 << argPieces.size() << __E__;
1238 ss << StringMacros::vectorToString(argPieces);
1244 if((argPieces[1].size() && (argPieces[1][argPieces[1].size() - 1] ==
'f' || argPieces[1].find(
'.') != std::string::npos)) ||
1245 (argPieces[2].size() && (argPieces[2][argPieces[2].size() - 1] ==
'f' || argPieces[2].find(
'.') != std::string::npos)))
1250 double startValue = strtod(argPieces[1].c_str(), 0);
1251 double stepSize = strtod(argPieces[2].c_str(), 0);
1253 __GEN_COUTV__(startValue);
1254 __GEN_COUTV__(stepSize);
1256 __GEN_COUT__ <<
"Creating double argument '" << argPieces[0] <<
"' := " << startValue <<
", " << stepSize << __E__;
1258 doubleDimensionParameters.back().emplace(std::make_pair(
1260 std::make_pair(startValue , std::make_pair(startValue , stepSize ))));
1267 long int startValue;
1270 StringMacros::getNumber(argPieces[1], startValue);
1271 StringMacros::getNumber(argPieces[2], stepSize);
1273 __GEN_COUTV__(startValue);
1274 __GEN_COUTV__(stepSize);
1276 __GEN_COUT__ <<
"Creating long argument '" << argPieces[0] <<
"' := " << startValue <<
", " << stepSize << __E__;
1278 longDimensionParameters.back().emplace(std::make_pair(
1280 std::make_pair(startValue , std::make_pair(startValue , stepSize ))));
1287 if(dimensionIterations.size() != longDimensionParameters.size() || dimensionIterations.size() != doubleDimensionParameters.size())
1289 __GEN_SS__ <<
"Impossible vector size mismatch! " << dimensionIterations.size() <<
" - " << longDimensionParameters.size() <<
" - "
1290 << doubleDimensionParameters.size() << __E__;
1296 std::stringstream outSS;
1298 outSS <<
"\n==========================\n" << __E__;
1299 outSS <<
"FEMacro '" << feMacro.feMacroName_ <<
"' multi-dimensional scan..." << __E__;
1300 outSS <<
"\t" << StringMacros::getTimestampString() << __E__;
1301 outSS <<
"\t" << dimensionIterations.size() <<
" dimensions defined." << __E__;
1302 for(
unsigned int i = 0; i < dimensionIterations.size(); ++i)
1305 <<
"dimension[" << i <<
"] has " << dimensionIterations[i] <<
" iterations and "
1306 << (longDimensionParameters[i].size() + doubleDimensionParameters[i].size()) <<
" arguments." << __E__;
1308 for(
auto& param : longDimensionParameters[i])
1310 <<
"'" << param.first <<
"' of type long with "
1311 <<
"initial value and step value [decimal] = "
1312 <<
"\t" << param.second.second.first <<
" & " << param.second.second.second << __E__;
1314 for(
auto& param : doubleDimensionParameters[i])
1316 <<
"'" << param.first <<
"' of type double with "
1317 <<
"initial value and step value = "
1318 <<
"\t" << param.second.second.first <<
" & " << param.second.second.second << __E__;
1321 outSS <<
"\nHere are the identified input arguments:" << __E__;
1322 for(
unsigned int i = 0; i < feMacro.namesOfInputArguments_.size(); ++i)
1323 outSS <<
"\t" << feMacro.namesOfInputArguments_[i] << __E__;
1324 outSS <<
"\nHere are the identified input arguments:" << __E__;
1325 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1326 outSS <<
"\t" << feMacro.namesOfOutputArguments_[i] << __E__;
1328 outSS <<
"\n==========================\n" << __E__;
1332 __GEN_COUT__ <<
"\n" << outSS.str();
1333 if(outputFilePointer)
1334 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1337 unsigned int iterationCount = 0;
1345 std::function<void(
const unsigned int
1347 localRecurse = [&dimensionIterations,
1348 &dimensionIterationCnt,
1350 &longDimensionParameters,
1351 &doubleDimensionParameters,
1357 &localRecurse](
const unsigned int dimension) {
1360 std::string mfSubject_ =
"multiD-" + std::to_string(dimension) +
"-" + feMacro.feMacroName_;
1361 __GEN_COUTV__(dimension);
1363 if(dimension >= dimensionIterations.size())
1365 __GEN_COUT__ <<
"Iteration count: " << iterationCount++ << __E__;
1366 __GEN_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_ <<
"' ..." << __E__;
1377 for(
unsigned int i = 0; i < argsIn.size(); ++i)
1379 foundAsLong =
false;
1380 for(
unsigned int j = 0; j < dimensionIterations.size(); ++j)
1382 auto longIt = longDimensionParameters[j].find(argsIn[i].first);
1383 if(longIt == longDimensionParameters[j].end())
1387 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first <<
"' to current long value '" << longIt->second.first
1388 <<
"' from dimension " << j <<
" parameter." << __E__;
1389 argsIn[i].second = std::to_string(longIt->second.first);
1396 for(
unsigned int j = 0; j < dimensionIterations.size(); ++j)
1398 auto doubleIt = doubleDimensionParameters[j].find(argsIn[i].first);
1399 if(doubleIt == doubleDimensionParameters[j].end())
1403 __GEN_COUT__ <<
"Assigning argIn '" << argsIn[i].first <<
"' to current double value '" << doubleIt->second.first
1404 <<
"' from dimension " << j <<
" parameter." << __E__;
1405 argsIn[i].second = std::to_string(doubleIt->second.first);
1410 __GEN_SS__ <<
"ArgIn '" << argsIn[i].first <<
"' was not assigned a value "
1411 <<
"by any dimensional loop parameter sets. "
1412 "This is illegal. FEMacro '"
1413 << feMacro.feMacroName_ <<
"' requires '" << argsIn[i].first
1414 <<
"' as an input argument. Either remove the "
1415 "input argument from this FEMacro, "
1416 <<
"or define a value as a dimensional loop "
1423 (fe->*(feMacro.macroFunction_))(feMacro, argsIn, argsOut);
1425 __GEN_COUT__ <<
"FE Macro complete!" << __E__;
1429 std::stringstream outSS;
1431 outSS <<
"\n---------------\n" << __E__;
1432 outSS <<
"FEMacro '" << feMacro.feMacroName_ <<
"' execution..." << __E__;
1434 <<
"iteration " << iterationCount << __E__;
1435 for(
unsigned int i = 0; i < dimensionIterationCnt.size(); ++i)
1437 <<
"dimension[" << i <<
"] index := " << dimensionIterationCnt[i] << __E__;
1441 <<
"Input arguments (count: " << argsIn.size() <<
"):" << __E__;
1442 for(
auto& argIn : argsIn)
1443 outSS <<
"\t\t" << argIn.first <<
" = " << argIn.second << __E__;
1447 <<
"Output arguments (count: " << argsOut.size() <<
"):" << __E__;
1448 for(
auto& argOut : argsOut)
1449 outSS <<
"\t\t" << argOut.first <<
" = " << argOut.second << __E__;
1453 __GEN_COUT__ <<
"\n" << outSS.str();
1454 if(outputFilePointer)
1455 fprintf(outputFilePointer,
"%s", outSS.str().c_str());
1462 if(dimension >= dimensionIterationCnt.size())
1463 dimensionIterationCnt.push_back(0);
1466 __GEN_COUT__ <<
"\n"
1467 <<
"======================================" << __E__ <<
"dimension[" << dimension
1468 <<
"] number of iterations := " << dimensionIterations[dimension] << __E__;
1473 for(
auto& longPair : longDimensionParameters[dimension])
1475 longPair.second.first =
1476 longPair.second.second.first;
1477 __GEN_COUT__ <<
"arg '" << longPair.first <<
"' current value: " << longPair.second.first << __E__;
1480 for(
auto& doublePair : doubleDimensionParameters[dimension])
1482 doublePair.second.first =
1483 doublePair.second.second.first;
1484 __GEN_COUT__ <<
"arg '" << doublePair.first <<
"' current value: " << doublePair.second.first << __E__;
1489 for(dimensionIterationCnt[dimension] = 0;
1490 dimensionIterationCnt[dimension] < dimensionIterations[dimension];
1491 ++dimensionIterationCnt[dimension])
1493 __GEN_COUT__ <<
"dimension[" << dimension <<
"] index := " << dimensionIterationCnt[dimension] << __E__;
1495 localRecurse(dimension + 1);
1500 for(
auto& longPair : longDimensionParameters[dimension])
1502 longPair.second.first +=
1503 longPair.second.second.second;
1504 __GEN_COUT__ <<
"arg '" << longPair.first <<
"' current value: " << longPair.second.first << __E__;
1507 for(
auto& doublePair : doubleDimensionParameters[dimension])
1509 doublePair.second.first +=
1510 doublePair.second.second.second;
1512 __GEN_COUT__ <<
"arg '" << doublePair.first <<
"' current value: " << doublePair.second.first << __E__;
1517 __GEN_COUT__ <<
"Completed dimension[" << dimension <<
"] number of iterations := " << dimensionIterationCnt[dimension] <<
" of "
1518 << dimensionIterations[dimension] << __E__;
1525 if(outputFilePointer)
1526 fclose(outputFilePointer);
1528 catch(
const std::runtime_error& e)
1530 __SS__ <<
"Error executing multi-dimensional FE Macro: " << e.what() << __E__;
1531 statusResult = ss.str();
1535 __SS__ <<
"Unknown error executing multi-dimensional FE Macro. " << __E__;
1536 statusResult = ss.str();
1539 __COUTV__(statusResult);
1542 std::lock_guard<std::mutex> lock(feMgr->macroMultiDimensionalDoneMutex_);
1544 feMgr->macroMultiDimensionalStatusMap_[interfaceID] = statusResult;
1557 __CFG_COUT__ <<
"Started multi-dimensional FE Macro '" << feMacroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
1568 bool FEVInterfacesManager::checkMacroMultiDimensional(
const std::string& interfaceID,
const std::string& macroName)
1572 std::lock_guard<std::mutex> lock(macroMultiDimensionalDoneMutex_);
1574 auto statusIt = macroMultiDimensionalStatusMap_.find(interfaceID);
1575 if(statusIt == macroMultiDimensionalStatusMap_.end())
1577 __CFG_SS__ <<
"Status missing for multi-dimensional launch of Macro '" << macroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
1580 else if(statusIt->second ==
"Done")
1582 __CFG_COUT__ <<
"Completed multi-dimensional launch of Macro '" << macroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
1585 macroMultiDimensionalStatusMap_.erase(statusIt);
1588 else if(statusIt->second ==
"Active")
1590 __CFG_COUT__ <<
"Still running multi-dimensional launch of Macro '" << macroName <<
"' for interface '" << interfaceID <<
".'" << __E__;
1595 __CFG_SS__ <<
"Error occured during multi-dimensional launch of Macro '" << macroName <<
"' for interface '" << interfaceID <<
"':" << statusIt->second
1613 void FEVInterfacesManager::runFEMacroByFE(
const std::string& callingInterfaceID,
1614 const std::string& interfaceID,
1615 const std::string& feMacroName,
1616 const std::string& inputArgs,
1617 std::string& outputArgs)
1619 __CFG_COUTV__(callingInterfaceID);
1625 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1626 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1628 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID <<
"' was not found!" << __E__;
1629 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1633 auto& feMacro = FEMacroIt->second;
1635 std::set<std::string> allowedFEsSet;
1636 StringMacros::getSetFromString(feMacro.allowedCallingFrontEnds_, allowedFEsSet);
1639 if(!StringMacros::inWildCardSet(callingInterfaceID, allowedFEsSet))
1641 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID <<
"' does not allow access to calling interfaceID '"
1642 << callingInterfaceID <<
"!' Did the interface add the calling interfaceID "
1643 <<
"to the access list when registering the front-end macro." << __E__;
1644 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1653 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1654 outputArgs += (i ?
"," :
"") + feMacro.namesOfOutputArguments_[i];
1656 __CFG_COUTV__(outputArgs);
1658 runFEMacro(interfaceID, feMacro, inputArgs, outputArgs);
1660 __CFG_COUTV__(outputArgs);
1675 void FEVInterfacesManager::runMacro(
const std::string& interfaceID,
const std::string& macroObjectString,
const std::string& inputArgs, std::string& outputArgs)
1686 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
1688 std::istringstream inputStream(inputArgs);
1689 std::string splitVal, argName, argValue;
1690 while(getline(inputStream, splitVal,
';'))
1692 std::istringstream pairInputStream(splitVal);
1693 getline(pairInputStream, argName,
',');
1694 getline(pairInputStream, argValue,
',');
1695 argsIn.push_back(std::make_pair(argName, argValue));
1700 if(macro.namesOfInputArguments_.size() != argsIn.size())
1702 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_ <<
"' was attempted on interfaceID '" << interfaceID <<
"' with a mismatch in"
1703 <<
" number of input arguments. " << argsIn.size() <<
" were given. " << macro.namesOfInputArguments_.size() <<
" expected." << __E__;
1706 for(
unsigned int i = 0; i < argsIn.size(); ++i)
1707 if(macro.namesOfInputArguments_.find(argsIn[i].first) == macro.namesOfInputArguments_.end())
1709 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_ <<
"' was attempted on interfaceID '" << interfaceID <<
"' with a mismatch in"
1710 <<
" a name of an input argument. " << argsIn[i].first
1711 <<
" was given. Expected: " << StringMacros::setToString(macro.namesOfInputArguments_) << __E__;
1717 std::vector<std::string> returnStrings;
1718 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
1721 std::istringstream inputStream(outputArgs);
1722 std::string argName;
1723 while(getline(inputStream, argName,
','))
1725 __CFG_COUT__ <<
"argName " << argName << __E__;
1727 returnStrings.push_back(
"DEFAULT");
1728 argsOut.push_back(FEVInterface::frontEndMacroArg_t(argName, returnStrings[returnStrings.size() - 1]));
1737 if(macro.namesOfOutputArguments_.size() != argsOut.size())
1739 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_ <<
"' was attempted on interfaceID '" << interfaceID <<
"' with a mismatch in"
1740 <<
" number of output arguments. " << argsOut.size() <<
" were given. " << macro.namesOfOutputArguments_.size() <<
" expected." << __E__;
1744 for(
unsigned int i = 0; i < argsOut.size(); ++i)
1745 if(macro.namesOfOutputArguments_.find(argsOut[i].first) == macro.namesOfOutputArguments_.end())
1747 __CFG_SS__ <<
"MacroMaker Macro '" << macro.macroName_ <<
"' was attempted on interfaceID '" << interfaceID <<
"' with a mismatch in"
1748 <<
" a name of an output argument. " << argsOut[i].first
1749 <<
" were given. Expected: " << StringMacros::setToString(macro.namesOfOutputArguments_) << __E__;
1754 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1756 std::map<std::string , uint64_t > variableMap;
1758 for(
const auto& outputArgName : macro.namesOfOutputArguments_)
1759 variableMap.emplace(
1760 std::pair<std::string /*name*/, uint64_t /*value*/>(outputArgName, 0));
1761 for(
const auto& inputArgName : macro.namesOfInputArguments_)
1762 variableMap.emplace(
1763 std::pair<std::string /*name*/, uint64_t /*value*/>(inputArgName, 0));
1765 for(
auto& argIn : argsIn)
1767 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1768 StringMacros::getNumber(argIn.second, variableMap.at(argIn.first));
1771 fe->runMacro(macro, variableMap);
1773 __CFG_COUT__ <<
"MacroMaker Macro complete!" << __E__;
1775 __CFG_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1776 for(
auto& arg : argsOut)
1778 std::stringstream numberSs;
1779 numberSs << std::dec << variableMap.at(arg.first) <<
" (0x" << std::hex << variableMap.at(arg.first) <<
")" << std::dec;
1780 arg.second = numberSs.str();
1781 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
1786 for(
unsigned int i = 0; i < argsOut.size(); ++i)
1790 outputArgs += argsOut[i].first +
"," + argsOut[i].second;
1793 __CFG_COUT__ <<
"outputArgs = " << outputArgs << __E__;
1808 void FEVInterfacesManager::runFEMacro(
const std::string& interfaceID,
const std::string& feMacroName,
const std::string& inputArgs, std::string& outputArgs)
1814 auto FEMacroIt = fe->getMapOfFEMacroFunctions().find(feMacroName);
1815 if(FEMacroIt == fe->getMapOfFEMacroFunctions().end())
1817 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" << interfaceID <<
"' was not found!" << __E__;
1818 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1822 runFEMacro(interfaceID, FEMacroIt->second, inputArgs, outputArgs);
1837 void FEVInterfacesManager::runFEMacro(
const std::string& interfaceID,
1839 const std::string& inputArgs,
1840 std::string& outputArgs)
1844 std::vector<FEVInterface::frontEndMacroArg_t> argsIn;
1846 std::istringstream inputStream(inputArgs);
1847 std::string splitVal, argName, argValue;
1848 while(getline(inputStream, splitVal,
';'))
1850 std::istringstream pairInputStream(splitVal);
1851 getline(pairInputStream, argName,
',');
1852 getline(pairInputStream, argValue,
',');
1853 argsIn.push_back(std::make_pair(argName, argValue));
1858 if(feMacro.namesOfInputArguments_.size() != argsIn.size())
1860 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '" << interfaceID <<
"' was attempted with a mismatch in"
1861 <<
" number of input arguments. " << argsIn.size() <<
" were given. " << feMacro.namesOfInputArguments_.size() <<
" expected." << __E__;
1862 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1865 for(
unsigned int i = 0; i < argsIn.size(); ++i)
1866 if(argsIn[i].first != feMacro.namesOfInputArguments_[i])
1868 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '" << interfaceID <<
"' was attempted with a mismatch in"
1869 <<
" a name of an input argument. " << argsIn[i].first <<
" was given. " << feMacro.namesOfInputArguments_[i] <<
" expected." << __E__;
1870 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1875 std::vector<std::string> returnStrings;
1876 std::vector<FEVInterface::frontEndMacroArg_t> argsOut;
1879 std::istringstream inputStream(outputArgs);
1880 std::string argName;
1881 while(getline(inputStream, argName,
','))
1883 __CFG_COUT__ <<
"argName " << argName << __E__;
1885 returnStrings.push_back(
"DEFAULT");
1886 argsOut.push_back(FEVInterface::frontEndMacroArg_t(argName, returnStrings[returnStrings.size() - 1]));
1889 __CFG_COUT__ << (uint64_t) & (returnStrings[returnStrings.size() - 1]) << __E__;
1894 if(feMacro.namesOfOutputArguments_.size() != argsOut.size())
1896 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '" << interfaceID <<
"' was attempted with a mismatch in"
1897 <<
" number of output arguments. " << argsOut.size() <<
" were given. " << feMacro.namesOfOutputArguments_.size() <<
" expected." << __E__;
1898 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1901 for(
unsigned int i = 0; i < argsOut.size(); ++i)
1902 if(argsOut[i].first != feMacro.namesOfOutputArguments_[i])
1904 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '" << interfaceID <<
"' was attempted with a mismatch in"
1905 <<
" a name of an output argument. " << argsOut[i].first <<
" were given. " << feMacro.namesOfOutputArguments_[i] <<
" expected."
1907 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1911 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1912 for(
auto& argIn : argsIn)
1913 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1921 __MOUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_ <<
"' ..." << __E__;
1922 __CFG_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_ <<
"' ..." << __E__;
1925 (getFEInterfaceP(interfaceID)->*(feMacro.macroFunction_))(feMacro, argsIn, argsOut);
1927 __CFG_COUT__ <<
"FE Macro complete!" << __E__;
1929 __CFG_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1930 for(
const auto& arg : argsOut)
1931 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
1934 if(feMacro.namesOfOutputArguments_.size() != argsOut.size())
1936 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '" << interfaceID
1937 <<
"' was attempted but the FE macro "
1938 "manipulated the output arguments vector. It is illegal "
1939 "to add or remove output vector name/value pairs."
1941 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1947 for(
unsigned int i = 0; i < argsOut.size(); ++i)
1957 if(StringMacros::getNumber(argsOut[i].second, tmpNumber))
1959 std::stringstream outNumberSs;
1960 outNumberSs << std::dec << tmpNumber <<
" (0x" << std::hex << tmpNumber <<
")" << std::dec;
1961 outputArgs += argsOut[i].first +
"," + outNumberSs.str();
1969 outputArgs += argsOut[i].first +
"," + StringMacros::encodeURIComponent(argsOut[i].second);
1972 __CFG_COUT__ <<
"outputArgs = " << outputArgs << __E__;
1984 std::string FEVInterfacesManager::getFEMacrosString(
const std::string& supervisorName,
const std::string& supervisorLid)
1986 std::string retList =
"";
1988 for(
const auto& it : theFEInterfaces_)
1990 __CFG_COUT__ <<
"FE interface UID = " << it.first << __E__;
1992 retList += supervisorName +
":" + supervisorLid +
":" + it.second->getInterfaceType() +
":" + it.second->getInterfaceUID();
1994 for(
const auto& macroPair : it.second->getMapOfFEMacroFunctions())
1996 __CFG_COUT__ <<
"FE Macro name = " << macroPair.first << __E__;
1997 retList +=
":" + macroPair.first +
":" + std::to_string(macroPair.second.requiredUserPermissions_) +
":" +
1998 std::to_string(macroPair.second.namesOfInputArguments_.size());
1999 for(
const auto& name : macroPair.second.namesOfInputArguments_)
2000 retList +=
":" + name;
2002 retList +=
":" + std::to_string(macroPair.second.namesOfOutputArguments_.size());
2003 for(
const auto& name : macroPair.second.namesOfOutputArguments_)
2004 retList +=
":" + name;
2013 bool FEVInterfacesManager::allFEWorkloopsAreDone(
void)
2015 bool allFEWorkloopsAreDone =
true;
2018 for(
const auto& FEInterface : theFEInterfaces_)
2020 isActive = FEInterface.second->WorkLoop::isActive();
2022 __CFG_COUT__ << FEInterface.second->getInterfaceUID() <<
" of type " << FEInterface.second->getInterfaceType() <<
": \t"
2023 <<
"workLoop_->isActive() " << (isActive ?
"yes" :
"no") << __E__;
2027 allFEWorkloopsAreDone =
false;
2032 return allFEWorkloopsAreDone;
2036 void FEVInterfacesManager::preStateMachineExecutionLoop(
void)
2038 VStateMachine::clearIterationWork();
2039 VStateMachine::clearSubIterationWork();
2041 stateMachinesIterationWorkCount_ = 0;
2043 __CFG_COUT__ <<
"Number of front ends to transition: " << theFENamesByPriority_.size() << __E__;
2045 if(VStateMachine::getIterationIndex() == 0 && VStateMachine::getSubIterationIndex() == 0)
2049 subIterationWorkStateMachineIndex_ = -1;
2051 stateMachinesIterationDone_.clear();
2052 for(
const auto& FEPair : theFEInterfaces_)
2053 stateMachinesIterationDone_[FEPair.first] =
false;
2056 __CFG_COUT__ <<
"Iteration " << VStateMachine::getIterationIndex() <<
"." << VStateMachine::getSubIterationIndex() <<
"("
2057 << (int)subIterationWorkStateMachineIndex_ <<
")" << __E__;
2061 void FEVInterfacesManager::preStateMachineExecution(
unsigned int i,
const std::string& transitionName)
2063 if(i >= theFENamesByPriority_.size())
2065 __CFG_SS__ <<
"FE Interface " << i <<
" not found!" << __E__;
2069 const std::string& name = theFENamesByPriority_[i];
2073 fe->VStateMachine::setTransitionName(transitionName);
2074 fe->VStateMachine::setIterationIndex(VStateMachine::getIterationIndex());
2075 fe->VStateMachine::setSubIterationIndex(VStateMachine::getSubIterationIndex());
2077 fe->VStateMachine::clearIterationWork();
2078 fe->VStateMachine::clearSubIterationWork();
2080 __CFG_COUT__ <<
"theStateMachineImplementation Iteration " << fe->VStateMachine::getIterationIndex() <<
"." << fe->VStateMachine::getSubIterationIndex()
2087 bool FEVInterfacesManager::postStateMachineExecution(
unsigned int i)
2089 if(i >= theFENamesByPriority_.size())
2091 __CFG_SS__ <<
"FE Interface index " << i <<
" not found!" << __E__;
2095 const std::string& name = theFENamesByPriority_[i];
2100 if(fe->VStateMachine::getSubIterationWork())
2102 subIterationWorkStateMachineIndex_ = i;
2103 VStateMachine::indicateSubIterationWork();
2105 __CFG_COUT__ <<
"FE Interface '" << name <<
"' is flagged for another sub-iteration..." << __E__;
2110 subIterationWorkStateMachineIndex_ = -1;
2112 bool& stateMachineDone = stateMachinesIterationDone_[name];
2113 stateMachineDone = !fe->VStateMachine::getIterationWork();
2115 if(!stateMachineDone)
2117 __CFG_COUT__ <<
"FE Interface '" << name <<
"' is flagged for another iteration..." << __E__;
2118 VStateMachine::indicateIterationWork();
2120 ++stateMachinesIterationWorkCount_;
2125 fe->VStateMachine::setTransitionName(
"");
2130 void FEVInterfacesManager::postStateMachineExecutionLoop(
void)
2132 if(VStateMachine::getSubIterationWork())
2133 __CFG_COUT__ <<
"FE Interface state machine implementation " << subIterationWorkStateMachineIndex_ <<
" is flagged for another sub-iteration..."
2135 else if(VStateMachine::getIterationWork())
2136 __CFG_COUT__ << stateMachinesIterationWorkCount_
2137 <<
" FE Interface state machine implementation(s) flagged for "
2138 "another iteration..."
2141 __CFG_COUT__ <<
"Done transitioning all state machine implementations..." << __E__;
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)