00001
00018
00019 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtPsbSetupConfigOnlineProd.h"
00020
00021
00022 #include "boost/lexical_cast.hpp"
00023 #include <algorithm>
00024
00025
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027
00028
00029 L1GtPsbSetupConfigOnlineProd::L1GtPsbSetupConfigOnlineProd(const edm::ParameterSet& parSet) :
00030 L1ConfigOnlineProdBase<L1GtPsbSetupRcd, L1GtPsbSetup> (parSet) {
00031
00032
00033
00034 }
00035
00036
00037 L1GtPsbSetupConfigOnlineProd::~L1GtPsbSetupConfigOnlineProd() {
00038
00039
00040
00041 }
00042
00043
00044
00045 boost::shared_ptr<L1GtPsbSetup> L1GtPsbSetupConfigOnlineProd::newObject(
00046 const std::string& objectKey) {
00047
00048
00049 boost::shared_ptr<L1GtPsbSetup> pL1GtPsbSetup = boost::shared_ptr<L1GtPsbSetup>(
00050 new L1GtPsbSetup());
00051
00052 const std::string gtSchema = "CMS_GT";
00053
00054
00055 std::vector<L1GtPsbConfig> psbConfigurations;
00056
00057
00058 std::vector<std::string> psbColumns = m_omdsReader.columnNames(gtSchema, "GT_SETUP");
00059
00060 std::vector<std::string>::iterator newEnd = std::remove_if(
00061 psbColumns.begin(), psbColumns.end(), ¬PsbColumnName);
00062 psbColumns.erase(newEnd, psbColumns.end());
00063
00064
00065 l1t::OMDSReader::QueryResults psbKeys = m_omdsReader.basicQuery(
00066 psbColumns, gtSchema, "GT_SETUP", "GT_SETUP.ID",
00067 m_omdsReader.singleAttribute(objectKey));
00068
00069
00070 if (!checkOneLineResult(psbKeys, "GT_SETUP query for PSB keys with ID = " + objectKey)) {
00071 edm::LogError("L1-O2O")
00072 << "Problem to get content of CMS_GT.GT_SETUP for GT_SETUP.ID key: "
00073 << objectKey;
00074 return pL1GtPsbSetup;
00075 }
00076
00077
00078 for (std::vector<std::string>::const_iterator it = psbColumns.begin(); it != psbColumns.end(); ++it) {
00079
00080 std::string psbKey;
00081 psbKeys.fillVariable(*it, psbKey);
00082
00083 if (psbKey.empty()) {
00084 addDefaultPsb(*it, psbConfigurations);
00085 } else {
00086 addPsbFromDb(psbKey, psbConfigurations);
00087 }
00088 }
00089
00090
00091 pL1GtPsbSetup->setGtPsbSetup(psbConfigurations);
00092
00093 if (edm::isDebugEnabled()) {
00094 LogTrace("L1-O2O") << (*pL1GtPsbSetup) << std::endl;
00095 }
00096
00097 return pL1GtPsbSetup;
00098 }
00099
00100
00101
00102 bool L1GtPsbSetupConfigOnlineProd::notPsbColumnName(const std::string& columnName) {
00103
00104 static std::string startMatch("PSB_SLOT_");
00105 static std::string endMatch("_SETUP_FK");
00106
00107 unsigned len = columnName.size();
00108
00109
00110 return len <= ( startMatch.size() + endMatch.size() ) ||
00111
00112 columnName.substr(0, startMatch.size()) != startMatch ||
00113
00114 columnName.substr(len - endMatch.size(), endMatch.size()) != endMatch;
00115 }
00116
00117 void L1GtPsbSetupConfigOnlineProd::addPsbFromDb(const std::string& psbKey, std::vector<
00118 L1GtPsbConfig>& psbSetup) const {
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 const std::string gtSchema = "CMS_GT";
00154
00155
00156 std::vector<std::string> columnNames;
00157
00158 static const std::string lvdPrefix = "ENABLE_TT_LVDS_";
00159 static const std::string lvdSuffix = "";
00160 static const std::string serPrefix = "SERLINK_CH";
00161 static const std::string serSuffix = "_REC_ENABLE";
00162 static const std::string boardSlotColumn = "BOARD_SLOT";
00163 static const std::string ch0FormatColumn = "CH0_SEND_LVDS_NOT_DS92LV16";
00164 static const std::string ch1FormatColumn = "CH1_SEND_LVDS_NOT_DS92LV16";
00165
00166 columnNames.push_back(boardSlotColumn);
00167 columnNames.push_back(ch0FormatColumn);
00168 columnNames.push_back(ch1FormatColumn);
00169
00170 for (unsigned i = 0; i < (unsigned) L1GtPsbConfig::PsbNumberLvdsGroups; ++i) {
00171 columnNames.push_back(numberedColumnName(lvdPrefix, i, lvdSuffix));
00172 }
00173
00174 for (unsigned i = 0; i < (unsigned) L1GtPsbConfig::PsbSerLinkNumberChannels; ++i) {
00175 columnNames.push_back(numberedColumnName(serPrefix, i, serSuffix));
00176 }
00177
00178
00179 l1t::OMDSReader::QueryResults psbQuery = m_omdsReader.basicQuery(
00180 columnNames, gtSchema, "GT_PSB_SETUP", "GT_PSB_SETUP.ID", m_omdsReader.singleAttribute(
00181 psbKey));
00182
00183
00184 if (!checkOneLineResult(psbQuery, "GT_PSB_SETUP query for PSB keys with ID = " + psbKey)) {
00185 edm::LogError("L1-O2O")
00186 << "Problem to get setup for PSB keys with ID = " << psbKey;
00187 return;
00188 }
00189
00190
00191 int16_t boardSlot;
00192
00193 getRequiredValue(psbQuery, boardSlotColumn, boardSlot);
00194
00195 bool sendLvds0, sendLvds1;
00196
00197 getRequiredValue(psbQuery, ch0FormatColumn, sendLvds0);
00198 getRequiredValue(psbQuery, ch1FormatColumn, sendLvds1);
00199
00200 const std::vector<bool>& enableRecLvds = extractBoolVector(
00201 psbQuery, lvdPrefix, lvdSuffix, L1GtPsbConfig::PsbNumberLvdsGroups);
00202 const std::vector<bool>& serLinkRecEnable = extractBoolVector(
00203 psbQuery, serPrefix, serSuffix, L1GtPsbConfig::PsbSerLinkNumberChannels);
00204
00205
00206 L1GtPsbConfig toAdd;
00207
00208 toAdd.setGtBoardSlot(boardSlot);
00209 toAdd.setGtPsbCh0SendLvds(sendLvds0);
00210 toAdd.setGtPsbCh1SendLvds(sendLvds1);
00211 toAdd.setGtPsbEnableRecLvds(enableRecLvds);
00212 toAdd.setGtPsbEnableRecSerLink(serLinkRecEnable);
00213
00214
00215 psbSetup.push_back(toAdd);
00216 }
00217
00218 void L1GtPsbSetupConfigOnlineProd::addDefaultPsb(const std::string& psbColumn, std::vector<
00219 L1GtPsbConfig>& psbSetup) const {
00220
00221
00222 unsigned boardSlot = numberFromString(psbColumn);
00223
00224
00225 L1GtPsbConfig toAdd;
00226 static std::vector<bool> allFalseLvds(L1GtPsbConfig::PsbNumberLvdsGroups, false);
00227 static std::vector<bool> allFalseSerLink(L1GtPsbConfig::PsbSerLinkNumberChannels, false);
00228
00229 toAdd.setGtBoardSlot(boardSlot);
00230 toAdd.setGtPsbCh0SendLvds(false);
00231 toAdd.setGtPsbCh1SendLvds(false);
00232 toAdd.setGtPsbEnableRecLvds(allFalseLvds);
00233 toAdd.setGtPsbEnableRecSerLink(allFalseSerLink);
00234
00235 psbSetup.push_back(toAdd);
00236 }
00237
00238 std::vector<bool> L1GtPsbSetupConfigOnlineProd::extractBoolVector(
00239 const l1t::OMDSReader::QueryResults& query, const std::string& prefix,
00240 const std::string& suffix, unsigned nColumns) const {
00241
00242 std::vector<bool> result(nColumns);
00243
00244 for (unsigned i = 0; i < nColumns; ++i) {
00245 bool dbValue;
00246 getRequiredValue(query, numberedColumnName(prefix, i, suffix), dbValue);
00247 result[i] = dbValue;
00248 }
00249
00250 return result;
00251 }
00252
00253 bool L1GtPsbSetupConfigOnlineProd::checkOneLineResult(
00254 const l1t::OMDSReader::QueryResults& result, const std::string& queryDescription) const {
00255
00256
00257 if (result.queryFailed()) {
00258 edm::LogError("L1-O2O") << "\n " << queryDescription + " failed: no match found!";
00259 return false;
00260
00261 } else if (result.numberRows() != 1) {
00262 edm::LogError("L1-O2O") << "\nProblem with " << queryDescription << ": "
00263 << ( result.numberRows() ) << " rows were returned, expected 1.";
00264 return false;
00265 }
00266
00267 return true;
00268 }
00269
00270
00271 std::string L1GtPsbSetupConfigOnlineProd::numberedColumnName(
00272 const std::string& prefix, unsigned number) const {
00273
00274 return numberedColumnName(prefix, number, "");
00275
00276 }
00277
00278 std::string L1GtPsbSetupConfigOnlineProd::numberedColumnName(
00279 const std::string& prefix, unsigned number, const std::string& suffix) const {
00280
00281 std::ostringstream colName;
00282 colName << prefix << number << suffix;
00283
00284 return colName.str();
00285 }
00286
00287 unsigned L1GtPsbSetupConfigOnlineProd::numberFromString(const std::string& aString) const {
00288
00289 std::istringstream stream(aString);
00290 unsigned result;
00291
00292 for (unsigned i = 0; i < aString.size(); ++i) {
00293 if (stream >> result) {
00294
00295 return result;
00296 } else {
00297
00298 stream.clear();
00299
00300 stream.seekg(i);
00301 }
00302 }
00303
00304
00305 throw cms::Exception("NumberNotFound") << "Failed to extract numeric value from " << aString;
00306 }
00307
00308 DEFINE_FWK_EVENTSETUP_MODULE( L1GtPsbSetupConfigOnlineProd);