Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
dbutils::daqconfig::ConfigDataTree Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/DatabaseUtils/cxx/include/DAQConfig/ConfigDataTree.h"

Public Types

typedef std::map< std::string, std::stringConfigValueMap
 
typedef boost::shared_ptr< ConfigValueMapConfigValueMapPtr
 
typedef std::map< std::string, ConfigValueMapPtrConfigDataContainer
 
typedef std::vector< std::stringConfigValueList
 
typedef boost::shared_ptr< ConfigValueListConfigValueListPtr
 
typedef std::map< std::string, ConfigValueListPtrConfigValueListMap
 

Public Member Functions

 ConfigDataTree (const std::string &tableDefinitionFilename, const std::vector< int64_t > &subsystemConfigIdList, const ConfigDataSelector &selector, std::vector< std::string > dataColumnNameList)
 
 ConfigDataTree (const std::string &tableDefinitionFilename, const std::vector< int64_t > &subsystemConfigIdList)
 
bool hasValidData () const
 
std::vector< std::stringgetSelectorColumnNames () const
 
std::string getSelectorValueForDefault (std::string columnName) const
 
std::vector< std::stringgetDistinctSelectorColumnValues (const std::string &columnName) const
 
std::vector< std::stringgetDataColumnNames () const
 
std::vector< std::stringgetDataColumnTypes () const
 
std::string getTableName () const
 
template<class T >
bool getTrueValue (const std::string &dataColumnName, T &resultValue)
 
template<class T , class U >
bool getTrueValueFor1Key (const U &primarySelectionValue, const std::string &dataColumnName, T &resultValue)
 
template<class T , class U , class V >
bool getTrueValueFor2Keys (const U &primarySelectionValue, const V &secondarySelectionValue, const std::string &dataColumnName, T &resultValue)
 
template<class T , class U , class V , class W >
bool getTrueValueFor3Keys (const U &primarySelectionValue, const V &secondarySelectionValue, const W &tertiarySelectionValue, const std::string &dataColumnName, T &resultValue)
 
template<class T , class U >
bool getEffectiveValueFor1Key (const U &primarySelectionValue, const std::string &dataColumnName, T &resultValue)
 
template<class T , class U , class V >
bool getEffectiveValueFor2Keys (const U &primarySelectionValue, const V &secondarySelectionValue, const std::string &dataColumnName, T &resultValue)
 
template<class T , class U , class V , class W >
bool getEffectiveValueFor3Keys (const U &primarySelectionValue, const V &secondarySelectionValue, const W &tertiarySelectionValue, const std::string &dataColumnName, T &resultValue)
 
bool saveValues (const std::vector< dbutils::SimpleParameterSet > &newDataList) const
 

Static Public Attributes

static const std::string KEY_FOR_SYSTEM_WIDE_PARAM
 
static const std::string KEY_SEPARATOR_STRING
 
static const std::string NO_DEFAULT_KEY_STRING
 

Private Member Functions

void _initialize (boost::shared_ptr< nova::database::Table > dbTablePtr, const std::vector< int64_t > &subsystemConfigIdList, const ConfigDataSelector &selector, std::vector< std::string > dataColumnNameList, int debugFlag)
 
template<class T >
bool _getValueFromContainer (const std::string &key, const std::string &dataColumnName, T &value)
 

Private Attributes

bool _hasValidData
 
std::string _tableDefinitionFilename
 
ConfigDataSelector _configSelector
 
ConfigValueMap _selectorDefaultValueMap
 
ConfigValueListMap _distinctSelectorValueMap
 
std::vector< std::string_dataColumnNameList
 
std::vector< std::string_dataColumnTypeList
 
std::string _tableName
 
ConfigDataContainer _resultSet
 
std::vector< std::string_keyElementsForDefaults
 
std::vector< bool > _noKeyElementForDefaults
 

Detailed Description

Class to handle fetching of DAQ configuration data from the database.

Author
Kurt Biery
Version
Revision
1.12.28.1
Date
2019/09/27 00:07:03

Definition at line 27 of file ConfigDataTree.h.

Member Typedef Documentation

Definition at line 37 of file ConfigDataTree.h.

Definition at line 38 of file ConfigDataTree.h.

Definition at line 40 of file ConfigDataTree.h.

Definition at line 39 of file ConfigDataTree.h.

Definition at line 35 of file ConfigDataTree.h.

Definition at line 36 of file ConfigDataTree.h.

Constructor & Destructor Documentation

dbutils::daqconfig::ConfigDataTree::ConfigDataTree ( const std::string tableDefinitionFilename,
const std::vector< int64_t > &  subsystemConfigIdList,
const ConfigDataSelector selector,
std::vector< std::string dataColumnNameList 
)

Constructs a configuration data tree for the specified input parameters.

Definition at line 45 of file ConfigDataTree.cpp.

References _configSelector, _dataColumnNameList, _dataColumnTypeList, _hasValidData, _initialize(), _tableDefinitionFilename, mkDefs::detName, novadaq::EnvVarCache::getEnvVar(), novadaq::EnvVarCache::getInstance(), nova::dbi::kDAQTable, LINE_NUMBER_DEBUG, and string.

Referenced by dbutils::daqconfig::sortingFunction().

