BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
Metadata.h
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/calibUtil/calibUtil/Metadata.h,v 1.22 2020/09/28 05:22:41 maqm Exp $
2#ifndef CALIBUTIL_METADATA_H
3#define CALIBUTIL_METADATA_H
4
8//#include "DatabaseSvc/DatabaseRecord.h"
10
11namespace rdbModel {
12 class Rdb;
13 class Manager;
14}
15
16namespace calibUtil {
17 /** Provide interface between calibration clients and the
18 MySQL database for calibration metadata. Supported operations
19 include writing a new record, looking for the serial number of
20 a "best match" record (findBest), and a method for retrieving
21 the information necessary to read the data set corresponding to
22 a particular metadata record (getReadInfo). Writing a record
23 is done in stages: open the record (openRecord), add certain
24 fields (addValidInterval, addNotes, etc.), and finally to write
25 the full record to the database (insertRecord).
26
27 The class contains definitions for several enumerated types,
28 corresponding to possible entries for columns in a metadata record.
29 Within the MySQL database the values are kept as strings. The
30 enumerated types are provided to insulate clients from these
31 details; enumerations are easier to document and to check for validity.
32 */
33 class Metadata {
34 public:
35 enum eRet {
36 RETOk = 0,
44 };
45 /// Used to form bit masks for dbs queries
46 enum eLevel {
51 };
52
53
54 /* Someday provide option of reading in description of table. In case
55 it is used, can check that it matches dbs we're connected to, and
56 can check column values.
57 */
58
59 /// Constructor keeps track of table of interest
60 Metadata(const std::string& host="bes3db2.ihep.ac.cn",
61 const std::string& table="*",
62 const std::string& dbName="calib");
63
64 ~Metadata();
65
66 /** Return serial number for calibration which is best match to
67 criteria, using strings for calibType and instrument arguments.
68 This method may be useful for development when a particular
69 instrument or calibration type is not officially supported.
70 @param ser serial number of best match
71 as integer or zero if no matches
72 (output)
73 @param calibType type of data, must match
74 @param timestamp must be within validity interval;
75 closer to center is better
76 @param levelMask acceptable levels ("production"
77 better than "dev" better than "test"
78 better than "superseded")
79 @param instrument e.g. LAT, EM, CU,...
80 @param flavor optionally specify non-standard
81 calibration flavor
82 @return status. Should be RETOk.
83
84
85 If there are multiple calibrations which are not distinguished
86 by the above, pick the one most recently written.
87 */
88/*maqm eRet findBest(unsigned int *ser,
89 const std::string& calibType,
90 const facilities::Timestamp& timestamp,
91 unsigned int levelMask,
92 const std::string& instrument,
93 const std::string& flavor="VANILLA");
94maqm*/
95 //maqm modify
96 eRet findBest(unsigned int *ser,
97 const std::string& calibType,
98 const std::string& sft_ver,
99 const std::string& cal_ver,
100 const std::string& cal_par,
101 const std::string& rec_alg,
102 const std::string& rec_par,
103 const std::string& machine,
104 const std::string& flavor="VANILLA");
105
106 /** Similar to findBest above, but here caller constrains the update_time
107 of the calibration by specifying an earliest and (optional) latest
108 time for it. The serial number of the calibration meeting all
109 other conditions, and with the earliest update_time, will be returned.
110 @param ser serial number of best match
111 as integer or zero if no matches
112 (output)
113 @param calibType type of data, must match
114 @param update_start ptr to time; early bound for update_time
115 @param update_end ptr to late bound for update_time (may be 0)
116 @param levelMask acceptable levels ("production"
117 better than "dev" better than "test"
118 better than "superseded")
119 @param instrument e.g. LAT, EM, CU,...
120 @param flavor optionally specify non-standard
121 calibration flavor
122 @return status. Should be RETOk.
123
124 */
125 eRet findSoonAfter(unsigned int *ser,
126 const std::string& calibType,
127 const std::string& sft_ver,
128 const std::string& cal_ver,
129 const std::string& cal_par,
130 const std::string& rec_alg,
131 const std::string& rec_par,
132 const std::string& machine,
133 const std::string& flavor="VANILLA");
134
135 // const std::string* const getCalibTypeStr(eCalibType cType);
136 // const std::string* const getDataFmtStr(eDataFmt fmt);
137 // const std::string* const getInstrumentStr(eInstrument inst);
138
139 /// Get validity interval for a particular calibration
140 eRet getInterval(unsigned int serialNo,
141 facilities::Timestamp*& since,
142 facilities::Timestamp*& till);
143
144 // Might also want a "findAll" which would just return a list
145 // of serial numbers, and a "getRecord" which would either
146 // just return the full row as a string or parse it into
147 // its separate columns
148
149 /** Given a calibration serial number, return information needed for
150 caller to read in the data.
151 @param serialNo [input]
152 @param dataFormat
153 @param fmtVersion
154 @param filename
155 @return true if serialNo exists in dbs and "filename" has
156 non-null value; else false.
157 */
158 eRet getReadInfo(unsigned int serialNo,
159 int *runFrm,
160 int *runTo,
161 std::string& dataFmt,
162 // std::string& fmtVersion,
163 std::string& dataIdent);
164
165 eRet getReadTOFInfo(unsigned int serialNo,
166 int *runFrm,
167 int *runTo,
168 std::string& calParVer,
170 int runNo,
171 std::string& sftver);
172
173 eRet getReadEMCInfo(unsigned int serialNo,
174 int *runFrm,
175 int *runTo,
176 std::string& calParVer,
178 int runNo,
179 std::string& sftver);
180
181 eRet getReadDedxInfo(unsigned int serialNo,
182 int *runFrm,
183 int *runTo,
184 std::string& calParVer,
186 int runNo,
187 std::string& sftver);
188
189 eRet getReadMDCInfo(unsigned int serialNo,
190 int *runFrm,
191 int *runTo,
192 std::string& calParVer,
194 int runNo,
195 std::string& sftver);
196 //Top_up Qiumei Ma
197 eRet getReadInjSigIntervalInfo(unsigned int serialNo,
198 int *runFrm,
199 int *runTo,
200 std::string& calParVer,
202 int runNo,
203 std::string& sftver);
204
205 eRet getReadInjSigTimeInfo(unsigned int serialNo,
206 int *runFrm,
207 int *runTo,
208 std::string& calParVer,
210 int runNo,
211 std::string& sftver);
212
213 eRet getReadOffEvtFilterInfo(unsigned int serialNo,
214 int *runFrm,
215 int *runTo,
216 std::string& calParVer,
218 int runNo,
219 std::string& sftver);
220
221 eRet getReadCorrectedETSInfo(unsigned int serialNo,
222 int runNo,
223 int FirstEvent,
224 std::string& Version,
226
227 eRet getReadMUCInfo(unsigned int serialNo,
228 int *runFrm,
229 int *runTo,
230 std::string& calParVer,
232 int runNo,
233 std::string& sftver);
234
235 eRet getReadEsTimeInfo(unsigned int serialNo,
236 int *runFrm,
237 int *runTo,
238 std::string& calParVer,
240 int runNo,
241 std::string& sftver);
242
243 eRet getReadEstTofInfo(unsigned int serialNo,
244 int *runFrm,
245 int *runTo,
246 std::string& calParVer,
248 int runNo,
249 std::string& sftver);
250 eRet getReadMdcAlignInfo(unsigned int serialNo,
251 int *runFrm,
252 int *runTo,
253 std::string& calParVer,
255 int runNo,
256 std::string& sftver);
257 eRet getReadMdcDataConstInfo(unsigned int serialNo,
258 int *runFrm,
259 int *runTo,
260 std::string& calParVer,
262 int runNo,
263 std::string& sftver);
264 eRet getReadTofQElecInfo(unsigned int serialNo,
265 int *runFrm,
266 int *runTo,
267 std::string& calParVer,
269 int runNo,
270 std::string& sftver);
271 eRet getReadTofSimInfo(unsigned int serialNo,
272 int *runFrm,
273 int *runTo,
274 std::string& calParVer,
276 int runNo,
277 std::string& sftver);
278 eRet getReadDedxSimInfo(unsigned int serialNo,
279 int *runFrm,
280 int *runTo,
281 std::string& calParVer,
283 int runNo,
284 std::string& sftver);
285
286
287
288 // Insert a new record; return serial number if successful
289 int registerCalib(const std::string& inst,
290 const std::string& flavor,
291 const std::string& calib_type,
292 const std::string& data_ident,
293 const std::string& data_format,
294 unsigned int& runfrm,
295 unsigned int& runto,
296 const std::string& input_desc,
297 const std::string& notes,
298 const std::string& proc_level,
299 const std::string& locale,
300 const std::string& fmt_version = "",
301 const std::string& completion = "OK");
302
303
304 bool connectRead(eRet& err);
305
306
307 bool checkValues(const rdbModel::StringVector& cols,
308 const rdbModel::StringVector& vals) const;
309
310 bool checkNulls(const rdbModel::StringVector& cols) const;
311
313
314 // Should probably be const
315 rdbModel::Rdb* getRdb() {return m_rdb;}
316 const std::string& getTable() {return m_table;}
317
318 // Might make these private
319 void disconnectRead();
320 void disconnectWrite();
321
322 private:
323
324 rdbModel::Connection* m_readCxt;
325 rdbModel::Connection* m_writeCxt;
326
327 // these could be static
328 rdbModel::Assertion* m_findBest;
329 rdbModel::Assertion* m_findSoonest;
330
331 // For each pre-existing row satisfying certain conditions,
332 // set its vend = vstart of new row
333 unsigned adjustVend(int newSer);
334
335
336 /*
337 Set val to string representation of "next" bit in levelMask
338 (one of "PROD", "DEV", "TEST" or "SUPSED"),
339 and mask off that bit in levelMask.
340 */
341 bool fetchLevel(std::string& val, unsigned int *levelMask);
342
343 // void initConditions(std::vector<rdbModel::Operator *> conditions);
344
345 // bool addLevel(std::string& q, unsigned int *levelMask);
346
347 /* Use rdbModel::MysqlConnection::open( .. ) to do most of the work */
348
349 // static bool connect(rdbModel::MysqlConnection* conn,
350 static bool connect(rdbModel::Connection* conn,
351 std::string& host,
352 const std::string& user,
353 const std::string& pw, eRet& err,
354 const std::string& dbName);
355
356 bool connectWrite(eRet& err);
357
358
359 eRet compareSchema(rdbModel::Connection* conn,
360 const std::string& schema);
361 // Find 'best' calibration, based on conditions and levelMask; store
362 // serial number.
363 //maqm fix
364 //eRet Metadata::doSelect(unsigned levelMask,
365 eRet doSelect(std::vector<rdbModel::Assertion::Operator *>&
366 conditions,
367 rdbModel::StringVector& orderBy,
368 unsigned*& ser);
369
370 /// Discover username and store in caller-supplied string
371 eRet fetchUser(std::string& user);
372
373 /// Compare schema described in xml file (schema argument) with
374 /// actual database. If schema="", derive file name from
375 /// database name.
376 // eRet compareSchema(const std::string& schema="");
377
378 // Won't need followin enum or bit mask if we eliminate multi-step
379 // insert procedure
380 /** Keep track of which columns in row have been initialized
381 with bit mask */
382 /*
383 enum eRow {
384 eOpened = 1,
385 eValid = 2,
386 eInputDesc = 4,
387 eComment = 8,
388 eFlavor = 0x10,
389 eLocale = 0x20,
390 eCreator = 0x40 };
391 */
392 /// Constant bit mask indicating all necessary fields have been set
393 // static const unsigned int s_rowReady;
394
395 // std::string m_row; // place to keep row as it's being built
396 // unsigned int m_rowStatus;
397 std::string m_host;
398 std::string m_table;
399 std::string m_dbName;
400 rdbModel::Manager* m_man;
401 rdbModel::Rdb* m_rdb;
402 IDatabaseSvc* m_dbsvc;
403 bool m_match; // true if succeeded. If not attempted, m_rdb is 0
404 };
405}
406
407#endif
int runNo
Definition: DQA_TO_DB.cxx:12
eRet getReadMdcDataConstInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:892
bool checkValues(const rdbModel::StringVector &cols, const rdbModel::StringVector &vals) const
Definition: Metadata.cxx:1183
eRet getReadEsTimeInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:702
bool checkNulls(const rdbModel::StringVector &cols) const
Definition: Metadata.cxx:1200
const std::string & getTable()
Definition: Metadata.h:316
eRet getReadInjSigTimeInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:412
eRet findBest(unsigned int *ser, const std::string &calibType, const std::string &sft_ver, const std::string &cal_ver, const std::string &cal_par, const std::string &rec_alg, const std::string &rec_par, const std::string &machine, const std::string &flavor="VANILLA")
Definition: Metadata.cxx:243
eRet getReadTOFInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:507
eRet getReadInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &dataFmt, std::string &dataIdent)
Definition: Metadata.cxx:314
bool connectRead(eRet &err)
Definition: Metadata.cxx:107
eRet getReadDedxSimInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:817
eRet getReadMUCInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:543
eRet getReadEstTofInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:740
eRet getReadTofSimInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:778
rdbModel::Connection * getReadConnection()
Definition: Metadata.h:312
eRet getReadOffEvtFilterInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:447
eLevel
Used to form bit masks for dbs queries.
Definition: Metadata.h:46
eRet getReadDedxInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:663
rdbModel::Rdb * getRdb()
Definition: Metadata.h:315
eRet getReadInjSigIntervalInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:377
eRet getReadCorrectedETSInfo(unsigned int serialNo, int runNo, int FirstEvent, std::string &Version, DatabaseRecordVector &res)
Definition: Metadata.cxx:483
eRet getReadMdcAlignInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:855
int registerCalib(const std::string &inst, const std::string &flavor, const std::string &calib_type, const std::string &data_ident, const std::string &data_format, unsigned int &runfrm, unsigned int &runto, const std::string &input_desc, const std::string &notes, const std::string &proc_level, const std::string &locale, const std::string &fmt_version="", const std::string &completion="OK")
Definition: Metadata.cxx:1049
eRet getInterval(unsigned int serialNo, facilities::Timestamp *&since, facilities::Timestamp *&till)
Get validity interval for a particular calibration.
eRet getReadMDCInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:583
eRet getReadTofQElecInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:928
eRet findSoonAfter(unsigned int *ser, const std::string &calibType, const std::string &sft_ver, const std::string &cal_ver, const std::string &cal_par, const std::string &rec_alg, const std::string &rec_par, const std::string &machine, const std::string &flavor="VANILLA")
Definition: Metadata.cxx:172
eRet getReadEMCInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:624
Module implements methods for clients to get generic services.
std::vector< std::string > StringVector
Definition: Connection.h:52