#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[]) |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 52 of file calibCoverage.cxx.
References Coverage::checkType(), facilities::BadTimeInput::complaint, Coverage::expandTypes(), genRecEmupikp::i, meta, printHelp(), and deljobs::string.
00052 { 00053 00054 using calibUtil::Metadata; 00055 using facilities::Timestamp; 00056 00057 if (argc < 2) { 00058 printHelp(); 00059 exit(0); 00060 } 00061 00062 00063 // rdbModel::MysqlConnection* conn = new rdbModel::MysqlConnection(); 00064 // First do read connection to db, see if xml schema is compatible with db 00065 // Then use it to check other arguments 00066 std::string dbname = "calib"; // the default 00067 // Gives us whatever is in requirements for host and table 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 // Sort out instr, flavor, level, ts arguments. Update local 00097 // variables if values other than defaults supplied 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 // Check instrument, level against standard list; 00121 // put out warning (but don't exit) if not found 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 // If calibtype arg is a class, generate list 00141 00142 std::vector<std::string> calibTypes; 00143 00144 // Following fails only if arg was a calibration class (TKR, CAL or * 00145 // meaning "all" and we don't have a schema. 00146 // ..except for now we haven't implemented classes at all. 00147 std::string arg1(argv[1]); 00148 bool expanded = cov.expandTypes(arg1, calibTypes); 00149 if (!expanded) { 00150 exit(1); 00151 } 00152 // For each calibtype, do the work 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 }
void printHelp | ( | ) |
Definition at line 34 of file calibCoverage.cxx.
Referenced by main().
00034 { 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 }