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