00001
00025 #include "calibUtil/Metadata.h"
00026 #include "Coverage.h"
00027 #include <iostream>
00028 #include <cstdio>
00029
00030 #include "string.h"
00031
00032
00033
00034 void printHelp() {
00035 std::cout << "Invoke as follows: " << std::endl;
00036 std::cout << "calibCoverage calibtype instrument flavor level start db"
00037 << std::endl;
00038 std::cout << "All arguments but the first are optional. Defaults are: " << std::endl;
00039 std::cout << "instrument = 'LAT'" << std::endl;
00040 std::cout << "flavor = 'vanilla'" << std::endl;
00041 std::cout << "level = 'PROD'" << std::endl;
00042 std::cout << "start = '1970-1-1 00:00'" << std::endl;
00043 std::cout << "db = 'calib'" << std::endl;
00044 }
00045
00046
00047 namespace rdbModel {
00048 class Rdb;
00049 class Connection;
00050 }
00051
00052 int main(int argc, char* argv[]) {
00053
00054 using calibUtil::Metadata;
00055 using facilities::Timestamp;
00056
00057 if (argc < 2) {
00058 printHelp();
00059 exit(0);
00060 }
00061
00062
00063
00064
00065
00066 std::string dbname = "calib";
00067
00068 std::string defValue = "*";
00069
00070 if (argc > 6) {
00071 if ((argv[6]) != "*") dbname = std::string(argv[6]);
00072 }
00073 Metadata* meta = new Metadata(defValue, defValue, dbname);
00074
00075 if (!meta) {
00076 std::cerr << "Unable to construct calibUtil::Metadata object "<< std::endl;
00077 std::cerr.flush();
00078 exit(1);
00079 }
00080 Metadata::eRet ret;
00081 bool ok = meta->connectRead(ret);
00082
00083 if (!ok) {
00084 std::cerr << "Connection to metadata dbs failed with return code "
00085 << ret << std::endl;
00086 std::cerr.flush();
00087 exit(1);
00088 }
00089 rdbModel::Rdb* rdb = meta->getRdb();
00090
00091 std::string instr("LAT");
00092 std::string flavor("vanilla");
00093 std::string level("PROD");
00094
00095 Timestamp ts;
00096
00097
00098 if (argc > 2) {
00099 if (!strcmp(argv[2], "*")) instr = std::string(argv[2]);
00100 if (argc > 3) {
00101 if (!strcmp(argv[3], "*")) flavor = std::string(argv[3]);
00102 if (argc > 4) {
00103 if (!strcmp(argv[4], "*")) level = std::string(argv[4]);
00104 }
00105 }
00106 }
00107 if (argc > 5) {
00108 try {
00109 ts = Timestamp(std::string(argv[5]));
00110 }
00111 catch (facilities::BadTimeInput ex) {
00112 std::cerr << "Caught facilities::BadTimeInput exception with complaint "
00113 << ex.complaint << std::endl << "Exiting..." << std::endl;
00114 std::cerr.flush();
00115 exit(1);
00116 }
00117 }
00118 else ts = Timestamp(0,0);
00119
00120
00121
00122 if (rdb) {
00123 rdbModel::StringVector cols;
00124 rdbModel::StringVector vals;
00125 cols.reserve(2);
00126 vals.reserve(2);
00127
00128 cols.push_back(std::string("instrument"));
00129 vals.push_back(instr);
00130 cols.push_back(std::string("proc_level"));
00131 vals.push_back(level);
00132 if (!(meta->checkValues(cols, vals))) {
00133 std::cout << "Non-standard value for instrument or level. " << std::endl;
00134 std::cout << "Supplied values were " << instr <<", " << level
00135 << ", respectively." << std::endl;
00136 }
00137 }
00138
00139 Coverage cov(meta, instr, flavor, level, ts);
00140
00141
00142 std::vector<std::string> calibTypes;
00143
00144
00145
00146
00147 std::string arg1(argv[1]);
00148 bool expanded = cov.expandTypes(arg1, calibTypes);
00149 if (!expanded) {
00150 exit(1);
00151 }
00152
00153 for (unsigned i = 0; i < calibTypes.size(); i++) {
00154 unsigned ret = cov.checkType(calibTypes[i]);
00155 if (ret > 0) {
00156 std::cerr << "Type " << calibTypes[i] << " failed with return code "
00157 << ret << std::endl;
00158 }
00159 else {
00160 std::cout << "Type " << calibTypes[i] << " ok in metadata database "
00161 << std::endl;
00162 }
00163 }
00164 return 0;
00165 }