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__;
61 if(lastConfigManager_ ==
nullptr)
63 __SS__ <<
"Illegal call to get status of channel list, no config manager has "
71 __COUT__ <<
"slowControlsChannelListHasChanged(): return " << std::boolalpha
72 << std::to_string(changed) << __E__;
77 unsigned int SlowControlsTableBase::slowControlsHandler(
78 std::stringstream& out,
80 std::string& commentStr,
81 std::string& subsystem,
82 std::string& location,
84 std::vector<std::pair<std::string , std::vector<std::string>>>*
89 unsigned int numberOfChannels = 0;
92 if(!slowControlsLink.isDisconnected())
95 std::vector<std::pair<std::string, ConfigurationTree>> channelChildren =
96 slowControlsLink.getChildren();
98 __COUTVS__(2, channelChildren.size());
101 for(
auto& channel : channelChildren)
103 if(channel.second.getNode(channelColNames_.colChannelDataType_)
104 .getValue<std::string>() !=
"1b")
110 OUT <<
"file \"dbt/soft_bi.dbt\" {" << __E__;
112 OUT <<
"pattern { Subsystem, loc, pvar, ZNAM, ONAM, ZSV, OSV, "
120 std::string pvName = channel.first;
121 std::string comment =
122 channel.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT)
123 .getValue<std::string>();
126 OUT <<
"{ \"" << subsystem <<
"\", \"" << location <<
"\", \"" << pvName
137 <<
"\", \"" << comment <<
"\" }" << __E__;
149 for(
auto& channel : channelChildren)
151 __COUTVS__(2, channel.first);
152 if(channel.second.getNode(channelColNames_.colChannelDataType_)
153 .getValue<std::string>() ==
"1b")
159 OUT <<
"file \"dbt/subst_ai.dbt\" {" << __E__;
161 OUT <<
"pattern { Subsystem, loc, pvar, PREC, EGU, LOLO, LOW, "
162 "HIGH, HIHI, MDEL, ADEL, INP, SCAN, DTYP, DESC }"
169 std::string experimentName =
"";
172 experimentName = __ENV__(
"OTS_EPICS_OWNER");
176 experimentName = __ENV__(
"OTS_OWNER");
178 __COUT__ <<
"experimentName has metricParameterValue: " << experimentName
181 std::string pvName = channel.first;
182 std::string comment =
183 channel.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT)
184 .getValue<std::string>();
185 std::string precision =
"0";
186 std::string units = channel.second.getNode(channelColNames_.colUnits_)
187 .getValue<std::string>();
190 std::string low_alarm_lmt =
191 channel.second.getNode(channelColNames_.colLowLowThreshold_)
192 .getValueWithDefault<std::string>(
"-1000");
193 std::string low_warn_lmt =
194 channel.second.getNode(channelColNames_.colLowThreshold_)
195 .getValueWithDefault<std::string>(
"-100");
196 std::string high_warn_lmt =
197 channel.second.getNode(channelColNames_.colHighThreshold_)
198 .getValueWithDefault<std::string>(
"100");
199 std::string high_alarm_lmt =
200 channel.second.getNode(channelColNames_.colHighHighThreshold_)
201 .getValueWithDefault<std::string>(
"1000");
202 if(channelList !=
nullptr)
204 std::vector<std::string> pvSettings;
205 pvSettings.push_back(comment);
206 pvSettings.push_back(low_warn_lmt);
207 pvSettings.push_back(high_warn_lmt);
208 pvSettings.push_back(low_alarm_lmt);
209 pvSettings.push_back(high_alarm_lmt);
210 pvSettings.push_back(precision);
211 pvSettings.push_back(units);
212 channelList->push_back(std::make_pair(
213 experimentName +
":" + subsystem +
":" + location +
":" + pvName,
218 OUT <<
"{ \"" << subsystem <<
"\", \"" << location <<
"\", \"" << pvName
219 <<
"\", \"" << precision
220 <<
"\", \"" << units <<
"\", \"" << low_alarm_lmt <<
"\", \""
221 << low_warn_lmt <<
"\", \"" << high_warn_lmt <<
"\", \"" << high_alarm_lmt
233 comment <<
"\" }" << __E__;
244 __COUT__ <<
"Disconnected EventBuilder Slow Controls metric channels link, so "
246 "no slow controls channels."
249 return numberOfChannels;
251 catch(
const std::runtime_error& e)
261 std::vector<std::pair<std::string , std::vector<std::string>>>*
306 std::string filename = setFilePath();
308 __COUT__ <<
"EPICS PV file: " << filename << __E__;
310 std::string previousConfigFileContents;
312 std::FILE* fp = std::fopen(filename.c_str(),
"rb");
315 std::fseek(fp, 0, SEEK_END);
316 previousConfigFileContents.resize(std::ftell(fp));
319 &previousConfigFileContents[0], 1, previousConfigFileContents.size(), fp);
323 __COUT_WARN__ <<
"Could not open EPICS IOC config file at " << filename
331 std::stringstream out;
332 unsigned int numberOfParameters =
333 slowControlsHandlerConfig(out, configManager, channelList);
334 __COUTVS__(2, numberOfParameters);
338 if(previousConfigFileContents != out.str())
340 __COUT__ <<
"Configuration has changed! Marking dirty flag..." << __E__;
344 if(channelList ==
nullptr)
347 fout.open(filename, std::fstream::out | std::fstream::trunc);
350 __SS__ <<
"Failed to open EPICS PV file: " << filename << __E__;
357 std::string csvFilename = filename.substr(0, filename.length() - 3) +
"csv";
358 fout.open(csvFilename, std::fstream::out | std::fstream::trunc);
361 __SS__ <<
"Failed to open CSV EPICS PV file: " << filename << __E__;
365 std::string csvOut = out.str();
368 csvOut.erase(0, csvOut.find(
"\n") + 1);
369 if(csvOut.find(
"pattern {") != std::string::npos)
370 csvOut = csvOut.replace(csvOut.find(
"pattern {"), 10,
"");
371 while(csvOut.find(
"{") != std::string::npos)
372 csvOut = csvOut.replace(csvOut.find(
"{"), 1,
"");
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(
"\t") != std::string::npos)
380 csvOut = csvOut.replace(csvOut.find(
"\t"), 1,
"");
382 fout << csvOut.substr(0, csvOut.length() - 1);
385 std::FILE* fp = fopen(EPICS_DIRTY_FILE_PATH.c_str(),
"w");
392 __COUT_WARN__ <<
"Could not open dirty file: " << EPICS_DIRTY_FILE_PATH
398 __COUT__ <<
"outputEpicsPVFile() return true" << __E__;
401 __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)
virtual bool slowControlsChannelListHasChanged(void) const
Getters.
defines used also by OtsConfigurationWizardSupervisor
static std::string stackTrace(void)