1 #include "otsdaq/TablePlugins/SlowControlsTableBase/SlowControlsTableBase.h"
2 #include "otsdaq/TablePlugins/XDAQContextTable/XDAQContextTable.h"
9 #define __MF_SUBJECT__ "SlowControlsTableBase"
18 std::string* accumulatedExceptions )
19 :
TableBase(tableName, accumulatedExceptions)
28 std::cout <<
"SlowControlsTableBase Before traceTID=" << traceTID << __E__;
30 traceInit(trace_name(TRACE_NAME, __TRACE_FILE__, buf,
sizeof(buf)), 0);
31 std::cout <<
"SlowControlsTableBase After traceTID=" << traceTID << __E__;
32 __COUT__ <<
"SlowControlsTableBase TRACE reinit and Constructed." << __E__;
41 __SS__ <<
"Should not call void constructor, table type is lost!" << __E__;
46 SlowControlsTableBase::~SlowControlsTableBase(
void) {}
49 void SlowControlsTableBase::getSlowControlsChannelList(
50 std::vector<std::pair<std::string , std::vector<std::string>>>&
59 __COUT__ <<
"channelListHasChanged()" << __E__;
63 if(lastConfigManager_ ==
nullptr)
65 __SS__ <<
"Illegal call to get status of channel list, no config manager has "
73 __COUT__ <<
"slowControlsChannelListHasChanged(): return " << std::boolalpha
74 << std::to_string(changed) << __E__;
79 unsigned int SlowControlsTableBase::slowControlsHandler(
80 std::stringstream& out,
82 std::string& commentStr,
83 std::string& subsystem,
84 std::string& location,
86 std::vector<std::pair<std::string , std::vector<std::string>>>*
91 unsigned int numberOfChannels = 0;
94 if(!slowControlsLink.isDisconnected())
97 std::vector<std::pair<std::string, ConfigurationTree>> channelChildren =
98 slowControlsLink.getChildren();
100 __COUTVS__(2, channelChildren.size());
103 for(
auto& channel : channelChildren)
105 if(channel.second.getNode(channelColNames_.colChannelDataType_)
106 .getValue<std::string>() !=
"1b")
112 OUT <<
"file \"dbt/soft_bi.dbt\" {" << __E__;
114 OUT <<
"pattern { Subsystem, loc, pvar, ZNAM, ONAM, ZSV, OSV, "
122 std::string pvName = channel.first;
123 std::string comment =
124 channel.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT)
125 .getValue<std::string>();
128 OUT <<
"{ \"" << subsystem <<
"\", \"" << location <<
"\", \"" << pvName
139 <<
"\", \"" << comment <<
"\" }" << __E__;
151 for(
auto& channel : channelChildren)
153 __COUTVS__(2, channel.first);
154 if(channel.second.getNode(channelColNames_.colChannelDataType_)
155 .getValue<std::string>() ==
"1b")
161 OUT <<
"file \"dbt/subst_ai.dbt\" {" << __E__;
163 OUT <<
"pattern { Subsystem, loc, pvar, PREC, EGU, LOLO, LOW, "
164 "HIGH, HIHI, MDEL, ADEL, INP, SCAN, DTYP, DESC }"
171 std::string experimentName =
"";
174 experimentName = __ENV__(
"OTS_EPICS_OWNER");
178 experimentName = __ENV__(
"OTS_OWNER");
180 __COUT__ <<
"experimentName has metricParameterValue: " << experimentName
183 std::string pvName = channel.first;
184 std::string comment =
185 channel.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT)
186 .getValue<std::string>();
187 std::string precision =
"0";
188 std::string units = channel.second.getNode(channelColNames_.colUnits_)
189 .getValue<std::string>();
192 std::string low_alarm_lmt =
193 channel.second.getNode(channelColNames_.colLowLowThreshold_)
194 .getValueWithDefault<std::string>(
"-1000");
195 std::string low_warn_lmt =
196 channel.second.getNode(channelColNames_.colLowThreshold_)
197 .getValueWithDefault<std::string>(
"-100");
198 std::string high_warn_lmt =
199 channel.second.getNode(channelColNames_.colHighThreshold_)
200 .getValueWithDefault<std::string>(
"100");
201 std::string high_alarm_lmt =
202 channel.second.getNode(channelColNames_.colHighHighThreshold_)
203 .getValueWithDefault<std::string>(
"1000");
204 if(channelList !=
nullptr)
206 std::vector<std::string> pvSettings;
207 pvSettings.push_back(comment);
208 pvSettings.push_back(low_warn_lmt);
209 pvSettings.push_back(high_warn_lmt);
210 pvSettings.push_back(low_alarm_lmt);
211 pvSettings.push_back(high_alarm_lmt);
212 pvSettings.push_back(precision);
213 pvSettings.push_back(units);
214 channelList->push_back(std::make_pair(
215 experimentName +
":" + subsystem +
":" + location +
":" + pvName,
220 OUT <<
"{ \"" << subsystem <<
"\", \"" << location <<
"\", \"" << pvName
221 <<
"\", \"" << precision
222 <<
"\", \"" << units <<
"\", \"" << low_alarm_lmt <<
"\", \""
223 << low_warn_lmt <<
"\", \"" << high_warn_lmt <<
"\", \"" << high_alarm_lmt
235 comment <<
"\" }" << __E__;
246 __COUT__ <<
"Disconnected EventBuilder Slow Controls metric channels link, so "
248 "no slow controls channels."
251 return numberOfChannels;
253 catch(
const std::runtime_error& e)
263 std::vector<std::pair<std::string , std::vector<std::string>>>*
308 std::string filename = setFilePath();
310 __COUT__ <<
"EPICS PV file: " << filename << __E__;
312 std::string previousConfigFileContents;
314 std::FILE* fp = std::fopen(filename.c_str(),
"rb");
317 std::fseek(fp, 0, SEEK_END);
318 previousConfigFileContents.resize(std::ftell(fp));
321 &previousConfigFileContents[0], 1, previousConfigFileContents.size(), fp);
325 __COUT_WARN__ <<
"Could not open EPICS IOC config file at " << filename
333 std::stringstream out;
334 unsigned int numberOfParameters =
335 slowControlsHandlerConfig(out, configManager, channelList);
336 __COUTVS__(2, numberOfParameters);
340 if(previousConfigFileContents != out.str())
342 __COUT__ <<
"Configuration has changed! Marking dirty flag..." << __E__;
346 if(channelList ==
nullptr)
349 fout.open(filename, std::fstream::out | std::fstream::trunc);
352 __SS__ <<
"Failed to open EPICS PV file: " << filename << __E__;
359 std::string csvFilename = filename.substr(0, filename.length() - 3) +
"csv";
360 fout.open(csvFilename, std::fstream::out | std::fstream::trunc);
363 __SS__ <<
"Failed to open CSV EPICS PV file: " << filename << __E__;
367 std::string csvOut = out.str();
370 csvOut.erase(0, csvOut.find(
"\n") + 1);
371 if(csvOut.find(
"pattern {") != std::string::npos)
372 csvOut = csvOut.replace(csvOut.find(
"pattern {"), 10,
"");
373 while(csvOut.find(
"{") != std::string::npos)
374 csvOut = csvOut.replace(csvOut.find(
"{"), 1,
"");
375 while(csvOut.find(
"}") != std::string::npos)
376 csvOut = csvOut.replace(csvOut.find(
"}"), 1,
"");
377 while(csvOut.find(
"\"") != std::string::npos)
378 csvOut = csvOut.replace(csvOut.find(
"\""), 1,
"");
379 while(csvOut.find(
" ") != std::string::npos)
380 csvOut = csvOut.replace(csvOut.find(
" "), 1,
"");
381 while(csvOut.find(
"\t") != std::string::npos)
382 csvOut = csvOut.replace(csvOut.find(
"\t"), 1,
"");
384 fout << csvOut.substr(0, csvOut.length() - 1);
387 std::FILE* fp = fopen(EPICS_DIRTY_FILE_PATH.c_str(),
"w");
394 __COUT_WARN__ <<
"Could not open dirty file: " << EPICS_DIRTY_FILE_PATH
400 __COUT__ <<
"outputEpicsPVFile() return true" << __E__;
403 __COUT__ <<
"outputEpicsPVFile() return false" << __E__;
SlowControlsTableBase(void)
virtual bool outputEpicsPVFile(ConfigurationManager *configManager, std::vector< std::pair< std::string, std::vector< std::string >>> *channelList=0) const
use table name to have different file names! (instead of DEFINES like in DTC)
bool channelListHasChanged_
for managing if PV list has changed
bool isFirstAppInContext_
for managing if PV list has changed
virtual bool slowControlsChannelListHasChanged(void) const
Getters.
static std::string stackTrace(void)