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