CMS 3D CMS Logo

L1GtPrescaleFactorsTechTrigConfigOnlineProd.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <vector>
20 
21 #include "boost/lexical_cast.hpp"
22 
23 // user include files
25 
26 // constructor
28  const edm::ParameterSet& parSet) :
30  m_isDebugEnabled(edm::isDebugEnabled()) {
31 
32  // empty
33 
34 }
35 
36 // destructor
38 
39  // empty
40 
41 }
42 
43 // public methods
44 
45 std::unique_ptr<L1GtPrescaleFactors> L1GtPrescaleFactorsTechTrigConfigOnlineProd::newObject(
46  const std::string& objectKey) {
47 
48  // FIXME seems to not work anymore in constructor...
50 
51  auto pL1GtPrescaleFactors = std::make_unique<L1GtPrescaleFactors>();
52 
53  // Procedure:
54  // objectKey received as input is GT_RUN_SETTINGS_FK
55  //
56  // get from GT_RUN_SETTINGS_PRESC_VIEW the PRESCALE_FACTORS_TT_FK and the index PRESCALE_INDEX
57  // for the GT_RUN_SETTINGS_FK
58  //
59  // get the prescale factors for key PRESCALE_FACTORS_TT_FK
60  // from GT_FDL_PRESCALE_FACTORS_TT table
61 
62  const std::string gtSchema = "CMS_GT";
63 
64  // select * from CMS_GT.GT_RUN_SETTINGS_PRESC_VIEW
65  // where GT_RUN_SETTINGS_PRESC_VIEW.ID = objectKey
66 
67  std::vector<std::string> columnsView;
68  columnsView.push_back("PRESCALE_INDEX");
69  columnsView.push_back("PRESCALE_FACTORS_TT_FK");
70 
72  columnsView, gtSchema, "GT_RUN_SETTINGS_PRESC_VIEW",
73  "GT_RUN_SETTINGS_PRESC_VIEW.ID", m_omdsReader.singleAttribute(
74  objectKey));
75 
76  // check if query was successful
77  if (resultsView.queryFailed()) {
78  edm::LogError("L1-O2O")
79  << "Problem to get content of GT_RUN_SETTINGS_PRESC_VIEW "
80  << "for GT_RUN_SETTINGS_PRESC_VIEW.ID: " << objectKey;
81  return pL1GtPrescaleFactors;
82  }
83 
84  // retrieve PRESCALE_INDEX and PRESCALE_FACTORS_TT_FK for GT_RUN_SETTINGS_FK
85 
86  std::string objectKeyPrescaleFactorsSet = "WRONG_KEY_INITIAL";
87  short prescaleFactorsSetIndex = 9999;
88 
89  int resultsViewRows = resultsView.numberRows();
90  if (m_isDebugEnabled) {
91  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd") << "\nFound "
92  << resultsViewRows << " prescale factors sets for \n "
93  << "GT_RUN_SETTINGS_PRESC_VIEW.ID = " << objectKey << "\n"
94  << std::endl;
95  }
96 
97  // vector to be filled (resultsViewRows prescale factors sets)
98  std::vector<std::vector<int> > pFactors;
99  pFactors.reserve(resultsViewRows);
100 
101  int countSet = -1;
102 
103  for (int iRow = 0; iRow < resultsViewRows; ++iRow) {
104 
105  for (std::vector<std::string>::const_iterator constIt =
106  columnsView.begin(); constIt != columnsView.end(); ++constIt) {
107 
108  if ((*constIt) == "PRESCALE_INDEX") {
109  resultsView.fillVariableFromRow(*constIt, iRow,
110  prescaleFactorsSetIndex);
111  } else if ((*constIt) == "PRESCALE_FACTORS_TT_FK") {
112  resultsView.fillVariableFromRow(*constIt, iRow,
113  objectKeyPrescaleFactorsSet);
114  } else {
115 
116  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd")
117  << "\nUnknown field " << (*constIt)
118  << " requested for columns in GT_RUN_SETTINGS_PRESC_VIEW"
119  << std::endl;
120 
121  }
122  }
123 
124  if (m_isDebugEnabled) {
125  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd")
126  << "\nFound prescale factors set: \n index = "
127  << prescaleFactorsSetIndex
128  << "\n PRESCALE_FACTORS_TT_FK = "
129  << objectKeyPrescaleFactorsSet << "\n" << std::endl;
130  }
131 
132  // retrive now the prescale factors for PRESCALE_FACTORS_TT_FK
133 
134 
135  // SQL query:
136  //
137  // select * from CMS_GT.GT_FDL_PRESCALE_FACTORS_TT
138  // WHERE GT_FDL_PRESCALE_FACTORS_TT.ID = objectKeyPrescaleFactorsSet
139  const std::vector<std::string>& columns = m_omdsReader.columnNames(
140  gtSchema, "GT_FDL_PRESCALE_FACTORS_TT");
141 
142  if (m_isDebugEnabled) {
143  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd")
144  << "\nColumn names for GT_FDL_PRESCALE_FACTORS_TT"
145  << std::endl;
146 
147  for (std::vector<std::string>::const_iterator iter =
148  columns.begin(); iter != columns.end(); iter++) {
149  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd")
150  << (*iter) << std::endl;
151 
152  }
153  }
154 
156  columns, gtSchema, "GT_FDL_PRESCALE_FACTORS_TT",
157  "GT_FDL_PRESCALE_FACTORS_TT.ID",
158  m_omdsReader.singleAttribute(objectKeyPrescaleFactorsSet));
159 
160  // check if query was successful
161  if (results.queryFailed()) {
162  edm::LogError("L1-O2O")
163  << "Problem with L1GtPrescaleFactorsTechTrigRcd key:"
164  << objectKeyPrescaleFactorsSet;
165  return pL1GtPrescaleFactors;
166  }
167 
168 
169 
170 
171  // check if set indices are ordered, starting from 0 (initial value for countSet is -1)
172  countSet++;
173  if (prescaleFactorsSetIndex != countSet) {
174  edm::LogError("L1-O2O")
175  << "L1GtPrescaleFactorsTechTrig has unordered sets PRESCALE_INDEX in DB for\n"
176  << " GT_RUN_SETTINGS_PRESC_VIEW.ID = " << objectKey << "\n"
177  << std::endl;
178  return pL1GtPrescaleFactors;
179 
180  }
181 
182 
183  // fill one set of prescale factors
184  int pfSetSize = columns.size() - 1; // table ID is also in columns
185  std::vector<int> pfSet(pfSetSize, 0);
186 
187  for (int i = 0; i < pfSetSize; i++) {
188  results.fillVariable(columns[i + 1], pfSet[i]);
189  }
190 
191  pFactors.push_back(pfSet);
192 
193  }
194 
195  // fill the record
196 
197  pL1GtPrescaleFactors->setGtPrescaleFactors(pFactors);
198 
199  if (m_isDebugEnabled) {
200  std::ostringstream myCoutStream;
201  pL1GtPrescaleFactors->print(myCoutStream);
202  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd")
203  << "\nThe following L1GtPrescaleFactorsTechTrigRcd record was read from OMDS: \n"
204  << myCoutStream.str() << "\n" << std::endl;
205  }
206 
207  return pL1GtPrescaleFactors;
208 }
209 
bool isDebugEnabled()
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:311
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:295
std::vector< std::string > columnNames(const std::string &schemaName, const std::string &tableName)
Definition: OMDSReader.cc:165
bool fillVariableFromRow(const std::string &columnName, int rowNumber, T &outputVariable) const
Definition: OMDSReader.h:319
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:86
L1GtPrescaleFactorsTechTrigConfigOnlineProd(const edm::ParameterSet &)
constructor
#define LogTrace(id)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
const QueryResults basicQueryView(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &viewName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
Definition: OMDSReader.cc:192
HLT enums.
std::unique_ptr< L1GtPrescaleFactors > newObject(const std::string &objectKey) override
public methods