Back to home page

Project CMSSW displayed by LXR

 
 

    


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    *   App constructor; Makes the database connection
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    *  App destructor;  Cleans up database connection
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     // now we do something else
0061     // this is an example for reading the odd weights
0062     // for a given config iconf_req
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       rd_modev[2] = rd_mode.getEnableEBOddPeakFinder();
0110       rd_modev[3] = rd_mode.getEnableEEOddPeakFinder();
0111       rd_modev[4] = rd_mode.getDisableEBEvenPeakFinder();
0112       rd_modev[5] = rd_mode.getDisableEEEvenPeakFinder();
0113       rd_modev[6] = rd_mode.getFenixEBStripOutput();
0114       rd_modev[7] = rd_mode.getFenixEEStripOutput();
0115       rd_modev[8] = rd_mode.getFenixEBStripInfobit2();
0116       rd_modev[9] = rd_mode.getFenixEEStripInfobit2();
0117       rd_modev[10] = rd_mode.getFenixEBTcpOutput();
0118       rd_modev[11] = rd_mode.getFenixEBTcpInfobit1();
0119       rd_modev[12] = rd_mode.getFenixEETcpOutput();
0120       rd_modev[13] = rd_mode.getFenixEETcpInfobit1();
0121       // ...
0122       std::cout << "here is the value for the weight mode: " << std::endl
0123                 << " EnableEBOddFilter:" << rd_modev[0] << std::endl
0124                 << " EnableEEOddFilter:" << rd_modev[1] << std::endl
0125                 << " EnableEBOddPeakFinder:" << rd_modev[2] << std::endl
0126                 << " EnableEEOddPeakFinder:" << rd_modev[3] << std::endl
0127                 << " DisableEBEvenPeakFinder:" << rd_modev[4] << std::endl
0128                 << " DisableEEEvenPeakFinder:" << rd_modev[5] << std::endl
0129                 << " FenixEBStripOutput:" << rd_modev[6] << std::endl
0130                 << " FenixEEStripOutput:" << rd_modev[7] << std::endl
0131                 << " FenixEBStripInfobit2:" << rd_modev[8] << std::endl
0132                 << " FenixEEStripInfobit2:" << rd_modev[9] << std::endl
0133                 << " FenixEBTcpOutput:" << rd_modev[10] << std::endl
0134                 << " FenixEBTcpinfobit1:" << rd_modev[11] << std::endl
0135                 << " FenixEETcpOutput:" << rd_modev[12] << std::endl
0136                 << " FenixEETcpinfobit1:" << rd_modev[13] << std::endl;
0137       k = k + 1;
0138     }
0139 
0140     cout << "*****************************************" << endl;
0141     cout << "test read done" << iconf_req << endl;
0142     cout << "*****************************************" << endl;
0143   }
0144 
0145   void testWriteOddWeights() {
0146     // now we do something else
0147     // this is an example for writing the odd weights
0148 
0149     cout << "*****************************************" << endl;
0150     cout << "************Inserting Odd weights************" << endl;
0151     cout << "*****************************************" << endl;
0152 
0153     FEConfigOddWeightInfo fe_wei_info;
0154     fe_wei_info.setNumberOfGroups(2);  // this eventually refers to some other table
0155     fe_wei_info.setConfigTag("oddweights_zeroing_flagging_test_v1");
0156     econn->insertConfigSet(&fe_wei_info);
0157 
0158     Tm tdb = fe_wei_info.getDBTime();
0159     //      tdb.dumpTm();
0160 
0161     vector<EcalLogicID> EB_ecid_vec, EE_ecid_vec1, EE_ecid_vec2;
0162     EB_ecid_vec = econn->getEcalLogicIDSet("EB_VFE", 1, 36, 1, 68, 1, 5);
0163 
0164     // EE Strip identifiers
0165     // DCC=601-609 TT = ~40 EEstrip = 5
0166     EE_ecid_vec1 =
0167         econn->getEcalLogicIDSetOrdered("ECAL_readout_strip", 601, 609, 1, 100, 0, 5, "ECAL_readout_strip", 123);
0168     // EE Strip identifiers
0169     // DCC=646-654 TT = ~40 EEstrip = 5
0170     EE_ecid_vec2 =
0171         econn->getEcalLogicIDSetOrdered("ECAL_readout_strip", 646, 654, 1, 100, 0, 5, "ECAL_readout_strip", 123);
0172 
0173     map<EcalLogicID, FEConfigOddWeightGroupDat> dataset;
0174     // All EB with the same weights, and all EE with slightly different
0175     for (int ich = 0; ich < 2; ich++) {
0176       FEConfigOddWeightGroupDat wei;
0177       wei.setWeightGroupId(ich);
0178       if (ich == 0) {         // first group
0179         wei.setWeight0(125);  // w0 in the confDB is w4 in the offline  125,63,0,0,68
0180         wei.setWeight1(63 + 0x80);
0181         wei.setWeight2(0);
0182         wei.setWeight3(0);
0183         wei.setWeight4(68);
0184         wei.setWeight5(0);
0185       } else {                // second group
0186         wei.setWeight0(125);  // w0 in the confDB is w4 in the offline  125,63,0,0,68
0187         wei.setWeight1(64 + 0x80);
0188         wei.setWeight2(0);
0189         wei.setWeight3(0);
0190         wei.setWeight4(67);
0191         wei.setWeight5(0);
0192       }
0193       // Fill the dataset
0194       dataset[EB_ecid_vec[ich]] = wei;  // we use any logic id, because it is in any case ignored...
0195     }
0196 
0197     // Insert the dataset
0198     econn->insertDataArraySet(&dataset, &fe_wei_info);
0199 
0200     // now we store in the DB the correspondence btw channels and odd weight groups
0201     map<EcalLogicID, FEConfigOddWeightDat> dataset2;
0202     // in this case I decide in a stupid way which channel belongs to which group
0203     for (int ich = 0; ich < (int)EB_ecid_vec.size(); ich++) {
0204       FEConfigOddWeightDat weid;
0205       std::cout << "EB " << EB_ecid_vec[ich].getID1() << "  " << EB_ecid_vec[ich].getID2() << "  "
0206                 << EB_ecid_vec[ich].getID3() << std::endl;
0207       weid.setWeightGroupId(0);  // EB
0208       // Fill the dataset
0209       dataset2[EB_ecid_vec[ich]] = weid;
0210     }
0211 
0212     for (int ich = 0; ich < (int)EE_ecid_vec1.size(); ich++) {
0213       FEConfigOddWeightDat weid;
0214       weid.setWeightGroupId(1);
0215       // Fill the dataset
0216       std::cout << "EE " << EE_ecid_vec1[ich].getID1() << "  " << EE_ecid_vec1[ich].getID2() << "  "
0217                 << EE_ecid_vec1[ich].getID3() << std::endl;
0218       dataset2[EE_ecid_vec1[ich]] = weid;
0219     }
0220     // EE loop 2 (we had to split the ids of EE in 2 vectors to avoid crash!)
0221     for (int ich = 0; ich < (int)EE_ecid_vec2.size(); ich++) {
0222       FEConfigOddWeightDat weid;
0223       std::cout << "EE " << EE_ecid_vec2[ich].getID1() << "  " << EE_ecid_vec2[ich].getID2() << "  "
0224                 << EE_ecid_vec2[ich].getID3() << std::endl;
0225       weid.setWeightGroupId(1);
0226       // Fill the dataset
0227       dataset2[EE_ecid_vec2[ich]] = weid;
0228     }
0229 
0230     // Insert the dataset
0231 
0232     econn->insertDataArraySet(&dataset2, &fe_wei_info);
0233 
0234     map<EcalLogicID, FEConfigOddWeightModeDat> datasetmode;
0235     FEConfigOddWeightModeDat wei_mode;
0236 
0237     wei_mode.setEnableEBOddFilter(1);
0238     wei_mode.setEnableEEOddFilter(1);
0239     wei_mode.setEnableEBOddPeakFinder(1);
0240     wei_mode.setEnableEEOddPeakFinder(1);
0241 
0242     wei_mode.setFenixEBStripOutput(2);
0243     wei_mode.setFenixEEStripOutput(2);
0244 
0245     wei_mode.setFenixEBStripInfobit2(1);
0246     wei_mode.setFenixEBTcpOutput(2);
0247     wei_mode.setFenixEBTcpInfoBit1(1);
0248 
0249     // Fill the dataset
0250     datasetmode[EB_ecid_vec[0]] = wei_mode;  // we use any logic id, because it is in any case ignored...
0251 
0252     econn->insertDataSet(&datasetmode, &fe_wei_info);
0253 
0254     cout << "*****************************************" << endl;
0255     cout << "*********** odd weights done ************" << endl;
0256     cout << "*****************************************" << endl;
0257   }
0258 
0259 private:
0260   CondDBApp();  // hidden default constructor
0261   EcalCondDBInterface* econn;
0262 
0263   uint64_t startmicros;
0264   uint64_t endmicros;
0265   run_t startrun;
0266   run_t endrun;
0267 
0268   TFile* f;
0269   TH2F* mataq_vs_run;
0270   TH2F* apd_pn_mean_vs_run;
0271 
0272   void printTag(const RunTag* tag) const {
0273     cout << endl;
0274     cout << "=============RunTag:" << endl;
0275     cout << "GeneralTag:         " << tag->getGeneralTag() << endl;
0276     cout << "Location:           " << tag->getLocationDef().getLocation() << endl;
0277     cout << "Run Type:           " << tag->getRunTypeDef().getRunType() << endl;
0278     cout << "====================" << endl;
0279   }
0280 
0281   void printIOV(const RunIOV* iov) const {
0282     cout << endl;
0283     cout << "=============RunIOV:" << endl;
0284     RunTag tag = iov->getRunTag();
0285     printTag(&tag);
0286     cout << "Run Number:         " << iov->getRunNumber() << endl;
0287     cout << "Run Start:          " << iov->getRunStart().str() << endl;
0288     cout << "Run End:            " << iov->getRunEnd().str() << endl;
0289     cout << "====================" << endl;
0290   }
0291 };
0292 
0293 int main(int argc, char* argv[]) {
0294   string sid;
0295   string user;
0296   string pass;
0297   string cfg_str;
0298   string read_and_w_str;
0299 
0300   if (argc != 6) {
0301     cout << "Usage:" << endl;
0302     cout << "  " << argv[0] << " <SID> <user> <pass> <cfg_id> <read_or_write(0:read 1:write 2:read_and_write)>" << endl;
0303     exit(-1);
0304   }
0305 
0306   sid = argv[1];
0307   user = argv[2];
0308   pass = argv[3];
0309   cfg_str = argv[4];
0310   int cfg_id = atoi(cfg_str.c_str());
0311   read_and_w_str = argv[5];
0312   int rw_id = atoi(read_and_w_str.c_str());
0313 
0314   try {
0315     CondDBApp app(sid, user, pass);
0316     if (rw_id == 1 || rw_id == 2)
0317       app.testWriteOddWeights();
0318     if (rw_id == 0 || rw_id == 2)
0319       app.testReadOddWeights(cfg_id);
0320   } catch (exception& e) {
0321     cout << "ERROR:  " << e.what() << endl;
0322   } catch (...) {
0323     cout << "Unknown error caught" << endl;
0324   }
0325 
0326   cout << "All Done." << endl;
0327 
0328   return 0;
0329 }