1 #include "otsdaq/FECore/FEVInterface.h"
2 #include "otsdaq/CoreSupervisors/CoreSupervisorBase.h"
3 #include "otsdaq/FECore/FEVInterfacesManager.h"
4 #include "otsdaq/Macros/BinaryStringMacros.h"
5 #include "otsdaq/NetworkUtilities/UDPDataStreamerBase.h"
9 #define TRACE_NAME "FEVInterface"
16 const std::string FEVInterface::UNKNOWN_TYPE =
"UNKNOWN";
18 TableViewColumnInfo::DATATYPE_STRING_ALT_DEFAULT;
21 FEVInterface::FEVInterface(
const std::string& interfaceUID,
23 const std::string& configurationPath)
25 ,
Configurable(theXDAQContextConfigTree, configurationPath)
27 , slowControlsWorkLoop_(interfaceUID +
"-SlowControls", this)
28 , interfaceUID_(interfaceUID)
30 , mfSubject_(interfaceUID)
36 VStateMachine::parentSupervisor_ =
nullptr;
40 interfaceType_ = theXDAQContextConfigTree_.getBackNode(theConfigurationPath_)
41 .getNode(
"FEInterfacePluginName")
42 .getValue<std::string>();
47 <<
"FEInterface type could not be determined in base class from "
48 "configuration tree path; "
49 "the type may be defined subsequently by the inheriting class (e.g. to "
50 "take advantage of Slow Controls caching functionality, "
51 "the FEInterface type should be defined for all frontend interfaces)"
57 registerFEMacroFunction(
58 "Slow Controls Pause/Resume",
60 &FEVInterface::PauseResumeSlowControls),
61 std::vector<std::string>{
"Pause Slow Controls (Default = false)"},
62 std::vector<std::string>{
"Result"},
65 "This FE Macro is used to Pause or Resume the Slow Controls workloop, which "
66 "could be valuable while debugging front-ends.");
69 __GEN_COUT__ <<
"Constructed." << __E__;
77 parentInterfaceManager_ = manager;
81 FEVInterface::~FEVInterface(
void)
86 __GEN_COUT__ <<
"Destructed." << __E__;
90 void FEVInterface::PauseResumeSlowControls(__ARGS__)
92 slowControlsWorkLoopShouldRun_ =
93 !__GET_ARG_IN__(
"Pause Slow Controls (Default = false)",
bool,
false);
94 __FE_COUTV__(slowControlsWorkLoopShouldRun_);
96 std::stringstream outss;
97 outss <<
"Slow Controls workloop is "
98 << (slowControlsWorkLoopShouldRun_ ?
"active." :
"paused.");
100 __SET_ARG_OUT__(
"Result", outss.str());
108 __COUT__ <<
"configureSlowControls path=" << theConfigurationPath_ << __E__;
111 if(metricMan && !metricMan->Running() && metricMan->Initialized())
113 __COUT__ <<
"Metric manager starting..." << __E__;
114 metricMan->do_start();
115 __COUT__ <<
"Metric manager started." << __E__;
117 else if(!metricMan || !metricMan->Initialized())
118 __COUT__ <<
"Metric manager could not be started! metricMan: " << metricMan
119 <<
" Initialized()= " << (metricMan ? metricMan->Initialized() : 0)
122 __COUT__ <<
"Metric manager already started." << __E__;
131 std::string errMessage;
135 theXDAQContextConfigTree_.
getNode(theConfigurationPath_)
136 .
getNode(
"LinkToSlowControlsChannelTable");
146 theXDAQContextConfigTree_.getBackNode(theConfigurationPath_)
147 .
getNode(
"LinkToSlowControlsChannelTable"),
154 theXDAQContextConfigTree_.
getNode(theConfigurationPath_)
155 .
getNode(
"LinkToSlowControlsChannelTable"),
158 catch(
const std::runtime_error& e)
160 __SS__ <<
"Configuring slow controls channels encountered an error: "
167 catch(
const std::runtime_error& e)
169 __SS__ <<
"Error was caught while configuring slow controls: " << e.what() << __E__;
174 __SS__ <<
"Unknown error was caught while configuring slow controls." << __E__;
179 catch(
const std::exception& e)
181 ss <<
"Exception message: " << e.what();
195 std::map<std::string /* ROC UID*/, FESlowControlsChannel>* mapOfSlowControlsChannels)
200 <<
"slowControlsGroupLink is disconnected, so done configuring slow controls."
204 __FE_COUT__ <<
"slowControlsGroupLink is valid! Adding slow controls channels..."
207 std::vector<std::pair<std::string, ConfigurationTree> > groupLinkChildren =
209 for(
auto& groupLinkChild : groupLinkChildren)
212 if(!(groupLinkChild.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
216 __FE_COUT__ <<
"Channel:" << slowControlsGroupLink.
getTableName() <<
"/"
217 << getInterfaceUID() <<
"/" << groupLinkChild.first
218 <<
"\t Type:" << groupLinkChild.second.getNode(
"ChannelDataType")
222 std::string transformation =
"";
226 groupLinkChild.second.getNode(
"Transformation").getValue<std::string>();
230 __FE_COUT__ <<
"Slow controls 'Transformation' setting not found." << __E__;
233 mapOfSlowControlsChannels->insert(std::pair<std::string, FESlowControlsChannel>(
234 groupLinkChild.first,
237 groupLinkChild.first,
238 groupLinkChild.second.getNode(
"ChannelDataType").getValue<std::string>(),
239 groupLinkChild.second.getNode(
"UniversalInterfaceAddress")
240 .getValue<std::string>(),
241 groupLinkChild.second.getNode(
"Transformation").getValue<std::string>(),
242 groupLinkChild.second.getNode(
"UniversalDataBitOffset")
243 .getValue<
unsigned int>(),
244 groupLinkChild.second.getNode(
"ReadAccess").getValue<
bool>(),
245 groupLinkChild.second.getNode(
"WriteAccess").getValue<
bool>(),
246 groupLinkChild.second.getNode(
"MonitoringEnabled").getValue<
bool>(),
247 groupLinkChild.second.getNode(
"RecordChangesOnly").getValue<
bool>(),
248 groupLinkChild.second.getNode(
"DelayBetweenSamplesInSeconds")
250 groupLinkChild.second.getNode(
"LocalSavingEnabled").getValue<
bool>(),
251 groupLinkChild.second.getNode(
"LocalFilePath").getValue<std::string>(),
252 groupLinkChild.second.getNode(
"RadixFileName").getValue<std::string>(),
253 groupLinkChild.second.getNode(
"SaveBinaryFile").getValue<
bool>(),
254 groupLinkChild.second.getNode(
"AlarmsEnabled").getValue<
bool>(),
255 groupLinkChild.second.getNode(
"LatchAlarms").getValue<
bool>(),
256 groupLinkChild.second.getNode(
"LowLowThreshold").getValue<std::string>(),
257 groupLinkChild.second.getNode(
"LowThreshold").getValue<std::string>(),
258 groupLinkChild.second.getNode(
"HighThreshold").getValue<std::string>(),
259 groupLinkChild.second.getNode(
"HighHighThreshold")
260 .getValue<std::string>())));
262 __FE_COUT__ <<
"Added " << mapOfSlowControlsChannels->size()
263 <<
" slow controls channels." << __E__;
282 (slowControlsChannelsIterator_++)->second);
296 __FE_COUT__ <<
"slowControlsRunning" << __E__;
301 <<
"No slow controls channels to monitor, exiting slow controls workloop."
308 const unsigned int txBufferSz = 1500;
309 const unsigned int txBufferFullThreshold = 750;
310 std::string txBuffer;
311 txBuffer.reserve(txBufferSz);
314 theXDAQContextConfigTree_.getBackNode(theConfigurationPath_);
317 std::unique_ptr<UDPDataStreamerBase> slowContrlolsTxSocket;
318 std::string slowControlsSupervisorIPAddress =
"", slowControlsSelfIPAddress =
"";
319 int slowControlsSupervisorPort = 0, slowControlsSelfPort = 0;
323 FEInterfaceNode.
getNode(
"LinkToSlowControlsSupervisorTable");
327 __FE_SS__ <<
"slowControlsInterfaceLink is disconnected, so no socket made."
332 slowControlsSelfIPAddress =
333 FEInterfaceNode.
getNode(
"SlowControlsTxSocketIPAddress")
335 slowControlsSelfPort =
337 slowControlsSupervisorIPAddress =
338 slowControlsInterfaceLink.
getNode(
"IPAddress").
getValue<std::string>();
339 slowControlsSupervisorPort =
344 __FE_COUT__ <<
"Link to slow controls supervisor is missing, so no socket made."
348 bool txBufferUsed =
false;
349 if(slowControlsSupervisorPort && slowControlsSelfPort &&
350 slowControlsSupervisorIPAddress !=
"" && slowControlsSelfIPAddress !=
"")
352 __FE_COUT__ <<
"slowControlsInterfaceLink is valid! Create tx socket..." << __E__;
353 slowContrlolsTxSocket.reset(
355 slowControlsSelfPort,
356 slowControlsSupervisorIPAddress,
357 slowControlsSupervisorPort));
362 __FE_COUT__ <<
"Invalid Slow Controls socket parameters, so no socket made."
369 bool aggregateFileIsBinaryFormat =
false;
372 if(FEInterfaceNode.
getNode(
"SlowControlsLocalAggregateSavingEnabled")
375 aggregateFileIsBinaryFormat =
376 FEInterfaceNode.
getNode(
"SlowControlsSaveBinaryFile").
getValue<
bool>();
378 __FE_COUT_INFO__ <<
"Slow Controls Aggregate Saving turned On BinaryFormat="
379 << aggregateFileIsBinaryFormat << __E__;
381 std::string saveFullFileName =
382 FEInterfaceNode.
getNode(
"SlowControlsLocalFilePath")
385 FEInterfaceNode.
getNode(
"SlowControlsRadixFileName")
388 std::to_string(time(0)) + (aggregateFileIsBinaryFormat ?
".dat" :
".txt");
391 fopen(saveFullFileName.c_str(), aggregateFileIsBinaryFormat ?
"ab" :
"a");
395 <<
"Failed to open slow controls channel file: " << saveFullFileName
401 <<
"Slow controls aggregate file opened: " << saveFullFileName
409 if(!aggregateFileIsBinaryFormat)
410 __FE_COUT_INFO__ <<
"Slow Controls Aggregate Saving turned off." << __E__;
412 time_t timeCounter = 0;
414 unsigned int numOfReadAccessChannels = 0;
415 bool firstTime =
true;
416 while(slowControlsWorkLoop_.getContinueWorkLoop())
422 if(!slowControlsWorkLoopShouldRun_)
425 <<
"Skipping slow controls loop... slowControlsWorkLoopShouldRun_ = "
426 << slowControlsWorkLoopShouldRun_ << __E__;
429 __COUTT__ <<
"Starting slow controls loop... slowControlsWorkLoopShouldRun_ = "
430 << slowControlsWorkLoopShouldRun_ << __E__;
433 __FE_COUT__ <<
"txBuffer sz=" << txBuffer.size() << __E__;
444 if(!channel->readAccess_)
448 ++numOfReadAccessChannels;
451 if(timeCounter % channel->delayBetweenSamples_)
454 __FE_COUT__ <<
"Reading Channel:" << channel->fullChannelName
455 <<
" at t=" << time(0) << __E__;
458 bool usingBufferedValue =
false;
459 if(channel->getInterfaceType() != FEVInterface::UNKNOWN_TYPE)
464 channelToCopy !=
nullptr)
466 __FE_COUTT__ <<
"Looking for buffered value at "
467 << BinaryStringMacros::binaryNumberToHexString(
468 channelToCopy->getUniversalAddress(),
"0x",
" ")
469 <<
" " << channelToCopy->getReadSizeBytes() <<
" "
470 << time(0) - channelToCopy->getLastSampleTime() << __E__;
472 __FE_COUTTV__(channel->getInterfaceUID());
473 __FE_COUTTV__(channelToCopy->getInterfaceUID());
474 __FE_COUTTV__(channel->getInterfaceType());
475 __FE_COUTTV__(channelToCopy->getInterfaceType());
477 if(!usingBufferedValue &&
478 channelToCopy->getInterfaceUID() == channel->getInterfaceUID() &&
479 channelToCopy->getInterfaceType() == channel->getInterfaceType() &&
480 BinaryStringMacros::binaryNumberToHexString(
481 channelToCopy->getUniversalAddress(),
"0x",
" ") ==
482 BinaryStringMacros::binaryNumberToHexString(
483 channel->getUniversalAddress(),
"0x",
" ") &&
484 channelToCopy->getReadSizeBytes() == channel->getReadSizeBytes() &&
485 time(0) - channelToCopy->getLastSampleTime() <
488 usingBufferedValue =
true;
490 <<
"Using buffered " << channelToCopy->getReadSizeBytes()
491 <<
"-byte value at address:"
492 << BinaryStringMacros::binaryNumberToHexString(
493 channelToCopy->getUniversalAddress(),
"0x",
" ")
498 << BinaryStringMacros::binaryNumberToHexString(
499 channelToCopy->getLastSampleReadValue(),
"0x",
" ")
500 <<
" at t=" << time(0) << __E__;
501 channel->
handleSample(channelToCopy->getLastSampleReadValue(),
504 aggregateFileIsBinaryFormat,
506 __FE_COUT__ <<
"Copied: "
507 << BinaryStringMacros::binaryNumberToHexString(
508 channel->getSample(),
"0x",
" ")
509 <<
" at t=" << time(0) << __E__;
517 if(!usingBufferedValue)
519 std::string readValInst;
520 std::string& readVal = readValInst;
521 readVal.resize(universalDataSize_);
522 channel->doRead(readVal);
524 readVal, txBuffer, fp, aggregateFileIsBinaryFormat, txBufferUsed);
525 __FE_COUT__ <<
"Have: "
526 << BinaryStringMacros::binaryNumberToHexString(
527 channel->getSample(),
"0x",
" ")
528 <<
" at t=" << time(0) << __E__;
532 __FE_COUT__ <<
"txBuffer sz=" << txBuffer.size() << __E__;
535 if(channel->monitoringEnabled && metricMan && metricMan->Running() &&
536 universalAddressSize_ <= 8)
539 for(
size_t ii = 0; ii < channel->getSample().size(); ++ii)
540 val += (uint8_t)channel->getSample()[ii] << (ii * 8);
543 if((channel->transformation).size() >
546 __FE_COUT__ <<
"Transformation formula = " << channel->transformation
549 TFormula transformationFormula(
"transformationFormula",
550 (channel->transformation).c_str());
551 double transformedVal = transformationFormula.Eval(val);
553 if(!std::isnan(transformedVal))
555 __FE_COUT__ <<
"Transformed " << val <<
" into " << transformedVal
557 __FE_COUT__ <<
"Sending \"" << channel->fullChannelName
558 <<
"\" transformed sample to Metric Manager..."
560 metricMan->sendMetric(channel->fullChannelName,
564 artdaq::MetricMode::LastPoint);
568 __FE_SS__ <<
"Transformed value is NaN!" << __E__;
574 __FE_COUT__ <<
"Sending \"" << channel->fullChannelName
575 <<
"\" sample to Metric Manager..." << __E__;
576 metricMan->sendMetric(channel->fullChannelName,
580 artdaq::MetricMode::LastPoint);
585 __FE_COUT__ <<
"Skipping \"" << channel->fullChannelName
586 <<
"\" sample to Metric Manager... "
587 <<
" channel->monitoringEnabled="
588 << channel->monitoringEnabled <<
" metricMan=" << metricMan
589 <<
" metricMan->Running()="
590 << (metricMan && metricMan->Running()) << __E__;
594 if(txBuffer.size() > txBufferSz)
596 __FE_SS__ <<
"This should never happen hopefully!" << __E__;
600 if(!slowContrlolsTxSocket && txBufferUsed)
604 if(slowContrlolsTxSocket && txBuffer.size() > txBufferFullThreshold)
606 __FE_COUT__ <<
"Sending now! txBufferFullThreshold="
607 << txBufferFullThreshold << __E__;
608 slowContrlolsTxSocket->send(txBuffer);
614 __FE_COUT__ <<
"txBuffer sz=" << txBuffer.size() << __E__;
617 if(slowContrlolsTxSocket && txBuffer.size())
619 __FE_COUT__ <<
"Sending now!" << __E__;
620 slowContrlolsTxSocket->send(txBuffer);
628 if(numOfReadAccessChannels == 0)
631 <<
"There are no slow controls channels with read access!" << __E__;
636 <<
" slow controls channels total. "
637 << numOfReadAccessChannels <<
" with read access enabled."
646 __FE_COUT__ <<
"Slow controls workloop done." << __E__;
655 bool isPauseException =
false;
656 bool isStopException =
false;
664 ss <<
"PAUSE Exception was caught during slow controls running thread: "
665 << e.what() << std::endl;
666 isPauseException =
true;
670 ss <<
"STOP Exception was caught during slow controls running thread: "
671 << e.what() << std::endl;
672 isStopException =
true;
674 catch(
const std::runtime_error& e)
676 ss <<
"Caught an error during slow controls running thread of FE Interface '"
677 << Configurable::theConfigurationRecordName_ <<
"': " << e.what() << __E__;
681 ss <<
"Caught an unknown error during slow controls running thread." << __E__;
686 catch(
const std::exception& e)
688 ss <<
"Exception message: " << e.what();
700 __FE_COUT_ERR__ << ss.str();
704 const std::string errorMessage,
705 bool isPauseException,
706 bool isStopException) {
708 fe, errorMessage, isPauseException, isStopException);
729 const std::string& errorMessage,
730 bool isPauseException,
731 bool isStopException)
734 std::stringstream feHeader;
735 feHeader <<
":FE:" << fe->getInterfaceType() <<
":" << fe->getInterfaceUID() <<
":"
736 << fe->theConfigurationRecordName_ <<
"\t";
740 __COUT_ERR__ << feHeader.str() <<
"Sending FE Async STOP Running Exception... \n"
741 << errorMessage << __E__;
742 fe->VStateMachine::parentSupervisor_->setAsyncPauseExceptionMessage(errorMessage);
744 else if(isPauseException)
746 __COUT_ERR__ << feHeader.str() <<
"Sending FE Async PAUSE Running Exception... \n"
747 << errorMessage << __E__;
748 fe->VStateMachine::parentSupervisor_->setAsyncStopExceptionMessage(errorMessage);
751 __COUT_ERR__ << feHeader.str() <<
"Sending FE Async Running Error... \n"
752 << errorMessage << __E__;
754 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
755 fe->VStateMachine::parentSupervisor_->allSupervisorInfo_.getGatewayInfo()
759 parameters.addParameter(
"ErrorMessage", errorMessage);
761 xoap::MessageReference replyMessage =
762 fe->VStateMachine::parentSupervisor_->SOAPMessenger::sendWithSOAPReply(
764 isPauseException ?
"AsyncPauseException" :
"AsyncError",
767 std::stringstream replyMessageSStream;
768 replyMessageSStream << SOAPUtilities::translate(replyMessage);
769 __COUT__ << feHeader.str() <<
"Received... " << replyMessageSStream.str()
772 if(replyMessageSStream.str().find(
"Fault") != std::string::npos)
774 __COUT_ERR__ << feHeader.str() <<
"Failure to indicate fault to Gateway..."
779 catch(
const xdaq::exception::Exception& e)
782 __COUT__ <<
"SOAP message failure indicating front-end asynchronous running SOFT "
783 "error back to Gateway: "
784 << e.what() << __E__;
786 __COUT__ <<
"SOAP message failure indicating front-end asynchronous running "
787 "error back to Gateway: "
788 << e.what() << __E__;
794 __COUT__ <<
"Unknown error encounter indicating front-end asynchronous running "
795 "SOFT error back to Gateway."
798 __COUT__ <<
"Unknown error encounter indicating front-end asynchronous running "
799 "error back to Gateway."
819 bool isPauseException =
false;
820 bool isStopException =
false;
828 ss <<
"SOFT Exception was caught while running: " << e.what() << std::endl;
829 isPauseException =
true;
833 ss <<
"STOP Exception was caught while running: " << e.what() << std::endl;
834 isStopException =
true;
836 catch(
const std::runtime_error& e)
838 ss <<
"Caught an error during running at FE Interface '"
839 << Configurable::theConfigurationRecordName_ <<
"': " << e.what() << __E__;
843 ss <<
"Caught an unknown error during running." << __E__;
848 catch(
const std::exception& e)
850 ss <<
"Exception message: " << e.what();
862 __FE_COUT_ERR__ << ss.str();
866 const std::string errorMessage,
867 bool isPauseException,
868 bool isStopException) {
870 fe, errorMessage, isPauseException, isStopException);
882 return continueWorkLoop_;
894 const std::string& feMacroName,
896 const std::vector<std::string>& namesOfInputArgs,
897 const std::vector<std::string>& namesOfOutputArgs,
898 uint8_t requiredUserPermissions,
899 const std::string& allowedCallingFEs,
900 const std::string& feMacroTooltip)
906 std::to_string(requiredUserPermissions),
911 const std::string& feMacroName,
912 frontEndMacroFunction_t feMacroFunction,
913 const std::vector<std::string>& namesOfInputArgs,
914 const std::vector<std::string>& namesOfOutputArgs,
915 const std::string& requiredUserPermissions,
916 const std::string& allowedCallingFEs,
917 const std::string& feMacroTooltip)
921 __FE_SS__ <<
"feMacroName '" << feMacroName <<
"' already exists! Not allowed."
923 __FE_COUT_ERR__ <<
"\n" << ss.str();
929 frontEndMacroStruct_t(feMacroName,
933 requiredUserPermissions,
945 const std::string& argName)
947 for(
const frontEndMacroArg_t& pair : args)
950 if(pair.first.substr(0, pair.first.find(
'(')) ==
951 argName.substr(0, argName.find(
'(')))
953 __COUT__ << argName <<
": " << pair.second << __E__;
957 __SS__ <<
"Requested input argument '" << argName
958 <<
"' not found in list of arguments." << __E__;
959 ss <<
"\nHere is the list of arguments: \n";
960 for(
const frontEndMacroArg_t& pair : args)
961 ss <<
"\t - " << pair.first <<
"\n";
969 std::string ots::getFEMacroConstArgumentValue<std::string>(
970 FEVInterface::frontEndMacroConstArgs_t& args,
971 const std::string& argName,
972 const std::string& defaultValue)
977 if(data ==
"Default" || data ==
"DEFAULT")
986 std::string ots::getFEMacroArgumentValue<std::string>(
987 FEVInterface::frontEndMacroArgs_t& args,
const std::string& argName)
998 const std::string& argName)
1000 for(std::pair<
const std::string ,
1001 std::string >& pair : args)
1003 if(pair.first == argName)
1006 __SS__ <<
"Requested argument not found with name '" << argName <<
"'" << __E__;
1017 std::map<uint64_t, uint64_t> writeHistory;
1018 uint64_t writeAddress, writeValue, bitMask;
1019 uint8_t bitPosition;
1021 std::string writeBuffer;
1022 std::string readBuffer;
1024 bool ignoreError =
true;
1030 theXDAQContextConfigTree_.
getNode(theConfigurationPath_)
1037 __FE_COUT__ <<
"Disconnected configure sequence" << __E__;
1040 __FE_COUT__ <<
"Handling configure sequence." << __E__;
1042 for(
const auto& child : childrenMap)
1047 child.second.getNode(
"WriteAddress").getValue<uint64_t>();
1048 writeValue = child.second.getNode(
"WriteValue").getValue<uint64_t>();
1050 child.second.getNode(
"StartingBitPosition").getValue<uint8_t>();
1052 (1 << child.second.getNode(
"BitFieldSize").getValue<uint8_t>()) -
1055 writeValue &= bitMask;
1056 writeValue <<= bitPosition;
1057 bitMask = ~(bitMask << bitPosition);
1060 if(writeHistory.find(writeAddress) == writeHistory.end())
1061 writeHistory[writeAddress] = 0;
1063 writeHistory[writeAddress] &= bitMask;
1064 writeHistory[writeAddress] |= writeValue;
1067 "\t Writing %s: \t %ld(0x%lX) \t %ld(0x%lX)",
1068 child.first.c_str(),
1071 writeHistory[writeAddress],
1072 writeHistory[writeAddress]);
1074 __FE_COUT__ << msg << __E__;
1076 universalWrite((
char*)&writeAddress,
1077 (
char*)&(writeHistory[writeAddress]));
1083 ignoreError =
false;
1093 <<
"Unable to access sequence of commands through configuration tree. "
1094 <<
"Assuming no sequence. " << __E__;
1107 const std::string& feMacroName,
1110 const std::vector<FEVInterface::frontEndMacroArg_t>& argsIn,
1111 std::vector<FEVInterface::frontEndMacroArg_t>& argsOut)
1114 auto FEMacroIt = this->getMapOfFEMacroFunctions().find(feMacroName);
1115 if(FEMacroIt == this->getMapOfFEMacroFunctions().end())
1117 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '"
1118 << getInterfaceUID() <<
"' was not found!" << __E__;
1119 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1125 for(
unsigned int i = 0;
1126 i < argsIn.size() && i < feMacro.namesOfInputArguments_.size();
1128 if(argsIn[i].first != feMacro.namesOfInputArguments_[i])
1130 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
1131 << getInterfaceUID() <<
"' was attempted with a mismatch in"
1132 <<
" a name of an input argument. " << argsIn[i].first
1133 <<
" was given. " << feMacro.namesOfInputArguments_[i]
1134 <<
" expected." << __E__;
1135 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1140 if(feMacro.namesOfInputArguments_.size() != argsIn.size())
1142 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
1143 << getInterfaceUID() <<
"' was attempted with a mismatch in"
1144 <<
" number of input arguments. " << argsIn.size() <<
" were given. "
1145 << feMacro.namesOfInputArguments_.size() <<
" expected." << __E__;
1146 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1150 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1151 for(
auto& argIn : argsIn)
1152 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1154 __CFG_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_ <<
"' ..." << __E__;
1157 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1158 argsOut.push_back(FEVInterface::frontEndMacroArg_t(
1159 feMacro.namesOfOutputArguments_[i],
"DEFAULT"));
1164 __CFG_COUT__ <<
"FE Macro complete!" << __E__;
1166 __CFG_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1167 for(
const auto& arg : argsOut)
1168 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
1177 const std::string& targetInterfaceID,
1178 const std::string& feMacroName,
1179 const std::vector<FEVInterface::frontEndMacroArg_t>& inputArgs,
1180 std::vector<FEVInterface::frontEndMacroArg_t>& outputArgs)
const
1182 __FE_COUTV__(targetInterfaceID);
1187 .getAllMacroMakerTypeSupervisorInfo();
1188 __FE_COUTV__(MacroMakerSupervisors.size());
1190 if(!MacroMakerSupervisors.size())
1192 __FE_SS__ <<
"No MacroMakerSupervisors found! Notify admins." << __E__;
1196 std::vector<FEVInterface::frontEndMacroArg_t> encodedInputArgs;
1197 for(
auto& arg : inputArgs)
1199 __FE_COUT__ << arg.first <<
": " << arg.second << __E__;
1200 encodedInputArgs.push_back(
1201 std::make_pair(StringMacros::encodeURIComponent(arg.first),
1202 StringMacros::encodeURIComponent(arg.second)));
1206 encodedInputArgs,
";" ,
"," );
1208 __FE_COUTV__(inputArgsStr);
1210 xoap::MessageReference message =
1211 SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
1214 parameters.addParameter(
"type",
"feMacro");
1215 parameters.addParameter(
"requester", FEVInterface::interfaceUID_);
1216 parameters.addParameter(
"targetInterfaceID", targetInterfaceID);
1217 parameters.addParameter(
"feMacroName", feMacroName);
1218 parameters.addParameter(
"inputArgs", inputArgsStr);
1219 SOAPUtilities::addParameters(message, parameters);
1221 __FE_COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message)
1224 xoap::MessageReference replyMessage =
1226 MacroMakerSupervisors.begin()->second.getDescriptor(), message);
1228 __FE_COUT__ <<
"Response received: " << SOAPUtilities::translate(replyMessage)
1232 rxParameters.addParameter(
"Error");
1233 SOAPUtilities::receive(replyMessage, rxParameters);
1235 std::string error = rxParameters.getValue(
"Error");
1240 __FE_SS__ <<
"Error transmitting request to target interface '"
1241 << targetInterfaceID <<
"' from '" << FEVInterface::interfaceUID_
1242 <<
".' " << error << __E__;
1248 argsOutParameter.addParameter(
"outputArgs");
1249 SOAPUtilities::receive(replyMessage, argsOutParameter);
1251 std::string outputArgsStr = argsOutParameter.getValue(
"outputArgs");
1252 std::set<char> pairDelimiter({
';'}), nameValueDelimiter({
','});
1254 std::map<std::string, std::string> mapToReturn;
1256 outputArgsStr, mapToReturn, pairDelimiter, nameValueDelimiter);
1259 for(
auto& mapPair : mapToReturn)
1260 outputArgs.push_back(mapPair);
1270 std::string& retValue,
1271 unsigned int timeoutInSeconds)
const
1273 __FE_COUTV__(requester);
1276 std::string data =
"0";
1282 std::lock_guard<std::mutex> lock(
1285 auto receiveBuffersForTargetIt =
1286 parentInterfaceManager_->frontEndCommunicationReceiveBuffer_.find(
1287 FEVInterface::interfaceUID_);
1288 if(receiveBuffersForTargetIt !=
1289 parentInterfaceManager_->frontEndCommunicationReceiveBuffer_.end())
1291 __FE_COUT__ <<
"Number of source buffers found for front-end '"
1292 << FEVInterface::interfaceUID_
1293 <<
"': " << receiveBuffersForTargetIt->second.size() << __E__;
1295 for(
auto& buffPair : receiveBuffersForTargetIt->second)
1296 __FE_COUTV__(buffPair.first);
1299 std::string sourceBufferId =
"";
1300 std::queue<std::string >& sourceBuffer =
1302 requester, receiveBuffersForTargetIt->second, &sourceBufferId);
1304 __FE_COUT__ <<
"Found source buffer '" << sourceBufferId <<
"' with size "
1305 << sourceBuffer.size() << __E__;
1307 if(sourceBuffer.size())
1309 __FE_COUT__ <<
"Found a value in queue of size "
1310 << sourceBuffer.size() << __E__;
1313 retValue = sourceBuffer.front();
1318 __FE_COUT__ <<
"Source buffer empty for '" << requester <<
"'"
1325 if(!timeoutInSeconds)
1327 __FE_SS__ <<
"Timeout (" << timeoutInSeconds
1328 <<
" s) waiting for front-end communication from " << requester
1337 __FE_COUT__ <<
"Waiting for front-end communication from " << requester <<
" for "
1338 << timeoutInSeconds <<
" more seconds..." << __E__;
1353 unsigned int timeoutInSeconds)
const
1355 std::string retValue;
1364 __COUTVS__(20, macroString);
1370 std::vector<std::string> extractVec;
1377 MACRONAME_NAME_INDEX = 1,
1378 MACRONAME_VALUE_INDEX = 3,
1379 SEQUENCE_NAME_INDEX = 5,
1380 SEQUENCE_VALUE_INDEX = 7,
1381 LSBF_NAME_INDEX = 17,
1382 LSFBF_VALUE_INDEX = 19,
1386 if(MACRONAME_NAME_INDEX >= extractVec.size() ||
1387 extractVec[MACRONAME_NAME_INDEX] !=
"name")
1389 __SS__ <<
"Invalid sequence, 'name' expected in position " << MACRONAME_NAME_INDEX
1393 if(SEQUENCE_NAME_INDEX >= extractVec.size() ||
1394 extractVec[SEQUENCE_NAME_INDEX] !=
"sequence")
1396 __SS__ <<
"Invalid sequence, 'sequence' expected in position "
1397 << SEQUENCE_NAME_INDEX << __E__;
1400 if(LSBF_NAME_INDEX >= extractVec.size() || extractVec[LSBF_NAME_INDEX] !=
"LSBF")
1402 __SS__ <<
"Invalid sequence, 'LSBF' expected in position " << LSBF_NAME_INDEX
1406 macroName_ = extractVec[MACRONAME_VALUE_INDEX];
1407 __COUTVS__(20, macroName_);
1408 lsbf_ = extractVec[LSFBF_VALUE_INDEX] ==
"false" ? false :
true;
1409 __COUTVS__(20,
lsbf_);
1410 std::string& sequence = extractVec[SEQUENCE_VALUE_INDEX];
1411 __COUTVS__(20, sequence);
1413 std::vector<std::string> sequenceCommands;
1418 for(
auto& command : sequenceCommands)
1420 __COUTVS__(20, command);
1425 std::vector<std::string> commandPieces;
1430 __COUTVS__(20, commandPieces.size());
1441 if(commandPieces.size() < 3 || commandPieces.size() > 4 ||
1442 commandPieces[1].size() != 1)
1444 __SS__ <<
"Invalid command type specified in command string: " << command
1451 std::function<bool(
const std::string&
1453 localIsVariable = [](
const std::string& fieldValue) {
1456 __GEN_COUTVS__(20, fieldValue);
1459 for(
const auto& c : fieldValue)
1460 if(!((c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f') ||
1461 (c >=
'A' && c <=
'F')))
1466 if(commandPieces[1][0] ==
'r' && commandPieces.size() == 4)
1468 TLOG_DEBUG(20) << __COUT_HDR__ <<
"Read type found." << __E__;
1472 operations_.push_back(
1473 std::make_pair(macroStruct_t::OP_TYPE_READ, readOps_.size()));
1476 readOps_.back().addressIsVar_ = localIsVariable(commandPieces[2]);
1477 readOps_.back().dataIsVar_ = localIsVariable(commandPieces[3]);
1479 if(!readOps_.back().addressIsVar_)
1483 std::string lsbfData =
"";
1486 commandPieces[2] =
"0" + commandPieces[2];
1487 for(
unsigned int i = 0; i < commandPieces[2].size() / 2; ++i)
1489 __COUTVS__(20, commandPieces[2].size() - 2 * (i + 1));
1492 commandPieces[2][commandPieces[2].size() - 2 * (i + 1)];
1494 commandPieces[2][commandPieces[2].size() - 2 * (i + 1) + 1];
1495 __COUTV__(lsbfData);
1497 __COUTVS__(20, lsbfData);
1502 readOps_.back().address_);
1506 readOps_.back().addressVarName_ = commandPieces[2];
1507 __COUTVS__(20, readOps_.back().addressVarName_);
1509 namesOfInputArguments_.emplace(readOps_.back().addressVarName_);
1512 if(readOps_.back().dataIsVar_)
1514 readOps_.back().dataVarName_ = commandPieces[3];
1515 __COUTVS__(20, readOps_.back().dataVarName_);
1517 namesOfOutputArguments_.emplace(readOps_.back().dataVarName_);
1520 else if(commandPieces[1][0] ==
'w' && commandPieces.size() == 4)
1522 TLOG_DEBUG(20) << __COUT_HDR__ <<
"Write type found." << __E__;
1526 operations_.push_back(
1527 std::make_pair(macroStruct_t::OP_TYPE_WRITE, writeOps_.size()));
1530 writeOps_.back().addressIsVar_ = localIsVariable(commandPieces[2]);
1531 writeOps_.back().dataIsVar_ = localIsVariable(commandPieces[3]);
1533 if(!writeOps_.back().addressIsVar_)
1537 std::string lsbfData =
"";
1540 commandPieces[2] =
"0" + commandPieces[2];
1541 for(
unsigned int i = 0; i < commandPieces[2].size() / 2; ++i)
1543 __COUTV__(commandPieces[2].size() - 2 * (i + 1));
1546 commandPieces[2][commandPieces[2].size() - 2 * (i + 1)];
1548 commandPieces[2][commandPieces[2].size() - 2 * (i + 1) + 1];
1549 __COUTV__(lsbfData);
1551 __COUTVS__(20, lsbfData);
1556 writeOps_.back().address_);
1560 writeOps_.back().addressVarName_ = commandPieces[2];
1561 __COUTVS__(20, writeOps_.back().addressVarName_);
1563 namesOfInputArguments_.emplace(writeOps_.back().addressVarName_);
1566 if(!writeOps_.back().dataIsVar_)
1570 std::string lsbfData =
"";
1573 commandPieces[2] =
"0" + commandPieces[3];
1574 for(
unsigned int i = 0; i < commandPieces[3].size() / 2; ++i)
1576 __COUTVS__(20, commandPieces[3].size() - 2 * (i + 1));
1579 commandPieces[3][commandPieces[3].size() - 2 * (i + 1)];
1581 commandPieces[3][commandPieces[3].size() - 2 * (i + 1) + 1];
1582 __COUTVS__(20, lsbfData);
1584 __COUTV__(lsbfData);
1589 writeOps_.back().data_);
1593 writeOps_.back().dataVarName_ = commandPieces[3];
1594 __COUTVS__(20, writeOps_.back().dataVarName_);
1596 namesOfInputArguments_.emplace(writeOps_.back().dataVarName_);
1599 else if(commandPieces[1][0] ==
'd' && commandPieces.size() == 3)
1601 TLOG_DEBUG(20) << __COUT_HDR__ <<
"Delay type found." << __E__;
1604 operations_.push_back(
1605 std::make_pair(macroStruct_t::OP_TYPE_DELAY, delayOps_.size()));
1608 delayOps_.back().delayIsVar_ = localIsVariable(commandPieces[2]);
1610 if(!delayOps_.back().delayIsVar_)
1614 delayOps_.back().delayVarName_ = commandPieces[2];
1615 __COUTVS__(20, delayOps_.back().delayVarName_);
1617 namesOfInputArguments_.emplace(delayOps_.back().delayVarName_);
1622 __SS__ <<
"Invalid command type '" << commandPieces[1][0]
1623 <<
"' specified with " << commandPieces.size() <<
" components."
1630 __COUTT__ << operations_.size() <<
" operations extracted: \n\t" << readOps_.size()
1631 <<
" reads \n\t" << writeOps_.size() <<
" writes \n\t" << delayOps_.size()
1632 <<
" delays" << __E__;
1634 __COUTT__ <<
"Input arguments: " << __E__;
1635 for(
const auto& inputArg : namesOfInputArguments_)
1636 __COUTT__ <<
"\t" << inputArg << __E__;
1638 __COUTT__ <<
"Output arguments: " << __E__;
1639 for(
const auto& outputArg : namesOfOutputArguments_)
1640 __COUTT__ <<
"\t" << outputArg << __E__;
1648 std::map<std::string /*name*/, uint64_t /*value*/>& variableMap)
1652 __FE_COUT__ <<
"Running Macro '" << macro.macroName_ <<
"' of "
1653 << macro.operations_.size() <<
" operations." << __E__;
1655 for(
auto& op : macro.operations_)
1657 if(op.first == macroStruct_t::OP_TYPE_READ)
1659 __FE_COUT__ <<
"Doing read op..." << __E__;
1661 if(readOp.addressIsVar_)
1663 __FE_COUTV__(readOp.addressVarName_);
1664 readOp.address_ = variableMap.at(readOp.addressVarName_);
1667 uint64_t dataValue = 0;
1669 __FE_COUT__ << std::hex <<
"Read address: \t 0x" << readOp.address_ << __E__
1674 __FE_COUT__ << std::hex <<
"Read data: \t 0x" << dataValue << __E__
1677 if(readOp.dataIsVar_)
1679 __FE_COUTV__(readOp.dataVarName_);
1680 variableMap.at(readOp.dataVarName_) = dataValue;
1684 else if(op.first == macroStruct_t::OP_TYPE_WRITE)
1686 __FE_COUT__ <<
"Doing write op..." << __E__;
1688 if(writeOp.addressIsVar_)
1690 __FE_COUTV__(writeOp.addressVarName_);
1691 writeOp.address_ = variableMap.at(writeOp.addressVarName_);
1693 if(writeOp.dataIsVar_)
1695 __FE_COUTV__(writeOp.dataVarName_);
1696 writeOp.data_ = variableMap.at(writeOp.dataVarName_);
1699 __FE_COUT__ << std::hex <<
"Write address: \t 0x" << writeOp.address_ << __E__
1701 __FE_COUT__ << std::hex <<
"Write data: \t 0x" << writeOp.data_ << __E__
1704 universalWrite((
char*)&writeOp.address_, (
char*)&writeOp.data_);
1707 else if(op.first == macroStruct_t::OP_TYPE_DELAY)
1709 __FE_COUT__ <<
"Doing delay op..." << __E__;
1712 if(delayOp.delayIsVar_)
1714 __FE_COUTV__(delayOp.delayVarName_);
1715 delayOp.
delay_ = variableMap.at(delayOp.delayVarName_);
1718 __FE_COUT__ << std::dec <<
"Delay ms: \t " << delayOp.
delay_ << __E__;
1720 usleep(delayOp.
delay_ * 1000);
1725 __FE_SS__ <<
"Invalid command type '" << op.first <<
"!'" << __E__;
bool isDisconnected(void) const
ConfigurationTree getNode(const std::string &nodeName, bool doNotThrowOnBrokenUIDLinks=false) const
navigating between nodes
const std::string & getTableName(void) const
getTableName
std::map< std::string, ConfigurationTree > getChildrenMap(std::map< std::string, std::string > filterMap=std::map< std::string, std::string >(), bool onlyStatusTrue=false) const
void getValue(T &value) 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 handleSample(const std::string &universalReadValue, std::string &txBuffer, FILE *fpAggregate=0, bool aggregateIsBinaryFormat=false, bool txBufferUsed=true)
static std::string underscoreString(const std::string &str)
void runMacro(FEVInterface::macroStruct_t ¯o, std::map< std::string, uint64_t > &variableMap)
runMacro
virtual void resetSlowControlsChannelIterator(void)
virtual in case channels are handled in multiple maps, for example
void(ots::FEVInterface::*)(const frontEndMacroStruct_t &feMacroStruct, FEVInterface::frontEndMacroConstArgs_t argsIn, FEVInterface::frontEndMacroArgs_t argsOut) frontEndMacroFunction_t
void function (vector-of-inputs, vector-of-outputs)
virtual void configureSlowControls(void)
end State Machine handlers
static void sendAsyncExceptionToGateway(FEVInterface *fe, const std::string &errMsg, bool isPauseException, bool isStopException)
void runSequenceOfCommands(const std::string &treeLinkName)
std::map< std::string, frontEndMacroStruct_t > mapOfFEMacroFunctions_
Map of FE Macro functions members.
static const std::string & getFEMacroConstArgument(frontEndMacroConstArgs_t args, const std::string &argName)
< for specialized access to FE Macro in/out arguments
void addSlowControlsChannels(ConfigurationTree slowControlsGroupLink, std::map< std::string, FESlowControlsChannel > *mapOfSlowControlsChannels)
static const std::string DEFAULT
end Slow Controls
std::string mfSubject_
for GEN_COUT decorations which would be safe in destructors, e.g. mirror interfaceUID_
virtual FESlowControlsChannel * getNextSlowControlsChannel(void)
virtual in case channels are handled in multiple maps, for example
void runFrontEndMacro(const std::string &targetInterfaceID, const std::string &feMacroName, const std::vector< FEVInterface::frontEndMacroArg_t > &inputArgs, std::vector< FEVInterface::frontEndMacroArg_t > &outputArgs) const
virtual void universalRead(char *address, char *returnValue)=0
throw std::runtime_error exception on error/timeout
void runSelfFrontEndMacro(const std::string &feMacroName, const std::vector< FEVInterface::frontEndMacroArg_t > &inputArgs, std::vector< FEVInterface::frontEndMacroArg_t > &outputArgs)
static std::string & getFEMacroArgument(frontEndMacroArgs_t args, const std::string &argName)
virtual bool running(void)
bool slowControlsRunning(void)
slow controls workloop calls this
virtual unsigned int getSlowControlsChannelCount(void)
virtual in case channels are handled in multiple maps, for example
void receiveFromFrontEnd(const std::string &requester, T &retValue, unsigned int timeoutInSeconds=1) const
bool workLoopThread(toolbox::task::WorkLoop *workLoop)
end FE Communication helpers //////
void registerFEMacroFunction(const std::string &feMacroName, frontEndMacroFunction_t feMacroFunction, const std::vector< std::string > &namesOfInputArgs, const std::vector< std::string > &namesOfOutputArgs, uint8_t requiredUserPermissions=1, const std::string &allowedCallingFEs="*", const std::string &feMacroTooltip="")
std::map< std::string, FESlowControlsChannel > mapOfSlowControlsChannels_
Slow Controls members.
std::mutex frontEndCommunicationReceiveMutex_
FE communication helpers.
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.
uint64_t delay_
milliseconds
macroStruct_t(const std::string ¯oString)
macroStruct_t constructor
bool lsbf_
least significant byte first
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 std::string vectorToString(const std::vector< T > &setToReturn, const std::string &delimeter=", ")
vectorToString ~
static T & getWildCardMatchFromMap(const std::string &needle, std::map< std::string, T > &haystack, std::string *foundKey=0)
defined in included .icc source
static void getMapFromString(const std::string &inputString, std::map< S, T > &mapToReturn, const std::set< char > &pairPairDelimiter={',', '|', '&'}, const std::set< char > &nameValueDelimiter={'=', ':'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'})
getMapFromString ~
static bool getNumber(const std::string &s, T &retValue)