49 {
50  // seed failure
51  _hasValidData = false;
52  _tableDefinitionFilename = tableDefinitionFilename;
53 
54  // check if a debug flag has been specified
55  int debugFlag = 0;
56  std::string debugString =
57  novadaq::EnvVarCache::getInstance().getEnvVar("CONFIG_DATA_TREE_DEBUG");
58  if (debugString.length() > 0) {
59  try {debugFlag = boost::lexical_cast<int>(debugString);}
60  catch (...) {}
61  }
62 
63  // set up the Table instance and its connection to the DB
64  // (if something fails here, we simply return and leave the hasValidData
65  // flag set to false)
66  boost::shared_ptr<NOVADB::Table> dbTablePtr;
67  dbTablePtr.reset(new NOVADB::Table(tableDefinitionFilename.c_str()));
69  novadaq::EnvVarCache::getInstance().getEnvVar("NOVADAQ_ENVIRONMENT");
70  dbTablePtr->SetDetector(detName);
71  dbTablePtr->SetTableType(NOVADB::kDAQTable);
72  std::string dbUser =
73  novadaq::EnvVarCache::getInstance().getEnvVar("CFGMGR_DB_USER");
75  if (dbUser.length() > 0) {
77  dbTablePtr->SetUser(dbUser);
78  }
80  if (! dbTablePtr->GetConnection()) {return;}
82  if (! dbTablePtr->ExistsInDB()) {return;}
84  _configSelector = selector;
85  _dataColumnNameList = dataColumnNameList;
86  _dataColumnTypeList.assign(_dataColumnNameList.size(), "unknown");
87 
88  _initialize(dbTablePtr, subsystemConfigIdList,
89  selector, dataColumnNameList, debugFlag);
91 }
std::vector< std::string > _dataColumnNameList
static EnvVarCache & getInstance()
Definition: EnvVarCache.cpp:12
std::vector< std::string > _dataColumnTypeList
#define LINE_NUMBER_DEBUG
void _initialize(boost::shared_ptr< nova::database::Table > dbTablePtr, const std::vector< int64_t > &subsystemConfigIdList, const ConfigDataSelector &selector, std::vector< std::string > dataColumnNameList, int debugFlag)
std::string getEnvVar(std::string name)
Definition: EnvVarCache.cpp:33
detName
Definition: mkDefs.py:106
enum BeamMode string
dbutils::daqconfig::ConfigDataTree::ConfigDataTree ( const std::string tableDefinitionFilename,
const std::vector< int64_t > &  subsystemConfigIdList 
)

Constructs a configuration data tree for the specified table and subsystem configuration ID list. Reasonable assumptions are made for which selector columns are of interest (e.g. dcmName, febId) and which data columns are of interest.

Definition at line 101 of file ConfigDataTree.cpp.

References _configSelector, _dataColumnNameList, _dataColumnTypeList, _hasValidData, _initialize(), _tableDefinitionFilename, dbutils::daqconfig::ConfigDataSelector::addSelectionColumn(), dbutils::daqconfig::DBColumnParams::DCMNAME_COLUMN_NAME, mkDefs::detName, dbutils::daqconfig::DBColumnParams::FEBID_COLUMN_NAME, novadaq::EnvVarCache::getEnvVar(), novadaq::EnvVarCache::getInstance(), dbutils::daqconfig::DBColumnParams::HOSTNAME_COLUMN_NAME, compare_h5_caf::idx, dbutils::daqconfig::DBColumnUtils::isInfrastructureColumn(), dbutils::daqconfig::DBColumnUtils::isSubsystemConfigReferenceColumn(), nova::dbi::kDAQTable, LINE_NUMBER_DEBUG, dbutils::daqconfig::DBColumnParams::PIXELID_COLUMN_NAME, saveValues(), and string.

103 {
104  // seed failure
105  _hasValidData = false;
106  _tableDefinitionFilename = tableDefinitionFilename;
107 
108  // check if a debug flag has been specified
109  int debugFlag = 0;
110  std::string debugString =
111  novadaq::EnvVarCache::getInstance().getEnvVar("CONFIG_DATA_TREE_DEBUG");
112  if (debugString.length() > 0) {
113  try {debugFlag = boost::lexical_cast<int>(debugString);}
114  catch (...) {}
115  }
116 
117  // set up the Table instance and its connection to the DB
118  // (if something fails here, we simply return and leave the hasValidData
119  // flag set to false)
120  boost::shared_ptr<NOVADB::Table> dbTablePtr;
121  dbTablePtr.reset(new NOVADB::Table(tableDefinitionFilename.c_str()));
123  novadaq::EnvVarCache::getInstance().getEnvVar("NOVADAQ_ENVIRONMENT");
124  dbTablePtr->SetDetector(detName);
125  dbTablePtr->SetTableType(NOVADB::kDAQTable);
126  std::string dbUser =
127  novadaq::EnvVarCache::getInstance().getEnvVar("CFGMGR_DB_USER");
129  if (dbUser.length() > 0) {
131  dbTablePtr->SetUser(dbUser);
132  }
134  if (! dbTablePtr->GetConnection()) {return;}
136  if (! dbTablePtr->ExistsInDB()) {return;}
138 
139  // determine the selector and data columns of interest
140  std::vector<std::string> colNames = dbTablePtr->GetColNames();
141 
142  // the order of the selectors matters, so we'll handle those carefully
143  std::vector<std::string> tmpSelectionList;
144  uint32_t indexForStartOfNormalHierarchy = 0;
145 
146  for (uint32_t idx = 0; idx < colNames.size(); ++idx) {
147  std::string colName = boost::to_lower_copy(colNames[idx]);
148  if (DBColumnUtils::isInfrastructureColumn(colName)) {continue;}
150  continue;
151  }
152 
153  std::vector<std::string>::iterator iter = tmpSelectionList.begin();
154  if (colName == DBColumnParams::DCMNAME_COLUMN_NAME) {
155  if (tmpSelectionList.size() > indexForStartOfNormalHierarchy) {
156  tmpSelectionList.insert(iter+indexForStartOfNormalHierarchy,
157  colName);
158  }
159  else {
160  tmpSelectionList.push_back(colName);
161  }
162  }
163  else if (colName == DBColumnParams::FEBID_COLUMN_NAME) {
164  if (tmpSelectionList.size() > indexForStartOfNormalHierarchy+1) {
165  tmpSelectionList.insert(iter+indexForStartOfNormalHierarchy+1,
166  colName);
167  }
168  else {
169  tmpSelectionList.push_back(colName);
170  }
171  }
172  else if (colName == DBColumnParams::PIXELID_COLUMN_NAME) {
173  if (tmpSelectionList.size() > indexForStartOfNormalHierarchy+2) {
174  tmpSelectionList.insert(iter+indexForStartOfNormalHierarchy+2,
175  colName);
176  }
177  else {
178  tmpSelectionList.push_back(colName);
179  }
180  }
181  else if (colName == DBColumnParams::HOSTNAME_COLUMN_NAME) {
182  if (tmpSelectionList.size() > indexForStartOfNormalHierarchy) {
183  tmpSelectionList.insert(iter+indexForStartOfNormalHierarchy,
184  colName);
185  }
186  else {
187  tmpSelectionList.push_back(colName);
188  }
189  }
190  else if (colName == "coolingstate") {
191  if (tmpSelectionList.size() > 0) {
192  tmpSelectionList.insert(iter, colName);
193  }
194  else {
195  tmpSelectionList.push_back(colName);
196  }
197  ++indexForStartOfNormalHierarchy;
198  }
199  else if (colName == "pvname") {
200  if (tmpSelectionList.size() > 0) {
201  tmpSelectionList.insert(iter, colName);
202  }
203  else {
204  tmpSelectionList.push_back(colName);
205  }
206  ++indexForStartOfNormalHierarchy;
207  }
208  else {
209  _dataColumnNameList.push_back(colName);
210  _dataColumnTypeList.push_back("unknown");
211  }
212  }
214 
215  for (uint32_t idx = 0; idx < tmpSelectionList.size(); ++idx) {
216  std::string colName = tmpSelectionList[idx];
218  }
220 
221  _initialize(dbTablePtr, subsystemConfigIdList,
224 }
void addSelectionColumn(std::string columnName)
std::vector< std::string > _dataColumnNameList
static EnvVarCache & getInstance()
Definition: EnvVarCache.cpp:12
std::vector< std::string > _dataColumnTypeList
#define LINE_NUMBER_DEBUG
void _initialize(boost::shared_ptr< nova::database::Table > dbTablePtr, const std::vector< int64_t > &subsystemConfigIdList, const ConfigDataSelector &selector, std::vector< std::string > dataColumnNameList, int debugFlag)
static const std::string HOSTNAME_COLUMN_NAME
static const std::string PIXELID_COLUMN_NAME
static bool isSubsystemConfigReferenceColumn(const std::string &columnName)
static const std::string DCMNAME_COLUMN_NAME
std::string getEnvVar(std::string name)
Definition: EnvVarCache.cpp:33
static const std::string FEBID_COLUMN_NAME
static bool isInfrastructureColumn(const std::string &columnName)
detName
Definition: mkDefs.py:106
enum BeamMode string

