Skip to content

Commit

Permalink
Merge pull request #12035 from Dr15Jones/removeLazyGetterFromSiPixelC…
Browse files Browse the repository at this point in the history
…lusterShapeCache

Removed LazyGetter from SiPixelClusterShapeCache
  • Loading branch information
cmsbuild committed Oct 22, 2015
2 parents 60f7e93 + e57e729 commit 5a2c839
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 63 deletions.
16 changes: 1 addition & 15 deletions DataFormats/SiPixelCluster/interface/SiPixelClusterShapeCache.h
Expand Up @@ -53,16 +53,8 @@ class SiPixelClusterShapeCache {
unsigned filled:1;
};

struct LazyGetter {
LazyGetter();
virtual ~LazyGetter();

virtual void fill(const ClusterRef& cluster, const PixelGeomDetUnit *pixDet, const SiPixelClusterShapeCache& cache) const = 0;
};

SiPixelClusterShapeCache() {};
explicit SiPixelClusterShapeCache(const edm::HandleBase& handle): productId_(handle.id()) {}
SiPixelClusterShapeCache(const edm::HandleBase& handle, std::shared_ptr<LazyGetter> getter): getter_(getter), productId_(handle.id()) {}
explicit SiPixelClusterShapeCache(const edm::ProductID& id): productId_(id) {}
~SiPixelClusterShapeCache();

