CMS 3D CMS Logo

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