Member Function Documentation

template<class T >
bool dbutils::daqconfig::ConfigDataTree::_getValueFromContainer ( const std::string key,
const std::string dataColumnName,
T value 
)
private

Definition at line 372 of file ConfigDataTree.h.

References _resultSet, findDuplicateFiles::key, and T.

Referenced by getEffectiveValueFor1Key(), getEffectiveValueFor2Keys(), getEffectiveValueFor3Keys(), getTableName(), getTrueValue(), getTrueValueFor1Key(), getTrueValueFor2Keys(), and getTrueValueFor3Keys().

375 {
376  ConfigDataContainer::const_iterator iter1 = _resultSet.find(key);
377  if (iter1 == _resultSet.end()) {return false;}
378 
379  ConfigValueMapPtr mapPtr = _resultSet[key];
380  ConfigValueMap::const_iterator iter2 = mapPtr->find(dataColumnName);
381  if (iter2 == mapPtr->end()) {return false;}
382 
383  value = boost::lexical_cast<T>(iter2->second);
384  return true;
385 }
boost::shared_ptr< ConfigValueMap > ConfigValueMapPtr
const XML_Char int const XML_Char * value
Definition: expat.h:331
double T
Definition: Xdiff_gwt.C:5
void dbutils::daqconfig::ConfigDataTree::_initialize ( boost::shared_ptr< nova::database::Table dbTablePtr,
const std::vector< int64_t > &  subsystemConfigIdList,
const ConfigDataSelector selector,
std::vector< std::string dataColumnNameList,
int  debugFlag 
)
private

Initializes the data in the tree by querying the database.

Definition at line 304 of file ConfigDataTree.cpp.

References _dataColumnTypeList, _distinctSelectorValueMap, _hasValidData, _keyElementsForDefaults, _noKeyElementForDefaults, _resultSet, _selectorDefaultValueMap, _tableName, nova::database::Row::Col(), om::cout, allTimeWatchdog::endl, nova::database::Column::Get(), getDistinctSelectorColumnValues(), dbutils::daqconfig::DBColumnParams::getInstance(), dbutils::daqconfig::ConfigDataSelector::getSelectionColumn(), dbutils::daqconfig::ConfigDataSelector::getSelectionCount(), dbutils::daqconfig::ConfigDataSelector::getSelectionHighValue(), dbutils::daqconfig::ConfigDataSelector::getSelectionLowValue(), getSelectorColumnNames(), getSelectorValueForDefault(), dbutils::daqconfig::ConfigDataSelector::hasSelectionValues(), compare_h5_caf::idx, nova::database::Column::IsNull(), findDuplicateFiles::key, KEY_FOR_SYSTEM_WIDE_PARAM, KEY_SEPARATOR_STRING, LINE_NUMBER_DEBUG, NO_DEFAULT_KEY_STRING, dbutils::daqconfig::sortingFunction(), string, and nova::database::Column::Type().

Referenced by ConfigDataTree(), getTableName(), and saveValues().

