CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/L1TriggerConfig/L1ScalesProducers/src/L1MuTriggerScalesOnlineProducer.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   \class L1MuTriggerScalesOnlineProducer
00004 //
00005 //   Description:  A class to produce the L1 mu emulator scales record in the event setup
00006 //                 from the OMDS database.
00007 //
00008 //   $Date: 2010/02/16 21:30:35 $
00009 //   $Revision: 1.2 $
00010 //
00011 //   Author :
00012 //   Thomas Themel
00013 //
00014 //--------------------------------------------------
00015 #include "L1TriggerConfig/L1ScalesProducers/interface/L1MuTriggerScalesOnlineProducer.h"
00016 #include "L1TriggerConfig/L1ScalesProducers/interface/ScaleRecordHelper.h"
00017 #include <cmath>
00018 
00019 using namespace std;
00020 
00021 L1MuTriggerScalesOnlineProducer::L1MuTriggerScalesOnlineProducer(const edm::ParameterSet& ps)
00022   : L1ConfigOnlineProdBase<L1MuTriggerScalesRcd, L1MuTriggerScales>(ps),
00023     m_scales( 
00024               ps.getParameter<int>("nbitPackingDTEta"),
00025               ps.getParameter<bool>("signedPackingDTEta"),
00026               ps.getParameter<int>("nbinsDTEta"),
00027               ps.getParameter<double>("minDTEta"),
00028               ps.getParameter<double>("maxDTEta"),
00029               ps.getParameter<int>("offsetDTEta"),
00030 
00031               ps.getParameter<int>("nbitPackingCSCEta"),
00032               ps.getParameter<int>("nbinsCSCEta"),
00033               ps.getParameter<double>("minCSCEta"),
00034               ps.getParameter<double>("maxCSCEta"),
00035 
00036               ps.getParameter<std::vector<double> >("scaleRPCEta"),
00037               ps.getParameter<int>("nbitPackingBrlRPCEta"),
00038               ps.getParameter<bool>("signedPackingBrlRPCEta"),
00039               ps.getParameter<int>("nbinsBrlRPCEta"),
00040               ps.getParameter<int>("offsetBrlRPCEta"),
00041               ps.getParameter<int>("nbitPackingFwdRPCEta"),
00042               ps.getParameter<bool>("signedPackingFwdRPCEta"),
00043               ps.getParameter<int>("nbinsFwdRPCEta"),
00044               ps.getParameter<int>("offsetFwdRPCEta"),
00045               // Fields that should now be generated from OMDS:
00046               // TODO: Adjust m_scales's definition to be a bit
00047               //       more accessible for the partial initialization.
00048               //ps.getParameter<int>("nbitPackingGMTEta"),
00049               0,
00050               //ps.getParameter<int>("nbinsGMTEta"),
00051               0,
00052               //ps.getParameter<std::vector<double> >("scaleGMTEta"),
00053               std::vector<double>(1),
00054               //ps.getParameter<int>("nbitPackingPhi"),
00055               0,
00056               //ps.getParameter<bool>("signedPackingPhi"),
00057               false,
00058               //ps.getParameter<int>("nbinsPhi"),
00059               0,
00060               //ps.getParameter<double>("minPhi"),
00061               0,
00062               //ps.getParameter<double>("maxPhi") 
00063               0       
00064               ),
00065     /* Metadata that's not yet in the database. */
00066     m_nbitPackingPhi(ps.getParameter<int>("nbitPackingPhi")),
00067     m_nbitPackingEta(ps.getParameter<int>("nbitPackingGMTEta")),
00068     m_nbinsEta(ps.getParameter<int>("nbinsGMTEta")),
00069     m_signedPackingPhi(ps.getParameter<bool>("signedPackingPhi"))
00070 {
00071 }
00072 
00073 L1MuTriggerScalesOnlineProducer::~L1MuTriggerScalesOnlineProducer() {}
00074 
00075 
00076 //
00077 // member functions
00078 //
00079 
00080 class PhiScaleHelper { 
00081   public:
00082   
00083   static L1MuBinnedScale* makeBinnedScale(l1t::OMDSReader::QueryResults& record, int nBits, bool signedPacking) {
00084     short nbins;
00085     record.fillVariable(BinsColumn, nbins);
00086     float lowMark;
00087     record.fillVariable(LowMarkColumn, lowMark);
00088     float step;
00089     record.fillVariable(StepColumn, step);
00090 
00091     return new L1MuBinnedScale(nBits, signedPacking, 
00092                                nbins, deg2rad(lowMark), 
00093                                deg2rad(lowMark + nbins*step));
00094 
00095   }
00096 
00097   static void pushColumnNames(vector<string>& columns) { 
00098     columns.push_back(BinsColumn);
00099     columns.push_back(LowMarkColumn);
00100     columns.push_back(StepColumn);
00101   }
00102 
00103   static double deg2rad(double deg) { return deg*M_PI/180.0; }
00104   static double rad2deg(double rad) { return rad/M_PI*180.0; }
00105 
00106   static const string BinsColumn;
00107   static const string LowMarkColumn;
00108   static const string StepColumn;
00109 };
00110 
00111 const string PhiScaleHelper::BinsColumn = "PHI_BINS";
00112 const string PhiScaleHelper::LowMarkColumn = "PHI_DEG_BIN_LOW_0";
00113 const string PhiScaleHelper::StepColumn = "PHI_DEG_BIN_STEP";
00114 
00115 // ------------ method called to produce the data  ------------
00116 boost::shared_ptr<L1MuTriggerScales> L1MuTriggerScalesOnlineProducer::newObject(const std::string& objectKey ) 
00117 {
00118    using namespace edm::es;   
00119 
00120    // The key we get from the O2O subsystem is the CMS_GMT.L1T_SCALES key,
00121    // but the eta/phi scales have their own subtables, so let's find 
00122    // out.
00123    vector<string> foreignKeys;
00124 
00125    const std::string etaKeyColumn("SC_MUON_ETA_FK");
00126    const std::string phiKeyColumn("SC_MUON_PHI_FK");
00127 
00128    foreignKeys.push_back(etaKeyColumn);
00129    foreignKeys.push_back(phiKeyColumn);
00130 
00131    l1t::OMDSReader::QueryResults keysRecord = 
00132          m_omdsReader.basicQuery(
00133           // SELECTed columns
00134           foreignKeys,
00135           // schema name
00136           "CMS_GT",
00137           // table name
00138           "L1T_SCALES",
00139           // WHERE lhs
00140           "L1T_SCALES.ID",
00141           // WHERE rhs
00142           m_omdsReader.singleAttribute( objectKey  ) );
00143 
00144    if( keysRecord.numberRows() != 1 ) // check if query was successful
00145    {
00146        throw cond::Exception("Problem finding L1MuTriggerScales associated "
00147                              "with scales key `" + objectKey + "'");
00148    }
00149 
00150 
00151    std::string etaKeyValue;
00152    std::string phiKeyValue;
00153    keysRecord.fillVariable(etaKeyColumn, etaKeyValue);
00154    keysRecord.fillVariable(phiKeyColumn, phiKeyValue);
00155 
00156    vector<string> columns;
00157 
00158    // get the eta scales from the database
00159    ScaleRecordHelper etaHelper("ETA_BIN_LOW", m_nbinsEta);
00160    etaHelper.pushColumnNames(columns);
00161 
00162    l1t::OMDSReader::QueryResults etaRecord = 
00163          m_omdsReader.basicQuery(
00164           // SELECTed columns
00165           columns,
00166           // schema name
00167           "CMS_GT",
00168           // table name
00169           "L1T_SCALE_MUON_ETA",
00170           // WHERE lhs
00171           "L1T_SCALE_MUON_ETA.ID",
00172           // WHERE rhs
00173           m_omdsReader.singleAttribute( etaKeyValue  ) );
00174 
00175    vector<double> etaScales;
00176    etaHelper.extractScales(etaRecord, etaScales);
00177    
00178    auto_ptr<L1MuSymmetricBinnedScale> ptrEtaScale(new L1MuSymmetricBinnedScale(m_nbitPackingEta, m_nbinsEta, etaScales));
00179    m_scales.setGMTEtaScale(*ptrEtaScale);
00180 
00181    columns.clear();   
00182 
00183    // get the phi scales from the database
00184    PhiScaleHelper phiHelper;
00185 
00186    l1t::OMDSReader::QueryResults phiRecord = 
00187          m_omdsReader.basicQuery(
00188           // SELECTed columns
00189           columns,
00190           // schema name
00191           "CMS_GT",
00192           // table name
00193           "L1T_SCALE_MUON_PHI",
00194           // WHERE lhs
00195           "L1T_SCALE_MUON_PHI.ID",
00196           // WHERE rhs
00197           m_omdsReader.singleAttribute( phiKeyValue  ) );
00198 
00199    auto_ptr<L1MuBinnedScale> ptrPhiScale(phiHelper.makeBinnedScale(phiRecord, m_nbitPackingPhi, m_signedPackingPhi));
00200 
00201    m_scales.setPhiScale(*ptrPhiScale);
00202 
00203    boost::shared_ptr<L1MuTriggerScales> l1muscale =
00204      boost::shared_ptr<L1MuTriggerScales>( new L1MuTriggerScales( m_scales ) );
00205 
00206    return l1muscale ;
00207 }