CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1MuTriggerScalesOnlineProducer.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // \class L1MuTriggerScalesOnlineProducer
4 //
5 // Description: A class to produce the L1 mu emulator scales record in the event setup
6 // from the OMDS database.
7 //
8 //
9 // Author :
10 // Thomas Themel
11 //
12 //--------------------------------------------------
15 #include <cmath>
16 
17 using namespace std;
18 
21  m_scales(ps.getParameter<int>("nbitPackingDTEta"),
22  ps.getParameter<bool>("signedPackingDTEta"),
23  ps.getParameter<int>("nbinsDTEta"),
24  ps.getParameter<double>("minDTEta"),
25  ps.getParameter<double>("maxDTEta"),
26  ps.getParameter<int>("offsetDTEta"),
27 
28  ps.getParameter<int>("nbitPackingCSCEta"),
29  ps.getParameter<int>("nbinsCSCEta"),
30  ps.getParameter<double>("minCSCEta"),
31  ps.getParameter<double>("maxCSCEta"),
32 
33  ps.getParameter<std::vector<double> >("scaleRPCEta"),
34  ps.getParameter<int>("nbitPackingBrlRPCEta"),
35  ps.getParameter<bool>("signedPackingBrlRPCEta"),
36  ps.getParameter<int>("nbinsBrlRPCEta"),
37  ps.getParameter<int>("offsetBrlRPCEta"),
38  ps.getParameter<int>("nbitPackingFwdRPCEta"),
39  ps.getParameter<bool>("signedPackingFwdRPCEta"),
40  ps.getParameter<int>("nbinsFwdRPCEta"),
41  ps.getParameter<int>("offsetFwdRPCEta"),
42  // Fields that should now be generated from OMDS:
43  // TODO: Adjust m_scales's definition to be a bit
44  // more accessible for the partial initialization.
45  //ps.getParameter<int>("nbitPackingGMTEta"),
46  0,
47  //ps.getParameter<int>("nbinsGMTEta"),
48  0,
49  //ps.getParameter<std::vector<double> >("scaleGMTEta"),
50  std::vector<double>(1),
51  //ps.getParameter<int>("nbitPackingPhi"),
52  0,
53  //ps.getParameter<bool>("signedPackingPhi"),
54  false,
55  //ps.getParameter<int>("nbinsPhi"),
56  0,
57  //ps.getParameter<double>("minPhi"),
58  0,
59  //ps.getParameter<double>("maxPhi")
60  0),
61  /* Metadata that's not yet in the database. */
62  m_nbitPackingPhi(ps.getParameter<int>("nbitPackingPhi")),
63  m_nbitPackingEta(ps.getParameter<int>("nbitPackingGMTEta")),
64  m_nbinsEta(ps.getParameter<int>("nbinsGMTEta")),
65  m_signedPackingPhi(ps.getParameter<bool>("signedPackingPhi")) {}
66 
68 
69 //
70 // member functions
71 //
72 
74 public:
75  static L1MuBinnedScale* makeBinnedScale(l1t::OMDSReader::QueryResults& record, int nBits, bool signedPacking) {
76  short nbins = 0;
77  record.fillVariable(BinsColumn, nbins);
78  float lowMark = 0.;
79  record.fillVariable(LowMarkColumn, lowMark);
80  float step = 0.;
81  record.fillVariable(StepColumn, step);
82 
83  return new L1MuBinnedScale(nBits, signedPacking, nbins, deg2rad(lowMark), deg2rad(lowMark + nbins * step));
84  }
85 
86  static void pushColumnNames(vector<string>& columns) {
87  columns.push_back(BinsColumn);
88  columns.push_back(LowMarkColumn);
89  columns.push_back(StepColumn);
90  }
91 
92  static double deg2rad(double deg) { return deg * M_PI / 180.0; }
93  static double rad2deg(double rad) { return rad / M_PI * 180.0; }
94 
95  static const string BinsColumn;
96  static const string LowMarkColumn;
97  static const string StepColumn;
98 };
99 
100 const string PhiScaleHelper::BinsColumn = "PHI_BINS";
101 const string PhiScaleHelper::LowMarkColumn = "PHI_DEG_BIN_LOW_0";
102 const string PhiScaleHelper::StepColumn = "PHI_DEG_BIN_STEP";
103 
104 // ------------ method called to produce the data ------------
105 std::unique_ptr<L1MuTriggerScales> L1MuTriggerScalesOnlineProducer::newObject(const std::string& objectKey) {
106  // The key we get from the O2O subsystem is the CMS_GMT.L1T_SCALES key,
107  // but the eta/phi scales have their own subtables, so let's find
108  // out.
109  vector<string> foreignKeys;
110 
111  const std::string etaKeyColumn("SC_MUON_ETA_FK");
112  const std::string phiKeyColumn("SC_MUON_PHI_FK");
113 
114  foreignKeys.push_back(etaKeyColumn);
115  foreignKeys.push_back(phiKeyColumn);
116 
118  // SELECTed columns
119  foreignKeys,
120  // schema name
121  "CMS_GT",
122  // table name
123  "L1T_SCALES",
124  // WHERE lhs
125  "L1T_SCALES.ID",
126  // WHERE rhs
127  m_omdsReader.singleAttribute(objectKey));
128 
129  if (keysRecord.numberRows() != 1) // check if query was successful
130  {
131  throw cond::Exception(
132  "Problem finding L1MuTriggerScales associated "
133  "with scales key `" +
134  objectKey + "'");
135  }
136 
137  std::string etaKeyValue;
138  std::string phiKeyValue;
139  keysRecord.fillVariable(etaKeyColumn, etaKeyValue);
140  keysRecord.fillVariable(phiKeyColumn, phiKeyValue);
141 
142  vector<string> columns;
143 
144  // get the eta scales from the database
145  ScaleRecordHelper etaHelper("ETA_BIN_LOW", m_nbinsEta);
146  etaHelper.pushColumnNames(columns);
147 
149  // SELECTed columns
150  columns,
151  // schema name
152  "CMS_GT",
153  // table name
154  "L1T_SCALE_MUON_ETA",
155  // WHERE lhs
156  "L1T_SCALE_MUON_ETA.ID",
157  // WHERE rhs
158  m_omdsReader.singleAttribute(etaKeyValue));
159 
160  vector<double> etaScales;
161  etaHelper.extractScales(etaRecord, etaScales);
162 
163  unique_ptr<L1MuSymmetricBinnedScale> ptrEtaScale(
165  m_scales.setGMTEtaScale(*ptrEtaScale);
166 
167  columns.clear();
168 
169  // get the phi scales from the database
170  PhiScaleHelper phiHelper;
171 
173  // SELECTed columns
174  columns,
175  // schema name
176  "CMS_GT",
177  // table name
178  "L1T_SCALE_MUON_PHI",
179  // WHERE lhs
180  "L1T_SCALE_MUON_PHI.ID",
181  // WHERE rhs
182  m_omdsReader.singleAttribute(phiKeyValue));
183 
184  unique_ptr<L1MuBinnedScale> ptrPhiScale(phiHelper.makeBinnedScale(phiRecord, m_nbitPackingPhi, m_signedPackingPhi));
185 
186  m_scales.setPhiScale(*ptrPhiScale);
187 
188  return std::make_unique<L1MuTriggerScales>(m_scales);
189 }
persistency::Exception Exception
Definition: Exception.h:25
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:274
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:259
L1MuTriggerScalesOnlineProducer(const edm::ParameterSet &)
static const string LowMarkColumn
void setGMTEtaScale(const L1MuSymmetricBinnedScale &scale)
set the GMT eta scale
static void pushColumnNames(vector< string > &columns)
static const string StepColumn
const QueryResults basicQuery(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &tableName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
Definition: OMDSReader.cc:75
static double deg2rad(double deg)
void setPhiScale(const L1MuBinnedScale &scale)
set the phi scale
#define M_PI
void pushColumnNames(std::vector< std::string > &columns)
std::unique_ptr< L1MuTriggerScales > newObject(const std::string &objectKey) override
void extractScales(l1t::OMDSReader::QueryResults &record, std::vector< double > &destScales)
static const string BinsColumn
tuple columns
Definition: mps_check.py:244
step
Definition: StallMonitor.cc:94
static double rad2deg(double rad)
static L1MuBinnedScale * makeBinnedScale(l1t::OMDSReader::QueryResults &record, int nBits, bool signedPacking)