309 {
310  _tableName = dbTablePtr->Name();
312 
313  // fetch information about keys to be used when selecting default values
314  std::string keyForSystemWideDefault;
315  DBColumnParams& colParams = DBColumnParams::getInstance();
316  if (selector.getSelectionCount() > 0) {
317  for (uint32_t sdx = 0; sdx < selector.getSelectionCount(); ++sdx) {
318  std::string keyForDefault = "";
319  std::string selectorName = selector.getSelectionColumn(sdx);
320  if (! colParams.
321  columnKeyToGetDefaultValue(selectorName, keyForDefault)) {
322  keyForDefault = NO_DEFAULT_KEY_STRING;
323  _noKeyElementForDefaults.push_back(true);
324  }
325  else {
326  _noKeyElementForDefaults.push_back(false);
327  }
328 
329  if (sdx > 0) {
330  keyForSystemWideDefault.append(KEY_SEPARATOR_STRING);
331  }
332  keyForSystemWideDefault.append(keyForDefault);
333 
334  _keyElementsForDefaults.push_back(keyForDefault);
335 
336  _selectorDefaultValueMap[selectorName] = keyForDefault;
337  }
338  }
339  else {
340  keyForSystemWideDefault = KEY_FOR_SYSTEM_WIDE_PARAM;
341  }
343 
344  // loop over each subsystem configuration ID that was provided
345  for (uint32_t cfgIdx = 0; cfgIdx < subsystemConfigIdList.size(); ++cfgIdx) {
346  dbTablePtr->Clear();
348 
349  // set the appropriate validity contexts
350  for (uint32_t sdx = 0; sdx < selector.getSelectionCount(); ++sdx) {
351  if (selector.hasSelectionValues(sdx)) {
352  if (! dbTablePtr->
353  SetValidityRange(selector.getSelectionColumn(sdx),
354  selector.getSelectionLowValue(sdx),
355  selector.getSelectionHighValue(sdx))) {
357  return;
358  }
359  }
360  }
361  if (! dbTablePtr->SetValidityRange("subsysCfgId",
362  subsystemConfigIdList[cfgIdx])) {
364  return;
365  }
366 
367  // fetch the data from the DB
368  if ((debugFlag & 0x10) != 0) {
369  dbTablePtr->SetVerbosity(1);
370  }
371  if (! dbTablePtr->LoadFromDB()) {
373  return;
374  }
376 
377  // also, fetch all default values that we may need
378  for (uint32_t sdx = selector.getSelectionCount(); sdx > 0; --sdx) {
379  if (selector.hasSelectionValues(sdx-1)) {
380  if (! dbTablePtr->
381  SetValidityRange(selector.getSelectionColumn(sdx-1),
383  _keyElementsForDefaults[sdx-1])) {
385  return;
386  }
387  if (! dbTablePtr->LoadFromDB()) {
389  return;
390  }
391  }
392  }
394 
395  // loop over each row that was selected and decide whether
396  // to add it to the internal result set
397  ConfigDataContainer tmpContainerForDefaults;
398  for (int32_t idx = 0; idx < dbTablePtr->NRow(); ++idx) {
399  NOVADB::Row* rowPtr = dbTablePtr->GetRow(idx);
400  std::string valueString;
401  NOVADB::Column* colPtr;
402 
403  // build the key that we'll use to store this entry in
404  // the result set
406  std::vector<std::string> keyElements;
407  bool thisKeyIsForADefault = false;
408  if (selector.getSelectionCount() > 0) {
409  for (uint32_t sdx = 0; sdx < selector.getSelectionCount();
410  ++sdx) {
411  std::string selectorName = selector.getSelectionColumn(sdx);
412  colPtr = rowPtr->Col(selectorName);
413  if (! colPtr->Get(valueString)) {
415  return;
416  }
417 
418  if (sdx > 0) {
419  key.append(KEY_SEPARATOR_STRING);
420  }
421  key.append(valueString);
422 
423  keyElements.push_back(valueString);
424 
425  if (valueString == _keyElementsForDefaults[sdx]) {
426  thisKeyIsForADefault = true;
427  }
428 
429  // build up the list(s) of unique selector values
430  ConfigValueListMap::const_iterator iter1 =
431  _distinctSelectorValueMap.find(selectorName);
432  if (iter1 == _distinctSelectorValueMap.end()) {
433  ConfigValueListPtr valueListPtr(new ConfigValueList());
434  valueListPtr->push_back(valueString);
435  _distinctSelectorValueMap[selectorName] = valueListPtr;
436  }
437  else {
438  ConfigValueListPtr valueListPtr = iter1->second;
439  ConfigValueList::const_iterator iter2 =
440  std::find(valueListPtr->begin(),
441  valueListPtr->end(), valueString);
442  if (iter2 == valueListPtr->end()) {
443  valueListPtr->push_back(valueString);
444  }
445  }
446  }
447  }
448  else {
450  }
451 
452  // check if the result set already has an entry for this key
453  ConfigDataContainer::const_iterator iter1 = _resultSet.find(key);
454  if (iter1 != _resultSet.end()) {continue;}
455 
456  // check if a default value exists that makes this entry irrelevant
457  bool foundDefault = false;
458  for (uint32_t testIdx = keyElements.size(); testIdx > 0; --testIdx) {
459  std::string tmpKey;
460  for (uint32_t sdx = 0; sdx < keyElements.size(); ++sdx) {
461  std::string keyFragment = keyElements[sdx];
462  if (sdx >= (testIdx - 1)) {
463  keyFragment = _keyElementsForDefaults[sdx];
464  }
465 
466  if (sdx > 0) {
467  tmpKey.append(KEY_SEPARATOR_STRING);
468  }
469  tmpKey.append(keyFragment);
470  }
471 
472  iter1 = _resultSet.find(tmpKey);
473  if (iter1 != _resultSet.end()) {
474  foundDefault = true;
475  break;
476  }
477  }
478  if (foundDefault) {continue;}
479 
480  // if we made it this far, then we should store the entry in the
481  // result set
482  ConfigValueMapPtr mapPtr(new ConfigValueMap());
483 
484  // fetch the requested data values from the DB row
485  for (uint32_t ndx = 0; ndx < dataColumnNameList.size(); ++ndx) {
486  std::string columnName = dataColumnNameList[ndx];
487  colPtr = rowPtr->Col(columnName);
488  _dataColumnTypeList[ndx] = colPtr->Type();
489  if (colPtr->IsNull()) {
490  (*mapPtr)[columnName] = "";
491  }
492  else {
493  if (! colPtr->Get(valueString)) {
495  return;
496  }
497  (*mapPtr)[columnName] = valueString;
498  }
499  }
500 
501  // insert the entry into the result set or the temporary
502  // container for defaults
503  if (thisKeyIsForADefault) {
504  tmpContainerForDefaults[key] = mapPtr;
505  }
506  else {
507  _resultSet[key] = mapPtr;
508  }
509  }
511 
512  // copy the defaults that were found with this configId to the
513  // result set, now that they won't mess up the logic above
514  ConfigDataContainer::const_iterator iter2;
515  ConfigDataContainer::const_iterator iter2End =
516  tmpContainerForDefaults.end();
517  for (iter2 = tmpContainerForDefaults.begin();
518  iter2 != iter2End; ++iter2) {
519  _resultSet[iter2->first] = iter2->second;
520  }
521 
522  // as soon as we find a system-wide default (or a system-wide
523  // parameter value), we're done
524  ConfigDataContainer::const_iterator iter3 =
525  _resultSet.find(keyForSystemWideDefault);
526  if (iter3 != _resultSet.end()) {break;}
527  }
529 
530  // sort the list(s) of distinct selector values
531  ConfigValueListMap::const_iterator iter;
532  ConfigValueListMap::const_iterator iterEnd =
534  for (iter = _distinctSelectorValueMap.begin(); iter != iterEnd; ++iter) {
535  ConfigValueListPtr valueListPtr = iter->second;
536  std::sort(valueListPtr->begin(), valueListPtr->end(), sortingFunction);
537  }
538 
539  // print out the contents of the tree, if requested
540  if ((debugFlag & 0x01) != 0) {
541  std::cout << "*** ConfigDataTree for " << dbTablePtr->Name()
542  << std::endl;
543  ConfigDataContainer::const_iterator resIterEnd = _resultSet.end();
544  ConfigDataContainer::const_iterator resIter;
545  for (resIter = _resultSet.begin(); resIter != resIterEnd; ++resIter) {
546  ConfigValueMapPtr mapPtr = resIter->second;
547  std::cout << " Key=" << resIter->first;
548  if (mapPtr.get() != 0) {
549  ConfigValueMap::const_iterator mapIterEnd = mapPtr->end();
550  ConfigValueMap::const_iterator mapIter;
551  for (mapIter = mapPtr->begin(); mapIter != mapIterEnd; ++mapIter) {
552  std::cout << ", " << mapIter->first << "=" << mapIter->second;
553  }
554  }
555  std::cout << std::endl;
556  }
557  }
558 
559  // print out the selector and data column details, if requested
560  if ((debugFlag & 0x02) != 0) {
561  std::cout << "*** ConfigDataTree for " << dbTablePtr->Name()
562  << std::endl;
563  std::vector<std::string> selectorColumnNames = getSelectorColumnNames();
564  for (uint32_t idx = 0; idx < selectorColumnNames.size(); ++idx) {
565  std::string columnName = selectorColumnNames[idx];
566  std::string defaultValue = getSelectorValueForDefault(columnName);
567  std::vector<std::string> distinctValues =
569  std::cout << " Selector = \"" << columnName << "\", default = \""
570  << defaultValue << "\"" << std::endl;
571  std::cout << " Distinct values = ";
572  for (uint32_t jdx = 0; jdx < distinctValues.size(); ++jdx) {
573  if (jdx > 0) {std::cout << ", ";}
574  std::cout << distinctValues[jdx];
575  }
576  std::cout << std::endl;
577  }
578  }
579 
580  // indicate success
581  _hasValidData = true;
583 }
std::vector< std::string > _keyElementsForDefaults
std::vector< bool > _noKeyElementForDefaults
std::vector< std::string > _dataColumnTypeList
std::vector< std::string > getDistinctSelectorColumnValues(const std::string &columnName) const
#define LINE_NUMBER_DEBUG
ConfigValueListMap _distinctSelectorValueMap
std::map< std::string, std::string > ConfigValueMap
boost::shared_ptr< ConfigValueMap > ConfigValueMapPtr
std::string getSelectorValueForDefault(std::string columnName) const
std::vector< std::string > getSelectorColumnNames() const
static const std::string NO_DEFAULT_KEY_STRING
bool sortingFunction(std::string leftString, std::string rightString)
bool Get(T &val) const
Definition: Column.h:53
static const std::string KEY_FOR_SYSTEM_WIDE_PARAM
bool IsNull() const
Definition: Column.h:39
OStream cout
Definition: OStream.cxx:6
static DBColumnParams & getInstance()
std::map< std::string, ConfigValueMapPtr > ConfigDataContainer
static const std::string KEY_SEPARATOR_STRING
std::vector< std::string > ConfigValueList
std::string Type() const
Definition: Column.h:36
boost::shared_ptr< ConfigValueList > ConfigValueListPtr
Column & Col(int i)
Definition: Row.h:51
enum BeamMode string
std::vector<std::string> dbutils::daqconfig::ConfigDataTree::getDataColumnNames ( ) const
inline

