CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/CalibCalorimetry/EcalTPGTools/plugins/EcalTPGDBApp.cc

Go to the documentation of this file.
00001 #include "CalibCalorimetry/EcalTPGTools/plugins/EcalTPGDBApp.h"
00002 
00003 #include <vector>
00004 #include <time.h>
00005 
00006 using namespace std;
00007 using namespace oracle::occi;
00008 
00009 EcalTPGDBApp::EcalTPGDBApp(std::string host, std::string sid, std::string user, std::string pass, int port)
00010   : EcalCondDBInterface( host, sid, user, pass, port )
00011 {}
00012  
00013 EcalTPGDBApp::EcalTPGDBApp(std::string sid, std::string user, std::string pass)
00014   : EcalCondDBInterface(  sid, user, pass )
00015 {}
00016 
00017 int EcalTPGDBApp::writeToConfDB_TPGPedestals(const  std::map<EcalLogicID, FEConfigPedDat> & pedset, int iovId, std::string tag) {
00018   
00019   int result=0;
00020 
00021   std::cout << "*****************************************" << std::endl;
00022   std::cout << "******** Inserting Peds in conf-OMDS*****" << std::endl;
00023   std::cout << "*****************************************" << std::endl;
00024   
00025   std::cout << "creating fe record " <<std::endl;
00026   FEConfigPedInfo fe_ped_info ;
00027   fe_ped_info.setIOVId(iovId) ;
00028   fe_ped_info.setConfigTag(tag) ;
00029   insertConfigSet(&fe_ped_info) ;
00030   result = fe_ped_info.getID() ;
00031 
00032 
00033   // Insert the dataset, identifying by iov
00034   std::cout << "*********about to insert peds *********" << std::endl;
00035   std::cout << " map size = "<<pedset.size()<<std::endl ;
00036   insertDataArraySet(&pedset, &fe_ped_info);
00037   std::cout << "*********Done peds            *********" << std::endl;
00038   
00039   return result;
00040 }
00041 
00042 int EcalTPGDBApp::writeToConfDB_TPGLinearCoef(const  std::map<EcalLogicID, FEConfigLinDat> & linset, 
00043                                               const  std::map<EcalLogicID, FEConfigLinParamDat> & linparamset, int iovId, std::string tag) {
00044   
00045   int result=0;
00046 
00047   std::cout << "*********************************************" << std::endl;
00048   std::cout << "**Inserting Linarization coeff in conf-OMDS**" << std::endl;
00049   std::cout << "*********************************************" << std::endl;
00050   
00051   std::cout << "creating fe record " <<std::endl;
00052   FEConfigLinInfo fe_lin_info ;
00053   fe_lin_info.setIOVId(iovId) ;
00054   fe_lin_info.setConfigTag(tag) ;
00055   insertConfigSet(&fe_lin_info) ;
00056   result = fe_lin_info.getID() ;
00057   
00058   // Insert the dataset, identifying by iov
00059   std::cout << "*********about to insert linearization coeff *********" << std::endl;
00060   std::cout << " map size = "<<linset.size()<<std::endl ;
00061   insertDataArraySet(&linset, &fe_lin_info);
00062   insertDataArraySet(&linparamset, &fe_lin_info);
00063   std::cout << "*********Done lineraization coeff            *********" << std::endl;
00064   
00065   return result;
00066 }
00067 
00068 int EcalTPGDBApp::writeToConfDB_TPGMain(int ped, int lin, int lut, int fgr, int sli, int wei, int bxt, int btt, std::string tag, int ver) {
00069   
00070   int result=0;
00071 
00072   std::cout << "*********************************************" << std::endl;
00073   std::cout << "**Inserting Main FE table in conf-OMDS     **" << std::endl;
00074   std::cout << "*********************************************" << std::endl;
00075   
00076   std::cout << "creating fe record " <<std::endl;
00077 
00078   FEConfigMainInfo fe_main ;
00079   fe_main.setPedId(ped) ;
00080   fe_main.setLinId(lin) ;
00081   fe_main.setLUTId(lut) ;
00082   fe_main.setFgrId(fgr) ;
00083   fe_main.setSliId(sli) ;
00084   fe_main.setWeiId(wei) ;
00085   fe_main.setBxtId(bxt) ;
00086   fe_main.setBttId(btt) ;
00087   fe_main.setConfigTag(tag) ;
00088   fe_main.setVersion(ver) ;
00089 
00090   insertConfigSet(&fe_main) ;
00091   result = fe_main.getId() ;
00092   
00093   std::cout << "*********Done Main           *********" << std::endl;
00094   
00095   return result;
00096 }
00097 
00098 
00099 void EcalTPGDBApp::readFromConfDB_TPGPedestals(int iconf_req ) {
00100   // now we do something else 
00101   // this is an example for reading the pedestals 
00102   // for a given config iconf_req 
00103 
00104   // FC alternatively a config set can be retrieved by the tag and version
00105   
00106   std::cout << "*****************************************" << std::endl;
00107   std::cout << "test readinf fe_ped with id="<<iconf_req  << std::endl;
00108   std::cout << "*****************************************" << std::endl;
00109   
00110   FEConfigPedInfo fe_ped_info;
00111   fe_ped_info.setId(iconf_req);
00112 
00113   fetchConfigSet(&fe_ped_info);
00114 
00115   std::map<EcalLogicID, FEConfigPedDat> dataset_ped;
00116   fetchDataSet(&dataset_ped, &fe_ped_info);
00117   
00118   typedef std::map<EcalLogicID, FEConfigPedDat>::const_iterator CIfeped;
00119   EcalLogicID ecid_xt;
00120   FEConfigPedDat  rd_ped;
00121   
00122   float ped_m12[61200];
00123   float ped_m6[61200];
00124   float ped_m1[61200];
00125   for (int i=0; i<61200; i++){
00126     ped_m12[i]=0;
00127     ped_m6[i]=0;
00128     ped_m1[i]=0;
00129   }
00130   
00131   for (CIfeped p = dataset_ped.begin(); p != dataset_ped.end(); p++) {
00132     ecid_xt = p->first;
00133     rd_ped  = p->second;
00134     //int sm_num=ecid_xt.getID1();
00135     int xt_num=ecid_xt.getID2();
00136     ped_m12[xt_num]=rd_ped.getPedMeanG12();
00137     ped_m6[xt_num]=rd_ped.getPedMeanG6();
00138     ped_m1[xt_num]=rd_ped.getPedMeanG1();
00139   }
00140   
00141   std::cout << "*****************************************" << std::endl;
00142   std::cout << "test read done"<<iconf_req  << std::endl;
00143   std::cout << "*****************************************" << std::endl;
00144   
00145 }
00146 
00147 
00148 int EcalTPGDBApp::readFromCondDB_Pedestals(std::map<EcalLogicID, MonPedestalsDat> & dataset, int runNb) {
00149 
00150 
00151   int iovId = 0 ;
00152   
00153   std::cout << "Retrieving run list from DB from run nb ... "<< runNb << std::endl;
00154   RunTag  my_runtag;
00155   LocationDef my_locdef;
00156   RunTypeDef my_rundef;
00157   my_locdef.setLocation("P5_Co");
00158   my_rundef.setRunType("PEDESTAL");
00159   my_runtag.setLocationDef(my_locdef);
00160   my_runtag.setRunTypeDef(my_rundef);
00161   my_runtag.setGeneralTag("LOCAL");
00162   
00163   // here we retrieve the Monitoring results
00164   MonVersionDef monverdef;
00165   monverdef.setMonitoringVersion("test01");
00166   MonRunTag montag;
00167   montag.setMonVersionDef(monverdef);
00168   montag.setGeneralTag("CMSSW");
00169   
00170   MonRunList mon_list;
00171   mon_list.setMonRunTag(montag);
00172   mon_list.setRunTag(my_runtag);
00173 
00174   std::cout<<"we are in read ped from condDB and runNb is "<< runNb<<std::endl;
00175 
00176   mon_list = fetchMonRunListLastNRuns(my_runtag, montag, runNb , 10 );
00177 
00178   std::cout<<"we are in read ped from condDB"<<std::endl;
00179 
00180   std::vector<MonRunIOV> mon_run_vec =  mon_list.getRuns();
00181   std::cout <<"number of ped runs is : "<< mon_run_vec.size()<< std::endl;
00182   int mon_runs = mon_run_vec.size();  
00183   //int sm_num = 0;  
00184 
00185   if(mon_runs>0) {
00186     for (int ii=0 ; ii<(int)mon_run_vec.size(); ii++) std::cout << "here is the run number: "<< mon_run_vec[ii].getRunIOV().getRunNumber() << std::endl;
00187     
00188     // for the first run of the list we retrieve the pedestals
00189     int run=0;
00190     std::cout <<" retrieve the data for a given run"<< std::endl;
00191     std::cout << "here is the run number: "<< mon_run_vec[run].getRunIOV().getRunNumber() << std::endl;
00192     iovId = mon_run_vec[run].getID();
00193     
00194     fetchDataSet(&dataset, &mon_run_vec[run]) ;   
00195   }
00196   return iovId ;
00197 }
00198 
00199 
00200 int EcalTPGDBApp::writeToConfDB_TPGSliding(const  std::map<EcalLogicID, FEConfigSlidingDat> & sliset, int iovId, std::string tag) 
00201 {
00202   std::cout << "*****************************************" << std::endl;
00203   std::cout << "************Inserting SLIDING************" << std::endl;
00204   std::cout << "*****************************************" << std::endl;
00205   int result=0; 
00206 
00207   FEConfigSlidingInfo fe_info ;
00208   fe_info.setIOVId(iovId); 
00209   fe_info.setConfigTag(tag);
00210   insertConfigSet(&fe_info);
00211   
00212   //  Tm tdb = fe_lut_info.getDBTime();
00213   //tdb.dumpTm();
00214   
00215   // Insert the dataset
00216   insertDataArraySet(&sliset, &fe_info);
00217 
00218   result=fe_info.getId();
00219 
00220   std::cout << "*****************************************" << std::endl;
00221   std::cout << "************SLI done*********************" << std::endl;
00222   std::cout << "*****************************************" << std::endl;
00223   return result;
00224 
00225 }
00226 
00227 int EcalTPGDBApp::writeToConfDB_TPGLUT(const  std::map<EcalLogicID, FEConfigLUTGroupDat> & lutgroupset,
00228                                         const  std::map<EcalLogicID, FEConfigLUTDat> & lutset, 
00229                                        const  std::map<EcalLogicID, FEConfigLUTParamDat> & lutparamset,int iovId, std::string tag) 
00230 {
00231   std::cout << "*****************************************" << std::endl;
00232   std::cout << "************Inserting LUT************" << std::endl;
00233   std::cout << "*****************************************" << std::endl;
00234   int result=0; 
00235 
00236   FEConfigLUTInfo fe_lut_info ;
00237   fe_lut_info.setNumberOfGroups(iovId); 
00238   fe_lut_info.setConfigTag(tag);
00239   insertConfigSet(&fe_lut_info);
00240   
00241   //  Tm tdb = fe_lut_info.getDBTime();
00242   //tdb.dumpTm();
00243   
00244   // Insert the dataset
00245   insertDataArraySet(&lutgroupset, &fe_lut_info);
00246   // Insert the dataset
00247   insertDataArraySet(&lutset, &fe_lut_info);
00248   // insert the parameters
00249   insertDataArraySet(&lutparamset, &fe_lut_info);
00250   
00251   result=fe_lut_info.getId();
00252 
00253   std::cout << "*****************************************" << std::endl;
00254   std::cout << "************LUT done*********************" << std::endl;
00255   std::cout << "*****************************************" << std::endl;
00256   return result;
00257 
00258 }
00259 
00260 int EcalTPGDBApp::writeToConfDB_TPGWeight(const  std::map<EcalLogicID, FEConfigWeightGroupDat> & lutgroupset,
00261                                         const  std::map<EcalLogicID, FEConfigWeightDat> & lutset, int ngr, std::string tag) 
00262 {  
00263   std::cout << "*****************************************" << std::endl;
00264   std::cout << "************Inserting weights************" << std::endl;
00265   std::cout << "*****************************************" << std::endl;
00266   
00267   int result=0; 
00268 
00269   FEConfigWeightInfo fe_wei_info ;
00270   fe_wei_info.setNumberOfGroups(5); // this eventually refers to some other table 
00271   fe_wei_info.setConfigTag(tag);
00272   insertConfigSet(&fe_wei_info);
00273   
00274   //  Tm tdb = fe_lut_info.getDBTime();
00275   //tdb.dumpTm();
00276   
00277   // Insert the dataset
00278   insertDataArraySet(&lutgroupset, &fe_wei_info);
00279   // Insert the dataset
00280   insertDataArraySet(&lutset, &fe_wei_info);
00281   
00282   result=fe_wei_info.getId();
00283 
00284   std::cout << "*****************************************" << std::endl;
00285   std::cout << "************WEIGHT done******************" << std::endl;
00286   std::cout << "*****************************************" << std::endl;
00287   return result;
00288 
00289   
00290 }
00291 
00292 
00293 int EcalTPGDBApp::writeToConfDB_TPGFgr(const  std::map<EcalLogicID, FEConfigFgrGroupDat> & fgrgroupset,
00294                                        const  std::map<EcalLogicID, FEConfigFgrDat> & fgrset,  
00295                                        const  std::map<EcalLogicID, FEConfigFgrParamDat> & fgrparamset,
00296                                        const  std::map<EcalLogicID, FEConfigFgrEETowerDat> & dataset3, 
00297                                        const  std::map<EcalLogicID, FEConfigFgrEEStripDat> & dataset4,
00298                                        int iovId, std::string tag) 
00299 {
00300   std::cout << "*****************************************" << std::endl;
00301   std::cout << "************Inserting Fgr************" << std::endl;
00302   std::cout << "*****************************************" << std::endl;
00303   int result=0; 
00304 
00305   FEConfigFgrInfo fe_fgr_info ;
00306   fe_fgr_info.setNumberOfGroups(iovId); // this eventually refers to some other table 
00307   fe_fgr_info.setConfigTag(tag);
00308   insertConfigSet(&fe_fgr_info);
00309   
00310   //  Tm tdb = fe_fgr_info.getDBTime();
00311   //tdb.dumpTm();
00312   
00313   // Insert the dataset
00314   insertDataArraySet(&fgrgroupset, &fe_fgr_info);
00315   // Insert the dataset
00316   insertDataArraySet(&fgrset, &fe_fgr_info);
00317   // Insert the parameters
00318   insertDataArraySet(&fgrparamset, &fe_fgr_info);
00319   // Insert the parameters
00320   insertDataArraySet(&dataset3, &fe_fgr_info);
00321   // Insert the parameters
00322   insertDataArraySet(&dataset4, &fe_fgr_info);
00323   
00324   result=fe_fgr_info.getId();
00325 
00326   std::cout << "*****************************************" << std::endl;
00327   std::cout << "************Fgr done*********************" << std::endl;
00328   std::cout << "*****************************************" << std::endl;
00329   return result;
00330 
00331 }
00332 
00333 
00334 
00335 void EcalTPGDBApp::printTag( const RunTag* tag) const
00336 {
00337   std::cout << std::endl;
00338   std::cout << "=============RunTag:" << std::endl;
00339   std::cout << "GeneralTag:         " << tag->getGeneralTag() << std::endl;
00340   std::cout << "Location:           " << tag->getLocationDef().getLocation() << std::endl;
00341   std::cout << "Run Type:           " << tag->getRunTypeDef().getRunType() << std::endl;
00342   std::cout << "====================" << std::endl;
00343 }
00344 
00345 void EcalTPGDBApp::printIOV( const RunIOV* iov) const
00346 {
00347   std::cout << std::endl;
00348   std::cout << "=============RunIOV:" << std::endl;
00349   RunTag tag = iov->getRunTag();
00350   printTag(&tag);
00351   std::cout << "Run Number:         " << iov->getRunNumber() << std::endl;
00352   std::cout << "Run Start:          " << iov->getRunStart().str() << std::endl;
00353   std::cout << "Run End:            " << iov->getRunEnd().str() << std::endl;
00354   std::cout << "====================" << std::endl;
00355 }
00356 
00357