BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
calibCoverage.cxx File Reference
#include "calibUtil/Metadata.h"
#include "Coverage.h"
#include <iostream>
#include <cstdio>
#include "string.h"

Go to the source code of this file.

Namespaces

namespace  rdbModel
 

Functions

void printHelp ()
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 52 of file calibCoverage.cxx.

52 {
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()
std::string complaint
Definition: Timestamp.h:17
const double meta
Definition: TConstant.h:8
std::vector< std::string > StringVector
Definition: Connection.h:52

◆ printHelp()

void printHelp ( )
@file calibCoverage

Determine whether, for a given calibration type (or set of calibration types), instrument, flavor, proc_level there is precisely one matching calibration in db. In all cases, supplying * for an argument will give you the default value for it

Call with arguments

calibtype    Specific type, e.g. "TKR_splits", or class.  Allowable
             classes are "CAL", "TKR", and "*"   (all). 
instrument   Defaults to LAT   
flavor       Defaults to "vanilla"
level        (i.e., proc_level) defaults to "PROD"
start        Timestamp for beginning of time period to be covered.
             Defaults to vstart for first calibration found
db           Defaults to "calib" (production db)

For most of the work, see Coverage class

Definition at line 34 of file calibCoverage.cxx.

34 {
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}

Referenced by main().