APDSettings.cpp
Go to the documentation of this file.
1 #include <DatabaseUtils/DCS/APDSettings.h>
2 #include <DatabaseUtils/DAQConfig/DBColumnParams.h>
3 #include <DatabaseUtils/DAQConfig/NamedConfigUtils.h>
4 #include <DatabaseUtils/DAQConfig/SubsystemNameSpec.h>
5 #include <algorithm>
6 
7 using namespace dbutils::daqconfig;
8 
9 namespace dbutils {
10 namespace dcs {
11 
12 const std::string APDSettings::WARM_COOLING_STATE("warm");
13 const std::string APDSettings::COLD_COOLING_STATE("cold");
14 
15 /**
16  * Constructs an APDSettings instance for the specified global
17  * configuration ID and list of DCMs.
18  */
19 APDSettings::
20 APDSettings(const int64_t& globalConfigId,
21  const std::vector<std::string>& dcmList)
22 {
23  _hasValidData = false;
24 
25  IDSpec idSpec(globalConfigId, IDSpec::GLOBAL, IDSpec::SLOWCONTROLS);
26  std::vector<int64_t> subsysConfigIdList;
29  "APDHardware",
30  "slowcontrols",
31  subsysConfigIdList);
32  if (! status) {return;}
33 
34  _dcmList = dcmList;
35  std::sort(_dcmList.begin(), _dcmList.end());
36 
37  _hasValidData = _fetchAllData(subsysConfigIdList);
38 }
39 
40 /**
41  * Constructs an APDSettings instance for the specified global
42  * configuration name specification and list of DCMs.
43  */
44 APDSettings::
45 APDSettings(GlobalNameSpec nameSpec,
46  const std::vector<std::string>& dcmList)
47 {
48  _hasValidData = false;
49 
50  // just in case...
51  nameSpec.isSlowControlsConfiguration(true);
52 
53  std::vector<int64_t> subsysConfigIdList;
54  int64_t subsystemConfigId;
56  getSubsystemConfigIdFromGlobalName(nameSpec, "APDHardware",
57  "slowcontrols", subsystemConfigId);
58  if (status) {
59  IDSpec idSpec(subsystemConfigId, IDSpec::SUBSYSTEM,
61  status = NamedConfigUtils::
62  getConfigIdAncestry(idSpec, subsysConfigIdList);
63  }
64  if (! status) {return;}
65 
66  _dcmList = dcmList;
67  std::sort(_dcmList.begin(), _dcmList.end());
68 
69  _hasValidData = _fetchAllData(subsysConfigIdList);
70 }
71 
72 /**
73  * Constructs an APDSettings instance for the specified subsystem
74  * configuration name specification and list of DCMs.
75  */
76 APDSettings::
77 APDSettings(SubsystemNameSpec nameSpec,
78  const std::vector<std::string>& dcmList)
79 {
80  _hasValidData = false;
81 
82  // just in case...
83  nameSpec.isSlowControlsConfiguration(true);
84 
85  std::vector<int64_t> subsysConfigIdList;
87  getSubsystemConfigIdAncestry(nameSpec, subsysConfigIdList);
88  if (! status) {return;}
89 
90  _dcmList = dcmList;
91  std::sort(_dcmList.begin(), _dcmList.end());
92 
93  _hasValidData = _fetchAllData(subsysConfigIdList);
94 }
95 
96 /**
97  * Fetches the temperature setpoint (as an int) for the
98  * specified DCM name and FEB ID.
99  *
100  * @return true if the value was successfully determined, false if not.
101  */
102 bool APDSettings::
103 getTemperature(const std::string& dcmName, const int& febId,
104  int& temperature)
105 {
106  if (_temperatureDataSet.get() == 0) {return false;}
107  if (! _temperatureDataSet->hasValidData()) {return false;}
108 
109  double doubleTemp;
110  bool status =
111  _temperatureDataSet->getEffectiveValueFor2Keys(dcmName, febId,
112  "temperature",
113  doubleTemp);
114  if (! status) {return false;}
115 
116  temperature = (int) doubleTemp;
117  return true;
118 }
119 
120 /**
121  * Fetches whether cooling is enabled for the specified DCM name and FEB ID.
122  *
123  * @return true if the value was successfully determined, false if not.
124  */
125 bool APDSettings::
126 getCoolingEnableFlag(const std::string& dcmName, const int& febId,
127  bool& isEnabled)
128 {
129  if (_enableMaskDataSet.get() == 0) {return false;}
130  if (! _enableMaskDataSet->hasValidData()) {return false;}
131 
132  int64_t fullMask;
133  if (! _enableMaskDataSet->getEffectiveValueFor1Key(dcmName, "mask",
134  fullMask)) {
135  return false;
136  }
137 
138  int64_t testMask = (((int64_t)1) << febId);
139  isEnabled = (febId >= 0 && febId < 64 && (fullMask & testMask) != 0);
140  return true;
141 }
142 
143 /**
144  * Fetches the voltage regulator setting for the specified DCM name and
145  * FEB ID, taking into account whether cooling is enabled for the FEB.
146  *
147  * @return true if the value was successfully determined, false if not.
148  */
149 bool APDSettings::
150 getVoltage(const std::string& dcmName, const int& febId,
151  int& regulatorSetting)
152 {
153  if (_hvAdjustDataSet.get() == 0) {return false;}
154  if (! _hvAdjustDataSet->hasValidData()) {return false;}
155 
156  std::string coolingState = WARM_COOLING_STATE;
157  bool isEnabled;
158  if (getCoolingEnableFlag(dcmName, febId, isEnabled)) {
159  if (isEnabled) {
160  coolingState = COLD_COOLING_STATE;
161  }
162  }
163 
164  return _hvAdjustDataSet->getEffectiveValueFor3Keys(coolingState,
165  dcmName, febId,
166  "voltage",
167  regulatorSetting);
168 }
169 
170 /**
171  * Fetches the temperature setpoint (as a double) for the
172  * specified DCM name and FEB ID.
173  *
174  * @return true if the value was successfully determined, false if not.
175  */
176 bool APDSettings::
177 getTemperature(const std::string& dcmName, const int& febId,
178  double& temperature)
179 {
180  if (_temperatureDataSet.get() == 0) {return false;}
181  if (! _temperatureDataSet->hasValidData()) {return false;}
182  return _temperatureDataSet->getEffectiveValueFor2Keys(dcmName, febId,
183  "temperature",
184  temperature);
185 }
186 
187 /**
188  * Fetches whether cooling is enabled for the specified DCM name and FEB ID.
189  *
190  * @return true if the value was successfully determined, false if not.
191  */
192 bool APDSettings::
193 getTemperatureEnable(const std::string& dcmName, const int& febId,
194  bool& enableFlag)
195 {
196  if (_enableMaskDataSet.get() == 0) {return false;}
197  if (! _enableMaskDataSet->hasValidData()) {return false;}
198 
199  int64_t fullMask;
200  if (! _enableMaskDataSet->getEffectiveValueFor1Key(dcmName, "mask",
201  fullMask)) {
202  return false;
203  }
204 
205  int64_t testMask = (((int64_t)1) << febId);
206  enableFlag = (febId >= 0 && febId < 64 && (fullMask & testMask) != 0);
207  return true;
208 }
209 
210 /**
211  * Fetches the voltage regulator setting for the specified DCM name,
212  * FEB ID, and cooling state.
213  *
214  * @return true if the value was successfully determined, false if not.
215  */
216 bool APDSettings::
217 getVoltage(const std::string& dcmName, const int& febId,
218  const std::string& coolingState, int& regulatorSetting)
219 {
220  if (_hvAdjustDataSet.get() == 0) {return false;}
221  if (! _hvAdjustDataSet->hasValidData()) {return false;}
222  return _hvAdjustDataSet->getEffectiveValueFor3Keys(coolingState,
223  dcmName, febId,
224  "voltage",
225  regulatorSetting);
226 }
227 
228 /**
229  * Fetches the list of temperature setpoints (as integers) for the
230  * FEBs that are connected to the specified DCM. The resulting list will
231  * be populated with 64 values, one for each FEB (in numerical order),
232  * when this method executes successfully.
233  *
234  * @return true if the requested values were successfully determined,
235  * false if not.
236  */
237 bool APDSettings::
238 getTemperatures(const std::string& dcmName,
239  std::vector<int>& temperatureList)
240 {
241  if (_temperatureDataSet.get() == 0) {return false;}
242  if (! _temperatureDataSet->hasValidData()) {return false;}
243 
244  temperatureList.clear();
245  for (uint16_t febId = DBColumnParams::LOW_FEB_ID;
246  febId <= DBColumnParams::HIGH_FEB_ID; ++febId) {
247  double tmpValue;
248  if (! _temperatureDataSet->getEffectiveValueFor2Keys(dcmName, febId,
249  "temperature",
250  tmpValue)) {
251  return false;
252  }
253  temperatureList.push_back((int) tmpValue);
254  }
255  return true;
256 }
257 
258 /**
259  * Fetches the cooling enable mask for the FEBs that are connected
260  * to the specified DCM. The resulting mask contains the information
261  * for all 64 FEBs, in numerical order, with the least significant bit
262  * in the mask corresponding to FEB 0.
263  *
264  * @return true if the requested mask was successfully determined,
265  * false if not.
266  */
267 bool APDSettings::
268 getCoolingEnableMask(const std::string& dcmName, int64_t& enableMask)
269 {
270  if (_enableMaskDataSet.get() == 0) {return false;}
271  if (! _enableMaskDataSet->hasValidData()) {return false;}
272  return _enableMaskDataSet->getEffectiveValueFor1Key(dcmName, "mask",
273  enableMask);
274 }
275 
276 /**
277  * Fetches the list of voltage regulator settings for the FEBs that are
278  * connected to the specified DCM, taking into account whether cooling
279  * is enabled for each FEB. The resulting list will
280  * be populated with 64 values, one for each FEB (in numerical order),
281  * when this method executes successfully.
282  *
283  * @return true if the requested values were successfully determined,
284  * false if not.
285  */
286 bool APDSettings::
287 getVoltages(const std::string& dcmName, std::vector<int>& voltageList)
288 {
289  if (_hvAdjustDataSet.get() == 0) {return false;}
290  if (! _hvAdjustDataSet->hasValidData()) {return false;}
291 
292  int64_t coolingEnableMask;
293  if (! getCoolingEnableMask(dcmName, coolingEnableMask)) {
294  return false;
295  }
296  int64_t _64BitOne = 1;
297 
298  voltageList.clear();
299  for (uint16_t febId = DBColumnParams::LOW_FEB_ID;
300  febId <= DBColumnParams::HIGH_FEB_ID; ++febId) {
301 
302  std::string coolingState = WARM_COOLING_STATE;
303  if ((coolingEnableMask & (_64BitOne << febId)) != 0) {
304  coolingState = COLD_COOLING_STATE;
305  }
306 
307  int tmpValue;
308  if (! _hvAdjustDataSet->getEffectiveValueFor3Keys(coolingState,
309  dcmName, febId,
310  "voltage",
311  tmpValue)) {
312  return false;
313  }
314  voltageList.push_back(tmpValue);
315  }
316  return true;
317 }
318 
319 /**
320  * Fetches the list of temperature setpoints (as doubles) for the
321  * FEBs that are connected to the specified DCM. The resulting list will
322  * be populated with 64 values, one for each FEB (in numerical order),
323  * when this method executes successfully.
324  *
325  * @return true if the requested values were successfully determined,
326  * false if not.
327  */
328 bool APDSettings::
329 getTemperatures(const std::string& dcmName,
330  std::vector<double>& temperatureList)
331 {
332  if (_temperatureDataSet.get() == 0) {return false;}
333  if (! _temperatureDataSet->hasValidData()) {return false;}
334 
335  temperatureList.clear();
336  for (uint16_t febId = DBColumnParams::LOW_FEB_ID;
337  febId <= DBColumnParams::HIGH_FEB_ID; ++febId) {
338  double tmpValue;
339  if (! _temperatureDataSet->getEffectiveValueFor2Keys(dcmName, febId,
340  "temperature",
341  tmpValue)) {
342  return false;
343  }
344  temperatureList.push_back(tmpValue);
345  }
346  return true;
347 }
348 
349 /**
350  * Fetches the cooling enable mask for the FEBs that are connected
351  * to the specified DCM. The resulting mask contains the information
352  * for all 64 FEBs, in numerical order, with the least significant bit
353  * in the mask corresponding to FEB 0.
354  *
355  * @return true if the requested mask was successfully determined,
356  * false if not.
357  */
358 bool APDSettings::
359 getTemperatureEnableMask(const std::string& dcmName, int64_t& enableMask)
360 {
361  if (_enableMaskDataSet.get() == 0) {return false;}
362  if (! _enableMaskDataSet->hasValidData()) {return false;}
363  return _enableMaskDataSet->getEffectiveValueFor1Key(dcmName, "mask",
364  enableMask);
365 }
366 
367 /**
368  * Fetches the list of warm or cold voltage regulator settings for the
369  * FEBs that are connected to the specified DCM. The resulting list will
370  * be populated with 64 values, one for each FEB (in numerical order),
371  * when this method executes successfully.
372  *
373  * @return true if the requested values were successfully determined,
374  * false if not.
375  */
376 bool APDSettings::
377 getVoltages(const std::string& dcmName, const std::string& coolingState,
378  std::vector<int>& voltageList)
379 {
380  if (_hvAdjustDataSet.get() == 0) {return false;}
381  if (! _hvAdjustDataSet->hasValidData()) {return false;}
382 
383  voltageList.clear();
384  for (uint16_t febId = DBColumnParams::LOW_FEB_ID;
385  febId <= DBColumnParams::HIGH_FEB_ID; ++febId) {
386  int tmpValue;
387  if (! _hvAdjustDataSet->getEffectiveValueFor3Keys(coolingState,
388  dcmName, febId,
389  "voltage",
390  tmpValue)) {
391  return false;
392  }
393  voltageList.push_back(tmpValue);
394  }
395  return true;
396 }
397 
398 /**
399  * Fetches the dry air channel for the specified DCM name and FEB ID.
400  *
401  * @return true if the value was successfully determined, false if not.
402  */
403 bool APDSettings::
404 getDryAirChannel(const std::string& dcmName, const int& febId,
405  int& channelNumber)
406 {
407  if (_dryAirChannelDataSet.get() == 0) {return false;}
408  if (! _dryAirChannelDataSet->hasValidData()) {return false;}
409  return _dryAirChannelDataSet->getEffectiveValueFor2Keys(dcmName, febId,
410  "dryairchannel",
411  channelNumber);
412 }
413 
414 /**
415  * Fetches the list of dry air channels for the
416  * FEBs that are connected to the specified DCM. The resulting list will
417  * be populated with 64 values, one for each FEB (in numerical order),
418  * when this method executes successfully.
419  *
420  * @return true if the requested values were successfully determined,
421  * false if not.
422  */
423 bool APDSettings::
424 getDryAirChannels(const std::string& dcmName, std::vector<int>& channelList)
425 {
426  if (_dryAirChannelDataSet.get() == 0) {return false;}
427  if (! _dryAirChannelDataSet->hasValidData()) {return false;}
428 
429  channelList.clear();
430  for (uint16_t febId = DBColumnParams::LOW_FEB_ID;
431  febId <= DBColumnParams::HIGH_FEB_ID; ++febId) {
432  int tmpValue;
433  if (! _dryAirChannelDataSet->getEffectiveValueFor2Keys(dcmName, febId,
434  "dryairchannel",
435  tmpValue)) {
436  return false;
437  }
438  channelList.push_back(tmpValue);
439  }
440  return true;
441 }
442 
443 /**
444  * Fetches the alarm threshold for the specified DCM name, FEB ID,
445  * PV name, and threshold type (hihi, hilo, lohi, or lolo).
446  *
447  * @return true if the value was successfully determined, false if not.
448  */
449 bool APDSettings::
450 getAlarmThreshold(const std::string& dcmName,
451  const int& febId,
452  const std::string& pvName,
453  const std::string& thresholdType,
454  double& threshold)
455 {
456  if (_alarmThresholdDataSet.get() == 0) {return false;}
457  if (! _alarmThresholdDataSet->hasValidData()) {return false;}
458  return _alarmThresholdDataSet->
459  getEffectiveValueFor3Keys(pvName, dcmName, febId,
460  thresholdType, threshold);
461 }
462 
463 bool APDSettings::
464 _fetchAllData(const std::vector<int64_t>& subsysConfigIdList)
465 {
466  {
467  ConfigDataSelector cfgSelector;
469  _dcmList[0],_dcmList[_dcmList.size()-1]);
471 
472  std::vector<std::string> dataColumnsOfInterest;
473  dataColumnsOfInterest.push_back("temperature");
474 
475  std::string fname("NovaDatabase/tables/DCS/APDTemperatureSettings.xml");
476  _temperatureDataSet.
477  reset(new ConfigDataTree(fname, subsysConfigIdList, cfgSelector,
478  dataColumnsOfInterest));
479  }
480 
481  {
482  ConfigDataSelector cfgSelector;
484  _dcmList[0],_dcmList[_dcmList.size()-1]);
485 
486  std::vector<std::string> dataColumnsOfInterest;
487  dataColumnsOfInterest.push_back("mask");
488 
489  std::string fname("NovaDatabase/tables/DCS/DCSFEBEnableMasks.xml");
490  _enableMaskDataSet.
491  reset(new ConfigDataTree(fname, subsysConfigIdList, cfgSelector,
492  dataColumnsOfInterest));
493  }
494 
495  {
496  ConfigDataSelector cfgSelector;
497  cfgSelector.addSelectionColumn("coolingstate");
499  _dcmList[0],_dcmList[_dcmList.size()-1]);
501 
502  std::vector<std::string> dataColumnsOfInterest;
503  dataColumnsOfInterest.push_back("voltage");
504 
505  std::string fname("NovaDatabase/tables/DCS/APDHighVoltages.xml");
506  _hvAdjustDataSet.
507  reset(new ConfigDataTree(fname, subsysConfigIdList, cfgSelector,
508  dataColumnsOfInterest));
509  }
510 
511  {
512  ConfigDataSelector cfgSelector;
514  _dcmList[0],_dcmList[_dcmList.size()-1]);
516 
517  std::vector<std::string> dataColumnsOfInterest;
518  dataColumnsOfInterest.push_back("dryairchannel");
519 
520  std::string fname("NovaDatabase/tables/DCS/FEBDryAirChannels.xml");
521  _dryAirChannelDataSet.
522  reset(new ConfigDataTree(fname, subsysConfigIdList, cfgSelector,
523  dataColumnsOfInterest));
524  }
525 
526  {
527  ConfigDataSelector cfgSelector;
528  cfgSelector.addSelectionColumn("pvName");
530  _dcmList[0],_dcmList[_dcmList.size()-1]);
532 
533  std::vector<std::string> dataColumnsOfInterest;
534  dataColumnsOfInterest.push_back("hihi");
535  dataColumnsOfInterest.push_back("hilo");
536  dataColumnsOfInterest.push_back("lohi");
537  dataColumnsOfInterest.push_back("lolo");
538 
539  std::string fname("NovaDatabase/tables/DCS/EPICSAlarmThresholds.xml");
540  _alarmThresholdDataSet.
541  reset(new ConfigDataTree(fname, subsysConfigIdList, cfgSelector,
542  dataColumnsOfInterest));
543  }
544 
545  return _temperatureDataSet.get() != 0 && _temperatureDataSet->hasValidData() &&
546  _enableMaskDataSet.get() != 0 && _enableMaskDataSet->hasValidData() &&
547  _hvAdjustDataSet.get() != 0 && _hvAdjustDataSet->hasValidData() &&
548  _dryAirChannelDataSet.get() != 0 && _dryAirChannelDataSet->hasValidData() &&
549  _alarmThresholdDataSet.get() != 0 && _alarmThresholdDataSet->hasValidData();
550 }
551 
552 } // end of namespace dcs
553 } // end of namespace dbutils
void addSelectionColumn(std::string columnName)
int status
Definition: fabricate.py:1613
static bool getConfigIdAncestry(const IDSpec &idSpec, std::vector< int64_t > &idList, const std::string &tableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static bool getSubsystemConfigIdAncestry(const SubsystemNameSpec &subsystemNameSpec, std::vector< int64_t > &idList, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE)
static const uint16_t HIGH_FEB_ID
static bool getSubsystemConfigIdFromGlobalName(const GlobalNameSpec &globalNameSpec, const std::string &subsystemName, const std::string &subsystemConfigType, int64_t &subsystemConfigId, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE)
static const uint16_t LOW_FEB_ID
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
static const std::string DCMID_COLUMN_NAME
static const std::string FEBID_COLUMN_NAME
static bool getSubsystemConfigIdAncestryFromGlobalId(const IDSpec &globalConfigId, const std::string &subsystemName, const std::string &subsystemConfigType, std::vector< int64_t > &idList, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE)