File indexing completed on 2024-04-06 12:23:14
0001 #include <iostream>
0002 #include <string>
0003 #include <vector>
0004 #include <time.h>
0005
0006 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
0007 #include "OnlineDB/EcalCondDB/interface/all_monitoring_types.h"
0008 #include "OnlineDB/EcalCondDB/interface/all_od_types.h"
0009
0010
0011 using namespace std;
0012
0013 class CondDBApp {
0014 public:
0015
0016
0017
0018
0019 CondDBApp(string host, string sid, string user, string pass)
0020 {
0021 try {
0022 cout << "Making connection..." << flush;
0023 econn = new EcalCondDBInterface( sid, user, pass );
0024 cout << "Done." << endl;
0025 } catch (runtime_error &e) {
0026 cerr << e.what() << endl;
0027 exit(-1);
0028 }
0029
0030 locations[0] = "H4";
0031 locations[1] = "867-1";
0032 locations[2] = "867-2";
0033 locations[3] = "867-3";
0034 }
0035
0036
0037
0038
0039
0040
0041 ~CondDBApp()
0042 {
0043 delete econn;
0044 }
0045
0046
0047 void printHVDataSet( const map<EcalLogicID, RunDCSHVDat>* dataset,
0048 int limit = 0 ) const
0049 {
0050 cout << "==========printDataSet()" << endl;
0051 if (dataset->size() == 0) {
0052 cout << "No data in map!" << endl;
0053 }
0054 EcalLogicID ecid;
0055 RunDCSHVDat hv;
0056
0057 int count = 0;
0058 typedef map< EcalLogicID, RunDCSHVDat >::const_iterator CI;
0059 for (CI p = dataset->begin(); p != dataset->end(); p++) {
0060 count++;
0061 if (limit && count > limit) { return; }
0062 ecid = p->first;
0063 hv = p->second;
0064
0065 cout << "SM: " << ecid.getID1() << endl;
0066 cout << "Xtal: " << ecid.getID2() << endl;
0067 cout << "HV: " << hv.getHV() << endl;
0068 cout << "HV nominal: " << hv.getHVNominal() << endl;
0069 cout << "HV status: " << hv.getStatus() << endl;
0070 cout << "========================" << endl;
0071 }
0072 cout << endl;
0073 }
0074
0075 void printLVDataSet( const map<EcalLogicID, RunDCSLVDat>* dataset,
0076 int limit = 0 ) const
0077 {
0078 cout << "==========printDataSet()" << endl;
0079 if (dataset->size() == 0) {
0080 cout << "No data in map!" << endl;
0081 }
0082 EcalLogicID ecid;
0083 RunDCSLVDat lv;
0084
0085 int count = 0;
0086 typedef map< EcalLogicID, RunDCSLVDat >::const_iterator CI;
0087 for (CI p = dataset->begin(); p != dataset->end(); p++) {
0088 count++;
0089 if (limit && count > limit) { return; }
0090 ecid = p->first;
0091 lv = p->second;
0092
0093 cout << "SM: " << ecid.getID1() << endl;
0094 cout << "Xtal: " << ecid.getID2() << endl;
0095 cout << "LV: " << lv.getLV() << endl;
0096 cout << "LV nominal: " << lv.getLVNominal() << endl;
0097 cout << "LV status: " << lv.getStatus() << endl;
0098 cout << "========================" << endl;
0099 }
0100 cout << endl;
0101 }
0102
0103
0104
0105
0106
0107
0108 void testRead()
0109 {
0110
0111
0112 cout << "Reading Table " << endl;
0113
0114 map<EcalLogicID, RunDCSHVDat> dataset;
0115 RunIOV *r = NULL;
0116 econn->fetchDataSet(&dataset, r);
0117
0118 if (!dataset.size()) {
0119 throw(runtime_error("Zero rows read back"));
0120 }
0121
0122
0123 cout << "read OK" << endl;
0124 printHVDataSet(&dataset);
0125
0126 map<EcalLogicID, RunDCSLVDat> dataset_lv;
0127 econn->fetchDataSet(&dataset_lv, r);
0128
0129 if (!dataset_lv.size()) {
0130 throw(runtime_error("Zero rows read back"));
0131 }
0132
0133
0134 cout << "read OK" << endl;
0135 printLVDataSet(&dataset_lv);
0136
0137
0138
0139 cout << "Done." << endl << endl << endl;
0140 };
0141
0142
0143
0144 private:
0145 CondDBApp();
0146 EcalCondDBInterface* econn;
0147 string locations[4];
0148 uint64_t startmicros;
0149 uint64_t endmicros;
0150 run_t startrun;
0151 run_t endrun;
0152
0153 int tablesTried;
0154 int tablesOK;
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164 void printTag( const RunTag* tag) const
0165 {
0166 cout << endl;
0167 cout << "=============RunTag:" << endl;
0168 cout << "GeneralTag: " << tag->getGeneralTag() << endl;
0169 cout << "Location: " << tag->getLocationDef().getLocation() << endl;
0170 cout << "Run Type: " << tag->getRunTypeDef().getRunType() << endl;
0171 cout << "====================" << endl;
0172 }
0173
0174 void printIOV( const RunIOV* iov) const
0175 {
0176 cout << endl;
0177 cout << "=============RunIOV:" << endl;
0178 RunTag tag = iov->getRunTag();
0179 printTag(&tag);
0180 cout << "Run Number: " << iov->getRunNumber() << endl;
0181 cout << "Run Start: " << iov->getRunStart().str() << endl;
0182 cout << "Run End: " << iov->getRunEnd().str() << endl;
0183 cout << "====================" << endl;
0184 }
0185 };
0186
0187
0188
0189 int main (int argc, char* argv[])
0190 {
0191 string host;
0192 string sid;
0193 string user;
0194 string pass;
0195 int run_num;
0196 string config_tag;
0197
0198 if (argc != 7) {
0199 cout << "Usage:" << endl;
0200 cout << " " << argv[0] << " <host> <SID> <user> <pass> <run_num> <config_tag>"
0201 << endl;
0202 exit(-1);
0203 }
0204
0205 host = argv[1];
0206 sid = argv[2];
0207 user = argv[3];
0208 pass = argv[4];
0209 run_num = atoi(argv[5]);
0210 config_tag = argv[6];
0211
0212 try {
0213 CondDBApp app(host, sid, user, pass);
0214
0215 app.testRead();
0216
0217 } catch (exception &e) {
0218 cout << "ERROR: " << e.what() << endl;
0219 } catch (...) {
0220 cout << "Unknown error caught" << endl;
0221 }
0222
0223 cout << "All Done." << endl;
0224
0225 return 0;
0226 }