CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/CaloOnlineTools/HcalOnlineDb/src/HcalOmdsCalibrations.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Original Author:  Gena Kukartsev Mar 11, 2009
00004 // Adapted from HcalAsciiCalibrations
00005 // $Id: HcalOmdsCalibrations.cc,v 1.14 2012/11/12 20:49:45 dlange Exp $
00006 //
00007 
00008 #include <memory>
00009 #include <iostream>
00010 #include <fstream>
00011 
00012 #include "FWCore/Utilities/interface/Exception.h"
00013 #include "FWCore/ParameterSet/interface/FileInPath.h"
00014 
00015 #include "FWCore/Framework/interface/ValidityInterval.h"
00016 #include "FWCore/Framework/interface/ESHandle.h"
00017 
00018 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalDbOmds.h"
00019 
00020 #include "CondFormats/DataRecord/interface/HcalPedestalsRcd.h"
00021 #include "CondFormats/DataRecord/interface/HcalPedestalWidthsRcd.h"
00022 #include "CondFormats/DataRecord/interface/HcalGainsRcd.h"
00023 #include "CondFormats/DataRecord/interface/HcalGainWidthsRcd.h"
00024 #include "CondFormats/DataRecord/interface/HcalElectronicsMapRcd.h"
00025 #include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
00026 #include "CondFormats/DataRecord/interface/HcalQIEDataRcd.h"
00027 #include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h"
00028 #include "CondFormats/DataRecord/interface/HcalZSThresholdsRcd.h"
00029 #include "CondFormats/DataRecord/interface/HcalL1TriggerObjectsRcd.h"
00030 #include "CondFormats/DataRecord/interface/HcalValidationCorrsRcd.h"
00031 #include "CondFormats/DataRecord/interface/HcalLutMetadataRcd.h"
00032 #include "CondFormats/DataRecord/interface/HcalDcsRcd.h"
00033 
00034 #include "CaloOnlineTools/HcalOnlineDb/interface/HCALConfigDB.h"
00035 
00036 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalOmdsCalibrations.h"
00037 //
00038 // class decleration
00039 //
00040 
00041 using namespace cms;
00042 
00043 HcalOmdsCalibrations::HcalOmdsCalibrations ( const edm::ParameterSet& iConfig ) 
00044   
00045 {
00046   //parsing parameters
00047   std::vector<edm::ParameterSet> data = iConfig.getParameter<std::vector<edm::ParameterSet> >("input");
00048   std::vector<edm::ParameterSet>::iterator request = data.begin ();
00049   for (; request != data.end (); request++) {
00050     std::string objectName = request->getParameter<std::string> ("object");
00051 
00052     if (request->exists("version")) mVersion[objectName] = request->getParameter<std::string>("version");
00053     if (request->exists("subversion")) mSubversion[objectName] = request->getParameter<int>("subversion");
00054     if (request->exists("iov_begin")) mIOVBegin[objectName] = request->getParameter<int>("iov_begin");
00055     if (request->exists("accessor")) mAccessor[objectName] = request->getParameter<std::string>("accessor");
00056     if (request->exists("query")) mQuery[objectName] = request->getParameter<std::string>("query");
00057 
00058     mInputs [objectName] = request->getParameter<std::string>("tag");
00059     if (objectName == "Pedestals") {
00060       setWhatProduced (this, &HcalOmdsCalibrations::producePedestals);
00061       findingRecord <HcalPedestalsRcd> ();
00062     }
00063     else if (objectName == "PedestalWidths") {
00064       setWhatProduced (this, &HcalOmdsCalibrations::producePedestalWidths);
00065       findingRecord <HcalPedestalWidthsRcd> ();
00066     }
00067     else if (objectName == "Gains") {
00068       setWhatProduced (this, &HcalOmdsCalibrations::produceGains);
00069       findingRecord <HcalGainsRcd> ();
00070     }
00071     else if (objectName == "GainWidths") {
00072       setWhatProduced (this, &HcalOmdsCalibrations::produceGainWidths);
00073       findingRecord <HcalGainWidthsRcd> ();
00074     }
00075     else if (objectName == "QIEData") {
00076       setWhatProduced (this, &HcalOmdsCalibrations::produceQIEData);
00077       findingRecord <HcalQIEDataRcd> ();
00078     }
00079     else if (objectName == "ChannelQuality") {
00080       setWhatProduced (this, &HcalOmdsCalibrations::produceChannelQuality);
00081       findingRecord <HcalChannelQualityRcd> ();
00082     }
00083     else if (objectName == "ZSThresholds") {
00084       setWhatProduced (this, &HcalOmdsCalibrations::produceZSThresholds);
00085       findingRecord <HcalZSThresholdsRcd> ();
00086     }
00087     else if (objectName == "RespCorrs") {
00088       setWhatProduced (this, &HcalOmdsCalibrations::produceRespCorrs);
00089       findingRecord <HcalRespCorrsRcd> ();
00090     }
00091     else if (objectName == "L1TriggerObjects") {
00092       setWhatProduced (this, &HcalOmdsCalibrations::produceL1TriggerObjects);
00093       findingRecord <HcalL1TriggerObjectsRcd> ();
00094     }
00095     else if (objectName == "ElectronicsMap") {
00096       setWhatProduced (this, &HcalOmdsCalibrations::produceElectronicsMap);
00097       findingRecord <HcalElectronicsMapRcd> ();
00098     }
00099     else if (objectName == "ValidationCorrs") {
00100       setWhatProduced (this, &HcalOmdsCalibrations::produceValidationCorrs);
00101       findingRecord <HcalValidationCorrsRcd> ();
00102     }
00103     else if (objectName == "LutMetadata") {
00104       setWhatProduced (this, &HcalOmdsCalibrations::produceLutMetadata);
00105       findingRecord <HcalLutMetadataRcd> ();
00106     }
00107     else if (objectName == "DcsValues") {
00108       setWhatProduced (this, &HcalOmdsCalibrations::produceDcsValues);
00109       findingRecord <HcalDcsRcd> ();
00110     }
00111     else {
00112       std::cerr << "HcalOmdsCalibrations-> Unknown object name '" << objectName 
00113                 << "', known names are: "
00114                 << "Pedestals PedestalWidths Gains GainWidths QIEData ChannelQuality ElectronicsMap "
00115                 << "ZSThresholds RespCorrs L1TriggerObjects ValidationCorrs LutMetadata DcsValues "
00116                 << std::endl;
00117     }
00118   }
00119   //  setWhatProduced(this);
00120 }
00121 
00122 
00123 HcalOmdsCalibrations::~HcalOmdsCalibrations()
00124 {
00125 }
00126 
00127 
00128 //
00129 // member functions
00130 //
00131 void 
00132 HcalOmdsCalibrations::setIntervalFor( const edm::eventsetup::EventSetupRecordKey& iKey, const edm::IOVSyncValue& iTime, edm::ValidityInterval& oInterval ) {
00133   std::string record = iKey.name ();
00134   oInterval = edm::ValidityInterval (edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime()); //infinite
00135 }
00136 
00137 // FIXME: put this into the HcalDbOmds namespace
00138 //const static std::string omds_occi_default_accessor = "occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22";
00139 const static std::string omds_occi_default_accessor = "occi://CMS_HCL_APPUSER_R@anyhost/cms_omds_lb?PASSWORD=HCAL_Reader_44,LHWM_VERSION=22";
00140 const static std::string default_version = "";
00141 const static std::string default_query = "";
00142 
00143 template <class T>
00144 std::auto_ptr<T> produce_impl (const HcalTopology* topo,
00145                                const std::string & fTag, 
00146                                const std::string & fVersion=default_version, 
00147                                const int fSubversion=1, 
00148                                const int fIOVBegin=1,
00149                                const std::string & fQuery = default_query, 
00150                                const std::string& fAccessor = omds_occi_default_accessor ) {
00151   std::auto_ptr<T> result (new T (topo));
00152 
00153   HCALConfigDB * db = new HCALConfigDB();
00154   try {
00155     db -> connect( fAccessor );
00156   } catch (hcal::exception::ConfigurationDatabaseException & e) {
00157     std::cerr << "Cannot connect to the database" << std::endl;
00158   }
00159   oracle::occi::Connection * _connection = db -> getConnection();
00160   if (_connection){
00161     if (!HcalDbOmds::getObject (_connection, fTag, fVersion, fSubversion, fIOVBegin, fQuery, &*result)) {
00162       std::cerr << "HcalOmdsCalibrations-> Can not read tag name '" << fTag << "' from database '" << fAccessor << "'" << std::endl;
00163       throw cms::Exception("ReadError") << "Can not read tag name '" << fTag << "' from database '" << fAccessor << "'" << std::endl;
00164     }
00165   }
00166   else{
00167     std::cerr << "Database connection is null. This should NEVER happen here. Something fishy is going on..." << std::endl;
00168   }
00169   return result;
00170 }
00171 template <class T>
00172 std::auto_ptr<T> produce_impl (const std::string & fTag, 
00173                                const std::string & fVersion=default_version, 
00174                                const int fSubversion=1, 
00175                                const int fIOVBegin=1,
00176                                const std::string & fQuery = default_query, 
00177                                const std::string& fAccessor = omds_occi_default_accessor ) {
00178   std::auto_ptr<T> result (new T ());
00179 
00180   HCALConfigDB * db = new HCALConfigDB();
00181   try {
00182     db -> connect( fAccessor );
00183   } catch (hcal::exception::ConfigurationDatabaseException & e) {
00184     std::cerr << "Cannot connect to the database" << std::endl;
00185   }
00186   oracle::occi::Connection * _connection = db -> getConnection();
00187   if (_connection){
00188     if (!HcalDbOmds::getObject (_connection, fTag, fVersion, fSubversion, fIOVBegin, fQuery, &*result)) {
00189       std::cerr << "HcalOmdsCalibrations-> Can not read tag name '" << fTag << "' from database '" << fAccessor << "'" << std::endl;
00190       throw cms::Exception("ReadError") << "Can not read tag name '" << fTag << "' from database '" << fAccessor << "'" << std::endl;
00191     }
00192   }
00193   else{
00194     std::cerr << "Database connection is null. This should NEVER happen here. Something fishy is going on..." << std::endl;
00195   }
00196   return result;
00197 }
00198 
00199 
00200 
00201 std::auto_ptr<HcalPedestals> HcalOmdsCalibrations::producePedestals (const HcalPedestalsRcd& rcd) {
00202   edm::ESHandle<HcalTopology> htopo;
00203   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00204   const HcalTopology* topo=&(*htopo);
00205 
00206   return produce_impl<HcalPedestals> (topo, mInputs ["Pedestals"],
00207                                       mVersion["Pedestals"], 
00208                                       mSubversion["Pedestals"], 
00209                                       mIOVBegin["Pedestals"], 
00210                                       mQuery["Pedestals"], 
00211                                       mAccessor["Pedestals"]);
00212 }
00213 
00214 std::auto_ptr<HcalPedestalWidths> HcalOmdsCalibrations::producePedestalWidths (const HcalPedestalWidthsRcd& rcd) {
00215   edm::ESHandle<HcalTopology> htopo;
00216   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00217   const HcalTopology* topo=&(*htopo);
00218   return produce_impl<HcalPedestalWidths> (topo, mInputs ["PedestalWidths"], 
00219                                            mVersion["PedestalWidths"], 
00220                                            mSubversion["PedestalWidths"], 
00221                                            mIOVBegin["PedestalWidths"], 
00222                                            mQuery["PedestalWidths"], 
00223                                            mAccessor["PedestalWidths"]);
00224 }
00225 
00226 std::auto_ptr<HcalGains> HcalOmdsCalibrations::produceGains (const HcalGainsRcd& rcd) {
00227   edm::ESHandle<HcalTopology> htopo;
00228   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00229   const HcalTopology* topo=&(*htopo);
00230   return produce_impl<HcalGains> (topo, mInputs ["Gains"], 
00231                                   mVersion["Gains"], 
00232                                   mSubversion["Gains"], 
00233                                   mIOVBegin["Gains"], 
00234                                   mQuery["Gains"], 
00235                                   mAccessor["Gains"]);
00236 }
00237 
00238 std::auto_ptr<HcalGainWidths> HcalOmdsCalibrations::produceGainWidths (const HcalGainWidthsRcd& rcd) {
00239   edm::ESHandle<HcalTopology> htopo;
00240   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00241   const HcalTopology* topo=&(*htopo);
00242   return produce_impl<HcalGainWidths> (topo, mInputs ["GainWidths"], 
00243                                        mVersion["GainWidths"], 
00244                                        mSubversion["GainWidths"], 
00245                                        mIOVBegin["GainWidths"], 
00246                                        mQuery["GainWidths"], 
00247                                        mAccessor["GainWidths"]);
00248 }
00249 
00250 std::auto_ptr<HcalQIEData> HcalOmdsCalibrations::produceQIEData (const HcalQIEDataRcd& rcd) {
00251   edm::ESHandle<HcalTopology> htopo;
00252   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00253   const HcalTopology* topo=&(*htopo);
00254   return produce_impl<HcalQIEData> (topo, mInputs ["QIEData"], 
00255                                     mVersion["QIEData"], 
00256                                     mSubversion["QIEData"], 
00257                                     mIOVBegin["QIEData"], 
00258                                     mQuery["QIEData"], 
00259                                     mAccessor["QIEData"]);
00260 }
00261 
00262 std::auto_ptr<HcalChannelQuality> HcalOmdsCalibrations::produceChannelQuality (const HcalChannelQualityRcd& rcd) {
00263   edm::ESHandle<HcalTopology> htopo;
00264   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00265   const HcalTopology* topo=&(*htopo);
00266   return produce_impl<HcalChannelQuality> (topo, mInputs ["ChannelQuality"], 
00267                                            mVersion["ChannelQuality"], 
00268                                            mSubversion["ChannelQuality"], 
00269                                            mIOVBegin["ChannelQuality"], 
00270                                            mQuery["ChannelQuality"], 
00271                                            mAccessor["ChannelQuality"]);
00272 }
00273 
00274 std::auto_ptr<HcalZSThresholds> HcalOmdsCalibrations::produceZSThresholds (const HcalZSThresholdsRcd& rcd) {
00275   edm::ESHandle<HcalTopology> htopo;
00276   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00277   const HcalTopology* topo=&(*htopo);
00278   return produce_impl<HcalZSThresholds> (topo, mInputs ["ZSThresholds"], 
00279                                          mVersion["ZSThresholds"], 
00280                                          mSubversion["ZSThresholds"], 
00281                                          mIOVBegin["ZSThresholds"], 
00282                                          mQuery["ZSThresholds"], 
00283                                          mAccessor["ZSThresholds"]);
00284 }
00285 
00286 std::auto_ptr<HcalRespCorrs> HcalOmdsCalibrations::produceRespCorrs (const HcalRespCorrsRcd& rcd) {
00287   edm::ESHandle<HcalTopology> htopo;
00288   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00289   const HcalTopology* topo=&(*htopo);
00290   return produce_impl<HcalRespCorrs> (topo, mInputs ["RespCorrs"], 
00291                                       mVersion["RespCorrs"], 
00292                                       mSubversion["RespCorrs"], 
00293                                       mIOVBegin["RespCorrs"], 
00294                                       mQuery["RespCorrs"], 
00295                                       mAccessor["RespCorrs"]);
00296 }
00297 
00298 std::auto_ptr<HcalL1TriggerObjects> HcalOmdsCalibrations::produceL1TriggerObjects (const HcalL1TriggerObjectsRcd& rcd) {
00299   edm::ESHandle<HcalTopology> htopo;
00300   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00301   const HcalTopology* topo=&(*htopo);
00302   return produce_impl<HcalL1TriggerObjects> (topo, mInputs ["L1TriggerObjects"], 
00303                                              mVersion["L1TriggerObjects"], 
00304                                              mSubversion["L1TriggerObjects"], 
00305                                              mIOVBegin["L1TriggerObjects"], 
00306                                              mQuery["L1TriggerObjects"], 
00307                                              mAccessor["L1TriggerObjects"]);
00308 }
00309 
00310 std::auto_ptr<HcalElectronicsMap> HcalOmdsCalibrations::produceElectronicsMap (const HcalElectronicsMapRcd& rcd) {
00311   return produce_impl<HcalElectronicsMap> (mInputs ["ElectronicsMap"], 
00312                                            mVersion["ElectronicsMap"], 
00313                                            mSubversion["ElectronicsMap"], 
00314                                            mIOVBegin["ElectronicsMap"], 
00315                                            mQuery["ElectronicsMap"], 
00316                                            mAccessor["ElectronicsMap"]);
00317 }
00318 
00319 std::auto_ptr<HcalValidationCorrs> HcalOmdsCalibrations::produceValidationCorrs (const HcalValidationCorrsRcd& rcd) {
00320   edm::ESHandle<HcalTopology> htopo;
00321   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00322   const HcalTopology* topo=&(*htopo);
00323   return produce_impl<HcalValidationCorrs> (topo, mInputs ["ValidationCorrs"], 
00324                                             mVersion["ValidationCorrs"], 
00325                                             mSubversion["ValidationCorrs"], 
00326                                             mIOVBegin["ValidationCorrs"], 
00327                                             mQuery["ValidationCorrs"], 
00328                                             mAccessor["ValidationCorrs"]);
00329 }
00330 
00331 std::auto_ptr<HcalLutMetadata> HcalOmdsCalibrations::produceLutMetadata (const HcalLutMetadataRcd& rcd) {
00332   edm::ESHandle<HcalTopology> htopo;
00333   rcd.getRecord<IdealGeometryRecord>().get(htopo);
00334   const HcalTopology* topo=&(*htopo);
00335   return produce_impl<HcalLutMetadata> (topo, mInputs ["LutMetadata"], 
00336                                         mVersion["LutMetadata"], 
00337                                         mSubversion["LutMetadata"], 
00338                                         mIOVBegin["LutMetadata"], 
00339                                         mQuery["LutMetadata"], 
00340                                         mAccessor["LutMetadata"]);
00341 }
00342 
00343 std::auto_ptr<HcalDcsValues> HcalOmdsCalibrations::produceDcsValues (const HcalDcsRcd& rcd) {
00344   return produce_impl<HcalDcsValues> (mInputs ["DcsValues"], 
00345                                         mVersion["DcsValues"], 
00346                                         mSubversion["DcsValues"], 
00347                                         mIOVBegin["DcsValues"], 
00348                                         mQuery["DcsValues"], 
00349                                         mAccessor["DcsValues"]);
00350 }
00351