Definition at line 88 of file ConfigDataTree.h.

References _dataColumnNameList.

89  {
90  return _dataColumnNameList;
91  }
std::vector< std::string > _dataColumnNameList
std::vector<std::string> dbutils::daqconfig::ConfigDataTree::getDataColumnTypes ( ) const
inline

Definition at line 92 of file ConfigDataTree.h.

References _dataColumnTypeList.

93  {
94  return _dataColumnTypeList;
95  }
std::vector< std::string > _dataColumnTypeList
std::vector<std::string> dbutils::daqconfig::ConfigDataTree::getDistinctSelectorColumnValues ( const std::string columnName) const
inline

Definition at line 76 of file ConfigDataTree.h.

References _distinctSelectorValueMap.

Referenced by _initialize().

77  {
78  ConfigValueListMap::const_iterator iter =
79  _distinctSelectorValueMap.find(columnName);
80  if (iter == _distinctSelectorValueMap.end()) {
81  std::vector<std::string> emptyList;
82  return emptyList;
83  }
84  else {
85  return *(iter->second);
86  }
87  }
ConfigValueListMap _distinctSelectorValueMap
template<class T , class U >
bool dbutils::daqconfig::ConfigDataTree::getEffectiveValueFor1Key ( const U &  primarySelectionValue,
const std::string dataColumnName,
T resultValue 
)

Fetches the requested value...

Definition at line 240 of file ConfigDataTree.h.

References _getValueFromContainer(), _keyElementsForDefaults, _noKeyElementForDefaults, getEffectiveValueFor2Keys(), findDuplicateFiles::key, NO_DEFAULT_KEY_STRING, cet::replace_all(), and string.

Referenced by dbutils::daqconfig::DCMConnectConfig::_fetchDCMApplicationParams(), dbutils::daqconfig::DCMRunConfig::_fetchDCMApplicationParams(), dbutils::daqconfig::DCMHardwareConfig::_fetchDCMApplicationParams(), dbutils::daqconfig::DCMRunConfig::_fetchDCMDataDevValues(), dbutils::daqconfig::DCMHardwareConfig::_fetchDCMDataDevValues(), dbutils::daqconfig::DCMHardwareConfig::_fetchDCMFirmwareLocations(), dbutils::daqconfig::DCMHardwareConfig::_fetchDCMFPGAParams(), dbutils::daqconfig::DCMHardwareConfig::_fetchFEBEnableMasks(), dbutils::daqconfig::DCMHardwareConfig::_fetchFEBFirmwareLocations(), dbutils::daqconfig::DCMHardwareConfig::_fetchTimingSystemValues(), getTableName(), and getTrueValueFor3Keys().

