Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:34

0001 
0002 #include "DQM/SiStripCommissioningDbClients/interface/NoiseHistosUsingDb.h"
0003 #include "CondFormats/SiStripObjects/interface/NoiseAnalysis.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 NoiseHistosUsingDb::NoiseHistosUsingDb(const edm::ParameterSet& pset,
0015                                        DQMStore* bei,
0016                                        SiStripConfigDb* const db,
0017                                        edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken)
0018     : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("NoiseParameters"), bei, sistrip::NOISE),
0019       CommissioningHistosUsingDb(db, tTopoToken, sistrip::NOISE),
0020       NoiseHistograms(pset.getParameter<edm::ParameterSet>("NoiseParameters"), bei) {
0021   LogTrace(mlDqmClient_) << "[NoiseHistosUsingDb::" << __func__ << "]"
0022                          << " Constructing object...";
0023 }
0024 
0025 // -----------------------------------------------------------------------------
0026 /** */
0027 NoiseHistosUsingDb::~NoiseHistosUsingDb() {
0028   LogTrace(mlDqmClient_) << "[NoiseHistosUsingDb::" << __func__ << "]"
0029                          << " Destructing object...";
0030 }
0031 
0032 // -----------------------------------------------------------------------------
0033 /** */
0034 void NoiseHistosUsingDb::uploadConfigurations() {
0035   LogTrace(mlDqmClient_) << "[NoiseHistosUsingDb::" << __func__ << "]";
0036 
0037   if (!db()) {
0038     edm::LogError(mlDqmClient_) << "[NoiseHistosUsingDb::" << __func__ << "]"
0039                                 << " NULL pointer to SiStripConfigDb interface!"
0040                                 << " Aborting upload...";
0041     return;
0042   }
0043 
0044   // Update FED descriptions with new peds/noise values
0045   SiStripConfigDb::FedDescriptionsRange feds = db()->getFedDescriptions();
0046   update(feds);
0047   if (doUploadConf()) {
0048     edm::LogVerbatim(mlDqmClient_) << "[NoiseHistosUsingDb::" << __func__ << "]"
0049                                    << " Uploading pedestals/noise to DB...";
0050     db()->uploadFedDescriptions();
0051     edm::LogVerbatim(mlDqmClient_) << "[NoiseHistosUsingDb::" << __func__ << "]"
0052                                    << " Completed database upload of " << feds.size() << " FED descriptions!";
0053   } else {
0054     edm::LogWarning(mlDqmClient_) << "[NoiseHistosUsingDb::" << __func__ << "]"
0055                                   << " TEST only! No pedestals/noise values will be uploaded to DB...";
0056   }
0057 }
0058 
0059 // -----------------------------------------------------------------------------
0060 /** */
0061 void NoiseHistosUsingDb::update(SiStripConfigDb::FedDescriptionsRange feds) {
0062   // Iterate through feds and update fed descriptions
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       // Build FED and FEC keys
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       // Locate appropriate analysis object
0079       Analyses::const_iterator iter = data().find(fec_key.key());
0080       if (iter != data().end()) {
0081         // Check if analysis is valid
0082         if (!iter->second->isValid()) {
0083           continue;
0084         }
0085 
0086         NoiseAnalysis* anal = dynamic_cast<NoiseAnalysis*>(iter->second);
0087         if (!anal) {
0088           edm::LogError(mlDqmClient_) << "[NoiseHistosUsingDb::" << __func__ << "]"
0089                                       << " NULL pointer to analysis object!";
0090           continue;
0091         }
0092 
0093         // Iterate through APVs and strips
0094         for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
0095           for (uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++) {
0096             constexpr float high_threshold = 5.;
0097             constexpr float low_threshold = 2.;
0098             constexpr bool disable_strip = false;
0099             Fed9U::Fed9UStripDescription data(static_cast<uint32_t>(anal->peds()[iapv][istr]),
0100                                               high_threshold,
0101                                               low_threshold,
0102                                               anal->noise()[iapv][istr],
0103                                               disable_strip);
0104             Fed9U::Fed9UAddress addr(ichan, iapv, istr);
0105             (*ifed)->getFedStrips().setStrip(addr, data);
0106           }
0107         }
0108         updated++;
0109 
0110       } else {
0111         edm::LogWarning(mlDqmClient_) << "[NoiseHistosUsingDb::" << __func__ << "]"
0112                                       << " Unable to find pedestals/noise for FedKey/Id/Ch: " << hex << setw(8)
0113                                       << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/"
0114                                       << ichan << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate() << "/"
0115                                       << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/" << fec_key.ccuAddr()
0116                                       << "/" << fec_key.ccuChan() << "/" << fec_key.channel();
0117       }
0118     }
0119   }
0120 
0121   edm::LogVerbatim(mlDqmClient_) << "[NoiseHistosUsingDb::" << __func__ << "]"
0122                                  << " Updated FED pedestals/noise for " << updated << " channels";
0123 }
0124 
0125 // -----------------------------------------------------------------------------
0126 /** */
0127 void NoiseHistosUsingDb::create(SiStripConfigDb::AnalysisDescriptionsV& desc, Analysis analysis) {
0128   NoiseAnalysis* anal = dynamic_cast<NoiseAnalysis*>(analysis->second);
0129   if (!anal) {
0130     return;
0131   }
0132 
0133   SiStripFecKey fec_key(anal->fecKey());
0134   SiStripFedKey fed_key(anal->fedKey());
0135 
0136   for (uint16_t iapv = 0; iapv < 2; ++iapv) {
0137     // Create description
0138     PedestalsAnalysisDescription* tmp;
0139     tmp = new PedestalsAnalysisDescription(anal->dead()[iapv],
0140                                            anal->noisy()[iapv],
0141                                            anal->pedsMean()[iapv],
0142                                            anal->pedsSpread()[iapv],
0143                                            anal->noiseMean()[iapv],
0144                                            anal->noiseSpread()[iapv],
0145                                            anal->rawMean()[iapv],
0146                                            anal->rawSpread()[iapv],
0147                                            anal->pedsMax()[iapv],
0148                                            anal->pedsMin()[iapv],
0149                                            anal->noiseMax()[iapv],
0150                                            anal->noiseMin()[iapv],
0151                                            anal->rawMax()[iapv],
0152                                            anal->rawMin()[iapv],
0153                                            fec_key.fecCrate(),
0154                                            fec_key.fecSlot(),
0155                                            fec_key.fecRing(),
0156                                            fec_key.ccuAddr(),
0157                                            fec_key.ccuChan(),
0158                                            SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0159                                            db()->dbParams().partitions().begin()->second.partitionName(),
0160                                            db()->dbParams().partitions().begin()->second.runNumber(),
0161                                            anal->isValid(),
0162                                            "",
0163                                            fed_key.fedId(),
0164                                            fed_key.feUnit(),
0165                                            fed_key.feChan(),
0166                                            fed_key.fedApv());
0167 
0168     // Add comments
0169     typedef std::vector<std::string> Strings;
0170     Strings errors = anal->getErrorCodes();
0171     Strings::const_iterator istr = errors.begin();
0172     Strings::const_iterator jstr = errors.end();
0173     for (; istr != jstr; ++istr) {
0174       tmp->addComments(*istr);
0175     }
0176 
0177     // Store description
0178     desc.push_back(tmp);
0179   }
0180 }