Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 #include "DQM/SiStripCommissioningDbClients/interface/PedestalsHistosUsingDb.h"
0003 #include "CondFormats/SiStripObjects/interface/PedestalsAnalysis.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 PedestalsHistosUsingDb::PedestalsHistosUsingDb(const edm::ParameterSet& pset,
0015                                                DQMStore* bei,
0016                                                SiStripConfigDb* const db,
0017                                                edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken)
0018     : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("PedestalsParameters"), bei, sistrip::PEDESTALS),
0019       CommissioningHistosUsingDb(db, tTopoToken, sistrip::PEDESTALS),
0020       PedestalsHistograms(pset.getParameter<edm::ParameterSet>("PedestalsParameters"), bei) {
0021   LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0022                          << " Constructing object...";
0023   highThreshold_ = this->pset().getParameter<double>("HighThreshold");
0024   lowThreshold_ = this->pset().getParameter<double>("LowThreshold");
0025   LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0026                          << " Set FED zero suppression high/low threshold to " << highThreshold_ << "/"
0027                          << lowThreshold_;
0028   disableBadStrips_ = this->pset().getParameter<bool>("DisableBadStrips");
0029   keepStripsDisabled_ = this->pset().getParameter<bool>("KeepStripsDisabled");
0030   LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0031                          << " Disabling strips: " << disableBadStrips_
0032                          << " ; keeping previously disabled strips: " << keepStripsDisabled_;
0033 
0034   allowSelectiveUpload_ =
0035       this->pset().existsAs<bool>("doSelectiveUpload") ? this->pset().getParameter<bool>("doSelectiveUpload") : false;
0036   LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0037                          << " Selective upload of modules set to : " << allowSelectiveUpload_;
0038 }
0039 
0040 // -----------------------------------------------------------------------------
0041 /** */
0042 PedestalsHistosUsingDb::~PedestalsHistosUsingDb() {
0043   LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0044                          << " Destructing object...";
0045 }
0046 
0047 // -----------------------------------------------------------------------------
0048 /** */
0049 void PedestalsHistosUsingDb::uploadConfigurations() {
0050   LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]";
0051 
0052   if (!db()) {
0053     edm::LogError(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0054                                 << " NULL pointer to SiStripConfigDb interface!"
0055                                 << " Aborting upload...";
0056     return;
0057   }
0058 
0059   // Update FED descriptions with new peds/noise values
0060   SiStripConfigDb::FedDescriptionsRange feds = db()->getFedDescriptions();
0061   update(feds);
0062   if (doUploadConf()) {
0063     edm::LogVerbatim(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0064                                    << " Uploading pedestals/noise to DB...";
0065     db()->uploadFedDescriptions();
0066     edm::LogVerbatim(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0067                                    << " Completed database upload of " << feds.size() << " FED descriptions!";
0068   } else {
0069     edm::LogWarning(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0070                                   << " TEST! No pedestals/noise values will be uploaded to DB...";
0071   }
0072 }
0073 
0074 // -----------------------------------------------------------------------------
0075 /** */
0076 void PedestalsHistosUsingDb::update(SiStripConfigDb::FedDescriptionsRange feds) {
0077   // Iterate through feds and update fed descriptions
0078   uint16_t updated = 0;
0079   SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
0080   for (ifed = feds.begin(); ifed != feds.end(); ifed++) {
0081     for (uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++) {
0082       // Build FED and FEC keys
0083       const FedChannelConnection& conn = cabling()->fedConnection((*ifed)->getFedId(), ichan);
0084       if (conn.fecCrate() == sistrip::invalid_ || conn.fecSlot() == sistrip::invalid_ ||
0085           conn.fecRing() == sistrip::invalid_ || conn.ccuAddr() == sistrip::invalid_ ||
0086           conn.ccuChan() == sistrip::invalid_ || conn.lldChannel() == sistrip::invalid_) {
0087         continue;
0088       }
0089       SiStripFedKey fed_key(conn.fedId(), SiStripFedKey::feUnit(conn.fedCh()), SiStripFedKey::feChan(conn.fedCh()));
0090       SiStripFecKey fec_key(
0091           conn.fecCrate(), conn.fecSlot(), conn.fecRing(), conn.ccuAddr(), conn.ccuChan(), conn.lldChannel());
0092 
0093       // Locate appropriate analysis object
0094       Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
0095       if (iter != data(allowSelectiveUpload_).end()) {
0096         // Check if analysis is valid
0097         if (!iter->second->isValid()) {
0098           continue;
0099         }
0100 
0101         PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>(iter->second);
0102         if (!anal) {
0103           edm::LogError(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0104                                       << " NULL pointer to analysis object!";
0105           continue;
0106         }
0107 
0108         // Determine the pedestal shift to apply
0109         uint32_t pedshift = 127;
0110         for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
0111           uint32_t pedmin = (uint32_t)anal->pedsMin()[iapv];
0112           pedshift = pedmin < pedshift ? pedmin : pedshift;
0113           std::stringstream ss;
0114           ss << "iapv: " << iapv << " pedsMin()[iapv]: " << anal->pedsMin()[iapv] << " pedmin: " << pedmin
0115              << " pedshift: " << pedshift;
0116           edm::LogWarning(mlDqmClient_) << ss.str();
0117         }
0118 
0119         // Iterate through APVs and strips
0120         for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
0121           for (uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++) {
0122             // get the information on the strip as it was on the db
0123             Fed9U::Fed9UAddress addr(ichan, iapv, istr);
0124             Fed9U::Fed9UStripDescription temp = (*ifed)->getFedStrips().getStrip(addr);
0125 
0126             if (anal->peds()[iapv][istr] < 1.) {  //@@ ie, zero
0127               edm::LogWarning(mlDqmClient_)
0128                   << "[PedestalsHistosUsingDb::" << __func__ << "]"
0129                   << " Skipping ZERO pedestal value (ie, NO UPLOAD TO DB!) for FedKey/Id/Ch: " << hex << setw(8)
0130                   << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/" << ichan
0131                   << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
0132                   << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
0133                   << fec_key.channel();
0134               continue;  //@@ do not upload
0135             }
0136 
0137             // determine whether we need to disable the strip
0138             bool disableStrip = false;
0139             if (keepStripsDisabled_) {
0140               disableStrip = temp.getDisable();
0141             } else if (disableBadStrips_) {
0142               PedestalsAnalysis::VInt dead = anal->dead()[iapv];
0143               if (find(dead.begin(), dead.end(), istr) != dead.end())
0144                 disableStrip = true;
0145               PedestalsAnalysis::VInt noisy = anal->noisy()[iapv];
0146               if (find(noisy.begin(), noisy.end(), istr) != noisy.end())
0147                 disableStrip = true;
0148             }
0149 
0150             Fed9U::Fed9UStripDescription data(static_cast<uint32_t>(anal->peds()[iapv][istr] - pedshift),
0151                                               highThreshold_,
0152                                               lowThreshold_,
0153                                               anal->noise()[iapv][istr],
0154                                               disableStrip);
0155 
0156             std::stringstream ss;
0157             if (data.getDisable() && edm::isDebugEnabled()) {
0158               ss << "[PedestalsHistosUsingDb::" << __func__ << "]"
0159                  << " Disabling strip in Fed9UStripDescription object..." << std::endl
0160                  << " for FED id/channel and APV/strip : " << fed_key.fedId() << "/" << fed_key.fedChannel() << " "
0161                  << iapv << "/" << istr << std::endl
0162                  << " and crate/FEC/ring/CCU/module    : " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
0163                  << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << std::endl
0164                  << " from ped/noise/high/low/disable  : " << static_cast<uint16_t>(temp.getPedestal()) << "/"
0165                  << static_cast<uint16_t>(temp.getHighThreshold()) << "/"
0166                  << static_cast<uint16_t>(temp.getLowThreshold()) << "/" << static_cast<uint16_t>(temp.getNoise())
0167                  << "/" << static_cast<uint16_t>(temp.getDisable()) << std::endl;
0168             }
0169             (*ifed)->getFedStrips().setStrip(addr, data);
0170             if (data.getDisable() && edm::isDebugEnabled()) {
0171               ss << " to ped/noise/high/low/disable    : " << static_cast<uint16_t>(data.getPedestal()) << "/"
0172                  << static_cast<uint16_t>(data.getHighThreshold()) << "/"
0173                  << static_cast<uint16_t>(data.getLowThreshold()) << "/" << static_cast<uint16_t>(data.getNoise())
0174                  << "/" << static_cast<uint16_t>(data.getDisable()) << std::endl;
0175               LogTrace(mlDqmClient_) << ss.str();
0176             }
0177 
0178           }  // end loop on strips
0179         }    // end loop on apvs
0180         updated++;
0181 
0182       } else {
0183         if (deviceIsPresent(fec_key)) {
0184           edm::LogWarning(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0185                                         << " Unable to find pedestals/noise for FedKey/Id/Ch: " << hex << setw(8)
0186                                         << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/"
0187                                         << ichan << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate()
0188                                         << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/"
0189                                         << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/" << fec_key.channel();
0190         }
0191       }
0192     }
0193   }
0194 
0195   edm::LogVerbatim(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0196                                  << " Updated FED pedestals/noise for " << updated << " channels";
0197 }
0198 
0199 // -----------------------------------------------------------------------------
0200 /** */
0201 void PedestalsHistosUsingDb::create(SiStripConfigDb::AnalysisDescriptionsV& desc, Analysis analysis) {
0202   PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>(analysis->second);
0203   if (!anal) {
0204     return;
0205   }
0206 
0207   SiStripFecKey fec_key(anal->fecKey());
0208   SiStripFedKey fed_key(anal->fedKey());
0209 
0210   for (uint16_t iapv = 0; iapv < 2; ++iapv) {
0211     // Create description
0212     PedestalsAnalysisDescription* tmp;
0213     tmp = new PedestalsAnalysisDescription(anal->dead()[iapv],
0214                                            anal->noisy()[iapv],
0215                                            anal->pedsMean()[iapv],
0216                                            anal->pedsSpread()[iapv],
0217                                            anal->noiseMean()[iapv],
0218                                            anal->noiseSpread()[iapv],
0219                                            anal->rawMean()[iapv],
0220                                            anal->rawSpread()[iapv],
0221                                            anal->pedsMax()[iapv],
0222                                            anal->pedsMin()[iapv],
0223                                            anal->noiseMax()[iapv],
0224                                            anal->noiseMin()[iapv],
0225                                            anal->rawMax()[iapv],
0226                                            anal->rawMin()[iapv],
0227                                            fec_key.fecCrate(),
0228                                            fec_key.fecSlot(),
0229                                            fec_key.fecRing(),
0230                                            fec_key.ccuAddr(),
0231                                            fec_key.ccuChan(),
0232                                            SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0233                                            db()->dbParams().partitions().begin()->second.partitionName(),
0234                                            db()->dbParams().partitions().begin()->second.runNumber(),
0235                                            anal->isValid(),
0236                                            "",
0237                                            fed_key.fedId(),
0238                                            fed_key.feUnit(),
0239                                            fed_key.feChan(),
0240                                            fed_key.fedApv());
0241 
0242     // Add comments
0243     typedef std::vector<std::string> Strings;
0244     Strings errors = anal->getErrorCodes();
0245     Strings::const_iterator istr = errors.begin();
0246     Strings::const_iterator jstr = errors.end();
0247     for (; istr != jstr; ++istr) {
0248       tmp->addComments(*istr);
0249     }
0250 
0251     // Store description
0252     desc.push_back(tmp);
0253   }
0254 }