CMS 3D CMS Logo

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