CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::shared_ptr<L1GtPrescaleFactors> L1GtPrescaleFactorsTechTrigConfigOnlineProd::newObject(
46  const std::string& objectKey) {
47 
48  // FIXME seems to not work anymore in constructor...
50 
51  // shared pointer for L1GtPrescaleFactors
52  auto pL1GtPrescaleFactors = std::make_shared<L1GtPrescaleFactors>();
53 
54  // Procedure:
55  // objectKey received as input is GT_RUN_SETTINGS_FK
56  //
57  // get from GT_RUN_SETTINGS_PRESC_VIEW the PRESCALE_FACTORS_TT_FK and the index PRESCALE_INDEX
58  // for the GT_RUN_SETTINGS_FK
59  //
60  // get the prescale factors for key PRESCALE_FACTORS_TT_FK
61  // from GT_FDL_PRESCALE_FACTORS_TT table
62 
63  const std::string gtSchema = "CMS_GT";
64 
65  // select * from CMS_GT.GT_RUN_SETTINGS_PRESC_VIEW
66  // where GT_RUN_SETTINGS_PRESC_VIEW.ID = objectKey
67 
68  std::vector<std::string> columnsView;
69  columnsView.push_back("PRESCALE_INDEX");
70  columnsView.push_back("PRESCALE_FACTORS_TT_FK");
71 
73  columnsView, gtSchema, "GT_RUN_SETTINGS_PRESC_VIEW",
74  "GT_RUN_SETTINGS_PRESC_VIEW.ID", m_omdsReader.singleAttribute(
75  objectKey));
76 
77  // check if query was successful
78  if (resultsView.queryFailed()) {
79  edm::LogError("L1-O2O")
80  << "Problem to get content of GT_RUN_SETTINGS_PRESC_VIEW "
81  << "for GT_RUN_SETTINGS_PRESC_VIEW.ID: " << objectKey;
82  return pL1GtPrescaleFactors;
83  }
84 
85  // retrieve PRESCALE_INDEX and PRESCALE_FACTORS_TT_FK for GT_RUN_SETTINGS_FK
86 
87  std::string objectKeyPrescaleFactorsSet = "WRONG_KEY_INITIAL";
88  short prescaleFactorsSetIndex = 9999;
89 
90  int resultsViewRows = resultsView.numberRows();
91  if (m_isDebugEnabled) {
92  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd") << "\nFound "
93  << resultsViewRows << " prescale factors sets for \n "
94  << "GT_RUN_SETTINGS_PRESC_VIEW.ID = " << objectKey << "\n"
95  << std::endl;
96  }
97 
98  // vector to be filled (resultsViewRows prescale factors sets)
99  std::vector<std::vector<int> > pFactors;
100  pFactors.reserve(resultsViewRows);
101 
102  int countSet = -1;
103 
104  for (int iRow = 0; iRow < resultsViewRows; ++iRow) {
105 
106  for (std::vector<std::string>::const_iterator constIt =
107  columnsView.begin(); constIt != columnsView.end(); ++constIt) {
108 
109  if ((*constIt) == "PRESCALE_INDEX") {
110  resultsView.fillVariableFromRow(*constIt, iRow,
111  prescaleFactorsSetIndex);
112  } else if ((*constIt) == "PRESCALE_FACTORS_TT_FK") {
113  resultsView.fillVariableFromRow(*constIt, iRow,
114  objectKeyPrescaleFactorsSet);
115  } else {
116 
117  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd")
118  << "\nUnknown field " << (*constIt)
119  << " requested for columns in GT_RUN_SETTINGS_PRESC_VIEW"
120  << std::endl;
121 
122  }
123  }
124 
125  if (m_isDebugEnabled) {
126  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd")
127  << "\nFound prescale factors set: \n index = "
128  << prescaleFactorsSetIndex
129  << "\n PRESCALE_FACTORS_TT_FK = "
130  << objectKeyPrescaleFactorsSet << "\n" << std::endl;
131  }
132 
133  // retrive now the prescale factors for PRESCALE_FACTORS_TT_FK
134 
135 
136  // SQL query:
137  //
138  // select * from CMS_GT.GT_FDL_PRESCALE_FACTORS_TT
139  // WHERE GT_FDL_PRESCALE_FACTORS_TT.ID = objectKeyPrescaleFactorsSet
140  const std::vector<std::string>& columns = m_omdsReader.columnNames(
141  gtSchema, "GT_FDL_PRESCALE_FACTORS_TT");
142 
143  if (m_isDebugEnabled) {
144  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd")
145  << "\nColumn names for GT_FDL_PRESCALE_FACTORS_TT"
146  << std::endl;
147 
148  for (std::vector<std::string>::const_iterator iter =
149  columns.begin(); iter != columns.end(); iter++) {
150  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd")
151  << (*iter) << std::endl;
152 
153  }
154  }
155 
157  columns, gtSchema, "GT_FDL_PRESCALE_FACTORS_TT",
158  "GT_FDL_PRESCALE_FACTORS_TT.ID",
159  m_omdsReader.singleAttribute(objectKeyPrescaleFactorsSet));
160 
161  // check if query was successful
162  if (results.queryFailed()) {
163  edm::LogError("L1-O2O")
164  << "Problem with L1GtPrescaleFactorsTechTrigRcd key:"
165  << objectKeyPrescaleFactorsSet;
166  return pL1GtPrescaleFactors;
167  }
168 
169 
170 
171 
172  // check if set indices are ordered, starting from 0 (initial value for countSet is -1)
173  countSet++;
174  if (prescaleFactorsSetIndex != countSet) {
175  edm::LogError("L1-O2O")
176  << "L1GtPrescaleFactorsTechTrig has unordered sets PRESCALE_INDEX in DB for\n"
177  << " GT_RUN_SETTINGS_PRESC_VIEW.ID = " << objectKey << "\n"
178  << std::endl;
179  return pL1GtPrescaleFactors;
180 
181  }
182 
183 
184  // fill one set of prescale factors
185  int pfSetSize = columns.size() - 1; // table ID is also in columns
186  std::vector<int> pfSet(pfSetSize, 0);
187 
188  for (int i = 0; i < pfSetSize; i++) {
189  results.fillVariable(columns[i + 1], pfSet[i]);
190  }
191 
192  pFactors.push_back(pfSet);
193 
194  }
195 
196  // fill the record
197 
198  pL1GtPrescaleFactors->setGtPrescaleFactors(pFactors);
199 
200  if (m_isDebugEnabled) {
201  std::ostringstream myCoutStream;
202  pL1GtPrescaleFactors->print(myCoutStream);
203  LogTrace("L1GtPrescaleFactorsTechTrigConfigOnlineProd")
204  << "\nThe following L1GtPrescaleFactorsTechTrigRcd record was read from OMDS: \n"
205  << myCoutStream.str() << "\n" << std::endl;
206  }
207 
208  return pL1GtPrescaleFactors;
209 }
210 
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)
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
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
HLT enums.
virtual std::shared_ptr< L1GtPrescaleFactors > newObject(const std::string &objectKey)
public methods