242 {
243  std::string key =
244  boost::lexical_cast<std::string>(primarySelectionValue);
245 
246  if (!_getValueFromContainer(key, dataColumnName, resultValue)) {
247  if (_keyElementsForDefaults.size() < 1) {return false;}
248 
249  key = _keyElementsForDefaults[0];
250  if (_noKeyElementForDefaults[0]) {
252  boost::lexical_cast<std::string>
253  (primarySelectionValue));
254  }
255 
256  return _getValueFromContainer(key, dataColumnName, resultValue);
257  }
258  return true;
259 }
std::vector< std::string > _keyElementsForDefaults
std::vector< bool > _noKeyElementForDefaults
bool replace_all(std::string &in, std::string const &from, std::string const &to)
Replace all occurrences of from in string with to.
static const std::string NO_DEFAULT_KEY_STRING
bool _getValueFromContainer(const std::string &key, const std::string &dataColumnName, T &value)
enum BeamMode string
template<class T , class U , class V >
bool dbutils::daqconfig::ConfigDataTree::getEffectiveValueFor2Keys ( const U &  primarySelectionValue,
const V &  secondarySelectionValue,
const std::string dataColumnName,
T resultValue 
)

Fetches the requested value...

Definition at line 266 of file ConfigDataTree.h.

References _getValueFromContainer(), _keyElementsForDefaults, _noKeyElementForDefaults, getEffectiveValueFor3Keys(), findDuplicateFiles::key, KEY_SEPARATOR_STRING, NO_DEFAULT_KEY_STRING, cet::replace_all(), and string.

Referenced by dbutils::daqconfig::DCMHardwareConfig::_fetchASICRegisterValues(), dbutils::daqconfig::DCMHardwareConfig::_fetchFEBPulserValues(), dbutils::daqconfig::DCMHardwareConfig::_fetchPixelEnableMasks(), getEffectiveValueFor1Key(), and getTableName().

270 {
271  std::string key =
272  boost::lexical_cast<std::string>(primarySelectionValue) +
274  boost::lexical_cast<std::string>(secondarySelectionValue);
275 
276  if (! _getValueFromContainer(key, dataColumnName, resultValue)) {
277  if (_keyElementsForDefaults.size() < 2) {return false;}
278 
279  std::string secondKeyElement = _keyElementsForDefaults[1];
280  if (_noKeyElementForDefaults[1]) {
281  boost::replace_all(secondKeyElement, NO_DEFAULT_KEY_STRING,
282  boost::lexical_cast<std::string>
283  (secondarySelectionValue));
284  }
285  key = boost::lexical_cast<std::string>(primarySelectionValue) +
286  KEY_SEPARATOR_STRING + secondKeyElement;
287 
288  if (! _getValueFromContainer(key, dataColumnName, resultValue)) {
289  std::string firstKeyElement = _keyElementsForDefaults[0];
290  if (_noKeyElementForDefaults[0]) {
291  boost::replace_all(firstKeyElement, NO_DEFAULT_KEY_STRING,
292  boost::lexical_cast<std::string>
293  (primarySelectionValue));
294  }
295  key = firstKeyElement + KEY_SEPARATOR_STRING + secondKeyElement;
296 
297  return _getValueFromContainer(key, dataColumnName,
298  resultValue);
299  }
300  }
301  return true;
302 }
std::vector< std::string > _keyElementsForDefaults
std::vector< bool > _noKeyElementForDefaults
bool replace_all(std::string &in, std::string const &from, std::string const &to)
Replace all occurrences of from in string with to.
static const std::string NO_DEFAULT_KEY_STRING
bool _getValueFromContainer(const std::string &key, const std::string &dataColumnName, T &value)
static const std::string KEY_SEPARATOR_STRING
enum BeamMode string
template<class T , class U , class V , class W >
bool dbutils::daqconfig::ConfigDataTree::getEffectiveValueFor3Keys ( const U &  primarySelectionValue,
const V &  secondarySelectionValue,
const W tertiarySelectionValue,
const std::string dataColumnName,
T resultValue 
)

Fetches the requested value...

Definition at line 309 of file ConfigDataTree.h.

References _getValueFromContainer(), _keyElementsForDefaults, _noKeyElementForDefaults, findDuplicateFiles::key, KEY_SEPARATOR_STRING, NO_DEFAULT_KEY_STRING, cet::replace_all(), and string.

Referenced by getEffectiveValueFor2Keys(), and getTableName().

314 {
315  std::string key =
316  boost::lexical_cast<std::string>(primarySelectionValue) +
318  boost::lexical_cast<std::string>(secondarySelectionValue) +
320  boost::lexical_cast<std::string>(tertiarySelectionValue);
321 
322  if (! _getValueFromContainer(key, dataColumnName, resultValue)) {
323  if (_keyElementsForDefaults.size() < 3) {return false;}
324 
325  std::string thirdKeyElement = _keyElementsForDefaults[2];
326  if (_noKeyElementForDefaults[2]) {
327  boost::replace_all(thirdKeyElement, NO_DEFAULT_KEY_STRING,
328  boost::lexical_cast<std::string>
329  (tertiarySelectionValue));
330  }
331  key = boost::lexical_cast<std::string>(primarySelectionValue) +
333  boost::lexical_cast<std::string>(secondarySelectionValue) +
334  KEY_SEPARATOR_STRING + thirdKeyElement;
335 
336  if (! _getValueFromContainer(key, dataColumnName, resultValue)) {
337  std::string secondKeyElement = _keyElementsForDefaults[1];
338  if (_noKeyElementForDefaults[1]) {
339  boost::replace_all(secondKeyElement, NO_DEFAULT_KEY_STRING,
340  boost::lexical_cast<std::string>
341  (secondarySelectionValue));
342  }
343  key = boost::lexical_cast<std::string>(primarySelectionValue) +
344  KEY_SEPARATOR_STRING + secondKeyElement +
345  KEY_SEPARATOR_STRING + thirdKeyElement;
346 
347  if (! _getValueFromContainer(key, dataColumnName,
348  resultValue)) {
349  std::string firstKeyElement = _keyElementsForDefaults[0];
350  if (_noKeyElementForDefaults[0]) {
351  boost::replace_all(firstKeyElement, NO_DEFAULT_KEY_STRING,
352  boost::lexical_cast<std::string>
353  (primarySelectionValue));
354  }
355  key = firstKeyElement +
356  KEY_SEPARATOR_STRING + secondKeyElement +
357  KEY_SEPARATOR_STRING + thirdKeyElement;
358 
359  return _getValueFromContainer(key, dataColumnName,
360  resultValue);
361  }
362  }
363  }
364  return true;
365 }
std::vector< std::string > _keyElementsForDefaults
std::vector< bool > _noKeyElementForDefaults
bool replace_all(std::string &in, std::string const &from, std::string const &to)
Replace all occurrences of from in string with to.
static const std::string NO_DEFAULT_KEY_STRING
bool _getValueFromContainer(const std::string &key, const std::string &dataColumnName, T &value)
static const std::string KEY_SEPARATOR_STRING
enum BeamMode string
std::vector<std::string> dbutils::daqconfig::ConfigDataTree::getSelectorColumnNames ( ) const
inline

