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";
19 FEVInterface::FEVInterface(
const std::string& interfaceUID,
21 const std::string& configurationPath)
23 ,
Configurable(theXDAQContextConfigTree, configurationPath)
25 , slowControlsWorkLoop_(interfaceUID +
"-SlowControls", this)
26 , interfaceUID_(interfaceUID)
28 , mfSubject_(interfaceUID)
37 interfaceType_ = theXDAQContextConfigTree_.getBackNode(theConfigurationPath_)
38 .getNode(
"FEInterfacePluginName")
39 .getValue<std::string>();
44 <<
"FEInterface type could not be determined in base class from "
45 "configuration tree path; "
46 "the type may be defined subsequently by the inheriting class (e.g. to "
47 "take advantage of Slow Controls caching functionality, "
48 "the FEInterface type should be defined for all frontend interfaces)"
54 registerFEMacroFunction(
55 "Slow Controls Pause/Resume",
57 &FEVInterface::PauseResumeSlowControls),
58 std::vector<std::string>{
"Pause Slow Controls (Default = false)"},
59 std::vector<std::string>{
"Result"},
62 "This FE Macro is used to Pause or Resume the Slow Controls workloop, which "
63 "could be valuable while debugging front-ends.");
66 __GEN_COUT__ <<
"Constructed." << __E__;
70 FEVInterface::~FEVInterface(
void)
75 __GEN_COUT__ <<
"Destructed." << __E__;
79 void FEVInterface::PauseResumeSlowControls(__ARGS__)
81 slowControlsWorkLoopShouldRun_ =
82 __GET_ARG_IN__(
"Pause Slow Controls (Default = false)",
bool,
false);
83 __FE_COUTV__(slowControlsWorkLoopShouldRun_);
85 std::stringstream outss;
86 outss <<
"Slow Controls workloop is "
87 << (slowControlsWorkLoopShouldRun_ ?
"paused." :
"active.");
89 __SET_ARG_OUT__(
"Result", outss.str());
97 __COUT__ <<
"configureSlowControls path=" << theConfigurationPath_ << __E__;
100 if(metricMan && !metricMan->Running() && metricMan->Initialized())
102 __COUT__ <<
"Metric manager starting..." << __E__;
103 metricMan->do_start();
104 __COUT__ <<
"Metric manager started." << __E__;
106 else if(!metricMan || !metricMan->Initialized())
107 __COUT__ <<
"Metric manager could not be started! metricMan: " << metricMan
108 <<
" Initialized()= " << (metricMan ? metricMan->Initialized() : 0)
111 __COUT__ <<
"Metric manager already started." << __E__;
120 std::string errMessage;
124 theXDAQContextConfigTree_.
getNode(theConfigurationPath_)
125 .
getNode(
"LinkToSlowControlsChannelTable");
135 theXDAQContextConfigTree_.getBackNode(theConfigurationPath_)
136 .
getNode(
"LinkToSlowControlsChannelTable"),
143 theXDAQContextConfigTree_.
getNode(theConfigurationPath_)
144 .
getNode(
"LinkToSlowControlsChannelTable"),
147 catch(
const std::runtime_error& e)
149 __SS__ <<
"Configuring slow controls channels encountered an error: "
156 catch(
const std::runtime_error& e)
158 __SS__ <<
"Error was caught while configuring slow controls: " << e.what() << __E__;
163 __SS__ <<
"Unknown error was caught while configuring slow controls." << __E__;
168 catch(
const std::exception& e)
170 ss <<
"Exception message: " << e.what();
184 std::map<std::string /* ROC UID*/, FESlowControlsChannel>* mapOfSlowControlsChannels)
189 <<
"slowControlsGroupLink is disconnected, so done configuring slow controls."
193 __FE_COUT__ <<
"slowControlsGroupLink is valid! Adding slow controls channels..."
196 std::vector<std::pair<std::string, ConfigurationTree> > groupLinkChildren =
198 for(
auto& groupLinkChild : groupLinkChildren)
201 if(!(groupLinkChild.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
205 __FE_COUT__ <<
"Channel:" << slowControlsGroupLink.
getTableName() <<
"/"
206 << getInterfaceUID() <<
"/" << groupLinkChild.first
207 <<
"\t Type:" << groupLinkChild.second.getNode(
"ChannelDataType")
211 std::string transformation =
"";
215 groupLinkChild.second.getNode(
"Transformation").getValue<std::string>();
219 __FE_COUT__ <<
"Slow controls 'Transformation' setting not found." << __E__;
222 mapOfSlowControlsChannels->insert(std::pair<std::string, FESlowControlsChannel>(
223 groupLinkChild.first,
226 groupLinkChild.first,
227 groupLinkChild.second.getNode(
"ChannelDataType").getValue<std::string>(),
228 groupLinkChild.second.getNode(
"UniversalInterfaceAddress")
229 .getValue<std::string>(),
230 groupLinkChild.second.getNode(
"Transformation").getValue<std::string>(),
231 groupLinkChild.second.getNode(
"UniversalDataBitOffset")
232 .getValue<
unsigned int>(),
233 groupLinkChild.second.getNode(
"ReadAccess").getValue<
bool>(),
234 groupLinkChild.second.getNode(
"WriteAccess").getValue<
bool>(),
235 groupLinkChild.second.getNode(
"MonitoringEnabled").getValue<
bool>(),
236 groupLinkChild.second.getNode(
"RecordChangesOnly").getValue<
bool>(),
237 groupLinkChild.second.getNode(
"DelayBetweenSamplesInSeconds")
239 groupLinkChild.second.getNode(
"LocalSavingEnabled").getValue<
bool>(),
240 groupLinkChild.second.getNode(
"LocalFilePath").getValue<std::string>(),
241 groupLinkChild.second.getNode(
"RadixFileName").getValue<std::string>(),
242 groupLinkChild.second.getNode(
"SaveBinaryFile").getValue<
bool>(),
243 groupLinkChild.second.getNode(
"AlarmsEnabled").getValue<
bool>(),
244 groupLinkChild.second.getNode(
"LatchAlarms").getValue<
bool>(),
245 groupLinkChild.second.getNode(
"LowLowThreshold").getValue<std::string>(),
246 groupLinkChild.second.getNode(
"LowThreshold").getValue<std::string>(),
247 groupLinkChild.second.getNode(
"HighThreshold").getValue<std::string>(),
248 groupLinkChild.second.getNode(
"HighHighThreshold")
249 .getValue<std::string>())));
251 __FE_COUT__ <<
"Added " << mapOfSlowControlsChannels->size()
252 <<
" slow controls channels." << __E__;
271 (slowControlsChannelsIterator_++)->second);
285 __FE_COUT__ <<
"slowControlsRunning" << __E__;
290 <<
"No slow controls channels to monitor, exiting slow controls workloop."
297 const unsigned int txBufferSz = 1500;
298 const unsigned int txBufferFullThreshold = 750;
299 std::string txBuffer;
300 txBuffer.reserve(txBufferSz);
303 theXDAQContextConfigTree_.getBackNode(theConfigurationPath_);
306 std::unique_ptr<UDPDataStreamerBase> slowContrlolsTxSocket;
307 std::string slowControlsSupervisorIPAddress =
"", slowControlsSelfIPAddress =
"";
308 int slowControlsSupervisorPort = 0, slowControlsSelfPort = 0;
312 FEInterfaceNode.
getNode(
"LinkToSlowControlsSupervisorTable");
316 __FE_SS__ <<
"slowControlsInterfaceLink is disconnected, so no socket made."
321 slowControlsSelfIPAddress =
322 FEInterfaceNode.
getNode(
"SlowControlsTxSocketIPAddress")
324 slowControlsSelfPort =
326 slowControlsSupervisorIPAddress =
327 slowControlsInterfaceLink.
getNode(
"IPAddress").
getValue<std::string>();
328 slowControlsSupervisorPort =
333 __FE_COUT__ <<
"Link to slow controls supervisor is missing, so no socket made."
337 bool txBufferUsed =
false;
338 if(slowControlsSupervisorPort && slowControlsSelfPort &&
339 slowControlsSupervisorIPAddress !=
"" && slowControlsSelfIPAddress !=
"")
341 __FE_COUT__ <<
"slowControlsInterfaceLink is valid! Create tx socket..." << __E__;
342 slowContrlolsTxSocket.reset(
344 slowControlsSelfPort,
345 slowControlsSupervisorIPAddress,
346 slowControlsSupervisorPort));
351 __FE_COUT__ <<
"Invalid Slow Controls socket parameters, so no socket made."
358 bool aggregateFileIsBinaryFormat =
false;
361 if(FEInterfaceNode.
getNode(
"SlowControlsLocalAggregateSavingEnabled")
364 aggregateFileIsBinaryFormat =
365 FEInterfaceNode.
getNode(
"SlowControlsSaveBinaryFile").
getValue<
bool>();
367 __FE_COUT_INFO__ <<
"Slow Controls Aggregate Saving turned On BinaryFormat="
368 << aggregateFileIsBinaryFormat << __E__;
370 std::string saveFullFileName =
371 FEInterfaceNode.
getNode(
"SlowControlsLocalFilePath")
374 FEInterfaceNode.
getNode(
"SlowControlsRadixFileName")
377 std::to_string(time(0)) + (aggregateFileIsBinaryFormat ?
".dat" :
".txt");
380 fopen(saveFullFileName.c_str(), aggregateFileIsBinaryFormat ?
"ab" :
"a");
384 <<
"Failed to open slow controls channel file: " << saveFullFileName
390 <<
"Slow controls aggregate file opened: " << saveFullFileName
398 if(!aggregateFileIsBinaryFormat)
399 __FE_COUT_INFO__ <<
"Slow Controls Aggregate Saving turned off." << __E__;
401 time_t timeCounter = 0;
403 unsigned int numOfReadAccessChannels = 0;
404 bool firstTime =
true;
405 while(slowControlsWorkLoop_.getContinueWorkLoop())
411 if(!slowControlsWorkLoopShouldRun_)
415 __FE_COUT__ <<
"txBuffer sz=" << txBuffer.size() << __E__;
426 if(!channel->readAccess_)
430 ++numOfReadAccessChannels;
433 if(timeCounter % channel->delayBetweenSamples_)
436 __FE_COUT__ <<
"Reading Channel:" << channel->fullChannelName
437 <<
" at t=" << time(0) << __E__;
440 bool usingBufferedValue =
false;
441 if(channel->getInterfaceType() != FEVInterface::UNKNOWN_TYPE)
446 channelToCopy !=
nullptr)
448 __FE_COUTT__ <<
"Looking for buffered value at "
449 << BinaryStringMacros::binaryNumberToHexString(
450 channelToCopy->getUniversalAddress(),
"0x",
" ")
451 <<
" " << channelToCopy->getReadSizeBytes() <<
" "
452 << time(0) - channelToCopy->getLastSampleTime() << __E__;
454 __FE_COUTTV__(channel->getInterfaceUID());
455 __FE_COUTTV__(channelToCopy->getInterfaceUID());
456 __FE_COUTTV__(channel->getInterfaceType());
457 __FE_COUTTV__(channelToCopy->getInterfaceType());
459 if(!usingBufferedValue &&
460 channelToCopy->getInterfaceUID() == channel->getInterfaceUID() &&
461 channelToCopy->getInterfaceType() == channel->getInterfaceType() &&
462 BinaryStringMacros::binaryNumberToHexString(
463 channelToCopy->getUniversalAddress(),
"0x",
" ") ==
464 BinaryStringMacros::binaryNumberToHexString(
465 channel->getUniversalAddress(),
"0x",
" ") &&
466 channelToCopy->getReadSizeBytes() == channel->getReadSizeBytes() &&
467 time(0) - channelToCopy->getLastSampleTime() <
470 usingBufferedValue =
true;
472 <<
"Using buffered " << channelToCopy->getReadSizeBytes()
473 <<
"-byte value at address:"
474 << BinaryStringMacros::binaryNumberToHexString(
475 channelToCopy->getUniversalAddress(),
"0x",
" ")
480 << BinaryStringMacros::binaryNumberToHexString(
481 channelToCopy->getLastSampleReadValue(),
"0x",
" ")
482 <<
" at t=" << time(0) << __E__;
483 channel->
handleSample(channelToCopy->getLastSampleReadValue(),
486 aggregateFileIsBinaryFormat,
488 __FE_COUT__ <<
"Copied: "
489 << BinaryStringMacros::binaryNumberToHexString(
490 channel->getSample(),
"0x",
" ")
491 <<
" at t=" << time(0) << __E__;
499 if(!usingBufferedValue)
501 std::string readValInst;
502 std::string& readVal = readValInst;
503 readVal.resize(universalDataSize_);
504 channel->doRead(readVal);
506 readVal, txBuffer, fp, aggregateFileIsBinaryFormat, txBufferUsed);
507 __FE_COUT__ <<
"Have: "
508 << BinaryStringMacros::binaryNumberToHexString(
509 channel->getSample(),
"0x",
" ")
510 <<
" at t=" << time(0) << __E__;
514 __FE_COUT__ <<
"txBuffer sz=" << txBuffer.size() << __E__;
517 if(channel->monitoringEnabled && metricMan && metricMan->Running() &&
518 universalAddressSize_ <= 8)
521 for(
size_t ii = 0; ii < channel->getSample().size(); ++ii)
522 val += (uint8_t)channel->getSample()[ii] << (ii * 8);
525 if((channel->transformation).size() >
528 __FE_COUT__ <<
"Transformation formula = " << channel->transformation
531 TFormula transformationFormula(
"transformationFormula",
532 (channel->transformation).c_str());
533 double transformedVal = transformationFormula.Eval(val);
535 if(!std::isnan(transformedVal))
537 __FE_COUT__ <<
"Transformed " << val <<
" into " << transformedVal
539 __FE_COUT__ <<
"Sending \"" << channel->fullChannelName
540 <<
"\" transformed sample to Metric Manager..."
542 metricMan->sendMetric(channel->fullChannelName,
546 artdaq::MetricMode::LastPoint);
550 __FE_SS__ <<
"Transformed value is NaN!" << __E__;
556 __FE_COUT__ <<
"Sending \"" << channel->fullChannelName
557 <<
"\" sample to Metric Manager..." << __E__;
558 metricMan->sendMetric(channel->fullChannelName,
562 artdaq::MetricMode::LastPoint);
567 __FE_COUT__ <<
"Skipping \"" << channel->fullChannelName
568 <<
"\" sample to Metric Manager... "
569 <<
" channel->monitoringEnabled="
570 << channel->monitoringEnabled <<
" metricMan=" << metricMan
571 <<
" metricMan->Running()="
572 << (metricMan && metricMan->Running()) << __E__;
576 if(txBuffer.size() > txBufferSz)
578 __FE_SS__ <<
"This should never happen hopefully!" << __E__;
582 if(!slowContrlolsTxSocket && txBufferUsed)
586 if(slowContrlolsTxSocket && txBuffer.size() > txBufferFullThreshold)
588 __FE_COUT__ <<
"Sending now! txBufferFullThreshold="
589 << txBufferFullThreshold << __E__;
590 slowContrlolsTxSocket->send(txBuffer);
596 __FE_COUT__ <<
"txBuffer sz=" << txBuffer.size() << __E__;
599 if(slowContrlolsTxSocket && txBuffer.size())
601 __FE_COUT__ <<
"Sending now!" << __E__;
602 slowContrlolsTxSocket->send(txBuffer);
610 if(numOfReadAccessChannels == 0)
613 <<
"There are no slow controls channels with read access!" << __E__;
618 <<
" slow controls channels total. "
619 << numOfReadAccessChannels <<
" with read access enabled."
628 __FE_COUT__ <<
"Slow controls workloop done." << __E__;
637 bool isPauseException =
false;
638 bool isStopException =
false;
646 ss <<
"PAUSE Exception was caught during slow controls running thread: "
647 << e.what() << std::endl;
648 isPauseException =
true;
652 ss <<
"STOP Exception was caught during slow controls running thread: "
653 << e.what() << std::endl;
654 isStopException =
true;
656 catch(
const std::runtime_error& e)
658 ss <<
"Caught an error during slow controls running thread of FE Interface '"
659 << Configurable::theConfigurationRecordName_ <<
"': " << e.what() << __E__;
663 ss <<
"Caught an unknown error during slow controls running thread." << __E__;
668 catch(
const std::exception& e)
670 ss <<
"Exception message: " << e.what();
682 __FE_COUT_ERR__ << ss.str();
686 const std::string errorMessage,
687 bool isPauseException,
688 bool isStopException) {
690 fe, errorMessage, isPauseException, isStopException);
711 const std::string& errorMessage,
712 bool isPauseException,
713 bool isStopException)
716 std::stringstream feHeader;
717 feHeader <<
":FE:" << fe->getInterfaceType() <<
":" << fe->getInterfaceUID() <<
":"
718 << fe->theConfigurationRecordName_ <<
"\t";
722 __COUT_ERR__ << feHeader.str() <<
"Sending FE Async STOP Running Exception... \n"
723 << errorMessage << __E__;
724 fe->VStateMachine::parentSupervisor_->setAsyncPauseExceptionMessage(errorMessage);
726 else if(isPauseException)
728 __COUT_ERR__ << feHeader.str() <<
"Sending FE Async PAUSE Running Exception... \n"
729 << errorMessage << __E__;
730 fe->VStateMachine::parentSupervisor_->setAsyncStopExceptionMessage(errorMessage);
733 __COUT_ERR__ << feHeader.str() <<
"Sending FE Async Running Error... \n"
734 << errorMessage << __E__;
736 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* gatewaySupervisor =
737 fe->VStateMachine::parentSupervisor_->allSupervisorInfo_.getGatewayInfo()
741 parameters.addParameter(
"ErrorMessage", errorMessage);
743 xoap::MessageReference replyMessage =
744 fe->VStateMachine::parentSupervisor_->SOAPMessenger::sendWithSOAPReply(
746 isPauseException ?
"AsyncPauseException" :
"AsyncError",
749 std::stringstream replyMessageSStream;
750 replyMessageSStream << SOAPUtilities::translate(replyMessage);
751 __COUT__ << feHeader.str() <<
"Received... " << replyMessageSStream.str()
754 if(replyMessageSStream.str().find(
"Fault") != std::string::npos)
756 __COUT_ERR__ << feHeader.str() <<
"Failure to indicate fault to Gateway..."
761 catch(
const xdaq::exception::Exception& e)
764 __COUT__ <<
"SOAP message failure indicating front-end asynchronous running SOFT "
765 "error back to Gateway: "
766 << e.what() << __E__;
768 __COUT__ <<
"SOAP message failure indicating front-end asynchronous running "
769 "error back to Gateway: "
770 << e.what() << __E__;
776 __COUT__ <<
"Unknown error encounter indicating front-end asynchronous running "
777 "SOFT error back to Gateway."
780 __COUT__ <<
"Unknown error encounter indicating front-end asynchronous running "
781 "error back to Gateway."
801 bool isPauseException =
false;
802 bool isStopException =
false;
810 ss <<
"SOFT Exception was caught while running: " << e.what() << std::endl;
811 isPauseException =
true;
815 ss <<
"STOP Exception was caught while running: " << e.what() << std::endl;
816 isStopException =
true;
818 catch(
const std::runtime_error& e)
820 ss <<
"Caught an error during running at FE Interface '"
821 << Configurable::theConfigurationRecordName_ <<
"': " << e.what() << __E__;
825 ss <<
"Caught an unknown error during running." << __E__;
830 catch(
const std::exception& e)
832 ss <<
"Exception message: " << e.what();
844 __FE_COUT_ERR__ << ss.str();
848 const std::string errorMessage,
849 bool isPauseException,
850 bool isStopException) {
852 fe, errorMessage, isPauseException, isStopException);
864 return continueWorkLoop_;
876 const std::string& feMacroName,
878 const std::vector<std::string>& namesOfInputArgs,
879 const std::vector<std::string>& namesOfOutputArgs,
880 uint8_t requiredUserPermissions,
881 const std::string& allowedCallingFEs,
882 const std::string& feMacroTooltip)
888 std::to_string(requiredUserPermissions),
893 const std::string& feMacroName,
894 frontEndMacroFunction_t feMacroFunction,
895 const std::vector<std::string>& namesOfInputArgs,
896 const std::vector<std::string>& namesOfOutputArgs,
897 const std::string& requiredUserPermissions,
898 const std::string& allowedCallingFEs,
899 const std::string& feMacroTooltip)
903 __FE_SS__ <<
"feMacroName '" << feMacroName <<
"' already exists! Not allowed."
905 __FE_COUT_ERR__ <<
"\n" << ss.str();
911 frontEndMacroStruct_t(feMacroName,
915 requiredUserPermissions,
927 const std::string& argName)
932 if(pair.first.substr(0, pair.first.find(
'(')) ==
933 argName.substr(0, argName.find(
'(')))
935 __COUT__ << argName <<
": " << pair.second << __E__;
939 __SS__ <<
"Requested input argument '" << argName
940 <<
"' not found in list of arguments." << __E__;
941 ss <<
"\nHere is the list of arguments: \n";
943 ss <<
"\t - " << pair.first <<
"\n";
951 std::string ots::getFEMacroConstArgumentValue<std::string>(
952 FEVInterface::frontEndMacroConstArgs_t& args,
953 const std::string& argName,
954 const std::string& defaultValue)
959 if(data ==
"Default")
968 std::string ots::getFEMacroArgumentValue<std::string>(
969 FEVInterface::frontEndMacroArgs_t& args,
const std::string& argName)
980 const std::string& argName)
982 for(std::pair<
const std::string ,
983 std::string >& pair : args)
985 if(pair.first == argName)
988 __SS__ <<
"Requested argument not found with name '" << argName <<
"'" << __E__;
999 std::map<uint64_t, uint64_t> writeHistory;
1000 uint64_t writeAddress, writeValue, bitMask;
1001 uint8_t bitPosition;
1003 std::string writeBuffer;
1004 std::string readBuffer;
1006 bool ignoreError =
true;
1012 theXDAQContextConfigTree_.
getNode(theConfigurationPath_)
1019 __FE_COUT__ <<
"Disconnected configure sequence" << __E__;
1022 __FE_COUT__ <<
"Handling configure sequence." << __E__;
1024 for(
const auto& child : childrenMap)
1029 child.second.getNode(
"WriteAddress").getValue<uint64_t>();
1030 writeValue = child.second.getNode(
"WriteValue").getValue<uint64_t>();
1032 child.second.getNode(
"StartingBitPosition").getValue<uint8_t>();
1034 (1 << child.second.getNode(
"BitFieldSize").getValue<uint8_t>()) -
1037 writeValue &= bitMask;
1038 writeValue <<= bitPosition;
1039 bitMask = ~(bitMask << bitPosition);
1042 if(writeHistory.find(writeAddress) == writeHistory.end())
1043 writeHistory[writeAddress] = 0;
1045 writeHistory[writeAddress] &= bitMask;
1046 writeHistory[writeAddress] |= writeValue;
1049 "\t Writing %s: \t %ld(0x%lX) \t %ld(0x%lX)",
1050 child.first.c_str(),
1053 writeHistory[writeAddress],
1054 writeHistory[writeAddress]);
1056 __FE_COUT__ << msg << __E__;
1058 universalWrite((
char*)&writeAddress,
1059 (
char*)&(writeHistory[writeAddress]));
1065 ignoreError =
false;
1075 <<
"Unable to access sequence of commands through configuration tree. "
1076 <<
"Assuming no sequence. " << __E__;
1089 const std::string& feMacroName,
1092 const std::vector<FEVInterface::frontEndMacroArg_t>& argsIn,
1093 std::vector<FEVInterface::frontEndMacroArg_t>& argsOut)
1096 auto FEMacroIt = this->getMapOfFEMacroFunctions().find(feMacroName);
1097 if(FEMacroIt == this->getMapOfFEMacroFunctions().end())
1099 __CFG_SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '"
1100 << getInterfaceUID() <<
"' was not found!" << __E__;
1101 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1107 for(
unsigned int i = 0;
1108 i < argsIn.size() && i < feMacro.namesOfInputArguments_.size();
1110 if(argsIn[i].first != feMacro.namesOfInputArguments_[i])
1112 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
1113 << getInterfaceUID() <<
"' was attempted with a mismatch in"
1114 <<
" a name of an input argument. " << argsIn[i].first
1115 <<
" was given. " << feMacro.namesOfInputArguments_[i]
1116 <<
" expected." << __E__;
1117 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1122 if(feMacro.namesOfInputArguments_.size() != argsIn.size())
1124 __CFG_SS__ <<
"FE Macro '" << feMacro.feMacroName_ <<
"' of interfaceID '"
1125 << getInterfaceUID() <<
"' was attempted with a mismatch in"
1126 <<
" number of input arguments. " << argsIn.size() <<
" were given. "
1127 << feMacro.namesOfInputArguments_.size() <<
" expected." << __E__;
1128 __CFG_COUT_ERR__ <<
"\n" << ss.str();
1132 __CFG_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1133 for(
auto& argIn : argsIn)
1134 __CFG_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1136 __CFG_COUT__ <<
"Launching FE Macro '" << feMacro.feMacroName_ <<
"' ..." << __E__;
1139 for(
unsigned int i = 0; i < feMacro.namesOfOutputArguments_.size(); ++i)
1141 feMacro.namesOfOutputArguments_[i],
"DEFAULT"));
1146 __CFG_COUT__ <<
"FE Macro complete!" << __E__;
1148 __CFG_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1149 for(
const auto& arg : argsOut)
1150 __CFG_COUT__ << arg.first <<
": " << arg.second << __E__;
1159 const std::string& targetInterfaceID,
1160 const std::string& feMacroName,
1161 const std::vector<FEVInterface::frontEndMacroArg_t>& inputArgs,
1162 std::vector<FEVInterface::frontEndMacroArg_t>& outputArgs)
const
1164 __FE_COUTV__(targetInterfaceID);
1168 inputArgs,
";" ,
"," );
1170 __FE_COUTV__(inputArgsStr);
1172 xoap::MessageReference message =
1173 SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
1176 parameters.addParameter(
"type",
"feMacro");
1177 parameters.addParameter(
"requester", FEVInterface::interfaceUID_);
1178 parameters.addParameter(
"targetInterfaceID", targetInterfaceID);
1179 parameters.addParameter(
"feMacroName", feMacroName);
1180 parameters.addParameter(
"inputArgs", inputArgsStr);
1181 SOAPUtilities::addParameters(message, parameters);
1183 __FE_COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message)
1186 xoap::MessageReference replyMessage =
1189 .getAllMacroMakerTypeSupervisorInfo()
1191 ->second.getDescriptor(),
1194 __FE_COUT__ <<
"Response received: " << SOAPUtilities::translate(replyMessage)
1198 rxParameters.addParameter(
"Error");
1199 SOAPUtilities::receive(replyMessage, rxParameters);
1201 std::string error = rxParameters.getValue(
"Error");
1206 __FE_SS__ <<
"Error transmitting request to target interface '"
1207 << targetInterfaceID <<
"' from '" << FEVInterface::interfaceUID_
1208 <<
".' " << error << __E__;
1214 argsOutParameter.addParameter(
"outputArgs");
1215 SOAPUtilities::receive(replyMessage, argsOutParameter);
1217 std::string outputArgsStr = argsOutParameter.getValue(
"outputArgs");
1218 std::set<char> pairDelimiter({
';'}), nameValueDelimiter({
','});
1220 std::map<std::string, std::string> mapToReturn;
1222 outputArgsStr, mapToReturn, pairDelimiter, nameValueDelimiter);
1225 for(
auto& mapPair : mapToReturn)
1226 outputArgs.push_back(mapPair);
1236 std::string& retValue,
1237 unsigned int timeoutInSeconds)
const
1239 __FE_COUTV__(requester);
1242 std::string data =
"0";
1248 std::lock_guard<std::mutex> lock(
1251 auto receiveBuffersForTargetIt =
1252 parentInterfaceManager_->frontEndCommunicationReceiveBuffer_.find(
1253 FEVInterface::interfaceUID_);
1254 if(receiveBuffersForTargetIt !=
1255 parentInterfaceManager_->frontEndCommunicationReceiveBuffer_.end())
1257 __FE_COUT__ <<
"Number of source buffers found for front-end '"
1258 << FEVInterface::interfaceUID_
1259 <<
"': " << receiveBuffersForTargetIt->second.size() << __E__;
1261 for(
auto& buffPair : receiveBuffersForTargetIt->second)
1262 __FE_COUTV__(buffPair.first);
1265 std::string sourceBufferId =
"";
1266 std::queue<std::string >& sourceBuffer =
1268 requester, receiveBuffersForTargetIt->second, &sourceBufferId);
1270 __FE_COUT__ <<
"Found source buffer '" << sourceBufferId <<
"' with size "
1271 << sourceBuffer.size() << __E__;
1273 if(sourceBuffer.size())
1275 __FE_COUT__ <<
"Found a value in queue of size "
1276 << sourceBuffer.size() << __E__;
1279 retValue = sourceBuffer.front();
1284 __FE_COUT__ <<
"Source buffer empty for '" << requester <<
"'"
1291 if(!timeoutInSeconds)
1293 __FE_SS__ <<
"Timeout (" << timeoutInSeconds
1294 <<
" s) waiting for front-end communication from " << requester
1303 __FE_COUT__ <<
"Waiting for front-end communication from " << requester <<
" for "
1304 << timeoutInSeconds <<
" more seconds..." << __E__;
1319 unsigned int timeoutInSeconds)
const
1321 std::string retValue;
1330 __COUTVS__(20, macroString);
1336 std::vector<std::string> extractVec;
1343 MACRONAME_NAME_INDEX = 1,
1344 MACRONAME_VALUE_INDEX = 3,
1345 SEQUENCE_NAME_INDEX = 5,
1346 SEQUENCE_VALUE_INDEX = 7,
1347 LSBF_NAME_INDEX = 17,
1348 LSFBF_VALUE_INDEX = 19,
1352 if(MACRONAME_NAME_INDEX >= extractVec.size() ||
1353 extractVec[MACRONAME_NAME_INDEX] !=
"name")
1355 __SS__ <<
"Invalid sequence, 'name' expected in position " << MACRONAME_NAME_INDEX
1359 if(SEQUENCE_NAME_INDEX >= extractVec.size() ||
1360 extractVec[SEQUENCE_NAME_INDEX] !=
"sequence")
1362 __SS__ <<
"Invalid sequence, 'sequence' expected in position "
1363 << SEQUENCE_NAME_INDEX << __E__;
1366 if(LSBF_NAME_INDEX >= extractVec.size() || extractVec[LSBF_NAME_INDEX] !=
"LSBF")
1368 __SS__ <<
"Invalid sequence, 'LSBF' expected in position " << LSBF_NAME_INDEX
1372 macroName_ = extractVec[MACRONAME_VALUE_INDEX];
1373 __COUTVS__(20, macroName_);
1374 lsbf_ = extractVec[LSFBF_VALUE_INDEX] ==
"false" ? false :
true;
1375 __COUTVS__(20,
lsbf_);
1376 std::string& sequence = extractVec[SEQUENCE_VALUE_INDEX];
1377 __COUTVS__(20, sequence);
1379 std::vector<std::string> sequenceCommands;
1384 for(
auto& command : sequenceCommands)
1386 __COUTVS__(20, command);
1391 std::vector<std::string> commandPieces;
1396 __COUTVS__(20, commandPieces.size());
1407 if(commandPieces.size() < 3 || commandPieces.size() > 4 ||
1408 commandPieces[1].size() != 1)
1410 __SS__ <<
"Invalid command type specified in command string: " << command
1417 std::function<bool(
const std::string&
1419 localIsVariable = [](
const std::string& fieldValue) {
1422 __GEN_COUTV__(fieldValue);
1425 for(
const auto& c : fieldValue)
1426 if(!((c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f') ||
1427 (c >=
'A' && c <=
'F')))
1432 if(commandPieces[1][0] ==
'r' && commandPieces.size() == 4)
1434 TLOG_DEBUG(20) << __COUT_HDR__ <<
"Read type found." << __E__;
1438 operations_.push_back(
1439 std::make_pair(macroStruct_t::OP_TYPE_READ, readOps_.size()));
1442 readOps_.back().addressIsVar_ = localIsVariable(commandPieces[2]);
1443 readOps_.back().dataIsVar_ = localIsVariable(commandPieces[3]);
1445 if(!readOps_.back().addressIsVar_)
1449 std::string lsbfData =
"";
1452 commandPieces[2] =
"0" + commandPieces[2];
1453 for(
unsigned int i = 0; i < commandPieces[2].size() / 2; ++i)
1455 __COUTVS__(20, commandPieces[2].size() - 2 * (i + 1));
1458 commandPieces[2][commandPieces[2].size() - 2 * (i + 1)];
1460 commandPieces[2][commandPieces[2].size() - 2 * (i + 1) + 1];
1461 __COUTV__(lsbfData);
1463 __COUTVS__(20, lsbfData);
1468 readOps_.back().address_);
1472 readOps_.back().addressVarName_ = commandPieces[2];
1473 __COUTVS__(20, readOps_.back().addressVarName_);
1475 namesOfInputArguments_.emplace(readOps_.back().addressVarName_);
1478 if(readOps_.back().dataIsVar_)
1480 readOps_.back().dataVarName_ = commandPieces[3];
1481 __COUTVS__(20, readOps_.back().dataVarName_);
1483 namesOfOutputArguments_.emplace(readOps_.back().dataVarName_);
1486 else if(commandPieces[1][0] ==
'w' && commandPieces.size() == 4)
1488 TLOG_DEBUG(20) << __COUT_HDR__ <<
"Write type found." << __E__;
1492 operations_.push_back(
1493 std::make_pair(macroStruct_t::OP_TYPE_WRITE, writeOps_.size()));
1496 writeOps_.back().addressIsVar_ = localIsVariable(commandPieces[2]);
1497 writeOps_.back().dataIsVar_ = localIsVariable(commandPieces[3]);
1499 if(!writeOps_.back().addressIsVar_)
1503 std::string lsbfData =
"";
1506 commandPieces[2] =
"0" + commandPieces[2];
1507 for(
unsigned int i = 0; i < commandPieces[2].size() / 2; ++i)
1509 __COUTV__(commandPieces[2].size() - 2 * (i + 1));
1512 commandPieces[2][commandPieces[2].size() - 2 * (i + 1)];
1514 commandPieces[2][commandPieces[2].size() - 2 * (i + 1) + 1];
1515 __COUTV__(lsbfData);
1517 __COUTVS__(20, lsbfData);
1522 writeOps_.back().address_);
1526 writeOps_.back().addressVarName_ = commandPieces[2];
1527 __COUTVS__(20, writeOps_.back().addressVarName_);
1529 namesOfInputArguments_.emplace(writeOps_.back().addressVarName_);
1532 if(!writeOps_.back().dataIsVar_)
1536 std::string lsbfData =
"";
1539 commandPieces[2] =
"0" + commandPieces[3];
1540 for(
unsigned int i = 0; i < commandPieces[3].size() / 2; ++i)
1542 __COUTVS__(20, commandPieces[3].size() - 2 * (i + 1));
1545 commandPieces[3][commandPieces[3].size() - 2 * (i + 1)];
1547 commandPieces[3][commandPieces[3].size() - 2 * (i + 1) + 1];
1548 __COUTVS__(20, lsbfData);
1550 __COUTV__(lsbfData);
1555 writeOps_.back().data_);
1559 writeOps_.back().dataVarName_ = commandPieces[3];
1560 __COUTVS__(20, writeOps_.back().dataVarName_);
1562 namesOfInputArguments_.emplace(writeOps_.back().dataVarName_);
1565 else if(commandPieces[1][0] ==
'd' && commandPieces.size() == 3)
1567 TLOG_DEBUG(20) << __COUT_HDR__ <<
"Delay type found." << __E__;
1570 operations_.push_back(
1571 std::make_pair(macroStruct_t::OP_TYPE_DELAY, delayOps_.size()));
1574 delayOps_.back().delayIsVar_ = localIsVariable(commandPieces[2]);
1576 if(!delayOps_.back().delayIsVar_)
1580 delayOps_.back().delayVarName_ = commandPieces[2];
1581 __COUTVS__(20, delayOps_.back().delayVarName_);
1583 namesOfInputArguments_.emplace(delayOps_.back().delayVarName_);
1588 __SS__ <<
"Invalid command type '" << commandPieces[1][0]
1589 <<
"' specified with " << commandPieces.size() <<
" components."
1596 __COUT__ << operations_.size() <<
" operations extracted: \n\t" << readOps_.size()
1597 <<
" reads \n\t" << writeOps_.size() <<
" writes \n\t" << delayOps_.size()
1598 <<
" delays" << __E__;
1600 __COUT__ <<
"Input arguments: " << __E__;
1601 for(
const auto& inputArg : namesOfInputArguments_)
1602 __COUT__ <<
"\t" << inputArg << __E__;
1604 __COUT__ <<
"Output arguments: " << __E__;
1605 for(
const auto& outputArg : namesOfOutputArguments_)
1606 __COUT__ <<
"\t" << outputArg << __E__;
1614 std::map<std::string /*name*/, uint64_t /*value*/>& variableMap)
1618 __FE_COUT__ <<
"Running Macro '" << macro.macroName_ <<
"' of "
1619 << macro.operations_.size() <<
" operations." << __E__;
1621 for(
auto& op : macro.operations_)
1623 if(op.first == macroStruct_t::OP_TYPE_READ)
1625 __FE_COUT__ <<
"Doing read op..." << __E__;
1627 if(readOp.addressIsVar_)
1629 __FE_COUTV__(readOp.addressVarName_);
1630 readOp.address_ = variableMap.at(readOp.addressVarName_);
1633 uint64_t dataValue = 0;
1635 __FE_COUT__ << std::hex <<
"Read address: \t 0x" << readOp.address_ << __E__
1640 __FE_COUT__ << std::hex <<
"Read data: \t 0x" << dataValue << __E__
1643 if(readOp.dataIsVar_)
1645 __FE_COUTV__(readOp.dataVarName_);
1646 variableMap.at(readOp.dataVarName_) = dataValue;
1650 else if(op.first == macroStruct_t::OP_TYPE_WRITE)
1652 __FE_COUT__ <<
"Doing write op..." << __E__;
1654 if(writeOp.addressIsVar_)
1656 __FE_COUTV__(writeOp.addressVarName_);
1657 writeOp.address_ = variableMap.at(writeOp.addressVarName_);
1659 if(writeOp.dataIsVar_)
1661 __FE_COUTV__(writeOp.dataVarName_);
1662 writeOp.data_ = variableMap.at(writeOp.dataVarName_);
1665 __FE_COUT__ << std::hex <<
"Write address: \t 0x" << writeOp.address_ << __E__
1667 __FE_COUT__ << std::hex <<
"Write data: \t 0x" << writeOp.data_ << __E__
1670 universalWrite((
char*)&writeOp.address_, (
char*)&writeOp.data_);
1673 else if(op.first == macroStruct_t::OP_TYPE_DELAY)
1675 __FE_COUT__ <<
"Doing delay op..." << __E__;
1678 if(delayOp.delayIsVar_)
1680 __FE_COUTV__(delayOp.delayVarName_);
1681 delayOp.
delay_ = variableMap.at(delayOp.delayVarName_);
1684 __FE_COUT__ << std::dec <<
"Delay ms: \t " << delayOp.
delay_ << __E__;
1686 usleep(delayOp.
delay_ * 1000);
1691 __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)
std::string mfSubject_
for GEN_COUT decorations which would be safe in destructors, e.g. mirror interfaceUID_
std::pair< const std::string, std::string > frontEndMacroArg_t
end Slow Controls
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_
< 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)