Skip to content

Commit

Permalink
Merge pull request #34902 from makortel/esconsumesMixing
Browse files Browse the repository at this point in the history
Migrate BMixingModule and EcalShapeBase-derived classes to esConsumes
  • Loading branch information
cmsbuild committed Sep 1, 2021
2 parents 134fbbd + 9ebd1a9 commit 40f81cc
Show file tree
Hide file tree
Showing 32 changed files with 147 additions and 151 deletions.
3 changes: 3 additions & 0 deletions CalibCalorimetry/EcalSRTools/interface/EcalDccWeightBuilder.h
Expand Up @@ -128,6 +128,9 @@ class EcalDccWeightBuilder : public edm::EDAnalyzer {
EcalIntercalibConstantMap emptyCalibMap_;
std::map<DetId, std::vector<int> > encodedWeights_;

EBShape ebShape_;
EEShape eeShape_;

static const double weightScale_;
const EcalElectronicsMapping* ecalElectronicsMap_;

Expand Down
11 changes: 5 additions & 6 deletions CalibCalorimetry/EcalSRTools/src/EcalDccWeightBuilder.cc
Expand Up @@ -59,7 +59,9 @@ EcalDccWeightBuilder::EcalDccWeightBuilder(edm::ParameterSet const& ps)
dbTag_(ps.getParameter<string>("dbTag")),
dbVersion_(ps.getParameter<int>("dbVersion")),
sqlMode_(ps.getParameter<bool>("sqlMode")),
calibMap_(emptyCalibMap_) {
calibMap_(emptyCalibMap_),
ebShape_(consumesCollector()),
eeShape_(consumesCollector()) {
if (mode_ == "weightsFromConfig") {
imode_ = WEIGHTS_FROM_CONFIG;
if (inputWeights_.size() != (unsigned)nDccWeights_) {
Expand Down Expand Up @@ -157,15 +159,12 @@ void EcalDccWeightBuilder::computeAllWeights(bool withIntercalib, const edm::Eve
#endif

try {
bool useDBShape = true;
EBShape ebShape(useDBShape);
EEShape eeShape(useDBShape);
EcalShapeBase* pShape;

if (it->subdetId() == EcalBarrel) {
pShape = &ebShape;
pShape = &ebShape_;
} else if (it->subdetId() == EcalEndcap) {
pShape = &eeShape;
pShape = &eeShape_;
} else {
throw cms::Exception("EcalDccWeightBuilder") << "Bug found in " << __FILE__ << ":" << __LINE__ << ": "
<< "Got a detId which is neither tagged as ECAL Barrel "
Expand Down
16 changes: 6 additions & 10 deletions CalibCalorimetry/EcalTPGTools/plugins/EcalTPGParamBuilder.cc
Expand Up @@ -14,8 +14,6 @@
#include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecord.h"

#include "SimCalorimetry/EcalSimAlgos/interface/EcalSimParameterMap.h"
#include "SimCalorimetry/EcalSimAlgos/interface/EBShape.h"
#include "SimCalorimetry/EcalSimAlgos/interface/EEShape.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <TF1.h>
Expand Down Expand Up @@ -53,7 +51,8 @@ EcalTPGParamBuilder::EcalTPGParamBuilder(edm::ParameterSet const& pSet)
xtal_LSB_EE_(0),
nSample_(5),
complement2_(7),
useDBShape_(true) {
shapeEB_(consumesCollector()), // EBShape, EEShape are fetched now from DB (2018.05.22 K. Theofilatos)
shapeEE_(consumesCollector()) {
ped_conf_id_ = 0;
lin_conf_id_ = 0;
lut_conf_id_ = 0;
Expand Down Expand Up @@ -1610,13 +1609,10 @@ void EcalTPGParamBuilder::analyze(const edm::Event& evt, const edm::EventSetup&
const int NWEIGROUPS = 2;
std::vector<unsigned int> weights[NWEIGROUPS];

bool useDBShape = useDBShape_;
EBShape shapeEB(useDBShape);
shapeEB.setEventSetup(evtSetup); // EBShape, EEShape are fetched now from DB (2018.05.22 K. Theofilatos)
EEShape shapeEE(useDBShape);
shapeEE.setEventSetup(evtSetup); //
weights[0] = computeWeights(shapeEB, hshapeEB);
weights[1] = computeWeights(shapeEE, hshapeEE);
shapeEB_.setEventSetup(evtSetup);
shapeEE_.setEventSetup(evtSetup);
weights[0] = computeWeights(shapeEB_, hshapeEB);
weights[1] = computeWeights(shapeEE_, hshapeEE);

map<EcalLogicID, FEConfigWeightGroupDat> dataset;

Expand Down
7 changes: 5 additions & 2 deletions CalibCalorimetry/EcalTPGTools/plugins/EcalTPGParamBuilder.h
Expand Up @@ -41,6 +41,8 @@
#include "CondFormats/EcalObjects/interface/EcalLaserAlphas.h"

#include "SimCalorimetry/EcalSimAlgos/interface/EcalShapeBase.h"
#include "SimCalorimetry/EcalSimAlgos/interface/EBShape.h"
#include "SimCalorimetry/EcalSimAlgos/interface/EEShape.h"

#include <TH1F.h>

Expand Down Expand Up @@ -162,6 +164,9 @@ class EcalTPGParamBuilder : public edm::one::EDAnalyzer<> {
//modif-alex 30/01/2012
std::map<int, double> Transparency_Correction_;

EBShape shapeEB_;
EEShape shapeEE_;

std::ofstream* out_file_;
std::ofstream* geomFile_;
EcalTPGDBApp* db_;
Expand Down Expand Up @@ -198,7 +203,5 @@ class EcalTPGParamBuilder : public edm::one::EDAnalyzer<> {
Int_t* ntupleInts_;
Char_t ntupleDet_[10];
Char_t ntupleCrate_[10];

bool useDBShape_;
};
#endif
1 change: 1 addition & 0 deletions Mixing/Base/interface/BMixingModule.h
Expand Up @@ -32,6 +32,7 @@ namespace edm {
int minBunch_;
int maxBunch_;
bool playback_;
bool configFromDB_ = false;
std::vector<std::string> sourceNames_;
std::vector<std::shared_ptr<PileUpConfig>> inputConfigs_;
};
Expand Down
11 changes: 10 additions & 1 deletion Mixing/Base/interface/PileUp.h
Expand Up @@ -5,7 +5,9 @@
#include <string>
#include <vector>
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Sources/interface/VectorInputSource.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "DataFormats/Provenance/interface/EventID.h"
#include "FWCore/Framework/interface/EventPrincipal.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
Expand All @@ -23,6 +25,9 @@ namespace CLHEP {
class HepRandomEngine;
} // namespace CLHEP

class MixingModuleConfig;
class MixingRcd;

namespace edm {
class SecondaryEventProvider;
class StreamID;
Expand All @@ -39,7 +44,10 @@ namespace edm {

class PileUp {
public:
explicit PileUp(ParameterSet const& pset, const std::shared_ptr<PileUpConfig>& config);
explicit PileUp(ParameterSet const& pset,
const std::shared_ptr<PileUpConfig>& config,
edm::ConsumesCollector iC,
const bool mixingConfigFromDB);
~PileUp();

template <typename T>
Expand Down Expand Up @@ -128,6 +136,7 @@ namespace edm {
int minBunch_cosmics_;
int maxBunch_cosmics_;

edm::ESGetToken<MixingModuleConfig, MixingRcd> configToken_;
size_t fileNameHash_;
std::shared_ptr<ProductRegistry> productRegistry_;
std::unique_ptr<VectorInputSource> const input_;
Expand Down
12 changes: 6 additions & 6 deletions Mixing/Base/src/BMixingModule.cc
Expand Up @@ -183,16 +183,14 @@ namespace edm {
maxBunch_(globalConf->maxBunch_),
mixProdStep1_(pset.getParameter<bool>("mixProdStep1")),
mixProdStep2_(pset.getParameter<bool>("mixProdStep2")),
readDB_(false),
readDB_(globalConf->configFromDB_),
playback_(globalConf->playback_) {
if (pset.exists("readDB"))
readDB_ = pset.getParameter<bool>("readDB");

for (size_t makeIdx = 0; makeIdx < maxNbSources_; makeIdx++) {
if (globalConf->inputConfigs_[makeIdx]) {
const edm::ParameterSet& psin =
pset.getParameter<edm::ParameterSet>(globalConf->inputConfigs_[makeIdx]->sourcename_);
inputSources_.push_back(std::make_shared<PileUp>(psin, globalConf->inputConfigs_[makeIdx]));
inputSources_.push_back(
std::make_shared<PileUp>(psin, globalConf->inputConfigs_[makeIdx], consumesCollector(), readDB_));
inputSources_.back()->input(makeIdx);
} else {
inputSources_.push_back(nullptr);
Expand Down Expand Up @@ -224,6 +222,9 @@ namespace edm {
for (size_t makeIdx = 0; makeIdx < maxNbSources; makeIdx++) {
inputConfigs_.push_back(maybeConfigPileUp(pset, sourceNames_[makeIdx], minBunch_, maxBunch_, playback_));
}

if (pset.exists("readDB"))
configFromDB_ = pset.getParameter<bool>("readDB");
}
} // namespace MixingCache

Expand All @@ -241,7 +242,6 @@ namespace edm {
}

void BMixingModule::beginRun(edm::Run const& run, edm::EventSetup const& setup) {
update(setup);
for (size_t endIdx = 0; endIdx < maxNbSources_; ++endIdx) {
if (inputSources_[endIdx])
inputSources_[endIdx]->beginRun(run, setup);
Expand Down
14 changes: 9 additions & 5 deletions Mixing/Base/src/PileUp.cc
Expand Up @@ -64,7 +64,10 @@ static Double_t GetRandom(TH1* th1, CLHEP::HepRandomEngine* rng) {
////////////////////////////////////////////////////////////////////////////////

namespace edm {
PileUp::PileUp(ParameterSet const& pset, const std::shared_ptr<PileUpConfig>& config)
PileUp::PileUp(ParameterSet const& pset,
const std::shared_ptr<PileUpConfig>& config,
edm::ConsumesCollector iC,
const bool mixingConfigFromDB)
: type_(pset.getParameter<std::string>("type")),
Source_type_(config->sourcename_),
averageNumber_(config->averageNumber_),
Expand Down Expand Up @@ -92,6 +95,10 @@ namespace edm {
randomEngine_(),
playback_(config->playback_),
sequential_(pset.getUntrackedParameter<bool>("sequential", false)) {
if (mixingConfigFromDB) {
configToken_ = iC.esConsumes<edm::Transition::BeginLuminosityBlock>();
}

// Use the empty parameter set for the parameter set ID of our "@MIXING" process.
processConfiguration_->setParameterSetID(ParameterSet::emptyParameterSetID());
processContext_->setProcessConfiguration(processConfiguration_.get());
Expand Down Expand Up @@ -234,10 +241,7 @@ namespace edm {

void PileUp::reload(const edm::EventSetup& setup) {
//get the required parameters from DB.
edm::ESHandle<MixingModuleConfig> configM;
setup.get<MixingRcd>().get(configM);

const MixingInputConfig& config = configM->config(inputType_);
const MixingInputConfig& config = setup.getData(configToken_).config(inputType_);

//get the type
type_ = config.type();
Expand Down
Expand Up @@ -14,8 +14,8 @@ EcalUncalibRecHitWorkerGlobal::EcalUncalibRecHitWorkerGlobal(const edm::Paramete
tokenGains_(c.esConsumes<EcalGainRatios, EcalGainRatiosRcd>()),
tokenGrps_(c.esConsumes<EcalWeightXtalGroups, EcalWeightXtalGroupsRcd>()),
tokenWgts_(c.esConsumes<EcalTBWeights, EcalTBWeightsRcd>()),
testbeamEEShape(EEShape(true)),
testbeamEBShape(EBShape(true)),
testbeamEEShape(c),
testbeamEBShape(c),
tokenSampleMask_(c.esConsumes<EcalSampleMask, EcalSampleMaskRcd>()),
tokenTimeCorrBias_(c.esConsumes<EcalTimeBiasCorrections, EcalTimeBiasCorrectionsRcd>()),
tokenItime_(c.esConsumes<EcalTimeCalibConstants, EcalTimeCalibConstantsRcd>()),
Expand Down
Expand Up @@ -44,7 +44,7 @@ namespace edm {
class EcalUncalibRecHitWorkerGlobal : public EcalUncalibRecHitWorkerRunOneDigiBase {
public:
EcalUncalibRecHitWorkerGlobal(const edm::ParameterSet&, edm::ConsumesCollector& c);
EcalUncalibRecHitWorkerGlobal() : testbeamEEShape(EEShape(true)), testbeamEBShape(EBShape(true)) { ; }
EcalUncalibRecHitWorkerGlobal() = default; // for EcalUncalibRecHitFillDescriptionWorkerFactory
~EcalUncalibRecHitWorkerGlobal() override{};

void set(const edm::EventSetup& es) override;
Expand Down
Expand Up @@ -15,8 +15,8 @@ EcalUncalibRecHitWorkerWeights::EcalUncalibRecHitWorkerWeights(const edm::Parame
tokenGains_(c.esConsumes<EcalGainRatios, EcalGainRatiosRcd>()),
tokenGrps_(c.esConsumes<EcalWeightXtalGroups, EcalWeightXtalGroupsRcd>()),
tokenWgts_(c.esConsumes<EcalTBWeights, EcalTBWeightsRcd>()),
testbeamEEShape(EEShape(true)),
testbeamEBShape(EBShape(true)) {}
testbeamEEShape(c),
testbeamEBShape(c) {}

void EcalUncalibRecHitWorkerWeights::set(const edm::EventSetup& es) {
gains_ = es.getHandle(tokenGains_);
Expand Down
Expand Up @@ -34,7 +34,7 @@ namespace edm {
class EcalUncalibRecHitWorkerWeights : public EcalUncalibRecHitWorkerRunOneDigiBase {
public:
EcalUncalibRecHitWorkerWeights(const edm::ParameterSet&, edm::ConsumesCollector& c);
EcalUncalibRecHitWorkerWeights() : testbeamEEShape(EEShape(true)), testbeamEBShape(EBShape(true)) { ; }
EcalUncalibRecHitWorkerWeights() = default; // for EcalUncalibRecHitFillDescriptionWorkerFactory
~EcalUncalibRecHitWorkerWeights() override{};

void set(const edm::EventSetup& es) override;
Expand Down
Expand Up @@ -46,10 +46,8 @@

#define DEBUG
EcalTBWeightUncalibRecHitProducer::EcalTBWeightUncalibRecHitProducer(const edm::ParameterSet& ps)
: testbeamEEShape(EEShape(
false)), // Shapes have been updated in 2018 such as to be able to fetch shape from the DB if EBShape(true)//EEShape(true) are used
testbeamEBShape(EBShape(
false)) // use false as argument if you would rather prefer to use Phase I hardcoded shapes (18.05.2018 K. Theofilatos)
: testbeamEEShape(), // Shapes have been updated in 2018 such as to be able to fetch shape from the DB if EBShape(consumesCollector())//EEShape(consumesCollector()) are used
testbeamEBShape() // use default constructor if you would rather prefer to use Phase I hardcoded shapes (18.05.2018 K. Theofilatos)
{
EBdigiCollection_ = ps.getParameter<edm::InputTag>("EBdigiCollection");
EEdigiCollection_ = ps.getParameter<edm::InputTag>("EEdigiCollection");
Expand Down
13 changes: 8 additions & 5 deletions SimCalorimetry/EcalSimAlgos/interface/APDShape.h
@@ -1,21 +1,24 @@
#ifndef EcalSimAlgos_APDShape_h
#define EcalSimAlgos_APDShape_h

#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "SimCalorimetry/EcalSimAlgos/interface/EcalShapeBase.h"

class APDShape : public EcalShapeBase {
public:
APDShape(bool useDB) : EcalShapeBase(useDB) {
if (!useDB)
buildMe();
} // if useDB = true, then buildMe is executed when setEventSetup and DB conditions are available
// APDShape():EcalShapeBase(false){;}
// useDB = false
APDShape() : EcalShapeBase(false) { buildMe(); }
// useDB = true, buildMe is executed when setEventSetup and DB conditions are available
APDShape(edm::ConsumesCollector iC) : EcalShapeBase(true), espsToken_(iC.esConsumes()) {}

protected:
void fillShape(float& time_interval,
double& m_thresh,
EcalShapeBase::DVec& aVec,
const edm::EventSetup* es) const override;

private:
edm::ESGetToken<EcalSimPulseShape, EcalSimPulseShapeRcd> espsToken_;
};

#endif
13 changes: 8 additions & 5 deletions SimCalorimetry/EcalSimAlgos/interface/EBShape.h
@@ -1,21 +1,24 @@
#ifndef EcalSimAlgos_EBShape_h
#define EcalSimAlgos_EBShape_h

#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "SimCalorimetry/EcalSimAlgos/interface/EcalShapeBase.h"

class EBShape : public EcalShapeBase {
public:
EBShape(bool useDB) : EcalShapeBase(useDB) {
if (!useDB)
buildMe();
} // if useDB = true, then buildMe is executed when setEventSetup and DB conditions are available
//EBShape():EcalShapeBase(false){;}
// useDB = false
EBShape() : EcalShapeBase(false) { buildMe(); }
// useDB = true, buildMe is executed when setEventSetup and DB conditions are available
EBShape(edm::ConsumesCollector iC) : EcalShapeBase(true), espsToken_(iC.esConsumes()) {}

protected:
void fillShape(float& time_interval,
double& m_thresh,
EcalShapeBase::DVec& aVec,
const edm::EventSetup* es) const override;

private:
edm::ESGetToken<EcalSimPulseShape, EcalSimPulseShapeRcd> espsToken_;
};

#endif
13 changes: 8 additions & 5 deletions SimCalorimetry/EcalSimAlgos/interface/EEShape.h
@@ -1,21 +1,24 @@
#ifndef EcalSimAlgos_EEShape_h
#define EcalSimAlgos_EEShape_h

#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "SimCalorimetry/EcalSimAlgos/interface/EcalShapeBase.h"

class EEShape : public EcalShapeBase {
public:
EEShape(bool useDB) : EcalShapeBase(useDB) {
if (!useDB)
buildMe();
} // if useDB = true, then buildMe is executed when setEventSetup and DB conditions are available}
// EEShape():EcalShapeBase(false){;}
// useDB = false
EEShape() : EcalShapeBase(false) { buildMe(); }
// useDB = true, buildMe is executed when setEventSetup and DB conditions are available
EEShape(edm::ConsumesCollector iC) : EcalShapeBase(true), espsToken_(iC.esConsumes()) {}

protected:
void fillShape(float& time_interval,
double& m_thresh,
EcalShapeBase::DVec& aVec,
const edm::EventSetup* es) const override;

private:
edm::ESGetToken<EcalSimPulseShape, EcalSimPulseShapeRcd> espsToken_;
};

#endif
9 changes: 4 additions & 5 deletions SimCalorimetry/EcalSimAlgos/src/APDShape.cc
Expand Up @@ -12,12 +12,11 @@ void APDShape::fillShape(float& time_interval,
if (es == nullptr) {
throw cms::Exception("EcalShapeBase:: DB conditions are not available, const edm::EventSetup* es == nullptr ");
}
edm::ESHandle<EcalSimPulseShape> esps;
es->get<EcalSimPulseShapeRcd>().get(esps);
auto const& esps = es->getData(espsToken_);

aVec = esps->apd_shape;
time_interval = esps->time_interval;
m_thresh = esps->apd_thresh;
aVec = esps.apd_shape;
time_interval = esps.time_interval;
m_thresh = esps.apd_thresh;
} else {
m_thresh = 0.0;
time_interval = 1.0;
Expand Down

0 comments on commit 40f81cc

Please sign in to comment.