GTRunConfig.cpp
Go to the documentation of this file.
1 #include <DatabaseUtils/DAQConfig/GTRunConfig.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 GT 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 GTRunConfig(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 GT 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 GT run configuration object from the specified
58  * global configuration specification.
59  *
60  * @param nameSpec The named configuration of interest.
61  */
63 {
64  _hasValidData=false;
66  int64_t subsystemConfigId;
67  if(!NamedConfigUtils::
68  getSubsystemConfigIdFromGlobalName(nameSpec,
70  GT_SUBSYSTEM_NAME,
72  RUN_CONFIG_TYPE,
73  subsystemConfigId))
74  throw db_exception(SubsystemNameSpec::GT_SUBSYSTEM_NAME,"Could not get ConfigId");
75 
76  std::vector<int64_t> subsystemConfigIdList;
77  IDSpec idSpec(subsystemConfigId, IDSpec::SUBSYSTEM, IDSpec::DAQ);
78  if(!NamedConfigUtils::
79  getConfigIdAncestry(idSpec, subsystemConfigIdList))
80  throw db_exception("getConfigIdAncestry"," Failed");
81 
82  _primarySubsystemConfigId = subsystemConfigIdList[0];
83  _hasValidData = _fetchAllData(subsystemConfigIdList);
84 }
85 
86 /**
87  * Creates a GT run configuration object from the specified
88  * global configuration ID.
89  *
90  * @param globalConfigId The ID of the global configuration of interest.
91  */
92 GTRunConfig::GTRunConfig(const int64_t& globalConfigId)
93 {
94  IDSpec idSpec(globalConfigId, IDSpec::GLOBAL, IDSpec::DAQ);
96  std::vector<int64_t> subsystemConfigIdList;
97  if (!NamedConfigUtils::
98  getSubsystemConfigIdAncestryFromGlobalId(idSpec,
100  GT_SUBSYSTEM_NAME,
102  RUN_CONFIG_TYPE,
103  subsystemConfigIdList))
104  throw db_exception(SubsystemNameSpec::GT_SUBSYSTEM_NAME,"Could not get ConfigId");
105  _primarySubsystemConfigId = subsystemConfigIdList[0];
106  _hasValidData = _fetchAllData(subsystemConfigIdList);
107 }
108 
109 bool GTRunConfig::
110 _fetchAllData(const std::vector<int64_t>& subsystemConfigIdList)
111 {
113 
114  // for the GT configuration, inheritance is not used,
115  // so only the first subsystem ID is relevant
116  int64_t subsystemConfigId = subsystemConfigIdList[0];
117  std::cout<<"SystemConfigId="<<_primarySubsystemConfigId<<", SubSystemConfigId="<<subsystemConfigId<<std::endl;
118  fname = "NovaDatabase/tables/DAQConfig/CalibrationTriggers.xml";
119  _fetchTriggerData(fname, subsystemConfigId,_calibrationTriggerList);
120  fname = "NovaDatabase/tables/DAQConfig/ExternalTriggers.xml";
121  _fetchTriggerData(fname, subsystemConfigId,_externalTriggerList);
122  fname = "NovaDatabase/tables/DAQConfig/ManualTriggers.xml";
123  _fetchTriggerData(fname, subsystemConfigId,_manualTriggerList);
124  fname = "NovaDatabase/tables/DAQConfig/SpillTriggers.xml";
125  _fetchTriggerData(fname, subsystemConfigId,_spillTriggerList);
126  fname = "NovaDatabase/tables/DAQConfig/DataDrivenTriggers.xml";
127  _fetchTriggerData(fname, subsystemConfigId,_dataDrivenTriggerList);
128  fname = "NovaDatabase/tables/DAQConfig/SNEWSTriggers.xml";
129  _fetchTriggerData(fname, subsystemConfigId,_SNEWSTriggerList);
130  fname = "NovaDatabase/tables/DAQConfig/SuperNovaFilter.xml";
131  _fetchTriggerData(fname, subsystemConfigId,_NSNFilterList);
132  fname = "NovaDatabase/tables/DAQConfig/DAQStatusTriggers.xml";
133  _fetchTriggerData(fname, subsystemConfigId,_daqStatusTriggerList);
134 
135  fname = "NovaDatabase/tables/DAQConfig/SuperNovaTrigger.xml";
136  _fetchParameterSet(fname, subsystemConfigId,_NSNTriggerParams);
137  fname = "NovaDatabase/tables/DAQConfig/TriggerOffsets.xml";
138  _fetchParameterSet(fname, subsystemConfigId,_triggerOffset);
139  fname = "NovaDatabase/tables/DAQConfig/GlobalThrottle.xml";
140  _fetchParameterSet(fname, subsystemConfigId,_globalThrottle);
141  fname = "NovaDatabase/tables/DAQConfig/DDTThrottle.xml";
142  _fetchParameterSet(fname, subsystemConfigId,_DDTThrottle);
143  fname = "NovaDatabase/tables/DAQConfig/GTQueue.xml";
144  _fetchParameterSet(fname, subsystemConfigId,_gtQueue);
145  fname = "NovaDatabase/tables/DAQConfig/SNEWSPipe.xml";
146  _fetchParameterSet(fname, subsystemConfigId,_SNEWSPipe);
147  fname = "NovaDatabase/tables/DAQConfig/GTGeneral.xml";
148  _fetchParameterSet(fname, subsystemConfigId,_gtGeneral);
149  return true;
150 }
151 
152 bool GTRunConfig::
153 _fetchParameterSet(const std::string& tableDefinitionFileName,
154  const int64_t& subsystemConfigId,
155  boost::shared_ptr<SimpleParameterSet> & parSet)
156 {
157  TriggerList tmpTriggerList;
158  _fetchTriggerData(tableDefinitionFileName, subsystemConfigId,
159  tmpTriggerList);
160  int listSize=tmpTriggerList.size();
161  if(listSize==0) throw GTRunConfig::db_exception(tableDefinitionFileName,
162  "ParameterSet is empty");
163  if(listSize>1) {
164  char buf[10];
165  sprintf(buf,"%d",listSize);
166  throw GTRunConfig::db_exception(tableDefinitionFileName,
167  "ParameterSet size = "+std::string(buf)+">1");
168  }
169  parSet = tmpTriggerList[0];
170  return true;
171 }
172 
173 bool GTRunConfig::
174 _fetchTriggerData(const std::string& tableDefinitionFileName,
175  const int64_t& subsystemConfigId,
176  TriggerList& triggerList)
177 {
178  boost::shared_ptr<NOVADB::Table> dbt;
179  dbt.reset(new NOVADB::Table(tableDefinitionFileName));
181  novadaq::EnvVarCache::getInstance().getEnvVar("NOVADAQ_ENVIRONMENT");
182  dbt->SetDetector(detName);
183  std::string dbUser =
184  novadaq::EnvVarCache::getInstance().getEnvVar("CFGMGR_DB_USER");
185  if (dbUser.length() > 0) {dbt->SetUser(dbUser);}
186  if (! dbt->GetConnection())
187  throw db_exception(tableDefinitionFileName,
188  "Could not connect to DB(detName="+detName+", user="+dbUser+")");
189  if (! dbt->ExistsInDB())
190  throw GTRunConfig::db_exception(tableDefinitionFileName,
191  "Table "+dbt->Name()+" doesn't exist in DB");
192 
193  dbt->Clear();
194  dbt->SetValidityRange(NamedConfigUtils::SUBSYSCFGID_COLUMN_NAME,
195  subsystemConfigId);
196  if (! dbt->LoadFromDB())
197  throw GTRunConfig::db_exception(tableDefinitionFileName,
198  "Could not load table "+dbt->Name()+" from DB");
199 
200  std::vector<std::string> colNames = dbt->GetColNames();
201  NOVADB::Row* rowPtr;
202  NOVADB::Column* colPtr;
203  std::cout<<"Table "<<dbt->Name()<<"( sscfg="<<subsystemConfigId<<") has "<<dbt->NRow()<<" rows"<<std::endl;
204  for (int rowIdx = 0; rowIdx < dbt->NRow(); ++rowIdx) {
205  boost::shared_ptr<SimpleParameterSet>
206  trigParamSet(new SimpleParameterSet());
207  rowPtr = dbt->GetRow(rowIdx);
208 
209  for (uint32_t colIdx = 0; colIdx < colNames.size(); ++colIdx) {
210  std::string colName = boost::to_lower_copy(colNames[colIdx]);
211  if (DBColumnUtils::isInfrastructureColumn(colName)) {continue;}
213  continue;
214  }
215 
216  std::string valueString;
217  colPtr = rowPtr->Col(colName);
218  if (! colPtr->Get(valueString))
219  throw GTRunConfig::db_exception(tableDefinitionFileName,
220  "Could not read column \""+colName+"\"");
221 
222 
223  trigParamSet->put(colName, valueString);
224  }
225 
226  triggerList.push_back(trigParamSet);
227  }
228 
229  return true;
230 }
231 
232 } // end of namespace daqconfig
233 } // end of namespace dbutils
boost::shared_ptr< SimpleParameterSet > _globalThrottle
Definition: GTRunConfig.h:112
static EnvVarCache & getInstance()
Definition: EnvVarCache.cpp:12
static const std::string GT_SUBSYSTEM_NAME
boost::shared_ptr< SimpleParameterSet > _DDTThrottle
Definition: GTRunConfig.h:113
boost::shared_ptr< SimpleParameterSet > _gtGeneral
Definition: GTRunConfig.h:117
boost::shared_ptr< SimpleParameterSet > _gtQueue
Definition: GTRunConfig.h:115
boost::shared_ptr< SimpleParameterSet > _NSNTriggerParams
Definition: GTRunConfig.h:111
bool _fetchParameterSet(const std::string &tableDefinitionFileName, const int64_t &subsystemConfigId, boost::shared_ptr< SimpleParameterSet > &parSet)
bool Get(T &val) const
Definition: Column.h:53
static bool isSubsystemConfigReferenceColumn(const std::string &columnName)
std::vector< boost::shared_ptr< SimpleParameterSet > > TriggerList
Definition: GTRunConfig.h:36
OStream cout
Definition: OStream.cxx:6
std::string getEnvVar(std::string name)
Definition: EnvVarCache.cpp:33
GTRunConfig(const std::vector< int64_t > &subsystemConfigIdList)
Definition: GTRunConfig.cpp:24
bool _fetchAllData(const std::vector< int64_t > &subsystemConfigIdList)
boost::shared_ptr< SimpleParameterSet > _triggerOffset
Definition: GTRunConfig.h:114
static bool isInfrastructureColumn(const std::string &columnName)
boost::shared_ptr< SimpleParameterSet > _SNEWSPipe
Definition: GTRunConfig.h:116
static const std::string SUBSYSCFGID_COLUMN_NAME
bool _fetchTriggerData(const std::string &tableDefinitionFileName, const int64_t &subsystemConfigId, TriggerList &triggerList)
detName
Definition: mkDefs.py:106
Column & Col(int i)
Definition: Row.h:51
enum BeamMode string