DLRunConfig.cpp
Go to the documentation of this file.
1 #include <DatabaseUtils/DAQConfig/DLRunConfig.h>
2 #include <DatabaseUtils/DAQConfig/ConfigDataTree.h>
3 #include <DatabaseUtils/DAQConfig/DBColumnParams.h>
4 #include <DatabaseUtils/DAQConfig/DBColumnUtils.h>
5 #include <DatabaseUtils/DAQConfig/NamedConfigUtils.h>
6 #include <NovaDatabase/Table.h>
7 #include <NovaDAQUtilities/EnvVarCache.h>
8 #include <boost/algorithm/string.hpp>
9 
10 namespace NOVADB = nova::database;
11 
12 namespace dbutils {
13 namespace daqconfig {
14 
15 /**
16  * Creates a DataLogger run configuration object from the specified
17  * list of subsystem configuration IDs.
18  *
19  * @param subsystemConfigIdList The list of subsystem
20  * configuration IDs.
21  * @param dcmName The name of the DCM of interest.
22  */
24 DLRunConfig(const std::vector<int64_t>& subsystemConfigIdList)
25 {
27  if (subsystemConfigIdList.size() > 0) {
28  _primarySubsystemConfigId = subsystemConfigIdList[0];
29  _hasValidData = _fetchAllData(subsystemConfigIdList);
30  }
31  else {
32  _hasValidData = false;
33  }
34 }
35 
36 /**
37  * Creates a DataLogger run configuration object from the specified
38  * subsystem configuration specification.
39  *
40  * @param nameSpec The named configuration of interest.
41  */
43 {
45  std::vector<int64_t> subsystemConfigIdList;
46  if (NamedConfigUtils::
47  getSubsystemConfigIdAncestry(nameSpec, subsystemConfigIdList)) {
48  _primarySubsystemConfigId = subsystemConfigIdList[0];
49  _hasValidData = _fetchAllData(subsystemConfigIdList);
50  }
51  else {
52  _hasValidData = false;
53  }
54 }
55 
56 /**
57  * Creates a DataLogger run configuration object from the specified
58  * global configuration specification.
59  *
60  * @param nameSpec The named configuration of interest.
61  */
63 {
65  int64_t subsystemConfigId;
69  DL_SUBSYSTEM_NAME,
71  RUN_CONFIG_TYPE,
72  subsystemConfigId);
73 
74  std::vector<int64_t> subsystemConfigIdList;
75  if (status) {
76  IDSpec idSpec(subsystemConfigId, IDSpec::SUBSYSTEM, IDSpec::DAQ);
77  status = NamedConfigUtils::
78  getConfigIdAncestry(idSpec, subsystemConfigIdList);
79  }
80 
81  if (status) {
82  _primarySubsystemConfigId = subsystemConfigIdList[0];
83  _hasValidData = _fetchAllData(subsystemConfigIdList);
84  }
85  else {
86  _hasValidData = false;
87  }
88 }
89 
90 /**
91  * Creates a DataLogger run configuration object from the specified
92  * global configuration ID.
93  *
94  * @param globalConfigId The ID of the global configuration of interest.
95  */
96 DLRunConfig::DLRunConfig(const int64_t& globalConfigId)
97 {
98  IDSpec idSpec(globalConfigId, IDSpec::GLOBAL, IDSpec::DAQ);
100  std::vector<int64_t> subsystemConfigIdList;
101  if (NamedConfigUtils::
102  getSubsystemConfigIdAncestryFromGlobalId(idSpec,
104  DL_SUBSYSTEM_NAME,
106  RUN_CONFIG_TYPE,
107  subsystemConfigIdList)) {
108  _primarySubsystemConfigId = subsystemConfigIdList[0];
109  _hasValidData = _fetchAllData(subsystemConfigIdList);
110  }
111  else {
112  _hasValidData = false;
113  }
114 }
115 
116 bool DLRunConfig::
117 _fetchAllData(const std::vector<int64_t>& subsystemConfigIdList)
118 {
119  bool status = true;
121 
122  // for the DL configuration, inheritance is not used,
123  // so only the first subsystem ID is relevant
124  int64_t subsystemConfigId = subsystemConfigIdList[0];
125 
126  if (status) {
127  fname = "NovaDatabase/tables/DAQConfig/DataLoggerStreams.xml";
128  status = _fetchStreamData(fname, subsystemConfigId);
129  }
130  if (status) {
131  fname = "NovaDatabase/tables/DAQConfig/DataLoggerSystemParameters.xml";
132  status = _fetchSystemData(fname, subsystemConfigId);
133  }
134 
135  return status;
136 }
137 
138 bool DLRunConfig::
139 _fetchStreamData(const std::string& tableDefinitionFileName,
140  const int64_t& subsystemConfigId)
141 {
142  boost::shared_ptr<NOVADB::Table> dbt;
143  dbt.reset(new NOVADB::Table(tableDefinitionFileName));
145  novadaq::EnvVarCache::getInstance().getEnvVar("NOVADAQ_ENVIRONMENT");
146  dbt->SetDetector(detName);
147  std::string dbUser =
148  novadaq::EnvVarCache::getInstance().getEnvVar("CFGMGR_DB_USER");
149  if (dbUser.length() > 0) {dbt->SetUser(dbUser);}
150  if (! dbt->GetConnection()) {return false;}
151  if (! dbt->ExistsInDB()) {return false;}
152 
153  dbt->Clear();
154  dbt->SetValidityRange(NamedConfigUtils::SUBSYSCFGID_COLUMN_NAME,
155  subsystemConfigId);
156  if (! dbt->LoadFromDB()) {return false;}
157 
158  std::vector<std::string> colNames = dbt->GetColNames();
159  NOVADB::Row* rowPtr;
160  NOVADB::Column* colPtr;
161  for (int rowIdx = 0; rowIdx < dbt->NRow(); ++rowIdx) {
162  boost::shared_ptr<SimpleParameterSet>
163  streamParamSet(new SimpleParameterSet());
164  rowPtr = dbt->GetRow(rowIdx);
165 
166  for (uint32_t colIdx = 0; colIdx < colNames.size(); ++colIdx) {
167  std::string colName = boost::to_lower_copy(colNames[colIdx]);
168  if (DBColumnUtils::isInfrastructureColumn(colName)) {continue;}
170  continue;
171  }
172 
173  std::string valueString;
174  colPtr = rowPtr->Col(colName);
175  if (! colPtr->Get(valueString)) {
176  return false;
177  }
178  streamParamSet->put(colName, valueString);
179  }
180 
181  _streamList.push_back(streamParamSet);
182  }
183 
184  return true;
185 }
186 
187 bool DLRunConfig::
188 _fetchSystemData(const std::string& tableDefinitionFileName,
189  const int64_t& subsystemConfigId)
190 {
191  boost::shared_ptr<NOVADB::Table> dbt;
192  dbt.reset(new NOVADB::Table(tableDefinitionFileName));
194  novadaq::EnvVarCache::getInstance().getEnvVar("NOVADAQ_ENVIRONMENT");
195  dbt->SetDetector(detName);
196  std::string dbUser =
197  novadaq::EnvVarCache::getInstance().getEnvVar("CFGMGR_DB_USER");
198  if (dbUser.length() > 0) {dbt->SetUser(dbUser);}
199  if (! dbt->GetConnection()) {return false;}
200  if (! dbt->ExistsInDB()) {return false;}
201 
202  dbt->Clear();
203  dbt->SetValidityRange(NamedConfigUtils::SUBSYSCFGID_COLUMN_NAME,
204  subsystemConfigId);
205  if (! dbt->LoadFromDB()) {return false;}
206 
207  if (dbt->NRow() != 1) {return false;}
208 
209  NOVADB::Row* rowPtr = dbt->GetRow(0);
210  NOVADB::Column* colPtr = rowPtr->Col("outputPath");
211  if (! colPtr->Get(_outputPath)) {
212  return false;
213  }
214 
215  return true;
216 }
217 
218 } // end of namespace daqconfig
219 } // end of namespace dbutils
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
bool _fetchSystemData(const std::string &tableDefinitionFileName, const int64_t &subsystemConfigId)
bool Get(T &val) const
Definition: Column.h:53
static bool isSubsystemConfigReferenceColumn(const std::string &columnName)
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
bool _fetchAllData(const std::vector< int64_t > &subsystemConfigIdList)
std::string getEnvVar(std::string name)
Definition: EnvVarCache.cpp:33
static bool isInfrastructureColumn(const std::string &columnName)
DLRunConfig(const std::vector< int64_t > &subsystemConfigIdList)
Definition: DLRunConfig.cpp:24
bool _fetchStreamData(const std::string &tableDefinitionFileName, const int64_t &subsystemConfigId)
static const std::string SUBSYSCFGID_COLUMN_NAME
detName
Definition: mkDefs.py:106
Column & Col(int i)
Definition: Row.h:51