Definition at line 60 of file ConfigDataTree.h.

References _configSelector, and dbutils::daqconfig::ConfigDataSelector::getSelectionColumns().

Referenced by _initialize().

61  {
63  }
std::vector< std::string > getSelectionColumns() const
std::string dbutils::daqconfig::ConfigDataTree::getSelectorValueForDefault ( std::string  columnName) const
inline

Definition at line 64 of file ConfigDataTree.h.

References _selectorDefaultValueMap, and NO_DEFAULT_KEY_STRING.

Referenced by _initialize().

65  {
66  ConfigValueMap::const_iterator iter =
67  _selectorDefaultValueMap.find(columnName);
68  if (iter == _selectorDefaultValueMap.end()) {
69  return NO_DEFAULT_KEY_STRING;
70  }
71  else {
72  return iter->second;
73  }
74  }
static const std::string NO_DEFAULT_KEY_STRING
std::string dbutils::daqconfig::ConfigDataTree::getTableName ( ) const
inline
template<class T >
bool dbutils::daqconfig::ConfigDataTree::getTrueValue ( const std::string dataColumnName,
T resultValue 
)

Fetches the requested value...

Definition at line 179 of file ConfigDataTree.h.

References _getValueFromContainer(), getTrueValueFor1Key(), findDuplicateFiles::key, KEY_FOR_SYSTEM_WIDE_PARAM, and string.

Referenced by dbutils::daqconfig::NDMRunConfig::_fetchAllData(), dbutils::daqconfig::DCMRunConfig::_fetchDCMSystemParams(), dbutils::daqconfig::DCMHardwareConfig::_fetchDCMSystemParams(), and getTableName().

180 {
182  return _getValueFromContainer(key, dataColumnName, resultValue);
183 }
bool _getValueFromContainer(const std::string &key, const std::string &dataColumnName, T &value)
static const std::string KEY_FOR_SYSTEM_WIDE_PARAM
enum BeamMode string
template<class T , class U >
bool dbutils::daqconfig::ConfigDataTree::getTrueValueFor1Key ( const U &  primarySelectionValue,
const std::string dataColumnName,
T resultValue 
)

Fetches the requested value...

Definition at line 190 of file ConfigDataTree.h.

References _getValueFromContainer(), getTrueValueFor2Keys(), findDuplicateFiles::key, and string.

Referenced by getTableName(), and getTrueValue().

192 {
193  std::string key =
194  boost::lexical_cast<std::string>(primarySelectionValue);
195  return _getValueFromContainer(key, dataColumnName, resultValue);
196 }
bool _getValueFromContainer(const std::string &key, const std::string &dataColumnName, T &value)
enum BeamMode string
template<class T , class U , class V >
bool dbutils::daqconfig::ConfigDataTree::getTrueValueFor2Keys ( const U &  primarySelectionValue,
const V &  secondarySelectionValue,
const std::string dataColumnName,
T resultValue 
)

Fetches the requested value...

Definition at line 203 of file ConfigDataTree.h.

References _getValueFromContainer(), getTrueValueFor3Keys(), findDuplicateFiles::key, KEY_SEPARATOR_STRING, and string.

Referenced by getTableName(), and getTrueValueFor1Key().

207 {
208  std::string key =
209  boost::lexical_cast<std::string>(primarySelectionValue) +
211  boost::lexical_cast<std::string>(secondarySelectionValue);
212  return _getValueFromContainer(key, dataColumnName, resultValue);
213 }
bool _getValueFromContainer(const std::string &key, const std::string &dataColumnName, T &value)
static const std::string KEY_SEPARATOR_STRING
enum BeamMode string
template<class T , class U , class V , class W >
bool dbutils::daqconfig::ConfigDataTree::getTrueValueFor3Keys ( const U &  primarySelectionValue,
const V &  secondarySelectionValue,
const W tertiarySelectionValue,
const std::string dataColumnName,
T resultValue 
)

Fetches the requested value...

Definition at line 220 of file ConfigDataTree.h.

References _getValueFromContainer(), getEffectiveValueFor1Key(), findDuplicateFiles::key, KEY_SEPARATOR_STRING, and string.

Referenced by getTableName(), and getTrueValueFor2Keys().

225 {
226  std::string key =
227  boost::lexical_cast<std::string>(primarySelectionValue) +
229  boost::lexical_cast<std::string>(secondarySelectionValue) +
231  boost::lexical_cast<std::string>(tertiarySelectionValue);
232  return _getValueFromContainer(key, dataColumnName, resultValue);
233 }
bool _getValueFromContainer(const std::string &key, const std::string &dataColumnName, T &value)
static const std::string KEY_SEPARATOR_STRING
enum BeamMode string
bool dbutils::daqconfig::ConfigDataTree::hasValidData ( ) const
inline

Definition at line 58 of file ConfigDataTree.h.

References _hasValidData.

bool dbutils::daqconfig::ConfigDataTree::saveValues ( const std::vector< dbutils::SimpleParameterSet > &  newDataList) const

