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>>>*
90 unsigned int numberOfChannels = 0;
91 __COUT__ <<
"slowControlsHandler" << __E__;
96 std::vector<std::pair<std::string, ConfigurationTree>> channelChildren =
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 if(channel.second.getNode(channelColNames_.colChannelDataType_)
152 .getValue<std::string>() ==
"1b")
158 OUT <<
"file \"dbt/subst_ai.dbt\" {" << __E__;
160 OUT <<
"pattern { Subsystem, loc, pvar, PREC, EGU, LOLO, LOW, "
161 "HIGH, HIHI, MDEL, ADEL, INP, SCAN, DTYP, DESC }"
168 std::string pvName = channel.first;
169 std::string comment =
170 channel.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT)
171 .getValue<std::string>();
172 std::string precision =
"0";
173 std::string units = channel.second.getNode(channelColNames_.colUnits_)
174 .getValue<std::string>();
177 std::string low_alarm_lmt =
178 channel.second.getNode(channelColNames_.colLowLowThreshold_)
179 .getValueWithDefault<std::string>(
"-1000");
180 std::string low_warn_lmt =
181 channel.second.getNode(channelColNames_.colLowThreshold_)
182 .getValueWithDefault<std::string>(
"-100");
183 std::string high_warn_lmt =
184 channel.second.getNode(channelColNames_.colHighThreshold_)
185 .getValueWithDefault<std::string>(
"100");
186 std::string high_alarm_lmt =
187 channel.second.getNode(channelColNames_.colHighHighThreshold_)
188 .getValueWithDefault<std::string>(
"1000");
189 if(channelList !=
nullptr)
191 std::vector<std::string> pvSettings;
192 pvSettings.push_back(comment);
193 pvSettings.push_back(low_warn_lmt);
194 pvSettings.push_back(high_warn_lmt);
195 pvSettings.push_back(low_alarm_lmt);
196 pvSettings.push_back(high_alarm_lmt);
197 pvSettings.push_back(precision);
198 pvSettings.push_back(units);
199 channelList->push_back(std::make_pair(
200 "Mu2e:" + subsystem +
":" + location +
":" + pvName, pvSettings));
204 OUT <<
"{ \"" << subsystem <<
"\", \"" << location <<
"\", \"" << pvName
205 <<
"\", \"" << precision
206 <<
"\", \"" << units <<
"\", \"" << low_alarm_lmt <<
"\", \""
207 << low_warn_lmt <<
"\", \"" << high_warn_lmt <<
"\", \"" << high_alarm_lmt
219 comment <<
"\" }" << __E__;
230 __COUT__ <<
"Disconnected EventBuilder Slow Controls metric channels link, so "
232 "no slow controls channels."
235 return numberOfChannels;
242 std::vector<std::pair<std::string , std::vector<std::string>>>*
287 std::string filename = setFilePath();
289 __COUT__ <<
"EPICS PV file: " << filename << __E__;
291 std::string previousConfigFileContents;
293 std::FILE* fp = std::fopen(filename.c_str(),
"rb");
296 std::fseek(fp, 0, SEEK_END);
297 previousConfigFileContents.resize(std::ftell(fp));
300 &previousConfigFileContents[0], 1, previousConfigFileContents.size(), fp);
304 __COUT_WARN__ <<
"Could not open EPICS IOC config file at " << filename
312 std::stringstream out;
313 unsigned int numberOfParameters =
314 slowControlsHandlerConfig(out, configManager, channelList);
315 __COUTV__(numberOfParameters);
319 if(previousConfigFileContents != out.str())
321 __COUT__ <<
"Configuration has changed! Marking dirty flag..." << __E__;
325 if(channelList ==
nullptr)
328 fout.open(filename, std::fstream::out | std::fstream::trunc);
331 __SS__ <<
"Failed to open EPICS PV file: " << filename << __E__;
338 std::string csvFilename = filename.substr(0, filename.length() - 3) +
"csv";
339 fout.open(csvFilename, std::fstream::out | std::fstream::trunc);
342 __SS__ <<
"Failed to open CSV EPICS PV file: " << filename << __E__;
346 std::string csvOut = out.str();
349 csvOut.erase(0, csvOut.find(
"\n") + 1);
350 if(csvOut.find(
"pattern {") != std::string::npos)
351 csvOut = csvOut.replace(csvOut.find(
"pattern {"), 10,
"");
352 while(csvOut.find(
"{") != std::string::npos)
353 csvOut = csvOut.replace(csvOut.find(
"{"), 1,
"");
354 while(csvOut.find(
"}") != std::string::npos)
355 csvOut = csvOut.replace(csvOut.find(
"}"), 1,
"");
356 while(csvOut.find(
"\"") != std::string::npos)
357 csvOut = csvOut.replace(csvOut.find(
"\""), 1,
"");
358 while(csvOut.find(
" ") != std::string::npos)
359 csvOut = csvOut.replace(csvOut.find(
" "), 1,
"");
360 while(csvOut.find(
"\t") != std::string::npos)
361 csvOut = csvOut.replace(csvOut.find(
"\t"), 1,
"");
363 fout << csvOut.substr(0, csvOut.length() - 1);
366 std::FILE* fp = fopen(EPICS_DIRTY_FILE_PATH.c_str(),
"w");
373 __COUT_WARN__ <<
"Could not open dirty file: " << EPICS_DIRTY_FILE_PATH
379 __COUT__ <<
"outputEpicsPVFile() return true" << __E__;
382 __COUT__ <<
"outputEpicsPVFile() return false" << __E__;
bool isDisconnected(void) 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
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.