Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mayConsume to SiStripESProducers #28138

Merged
merged 1 commit into from Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,66 +34,92 @@
#include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
#include "CalibTracker/Records/interface/SiStripDependentRecords.h"

#include "FWCore/Utilities/interface/ESProductTag.h"

class SiStripBackPlaneCorrectionDepESProducer : public edm::ESProducer {
public:
SiStripBackPlaneCorrectionDepESProducer(const edm::ParameterSet&);
~SiStripBackPlaneCorrectionDepESProducer() override{};

std::unique_ptr<SiStripBackPlaneCorrection> produce(const SiStripBackPlaneCorrectionDepRcd&);
std::shared_ptr<SiStripBackPlaneCorrection const> produce(const SiStripBackPlaneCorrectionDepRcd&);

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
edm::ParameterSet getLatency;
edm::ParameterSet getPeak;
edm::ParameterSet getDeconv;
edm::ESGetToken<SiStripBackPlaneCorrection, SiStripBackPlaneCorrectionRcd> backPlaneCorrectionToken_;
};

SiStripBackPlaneCorrectionDepESProducer::SiStripBackPlaneCorrectionDepESProducer(const edm::ParameterSet& iConfig)
: getLatency(iConfig.getParameter<edm::ParameterSet>("LatencyRecord")),
getPeak(iConfig.getParameter<edm::ParameterSet>("BackPlaneCorrectionPeakMode")),
getDeconv(iConfig.getParameter<edm::ParameterSet>("BackPlaneCorrectionDeconvMode")) {
setWhatProduced(this);

SiStripBackPlaneCorrectionDepESProducer::SiStripBackPlaneCorrectionDepESProducer(const edm::ParameterSet& iConfig) {
edm::LogInfo("SiStripBackPlaneCorrectionDepESProducer") << "ctor" << std::endl;

auto getLatency = iConfig.getParameter<edm::ParameterSet>("LatencyRecord");
// How useful the "record" parameter really is?
if (getLatency.getParameter<std::string>("record") != "SiStripLatencyRcd") {
throw edm::Exception(edm::errors::Configuration,
"[SiStripBackPlaneCorrectionDepESProducer::ctor] No Latency Record found ");
}

auto getPeak = iConfig.getParameter<edm::ParameterSet>("BackPlaneCorrectionPeakMode");
if (getPeak.getParameter<std::string>("record") != "SiStripBackPlaneCorrectionRcd") {
throw edm::Exception(edm::errors::Configuration,
"[SiStripBackPlaneCorrectionDepESProducer::ctor] No Lorentz Angle Record found ");
}

auto getDeconv = iConfig.getParameter<edm::ParameterSet>("BackPlaneCorrectionDeconvMode");
// How useful the "record" parameter really is?
if (getDeconv.getParameter<std::string>("record") != "SiStripBackPlaneCorrectionRcd") {
throw edm::Exception(edm::errors::Configuration,
"[SiStripBackPlaneCorrectionDepESProducer::ctor] No Lorentz Angle Record found ");
}

auto peakLabel{getPeak.getUntrackedParameter<std::string>("label")};
auto deconvLabel{getDeconv.getUntrackedParameter<std::string>("label")};

setWhatProduced(this).setMayConsume(
backPlaneCorrectionToken_,
[peakLabel, deconvLabel](auto const& get, edm::ESTransientHandle<SiStripLatency> iLatency) {
if (iLatency->singleReadOutMode() == 1) {
return get("", peakLabel);
}
return get("", deconvLabel);
},
edm::ESProductTag<SiStripLatency, SiStripLatencyRcd>("", getLatency.getUntrackedParameter<std::string>("label")));
}

std::unique_ptr<SiStripBackPlaneCorrection> SiStripBackPlaneCorrectionDepESProducer::produce(
std::shared_ptr<SiStripBackPlaneCorrection const> SiStripBackPlaneCorrectionDepESProducer::produce(
const SiStripBackPlaneCorrectionDepRcd& iRecord) {
std::unique_ptr<SiStripBackPlaneCorrection> siStripBPC;
edm::LogInfo("SiStripBackPlaneCorrectionDepESProducer") << "Producer called" << std::endl;

std::string latencyRecordName = getLatency.getParameter<std::string>("record");
std::string latencyLabel = getLatency.getUntrackedParameter<std::string>("label");
bool peakMode = false;

if (latencyRecordName == "SiStripLatencyRcd") {
edm::ESHandle<SiStripLatency> latency;
iRecord.getRecord<SiStripLatencyRcd>().get(latencyLabel, latency);
if (latency->singleReadOutMode() == 1)
peakMode = true;
} else
edm::LogError("SiStripBackPlaneCorrectionDepESProducer")
<< "[SiStripBackPlaneCorrectionDepESProducer::produce] No Latency Record found " << std::endl;

std::string backPlaneCorrectionRecordName;
std::string backPlaneCorrectionLabel;

if (peakMode) {
backPlaneCorrectionRecordName = getPeak.getParameter<std::string>("record");
backPlaneCorrectionLabel = getPeak.getUntrackedParameter<std::string>("label");
} else {
backPlaneCorrectionRecordName = getDeconv.getParameter<std::string>("record");
backPlaneCorrectionLabel = getDeconv.getUntrackedParameter<std::string>("label");
//tell shared_ptr not to delete the product since it is already owned by the record
return std::shared_ptr<SiStripBackPlaneCorrection const>(&iRecord.get(backPlaneCorrectionToken_), [](auto) {});
}

void SiStripBackPlaneCorrectionDepESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
{
edm::ParameterSetDescription latency;
latency.add<std::string>("record", "SiStripLatencyRcd");
latency.addUntracked<std::string>("label", "");

desc.add<edm::ParameterSetDescription>("LatencyRecord", latency);
}

if (backPlaneCorrectionRecordName == "SiStripBackPlaneCorrectionRcd") {
edm::ESHandle<SiStripBackPlaneCorrection> siStripBackPlaneCorrection;
iRecord.getRecord<SiStripBackPlaneCorrectionRcd>().get(backPlaneCorrectionLabel, siStripBackPlaneCorrection);
siStripBPC = std::make_unique<SiStripBackPlaneCorrection>(*(siStripBackPlaneCorrection.product()));
} else
edm::LogError("SiStripBackPlaneCorrectionDepESProducer")
<< "[SiStripBackPlaneCorrectionDepESProducer::produce] No Lorentz Angle Record found " << std::endl;
{
edm::ParameterSetDescription peak;
peak.add<std::string>("record", "SiStripBackPlaneCorrectionRcd");
peak.addUntracked<std::string>("label", "peak");

desc.add<edm::ParameterSetDescription>("BackPlaneCorrectionPeakMode", peak);
}

{
edm::ParameterSetDescription deconv;
deconv.add<std::string>("record", "SiStripBackPlaneCorrectionRcd");
deconv.addUntracked<std::string>("label", "deconvolution");

desc.add<edm::ParameterSetDescription>("BackPlaneCorrectionDeconvMode", deconv);
}

return siStripBPC;
descriptions.addDefault(desc);
}

DEFINE_FWK_EVENTSETUP_MODULE(SiStripBackPlaneCorrectionDepESProducer);
Expand Up @@ -29,6 +29,8 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "FWCore/Utilities/interface/ESProductTag.h"

#include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
#include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
#include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
Expand All @@ -37,63 +39,86 @@
class SiStripLorentzAngleDepESProducer : public edm::ESProducer {
public:
SiStripLorentzAngleDepESProducer(const edm::ParameterSet&);
~SiStripLorentzAngleDepESProducer() override{};

std::unique_ptr<SiStripLorentzAngle> produce(const SiStripLorentzAngleDepRcd&);
std::shared_ptr<SiStripLorentzAngle const> produce(const SiStripLorentzAngleDepRcd&);

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
edm::ParameterSet getLatency;
edm::ParameterSet getPeak;
edm::ParameterSet getDeconv;
edm::ESGetToken<SiStripLorentzAngle, SiStripLorentzAngleRcd> lorentzAngleToken_;
};

SiStripLorentzAngleDepESProducer::SiStripLorentzAngleDepESProducer(const edm::ParameterSet& iConfig)
: getLatency(iConfig.getParameter<edm::ParameterSet>("LatencyRecord")),
getPeak(iConfig.getParameter<edm::ParameterSet>("LorentzAnglePeakMode")),
getDeconv(iConfig.getParameter<edm::ParameterSet>("LorentzAngleDeconvMode")) {
setWhatProduced(this);
SiStripLorentzAngleDepESProducer::SiStripLorentzAngleDepESProducer(const edm::ParameterSet& iConfig) {
auto const getLatency = iConfig.getParameter<edm::ParameterSet>("LatencyRecord");
// How useful the "record" parameter really is?
if (getLatency.getParameter<std::string>("record") != "SiStripLatencyRcd") {
throw edm::Exception(edm::errors::Configuration,
"[SiStripLorentzAngleDepESProducer::ctor] No Latency Record found ");
}

auto const getPeak = iConfig.getParameter<edm::ParameterSet>("LorentzAnglePeakMode");
if (getPeak.getParameter<std::string>("record") != "SiStripLorentzAngleRcd") {
throw edm::Exception(edm::errors::Configuration,
"[SiStripLorentzAngleDepESProducer::ctor] No Lorentz Angle Record found ");
}

auto const getDeconv = iConfig.getParameter<edm::ParameterSet>("LorentzAngleDeconvMode");
// How useful the "record" parameter really is?
if (getDeconv.getParameter<std::string>("record") != "SiStripLorentzAngleRcd") {
throw edm::Exception(edm::errors::Configuration,
"[SiStripLorentzAngleDepESProducer::ctor] No Lorentz Angle Record found ");
}

auto const peakLabel{getPeak.getUntrackedParameter<std::string>("label")};
auto const deconvLabel{getDeconv.getUntrackedParameter<std::string>("label")};
setWhatProduced(this).setMayConsume(
lorentzAngleToken_,
[peakLabel, deconvLabel](auto const& get, edm::ESTransientHandle<SiStripLatency> iLatency) {
if (iLatency->singleReadOutMode() == 1) {
return get("", peakLabel);
}
return get("", deconvLabel);
},
edm::ESProductTag<SiStripLatency, SiStripLatencyRcd>("", getLatency.getUntrackedParameter<std::string>("label")));

edm::LogInfo("SiStripLorentzAngleDepESProducer") << "ctor" << std::endl;
}

std::unique_ptr<SiStripLorentzAngle> SiStripLorentzAngleDepESProducer::produce(
std::shared_ptr<SiStripLorentzAngle const> SiStripLorentzAngleDepESProducer::produce(
const SiStripLorentzAngleDepRcd& iRecord) {
std::unique_ptr<SiStripLorentzAngle> siStripLA;
edm::LogInfo("SiStripLorentzAngleDepESProducer") << "Producer called" << std::endl;

std::string latencyRecordName = getLatency.getParameter<std::string>("record");
std::string latencyLabel = getLatency.getUntrackedParameter<std::string>("label");
bool peakMode = false;

if (latencyRecordName == "SiStripLatencyRcd") {
edm::ESHandle<SiStripLatency> latency;
iRecord.getRecord<SiStripLatencyRcd>().get(latencyLabel, latency);
if (latency->singleReadOutMode() == 1)
peakMode = true;
} else
edm::LogError("SiStripLorentzAngleDepESProducer")
<< "[SiStripLorentzAngleDepESProducer::produce] No Latency Record found " << std::endl;

std::string lorentzAngleRecordName;
std::string lorentzAngleLabel;

if (peakMode) {
lorentzAngleRecordName = getPeak.getParameter<std::string>("record");
lorentzAngleLabel = getPeak.getUntrackedParameter<std::string>("label");
} else {
lorentzAngleRecordName = getDeconv.getParameter<std::string>("record");
lorentzAngleLabel = getDeconv.getUntrackedParameter<std::string>("label");
//tell shared_ptr not to delete the product since it is already owned by the record
return std::shared_ptr<SiStripLorentzAngle const>(&iRecord.get(lorentzAngleToken_), [](auto) {});
}

void SiStripLorentzAngleDepESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
{
edm::ParameterSetDescription latency;
latency.add<std::string>("record", "SiStripLatencyRcd");
latency.addUntracked<std::string>("label", "");

desc.add<edm::ParameterSetDescription>("LatencyRecord", latency);
}

{
edm::ParameterSetDescription peak;
peak.add<std::string>("record", "SiStripLorentzAngleRcd");
peak.addUntracked<std::string>("label", "peak");

desc.add<edm::ParameterSetDescription>("LorentzAnglePeakMode", peak);
}

if (lorentzAngleRecordName == "SiStripLorentzAngleRcd") {
edm::ESHandle<SiStripLorentzAngle> siStripLorentzAngle;
iRecord.getRecord<SiStripLorentzAngleRcd>().get(lorentzAngleLabel, siStripLorentzAngle);
siStripLA.reset(new SiStripLorentzAngle(*(siStripLorentzAngle.product())));
} else
edm::LogError("SiStripLorentzAngleDepESProducer")
<< "[SiStripLorentzAngleDepESProducer::produce] No Lorentz Angle Record found " << std::endl;
{
edm::ParameterSetDescription deconv;
deconv.add<std::string>("record", "SiStripLorentzAngleRcd");
deconv.addUntracked<std::string>("label", "deconvolution");

desc.add<edm::ParameterSetDescription>("LorentzAngleDeconvMode", deconv);
}

return siStripLA;
descriptions.addDefault(desc);
}

DEFINE_FWK_EVENTSETUP_MODULE(SiStripLorentzAngleDepESProducer);