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