CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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.13 2010/08/06 20:24:13 wmtan 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 
00017 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalDbOmds.h"
00018 
00019 #include "CondFormats/DataRecord/interface/HcalPedestalsRcd.h"
00020 #include "CondFormats/DataRecord/interface/HcalPedestalWidthsRcd.h"
00021 #include "CondFormats/DataRecord/interface/HcalGainsRcd.h"
00022 #include "CondFormats/DataRecord/interface/HcalGainWidthsRcd.h"
00023 #include "CondFormats/DataRecord/interface/HcalElectronicsMapRcd.h"
00024 #include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
00025 #include "CondFormats/DataRecord/interface/HcalQIEDataRcd.h"
00026 #include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h"
00027 #include "CondFormats/DataRecord/interface/HcalZSThresholdsRcd.h"
00028 #include "CondFormats/DataRecord/interface/HcalL1TriggerObjectsRcd.h"
00029 #include "CondFormats/DataRecord/interface/HcalValidationCorrsRcd.h"
00030 #include "CondFormats/DataRecord/interface/HcalLutMetadataRcd.h"
00031 #include "CondFormats/DataRecord/interface/HcalDcsRcd.h"
00032 
00033 #include "CaloOnlineTools/HcalOnlineDb/interface/HCALConfigDB.h"
00034 
00035 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalOmdsCalibrations.h"
00036 //
00037 // class decleration
00038 //
00039 
00040 using namespace cms;
00041 
00042 HcalOmdsCalibrations::HcalOmdsCalibrations ( const edm::ParameterSet& iConfig ) 
00043   
00044 {
00045   //parsing parameters
00046   std::vector<edm::ParameterSet> data = iConfig.getParameter<std::vector<edm::ParameterSet> >("input");
00047   std::vector<edm::ParameterSet>::iterator request = data.begin ();
00048   for (; request != data.end (); request++) {
00049     std::string objectName = request->getParameter<std::string> ("object");
00050 
00051     if (request->exists("version")) mVersion[objectName] = request->getParameter<std::string>("version");
00052     if (request->exists("subversion")) mSubversion[objectName] = request->getParameter<int>("subversion");
00053     if (request->exists("iov_begin")) mIOVBegin[objectName] = request->getParameter<int>("iov_begin");
00054     if (request->exists("accessor")) mAccessor[objectName] = request->getParameter<std::string>("accessor");
00055     if (request->exists("query")) mQuery[objectName] = request->getParameter<std::string>("query");
00056 
00057     mInputs [objectName] = request->getParameter<std::string>("tag");
00058     if (objectName == "Pedestals") {
00059       setWhatProduced (this, &HcalOmdsCalibrations::producePedestals);
00060       findingRecord <HcalPedestalsRcd> ();
00061     }
00062     else if (objectName == "PedestalWidths") {
00063       setWhatProduced (this, &HcalOmdsCalibrations::producePedestalWidths);
00064       findingRecord <HcalPedestalWidthsRcd> ();
00065     }
00066     else if (objectName == "Gains") {
00067       setWhatProduced (this, &HcalOmdsCalibrations::produceGains);
00068       findingRecord <HcalGainsRcd> ();
00069     }
00070     else if (objectName == "GainWidths") {
00071       setWhatProduced (this, &HcalOmdsCalibrations::produceGainWidths);
00072       findingRecord <HcalGainWidthsRcd> ();
00073     }
00074     else if (objectName == "QIEData") {
00075       setWhatProduced (this, &HcalOmdsCalibrations::produceQIEData);
00076       findingRecord <HcalQIEDataRcd> ();
00077     }
00078     else if (objectName == "ChannelQuality") {
00079       setWhatProduced (this, &HcalOmdsCalibrations::produceChannelQuality);
00080       findingRecord <HcalChannelQualityRcd> ();
00081     }
00082     else if (objectName == "ZSThresholds") {
00083       setWhatProduced (this, &HcalOmdsCalibrations::produceZSThresholds);
00084       findingRecord <HcalZSThresholdsRcd> ();
00085     }
00086     else if (objectName == "RespCorrs") {
00087       setWhatProduced (this, &HcalOmdsCalibrations::produceRespCorrs);
00088       findingRecord <HcalRespCorrsRcd> ();
00089     }
00090     else if (objectName == "L1TriggerObjects") {
00091       setWhatProduced (this, &HcalOmdsCalibrations::produceL1TriggerObjects);
00092       findingRecord <HcalL1TriggerObjectsRcd> ();
00093     }
00094     else if (objectName == "ElectronicsMap") {
00095       setWhatProduced (this, &HcalOmdsCalibrations::produceElectronicsMap);
00096       findingRecord <HcalElectronicsMapRcd> ();
00097     }
00098     else if (objectName == "ValidationCorrs") {
00099       setWhatProduced (this, &HcalOmdsCalibrations::produceValidationCorrs);
00100       findingRecord <HcalValidationCorrsRcd> ();
00101     }
00102     else if (objectName == "LutMetadata") {
00103       setWhatProduced (this, &HcalOmdsCalibrations::produceLutMetadata);
00104       findingRecord <HcalLutMetadataRcd> ();
00105     }
00106     else if (objectName == "DcsValues") {
00107       setWhatProduced (this, &HcalOmdsCalibrations::produceDcsValues);
00108       findingRecord <HcalDcsRcd> ();
00109     }
00110     else {
00111       std::cerr << "HcalOmdsCalibrations-> Unknown object name '" << objectName 
00112                 << "', known names are: "
00113                 << "Pedestals PedestalWidths Gains GainWidths QIEData ChannelQuality ElectronicsMap "
00114                 << "ZSThresholds RespCorrs L1TriggerObjects ValidationCorrs LutMetadata DcsValues "
00115                 << std::endl;
00116     }
00117   }
00118   //  setWhatProduced(this);
00119 }
00120 
00121 
00122 HcalOmdsCalibrations::~HcalOmdsCalibrations()
00123 {
00124 }
00125 
00126 
00127 //
00128 // member functions
00129 //
00130 void 
00131 HcalOmdsCalibrations::setIntervalFor( const edm::eventsetup::EventSetupRecordKey& iKey, const edm::IOVSyncValue& iTime, edm::ValidityInterval& oInterval ) {
00132   std::string record = iKey.name ();
00133   oInterval = edm::ValidityInterval (edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime()); //infinite
00134 }
00135 
00136 // FIXME: put this into the HcalDbOmds namespace
00137 //const static std::string omds_occi_default_accessor = "occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22";
00138 const static std::string omds_occi_default_accessor = "occi://CMS_HCL_APPUSER_R@anyhost/cms_omds_lb?PASSWORD=HCAL_Reader_44,LHWM_VERSION=22";
00139 const static std::string default_version = "";
00140 const static std::string default_query = "";
00141 
00142 template <class T>
00143 std::auto_ptr<T> produce_impl (const std::string & fTag, 
00144                                const std::string & fVersion=default_version, 
00145                                const int fSubversion=1, 
00146                                const int fIOVBegin=1,
00147                                const std::string & fQuery = default_query, 
00148                                const std::string& fAccessor = omds_occi_default_accessor ) {
00149   std::auto_ptr<T> result (new T ());
00150 
00151   HCALConfigDB * db = new HCALConfigDB();
00152   try {
00153     db -> connect( fAccessor );
00154   } catch (hcal::exception::ConfigurationDatabaseException & e) {
00155     std::cerr << "Cannot connect to the database" << std::endl;
00156   }
00157   oracle::occi::Connection * _connection = db -> getConnection();
00158   if (_connection){
00159     if (!HcalDbOmds::getObject (_connection, fTag, fVersion, fSubversion, fIOVBegin, fQuery, &*result)) {
00160       std::cerr << "HcalOmdsCalibrations-> Can not read tag name '" << fTag << "' from database '" << fAccessor << "'" << std::endl;
00161       throw cms::Exception("ReadError") << "Can not read tag name '" << fTag << "' from database '" << fAccessor << "'" << std::endl;
00162     }
00163   }
00164   else{
00165     std::cerr << "Database connection is null. This should NEVER happen here. Something fishy is going on..." << std::endl;
00166   }
00167   return result;
00168 }
00169 
00170 
00171 
00172 std::auto_ptr<HcalPedestals> HcalOmdsCalibrations::producePedestals (const HcalPedestalsRcd&) {
00173   return produce_impl<HcalPedestals> (mInputs ["Pedestals"],
00174                                       mVersion["Pedestals"], 
00175                                       mSubversion["Pedestals"], 
00176                                       mIOVBegin["Pedestals"], 
00177                                       mQuery["Pedestals"], 
00178                                       mAccessor["Pedestals"]);
00179 }
00180 
00181 std::auto_ptr<HcalPedestalWidths> HcalOmdsCalibrations::producePedestalWidths (const HcalPedestalWidthsRcd&) {
00182   return produce_impl<HcalPedestalWidths> (mInputs ["PedestalWidths"], 
00183                                            mVersion["PedestalWidths"], 
00184                                            mSubversion["PedestalWidths"], 
00185                                            mIOVBegin["PedestalWidths"], 
00186                                            mQuery["PedestalWidths"], 
00187                                            mAccessor["PedestalWidths"]);
00188 }
00189 
00190 std::auto_ptr<HcalGains> HcalOmdsCalibrations::produceGains (const HcalGainsRcd&) {
00191   return produce_impl<HcalGains> (mInputs ["Gains"], 
00192                                   mVersion["Gains"], 
00193                                   mSubversion["Gains"], 
00194                                   mIOVBegin["Gains"], 
00195                                   mQuery["Gains"], 
00196                                   mAccessor["Gains"]);
00197 }
00198 
00199 std::auto_ptr<HcalGainWidths> HcalOmdsCalibrations::produceGainWidths (const HcalGainWidthsRcd&) {
00200   return produce_impl<HcalGainWidths> (mInputs ["GainWidths"], 
00201                                        mVersion["GainWidths"], 
00202                                        mSubversion["GainWidths"], 
00203                                        mIOVBegin["GainWidths"], 
00204                                        mQuery["GainWidths"], 
00205                                        mAccessor["GainWidths"]);
00206 }
00207 
00208 std::auto_ptr<HcalQIEData> HcalOmdsCalibrations::produceQIEData (const HcalQIEDataRcd& rcd) {
00209   return produce_impl<HcalQIEData> (mInputs ["QIEData"], 
00210                                     mVersion["QIEData"], 
00211                                     mSubversion["QIEData"], 
00212                                     mIOVBegin["QIEData"], 
00213                                     mQuery["QIEData"], 
00214                                     mAccessor["QIEData"]);
00215 }
00216 
00217 std::auto_ptr<HcalChannelQuality> HcalOmdsCalibrations::produceChannelQuality (const HcalChannelQualityRcd& rcd) {
00218   return produce_impl<HcalChannelQuality> (mInputs ["ChannelQuality"], 
00219                                            mVersion["ChannelQuality"], 
00220                                            mSubversion["ChannelQuality"], 
00221                                            mIOVBegin["ChannelQuality"], 
00222                                            mQuery["ChannelQuality"], 
00223                                            mAccessor["ChannelQuality"]);
00224 }
00225 
00226 std::auto_ptr<HcalZSThresholds> HcalOmdsCalibrations::produceZSThresholds (const HcalZSThresholdsRcd& rcd) {
00227   return produce_impl<HcalZSThresholds> (mInputs ["ZSThresholds"], 
00228                                          mVersion["ZSThresholds"], 
00229                                          mSubversion["ZSThresholds"], 
00230                                          mIOVBegin["ZSThresholds"], 
00231                                          mQuery["ZSThresholds"], 
00232                                          mAccessor["ZSThresholds"]);
00233 }
00234 
00235 std::auto_ptr<HcalRespCorrs> HcalOmdsCalibrations::produceRespCorrs (const HcalRespCorrsRcd& rcd) {
00236   return produce_impl<HcalRespCorrs> (mInputs ["RespCorrs"], 
00237                                       mVersion["RespCorrs"], 
00238                                       mSubversion["RespCorrs"], 
00239                                       mIOVBegin["RespCorrs"], 
00240                                       mQuery["RespCorrs"], 
00241                                       mAccessor["RespCorrs"]);
00242 }
00243 
00244 std::auto_ptr<HcalL1TriggerObjects> HcalOmdsCalibrations::produceL1TriggerObjects (const HcalL1TriggerObjectsRcd& rcd) {
00245   return produce_impl<HcalL1TriggerObjects> (mInputs ["L1TriggerObjects"], 
00246                                              mVersion["L1TriggerObjects"], 
00247                                              mSubversion["L1TriggerObjects"], 
00248                                              mIOVBegin["L1TriggerObjects"], 
00249                                              mQuery["L1TriggerObjects"], 
00250                                              mAccessor["L1TriggerObjects"]);
00251 }
00252 
00253 std::auto_ptr<HcalElectronicsMap> HcalOmdsCalibrations::produceElectronicsMap (const HcalElectronicsMapRcd& rcd) {
00254   return produce_impl<HcalElectronicsMap> (mInputs ["ElectronicsMap"], 
00255                                            mVersion["ElectronicsMap"], 
00256                                            mSubversion["ElectronicsMap"], 
00257                                            mIOVBegin["ElectronicsMap"], 
00258                                            mQuery["ElectronicsMap"], 
00259                                            mAccessor["ElectronicsMap"]);
00260 }
00261 
00262 std::auto_ptr<HcalValidationCorrs> HcalOmdsCalibrations::produceValidationCorrs (const HcalValidationCorrsRcd& rcd) {
00263   return produce_impl<HcalValidationCorrs> (mInputs ["ValidationCorrs"], 
00264                                             mVersion["ValidationCorrs"], 
00265                                             mSubversion["ValidationCorrs"], 
00266                                             mIOVBegin["ValidationCorrs"], 
00267                                             mQuery["ValidationCorrs"], 
00268                                             mAccessor["ValidationCorrs"]);
00269 }
00270 
00271 std::auto_ptr<HcalLutMetadata> HcalOmdsCalibrations::produceLutMetadata (const HcalLutMetadataRcd& rcd) {
00272   return produce_impl<HcalLutMetadata> (mInputs ["LutMetadata"], 
00273                                         mVersion["LutMetadata"], 
00274                                         mSubversion["LutMetadata"], 
00275                                         mIOVBegin["LutMetadata"], 
00276                                         mQuery["LutMetadata"], 
00277                                         mAccessor["LutMetadata"]);
00278 }
00279 
00280 std::auto_ptr<HcalDcsValues> HcalOmdsCalibrations::produceDcsValues (const HcalDcsRcd& rcd) {
00281   return produce_impl<HcalDcsValues> (mInputs ["DcsValues"], 
00282                                         mVersion["DcsValues"], 
00283                                         mSubversion["DcsValues"], 
00284                                         mIOVBegin["DcsValues"], 
00285                                         mQuery["DcsValues"], 
00286                                         mAccessor["DcsValues"]);
00287 }
00288