test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelClusterShapeCache.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 #ifndef DataFormats_SiPixelCluster_SiPixelClusterShapeData_h
3 #define DataFormats_SiPixelCluster_SiPixelClusterShapeData_h
4 
10 
11 #include <utility>
12 #include <vector>
13 #include <algorithm>
14 #include <cassert>
15 #include <memory>
16 
17 class PixelGeomDetUnit;
18 
20 public:
21  typedef std::vector<std::pair<int, int> >::const_iterator const_iterator;
22  typedef std::pair<const_iterator, const_iterator> Range;
24  begin_(begin), end_(end), isStraight_(isStraight), isComplete_(isComplete), hasBigPixelsOnlyInside_(hasBigPixelsOnlyInside)
25  {}
27 
28  Range size() const { return std::make_pair(begin_, end_); }
29 
30  bool isStraight() const { return isStraight_; }
31  bool isComplete() const { return isComplete_; }
33 
34 private:
37 };
38 
40 public:
42 
43  struct Field {
45 
46  Field(unsigned off, unsigned siz, bool s, bool c, bool h):
47  offset(off), size(siz), straight(s), complete(c), has(h), filled(true) {}
48  unsigned offset: 24; // room for 2^24/9 = ~2.8e6 clusters, should be enough
49  unsigned size: 4; // max 9 elements / cluster (2^4=16)
50  unsigned straight:1;
51  unsigned complete:1;
52  unsigned has:1;
53  unsigned filled:1;
54  };
55 
56  struct LazyGetter {
57  LazyGetter();
58  virtual ~LazyGetter();
59 
60  virtual void fill(const ClusterRef& cluster, const PixelGeomDetUnit *pixDet, const SiPixelClusterShapeCache& cache) const = 0;
61  };
62 
64  explicit SiPixelClusterShapeCache(const edm::HandleBase& handle): productId_(handle.id()) {}
65  SiPixelClusterShapeCache(const edm::HandleBase& handle, std::shared_ptr<LazyGetter> getter): getter_(getter), productId_(handle.id()) {}
68 
69  void resize(size_t size) {
70  data_.resize(size);
71  sizeData_.reserve(size);
72  }
73 
75  data_.swap(other.data_);
76  sizeData_.swap(other.sizeData_);
77  std::swap(getter_, other.getter_);
79  }
80 
81 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
82  void shrink_to_fit() {
83  data_.shrink_to_fit();
84  sizeData_.shrink_to_fit();
85  }
86 
87  template <typename T>
88  void insert(const ClusterRef& cluster, const T& data) {
89  static_assert(T::ArrayType::capacity() <= 16, "T::ArrayType::capacity() more than 16, bit field too narrow");
90  checkRef(cluster);
91 
92  data_[cluster.index()] = Field(sizeData_.size(), data.size.size(), data.isStraight, data.isComplete, data.hasBigPixelsOnlyInside);
93  std::copy(data.size.begin(), data.size.end(), std::back_inserter(sizeData_));
94  }
95 
96  bool isFilled(const ClusterRef& cluster) const {
97  checkRef(cluster);
98  return data_[cluster.index()].filled;
99  }
100 
101  SiPixelClusterShapeData get(const ClusterRef& cluster, const PixelGeomDetUnit *pixDet) const {
102  checkRef(cluster);
103  Field f = data_[cluster.index()];
104  if(!f.filled) {
105  assert(getter_);
106  getter_->fill(cluster, pixDet, *this);
107  f = data_[cluster.index()];
108  }
109 
110  auto beg = sizeData_.begin()+f.offset;
111  auto end = beg+f.size;
112 
113  return SiPixelClusterShapeData(beg, end, f.straight, f.complete, f.has);
114  }
115 #endif
116 
117 private:
118  void checkRef(const ClusterRef& cluster) const;
119 
120  std::vector<Field> data_;
121  std::vector<std::pair<int, int> > sizeData_;
122  std::shared_ptr<LazyGetter> getter_;
124 };
125 
126 #endif
std::shared_ptr< LazyGetter > getter_
bool isFilled(const ClusterRef &cluster) const
void insert(const ClusterRef &cluster, const T &data)
std::vector< std::pair< int, int > > sizeData_
void checkRef(const ClusterRef &cluster) const
Field(unsigned off, unsigned siz, bool s, bool c, bool h)
virtual void fill(const ClusterRef &cluster, const PixelGeomDetUnit *pixDet, const SiPixelClusterShapeCache &cache) const =0
assert(m_qm.get())
key_type index() const
Definition: Ref.h:267
SiPixelClusterShapeCache(const edm::HandleBase &handle)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
SiPixelClusterShapeCache(const edm::HandleBase &handle, std::shared_ptr< LazyGetter > getter)
tuple handle
Definition: patZpeak.py:22
std::pair< const_iterator, const_iterator > Range
double f[11][100]
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define end
Definition: vmac.h:37
std::vector< std::pair< int, int > >::const_iterator const_iterator
Pixel cluster – collection of neighboring pixels above threshold.
#define begin
Definition: vmac.h:30
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
volatile std::atomic< bool > shutdown_flag false
SiPixelClusterShapeData(const_iterator begin, const_iterator end, bool isStraight, bool isComplete, bool hasBigPixelsOnlyInside)
long double T
void swap(SiPixelClusterShapeCache &other)
edm::Ref< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster > ClusterRef
tuple size
Write out results.
SiPixelClusterShapeCache(const edm::ProductID &id)