Definition at line 227 of file ConfigDataTree.cpp.

References _initialize(), _tableDefinitionFilename, om::cout, mkDefs::detName, allTimeWatchdog::endl, dbutils::SimpleParameterSet::get(), novadaq::EnvVarCache::getEnvVar(), novadaq::EnvVarCache::getInstance(), compare_h5_caf::idx, makeTrainCVSamples::int, nova::dbi::kDAQTable, findDuplicateFiles::key, dbutils::SimpleParameterSet::keys(), LINE_NUMBER_DEBUG, string, and dbutils::SimpleParameterSet::toString().

Referenced by ConfigDataTree(), and getTableName().

228 {
229  // check if a debug flag has been specified
230  int debugFlag = 0;
231  std::string debugString =
232  novadaq::EnvVarCache::getInstance().getEnvVar("CONFIG_DATA_TREE_DEBUG");
233  if (debugString.length() > 0) {
234  try {debugFlag = boost::lexical_cast<int>(debugString);}
235  catch (...) {}
236  }
237 
238  boost::shared_ptr<NOVADB::Table> dbTablePtr;
239  dbTablePtr.reset(new NOVADB::Table(_tableDefinitionFilename.c_str()));
241  novadaq::EnvVarCache::getInstance().getEnvVar("NOVADAQ_ENVIRONMENT");
242  dbTablePtr->SetDetector(detName);
243  dbTablePtr->SetTableType(NOVADB::kDAQTable);
244  std::string dbUser =
245  novadaq::EnvVarCache::getInstance().getEnvVar("CFGMGR_DB_USER");
247  if (dbUser.length() > 0) {
249  dbTablePtr->SetUser(dbUser);
250  }
252  if (! dbTablePtr->GetConnection()) {return false;}
254  if (! dbTablePtr->ExistsInDB()) {return false;}
256 
257  if ((debugFlag & 0x20) != 0) {
258  dbTablePtr->SetVerbosity(1);
259  }
260 
261  if ((debugFlag & 0x04) != 0) {
262  std::cout << "*** ConfigDataTree for " << dbTablePtr->Name()
263  << ", storing values:" << std::endl;
264  }
265 
266  for (int idx = 0; idx < (int) newDataList.size(); ++idx) {
267  dbutils::SimpleParameterSet paramSet = newDataList[idx];
269 
270  if ((debugFlag & 0x04) != 0) {
271  std::cout << " " << paramSet.toString() << std::endl;
272  }
273 
274  boost::shared_ptr<NOVADB::Row> newRow(dbTablePtr->NewRow());
275  if (newRow.get() == 0) {return false;}
277 
278  std::vector<std::string> keyList = paramSet.keys();
279  for (int jdx = 0; jdx < (int) keyList.size(); ++jdx) {
280 
281  std::string key = keyList[jdx];
283  if (paramSet.get(key, value)) {
284  newRow->Set(key, value);
285  }
286  }
288 
289  dbTablePtr->AddRow(newRow.get());
291  }
293 
294  if (! dbTablePtr->WriteToDB()) {return false;}
296 
297  return true;
298 }
std::vector< std::string > keys() const
static EnvVarCache & getInstance()
Definition: EnvVarCache.cpp:12
#define LINE_NUMBER_DEBUG
bool get(const std::string &key, T &resultValue) const
const XML_Char int const XML_Char * value
Definition: expat.h:331
OStream cout
Definition: OStream.cxx:6
std::string getEnvVar(std::string name)
Definition: EnvVarCache.cpp:33
detName
Definition: mkDefs.py:106
enum BeamMode string

Member Data Documentation

ConfigDataSelector dbutils::daqconfig::ConfigDataTree::_configSelector
private

Definition at line 162 of file ConfigDataTree.h.

Referenced by ConfigDataTree(), and getSelectorColumnNames().

std::vector<std::string> dbutils::daqconfig::ConfigDataTree::_dataColumnNameList
private

Definition at line 165 of file ConfigDataTree.h.

Referenced by ConfigDataTree(), and getDataColumnNames().

std::vector<std::string> dbutils::daqconfig::ConfigDataTree::_dataColumnTypeList
private

Definition at line 166 of file ConfigDataTree.h.

Referenced by _initialize(), ConfigDataTree(), and getDataColumnTypes().

ConfigValueListMap dbutils::daqconfig::ConfigDataTree::_distinctSelectorValueMap
private

Definition at line 164 of file ConfigDataTree.h.

Referenced by _initialize(), and getDistinctSelectorColumnValues().

bool dbutils::daqconfig::ConfigDataTree::_hasValidData
private

Definition at line 160 of file ConfigDataTree.h.

Referenced by _initialize(), ConfigDataTree(), and hasValidData().

std::vector<std::string> dbutils::daqconfig::ConfigDataTree::_keyElementsForDefaults
private
std::vector<bool> dbutils::daqconfig::ConfigDataTree::_noKeyElementForDefaults
private
ConfigDataContainer dbutils::daqconfig::ConfigDataTree::_resultSet
private

Definition at line 168 of file ConfigDataTree.h.

Referenced by _getValueFromContainer(), and _initialize().

ConfigValueMap dbutils::daqconfig::ConfigDataTree::_selectorDefaultValueMap
private

Definition at line 163 of file ConfigDataTree.h.

Referenced by _initialize(), and getSelectorValueForDefault().

std::string dbutils::daqconfig::ConfigDataTree::_tableDefinitionFilename
private

Definition at line 161 of file ConfigDataTree.h.

Referenced by ConfigDataTree(), and saveValues().

std::string dbutils::daqconfig::ConfigDataTree::_tableName
private

Definition at line 167 of file ConfigDataTree.h.

Referenced by _initialize(), and getTableName().

const std::string dbutils::daqconfig::ConfigDataTree::KEY_FOR_SYSTEM_WIDE_PARAM
static

Definition at line 31 of file ConfigDataTree.h.

Referenced by _initialize(), and getTrueValue().

const std::string dbutils::daqconfig::ConfigDataTree::KEY_SEPARATOR_STRING
static
const std::string dbutils::daqconfig::ConfigDataTree::NO_DEFAULT_KEY_STRING
static

The documentation for this class was generated from the following files: