NamedConfigUtils.h
Go to the documentation of this file.
1 #ifndef _DBUTILS_DAQCONFIG_NAMEDCONFIGUTILS_H
2 #define _DBUTILS_DAQCONFIG_NAMEDCONFIGUTILS_H
3 
4 #include <DatabaseUtils/DAQConfig/IDSpec.h>
5 #include <DatabaseUtils/DAQConfig/GlobalNameSpec.h>
6 #include <DatabaseUtils/DAQConfig/SubsystemNameSpec.h>
7 #include <DatabaseUtils/SimpleParameterSet.h>
8 #include <NovaDatabase/Table.h>
9 #include <NovaDAQUtilities/Status.h>
10 
11 #include <boost/shared_ptr.hpp>
12 #include <string>
13 #include <vector>
14 
15 namespace dbutils {
16 namespace daqconfig {
17 
18 /**
19  * Utilities for accessing DAQ named configurations in the database.
20  *
21  * @author Kurt Biery
22  * @version $Revision: 1.31.14.1 $ $Date: 2019/09/27 00:07:03 $
23  */
24 
26 
27  public:
28 
33 
37  static const std::string DETECTORID_COLUMN_NAME; // deprecated
53 
57 
59 
60  static const int32_t COPY_SUCCEEDED;
61  static const int32_t COPY_FAILED;
62  static const int32_t COPY_FOUND_UPDATE_IN_PROGRESS;
63  static const int32_t COPY_FOUND_INTERMEDIATE_UPDATE;
64 
65 
66  typedef std::map<std::string, std::string> NamedConfigDetails;
67  typedef boost::shared_ptr<NamedConfigDetails> NamedConfigDetailsPtr;
68 
69  typedef std::map<std::string, std::string> NamedConfigSelectionCriteria;
70 
71  typedef boost::shared_ptr<GlobalNameSpec> GlobalNameSpecPtr;
72  typedef std::vector<GlobalNameSpec> GlobalNameSpecList;
73  typedef std::map<GlobalNameSpec, std::vector<GlobalNameSpec> >
75  typedef std::map<SubsystemNameSpec, std::vector<SubsystemNameSpec> >
77 
78 
79  static bool
80  getGlobalConfigId(const GlobalNameSpec& globalNameSpec,
81  int64_t& globalConfigId,
82  const std::string& globalNamesTableFile =
83  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
84 
85  static bool
86  getSubsystemConfigId(const SubsystemNameSpec& subsystemNameSpec,
87  int64_t& subsystemConfigId,
88  const std::string& subsystemNamesTableFile =
89  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE);
90 
91  static bool getConfigIdAncestry(const IDSpec& idSpec,
92  std::vector<int64_t>& idList,
93  const std::string& tableFile =
94  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
95 
96  static bool
97  getGlobalConfigIdAncestry(const GlobalNameSpec& globalNameSpec,
98  std::vector<int64_t>& idList,
99  const std::string& globalNamesTableFile =
100  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
101 
102  static bool
104  subsystemNameSpec,
105  std::vector<int64_t>& idList,
106  const std::string&
107  subsystemNamesTableFile =
108  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE);
109 
110  static bool
112  globalNameSpec,
113  const std::string& subsystemName,
114  const std::string& subsystemConfigType,
115  int64_t& subsystemConfigId,
116  const std::string&
117  globalNamesTableFile =
118  DEFAULT_GLOBAL_NAMES_TABLE_FILE,
119  const std::string&
120  subsystemNamesTableFile =
121  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE);
122 
123  static bool
125  const std::string& subsystemName,
126  const std::string& subsystemConfigType,
127  int64_t& subsystemConfigId,
128  const std::string&
129  globalNamesTableFile =
130  DEFAULT_GLOBAL_NAMES_TABLE_FILE,
131  const std::string&
132  subsystemNamesTableFile =
133  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE);
134 
135  static bool
136  getSubsystemConfigIdAncestryFromGlobalId(const IDSpec& globalConfigId,
137  const std::string& subsystemName,
138  const std::string& subsystemConfigType,
139  std::vector<int64_t>& idList,
140  const std::string&
141  globalNamesTableFile =
142  DEFAULT_GLOBAL_NAMES_TABLE_FILE,
143  const std::string&
144  subsystemNamesTableFile =
145  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE);
146 
147  static bool
149  std::vector<int64_t>& idList,
150  std::vector<SubsystemNameSpec>&
151  subsystemNameSpecList,
152  const std::string&
153  globalNamesTableFile =
154  DEFAULT_GLOBAL_NAMES_TABLE_FILE,
155  const std::string&
156  subsystemNamesTableFile =
157  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE);
158 
159  static std::vector<NamedConfigDetailsPtr>
161  const std::string&
162  globalNamesTableFile =
163  DEFAULT_GLOBAL_NAMES_TABLE_FILE,
164  const std::string&
165  subsystemNamesTableFile =
166  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE);
167 
168  static NamedConfigDetailsPtr
170  subsystemNameSpec,
171  const std::string&
172  subsystemNamesTableFile =
173  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE,
174  const std::string&
175  globalNamesTableFile =
176  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
177 
178  static NamedConfigDetailsPtr
180  const std::string&
181  subsystemNamesTableFile =
182  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE,
183  const std::string&
184  globalNamesTableFile =
185  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
186 
187  static NamedConfigDetailsPtr
189  const std::string&
190  globalNamesTableFile =
191  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
192 
193  static GlobalNameSpecPtr
195  const int& partitionNumber,
196  const std::string& globalNamesTableFile =
197  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
198 
199  static bool
201  const std::string& detectorName,
202  int resultOffset, int resultLimit,
203  GlobalNameSpecList& resultList,
204  const std::string& globalNamesTableFile =
205  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
206 
207  static bool
209  const std::string& detectorName,
210  GlobalNameSpecMap& resultsTable,
211  int maxDetailCountPerSummary = 10,
212  const std::string& globalNamesTableFile =
213  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
214 
215  static bool
217  const std::string& detectorName,
218  const std::string& subsystemName,
219  const std::string& configType,
220  SubsystemNameSpecMap& resultsTable,
221  int maxDetailCountPerSummary = 10,
222  const std::string&
223  subsystemNamesTableFile =
224  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE);
225 
226  static novadaq::Status
227  copyGlobalConfig(const IDSpec& sourceId, bool makeParentChildLink,
228  const SimpleParameterSet& valuesToOverride,
229  std::string baselineTimestamp,
230  bool overrideIntermediateUpdate,
231  int64_t& resultId,
232  const std::string& globalNamesTableFile =
233  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
234 
235  static novadaq::Status
236  copySubsystemConfig(const IDSpec& sourceId, bool makeParentChildLink,
237  const SimpleParameterSet& valuesToOverride,
238  std::string baselineTimestamp,
239  bool overrideIntermediateUpdate,
240  int64_t& resultId,
241  const std::string& subsystemNamesTableFile =
242  DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE);
243 
244  static bool markConfigDone(const IDSpec& idSpec,
245  bool alsoComplete = false,
246  const std::string& tableFile =
247  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
248 
249  static bool incrementUsageCount(const IDSpec& idSpec,
250  const std::string& tableFile =
251  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
252 
253  static std::vector<NamedConfigDetailsPtr>
255  globalNameSpec,
256  const std::string&
257  globalNamesTableFile =
258  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
259 
260  static std::vector<NamedConfigDetailsPtr>
261  getConfigDetailAncestry(const IDSpec& idSpec,
262  const std::string& tableFile =
263  DEFAULT_GLOBAL_NAMES_TABLE_FILE);
264 
265  static bool
266  getFieldValue(const NamedConfigDetailsPtr& details,
267  const std::string& fieldName,
268  std::string& fieldValue);
269 
270  private:
271 
272  static NamedConfigDetailsPtr
273  _getDetails(const boost::shared_ptr<nova::database::Table>& dbt,
274  const NamedConfigSelectionCriteria& selections);
275 
276  static bool
277  _getId(const boost::shared_ptr<nova::database::Table>& dbt,
278  const NamedConfigSelectionCriteria& selections,
279  int64_t& id);
280 
281  static bool
282  _findNextAncestor(const boost::shared_ptr<nova::database::Table>& dbt,
283  std::vector<int64_t>& idList);
284 
285  static bool
286  _findNextChild(const boost::shared_ptr<nova::database::Table>& dbt,
287  std::vector<int64_t>& idList);
288 };
289 
290 } // end of namespace daqconfig
291 } // end of namespace dbutils
292 
293 #endif
static bool getSubsystemConfigId(const SubsystemNameSpec &subsystemNameSpec, int64_t &subsystemConfigId, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE)
static const std::string GLOBALCFGID_COLUMN_NAME
static const std::string USAGECOUNT_COLUMN_NAME
std::vector< GlobalNameSpec > GlobalNameSpecList
static const std::string ISCHANGING_COLUMN_NAME
static const std::string DESCRIPTION_COLUMN_NAME
static bool getGlobalConfigId(const GlobalNameSpec &globalNameSpec, int64_t &globalConfigId, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static const std::string DEFAULT_GLOBAL_NAMES_TABLE_FILE
boost::shared_ptr< NamedConfigDetails > NamedConfigDetailsPtr
static const std::string DEFAULT_DCS_GLOBAL_NAMES_TABLE_FILE
static bool getAvailableSubsystemConfigs(IDSpec::MAJOR_SYSTEM_TYPE daqOrSlowControls, const std::string &detectorName, const std::string &subsystemName, const std::string &configType, SubsystemNameSpecMap &resultsTable, int maxDetailCountPerSummary=10, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE)
static bool getConfigIdAncestry(const IDSpec &idSpec, std::vector< int64_t > &idList, const std::string &tableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static GlobalNameSpecPtr getNewestInstanceOfLatestUsedDAQGlobalConfig(const std::string &detectorName, const int &partitionNumber, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static bool getSubsystemConfigIdsFromGlobalId(const IDSpec &idSpec, std::vector< int64_t > &idList, std::vector< SubsystemNameSpec > &subsystemNameSpecList, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE)
static bool getAvailableGlobalConfigs(IDSpec::MAJOR_SYSTEM_TYPE daqOrSlowControls, const std::string &detectorName, GlobalNameSpecMap &resultsTable, int maxDetailCountPerSummary=10, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static const std::string INSERTTIME_COLUMN_NAME
static const int32_t COPY_FOUND_INTERMEDIATE_UPDATE
static const std::string DETECTORID_COLUMN_NAME
static bool _findNextChild(const boost::shared_ptr< nova::database::Table > &dbt, std::vector< int64_t > &idList)
std::map< SubsystemNameSpec, std::vector< SubsystemNameSpec > > SubsystemNameSpecMap
static const std::string ISCOMPLETE_COLUMN_NAME
std::map< std::string, std::string > NamedConfigSelectionCriteria
static NamedConfigDetailsPtr _getDetails(const boost::shared_ptr< nova::database::Table > &dbt, const NamedConfigSelectionCriteria &selections)
std::map< GlobalNameSpec, std::vector< GlobalNameSpec > > GlobalNameSpecMap
static bool getSubsystemConfigIdAncestry(const SubsystemNameSpec &subsystemNameSpec, std::vector< int64_t > &idList, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE)
static NamedConfigDetailsPtr getNewestGlobalConfigFromSubsystemName(const SubsystemNameSpec &subsystemNameSpec, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static const std::string DCMOPMODE_COLUMN_NAME
static const std::string CONFIGTYPE_COLUMN_NAME
static bool incrementUsageCount(const IDSpec &idSpec, const std::string &tableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static std::vector< NamedConfigDetailsPtr > getSubsystemConfigsFromGlobalId(const IDSpec &idSpec, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE)
static novadaq::Status copyGlobalConfig(const IDSpec &sourceId, bool makeParentChildLink, const SimpleParameterSet &valuesToOverride, std::string baselineTimestamp, bool overrideIntermediateUpdate, int64_t &resultId, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static const std::string UPDATEUSER_COLUMN_NAME
boost::shared_ptr< GlobalNameSpec > GlobalNameSpecPtr
static const std::string DETECTORNAME_COLUMN_NAME
static const std::string UPDATETIME_COLUMN_NAME
static const std::string ID_COLUMN_NAME
static const std::string SUBSYSTEMNAME_COLUMN_NAME
static std::vector< NamedConfigDetailsPtr > getConfigDetailAncestry(const IDSpec &idSpec, const std::string &tableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static novadaq::Status copySubsystemConfig(const IDSpec &sourceId, bool makeParentChildLink, const SimpleParameterSet &valuesToOverride, std::string baselineTimestamp, bool overrideIntermediateUpdate, int64_t &resultId, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE)
static bool _getId(const boost::shared_ptr< nova::database::Table > &dbt, const NamedConfigSelectionCriteria &selections, int64_t &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 NamedConfigDetailsPtr getNewestGlobalConfigFromSubsystemId(const IDSpec &idSpec, const std::string &subsystemNamesTableFile=DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static const std::string NDOS_DETECTOR_NAME
static const std::string DEFAULT_DCS_SUBSYSTEM_NAMES_TABLE_FILE
static NamedConfigDetailsPtr getNewestGlobalConfigFromGlobalId(const IDSpec &idSpec, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static const std::string FAR_DETECTOR_NAME
std::map< std::string, std::string > NamedConfigDetails
static bool _findNextAncestor(const boost::shared_ptr< nova::database::Table > &dbt, std::vector< int64_t > &idList)
static const int32_t COPY_FOUND_UPDATE_IN_PROGRESS
static const std::string PARENTID_COLUMN_NAME
static bool markConfigDone(const IDSpec &idSpec, bool alsoComplete=false, const std::string &tableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static const std::string ISOBSOLETE_COLUMN_NAME
static bool getRecentGlobalConfigs(IDSpec::MAJOR_SYSTEM_TYPE daqOrSlowControls, const std::string &detectorName, int resultOffset, int resultLimit, GlobalNameSpecList &resultList, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static const std::string DEFAULT_SUBSYSTEM_NAMES_TABLE_FILE
static bool getSubsystemConfigIdFromGlobalId(const IDSpec &idSpec, 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 bool getFieldValue(const NamedConfigDetailsPtr &details, const std::string &fieldName, std::string &fieldValue)
static const std::string LATEST_TIME_STRING
static const std::string NAME_COLUMN_NAME
static bool getGlobalConfigIdAncestry(const GlobalNameSpec &globalNameSpec, std::vector< int64_t > &idList, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)
static const std::string INSERTUSER_COLUMN_NAME
static const std::string SUBSYSCFGID_COLUMN_NAME
static const std::string NEAR_DETECTOR_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)
enum BeamMode string
static std::vector< NamedConfigDetailsPtr > getGlobalConfigDetailAncestry(const GlobalNameSpec &globalNameSpec, const std::string &globalNamesTableFile=DEFAULT_GLOBAL_NAMES_TABLE_FILE)