File indexing completed on 2024-04-06 12:23:15
0001 #include <iostream>
0002 #include <string>
0003 #include <sstream>
0004 #include <vector>
0005 #include <time.h>
0006 #include <cstdlib>
0007
0008 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
0009 #include "OnlineDB/EcalCondDB/interface/all_monitoring_types.h"
0010 #include "OnlineDB/EcalCondDB/interface/all_fe_config_types.h"
0011 #include "OnlineDB/EcalCondDB/interface/RunDat.h"
0012 #include "OnlineDB/EcalCondDB/interface/RunList.h"
0013 #include "OnlineDB/EcalCondDB/interface/MonPedestalsDat.h"
0014 #include "TROOT.h"
0015 #include "TFile.h"
0016 #include "TDirectory.h"
0017 #include "TH2F.h"
0018 #include "TF1.h"
0019
0020 using namespace std;
0021
0022 class CondDBApp {
0023 public:
0024
0025
0026
0027 CondDBApp(string host, string sid, string user, string pass, int port) {
0028 try {
0029 cout << "Making connection...to " << port << flush;
0030 econn = new EcalCondDBInterface(host, sid, user, pass, port);
0031 cout << "Done." << endl;
0032 } catch (runtime_error& e) {
0033 cerr << e.what() << endl;
0034 exit(-1);
0035 }
0036 }
0037 CondDBApp(string sid, string user, string pass) {
0038 try {
0039 cout << "Making connection...to " << sid << endl;
0040 econn = new EcalCondDBInterface(sid, user, pass);
0041 cout << "Done." << endl;
0042 } catch (runtime_error& e) {
0043 cerr << e.what() << endl;
0044 exit(-1);
0045 }
0046 }
0047
0048
0049
0050
0051 ~CondDBApp() { delete econn; }
0052
0053 inline std::string to_string(char value[]) {
0054 std::ostringstream streamOut;
0055 streamOut << value;
0056 return streamOut.str();
0057 }
0058
0059 void testReadOddWeights(int iconf_req) {
0060
0061
0062
0063
0064 cout << "*****************************************" << endl;
0065 cout << "test reading odd weights with id=" << iconf_req << endl;
0066 cout << "*****************************************" << endl;
0067
0068 FEConfigOddWeightInfo fe_wei_info;
0069 fe_wei_info.setId(iconf_req);
0070 econn->fetchConfigSet(&fe_wei_info);
0071
0072 map<EcalLogicID, FEConfigOddWeightDat> dataset_wei;
0073 econn->fetchDataSet(&dataset_wei, &fe_wei_info);
0074
0075 typedef map<EcalLogicID, FEConfigOddWeightDat>::const_iterator CIfewei;
0076 EcalLogicID ecid_xt;
0077 FEConfigOddWeightDat rd_wei;
0078
0079 int rd_weiv[15176];
0080 for (int i = 0; i < 15176; i++) {
0081 rd_weiv[i] = 0;
0082 }
0083 int i = 0;
0084 for (CIfewei p = dataset_wei.begin(); p != dataset_wei.end(); p++) {
0085 ecid_xt = p->first;
0086 rd_wei = p->second;
0087 int sm_num = ecid_xt.getID1();
0088 int tow_num = ecid_xt.getID2();
0089 int strip_num = ecid_xt.getID3();
0090 rd_weiv[i] = rd_wei.getWeightGroupId();
0091 if (i < 10)
0092 std::cout << "here is the value for SM:" << sm_num << " tower:" << tow_num << " strip:" << strip_num
0093 << " group id:" << rd_weiv[i] << endl;
0094 i = i + 1;
0095 }
0096
0097 map<EcalLogicID, FEConfigOddWeightModeDat> dataset_mode;
0098 econn->fetchDataSet(&dataset_mode, &fe_wei_info);
0099
0100 typedef map<EcalLogicID, FEConfigOddWeightModeDat>::const_iterator CIfem;
0101 FEConfigOddWeightModeDat rd_mode;
0102
0103 int rd_modev[19] = {0};
0104 int k = 0;
0105 for (CIfem p = dataset_mode.begin(); p != dataset_mode.end(); p++) {
0106 rd_mode = p->second;
0107 rd_modev[0] = rd_mode.getEnableEBOddFilter();
0108 rd_modev[1] = rd_mode.getEnableEEOddFilter();
0109
0110 std::cout << "here is the value for the weight mode: EnableEBOddFilter:" << rd_modev[0]
0111 << " EnableEEOddFilter:" << rd_modev[1] << std::endl;
0112 k = k + 1;
0113 }
0114
0115 cout << "*****************************************" << endl;
0116 cout << "test read done" << iconf_req << endl;
0117 cout << "*****************************************" << endl;
0118 }
0119
0120 void testWriteOddWeights() {
0121
0122
0123
0124 cout << "*****************************************" << endl;
0125 cout << "************Inserting Odd weights************" << endl;
0126 cout << "*****************************************" << endl;
0127
0128 FEConfigOddWeightInfo fe_wei_info;
0129 fe_wei_info.setNumberOfGroups(2);
0130 fe_wei_info.setConfigTag("my preferred odd weights");
0131 econn->insertConfigSet(&fe_wei_info);
0132
0133 Tm tdb = fe_wei_info.getDBTime();
0134
0135
0136 vector<EcalLogicID> ecid_vec;
0137 ecid_vec = econn->getEcalLogicIDSet("EB_VFE", 1, 36, 1, 68, 1, 5);
0138
0139 map<EcalLogicID, FEConfigOddWeightGroupDat> dataset;
0140
0141 for (int ich = 0; ich < 2; ich++) {
0142 FEConfigOddWeightGroupDat wei;
0143 wei.setWeightGroupId(ich);
0144 if (ich == 0) {
0145 wei.setWeight0(0);
0146 wei.setWeight1(1);
0147 wei.setWeight2(2);
0148 wei.setWeight3(3);
0149 wei.setWeight4(4);
0150 wei.setWeight5(5);
0151 } else {
0152 wei.setWeight0(2);
0153 wei.setWeight1(3);
0154 wei.setWeight2(4);
0155 wei.setWeight3(5);
0156 wei.setWeight4(6);
0157 wei.setWeight5(7);
0158 }
0159
0160 dataset[ecid_vec[ich]] = wei;
0161 }
0162
0163
0164 econn->insertDataArraySet(&dataset, &fe_wei_info);
0165
0166 vector<EcalLogicID> my_StripEcalLogicId1_EE;
0167 vector<EcalLogicID> my_StripEcalLogicId2_EE;
0168
0169
0170
0171 my_StripEcalLogicId1_EE =
0172 econn->getEcalLogicIDSetOrdered("ECAL_readout_strip", 601, 609, 1, 100, 0, 5, "ECAL_readout_strip", 123);
0173
0174
0175 my_StripEcalLogicId2_EE =
0176 econn->getEcalLogicIDSetOrdered("ECAL_readout_strip", 646, 654, 1, 100, 0, 5, "ECAL_readout_strip", 123);
0177
0178
0179 map<EcalLogicID, FEConfigOddWeightDat> dataset2;
0180
0181 for (int ich = 0; ich < (int)ecid_vec.size(); ich++) {
0182 FEConfigOddWeightDat weid;
0183 if (ecid_vec[ich].getID1() <= 609 || ecid_vec[ich].getID1() > 645) {
0184 weid.setWeightGroupId(0);
0185 }
0186
0187 dataset2[ecid_vec[ich]] = weid;
0188 }
0189
0190
0191 for (int ich = 0; ich < (int)my_StripEcalLogicId1_EE.size(); ich++) {
0192 FEConfigOddWeightDat wut;
0193 int igroup = 1;
0194 wut.setWeightGroupId(igroup);
0195
0196 dataset2[my_StripEcalLogicId1_EE[ich]] = wut;
0197 }
0198
0199 for (int ich = 0; ich < (int)my_StripEcalLogicId2_EE.size(); ich++) {
0200 FEConfigOddWeightDat wut;
0201 int igroup = 1;
0202 wut.setWeightGroupId(igroup);
0203
0204 dataset2[my_StripEcalLogicId2_EE[ich]] = wut;
0205 }
0206
0207
0208
0209 econn->insertDataArraySet(&dataset2, &fe_wei_info);
0210
0211 map<EcalLogicID, FEConfigOddWeightModeDat> datasetmode;
0212 FEConfigOddWeightModeDat wei_mode;
0213 wei_mode.setEnableEBOddFilter(3);
0214 wei_mode.setDisableEBEvenPeakFinder(4);
0215 wei_mode.setFenixEEStripOutput(5);
0216
0217
0218
0219 datasetmode[ecid_vec[0]] = wei_mode;
0220
0221 econn->insertDataSet(&datasetmode, &fe_wei_info);
0222
0223 cout << "*****************************************" << endl;
0224 cout << "*********** odd weights done ************" << endl;
0225 cout << "*****************************************" << endl;
0226 }
0227
0228 private:
0229 CondDBApp();
0230 EcalCondDBInterface* econn;
0231
0232 uint64_t startmicros;
0233 uint64_t endmicros;
0234 run_t startrun;
0235 run_t endrun;
0236
0237 TFile* f;
0238 TH2F* mataq_vs_run;
0239 TH2F* apd_pn_mean_vs_run;
0240
0241 void printTag(const RunTag* tag) const {
0242 cout << endl;
0243 cout << "=============RunTag:" << endl;
0244 cout << "GeneralTag: " << tag->getGeneralTag() << endl;
0245 cout << "Location: " << tag->getLocationDef().getLocation() << endl;
0246 cout << "Run Type: " << tag->getRunTypeDef().getRunType() << endl;
0247 cout << "====================" << endl;
0248 }
0249
0250 void printIOV(const RunIOV* iov) const {
0251 cout << endl;
0252 cout << "=============RunIOV:" << endl;
0253 RunTag tag = iov->getRunTag();
0254 printTag(&tag);
0255 cout << "Run Number: " << iov->getRunNumber() << endl;
0256 cout << "Run Start: " << iov->getRunStart().str() << endl;
0257 cout << "Run End: " << iov->getRunEnd().str() << endl;
0258 cout << "====================" << endl;
0259 }
0260 };
0261
0262 int main(int argc, char* argv[]) {
0263 string sid;
0264 string user;
0265 string pass;
0266 string cfg_str;
0267 string read_and_w_str;
0268
0269 if (argc != 6) {
0270 cout << "Usage:" << endl;
0271 cout << " " << argv[0] << " <SID> <user> <pass> <cfg_id> <read_or_write(0:read 1:write 2:read_and_write)>" << endl;
0272 exit(-1);
0273 }
0274
0275 sid = argv[1];
0276 user = argv[2];
0277 pass = argv[3];
0278 cfg_str = argv[4];
0279 int cfg_id = atoi(cfg_str.c_str());
0280 read_and_w_str = argv[5];
0281 int rw_id = atoi(read_and_w_str.c_str());
0282
0283 try {
0284 CondDBApp app(sid, user, pass);
0285 if (rw_id == 1 || rw_id == 2)
0286 app.testWriteOddWeights();
0287 if (rw_id == 0 || rw_id == 2)
0288 app.testReadOddWeights(cfg_id);
0289 } catch (exception& e) {
0290 cout << "ERROR: " << e.what() << endl;
0291 } catch (...) {
0292 cout << "Unknown error caught" << endl;
0293 }
0294
0295 cout << "All Done." << endl;
0296
0297 return 0;
0298 }