CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
calibCoverage.cxx
Go to the documentation of this file.
1/**
2
3 @file calibCoverage
4
5 Determine whether, for a given calibration type (or set of calibration
6 types), instrument, flavor, proc_level there is precisely one
7 matching calibration in db. In all cases, supplying * for
8 an argument will give you the default value for it
9
10 Call with arguments
11
12 calibtype Specific type, e.g. "TKR_splits", or class. Allowable
13 classes are "CAL", "TKR", and "*" (all).
14 instrument Defaults to LAT
15 flavor Defaults to "vanilla"
16 level (i.e., proc_level) defaults to "PROD"
17 start Timestamp for beginning of time period to be covered.
18 Defaults to vstart for first calibration found
19 db Defaults to "calib" (production db)
20
21 For most of the work, see Coverage class
22
23*/
24
25#include "calibUtil/Metadata.h"
26#include "Coverage.h"
27#include <iostream>
28#include <cstdio>
29
30#include "string.h"
31
32
33
34void printHelp() {
35 std::cout << "Invoke as follows: " << std::endl;
36 std::cout << "calibCoverage calibtype instrument flavor level start db"
37 << std::endl;
38 std::cout << "All arguments but the first are optional. Defaults are: " << std::endl;
39 std::cout << "instrument = 'LAT'" << std::endl;
40 std::cout << "flavor = 'vanilla'" << std::endl;
41 std::cout << "level = 'PROD'" << std::endl;
42 std::cout << "start = '1970-1-1 00:00'" << std::endl;
43 std::cout << "db = 'calib'" << std::endl;
44}
45
46
47namespace rdbModel {
48 class Rdb;
49 class Connection;
50}
51
52int main(int argc, char* argv[]) {
53
56
57 if (argc < 2) {
58 printHelp();
59 exit(0);
60 }
61
62
63 // rdbModel::MysqlConnection* conn = new rdbModel::MysqlConnection();
64 // First do read connection to db, see if xml schema is compatible with db
65 // Then use it to check other arguments
66 std::string dbname = "calib"; // the default
67 // Gives us whatever is in requirements for host and table
68 std::string defValue = "*";
69
70 if (argc > 6) {
71 if ((argv[6]) != "*") dbname = std::string(argv[6]);
72 }
73 Metadata* meta = new Metadata(defValue, defValue, dbname);
74
75 if (!meta) {
76 std::cerr << "Unable to construct calibUtil::Metadata object "<< std::endl;
77 std::cerr.flush();
78 exit(1);
79 }
80 Metadata::eRet ret;
81 bool ok = meta->connectRead(ret);
82
83 if (!ok) {
84 std::cerr << "Connection to metadata dbs failed with return code "
85 << ret << std::endl;
86 std::cerr.flush();
87 exit(1);
88 }
89 rdbModel::Rdb* rdb = meta->getRdb();
90
91 std::string instr("LAT");
92 std::string flavor("vanilla");
93 std::string level("PROD");
94
95 Timestamp ts;
96 // Sort out instr, flavor, level, ts arguments. Update local
97 // variables if values other than defaults supplied
98 if (argc > 2) {
99 if (!strcmp(argv[2], "*")) instr = std::string(argv[2]);
100 if (argc > 3) {
101 if (!strcmp(argv[3], "*")) flavor = std::string(argv[3]);
102 if (argc > 4) {
103 if (!strcmp(argv[4], "*")) level = std::string(argv[4]);
104 }
105 }
106 }
107 if (argc > 5) {
108 try {
109 ts = Timestamp(std::string(argv[5]));
110 }
111 catch (facilities::BadTimeInput ex) {
112 std::cerr << "Caught facilities::BadTimeInput exception with complaint "
113 << ex.complaint << std::endl << "Exiting..." << std::endl;
114 std::cerr.flush();
115 exit(1);
116 }
117 }
118 else ts = Timestamp(0,0);
119
120 // Check instrument, level against standard list;
121 // put out warning (but don't exit) if not found
122 if (rdb) {
125 cols.reserve(2);
126 vals.reserve(2);
127
128 cols.push_back(std::string("instrument"));
129 vals.push_back(instr);
130 cols.push_back(std::string("proc_level"));
131 vals.push_back(level);
132 if (!(meta->checkValues(cols, vals))) {
133 std::cout << "Non-standard value for instrument or level. " << std::endl;
134 std::cout << "Supplied values were " << instr <<", " << level
135 << ", respectively." << std::endl;
136 }
137 }
138
139 Coverage cov(meta, instr, flavor, level, ts);
140 // If calibtype arg is a class, generate list
141
142 std::vector<std::string> calibTypes;
143
144 // Following fails only if arg was a calibration class (TKR, CAL or *
145 // meaning "all" and we don't have a schema.
146 // ..except for now we haven't implemented classes at all.
147 std::string arg1(argv[1]);
148 bool expanded = cov.expandTypes(arg1, calibTypes);
149 if (!expanded) {
150 exit(1);
151 }
152 // For each calibtype, do the work
153 for (unsigned i = 0; i < calibTypes.size(); i++) {
154 unsigned ret = cov.checkType(calibTypes[i]);
155 if (ret > 0) {
156 std::cerr << "Type " << calibTypes[i] << " failed with return code "
157 << ret << std::endl;
158 }
159 else {
160 std::cout << "Type " << calibTypes[i] << " ok in metadata database "
161 << std::endl;
162 }
163 }
164 return 0;
165}
void printHelp()
unsigned checkType(std::string calibtype)
Definition: Coverage.cxx:88
bool expandTypes(std::string &nickname, std::vector< std::string > &types)
Definition: Coverage.cxx:67
int main()
Definition: test_IFile.cxx:11