1 #include "otsdaq/TablePlugins/SlowControlsTableBase/SlowControlsTableBase.h"
2 #include "otsdaq/TablePlugins/XDAQContextTable.h"
9 #define __MF_SUBJECT__ "SlowControlsTableBase"
18 SlowControlsTableBase::SlowControlsTableBase(std::string tableName, std::string* accumulatedExceptions )
19 :
TableBase(tableName,accumulatedExceptions)
26 SlowControlsTableBase::SlowControlsTableBase(
void)
29 __SS__ <<
"Should not call void constructor, table type is lost!" << __E__;
34 SlowControlsTableBase::~SlowControlsTableBase(
void) {}
37 void SlowControlsTableBase::getSlowControlsChannelList(
38 std::vector<std::pair<std::string , std::vector<std::string>>>&
41 outputEpicsPVFile(lastConfigManager_,&channelList);
45 bool SlowControlsTableBase::slowControlsChannelListHasChanged(
void)
const
47 __COUT__ <<
"channelListHasChanged()" << __E__;
48 if(isFirstAppInContext_)
49 return channelListHasChanged_;
51 if(lastConfigManager_ ==
nullptr)
53 __SS__ <<
"Illegal call to get status of channel list, no config manager has been initialized!" << __E__;
58 bool changed = outputEpicsPVFile(lastConfigManager_);
59 __COUT__ <<
"slowControlsChannelListHasChanged(): return " << std::boolalpha << std::to_string(changed) << __E__;
64 unsigned int SlowControlsTableBase::slowControlsHandler(std::stringstream& out,
66 std::string& commentStr,
67 std::string& subsystem,
68 std::string& location,
70 std::vector<std::pair<std::string , std::vector<std::string>>>* channelList
73 unsigned int numberOfChannels = 0;
74 __COUT__ <<
"slowControlsHandler" << __E__;
76 if(!slowControlsLink.isDisconnected())
79 std::vector<std::pair<std::string, ConfigurationTree>> channelChildren = slowControlsLink.getChildren();
83 for(
auto& channel : channelChildren)
85 if(channel.second.getNode(channelColNames_.colChannelDataType_).getValue<std::string>() !=
"1b")
91 OUT <<
"file \"dbt/soft_bi.dbt\" {" << __E__;
93 OUT <<
"pattern { Subsystem, loc, pvar, ZNAM, ONAM, ZSV, OSV, "
101 std::string pvName = channel.first;
102 std::string comment = channel.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT).getValue<std::string>();
105 OUT <<
"{ \"" << subsystem <<
"\", \"" << location <<
"\", \"" << pvName <<
"\", \""
115 <<
"\", \"" << comment <<
"\" }" << __E__;
127 for(
auto& channel : channelChildren)
129 if(channel.second.getNode(channelColNames_.colChannelDataType_).getValue<std::string>() ==
"1b")
135 OUT <<
"file \"dbt/subst_ai.dbt\" {" << __E__;
137 OUT <<
"pattern { Subsystem, loc, pvar, PREC, EGU, LOLO, LOW, "
138 "HIGH, HIHI, MDEL, ADEL, INP, SCAN, DTYP, DESC }"
145 std::string pvName = channel.first;
146 std::string comment = channel.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT).getValue<std::string>();
147 std::string precision =
"0";
148 std::string units = channel.second.getNode(channelColNames_.colUnits_).getValue<std::string>();
151 std::string low_alarm_lmt = channel.second.getNode(channelColNames_.colLowLowThreshold_).getValueWithDefault<std::string>(
"-1000");
152 std::string low_warn_lmt = channel.second.getNode(channelColNames_.colLowThreshold_).getValueWithDefault<std::string>(
"-100");
153 std::string high_warn_lmt = channel.second.getNode(channelColNames_.colHighThreshold_).getValueWithDefault<std::string>(
"100");
154 std::string high_alarm_lmt = channel.second.getNode(channelColNames_.colHighHighThreshold_).getValueWithDefault<std::string>(
"1000");
155 if(channelList !=
nullptr)
157 std::vector<std::string> pvSettings;
158 pvSettings.push_back(comment);
159 pvSettings.push_back(low_warn_lmt);
160 pvSettings.push_back(high_warn_lmt);
161 pvSettings.push_back(low_alarm_lmt);
162 pvSettings.push_back(high_alarm_lmt);
163 pvSettings.push_back(precision);
164 pvSettings.push_back(units);
165 channelList->push_back(std::make_pair(
"Mu2e:" + subsystem +
":" + location +
":" + pvName, pvSettings));
169 OUT <<
"{ \"" << subsystem <<
"\", \"" << location <<
"\", \"" << pvName <<
"\", \"" << precision
170 <<
"\", \"" << units <<
"\", \"" << low_alarm_lmt <<
"\", \"" << low_warn_lmt <<
"\", \"" << high_warn_lmt <<
"\", \"" << high_alarm_lmt
182 comment <<
"\" }" << __E__;
193 __COUT__ <<
"Disconnected EventBuilder Slow Controls metric channels link, so assuming "
194 "no slow controls channels."
197 return numberOfChannels;
203 std::vector<std::pair<std::string , std::vector<std::string>>>* channelList )
const
247 std::string filename = setFilePath();
249 __COUT__ <<
"EPICS PV file: " << filename << __E__;
251 std::string previousConfigFileContents;
253 std::FILE* fp = std::fopen(filename.c_str(),
"rb");
256 std::fseek(fp, 0, SEEK_END);
257 previousConfigFileContents.resize(std::ftell(fp));
259 std::fread(&previousConfigFileContents[0], 1, previousConfigFileContents.size(), fp);
263 __COUT_WARN__ <<
"Could not open EPICS IOC config file at " << filename << __E__;
270 std::stringstream out;
271 unsigned int numberOfParameters = slowControlsHandlerConfig(out, configManager, channelList);
272 __COUTV__(numberOfParameters);
276 if(previousConfigFileContents != out.str())
278 __COUT__ <<
"Configuration has changed! Marking dirty flag..." << __E__;
282 if(channelList ==
nullptr)
285 fout.open(filename, std::fstream::out | std::fstream::trunc);
288 __SS__ <<
"Failed to open EPICS PV file: " << filename << __E__;
295 std::FILE* fp = fopen(EPICS_DIRTY_FILE_PATH.c_str(),
"w");
302 __COUT_WARN__ <<
"Could not open dirty file: " << EPICS_DIRTY_FILE_PATH << __E__;
307 __COUT__ <<
"outputEpicsPVFile() return true" << __E__;
310 __COUT__ <<
"outputEpicsPVFile() return false" << __E__;