File indexing completed on 2023-03-17 11:15:30
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 RunIOV makeRunIOV(int run_num)
0048 {
0049
0050 LocationDef locdef;
0051 RunTypeDef rundef;
0052 RunTag runtag;
0053
0054 locdef.setLocation("P5_Co");
0055
0056 rundef.setRunType("COSMIC");
0057 runtag.setLocationDef(locdef);
0058 runtag.setRunTypeDef(rundef);
0059 runtag.setGeneralTag("GLOBAL");
0060
0061
0062
0063
0064 Tm startTm;
0065 startTm.setToCurrentGMTime();
0066 uint64_t microseconds = startTm.microsTime();
0067 startTm.setToMicrosTime(microseconds);
0068
0069
0070
0071
0072
0073
0074 cout << "Run Time: " << startTm.str() << endl;
0075 cout << "Run Number: " << run_num << endl;
0076
0077
0078 RunIOV runiov;
0079
0080 runiov.setRunNumber(run_num);
0081 runiov.setRunStart(startTm);
0082 runiov.setRunTag(runtag);
0083
0084 return runiov;
0085 }
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 void testWrite(int run_num, string config_tag)
0096 {
0097 cout << "Writing to database..." << endl;
0098 RunIOV runiov = this->makeRunIOV(run_num);
0099 RunTag runtag = runiov.getRunTag();
0100 run_t run = runiov.getRunNumber();
0101
0102
0103 cout << "Inserting run..." << flush;
0104 econn->insertRunIOV(&runiov);
0105 cout << "Done." << endl;
0106 printIOV(&runiov);
0107
0108 int c = 1;
0109 EcalLogicID ecid;
0110 ecid = econn->getEcalLogicID("ECAL");
0111
0112
0113
0114 FEConfigMainInfo cfg_info;
0115 cfg_info.setConfigTag(config_tag);
0116 econn->fetchConfigSet(&cfg_info);
0117
0118
0119 int iversion= cfg_info.getVersion();
0120
0121
0122
0123 RunTPGConfigDat cfgdat;
0124 map<EcalLogicID, RunTPGConfigDat> dataset;
0125
0126 cfgdat.setConfigTag(config_tag);
0127 cfgdat.setVersion(iversion);
0128
0129
0130 dataset[ecid] = cfgdat;
0131
0132
0133 cout << "Inserting dataset..." << flush;
0134 econn->insertDataSet(&dataset, &runiov);
0135 cout << "Done." << endl;
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.testWrite(run_num, config_tag);
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 }