File indexing completed on 2024-04-06 12:08:34
0001
0002 #include "DQM/SiStripCommissioningDbClients/interface/VpspScanHistosUsingDb.h"
0003 #include "CondFormats/SiStripObjects/interface/VpspScanAnalysis.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 VpspScanHistosUsingDb::VpspScanHistosUsingDb(const edm::ParameterSet& pset,
0014 DQMStore* bei,
0015 SiStripConfigDb* const db,
0016 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken)
0017 : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("VpspScanParameters"), bei, sistrip::VPSP_SCAN),
0018 CommissioningHistosUsingDb(db, tTopoToken, sistrip::VPSP_SCAN),
0019 VpspScanHistograms(pset.getParameter<edm::ParameterSet>("VpspScanParameters"), bei) {
0020 LogTrace(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
0021 << " Constructing object...";
0022
0023 allowSelectiveUpload_ =
0024 this->pset().existsAs<bool>("doSelectiveUpload") ? this->pset().getParameter<bool>("doSelectiveUpload") : false;
0025 LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0026 << " Selective upload of modules set to : " << allowSelectiveUpload_;
0027 }
0028
0029
0030
0031 VpspScanHistosUsingDb::~VpspScanHistosUsingDb() {
0032 LogTrace(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
0033 << " Destructing object...";
0034 }
0035
0036
0037
0038 void VpspScanHistosUsingDb::uploadConfigurations() {
0039 LogTrace(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]";
0040
0041 if (!db()) {
0042 edm::LogError(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
0043 << " NULL pointer to SiStripConfigDb interface!"
0044 << " Aborting upload...";
0045 return;
0046 }
0047
0048
0049 SiStripConfigDb::DeviceDescriptionsRange devices = db()->getDeviceDescriptions();
0050 update(devices);
0051 if (doUploadConf()) {
0052 edm::LogVerbatim(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
0053 << " Uploading VPSP settings to DB...";
0054 db()->uploadDeviceDescriptions();
0055 edm::LogVerbatim(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
0056 << " Uploaded VPSP settings to DB!";
0057 } else {
0058 edm::LogWarning(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
0059 << " TEST only! No VPSP settings will be uploaded to DB...";
0060 }
0061 LogTrace(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
0062 << " Upload of VPSP settings to DB finished!";
0063 }
0064
0065
0066
0067 void VpspScanHistosUsingDb::update(SiStripConfigDb::DeviceDescriptionsRange devices) {
0068
0069 SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
0070 for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
0071
0072 if ((*idevice)->getDeviceType() != APV25) {
0073 continue;
0074 }
0075
0076
0077 apvDescription* desc = dynamic_cast<apvDescription*>(*idevice);
0078 if (!desc) {
0079 continue;
0080 }
0081
0082
0083 const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
0084
0085
0086 uint16_t ichan = (desc->getAddress() - 0x20) / 2;
0087 uint16_t iapv = (desc->getAddress() - 0x20) % 2;
0088
0089
0090 SiStripFecKey fec_key(addr.fecCrate_, addr.fecSlot_, addr.fecRing_, addr.ccuAddr_, addr.ccuChan_, ichan + 1);
0091
0092
0093 Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
0094 if (iter != data(allowSelectiveUpload_).end()) {
0095 VpspScanAnalysis* anal = dynamic_cast<VpspScanAnalysis*>(iter->second);
0096 if (!anal) {
0097 edm::LogError(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
0098 << " NULL pointer to analysis object!";
0099 continue;
0100 }
0101
0102 std::stringstream ss;
0103 ss << "[VpspScanHistosUsingDb::" << __func__ << "]"
0104 << " Updating VPSP setting for crate/FEC/slot/ring/CCU/LLD/APV " << fec_key.fecCrate() << "/"
0105 << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
0106 << fec_key.channel() << iapv << " from " << static_cast<uint16_t>(desc->getVpsp());
0107 if (iapv == 0) {
0108 desc->setVpsp(anal->vpsp()[0]);
0109 }
0110 if (iapv == 1) {
0111 desc->setVpsp(anal->vpsp()[1]);
0112 }
0113 ss << " to " << static_cast<uint16_t>(desc->getVpsp());
0114 LogTrace(mlDqmClient_) << ss.str();
0115
0116 } else {
0117 if (deviceIsPresent(fec_key)) {
0118 edm::LogWarning(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
0119 << " Unable to find FEC key with params FEC/slot/ring/CCU/LLDchan/APV: "
0120 << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing()
0121 << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
0122 << fec_key.channel() << "/" << iapv + 1;
0123 }
0124 }
0125 }
0126 }
0127
0128
0129
0130 void VpspScanHistosUsingDb::create(SiStripConfigDb::AnalysisDescriptionsV& desc, Analysis analysis) {
0131 VpspScanAnalysis* anal = dynamic_cast<VpspScanAnalysis*>(analysis->second);
0132 if (!anal) {
0133 return;
0134 }
0135
0136 SiStripFecKey fec_key(anal->fecKey());
0137 SiStripFedKey fed_key(anal->fedKey());
0138
0139 for (uint16_t iapv = 0; iapv < 2; ++iapv) {
0140
0141 VpspScanAnalysisDescription* tmp;
0142 tmp = new VpspScanAnalysisDescription(anal->vpsp()[iapv],
0143 anal->adcLevel()[iapv],
0144 anal->fraction()[iapv],
0145 anal->topEdge()[iapv],
0146 anal->bottomEdge()[iapv],
0147 anal->topLevel()[iapv],
0148 anal->bottomLevel()[iapv],
0149 fec_key.fecCrate(),
0150 fec_key.fecSlot(),
0151 fec_key.fecRing(),
0152 fec_key.ccuAddr(),
0153 fec_key.ccuChan(),
0154 SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0155 db()->dbParams().partitions().begin()->second.partitionName(),
0156 db()->dbParams().partitions().begin()->second.runNumber(),
0157 anal->isValid(),
0158 "",
0159 fed_key.fedId(),
0160 fed_key.feUnit(),
0161 fed_key.feChan(),
0162 fed_key.fedApv());
0163
0164
0165 typedef std::vector<std::string> Strings;
0166 Strings errors = anal->getErrorCodes();
0167 Strings::const_iterator istr = errors.begin();
0168 Strings::const_iterator jstr = errors.end();
0169 for (; istr != jstr; ++istr) {
0170 tmp->addComments(*istr);
0171 }
0172
0173
0174 desc.push_back(tmp);
0175 }
0176 }