File indexing completed on 2024-04-06 12:08:34
0001
0002 #include "DQM/SiStripCommissioningDbClients/interface/PedsOnlyHistosUsingDb.h"
0003 #include "CondFormats/SiStripObjects/interface/PedsOnlyAnalysis.h"
0004 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0005 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0006 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include <iostream>
0009
0010 using namespace sistrip;
0011
0012
0013
0014 PedsOnlyHistosUsingDb::PedsOnlyHistosUsingDb(const edm::ParameterSet& pset,
0015 DQMStore* bei,
0016 SiStripConfigDb* const db,
0017 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken)
0018 : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("PedsOnlyParameters"), bei, sistrip::PEDS_ONLY),
0019 CommissioningHistosUsingDb(db, tTopoToken, sistrip::PEDS_ONLY),
0020 PedsOnlyHistograms(pset.getParameter<edm::ParameterSet>("PedsOnlyParameters"), bei) {
0021 LogTrace(mlDqmClient_) << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
0022 << " Constructing object...";
0023 }
0024
0025
0026
0027 PedsOnlyHistosUsingDb::~PedsOnlyHistosUsingDb() {
0028 LogTrace(mlDqmClient_) << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
0029 << " Destructing object...";
0030 }
0031
0032
0033
0034 void PedsOnlyHistosUsingDb::uploadConfigurations() {
0035 LogTrace(mlDqmClient_) << "[PedsOnlyHistosUsingDb::" << __func__ << "]";
0036
0037 if (!db()) {
0038 edm::LogError(mlDqmClient_) << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
0039 << " NULL pointer to SiStripConfigDb interface!"
0040 << " Aborting upload...";
0041 return;
0042 }
0043
0044
0045 SiStripConfigDb::FedDescriptionsRange feds = db()->getFedDescriptions();
0046 update(feds);
0047 if (doUploadConf()) {
0048 edm::LogVerbatim(mlDqmClient_) << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
0049 << " Uploading pedestals/noise to DB...";
0050 db()->uploadFedDescriptions();
0051 edm::LogVerbatim(mlDqmClient_) << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
0052 << " Completed database upload of " << feds.size() << " FED descriptions!";
0053 } else {
0054 edm::LogWarning(mlDqmClient_) << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
0055 << " TEST only! No pedestals/noise values will be uploaded to DB...";
0056 }
0057 }
0058
0059
0060
0061 void PedsOnlyHistosUsingDb::update(SiStripConfigDb::FedDescriptionsRange feds) {
0062
0063 uint16_t updated = 0;
0064 SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
0065 for (ifed = feds.begin(); ifed != feds.end(); ifed++) {
0066 for (uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++) {
0067
0068 const FedChannelConnection& conn = cabling()->fedConnection((*ifed)->getFedId(), ichan);
0069 if (conn.fecCrate() == sistrip::invalid_ || conn.fecSlot() == sistrip::invalid_ ||
0070 conn.fecRing() == sistrip::invalid_ || conn.ccuAddr() == sistrip::invalid_ ||
0071 conn.ccuChan() == sistrip::invalid_ || conn.lldChannel() == sistrip::invalid_) {
0072 continue;
0073 }
0074 SiStripFedKey fed_key(conn.fedId(), SiStripFedKey::feUnit(conn.fedCh()), SiStripFedKey::feChan(conn.fedCh()));
0075 SiStripFecKey fec_key(
0076 conn.fecCrate(), conn.fecSlot(), conn.fecRing(), conn.ccuAddr(), conn.ccuChan(), conn.lldChannel());
0077
0078
0079 Analyses::const_iterator iter = data().find(fec_key.key());
0080 if (iter != data().end()) {
0081
0082 if (!iter->second->isValid()) {
0083 continue;
0084 }
0085
0086 PedsOnlyAnalysis* anal = dynamic_cast<PedsOnlyAnalysis*>(iter->second);
0087 if (!anal) {
0088 edm::LogError(mlDqmClient_) << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
0089 << " NULL pointer to analysis object!";
0090 continue;
0091 }
0092
0093
0094 uint32_t pedshift = 127;
0095 for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
0096 uint32_t pedmin = (uint32_t)anal->pedsMin()[iapv];
0097 pedshift = pedmin < pedshift ? pedmin : pedshift;
0098 }
0099
0100
0101 for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
0102 for (uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++) {
0103 constexpr float high_threshold = 5.;
0104 constexpr float low_threshold = 2.;
0105 constexpr bool disable_strip = false;
0106 Fed9U::Fed9UStripDescription data(static_cast<uint32_t>(anal->peds()[iapv][istr] - pedshift),
0107 high_threshold,
0108 low_threshold,
0109 anal->raw()[iapv][istr],
0110 disable_strip);
0111 Fed9U::Fed9UAddress addr(ichan, iapv, istr);
0112 (*ifed)->getFedStrips().setStrip(addr, data);
0113 }
0114 }
0115 updated++;
0116
0117 } else {
0118 edm::LogWarning(mlDqmClient_) << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
0119 << " Unable to find pedestals/noise for FedKey/Id/Ch: " << hex << setw(8)
0120 << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/"
0121 << ichan << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate() << "/"
0122 << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/" << fec_key.ccuAddr()
0123 << "/" << fec_key.ccuChan() << "/" << fec_key.channel();
0124 }
0125 }
0126 }
0127
0128 edm::LogVerbatim(mlDqmClient_) << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
0129 << " Updated FED pedestals/noise for " << updated << " channels";
0130 }
0131
0132
0133
0134 void PedsOnlyHistosUsingDb::create(SiStripConfigDb::AnalysisDescriptionsV& desc, Analysis analysis) {
0135 PedsOnlyAnalysis* anal = dynamic_cast<PedsOnlyAnalysis*>(analysis->second);
0136 if (!anal) {
0137 return;
0138 }
0139
0140 SiStripFecKey fec_key(anal->fecKey());
0141 SiStripFedKey fed_key(anal->fedKey());
0142
0143 for (uint16_t iapv = 0; iapv < 2; ++iapv) {
0144
0145 PedestalsAnalysisDescription* tmp;
0146 tmp = new PedestalsAnalysisDescription(std::vector<uint16_t>(0, 0),
0147 std::vector<uint16_t>(0, 0),
0148 anal->pedsMean()[iapv],
0149 anal->pedsSpread()[iapv],
0150 1. * sistrip::invalid_,
0151 1. * sistrip::invalid_,
0152 anal->rawMean()[iapv],
0153 anal->rawSpread()[iapv],
0154 anal->pedsMax()[iapv],
0155 anal->pedsMin()[iapv],
0156 1. * sistrip::invalid_,
0157 1. * sistrip::invalid_,
0158 anal->rawMax()[iapv],
0159 anal->rawMin()[iapv],
0160 fec_key.fecCrate(),
0161 fec_key.fecSlot(),
0162 fec_key.fecRing(),
0163 fec_key.ccuAddr(),
0164 fec_key.ccuChan(),
0165 SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0166 db()->dbParams().partitions().begin()->second.partitionName(),
0167 db()->dbParams().partitions().begin()->second.runNumber(),
0168 anal->isValid(),
0169 "",
0170 fed_key.fedId(),
0171 fed_key.feUnit(),
0172 fed_key.feChan(),
0173 fed_key.fedApv());
0174
0175
0176 typedef std::vector<std::string> Strings;
0177 Strings errors = anal->getErrorCodes();
0178 Strings::const_iterator istr = errors.begin();
0179 Strings::const_iterator jstr = errors.end();
0180 for (; istr != jstr; ++istr) {
0181 tmp->addComments(*istr);
0182 }
0183
0184
0185 desc.push_back(tmp);
0186 }
0187 }