Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

#include "DQM/SiStripCommissioningDbClients/interface/VpspScanHistosUsingDb.h"
#include "CondFormats/SiStripObjects/interface/VpspScanAnalysis.h"
#include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
#include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <iostream>

using namespace sistrip;

// -----------------------------------------------------------------------------
/** */
VpspScanHistosUsingDb::VpspScanHistosUsingDb(const edm::ParameterSet& pset,
                                             DQMStore* bei,
                                             SiStripConfigDb* const db,
                                             edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken)
    : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("VpspScanParameters"), bei, sistrip::VPSP_SCAN),
      CommissioningHistosUsingDb(db, tTopoToken, sistrip::VPSP_SCAN),
      VpspScanHistograms(pset.getParameter<edm::ParameterSet>("VpspScanParameters"), bei) {
  LogTrace(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
                         << " Constructing object...";

  allowSelectiveUpload_ =
      this->pset().existsAs<bool>("doSelectiveUpload") ? this->pset().getParameter<bool>("doSelectiveUpload") : false;
  LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
                         << " Selective upload of modules set to : " << allowSelectiveUpload_;
}

// -----------------------------------------------------------------------------
/** */
VpspScanHistosUsingDb::~VpspScanHistosUsingDb() {
  LogTrace(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
                         << " Destructing object...";
}

// -----------------------------------------------------------------------------
/** */
void VpspScanHistosUsingDb::uploadConfigurations() {
  LogTrace(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]";

  if (!db()) {
    edm::LogError(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
                                << " NULL pointer to SiStripConfigDb interface!"
                                << " Aborting upload...";
    return;
  }

  // Update all APV device descriptions with new VPSP settings
  SiStripConfigDb::DeviceDescriptionsRange devices = db()->getDeviceDescriptions();
  update(devices);
  if (doUploadConf()) {
    edm::LogVerbatim(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
                                   << " Uploading VPSP settings to DB...";
    db()->uploadDeviceDescriptions();
    edm::LogVerbatim(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
                                   << " Uploaded VPSP settings to DB!";
  } else {
    edm::LogWarning(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
                                  << " TEST only! No VPSP settings will be uploaded to DB...";
  }
  LogTrace(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
                         << " Upload of VPSP settings to DB finished!";
}

// -----------------------------------------------------------------------------
/** */
void VpspScanHistosUsingDb::update(SiStripConfigDb::DeviceDescriptionsRange devices) {
  // Iterate through devices and update device descriptions
  SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
  for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
    // Check device type
    if ((*idevice)->getDeviceType() != APV25) {
      continue;
    }

    // Cast to retrieve appropriate description object
    apvDescription* desc = dynamic_cast<apvDescription*>(*idevice);
    if (!desc) {
      continue;
    }

    // Retrieve device addresses from device description
    const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);

    // Retrieve LLD channel and APV numbers
    uint16_t ichan = (desc->getAddress() - 0x20) / 2;
    uint16_t iapv = (desc->getAddress() - 0x20) % 2;

    // Construct key from device description
    SiStripFecKey fec_key(addr.fecCrate_, addr.fecSlot_, addr.fecRing_, addr.ccuAddr_, addr.ccuChan_, ichan + 1);

    // Iterate through all channels and extract LLD settings
    Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
    if (iter != data(allowSelectiveUpload_).end()) {
      VpspScanAnalysis* anal = dynamic_cast<VpspScanAnalysis*>(iter->second);
      if (!anal) {
        edm::LogError(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
                                    << " NULL pointer to analysis object!";
        continue;
      }

      std::stringstream ss;
      ss << "[VpspScanHistosUsingDb::" << __func__ << "]"
         << " Updating VPSP setting for crate/FEC/slot/ring/CCU/LLD/APV " << fec_key.fecCrate() << "/"
         << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
         << fec_key.channel() << iapv << " from " << static_cast<uint16_t>(desc->getVpsp());
      if (iapv == 0) {
        desc->setVpsp(anal->vpsp()[0]);
      }
      if (iapv == 1) {
        desc->setVpsp(anal->vpsp()[1]);
      }
      ss << " to " << static_cast<uint16_t>(desc->getVpsp());
      LogTrace(mlDqmClient_) << ss.str();

    } else {
      if (deviceIsPresent(fec_key)) {
        edm::LogWarning(mlDqmClient_) << "[VpspScanHistosUsingDb::" << __func__ << "]"
                                      << " Unable to find FEC key with params FEC/slot/ring/CCU/LLDchan/APV: "
                                      << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing()
                                      << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
                                      << fec_key.channel() << "/" << iapv + 1;
      }
    }
  }
}

// -----------------------------------------------------------------------------
/** */
void VpspScanHistosUsingDb::create(SiStripConfigDb::AnalysisDescriptionsV& desc, Analysis analysis) {
  VpspScanAnalysis* anal = dynamic_cast<VpspScanAnalysis*>(analysis->second);
  if (!anal) {
    return;
  }

  SiStripFecKey fec_key(anal->fecKey());
  SiStripFedKey fed_key(anal->fedKey());

  for (uint16_t iapv = 0; iapv < 2; ++iapv) {
    // Create description
    VpspScanAnalysisDescription* tmp;
    tmp = new VpspScanAnalysisDescription(anal->vpsp()[iapv],
                                          anal->adcLevel()[iapv],
                                          anal->fraction()[iapv],
                                          anal->topEdge()[iapv],
                                          anal->bottomEdge()[iapv],
                                          anal->topLevel()[iapv],
                                          anal->bottomLevel()[iapv],
                                          fec_key.fecCrate(),
                                          fec_key.fecSlot(),
                                          fec_key.fecRing(),
                                          fec_key.ccuAddr(),
                                          fec_key.ccuChan(),
                                          SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
                                          db()->dbParams().partitions().begin()->second.partitionName(),
                                          db()->dbParams().partitions().begin()->second.runNumber(),
                                          anal->isValid(),
                                          "",
                                          fed_key.fedId(),
                                          fed_key.feUnit(),
                                          fed_key.feChan(),
                                          fed_key.fedApv());

    // Add comments
    typedef std::vector<std::string> Strings;
    Strings errors = anal->getErrorCodes();
    Strings::const_iterator istr = errors.begin();
    Strings::const_iterator jstr = errors.end();
    for (; istr != jstr; ++istr) {
      tmp->addComments(*istr);
    }

    // Store description
    desc.push_back(tmp);
  }
}