Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:33

0001 #include "DQM/SiStripCommissioningDbClients/interface/CalibrationHistosUsingDb.h"
0002 #include "CondFormats/SiStripObjects/interface/CalibrationAnalysis.h"
0003 #include "CondFormats/SiStripObjects/interface/CalibrationScanAnalysis.h"
0004 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0005 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0006 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include <iostream>
0009 
0010 using namespace sistrip;
0011 
0012 // -----------------------------------------------------------------------------
0013 /** */
0014 std::string getBasePath(const std::string& path) {
0015   return path.substr(0, path.find(std::string(sistrip::root_) + "/") + sizeof(sistrip::root_));
0016 }
0017 
0018 // -----------------------------------------------------------------------------
0019 /** */
0020 CalibrationHistosUsingDb::CalibrationHistosUsingDb(const edm::ParameterSet& pset,
0021                                                    DQMStore* bei,
0022                                                    SiStripConfigDb* const db,
0023                                                    edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken,
0024                                                    const sistrip::RunType& task)
0025     : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("CalibrationParameters"), bei, task),
0026       CommissioningHistosUsingDb(db, tTopoToken, task),
0027       CalibrationHistograms(pset.getParameter<edm::ParameterSet>("CalibrationParameters"), bei, task) {
0028   LogTrace(mlDqmClient_) << "[CalibrationHistosUsingDb::" << __func__ << "]"
0029                          << " Constructing object...";
0030 
0031   // Load and dump the current ISHA/VFS values. This is used by the standalone analysis script
0032   const SiStripConfigDb::DeviceDescriptionsRange& apvDescriptions = db->getDeviceDescriptions(APV25);
0033   for (SiStripConfigDb::DeviceDescriptionsV::const_iterator apv = apvDescriptions.begin(); apv != apvDescriptions.end();
0034        ++apv) {
0035     apvDescription* desc = dynamic_cast<apvDescription*>(*apv);
0036     if (!desc) {
0037       continue;
0038     }
0039     // Retrieve device addresses from device description
0040     const SiStripConfigDb::DeviceAddress& addr = db->deviceAddress(*desc);
0041     std::stringstream bin;
0042     bin << std::setw(1) << std::setfill('0') << addr.fecCrate_;
0043     bin << "." << std::setw(2) << std::setfill('0') << addr.fecSlot_;
0044     bin << "." << std::setw(1) << std::setfill('0') << addr.fecRing_;
0045     bin << "." << std::setw(3) << std::setfill('0') << addr.ccuAddr_;
0046     bin << "." << std::setw(2) << std::setfill('0') << addr.ccuChan_;
0047     bin << "." << desc->getAddress();
0048     LogTrace(mlDqmClient_) << "Present values for ISHA/VFS of APV " << bin.str() << " : "
0049                            << static_cast<uint16_t>(desc->getIsha()) << " " << static_cast<uint16_t>(desc->getVfs());
0050   }
0051 
0052   allowSelectiveUpload_ =
0053       this->pset().existsAs<bool>("doSelectiveUpload") ? this->pset().getParameter<bool>("doSelectiveUpload") : false;
0054   if (allowSelectiveUpload_)
0055     LogTrace(mlDqmClient_) << "[CalibrationHistosUsingDb::" << __func__ << "]"
0056                            << " Enabling selective update of FED parameters.";
0057 }
0058 
0059 // -----------------------------------------------------------------------------
0060 /** */
0061 CalibrationHistosUsingDb::~CalibrationHistosUsingDb() {
0062   LogTrace(mlDqmClient_) << "[CalibrationHistosUsingDb::" << __func__ << "]"
0063                          << " Destructing object...";
0064 }
0065 
0066 // -----------------------------------------------------------------------------
0067 /** */
0068 void CalibrationHistosUsingDb::uploadConfigurations() {
0069   if (!db()) {
0070     edm::LogWarning(mlDqmClient_) << "[CalibrationHistosUsingDb::" << __func__ << "]"
0071                                   << " NULL pointer to SiStripConfigDb interface!"
0072                                   << " Aborting upload...";
0073     return;
0074   }
0075 
0076   if (task() == sistrip::CALIBRATION or task() == sistrip::CALIBRATION_DECO) {
0077     edm::LogWarning(mlDqmClient_)
0078         << "[CalibrationHistosUsingDb::" << __func__ << "]"
0079         << " Nothing has to be uploaded to the SiStripConfigDb for CALIBRATION_SCAN or CALIBRATION_SCAN_DECO run-types"
0080         << " Aborting upload...";
0081     return;
0082   } else if (task() == sistrip::CALIBRATION_SCAN or task() == sistrip::CALIBRATION_SCAN_DECO) {
0083     // Update all APV device descriptions with new ISHA and VFS settings
0084     SiStripConfigDb::DeviceDescriptionsRange devices = db()->getDeviceDescriptions(APV25);
0085     update(devices);
0086     if (doUploadConf()) {
0087       edm::LogVerbatim(mlDqmClient_) << "[CalibrationHistosUsingDb::" << __func__ << "]"
0088                                      << " Uploading ISHA/VFS settings to DB...";
0089       db()->uploadDeviceDescriptions();
0090       edm::LogVerbatim(mlDqmClient_) << "[CalibrationHistosUsingDb::" << __func__ << "]"
0091                                      << " Uploaded ISHA/VFS settings to DB!";
0092     } else {
0093       edm::LogWarning(mlDqmClient_) << "[CalibrationHistosUsingDb::" << __func__ << "]"
0094                                     << " TEST only! No ISHA/VFS settings will be uploaded to DB...";
0095     }
0096 
0097     LogTrace(mlDqmClient_) << "[CalibrationHistosUsingDb::" << __func__ << "]"
0098                            << " Upload of ISHA/VFS settings to DB finished!";
0099   }
0100 }
0101 
0102 // -----------------------------------------------------------------------------
0103 void CalibrationHistosUsingDb::update(SiStripConfigDb::DeviceDescriptionsRange& devices) {
0104   if (task() == sistrip::CALIBRATION or task() == sistrip::CALIBRATION_DECO) {
0105     edm::LogWarning(mlDqmClient_)
0106         << "[CalibrationHistosUsingDb::" << __func__ << "]"
0107         << " Nothing has to be uploaded to the SiStripConfigDb for CALIBRATION_SCAN or CALIBRATION_SCAN_DECO run-type"
0108         << " Aborting upload...";
0109     return;
0110   } else if (task() == sistrip::CALIBRATION_SCAN or task() == sistrip::CALIBRATION_SCAN_DECO) {
0111     // Iterate through devices and update device descriptions
0112     SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
0113     for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
0114       // Check device type
0115       if ((*idevice)->getDeviceType() != APV25) {
0116         continue;
0117       }
0118       // Cast to retrieve appropriate description object
0119       apvDescription* desc = dynamic_cast<apvDescription*>(*idevice);
0120       if (!desc) {
0121         continue;
0122       }
0123       // Retrieve the device address from device description
0124       const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
0125 
0126       // Retrieve LLD channel and APV numbers
0127       uint16_t ichan = (desc->getAddress() - 0x20) / 2;
0128       uint16_t iapv = (desc->getAddress() - 0x20) % 2;
0129 
0130       // Construct key from device description
0131       SiStripFecKey fec_key(addr.fecCrate_, addr.fecSlot_, addr.fecRing_, addr.ccuAddr_, addr.ccuChan_, ichan + 1);
0132 
0133       // Iterate through all channels and extract LLD settings
0134       Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
0135       if (iter != data(allowSelectiveUpload_).end()) {
0136         CalibrationScanAnalysis* anal = dynamic_cast<CalibrationScanAnalysis*>(iter->second);
0137 
0138         if (!anal) {
0139           edm::LogError(mlDqmClient_) << "[CalibrationHistosUsingDb::" << __func__ << "]"
0140                                       << " NULL pointer to analysis object!";
0141           continue;
0142         }
0143 
0144         std::stringstream ss;
0145         ss << "[CalibrationHistosUsingDb::" << __func__ << "]"
0146            << " Updating ISHA and VFS setting for FECCrate/FECSlot/FECRing/CCUAddr/LLD/APV " << fec_key.fecCrate()
0147            << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/"
0148            << fec_key.ccuChan() << "/" << fec_key.channel() << iapv << " from ISHA "
0149            << static_cast<uint16_t>(desc->getIsha()) << " and VFS " << static_cast<uint16_t>(desc->getVfs());
0150         if (iapv == 0) {
0151           desc->setIsha(anal->bestISHA()[0]);
0152         }
0153         if (iapv == 1) {
0154           desc->setIsha(anal->bestISHA()[1]);
0155         }
0156         if (iapv == 0) {
0157           desc->setVfs(anal->bestVFS()[0]);
0158         }
0159         if (iapv == 1) {
0160           desc->setVfs(anal->bestVFS()[1]);
0161         }
0162         ss << " to ISHA " << static_cast<uint16_t>(desc->getIsha()) << " and VFS "
0163            << static_cast<uint16_t>(desc->getVfs());
0164         edm::LogWarning(mlDqmClient_) << ss.str();
0165       } else {
0166         if (deviceIsPresent(fec_key)) {
0167           edm::LogWarning(mlDqmClient_) << "[CalibrationHistosUsingDb::" << __func__ << "]"
0168                                         << " Unable to find FEC key with params FEC/slot/ring/CCU/LLDchan/APV: "
0169                                         << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing()
0170                                         << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
0171                                         << fec_key.channel() << "/" << iapv + 1;
0172         }
0173       }
0174     }
0175   }
0176 }
0177 
0178 // -----------------------------------------------------------------------------
0179 void CalibrationHistosUsingDb::create(SiStripConfigDb::AnalysisDescriptionsV& desc, Analysis analysis) {
0180   if (task() == sistrip::CALIBRATION or
0181       task() == sistrip::CALIBRATION_DECO) {  // calibration run --> pulse shape measurement
0182 
0183     CalibrationAnalysis* anal = dynamic_cast<CalibrationAnalysis*>(analysis->second);
0184     if (!anal) {
0185       return;
0186     }
0187 
0188     SiStripFecKey fec_key(anal->fecKey());
0189     SiStripFedKey fed_key(anal->fedKey());
0190 
0191     for (uint16_t iapv = 0; iapv < 2; ++iapv) {
0192       // Create description table with placeholder values for isha and vfs
0193       CalibrationAnalysisDescription* tmp;
0194       tmp = new CalibrationAnalysisDescription(anal->amplitudeMean()[iapv],
0195                                                anal->tailMean()[iapv],
0196                                                anal->riseTimeMean()[iapv],
0197                                                anal->decayTimeMean()[iapv],
0198                                                anal->smearingMean()[iapv],
0199                                                anal->chi2Mean()[iapv],
0200                                                anal->deconvMode(),
0201                                                fec_key.fecCrate(),
0202                                                fec_key.fecSlot(),
0203                                                fec_key.fecRing(),
0204                                                fec_key.ccuAddr(),
0205                                                fec_key.ccuChan(),
0206                                                SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0207                                                db()->dbParams().partitions().begin()->second.partitionName(),
0208                                                db()->dbParams().partitions().begin()->second.runNumber(),
0209                                                anal->isValid(),
0210                                                "",
0211                                                fed_key.fedId(),
0212                                                fed_key.feUnit(),
0213                                                fed_key.feChan(),
0214                                                fed_key.fedApv(),
0215                                                anal->calChan(),
0216                                                -1,
0217                                                -1);
0218 
0219       // Add comments
0220       typedef std::vector<std::string> Strings;
0221       Strings errors = anal->getErrorCodes();
0222       Strings::const_iterator istr = errors.begin();
0223       Strings::const_iterator jstr = errors.end();
0224       for (; istr != jstr; ++istr) {
0225         tmp->addComments(*istr);
0226       }
0227       // Store description
0228       desc.push_back(tmp);
0229     }
0230   } else if (task() == sistrip::CALIBRATION_SCAN or task() == sistrip::CALIBRATION_SCAN_DECO) {
0231     CalibrationScanAnalysis* anal = dynamic_cast<CalibrationScanAnalysis*>(analysis->second);
0232     if (!anal) {
0233       return;
0234     }
0235 
0236     SiStripFecKey fec_key(anal->fecKey());
0237     SiStripFedKey fed_key(anal->fedKey());
0238 
0239     for (uint16_t iapv = 0; iapv < 2; ++iapv) {
0240       // Create description table with placeholder values for isha and vfs
0241       CalibrationAnalysisDescription* tmp;
0242       tmp = new CalibrationAnalysisDescription(anal->tunedAmplitude()[iapv],
0243                                                anal->tunedTail()[iapv],
0244                                                anal->tunedRiseTime()[iapv],
0245                                                anal->tunedDecayTime()[iapv],
0246                                                anal->tunedSmearing()[iapv],
0247                                                anal->tunedChi2()[iapv],
0248                                                anal->deconvMode(),
0249                                                fec_key.fecCrate(),
0250                                                fec_key.fecSlot(),
0251                                                fec_key.fecRing(),
0252                                                fec_key.ccuAddr(),
0253                                                fec_key.ccuChan(),
0254                                                SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0255                                                db()->dbParams().partitions().begin()->second.partitionName(),
0256                                                db()->dbParams().partitions().begin()->second.runNumber(),
0257                                                anal->isValid(),
0258                                                "",
0259                                                fed_key.fedId(),
0260                                                fed_key.feUnit(),
0261                                                fed_key.feChan(),
0262                                                fed_key.fedApv(),
0263                                                -1,
0264                                                anal->tunedISHA()[iapv],
0265                                                anal->tunedVFS()[iapv]);
0266 
0267       // Add comments
0268       typedef std::vector<std::string> Strings;
0269       Strings errors = anal->getErrorCodes();
0270       Strings::const_iterator istr = errors.begin();
0271       Strings::const_iterator jstr = errors.end();
0272       for (; istr != jstr; ++istr) {
0273         tmp->addComments(*istr);
0274       }
0275       // Store description
0276       desc.push_back(tmp);
0277     }
0278   }
0279 }