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

Use esConsumes with SiPixelStatusProducer #32484

Merged
merged 1 commit into from
Dec 15, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion CalibTracker/SiPixelQuality/plugins/SiPixelStatusProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
// Header file
#include "CalibTracker/SiPixelQuality/plugins/SiPixelStatusProducer.h"

SiPixelStatusProducer::SiPixelStatusProducer(const edm::ParameterSet& iConfig, SiPixelTopoCache const*) {
SiPixelStatusProducer::SiPixelStatusProducer(const edm::ParameterSet& iConfig, SiPixelStatusCache const* iCache) {
//NOTE: Token for all stream replicas are identical and constructors for the replicas are called
// sequentially so there is no race condition.
iCache->trackerGeometryToken_ = esConsumes<edm::Transition::BeginRun>();
iCache->trackerTopologyToken_ = esConsumes<edm::Transition::BeginRun>();
iCache->siPixelFedCablingMapToken_ = esConsumes<edm::Transition::BeginRun>();

/* badPixelFEDChannelCollections */
std::vector<edm::InputTag> badPixelFEDChannelCollectionLabels =
iConfig.getParameter<edm::ParameterSet>("SiPixelStatusProducerParameters")
Expand All @@ -50,6 +56,19 @@ SiPixelStatusProducer::~SiPixelStatusProducer() {}

//--------------------------------------------------------------------------------------------------

std::shared_ptr<SiPixelTopoFinder> SiPixelStatusProducer::globalBeginRun(edm::Run const& iRun,
edm::EventSetup const& iSetup,
GlobalCache const* iCache) {
const TrackerGeometry* trackerGeometry = &iSetup.getData(iCache->trackerGeometryToken_);
const TrackerTopology* trackerTopology = &iSetup.getData(iCache->trackerTopologyToken_);
const SiPixelFedCablingMap* cablingMap = &iSetup.getData(iCache->siPixelFedCablingMapToken_);

auto returnValue = std::make_shared<SiPixelTopoFinder>();

returnValue->init(trackerGeometry, trackerTopology, cablingMap);
return returnValue;
}

void SiPixelStatusProducer::beginRun(edm::Run const&, edm::EventSetup const&) {
/*Is it good to pass the objects stored in runCache to set class private members values *
or just call runCahche every time in the calss function?*/
Expand Down
79 changes: 11 additions & 68 deletions CalibTracker/SiPixelQuality/plugins/SiPixelStatusProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,73 +50,25 @@
#include "CalibTracker/SiPixelQuality/interface/SiPixelDetectorStatus.h"

/* Cache to pertain SiPixelTopoFinder */
class SiPixelTopoCache {
class SiPixelStatusCache {
public:
SiPixelTopoCache(edm::ParameterSet const& iPSet){};

std::shared_ptr<SiPixelTopoFinder> getSiPixelTopoFinder(edm::EventSetup const& iSetup) const {
std::shared_ptr<SiPixelTopoFinder> returnValue;

m_queue.pushAndWait([&]() {
if (!this->siPixelFedCablingMapWatcher_.check(iSetup) && !this->trackerDIGIGeoWatcher_.check(iSetup) &&
!this->trackerTopoWatcher_.check(iSetup)) {
/*the condition hasn't changed so we can just use our old value*/
returnValue = m_mostRecentSiPixelTopoFinder_;
} else {
edm::ESHandle<TrackerGeometry> tkGeoHandle;
iSetup.get<TrackerDigiGeometryRecord>().get(tkGeoHandle);
const TrackerGeometry* trackerGeometry = tkGeoHandle.product();

edm::ESHandle<TrackerTopology> tkTopoHandle;
iSetup.get<TrackerTopologyRcd>().get(tkTopoHandle);
const TrackerTopology* trackerTopology = tkTopoHandle.product();

edm::ESHandle<SiPixelFedCablingMap> cMapHandle;
iSetup.get<SiPixelFedCablingMapRcd>().get(cMapHandle);
const SiPixelFedCablingMap* cablingMap = cMapHandle.product();

/*the condition has changed so we need to update*/
//const TrackerGeometry* trackerGeometry = &iSetup.getData(trackerGeometryToken);
//const TrackerTopology* trackerTopology = &iSetup.getData(trackerTopologyToken);
//const SiPixelFedCablingMap* cablingMap = &iSetup.getData(siPixelFedCablingMapToken);

returnValue = m_holder.makeOrGet([]() { return new SiPixelTopoFinder(); });
returnValue->init(trackerGeometry, trackerTopology, cablingMap);

m_mostRecentSiPixelTopoFinder_ = returnValue;
}
}); //m_queue

return returnValue;
}

private:
mutable edm::ReusableObjectHolder<SiPixelTopoFinder> m_holder;
mutable edm::SerialTaskQueue m_queue;

/* Condition watchers */
/* CablingMaps */
mutable edm::ESWatcher<SiPixelFedCablingMapRcd> siPixelFedCablingMapWatcher_;
/* TrackerDIGIGeo */
mutable edm::ESWatcher<TrackerDigiGeometryRecord> trackerDIGIGeoWatcher_;
/* TrackerTopology */
mutable edm::ESWatcher<TrackerTopologyRcd> trackerTopoWatcher_;

/* SiPixelTopoFinder */
mutable std::shared_ptr<SiPixelTopoFinder> m_mostRecentSiPixelTopoFinder_;
//NOTE: these are only changes in the constructor call
mutable edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeometryToken_;
mutable edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> trackerTopologyToken_;
mutable edm::ESGetToken<SiPixelFedCablingMap, SiPixelFedCablingMapRcd> siPixelFedCablingMapToken_;
};

/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

class SiPixelStatusProducer :

public edm::stream::EDProducer<edm::GlobalCache<SiPixelTopoCache>,
public edm::stream::EDProducer<edm::GlobalCache<SiPixelStatusCache>,
edm::RunCache<SiPixelTopoFinder>,
edm::LuminosityBlockSummaryCache<std::vector<SiPixelDetectorStatus>>,
edm::EndLuminosityBlockProducer,
edm::Accumulator> {
public:
SiPixelStatusProducer(edm::ParameterSet const& iPSet, SiPixelTopoCache const*);
SiPixelStatusProducer(edm::ParameterSet const& iPSet, SiPixelStatusCache const*);
~SiPixelStatusProducer() override;

/* module description */
Expand Down Expand Up @@ -150,23 +102,20 @@ class SiPixelStatusProducer :

/* For global or runCache */

static std::unique_ptr<SiPixelTopoCache> initializeGlobalCache(edm::ParameterSet const& iPSet) {
static std::unique_ptr<SiPixelStatusCache> initializeGlobalCache(edm::ParameterSet const& iPSet) {
edm::LogInfo("SiPixelStatusProducer") << "Init global Cache " << std::endl;
return std::make_unique<SiPixelTopoCache>(iPSet);
return std::make_unique<SiPixelStatusCache>();
}

static std::shared_ptr<SiPixelTopoFinder> globalBeginRun(edm::Run const& iRun,
edm::EventSetup const& iSetup,
GlobalCache const* iCache) {
edm::LogInfo("SiPixelStatusProducer") << "Global beginRun " << std::endl;
return iCache->getSiPixelTopoFinder(iSetup);
}
GlobalCache const* iCache);

static void globalEndRun(edm::Run const& iRun, edm::EventSetup const&, RunContext const* iContext) {
/* Do nothing */
}

static void globalEndJob(SiPixelTopoCache const*) { /* Do nothing */
static void globalEndJob(SiPixelStatusCache const*) { /* Do nothing */
}

static std::shared_ptr<std::vector<SiPixelDetectorStatus>> globalBeginLuminosityBlockSummary(
Expand Down Expand Up @@ -228,12 +177,6 @@ class SiPixelStatusProducer :
edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster>> fSiPixelClusterToken_;
std::vector<edm::EDGetTokenT<PixelFEDChannelCollection>> theBadPixelFEDChannelsTokens_;

/*
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeometryToken_;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> trackerTopologyToken_;
edm::ESGetToken<SiPixelFedCablingMap, SiPixelFedCablingMapRcd> siPixelFedCablingMapToken_;
*/

/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/* private data member, one instance per stream */

Expand Down