BNEVBRunConfig.cpp
Go to the documentation of this file.
1 #include <DatabaseUtils/DAQConfig/BNEVBRunConfig.h>
2 #include <DatabaseUtils/DAQConfig/DBColumnParams.h>
3 #include <DatabaseUtils/DAQConfig/DBColumnUtils.h>
4 #include <DatabaseUtils/DAQConfig/NamedConfigUtils.h>
5 #include <NovaDatabase/Table.h>
6 #include <NovaDAQUtilities/EnvVarCache.h>
7 #include <boost/algorithm/string.hpp>
8 
9 namespace NOVADB = nova::database;
10 
11 namespace dbutils {
12 namespace daqconfig {
13 
14 /**
15  * Creates a BufferNodeEVB run configuration object from the specified
16  * list of subsystem configuration IDs.
17  *
18  * @param subsystemConfigIdList The list of subsystem
19  * configuration IDs.
20  * @param dcmName The name of the DCM of interest.
21  */
23 BNEVBRunConfig(const std::vector<int64_t>& subsystemConfigIdList)
24 {
26  if (subsystemConfigIdList.size() > 0) {
27  _primarySubsystemConfigId = subsystemConfigIdList[0];
28  _hasValidData = _fetchAllData(subsystemConfigIdList);
29  }
30  else {
31  _hasValidData = false;
32  }
33 }
34 
35 /**
36  * Creates a BufferNodeEVB run configuration object from the specified
37  * subsystem configuration specification.
38  *
39  * @param nameSpec The named configuration of interest.
40  */
42 {
44  std::vector<int64_t> subsystemConfigIdList;
45  if (NamedConfigUtils::
46  getSubsystemConfigIdAncestry(nameSpec, subsystemConfigIdList)) {
47  _primarySubsystemConfigId = subsystemConfigIdList[0];
48  _hasValidData = _fetchAllData(subsystemConfigIdList);
49  }
50  else {
51  _hasValidData = false;
52  }
53 }
54 
55 /**
56  * Creates a BufferNodeEVB run configuration object from the specified
57  * global configuration specification.
58  *
59  * @param nameSpec The named configuration of interest.
60  */
62 {
64  int64_t subsystemConfigId;
68  BNEVB_SUBSYSTEM_NAME,
70  RUN_CONFIG_TYPE,
71  subsystemConfigId);
72 
73  std::vector<int64_t> subsystemConfigIdList;
74  if (status) {
75  IDSpec idSpec(subsystemConfigId, IDSpec::SUBSYSTEM, IDSpec::DAQ);
76  status = NamedConfigUtils::
77  getConfigIdAncestry(idSpec, subsystemConfigIdList);
78  }
79 
80  if (status) {
81  _primarySubsystemConfigId = subsystemConfigIdList[0];
82  _hasValidData = _fetchAllData(subsystemConfigIdList);
83  }
84  else {
85  _hasValidData = false;
86  }
87 }
88 
89 /**
90  * Creates a BufferNodeEVB run configuration object from the specified
91  * global configuration ID.
92  *
93  * @param globalConfigId The ID of the global configuration of interest.
94  */
95 BNEVBRunConfig::BNEVBRunConfig(const int64_t& globalConfigId)
96 {
97  IDSpec idSpec(globalConfigId, IDSpec::GLOBAL, IDSpec::DAQ);
99  std::vector<int64_t> subsystemConfigIdList;
100  if (NamedConfigUtils::
101  getSubsystemConfigIdAncestryFromGlobalId(idSpec,
103  BNEVB_SUBSYSTEM_NAME,
105  RUN_CONFIG_TYPE,
106  subsystemConfigIdList)) {
107  _primarySubsystemConfigId = subsystemConfigIdList[0];
108  _hasValidData = _fetchAllData(subsystemConfigIdList);
109  }
110  else {
111  _hasValidData = false;
112  }
113 }
114 
115 bool BNEVBRunConfig::
116 _fetchAllData(const std::vector<int64_t>& subsystemConfigIdList)
117 {
118  bool status = true;
120 
121  // for the BNEVB configuration, inheritance is not used,
122  // so only the first subsystem ID is relevant
123  int64_t subsystemConfigId = subsystemConfigIdList[0];
124 
125  if (status) {
126  fname = "NovaDatabase/tables/DAQConfig/BNEVBRunParameters.xml";
127  status = _fetchSystemData(fname, subsystemConfigId);
128  }
129 
130  return status;
131 }
132 
133 bool BNEVBRunConfig::
134 _fetchSystemData(const std::string& tableDefinitionFileName,
135  const int64_t& subsystemConfigId)
136 {
137  boost::shared_ptr<NOVADB::Table> dbt;
138  dbt.reset(new NOVADB::Table(tableDefinitionFileName));
140  novadaq::EnvVarCache::getInstance().getEnvVar("NOVADAQ_ENVIRONMENT");
141  dbt->SetDetector(detName);
142  std::string dbUser =
143  novadaq::EnvVarCache::getInstance().getEnvVar("CFGMGR_DB_USER");
144  if (dbUser.length() > 0) {dbt->SetUser(dbUser);}
145  if (! dbt->GetConnection()) {return false;}
146  if (! dbt->ExistsInDB()) {return false;}
147 
148  dbt->Clear();
149  dbt->SetValidityRange(NamedConfigUtils::SUBSYSCFGID_COLUMN_NAME,
150  subsystemConfigId);
151  if (! dbt->LoadFromDB()) {return false;}
152 
153  if (dbt->NRow() != 1) {return false;}
154 
155  NOVADB::Row* rowPtr = dbt->GetRow(0);
156  NOVADB::Column* colPtr = rowPtr->Col("poolSizeSeconds");
157  if (! colPtr->Get(_poolSizeSeconds)) {
158  return false;
159  }
160 
161  return true;
162 }
163 
164 } // end of namespace daqconfig
165 } // end of namespace dbutils
bool _fetchSystemData(const std::string &tableDefinitionFileName, const int64_t &subsystemConfigId)
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 EnvVarCache & getInstance()
Definition: EnvVarCache.cpp:12
BNEVBRunConfig(const std::vector< int64_t > &subsystemConfigIdList)
bool Get(T &val) const
Definition: Column.h:53
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)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::string getEnvVar(std::string name)
Definition: EnvVarCache.cpp:33
bool _fetchAllData(const std::vector< int64_t > &subsystemConfigIdList)
static const std::string SUBSYSCFGID_COLUMN_NAME
detName
Definition: mkDefs.py:106
Column & Col(int i)
Definition: Row.h:51