1 #include "otsdaq-core/FECore/FEVInterface.h"
2 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 #include "otsdaq-core/NetworkUtilities/UDPDataStreamerBase.h"
13 void FEVInterface::configureSlowControls(
void)
16 theXDAQContextConfigTree_.getBackNode(
17 theConfigurationPath_).getNode(
"LinkToSlowControlChannelsConfiguration");
19 if(slowControlsGroupLink.isDisconnected())
21 __COUT__ <<
"slowControlsGroupLink is disconnected, so done configuring slow controls." <<
25 __COUT__ <<
"slowControlsGroupLink is valid! Configuring slow controls..." <<
28 mapOfSlowControlsChannels_.clear();
29 std::vector<std::pair<std::string,ConfigurationTree> > groupLinkChildren =
30 slowControlsGroupLink.getChildren();
31 for(
auto &groupLinkChild: groupLinkChildren)
34 if(!(groupLinkChild.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>()))
continue;
36 __COUT__ <<
"Channel:" << getInterfaceUID() <<
37 "/" << groupLinkChild.first <<
"\t Type:" <<
38 groupLinkChild.second.getNode(
"ChannelDataType") <<
41 mapOfSlowControlsChannels_.insert(
42 std::pair<std::string,FESlowControlsChannel>(
47 groupLinkChild.second.getNode(
"ChannelDataType").getValue<std::string>(),
49 universalAddressSize_,
50 groupLinkChild.second.getNode(
"UniversalInterfaceAddress").getValue <std::string>(),
51 groupLinkChild.second.getNode(
"UniversalDataBitOffset").getValue <
unsigned int>(),
52 groupLinkChild.second.getNode(
"ReadAccess").getValue <
bool>(),
53 groupLinkChild.second.getNode(
"WriteAccess").getValue <
bool>(),
54 groupLinkChild.second.getNode(
"MonitoringEnabled").getValue <
bool>(),
55 groupLinkChild.second.getNode(
"RecordChangesOnly").getValue <
bool>(),
56 groupLinkChild.second.getNode(
"DelayBetweenSamplesInSeconds").getValue <time_t>(),
57 groupLinkChild.second.getNode(
"LocalSavingEnabled").getValue <
bool>(),
58 groupLinkChild.second.getNode(
"LocalFilePath").getValue <std::string>(),
59 groupLinkChild.second.getNode(
"RadixFileName").getValue <std::string>(),
60 groupLinkChild.second.getNode(
"SaveBinaryFile").getValue <
bool>(),
61 groupLinkChild.second.getNode(
"AlarmsEnabled").getValue <
bool>(),
62 groupLinkChild.second.getNode(
"LatchAlarms").getValue <
bool>(),
63 groupLinkChild.second.getNode(
"LowLowThreshold").getValue <std::string>(),
64 groupLinkChild.second.getNode(
"LowThreshold").getValue <std::string>(),
65 groupLinkChild.second.getNode(
"HighThreshold").getValue <std::string>(),
66 groupLinkChild.second.getNode(
"HighHighThreshold").getValue <std::string>()
73 bool FEVInterface::slowControlsRunning(
void)
75 __COUT__ <<
"slowControlsRunning" << std::endl;
77 readVal.resize(universalDataSize_);
81 const unsigned int txBufferSz = 1500;
82 const unsigned int txBufferFullThreshold = 750;
84 txBuffer.reserve(txBufferSz);
87 theConfigurationPath_);
90 FEInterfaceNode.getNode(
"LinkToSlowControlsMonitorConfiguration");
92 std::unique_ptr<UDPDataStreamerBase> txSocket;
94 if(slowControlsInterfaceLink.isDisconnected())
96 __COUT__ <<
"slowControlsInterfaceLink is disconnected, so no socket made." <<
101 __COUT__ <<
"slowControlsInterfaceLink is valid! Create tx socket..." <<
104 FEInterfaceNode.getNode(
"SlowControlsTxSocketIPAddress").getValue <std::string>(),
105 FEInterfaceNode.getNode(
"SlowControlsTxSocketPort").getValue <
int>(),
106 slowControlsInterfaceLink.getNode(
"IPAddress").getValue <std::string>(),
107 slowControlsInterfaceLink.getNode(
"Port").getValue <
int>()
116 bool aggregateFileIsBinaryFormat =
false;
117 if(FEInterfaceNode.getNode(
"SlowControlsLocalAggregateSavingEnabled").getValue<
bool>())
119 aggregateFileIsBinaryFormat =
120 FEInterfaceNode.getNode(
"SlowControlsSaveBinaryFile").getValue<
bool>();
122 __COUT_INFO__ <<
"Slow Controls Aggregate Saving turned On BinaryFormat=" <<
123 aggregateFileIsBinaryFormat << std::endl;
125 std::string saveFullFileName =
126 FEInterfaceNode.getNode(
"SlowControlsLocalFilePath").getValue<std::string>() +
128 FEInterfaceNode.getNode(
"SlowControlsRadixFileName").getValue<std::string>() +
130 FESlowControlsChannel::underscoreString(getInterfaceUID()) +
131 "-" + std::to_string(time(0)) +
132 (aggregateFileIsBinaryFormat?
".dat":
".txt");
135 fp = fopen(saveFullFileName.c_str(),
136 aggregateFileIsBinaryFormat?
140 __COUT_ERR__ <<
"Failed to open slow controls channel file: " <<
141 saveFullFileName << std::endl;
145 __COUT_INFO__ <<
"Slow controls aggregate file opened: " <<
146 saveFullFileName << std::endl;
149 __COUT_INFO__ <<
"Slow Controls Aggregate Saving turned off." << std::endl;
152 time_t timeCounter = 0;
154 while(slowControlsWorkLoop_.getContinueWorkLoop())
160 __COUT__ <<
"txBuffer sz=" << txBuffer.size() << std::endl;
167 for(
auto &slowControlsChannelPair : mapOfSlowControlsChannels_)
169 channel = &slowControlsChannelPair.second;
172 if(!channel->readAccess_)
continue;
175 if(timeCounter % channel->delayBetweenSamples_)
continue;
178 __COUT__ <<
"Channel:" << getInterfaceUID() <<
179 "/" << slowControlsChannelPair.first << std::endl;
180 __COUT__ <<
"Monitoring..." << std::endl;
182 universalRead(channel->getUniversalAddress(),
195 channel->handleSample(readVal,txBuffer, fp, aggregateFileIsBinaryFormat);
197 __COUT__ <<
"txBuffer sz=" << txBuffer.size() << std::endl;
200 if(txBuffer.size() > txBufferSz)
202 __SS__ <<
"This should never happen hopefully!" << std::endl;
203 __COUT_ERR__ <<
"\n" << ss.str();
204 throw std::runtime_error(ss.str());
209 txBuffer.size() > txBufferFullThreshold)
211 __COUT__ <<
"Sending now! txBufferFullThreshold=" << txBufferFullThreshold << std::endl;
212 txSocket->send(txBuffer);
220 __COUT__ <<
"txBuffer sz=" << txBuffer.size() << std::endl;
226 __COUT__ <<
"Sending now!" << std::endl;
227 txSocket->send(txBuffer);
244 void FEVInterface::registerFEMacroFunction(
245 const std::string &feMacroName, frontEndMacroFunction_t feMacroFunction,
246 const std::vector<std::string> &namesOfInputArgs,
247 const std::vector<std::string> &namesOfOutputArgs,
248 uint8_t requiredUserPermissions)
250 if(mapOfFEMacroFunctions_.find(feMacroName) !=
251 mapOfFEMacroFunctions_.end())
253 __SS__ <<
"feMacroName '" << feMacroName <<
"' already exists! Not allowed." << std::endl;
254 __COUT_ERR__ <<
"\n" << ss.str();
255 throw std::runtime_error(ss.str());
258 mapOfFEMacroFunctions_.insert(
259 std::pair<std::string, frontEndMacroStruct_t> (
261 frontEndMacroStruct_t(
265 requiredUserPermissions
273 const std::string& FEVInterface::getFEMacroInputArgument(frontEndMacroInArgs_t& argsIn,
274 const std::string& argName)
277 for(
const std::pair<const std::string /* input arg name */ , const std::string /* arg input value */ >&
280 if(pair.first == argName)
283 __SS__ <<
"Requested input argument not found with name '" << argName <<
"'" << std::endl;
284 __COUT_ERR__ <<
"\n" << ss.str();
285 throw std::runtime_error(ss.str());
291 std::string& FEVInterface::getFEMacroOutputArgument(frontEndMacroOutArgs_t& argsOut,
292 const std::string& argName)
295 for(std::pair<const std::string /* output arg name */ , std::string /* arg output value */ >&
298 if(pair.first == argName)
301 __SS__ <<
"Requested output argument not found with name '" << argName <<
"'" << std::endl;
302 __COUT_ERR__ <<
"\n" << ss.str();
303 throw std::runtime_error(ss.str());