CMS 3D CMS Logo

L1GtPsbSetupConfigOnlineProd.cc
Go to the documentation of this file.
1 
16 // this class header
18 
19 // system include files
20 #include "boost/lexical_cast.hpp"
21 #include <algorithm>
22 
23 // user include files
25 
26 // constructor
29 
30  // empty
31 
32 }
33 
34 // destructor
36 
37  // empty
38 
39 }
40 
41 // public methods
42 
43 std::shared_ptr<L1GtPsbSetup> L1GtPsbSetupConfigOnlineProd::newObject(
44  const std::string& objectKey) {
45 
46  // shared pointer for L1GtPsbSetup
47  auto pL1GtPsbSetup = std::make_shared<L1GtPsbSetup>();
48 
49  const std::string gtSchema = "CMS_GT";
50 
51  // the setup's contents, to be filled from database
52  std::vector<L1GtPsbConfig> psbConfigurations;
53 
54  // SELECT PSB_SLOT_*_SETUP_FK FROM CMS_GT.GT_SETUP WHERE GT_SETUP.ID = MyKey
55  std::vector<std::string> psbColumns = m_omdsReader.columnNames(gtSchema, "GT_SETUP");
56 
57  std::vector<std::string>::iterator newEnd = std::remove_if(
58  psbColumns.begin(), psbColumns.end(), &notPsbColumnName);
59  psbColumns.erase(newEnd, psbColumns.end());
60 
61  // select * from CMS_GT.GT_SETUP where GT_SETUP.ID = objectKey
63  psbColumns, gtSchema, "GT_SETUP", "GT_SETUP.ID",
64  m_omdsReader.singleAttribute(objectKey));
65 
66  // check if query was successful and produced one line only
67  if (!checkOneLineResult(psbKeys, "GT_SETUP query for PSB keys with ID = " + objectKey)) {
68  edm::LogError("L1-O2O")
69  << "Problem to get content of CMS_GT.GT_SETUP for GT_SETUP.ID key: "
70  << objectKey;
71  return pL1GtPsbSetup;
72  }
73 
74  // fill the psbConfigurations vector
75  for (std::vector<std::string>::const_iterator it = psbColumns.begin(); it != psbColumns.end(); ++it) {
76 
77  std::string psbKey;
78  psbKeys.fillVariable(*it, psbKey);
79 
80  if (psbKey.empty()) {
81  addDefaultPsb(*it, psbConfigurations);
82  } else {
83  addPsbFromDb(psbKey, psbConfigurations);
84  }
85  }
86 
87  // assign to the result object
88  pL1GtPsbSetup->setGtPsbSetup(psbConfigurations);
89 
90  if (edm::isDebugEnabled()) {
91  LogTrace("L1-O2O") << (*pL1GtPsbSetup) << std::endl;
92  }
93 
94  return pL1GtPsbSetup;
95 }
96 
97 // Return true if columnName does NOT match the pattern
98 // PSB_SLOT_.*_SETUP_FK
100 
101  static std::string startMatch("PSB_SLOT_");
102  static std::string endMatch("_SETUP_FK");
103 
104  unsigned len = columnName.size();
105 
106  // it's not a PSB column name if it's too short
107  return len <= ( startMatch.size() + endMatch.size() ) ||
108  // or the start doesn't match
109  columnName.substr(0, startMatch.size()) != startMatch ||
110  // or the end doesn't match
111  columnName.substr(len - endMatch.size(), endMatch.size()) != endMatch;
112 }
113 
115  L1GtPsbConfig>& psbSetup) {
116 
117  // SQL> describe gt_psb_setup;
118  // (heavily pruned to just the stuff we need to set up a GtPsbConfig)
119  // Name Null? Type
120  // ----------------------------------------- -------- ----------------------------
121  // ID NOT NULL VARCHAR2(256)
122  // BOARD_SLOT NUMBER(3)
123  // CH0_SEND_LVDS_NOT_DS92LV16 NUMBER(1)
124  // CH1_SEND_LVDS_NOT_DS92LV16 NUMBER(1)
125  // ENABLE_TT_LVDS_0 NUMBER(1)
126  // ENABLE_TT_LVDS_1 NUMBER(1)
127  // ENABLE_TT_LVDS_2 NUMBER(1)
128  // ENABLE_TT_LVDS_3 NUMBER(1)
129  // ENABLE_TT_LVDS_4 NUMBER(1)
130  // ENABLE_TT_LVDS_5 NUMBER(1)
131  // ENABLE_TT_LVDS_6 NUMBER(1)
132  // ENABLE_TT_LVDS_7 NUMBER(1)
133  // ENABLE_TT_LVDS_8 NUMBER(1)
134  // ENABLE_TT_LVDS_9 NUMBER(1)
135  // ENABLE_TT_LVDS_10 NUMBER(1)
136  // ENABLE_TT_LVDS_11 NUMBER(1)
137  // ENABLE_TT_LVDS_12 NUMBER(1)
138  // ENABLE_TT_LVDS_13 NUMBER(1)
139  // ENABLE_TT_LVDS_14 NUMBER(1)
140  // ENABLE_TT_LVDS_15 NUMBER(1)
141  // SERLINK_CH0_REC_ENABLE NUMBER(1)
142  // SERLINK_CH1_REC_ENABLE NUMBER(1)
143  // SERLINK_CH2_REC_ENABLE NUMBER(1)
144  // SERLINK_CH3_REC_ENABLE NUMBER(1)
145  // SERLINK_CH4_REC_ENABLE NUMBER(1)
146  // SERLINK_CH5_REC_ENABLE NUMBER(1)
147  // SERLINK_CH6_REC_ENABLE NUMBER(1)
148  // SERLINK_CH7_REC_ENABLE NUMBER(1)
149 
150  const std::string gtSchema = "CMS_GT";
151 
152  // setup up columns to query
153  std::vector<std::string> columnNames;
154 
155  static const std::string lvdPrefix = "ENABLE_TT_LVDS_";
156  static const std::string lvdSuffix = "";
157  static const std::string serPrefix = "SERLINK_CH";
158  static const std::string serSuffix = "_REC_ENABLE";
159  static const std::string boardSlotColumn = "BOARD_SLOT";
160  static const std::string ch0FormatColumn = "CH0_SEND_LVDS_NOT_DS92LV16";
161  static const std::string ch1FormatColumn = "CH1_SEND_LVDS_NOT_DS92LV16";
162 
163  columnNames.push_back(boardSlotColumn);
164  columnNames.push_back(ch0FormatColumn);
165  columnNames.push_back(ch1FormatColumn);
166 
167  for (unsigned i = 0; i < (unsigned) L1GtPsbConfig::PsbNumberLvdsGroups; ++i) {
168  columnNames.push_back(numberedColumnName(lvdPrefix, i, lvdSuffix));
169  }
170 
171  for (unsigned i = 0; i < (unsigned) L1GtPsbConfig::PsbSerLinkNumberChannels; ++i) {
172  columnNames.push_back(numberedColumnName(serPrefix, i, serSuffix));
173  }
174 
175  // execute database query
177  columnNames, gtSchema, "GT_PSB_SETUP", "GT_PSB_SETUP.ID", m_omdsReader.singleAttribute(
178  psbKey));
179 
180  // check if query was successful and we get only one line
181  if (!checkOneLineResult(psbQuery, "GT_PSB_SETUP query for PSB keys with ID = " + psbKey)) {
182  edm::LogError("L1-O2O")
183  << "Problem to get setup for PSB keys with ID = " << psbKey;
184  return; // FIXME: change method to bool?
185  }
186 
187  // extract values
188  int16_t boardSlot;
189 
190  getRequiredValue(psbQuery, boardSlotColumn, boardSlot);
191 
192  bool sendLvds0, sendLvds1;
193 
194  getRequiredValue(psbQuery, ch0FormatColumn, sendLvds0);
195  getRequiredValue(psbQuery, ch1FormatColumn, sendLvds1);
196 
197  const std::vector<bool>& enableRecLvds = extractBoolVector(
198  psbQuery, lvdPrefix, lvdSuffix, L1GtPsbConfig::PsbNumberLvdsGroups);
199  const std::vector<bool>& serLinkRecEnable = extractBoolVector(
200  psbQuery, serPrefix, serSuffix, L1GtPsbConfig::PsbSerLinkNumberChannels);
201 
202  // create new PSB object with db values
204 
205  toAdd.setGtBoardSlot(boardSlot);
206  toAdd.setGtPsbCh0SendLvds(sendLvds0);
207  toAdd.setGtPsbCh1SendLvds(sendLvds1);
208  toAdd.setGtPsbEnableRecLvds(enableRecLvds);
209  toAdd.setGtPsbEnableRecSerLink(serLinkRecEnable);
210 
211  // add to vector
212  psbSetup.push_back(toAdd);
213 }
214 
215 void L1GtPsbSetupConfigOnlineProd::addDefaultPsb(const std::string& psbColumn, std::vector<
216  L1GtPsbConfig>& psbSetup) const {
217 
218  // deduce the assigned board from the column name
219  unsigned boardSlot = numberFromString(psbColumn);
220 
221  // create a default PsbConfig with the appropriate board slot and all links disabled
223  static std::vector<bool> allFalseLvds(L1GtPsbConfig::PsbNumberLvdsGroups, false);
224  static std::vector<bool> allFalseSerLink(L1GtPsbConfig::PsbSerLinkNumberChannels, false);
225 
226  toAdd.setGtBoardSlot(boardSlot);
227  toAdd.setGtPsbCh0SendLvds(false);
228  toAdd.setGtPsbCh1SendLvds(false);
229  toAdd.setGtPsbEnableRecLvds(allFalseLvds);
230  toAdd.setGtPsbEnableRecSerLink(allFalseSerLink);
231 
232  psbSetup.push_back(toAdd);
233 }
234 
237  const std::string& suffix, unsigned nColumns) const {
238 
239  std::vector<bool> result(nColumns);
240 
241  for (unsigned i = 0; i < nColumns; ++i) {
242  bool dbValue;
243  getRequiredValue(query, numberedColumnName(prefix, i, suffix), dbValue);
244  result[i] = dbValue;
245  }
246 
247  return result;
248 }
249 
251  const l1t::OMDSReader::QueryResults& result, const std::string& queryDescription) const {
252 
253  // check if query was successful
254  if (result.queryFailed()) {
255  edm::LogError("L1-O2O") << "\n " << queryDescription + " failed: no match found!";
256  return false;
257 
258  } else if (result.numberRows() != 1) {
259  edm::LogError("L1-O2O") << "\nProblem with " << queryDescription << ": "
260  << ( result.numberRows() ) << " rows were returned, expected 1.";
261  return false;
262  }
263 
264  return true;
265 }
266 
267 
269  const std::string& prefix, unsigned number) const {
270 
271  return numberedColumnName(prefix, number, "");
272 
273 }
274 
276  const std::string& prefix, unsigned number, const std::string& suffix) const {
277 
278  std::ostringstream colName;
279  colName << prefix << number << suffix;
280 
281  return colName.str();
282 }
283 
285 
286  std::istringstream stream(aString);
287  unsigned result;
288 
289  for (unsigned i = 0; i < aString.size(); ++i) {
290  if (stream >> result) {
291  // we got a value
292  return result;
293  } else {
294  // clear error flags from failed >>
295  stream.clear();
296  // skip another character
297  stream.seekg(i);
298  }
299  }
300 
301  // throw here
302  throw cms::Exception("NumberNotFound") << "Failed to extract numeric value from " << aString;
303 }
304 
bool checkOneLineResult(const l1t::OMDSReader::QueryResults &result, const std::string &queryDescription) const
Ensures that result contains exactly one line, returning false otherwise.
bool isDebugEnabled()
static bool notPsbColumnName(const std::string &columnName)
std::string numberedColumnName(const std::string &prefix, unsigned number, const std::string &suffix) const
Concatenates prefix, number and suffix into a string.
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:311
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:295
void getRequiredValue(const l1t::OMDSReader::QueryResults &result, const std::string &colName, T &value) const
void setGtPsbEnableRecLvds(const std::vector< bool > &)
void setGtPsbCh0SendLvds(const bool &)
void addDefaultPsb(const std::string &psbColumn, std::vector< L1GtPsbConfig > &psbSetup) const
Creates a default valued PSB from an empty foreign key in the GT_SETUP table.
static const int PsbSerLinkNumberChannels
number of channels per board
Definition: L1GtPsbConfig.h:67
~L1GtPsbSetupConfigOnlineProd() override
destructor
std::shared_ptr< L1GtPsbSetup > newObject(const std::string &objectKey) override
public methods
static const int PsbNumberLvdsGroups
number of LVDS groups per board
Definition: L1GtPsbConfig.h:64
Definition: query.py:1
void setGtPsbEnableRecSerLink(const std::vector< bool > &)
std::vector< std::string > columnNames(const std::string &schemaName, const std::string &tableName)
Definition: OMDSReader.cc:165
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
#define LogTrace(id)
std::vector< bool > extractBoolVector(const l1t::OMDSReader::QueryResults &query, const std::string &prefix, const std::string &suffix, unsigned nColumns) const
void setGtBoardSlot(const int &)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
L1GtPsbSetupConfigOnlineProd(const edm::ParameterSet &)
constructor
void addPsbFromDb(const std::string &psbKey, std::vector< L1GtPsbConfig > &psbSetup)
Creates a new PSB object from a GT_PSB_SETUP entry and adds.
void setGtPsbCh1SendLvds(const bool &)
unsigned numberFromString(const std::string &aString) const