Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:59

0001 #include "CalibCalorimetry/EcalTPGTools/plugins/EcalTPGDBApp.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 #include <vector>
0005 #include <ctime>
0006 
0007 using namespace std;
0008 using namespace oracle::occi;
0009 
0010 EcalTPGDBApp::EcalTPGDBApp(string host, string sid, string user, string pass, int port)
0011     : EcalCondDBInterface(host, sid, user, pass, port) {}
0012 
0013 EcalTPGDBApp::EcalTPGDBApp(string sid, string user, string pass) : EcalCondDBInterface(sid, user, pass) {}
0014 
0015 int EcalTPGDBApp::writeToConfDB_TPGPedestals(const map<EcalLogicID, FEConfigPedDat>& pedset, int iovId, string tag) {
0016   int result = 0;
0017 
0018   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0019   edm::LogVerbatim("ECALTPGDBApp") << "******** Inserting Peds in conf-OMDS*****";
0020   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0021 
0022   edm::LogVerbatim("ECALTPGDBApp") << "creating fe record ";
0023   FEConfigPedInfo fe_ped_info;
0024   fe_ped_info.setIOVId(iovId);
0025   fe_ped_info.setConfigTag(tag);
0026   insertConfigSet(&fe_ped_info);
0027   result = fe_ped_info.getID();
0028 
0029   // Insert the dataset, identifying by iov
0030   edm::LogVerbatim("ECALTPGDBApp") << "*********about to insert peds *********";
0031   edm::LogVerbatim("ECALTPGDBApp") << " map size = " << pedset.size();
0032   insertDataArraySet(&pedset, &fe_ped_info);
0033   edm::LogVerbatim("ECALTPGDBApp") << "*********Done peds            *********";
0034 
0035   return result;
0036 }
0037 
0038 int EcalTPGDBApp::writeToConfDB_TPGLinearCoef(const map<EcalLogicID, FEConfigLinDat>& linset,
0039                                               const map<EcalLogicID, FEConfigLinParamDat>& linparamset,
0040                                               int iovId,
0041                                               string tag) {
0042   int result = 0;
0043 
0044   edm::LogVerbatim("ECALTPGDBApp") << "*********************************************";
0045   edm::LogVerbatim("ECALTPGDBApp") << "**Inserting Linarization coeff in conf-OMDS**";
0046   edm::LogVerbatim("ECALTPGDBApp") << "*********************************************";
0047 
0048   edm::LogVerbatim("ECALTPGDBApp") << "creating fe record ";
0049   FEConfigLinInfo fe_lin_info;
0050   fe_lin_info.setIOVId(iovId);
0051   fe_lin_info.setConfigTag(tag);
0052   insertConfigSet(&fe_lin_info);
0053   result = fe_lin_info.getID();
0054 
0055   // Insert the dataset, identifying by iov
0056   edm::LogVerbatim("ECALTPGDBApp") << "*********about to insert linearization coeff *********";
0057   edm::LogVerbatim("ECALTPGDBApp") << " map size = " << linset.size();
0058   insertDataArraySet(&linset, &fe_lin_info);
0059   insertDataArraySet(&linparamset, &fe_lin_info);
0060   edm::LogVerbatim("ECALTPGDBApp") << "*********Done lineraization coeff            *********";
0061 
0062   return result;
0063 }
0064 
0065 int EcalTPGDBApp::writeToConfDB_TPGMain(int ped,
0066                                         int lin,
0067                                         int lut,
0068                                         int fgr,
0069                                         int sli,
0070                                         int wei,
0071                                         int wei2,
0072                                         int spi,
0073                                         int tim,
0074                                         int bxt,
0075                                         int btt,
0076                                         int bst,
0077                                         int cok,
0078                                         string tag,
0079                                         int ver) {
0080   int result = 0;
0081 
0082   edm::LogVerbatim("ECALTPGDBApp") << "*********************************************";
0083   edm::LogVerbatim("ECALTPGDBApp") << "**Inserting Main FE table in conf-OMDS     **";
0084   edm::LogVerbatim("ECALTPGDBApp") << "*********************************************";
0085 
0086   edm::LogVerbatim("ECALTPGDBApp") << "creating fe record ";
0087 
0088   FEConfigMainInfo fe_main;
0089   fe_main.setPedId(ped);
0090   fe_main.setLinId(lin);
0091   fe_main.setLUTId(lut);
0092   fe_main.setFgrId(fgr);
0093   fe_main.setSliId(sli);
0094   fe_main.setWeiId(wei);
0095   fe_main.setWei2Id(wei2);
0096   fe_main.setSpiId(spi);
0097   fe_main.setTimId(tim);
0098   fe_main.setBxtId(bxt);
0099   fe_main.setBttId(btt);
0100   fe_main.setBstId(bst);
0101   fe_main.setCokeId(cok);
0102   fe_main.setConfigTag(tag);
0103   fe_main.setVersion(ver);
0104 
0105   insertConfigSet(&fe_main);
0106   result = fe_main.getId();
0107 
0108   edm::LogVerbatim("ECALTPGDBApp") << "*********Done Main           *********";
0109 
0110   return result;
0111 }
0112 
0113 void EcalTPGDBApp::readFromConfDB_TPGPedestals(int iconf_req) {
0114   // now we do something else
0115   // this is an example for reading the pedestals
0116   // for a given config iconf_req
0117 
0118   // FC alternatively a config set can be retrieved by the tag and version
0119 
0120   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0121   edm::LogVerbatim("ECALTPGDBApp") << "test readinf fe_ped with id=" << iconf_req;
0122   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0123 
0124   FEConfigPedInfo fe_ped_info;
0125   fe_ped_info.setId(iconf_req);
0126 
0127   fetchConfigSet(&fe_ped_info);
0128 
0129   map<EcalLogicID, FEConfigPedDat> dataset_ped;
0130   fetchDataSet(&dataset_ped, &fe_ped_info);
0131 
0132   typedef map<EcalLogicID, FEConfigPedDat>::const_iterator CIfeped;
0133   EcalLogicID ecid_xt;
0134   FEConfigPedDat rd_ped;
0135 
0136   for (CIfeped p = dataset_ped.begin(); p != dataset_ped.end(); ++p) {
0137     ecid_xt = p->first;
0138     rd_ped = p->second;
0139     //int sm_num=ecid_xt.getID1();
0140     ecid_xt.getID2();
0141     rd_ped.getPedMeanG12();
0142     rd_ped.getPedMeanG6();
0143     rd_ped.getPedMeanG1();
0144   }
0145 
0146   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0147   edm::LogVerbatim("ECALTPGDBApp") << "test read done" << iconf_req;
0148   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0149 }
0150 
0151 int EcalTPGDBApp::readFromCondDB_Pedestals(map<EcalLogicID, MonPedestalsDat>& dataset, int runNb) {
0152   int iovId = 0;
0153 
0154   edm::LogVerbatim("ECALTPGDBApp") << "Retrieving run list from DB from run nb ... " << runNb;
0155   RunTag my_runtag;
0156   LocationDef my_locdef;
0157   RunTypeDef my_rundef;
0158   my_locdef.setLocation("P5_Co");
0159   my_rundef.setRunType("PEDESTAL");
0160   my_runtag.setLocationDef(my_locdef);
0161   my_runtag.setRunTypeDef(my_rundef);
0162   my_runtag.setGeneralTag("LOCAL");
0163 
0164   // here we retrieve the Monitoring results
0165   MonVersionDef monverdef;
0166   monverdef.setMonitoringVersion("test01");
0167   MonRunTag montag;
0168   montag.setMonVersionDef(monverdef);
0169   montag.setGeneralTag("CMSSW");
0170 
0171   MonRunList mon_list;
0172   mon_list.setMonRunTag(montag);
0173   mon_list.setRunTag(my_runtag);
0174 
0175   edm::LogVerbatim("ECALTPGDBApp") << "we are in read ped from condDB and runNb is " << runNb;
0176 
0177   mon_list = fetchMonRunListLastNRuns(my_runtag, montag, runNb, 10);
0178 
0179   edm::LogVerbatim("ECALTPGDBApp") << "we are in read ped from condDB";
0180 
0181   std::vector<MonRunIOV> mon_run_vec = mon_list.getRuns();
0182   edm::LogVerbatim("ECALTPGDBApp") << "number of ped runs is : " << mon_run_vec.size();
0183   int mon_runs = mon_run_vec.size();
0184   //int sm_num = 0;
0185 
0186   if (mon_runs > 0) {
0187     for (int ii = 0; ii < (int)mon_run_vec.size(); ii++)
0188       edm::LogVerbatim("ECALTPGDBApp") << "here is the run number: " << mon_run_vec[ii].getRunIOV().getRunNumber();
0189 
0190     // for the first run of the list we retrieve the pedestals
0191     int run = 0;
0192     edm::LogVerbatim("ECALTPGDBApp") << " retrieve the data for a given run";
0193     edm::LogVerbatim("ECALTPGDBApp") << "here is the run number: " << mon_run_vec[run].getRunIOV().getRunNumber();
0194     iovId = mon_run_vec[run].getID();
0195 
0196     fetchDataSet(&dataset, &mon_run_vec[run]);
0197   }
0198   return iovId;
0199 }
0200 
0201 int EcalTPGDBApp::writeToConfDB_TPGSliding(const map<EcalLogicID, FEConfigSlidingDat>& sliset, int iovId, string tag) {
0202   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0203   edm::LogVerbatim("ECALTPGDBApp") << "************Inserting SLIDING************";
0204   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0205   int result = 0;
0206 
0207   FEConfigSlidingInfo fe_info;
0208   fe_info.setIOVId(iovId);
0209   fe_info.setConfigTag(tag);
0210   insertConfigSet(&fe_info);
0211 
0212   //  Tm tdb = fe_lut_info.getDBTime();
0213   //tdb.dumpTm();
0214 
0215   // Insert the dataset
0216   insertDataArraySet(&sliset, &fe_info);
0217 
0218   result = fe_info.getId();
0219 
0220   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0221   edm::LogVerbatim("ECALTPGDBApp") << "************SLI done*********************";
0222   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0223   return result;
0224 }
0225 
0226 int EcalTPGDBApp::writeToConfDB_TPGLUT(const map<EcalLogicID, FEConfigLUTGroupDat>& lutgroupset,
0227                                        const map<EcalLogicID, FEConfigLUTDat>& lutset,
0228                                        const map<EcalLogicID, FEConfigLUTParamDat>& lutparamset,
0229                                        int iovId,
0230                                        string tag) {
0231   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0232   edm::LogVerbatim("ECALTPGDBApp") << "************Inserting LUT************";
0233   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0234   int result = 0;
0235 
0236   FEConfigLUTInfo fe_lut_info;
0237   fe_lut_info.setNumberOfGroups(iovId);
0238   fe_lut_info.setConfigTag(tag);
0239   insertConfigSet(&fe_lut_info);
0240 
0241   //  Tm tdb = fe_lut_info.getDBTime();
0242   //tdb.dumpTm();
0243 
0244   // Insert the dataset
0245   insertDataArraySet(&lutgroupset, &fe_lut_info);
0246   // Insert the dataset
0247   insertDataArraySet(&lutset, &fe_lut_info);
0248   // insert the parameters
0249   insertDataArraySet(&lutparamset, &fe_lut_info);
0250 
0251   result = fe_lut_info.getId();
0252 
0253   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0254   edm::LogVerbatim("ECALTPGDBApp") << "************LUT done*********************";
0255   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0256   return result;
0257 }
0258 
0259 int EcalTPGDBApp::writeToConfDB_TPGWeight(const map<EcalLogicID, FEConfigWeightGroupDat>& lutgroupset,
0260                                           const map<EcalLogicID, FEConfigWeightDat>& lutset,
0261                                           int ngr,
0262                                           string tag) {
0263   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0264   edm::LogVerbatim("ECALTPGDBApp") << "************Inserting weights************";
0265   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0266 
0267   int result = 0;
0268 
0269   FEConfigWeightInfo fe_wei_info;
0270   fe_wei_info.setNumberOfGroups(ngr);
0271   fe_wei_info.setConfigTag(tag);
0272   insertConfigSet(&fe_wei_info);
0273 
0274   //  Tm tdb = fe_lut_info.getDBTime();
0275   //tdb.dumpTm();
0276 
0277   // Insert the dataset
0278   insertDataArraySet(&lutgroupset, &fe_wei_info);
0279   // Insert the dataset
0280   insertDataArraySet(&lutset, &fe_wei_info);
0281 
0282   result = fe_wei_info.getId();
0283 
0284   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0285   edm::LogVerbatim("ECALTPGDBApp") << "************WEIGHT done******************";
0286   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0287   return result;
0288 }
0289 
0290 int EcalTPGDBApp::writeToConfDB_TPGWeight_doubleWeights(const map<EcalLogicID, FEConfigOddWeightGroupDat>& lutgroupset,
0291                                                         const map<EcalLogicID, FEConfigOddWeightDat>& lutset,
0292                                                         const map<EcalLogicID, FEConfigOddWeightModeDat>& tpmode,
0293                                                         int ngr,
0294                                                         string tag) {
0295   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0296   edm::LogVerbatim("ECALTPGDBApp") << "************Inserting odd weights************";
0297   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0298 
0299   int result = 0;
0300 
0301   FEConfigOddWeightInfo fe_wei_info;
0302   fe_wei_info.setNumberOfGroups(ngr);
0303   fe_wei_info.setConfigTag(tag);
0304   insertConfigSet(&fe_wei_info);
0305 
0306   //  Tm tdb = fe_lut_info.getDBTime();
0307   //tdb.dumpTm();
0308 
0309   // Insert the dataset
0310   insertDataArraySet(&lutgroupset, &fe_wei_info);
0311   // Insert the dataset
0312   insertDataArraySet(&lutset, &fe_wei_info);
0313   // Insert the Tpmode
0314   insertDataSet(&tpmode, &fe_wei_info);
0315 
0316   result = fe_wei_info.getId();
0317 
0318   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0319   edm::LogVerbatim("ECALTPGDBApp") << "************ODD WEIGHT + TPmode done******************";
0320   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0321   return result;
0322 }
0323 
0324 int EcalTPGDBApp::writeToConfDB_TPGFgr(const map<EcalLogicID, FEConfigFgrGroupDat>& fgrgroupset,
0325                                        const map<EcalLogicID, FEConfigFgrDat>& fgrset,
0326                                        const map<EcalLogicID, FEConfigFgrParamDat>& fgrparamset,
0327                                        const map<EcalLogicID, FEConfigFgrEETowerDat>& dataset3,
0328                                        const map<EcalLogicID, FEConfigFgrEEStripDat>& dataset4,
0329                                        int iovId,
0330                                        string tag) {
0331   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0332   edm::LogVerbatim("ECALTPGDBApp") << "************Inserting Fgr************";
0333   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0334   int result = 0;
0335 
0336   FEConfigFgrInfo fe_fgr_info;
0337   fe_fgr_info.setNumberOfGroups(iovId);  // this eventually refers to some other table
0338   fe_fgr_info.setConfigTag(tag);
0339   insertConfigSet(&fe_fgr_info);
0340 
0341   //  Tm tdb = fe_fgr_info.getDBTime();
0342   //tdb.dumpTm();
0343 
0344   // Insert the dataset
0345   insertDataArraySet(&fgrgroupset, &fe_fgr_info);
0346   // Insert the dataset
0347   insertDataArraySet(&fgrset, &fe_fgr_info);
0348   // Insert the parameters
0349   insertDataArraySet(&fgrparamset, &fe_fgr_info);
0350   // Insert the parameters
0351   insertDataArraySet(&dataset3, &fe_fgr_info);
0352   // Insert the parameters
0353   insertDataArraySet(&dataset4, &fe_fgr_info);
0354 
0355   result = fe_fgr_info.getId();
0356 
0357   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0358   edm::LogVerbatim("ECALTPGDBApp") << "************Fgr done*********************";
0359   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0360   return result;
0361 }
0362 
0363 int EcalTPGDBApp::writeToConfDB_Spike(const map<EcalLogicID, FEConfigSpikeDat>& spikegroupset, string tag) {
0364   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0365   edm::LogVerbatim("ECALTPGDBApp") << "************Inserting Spike************";
0366   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0367   int result = 0;
0368 
0369   FEConfigSpikeInfo fe_spike_info;
0370   fe_spike_info.setConfigTag(tag);
0371   insertConfigSet(&fe_spike_info);
0372 
0373   //  Tm tdb = fe_fgr_info.getDBTime();
0374   //tdb.dumpTm();
0375 
0376   // Insert the dataset
0377   insertDataArraySet(&spikegroupset, &fe_spike_info);
0378 
0379   result = fe_spike_info.getId();
0380 
0381   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0382   edm::LogVerbatim("ECALTPGDBApp") << "************Spike done*******************";
0383   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0384   return result;
0385 }
0386 
0387 int EcalTPGDBApp::writeToConfDB_Delay(const map<EcalLogicID, FEConfigTimingDat>& timegroupset, string tag) {
0388   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0389   edm::LogVerbatim("ECALTPGDBApp") << "************Inserting Delays************";
0390   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0391   int result = 0;
0392 
0393   FEConfigTimingInfo fe_time_info;
0394   fe_time_info.setConfigTag(tag);
0395   insertConfigSet(&fe_time_info);
0396 
0397   //  Tm tdb = fe_fgr_info.getDBTime();
0398   //tdb.dumpTm();
0399 
0400   // Insert the dataset
0401   insertDataArraySet(&timegroupset, &fe_time_info);
0402 
0403   result = fe_time_info.getId();
0404 
0405   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0406   edm::LogVerbatim("ECALTPGDBApp") << "************Delays done******************";
0407   edm::LogVerbatim("ECALTPGDBApp") << "*****************************************";
0408   return result;
0409 }
0410 
0411 void EcalTPGDBApp::printTag(const RunTag* tag) const {
0412   edm::LogVerbatim("ECALTPGDBApp") << "=============RunTag:";
0413   edm::LogVerbatim("ECALTPGDBApp") << "GeneralTag:         " << tag->getGeneralTag();
0414   edm::LogVerbatim("ECALTPGDBApp") << "Location:           " << tag->getLocationDef().getLocation();
0415   edm::LogVerbatim("ECALTPGDBApp") << "Run Type:           " << tag->getRunTypeDef().getRunType();
0416   edm::LogVerbatim("ECALTPGDBApp") << "====================";
0417 }
0418 
0419 void EcalTPGDBApp::printIOV(const RunIOV* iov) const {
0420   edm::LogVerbatim("ECALTPGDBApp") << "=============RunIOV:";
0421   RunTag tag = iov->getRunTag();
0422   printTag(&tag);
0423   edm::LogVerbatim("ECALTPGDBApp") << "Run Number:         " << iov->getRunNumber();
0424   edm::LogVerbatim("ECALTPGDBApp") << "Run Start:          " << iov->getRunStart().str();
0425   edm::LogVerbatim("ECALTPGDBApp") << "Run End:            " << iov->getRunEnd().str();
0426   edm::LogVerbatim("ECALTPGDBApp") << "====================";
0427 }