CMS 3D CMS Logo

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