Expand All @@ -74,7 +66,6 @@ class SiPixelClusterShapeCache {
void swap(SiPixelClusterShapeCache& other) {
data_.swap(other.data_);
sizeData_.swap(other.sizeData_);
std::swap(getter_, other.getter_);
std::swap(productId_, other.productId_);
}

Expand All @@ -101,11 +92,7 @@ class SiPixelClusterShapeCache {
SiPixelClusterShapeData get(const ClusterRef& cluster, const PixelGeomDetUnit *pixDet) const {
checkRef(cluster);
Field f = data_[cluster.index()];
if(!f.filled) {
assert(getter_);
getter_->fill(cluster, pixDet, *this);
f = data_[cluster.index()];
}
assert(f.filled);

auto beg = sizeData_.begin()+f.offset;
auto end = beg+f.size;
Expand All @@ -119,7 +106,6 @@ class SiPixelClusterShapeCache {

std::vector<Field> data_;
std::vector<std::pair<int, int> > sizeData_;
std::shared_ptr<LazyGetter> getter_;
edm::ProductID productId_;
};

Expand Down
3 changes: 0 additions & 3 deletions DataFormats/SiPixelCluster/src/SiPixelClusterShapeCache.cc
Expand Up @@ -3,9 +3,6 @@

SiPixelClusterShapeData::~SiPixelClusterShapeData() {}

SiPixelClusterShapeCache::LazyGetter::LazyGetter() {}
SiPixelClusterShapeCache::LazyGetter::~LazyGetter() {}

SiPixelClusterShapeCache::~SiPixelClusterShapeCache() {}

void SiPixelClusterShapeCache::checkRef(const ClusterRef& ref) const {
Expand Down
@@ -1,4 +1,4 @@
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
Expand All @@ -23,47 +23,27 @@

#include <cassert>

namespace {
class ClusterShapeLazyGetter: public SiPixelClusterShapeCache::LazyGetter {
public:
ClusterShapeLazyGetter() {}
~ClusterShapeLazyGetter() {}

void fill(const SiPixelClusterShapeCache::ClusterRef& cluster, const PixelGeomDetUnit *pixDet, const SiPixelClusterShapeCache& constCache) const override {
if(constCache.isFilled(cluster))
return;
SiPixelClusterShapeCache& cache = const_cast<SiPixelClusterShapeCache&>(constCache);
this->data_.size.clear();
this->clusterShape_.determineShape(*pixDet, *cluster, this->data_);
cache.insert(cluster, this->data_);
}

private:
mutable ClusterData data_; // reused
mutable ClusterShape clusterShape_;
};
}

class SiPixelClusterShapeCacheProducer: public edm::stream::EDProducer<> {
class SiPixelClusterShapeCacheProducer: public edm::global::EDProducer<> {
public:
explicit SiPixelClusterShapeCacheProducer(const edm::ParameterSet& iConfig);
~SiPixelClusterShapeCacheProducer();

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

void produce(edm::Event& iEvent, const edm::EventSetup& iSetup);
void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const;

private:
using InputCollection = edmNew::DetSetVector<SiPixelCluster>;

edm::EDGetTokenT<InputCollection> token_;
const bool onDemand_;
const edm::EDGetTokenT<InputCollection> token_;
};

SiPixelClusterShapeCacheProducer::SiPixelClusterShapeCacheProducer(const edm::ParameterSet& iConfig):
token_(consumes<InputCollection>(iConfig.getParameter<edm::InputTag>("src"))),
onDemand_(iConfig.getParameter<bool>("onDemand"))
token_(consumes<InputCollection>(iConfig.getParameter<edm::InputTag>("src")))
{
if(iConfig.getParameter<bool>("onDemand")) {
throw cms::Exception("OnDemandNotAllowed")<<"Use of the `onDemand` feature of SiPixelClusterShapeCacheProducer is no longer supported";
}
produces<SiPixelClusterShapeCache>();
}

Expand All @@ -72,38 +52,40 @@ SiPixelClusterShapeCacheProducer::~SiPixelClusterShapeCacheProducer() {}
void SiPixelClusterShapeCacheProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("src", edm::InputTag("siPixelClusters"));
desc.add<bool>("onDemand", false);
desc.add<bool>("onDemand", false)->setComment("The on demand feature is no longer supported");
descriptions.add("siPixelClusterShapeCache", desc);
}

void SiPixelClusterShapeCacheProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
void SiPixelClusterShapeCacheProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
edm::Handle<InputCollection> input;
iEvent.getByToken(token_, input);

edm::ESHandle<TrackerGeometry> geom;
iSetup.get<TrackerDigiGeometryRecord>().get(geom);

auto filler = std::make_shared<ClusterShapeLazyGetter>();

std::auto_ptr<SiPixelClusterShapeCache> output(onDemand_ ?
new SiPixelClusterShapeCache(input, filler) :
new SiPixelClusterShapeCache(input));
std::auto_ptr<SiPixelClusterShapeCache> output(new SiPixelClusterShapeCache(input));
output->resize(input->data().size());

if(!onDemand_) {
for(const auto& detSet: *input) {
const GeomDetUnit *genericDet = geom->idToDetUnit(detSet.detId());
const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(genericDet);
assert(pixDet);

edmNew::DetSet<SiPixelCluster>::const_iterator iCluster = detSet.begin(), endCluster = detSet.end();
for(; iCluster != endCluster; ++iCluster) {
SiPixelClusterShapeCache::ClusterRef clusterRef = edmNew::makeRefTo(input, iCluster);
filler->fill(clusterRef, pixDet, *output);
ClusterData data; // reused
ClusterShape clusterShape;

for(const auto& detSet: *input) {
const GeomDetUnit *genericDet = geom->idToDetUnit(detSet.detId());
const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(genericDet);
assert(pixDet);

edmNew::DetSet<SiPixelCluster>::const_iterator iCluster = detSet.begin(), endCluster = detSet.end();
for(; iCluster != endCluster; ++iCluster) {
SiPixelClusterShapeCache::ClusterRef clusterRef = edmNew::makeRefTo(input, iCluster);
if(not output->isFilled(clusterRef)) {
data.size.clear();
clusterShape.determineShape(*pixDet,*iCluster, data);
output->insert(clusterRef,data);
}
}
output->shrink_to_fit();
}
output->shrink_to_fit();

iEvent.put(output);
}
Expand Down

0 comments on commit 5a2c839

Please sign in to comment.