CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelClusterShapeCacheProducer.cc
Go to the documentation of this file.
7 
10 
14 
18 
21 
24 
25 #include <cassert>
26 
27 namespace {
28  class ClusterShapeLazyGetter: public SiPixelClusterShapeCache::LazyGetter {
29  public:
30  ClusterShapeLazyGetter() {}
31  ~ClusterShapeLazyGetter() {}
32 
33  void fill(const SiPixelClusterShapeCache::ClusterRef& cluster, const PixelGeomDetUnit *pixDet, const SiPixelClusterShapeCache& constCache) const override {
34  taskQueue_.pushAndWait([this, &cluster, pixDet, &constCache]{
35  if(constCache.isFilled(cluster))
36  return;
37  SiPixelClusterShapeCache& cache = const_cast<SiPixelClusterShapeCache&>(constCache);
38  this->data_.size.clear();
39  this->clusterShape_.determineShape(*pixDet, *cluster, this->data_);
40  cache.insert(cluster, this->data_);
41  });
42  }
43 
44  private:
45  mutable edm::SerialTaskQueue taskQueue_; // not sure if this is the best synchronization mechanism
46  mutable ClusterData data_; // reused
47  mutable ClusterShape clusterShape_;
48  };
49 }
50 
52 public:
53  explicit SiPixelClusterShapeCacheProducer(const edm::ParameterSet& iConfig);
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
57 
58  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup);
59 
60 private:
62 
64  const bool onDemand_;
65 };
66 
68  token_(consumes<InputCollection>(iConfig.getParameter<edm::InputTag>("src"))),
69  onDemand_(iConfig.getParameter<bool>("onDemand"))
70 {
71  produces<SiPixelClusterShapeCache>();
72 }
73 
75 
78  desc.add<edm::InputTag>("src", edm::InputTag("siPixelClusters"));
79  desc.add<bool>("onDemand", false);
80  descriptions.add("siPixelClusterShapeCache", desc);
81 }
82 
85  iEvent.getByToken(token_, input);
86 
88  iSetup.get<TrackerDigiGeometryRecord>().get(geom);
89 
90  auto filler = std::make_shared<ClusterShapeLazyGetter>();
91 
92  std::auto_ptr<SiPixelClusterShapeCache> output(onDemand_ ?
93  new SiPixelClusterShapeCache(input, filler) :
94  new SiPixelClusterShapeCache(input));
95  output->resize(input->data().size());
96 
97  if(!onDemand_) {
98  for(const auto& detSet: *input) {
99  const GeomDetUnit *genericDet = geom->idToDetUnit(detSet.detId());
100  const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(genericDet);
101  assert(pixDet);
102 
103  edmNew::DetSet<SiPixelCluster>::const_iterator iCluster = detSet.begin(), endCluster = detSet.end();
104  for(; iCluster != endCluster; ++iCluster) {
105  SiPixelClusterShapeCache::ClusterRef clusterRef = edmNew::makeRefTo(input, iCluster);
106  filler->fill(clusterRef, pixDet, *output);
107  }
108  }
109  output->shrink_to_fit();
110  }
111 
112  iEvent.put(output);
113 }
114 
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, typename HandleT::element_type::value_type::const_iterator itIter)
bool isFilled(const ClusterRef &cluster) const
void insert(const ClusterRef &cluster, const T &data)
SiPixelClusterShapeCacheProducer(const edm::ParameterSet &iConfig)
virtual void fill(const ClusterRef &cluster, const PixelGeomDetUnit *pixDet, const SiPixelClusterShapeCache &cache) const =0
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
assert(m_qm.get())
data_type const * const_iterator
Definition: DetSetNew.h:30
static std::string const input
Definition: EdmProvDump.cc:43
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const T & get() const
Definition: EventSetup.h:55
edm::EDGetTokenT< InputCollection > token_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)