Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/SiStripCommissioningDbClients/interface/DaqScopeModeHistosUsingDb.h"
0002 #include "CondFormats/SiStripObjects/interface/DaqScopeModeAnalysis.h"
0003 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0004 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0005 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include <iostream>
0008 
0009 using namespace sistrip;
0010 
0011 // -----------------------------------------------------------------------------
0012 DaqScopeModeHistosUsingDb::DaqScopeModeHistosUsingDb(const edm::ParameterSet& pset,
0013                                                      DQMStore* bei,
0014                                                      SiStripConfigDb* const db,
0015                                                      edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken)
0016     : CommissioningHistograms(
0017           pset.getParameter<edm::ParameterSet>("DaqScopeModeParameters"), bei, sistrip::DAQ_SCOPE_MODE),
0018       CommissioningHistosUsingDb(db, tTopoToken, sistrip::DAQ_SCOPE_MODE),
0019       DaqScopeModeHistograms(pset.getParameter<edm::ParameterSet>("DaqScopeModeParameters"), bei) {
0020   LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0021                          << " Constructing object...";
0022   highThreshold_ = this->pset().getParameter<double>("HighThreshold");
0023   lowThreshold_ = this->pset().getParameter<double>("LowThreshold");
0024   LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0025                          << " Set FED zero suppression high/low threshold to " << highThreshold_ << "/"
0026                          << lowThreshold_;
0027   disableBadStrips_ = this->pset().getParameter<bool>("DisableBadStrips");
0028   keepStripsDisabled_ = this->pset().getParameter<bool>("KeepStripsDisabled");
0029   LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0030                          << " Disabling strips: " << disableBadStrips_
0031                          << " ; keeping previously disabled strips: " << keepStripsDisabled_;
0032   allowSelectiveUpload_ =
0033       this->pset().existsAs<bool>("doSelectiveUpload") ? this->pset().getParameter<bool>("doSelectiveUpload") : false;
0034   LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0035                          << " Selective upload of modules set to : " << allowSelectiveUpload_;
0036 
0037   skipPedestalUpdate_ =
0038       this->pset().existsAs<bool>("SkipPedestalUpdate") ? this->pset().getParameter<bool>("SkipPedestalUpdate") : false;
0039   skipTickUpdate_ =
0040       this->pset().existsAs<bool>("SkipTickUpdate") ? this->pset().getParameter<bool>("SkipTickUpdate") : false;
0041   LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0042                          << " Perform pedestal upload set to : " << skipPedestalUpdate_;
0043   LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0044                          << " Perform tick-mark upload set to : " << skipTickUpdate_;
0045 }
0046 
0047 // -----------------------------------------------------------------------------
0048 DaqScopeModeHistosUsingDb::~DaqScopeModeHistosUsingDb() {
0049   LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0050                          << " Destructing object...";
0051 }
0052 
0053 // -----------------------------------------------------------------------------
0054 void DaqScopeModeHistosUsingDb::uploadConfigurations() {
0055   LogTrace(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]";
0056 
0057   if (!db()) {
0058     edm::LogError(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0059                                 << " NULL pointer to SiStripConfigDb interface!"
0060                                 << " Aborting upload...";
0061     return;
0062   }
0063 
0064   // Update FED descriptions with new peds/noise values as well as tick-marks (no PLL delays, for these ones please use the Timing run
0065   SiStripConfigDb::FedDescriptionsRange feds = db()->getFedDescriptions();
0066   update(feds);
0067 
0068   if (doUploadConf()) {
0069     edm::LogVerbatim(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0070                                    << " Uploading FED information to DB...";
0071     db()->uploadFedDescriptions();
0072     edm::LogVerbatim(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0073                                    << " Completed database upload of " << feds.size() << " FED descriptions!";
0074   } else {
0075     edm::LogWarning(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0076                                   << " No FED values will be uploaded to DB...";
0077   }
0078 }
0079 
0080 // -----------------------------------------------------------------------------
0081 void DaqScopeModeHistosUsingDb::update(SiStripConfigDb::FedDescriptionsRange feds) {
0082   // Retrieve FED ids from cabling
0083   auto ids = cabling()->fedIds();
0084 
0085   // Iterate through feds and update fed descriptions
0086   uint16_t updated_peds = 0;
0087   uint16_t updated_ticks = 0;
0088   SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
0089   for (ifed = feds.begin(); ifed != feds.end(); ifed++) {
0090     // If FED id not found in list (from cabling), then continue
0091     if (find(ids.begin(), ids.end(), (*ifed)->getFedId()) == ids.end()) {
0092       continue;
0093     }
0094 
0095     for (uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++) {
0096       // Build FED and FEC keys
0097       const FedChannelConnection& conn = cabling()->fedConnection((*ifed)->getFedId(), ichan);
0098 
0099       if (conn.fecCrate() == sistrip::invalid_ || conn.fecSlot() == sistrip::invalid_ ||
0100           conn.fecRing() == sistrip::invalid_ || conn.ccuAddr() == sistrip::invalid_ ||
0101           conn.ccuChan() == sistrip::invalid_ || conn.lldChannel() == sistrip::invalid_) {
0102         continue;
0103       }
0104 
0105       SiStripFedKey fed_key(conn.fedId(), SiStripFedKey::feUnit(conn.fedCh()), SiStripFedKey::feChan(conn.fedCh()));
0106 
0107       SiStripFecKey fec_key(
0108           conn.fecCrate(), conn.fecSlot(), conn.fecRing(), conn.ccuAddr(), conn.ccuChan(), conn.lldChannel());
0109 
0110       // Locate appropriate analysis object
0111       Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
0112 
0113       if (iter != data(allowSelectiveUpload_).end()) {
0114         // Check if analysis is valid
0115         if (!iter->second->isValid()) {
0116           edm::LogWarning(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0117                                         << " Skipping invalid channel with coordinates: FedKey/Id/Ch: " << hex
0118                                         << setw(8) << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId()
0119                                         << "/" << ichan << " and device with FEC/slot/ring/CCU/LLD "
0120                                         << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing()
0121                                         << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
0122                                         << fec_key.channel();
0123           continue;
0124         }
0125 
0126         DaqScopeModeAnalysis* anal = dynamic_cast<DaqScopeModeAnalysis*>(iter->second);
0127         if (!anal) {
0128           edm::LogError(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0129                                       << " NULL pointer to analysis object!";
0130           continue;
0131         }
0132 
0133         /// Pedestal and noise uploads
0134         if (not skipPedestalUpdate_) {
0135           // Determine the pedestal shift to apply
0136           uint32_t pedshift = 127;
0137           for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
0138             uint32_t pedmin = (uint32_t)anal->pedsMin()[iapv];
0139             pedshift = pedmin < pedshift ? pedmin : pedshift;
0140             std::stringstream ss;
0141             ss << "iapv: " << iapv << " pedsMin()[iapv]: " << anal->pedsMin()[iapv] << " pedmin: " << pedmin
0142                << " pedshift: " << pedshift;
0143             edm::LogWarning(mlDqmClient_) << ss.str();
0144           }
0145 
0146           // Iterate through APVs and strips
0147           for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
0148             for (uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++) {
0149               // Patch added by R.B. (I'm back! ;-), requested by J.F. and S.L. (04/11/2010)
0150               if (anal->peds()[iapv][istr] < 1.) {  //@@ ie, zero
0151                 edm::LogWarning(mlDqmClient_)
0152                     << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0153                     << " Skipping ZERO pedestal value (ie, NO UPLOAD TO DB!) for FedKey/Id/Ch: " << hex << setw(8)
0154                     << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/" << ichan
0155                     << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate() << "/" << fec_key.fecSlot()
0156                     << "/" << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
0157                     << fec_key.channel();
0158                 continue;  //@@ do not upload
0159               }
0160 
0161               // get the information on the strip as it was on the db
0162               Fed9U::Fed9UAddress addr(ichan, iapv, istr);
0163               Fed9U::Fed9UStripDescription temp = (*ifed)->getFedStrips().getStrip(addr);
0164 
0165               // determine whether we need to disable the strip
0166               bool disableStrip = false;
0167               if (keepStripsDisabled_) {
0168                 disableStrip = temp.getDisable();
0169               } else if (disableBadStrips_) {
0170                 DaqScopeModeAnalysis::VInt dead = anal->dead()[iapv];
0171                 if (find(dead.begin(), dead.end(), istr) != dead.end())
0172                   disableStrip = true;
0173                 DaqScopeModeAnalysis::VInt noisy = anal->noisy()[iapv];
0174                 if (find(noisy.begin(), noisy.end(), istr) != noisy.end())
0175                   disableStrip = true;
0176               }
0177 
0178               Fed9U::Fed9UStripDescription data(static_cast<uint32_t>(anal->peds()[iapv][istr] - pedshift),
0179                                                 highThreshold_,
0180                                                 lowThreshold_,
0181                                                 anal->noise()[iapv][istr],
0182                                                 disableStrip);
0183 
0184               std::stringstream ss;
0185               if (data.getDisable() && edm::isDebugEnabled()) {
0186                 ss << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0187                    << " Disabling strip in Fed9UStripDescription object..." << std::endl
0188                    << " for FED id/channel and APV/strip : " << fed_key.fedId() << "/" << fed_key.fedChannel() << " "
0189                    << iapv << "/" << istr << std::endl
0190                    << " and crate/FEC/ring/CCU/module    : " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
0191                    << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << std::endl
0192                    << " from ped/noise/high/low/disable  : " << static_cast<uint16_t>(temp.getPedestal()) << "/"
0193                    << static_cast<uint16_t>(temp.getHighThreshold()) << "/"
0194                    << static_cast<uint16_t>(temp.getLowThreshold()) << "/" << static_cast<uint16_t>(temp.getNoise())
0195                    << "/" << static_cast<uint16_t>(temp.getDisable()) << std::endl;
0196               }
0197 
0198               // update strip inf
0199               (*ifed)->getFedStrips().setStrip(addr, data);
0200 
0201               if (data.getDisable() && edm::isDebugEnabled()) {
0202                 ss << " to ped/noise/high/low/disable    : " << static_cast<uint16_t>(data.getPedestal()) << "/"
0203                    << static_cast<uint16_t>(data.getHighThreshold()) << "/"
0204                    << static_cast<uint16_t>(data.getLowThreshold()) << "/" << static_cast<uint16_t>(data.getNoise())
0205                    << "/" << static_cast<uint16_t>(data.getDisable()) << std::endl;
0206                 LogTrace(mlDqmClient_) << ss.str();
0207               }
0208             }  // end loop on strips
0209           }    // end loop on apvs
0210           updated_peds++;
0211         }
0212 
0213         // if one wants to update the frame finding threhsolds
0214         if (not skipTickUpdate_) {
0215           // Update frame finding threshold
0216           Fed9U::Fed9UAddress addr(ichan);
0217           uint16_t old_threshold = static_cast<uint16_t>((*ifed)->getFrameThreshold(addr));
0218           if (anal->isValid()) {
0219             (*ifed)->setFrameThreshold(addr, anal->frameFindingThreshold());
0220             updated_ticks++;
0221           }
0222           uint16_t new_threshold = static_cast<uint16_t>((*ifed)->getFrameThreshold(addr));
0223 
0224           std::stringstream ss;
0225           ss << "LLD channel : old frame threshold " << old_threshold << " new frame threshold " << new_threshold
0226              << std::endl;
0227           edm::LogWarning(mlDqmClient_) << ss.str();
0228 
0229           // Debug
0230           ss.clear();
0231           ss << "[DaqScopeModeHistosUsingDb::" << __func__ << "]";
0232           if (anal->isValid()) {
0233             ss << " Updating the frame-finding threshold"
0234                << " from " << old_threshold << " to " << new_threshold << " using tick mark base/peak/height "
0235                << anal->base() << "/" << anal->peak() << "/" << anal->height();
0236           } else {
0237             ss << " Cannot update the frame-finding threshold"
0238                << " from " << old_threshold << " to a new value using invalid analysis ";
0239           }
0240           ss << " for crate/FEC/ring/CCU/module/LLD " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
0241              << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << fec_key.channel()
0242              << " and FED id/ch " << fed_key.fedId() << "/" << fed_key.fedChannel();
0243           anal->print(ss);
0244           LogTrace(mlDqmClient_) << ss.str();
0245         }
0246       } else {
0247         if (deviceIsPresent(fec_key)) {
0248           edm::LogWarning(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0249                                         << " Unable to find pedestals/noise for FedKey/Id/Ch: " << hex << setw(8)
0250                                         << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/"
0251                                         << ichan << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate()
0252                                         << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/"
0253                                         << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/" << fec_key.channel();
0254         }
0255       }
0256     }
0257   }
0258 
0259   edm::LogVerbatim(mlDqmClient_) << "[DaqScopeModeHistosUsingDb::" << __func__ << "]"
0260                                  << " Updated FED parameters for pedestal/noise " << updated_peds << " channels"
0261                                  << " Updated FED parameters for frame finding thresholds " << updated_ticks
0262                                  << " channels";
0263 }
0264 
0265 // -----------------------------------------------------------------------------
0266 void DaqScopeModeHistosUsingDb::create(SiStripConfigDb::AnalysisDescriptionsV& desc, Analysis analysis) {
0267   DaqScopeModeAnalysis* anal = dynamic_cast<DaqScopeModeAnalysis*>(analysis->second);
0268   if (!anal) {
0269     return;
0270   }
0271 
0272   SiStripFecKey fec_key(anal->fecKey());
0273   SiStripFedKey fed_key(anal->fedKey());
0274 
0275   for (uint16_t iapv = 0; iapv < 2; ++iapv) {
0276     // Create description for the pedestal table
0277     PedestalsAnalysisDescription* peds_tmp;
0278     peds_tmp = new PedestalsAnalysisDescription(anal->dead()[iapv],
0279                                                 anal->noisy()[iapv],
0280                                                 anal->pedsMean()[iapv],
0281                                                 anal->pedsSpread()[iapv],
0282                                                 anal->noiseMean()[iapv],
0283                                                 anal->noiseSpread()[iapv],
0284                                                 anal->rawMean()[iapv],
0285                                                 anal->rawSpread()[iapv],
0286                                                 anal->pedsMax()[iapv],
0287                                                 anal->pedsMin()[iapv],
0288                                                 anal->noiseMax()[iapv],
0289                                                 anal->noiseMin()[iapv],
0290                                                 anal->rawMax()[iapv],
0291                                                 anal->rawMin()[iapv],
0292                                                 fec_key.fecCrate(),
0293                                                 fec_key.fecSlot(),
0294                                                 fec_key.fecRing(),
0295                                                 fec_key.ccuAddr(),
0296                                                 fec_key.ccuChan(),
0297                                                 SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0298                                                 db()->dbParams().partitions().begin()->second.partitionName(),
0299                                                 db()->dbParams().partitions().begin()->second.runNumber(),
0300                                                 anal->isValid(),
0301                                                 "",
0302                                                 fed_key.fedId(),
0303                                                 fed_key.feUnit(),
0304                                                 fed_key.feChan(),
0305                                                 fed_key.fedApv());
0306 
0307     // Add comments
0308     typedef std::vector<std::string> Strings;
0309     Strings errors = anal->getErrorCodes();
0310     Strings::const_iterator istr = errors.begin();
0311     Strings::const_iterator jstr = errors.end();
0312     for (; istr != jstr; ++istr) {
0313       peds_tmp->addComments(*istr);
0314     }
0315 
0316     // Store description
0317     desc.push_back(peds_tmp);
0318 
0319     // Create description
0320     TimingAnalysisDescription* timing_tmp;
0321     timing_tmp = new TimingAnalysisDescription(-1.,
0322                                                -1.,
0323                                                -1.,
0324                                                anal->height(),
0325                                                anal->base(),
0326                                                anal->peak(),
0327                                                anal->frameFindingThreshold(),
0328                                                -1.,
0329                                                DaqScopeModeAnalysis::tickMarkHeightThreshold_,
0330                                                true,  //@@ APV timing analysis (not FED timing)
0331                                                fec_key.fecCrate(),
0332                                                fec_key.fecSlot(),
0333                                                fec_key.fecRing(),
0334                                                fec_key.ccuAddr(),
0335                                                fec_key.ccuChan(),
0336                                                SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0337                                                db()->dbParams().partitions().begin()->second.partitionName(),
0338                                                db()->dbParams().partitions().begin()->second.runNumber(),
0339                                                anal->isValid(),
0340                                                "",
0341                                                fed_key.fedId(),
0342                                                fed_key.feUnit(),
0343                                                fed_key.feChan(),
0344                                                fed_key.fedApv());
0345 
0346     istr = errors.begin();
0347     jstr = errors.end();
0348     for (; istr != jstr; ++istr) {
0349       timing_tmp->addComments(*istr);
0350     }
0351     desc.push_back(timing_tmp);
0352   }
0353 }