File indexing completed on 2024-04-06 12:08:34
0001
0002 #include "DQM/SiStripCommissioningDbClients/interface/OptoScanHistosUsingDb.h"
0003 #include "CondFormats/SiStripObjects/interface/OptoScanAnalysis.h"
0004 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0005 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include <iostream>
0008
0009 using namespace sistrip;
0010
0011
0012
0013 OptoScanHistosUsingDb::OptoScanHistosUsingDb(const edm::ParameterSet& pset,
0014 DQMStore* bei,
0015 SiStripConfigDb* const db,
0016 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken)
0017 : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("OptoScanParameters"), bei, sistrip::OPTO_SCAN),
0018 CommissioningHistosUsingDb(db, tTopoToken, sistrip::OPTO_SCAN),
0019 OptoScanHistograms(pset.getParameter<edm::ParameterSet>("OptoScanParameters"), bei) {
0020 LogTrace(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0021 << " Constructing object...";
0022 skipGainUpdate_ = this->pset().getParameter<bool>("SkipGainUpdate");
0023 if (skipGainUpdate_)
0024 LogTrace(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0025 << " Skipping db update of gain parameters.";
0026
0027 allowSelectiveUpload_ =
0028 this->pset().existsAs<bool>("doSelectiveUpload") ? this->pset().getParameter<bool>("doSelectiveUpload") : false;
0029 if (allowSelectiveUpload_)
0030 LogTrace(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0031 << " Enabling selective upload of gain parameters";
0032 }
0033
0034
0035
0036 OptoScanHistosUsingDb::~OptoScanHistosUsingDb() {
0037 LogTrace(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0038 << " Destructing object...";
0039 }
0040
0041
0042
0043 void OptoScanHistosUsingDb::uploadConfigurations() {
0044 LogTrace(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]";
0045
0046 if (!db()) {
0047 edm::LogError(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0048 << " NULL pointer to SiStripConfigDb interface!"
0049 << " Aborting upload...";
0050 return;
0051 }
0052
0053
0054 SiStripConfigDb::DeviceDescriptionsRange devices = db()->getDeviceDescriptions(LASERDRIVER);
0055 update(devices);
0056 if (doUploadConf()) {
0057 edm::LogVerbatim(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0058 << " Uploading LLD settings to DB...";
0059 db()->uploadDeviceDescriptions();
0060 edm::LogVerbatim(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0061 << " Upload of LLD settings to DB finished!";
0062 } else {
0063 edm::LogWarning(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0064 << " TEST only! No LLD settings will be uploaded to DB...";
0065 }
0066 }
0067
0068
0069
0070 void OptoScanHistosUsingDb::update(SiStripConfigDb::DeviceDescriptionsRange devices) {
0071
0072 uint16_t updated = 0;
0073 SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
0074 for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
0075 if ((*idevice)->getDeviceType() != LASERDRIVER) {
0076 continue;
0077 }
0078
0079
0080 laserdriverDescription* desc = dynamic_cast<laserdriverDescription*>(*idevice);
0081 if (!desc) {
0082 continue;
0083 }
0084
0085
0086 const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
0087
0088
0089 for (uint16_t ichan = 0; ichan < sistrip::CHANS_PER_LLD; ichan++) {
0090
0091 SiStripFecKey fec_key(addr.fecCrate_, addr.fecSlot_, addr.fecRing_, addr.ccuAddr_, addr.ccuChan_, ichan + 1);
0092
0093
0094 Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
0095 if (iter != data(allowSelectiveUpload_).end()) {
0096 OptoScanAnalysis* anal = dynamic_cast<OptoScanAnalysis*>(iter->second);
0097 if (!anal) {
0098 edm::LogError(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0099 << " NULL pointer to analysis object!";
0100 continue;
0101 }
0102
0103 uint16_t gain = anal->gain();
0104 std::stringstream ss;
0105 ss << "[OptoScanHistosUsingDb::" << __func__ << "]"
0106 << " Updating LLD gain/bias settings for crate/crate/FEC/ring/CCU/module/LLD " << fec_key.fecCrate() << "/"
0107 << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan()
0108 << "/" << fec_key.channel() << " from " << static_cast<uint16_t>(desc->getGain(ichan)) << "/"
0109 << static_cast<uint16_t>(desc->getBias(ichan));
0110 if (!skipGainUpdate_)
0111 desc->setGain(ichan, gain);
0112 desc->setBias(ichan, anal->bias()[gain]);
0113 updated++;
0114 ss << " to " << static_cast<uint16_t>(desc->getGain(ichan)) << "/"
0115 << static_cast<uint16_t>(desc->getBias(ichan));
0116 LogTrace(mlDqmClient_) << ss.str();
0117
0118 } else {
0119 if (deviceIsPresent(fec_key)) {
0120 edm::LogWarning(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0121 << " Unable to find FEC key with params crate/FEC/ring/CCU/module/LLD "
0122 << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing()
0123 << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
0124 << fec_key.channel();
0125 }
0126 }
0127 }
0128 }
0129
0130 edm::LogVerbatim(mlDqmClient_) << "[OptoScanHistosUsingDb::" << __func__ << "]"
0131 << " Updated LLD bias/gain settings for " << updated << " modules";
0132 }
0133
0134
0135
0136 void OptoScanHistosUsingDb::create(SiStripConfigDb::AnalysisDescriptionsV& desc, Analysis analysis) {
0137 OptoScanAnalysis* anal = dynamic_cast<OptoScanAnalysis*>(analysis->second);
0138 if (!anal) {
0139 return;
0140 }
0141
0142 SiStripFecKey fec_key(anal->fecKey());
0143 SiStripFedKey fed_key(anal->fedKey());
0144
0145 for (uint16_t iapv = 0; iapv < 2; ++iapv) {
0146
0147 OptoScanAnalysisDescription* tmp;
0148 tmp = new OptoScanAnalysisDescription(anal->baseSlope()[0],
0149 anal->baseSlope()[1],
0150 anal->baseSlope()[2],
0151 anal->baseSlope()[3],
0152 anal->gain(),
0153 anal->bias()[0],
0154 anal->bias()[1],
0155 anal->bias()[2],
0156 anal->bias()[3],
0157 anal->measGain()[0],
0158 anal->measGain()[1],
0159 anal->measGain()[2],
0160 anal->measGain()[3],
0161 anal->zeroLight()[0],
0162 anal->zeroLight()[1],
0163 anal->zeroLight()[2],
0164 anal->zeroLight()[3],
0165 anal->linkNoise()[0],
0166 anal->linkNoise()[1],
0167 anal->linkNoise()[2],
0168 anal->linkNoise()[3],
0169 anal->liftOff()[0],
0170 anal->liftOff()[1],
0171 anal->liftOff()[2],
0172 anal->liftOff()[3],
0173 anal->threshold()[0],
0174 anal->threshold()[1],
0175 anal->threshold()[2],
0176 anal->threshold()[3],
0177 anal->tickHeight()[0],
0178 anal->tickHeight()[1],
0179 anal->tickHeight()[2],
0180 anal->tickHeight()[3],
0181 fec_key.fecCrate(),
0182 fec_key.fecSlot(),
0183 fec_key.fecRing(),
0184 fec_key.ccuAddr(),
0185 fec_key.ccuChan(),
0186 SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0187 db()->dbParams().partitions().begin()->second.partitionName(),
0188 db()->dbParams().partitions().begin()->second.runNumber(),
0189 anal->isValid(),
0190 "",
0191 fed_key.fedId(),
0192 fed_key.feUnit(),
0193 fed_key.feChan(),
0194 fed_key.fedApv());
0195
0196
0197 typedef std::vector<std::string> Strings;
0198 Strings errors = anal->getErrorCodes();
0199 Strings::const_iterator istr = errors.begin();
0200 Strings::const_iterator jstr = errors.end();
0201 for (; istr != jstr; ++istr) {
0202 tmp->addComments(*istr);
0203 }
0204
0205
0206 desc.push_back(tmp);
0207 }
0208 }