BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
Calibration/calibUtil/calibUtil-00-00-43/calibUtil/Metadata.h
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/calibUtil/calibUtil/Metadata.h,v 1.20 2012/01/05 03:53:49 zhangy Exp $
2#ifndef CALIBUTIL_METADATA_H
3#define CALIBUTIL_METADATA_H
4
5#include "facilities/Timestamp.h"
6#include "rdbModel/Db/Connection.h"
7#include "rdbModel/Tables/Assertion.h"
8//#include "DatabaseSvc/DatabaseRecord.h"
9#include "DatabaseSvc/IDatabaseSvc.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
197 eRet getReadMUCInfo(unsigned int serialNo,
198 int *runFrm,
199 int *runTo,
200 std::string& calParVer,
202 int runNo,
203 std::string& sftver);
204
205 eRet getReadEsTimeInfo(unsigned int serialNo,
206 int *runFrm,
207 int *runTo,
208 std::string& calParVer,
210 int runNo,
211 std::string& sftver);
212
213 eRet getReadEstTofInfo(unsigned int serialNo,
214 int *runFrm,
215 int *runTo,
216 std::string& calParVer,
218 int runNo,
219 std::string& sftver);
220 eRet getReadMdcAlignInfo(unsigned int serialNo,
221 int *runFrm,
222 int *runTo,
223 std::string& calParVer,
225 int runNo,
226 std::string& sftver);
227 eRet getReadMdcDataConstInfo(unsigned int serialNo,
228 int *runFrm,
229 int *runTo,
230 std::string& calParVer,
232 int runNo,
233 std::string& sftver);
234 eRet getReadTofQElecInfo(unsigned int serialNo,
235 int *runFrm,
236 int *runTo,
237 std::string& calParVer,
239 int runNo,
240 std::string& sftver);
241 eRet getReadTofSimInfo(unsigned int serialNo,
242 int *runFrm,
243 int *runTo,
244 std::string& calParVer,
246 int runNo,
247 std::string& sftver);
248 eRet getReadDedxSimInfo(unsigned int serialNo,
249 int *runFrm,
250 int *runTo,
251 std::string& calParVer,
253 int runNo,
254 std::string& sftver);
255
256
257
258 // Insert a new record; return serial number if successful
259 int registerCalib(const std::string& inst,
260 const std::string& flavor,
261 const std::string& calib_type,
262 const std::string& data_ident,
263 const std::string& data_format,
264 unsigned int& runfrm,
265 unsigned int& runto,
266 const std::string& input_desc,
267 const std::string& notes,
268 const std::string& proc_level,
269 const std::string& locale,
270 const std::string& fmt_version = "",
271 const std::string& completion = "OK");
272
273
274 bool connectRead(eRet& err);
275
276
277 bool checkValues(const rdbModel::StringVector& cols,
278 const rdbModel::StringVector& vals) const;
279
280 bool checkNulls(const rdbModel::StringVector& cols) const;
281
283
284 // Should probably be const
285 rdbModel::Rdb* getRdb() {return m_rdb;}
286 const std::string& getTable() {return m_table;}
287
288 // Might make these private
289 void disconnectRead();
290 void disconnectWrite();
291
292 private:
293
294 rdbModel::Connection* m_readCxt;
295 rdbModel::Connection* m_writeCxt;
296
297 // these could be static
298 rdbModel::Assertion* m_findBest;
299 rdbModel::Assertion* m_findSoonest;
300
301 // For each pre-existing row satisfying certain conditions,
302 // set its vend = vstart of new row
303 unsigned adjustVend(int newSer);
304
305
306 /*
307 Set val to string representation of "next" bit in levelMask
308 (one of "PROD", "DEV", "TEST" or "SUPSED"),
309 and mask off that bit in levelMask.
310 */
311 bool fetchLevel(std::string& val, unsigned int *levelMask);
312
313 // void initConditions(std::vector<rdbModel::Operator *> conditions);
314
315 // bool addLevel(std::string& q, unsigned int *levelMask);
316
317 /* Use rdbModel::MysqlConnection::open( .. ) to do most of the work */
318
319 // static bool connect(rdbModel::MysqlConnection* conn,
320 static bool connect(rdbModel::Connection* conn,
321 std::string& host,
322 const std::string& user,
323 const std::string& pw, eRet& err,
324 const std::string& dbName);
325
326 bool connectWrite(eRet& err);
327
328
329 eRet compareSchema(rdbModel::Connection* conn,
330 const std::string& schema);
331 // Find 'best' calibration, based on conditions and levelMask; store
332 // serial number.
333 //maqm fix
334 //eRet Metadata::doSelect(unsigned levelMask,
335 eRet doSelect(std::vector<rdbModel::Assertion::Operator *>&
336 conditions,
337 rdbModel::StringVector& orderBy,
338 unsigned*& ser);
339
340 /// Discover username and store in caller-supplied string
341 eRet fetchUser(std::string& user);
342
343 /// Compare schema described in xml file (schema argument) with
344 /// actual database. If schema="", derive file name from
345 /// database name.
346 // eRet compareSchema(const std::string& schema="");
347
348 // Won't need followin enum or bit mask if we eliminate multi-step
349 // insert procedure
350 /** Keep track of which columns in row have been initialized
351 with bit mask */
352 /*
353 enum eRow {
354 eOpened = 1,
355 eValid = 2,
356 eInputDesc = 4,
357 eComment = 8,
358 eFlavor = 0x10,
359 eLocale = 0x20,
360 eCreator = 0x40 };
361 */
362 /// Constant bit mask indicating all necessary fields have been set
363 // static const unsigned int s_rowReady;
364
365 // std::string m_row; // place to keep row as it's being built
366 // unsigned int m_rowStatus;
367 std::string m_host;
368 std::string m_table;
369 std::string m_dbName;
370 rdbModel::Manager* m_man;
371 rdbModel::Rdb* m_rdb;
372 IDatabaseSvc* m_dbsvc;
373 bool m_match; // true if succeeded. If not attempted, m_rdb is 0
374 };
375}
376
377#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:718
bool checkValues(const rdbModel::StringVector &cols, const rdbModel::StringVector &vals) const
Definition: Metadata.cxx:999
eRet getReadEsTimeInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:550
bool checkNulls(const rdbModel::StringVector &cols) const
Definition: Metadata.cxx:1016
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:376
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:652
eRet getReadMUCInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:408
eRet getReadEstTofInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:584
eRet getReadTofSimInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:617
eRet getReadDedxInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:516
eRet getReadMdcAlignInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:685
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:865
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:445
eRet getReadTofQElecInfo(unsigned int serialNo, int *runFrm, int *runTo, std::string &calParVer, DatabaseRecordVector &res, int runNo, std::string &sftver)
Definition: Metadata.cxx:750
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:482
Module implements methods for clients to get generic services.