File indexing completed on 2023-03-17 11:14:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtPsbSetupConfigOnlineProd.h"
0018
0019
0020 #include <algorithm>
0021
0022
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024
0025
0026 L1GtPsbSetupConfigOnlineProd::L1GtPsbSetupConfigOnlineProd(const edm::ParameterSet& parSet)
0027 : L1ConfigOnlineProdBase<L1GtPsbSetupRcd, L1GtPsbSetup>(parSet) {
0028
0029 }
0030
0031
0032 L1GtPsbSetupConfigOnlineProd::~L1GtPsbSetupConfigOnlineProd() {
0033
0034 }
0035
0036
0037
0038 std::unique_ptr<L1GtPsbSetup> L1GtPsbSetupConfigOnlineProd::newObject(const std::string& objectKey) {
0039 auto pL1GtPsbSetup = std::make_unique<L1GtPsbSetup>();
0040
0041 const std::string gtSchema = "CMS_GT";
0042
0043
0044 std::vector<L1GtPsbConfig> psbConfigurations;
0045
0046
0047 std::vector<std::string> psbColumns = m_omdsReader.columnNames(gtSchema, "GT_SETUP");
0048
0049 std::vector<std::string>::iterator newEnd = std::remove_if(psbColumns.begin(), psbColumns.end(), ¬PsbColumnName);
0050 psbColumns.erase(newEnd, psbColumns.end());
0051
0052
0053 l1t::OMDSReader::QueryResults psbKeys =
0054 m_omdsReader.basicQuery(psbColumns, gtSchema, "GT_SETUP", "GT_SETUP.ID", m_omdsReader.singleAttribute(objectKey));
0055
0056
0057 if (!checkOneLineResult(psbKeys, "GT_SETUP query for PSB keys with ID = " + objectKey)) {
0058 edm::LogError("L1-O2O") << "Problem to get content of CMS_GT.GT_SETUP for GT_SETUP.ID key: " << objectKey;
0059 return pL1GtPsbSetup;
0060 }
0061
0062
0063 for (std::vector<std::string>::const_iterator it = psbColumns.begin(); it != psbColumns.end(); ++it) {
0064 std::string psbKey;
0065 psbKeys.fillVariable(*it, psbKey);
0066
0067 if (psbKey.empty()) {
0068 addDefaultPsb(*it, psbConfigurations);
0069 } else {
0070 addPsbFromDb(psbKey, psbConfigurations);
0071 }
0072 }
0073
0074
0075 pL1GtPsbSetup->setGtPsbSetup(psbConfigurations);
0076
0077 if (edm::isDebugEnabled()) {
0078 LogTrace("L1-O2O") << (*pL1GtPsbSetup) << std::endl;
0079 }
0080
0081 return pL1GtPsbSetup;
0082 }
0083
0084
0085
0086 bool L1GtPsbSetupConfigOnlineProd::notPsbColumnName(const std::string& columnName) {
0087 static std::string startMatch("PSB_SLOT_");
0088 static std::string endMatch("_SETUP_FK");
0089
0090 unsigned len = columnName.size();
0091
0092
0093 return len <= (startMatch.size() + endMatch.size()) ||
0094
0095 columnName.substr(0, startMatch.size()) != startMatch ||
0096
0097 columnName.substr(len - endMatch.size(), endMatch.size()) != endMatch;
0098 }
0099
0100 void L1GtPsbSetupConfigOnlineProd::addPsbFromDb(const std::string& psbKey, std::vector<L1GtPsbConfig>& psbSetup) {
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 const std::string gtSchema = "CMS_GT";
0135
0136
0137 std::vector<std::string> columnNames;
0138
0139 static const std::string lvdPrefix = "ENABLE_TT_LVDS_";
0140 static const std::string lvdSuffix = "";
0141 static const std::string serPrefix = "SERLINK_CH";
0142 static const std::string serSuffix = "_REC_ENABLE";
0143 static const std::string boardSlotColumn = "BOARD_SLOT";
0144 static const std::string ch0FormatColumn = "CH0_SEND_LVDS_NOT_DS92LV16";
0145 static const std::string ch1FormatColumn = "CH1_SEND_LVDS_NOT_DS92LV16";
0146
0147 columnNames.push_back(boardSlotColumn);
0148 columnNames.push_back(ch0FormatColumn);
0149 columnNames.push_back(ch1FormatColumn);
0150
0151 for (unsigned i = 0; i < (unsigned)L1GtPsbConfig::PsbNumberLvdsGroups; ++i) {
0152 columnNames.push_back(numberedColumnName(lvdPrefix, i, lvdSuffix));
0153 }
0154
0155 for (unsigned i = 0; i < (unsigned)L1GtPsbConfig::PsbSerLinkNumberChannels; ++i) {
0156 columnNames.push_back(numberedColumnName(serPrefix, i, serSuffix));
0157 }
0158
0159
0160 l1t::OMDSReader::QueryResults psbQuery = m_omdsReader.basicQuery(
0161 columnNames, gtSchema, "GT_PSB_SETUP", "GT_PSB_SETUP.ID", m_omdsReader.singleAttribute(psbKey));
0162
0163
0164 if (!checkOneLineResult(psbQuery, "GT_PSB_SETUP query for PSB keys with ID = " + psbKey)) {
0165 edm::LogError("L1-O2O") << "Problem to get setup for PSB keys with ID = " << psbKey;
0166 return;
0167 }
0168
0169
0170 int16_t boardSlot;
0171
0172 getRequiredValue(psbQuery, boardSlotColumn, boardSlot);
0173
0174 bool sendLvds0, sendLvds1;
0175
0176 getRequiredValue(psbQuery, ch0FormatColumn, sendLvds0);
0177 getRequiredValue(psbQuery, ch1FormatColumn, sendLvds1);
0178
0179 const std::vector<bool>& enableRecLvds =
0180 extractBoolVector(psbQuery, lvdPrefix, lvdSuffix, L1GtPsbConfig::PsbNumberLvdsGroups);
0181 const std::vector<bool>& serLinkRecEnable =
0182 extractBoolVector(psbQuery, serPrefix, serSuffix, L1GtPsbConfig::PsbSerLinkNumberChannels);
0183
0184
0185 L1GtPsbConfig toAdd;
0186
0187 toAdd.setGtBoardSlot(boardSlot);
0188 toAdd.setGtPsbCh0SendLvds(sendLvds0);
0189 toAdd.setGtPsbCh1SendLvds(sendLvds1);
0190 toAdd.setGtPsbEnableRecLvds(enableRecLvds);
0191 toAdd.setGtPsbEnableRecSerLink(serLinkRecEnable);
0192
0193
0194 psbSetup.push_back(toAdd);
0195 }
0196
0197 void L1GtPsbSetupConfigOnlineProd::addDefaultPsb(const std::string& psbColumn,
0198 std::vector<L1GtPsbConfig>& psbSetup) const {
0199
0200 unsigned boardSlot = numberFromString(psbColumn);
0201
0202
0203 L1GtPsbConfig toAdd;
0204 static std::vector<bool> allFalseLvds(L1GtPsbConfig::PsbNumberLvdsGroups, false);
0205 static std::vector<bool> allFalseSerLink(L1GtPsbConfig::PsbSerLinkNumberChannels, false);
0206
0207 toAdd.setGtBoardSlot(boardSlot);
0208 toAdd.setGtPsbCh0SendLvds(false);
0209 toAdd.setGtPsbCh1SendLvds(false);
0210 toAdd.setGtPsbEnableRecLvds(allFalseLvds);
0211 toAdd.setGtPsbEnableRecSerLink(allFalseSerLink);
0212
0213 psbSetup.push_back(toAdd);
0214 }
0215
0216 std::vector<bool> L1GtPsbSetupConfigOnlineProd::extractBoolVector(const l1t::OMDSReader::QueryResults& query,
0217 const std::string& prefix,
0218 const std::string& suffix,
0219 unsigned nColumns) const {
0220 std::vector<bool> result(nColumns);
0221
0222 for (unsigned i = 0; i < nColumns; ++i) {
0223 bool dbValue;
0224 getRequiredValue(query, numberedColumnName(prefix, i, suffix), dbValue);
0225 result[i] = dbValue;
0226 }
0227
0228 return result;
0229 }
0230
0231 bool L1GtPsbSetupConfigOnlineProd::checkOneLineResult(const l1t::OMDSReader::QueryResults& result,
0232 const std::string& queryDescription) const {
0233
0234 if (result.queryFailed()) {
0235 edm::LogError("L1-O2O") << "\n " << queryDescription + " failed: no match found!";
0236 return false;
0237
0238 } else if (result.numberRows() != 1) {
0239 edm::LogError("L1-O2O") << "\nProblem with " << queryDescription << ": " << (result.numberRows())
0240 << " rows were returned, expected 1.";
0241 return false;
0242 }
0243
0244 return true;
0245 }
0246
0247 std::string L1GtPsbSetupConfigOnlineProd::numberedColumnName(const std::string& prefix, unsigned number) const {
0248 return numberedColumnName(prefix, number, "");
0249 }
0250
0251 std::string L1GtPsbSetupConfigOnlineProd::numberedColumnName(const std::string& prefix,
0252 unsigned number,
0253 const std::string& suffix) const {
0254 std::ostringstream colName;
0255 colName << prefix << number << suffix;
0256
0257 return colName.str();
0258 }
0259
0260 unsigned L1GtPsbSetupConfigOnlineProd::numberFromString(const std::string& aString) const {
0261 std::istringstream stream(aString);
0262 unsigned result;
0263
0264 for (unsigned i = 0; i < aString.size(); ++i) {
0265 if (stream >> result) {
0266
0267 return result;
0268 } else {
0269
0270 stream.clear();
0271
0272 stream.seekg(i);
0273 }
0274 }
0275
0276
0277 throw cms::Exception("NumberNotFound") << "Failed to extract numeric value from " << aString;
0278 }
0279
0280 DEFINE_FWK_EVENTSETUP_MODULE(L1GtPsbSetupConfigOnlineProd);