SiStripThresholdFakeESSource

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
// -*- C++ -*-
//
// Package:    CalibTracker/SiStripESProducers
// Class:      SiStripThresholdFakeESSource
//
/**\class SiStripThresholdFakeESSource SiStripThresholdFakeESSource.h CalibTracker/SiStripESProducers/plugins/SiStripThresholdFakeESSource.cc

 Description: "fake" SiStripThreshold ESProducer - fixed values from configuration for all thresholds (low, high and cluster)

 Implementation:
     Port of SiStripThresholdGenerator and templated fake ESSource to an edm::ESProducer
*/

// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"

#include "CondFormats/SiStripObjects/interface/SiStripThreshold.h"
#include "CondFormats/DataRecord/interface/SiStripThresholdRcd.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"

class SiStripThresholdFakeESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
public:
  SiStripThresholdFakeESSource(const edm::ParameterSet&);
  ~SiStripThresholdFakeESSource() override;

  void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
                      const edm::IOVSyncValue& iov,
                      edm::ValidityInterval& iValidity) override;

  typedef std::unique_ptr<SiStripThreshold> ReturnType;
  ReturnType produce(const SiStripThresholdRcd&);

private:
  float m_lTh;
  float m_hTh;
  float m_cTh;
  SiStripDetInfo m_detInfo;
};

SiStripThresholdFakeESSource::SiStripThresholdFakeESSource(const edm::ParameterSet& iConfig) {
  setWhatProduced(this);
  findingRecord<SiStripThresholdRcd>();

  m_lTh = iConfig.getParameter<double>("LowTh");
  m_hTh = iConfig.getParameter<double>("HighTh");
  m_cTh = iConfig.getParameter<double>("ClusTh");
  m_detInfo = SiStripDetInfoFileReader::read(iConfig.getParameter<edm::FileInPath>("SiStripDetInfoFile").fullPath());
}

SiStripThresholdFakeESSource::~SiStripThresholdFakeESSource() {}

void SiStripThresholdFakeESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
                                                  const edm::IOVSyncValue& iov,
                                                  edm::ValidityInterval& iValidity) {
  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
}

// ------------ method called to produce the data  ------------
SiStripThresholdFakeESSource::ReturnType SiStripThresholdFakeESSource::produce(const SiStripThresholdRcd& iRecord) {
  using namespace edm::es;

  auto threshold = std::make_unique<SiStripThreshold>();

  for (const auto& elm : m_detInfo.getAllData()) {
    //Generate Thresholds for det detid
    SiStripThreshold::Container theSiStripVector;
    uint16_t strip = 0;

    threshold->setData(strip, m_lTh, m_hTh, m_cTh, theSiStripVector);
    LogDebug("SiStripThresholdFakeESSource::produce")
        << "detid: " << elm.first << " \t"
        << "firstStrip: " << strip << " \t" << theSiStripVector.back().getFirstStrip() << " \t"
        << "lTh: " << m_lTh << " \t" << theSiStripVector.back().getLth() << " \t"
        << "hTh: " << m_hTh << " \t" << theSiStripVector.back().getHth() << " \t"
        << "FirstStrip_and_Hth: " << theSiStripVector.back().FirstStrip_and_Hth << " \t";

    if (!threshold->put(elm.first, theSiStripVector)) {
      edm::LogError("SiStripThresholdFakeESSource::produce ") << " detid already exists";
    }
  }

  return threshold;
}

//define this as a plug-in
#include "FWCore/Framework/interface/SourceFactory.h"
DEFINE_FWK_EVENTSETUP_SOURCE(SiStripThresholdFakeESSource);