CMS 3D CMS Logo

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;
23  SiPixelClusterShapeData(const_iterator begin, const_iterator end, bool isStraight, bool isComplete, bool hasBigPixelsOnlyInside):
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:
35  const_iterator begin_, end_;
37 };
38 
40 public:
42 
43  struct Field {
44  Field(): offset(0), size(0), straight(false), complete(false), has(false), filled(false) {}
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 = ~1.8e6 clusters, should be enough
49  unsigned size: 4; // max 9 elements / cluster (2^4-1=15)
50  unsigned straight:1;
51  unsigned complete:1;
52  unsigned has:1;
53  unsigned filled:1;
54  };
55 
57  explicit SiPixelClusterShapeCache(const edm::HandleBase& handle): productId_(handle.id()) {}
58  explicit SiPixelClusterShapeCache(const edm::ProductID& id): productId_(id) {}
60 
61  void resize(size_t size) {
62  data_.resize(size);
63  sizeData_.reserve(size);
64  }
65 
67  data_.swap(other.data_);
68  sizeData_.swap(other.sizeData_);
69  std::swap(productId_, other.productId_);
70  }
71 
72 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
73  void shrink_to_fit() {
74  data_.shrink_to_fit();
75  sizeData_.shrink_to_fit();
76  }
77 
78  template <typename T>
79  void insert(const ClusterRef& cluster, const T& data) {
80  static_assert(T::ArrayType::capacity() <= 15, "T::ArrayType::capacity() more than 15, bit field too narrow");
81  checkRef(cluster);
82 
83  data_[cluster.index()] = Field(sizeData_.size(), data.size.size(), data.isStraight, data.isComplete, data.hasBigPixelsOnlyInside);
84  std::copy(data.size.begin(), data.size.end(), std::back_inserter(sizeData_));
85  }
86 
87  bool isFilled(const ClusterRef& cluster) const {
88  checkRef(cluster);
89  return data_[cluster.index()].filled;
90  }
91 
92  SiPixelClusterShapeData get(const ClusterRef& cluster, const PixelGeomDetUnit *pixDet) const {
93  checkRef(cluster);
94  Field f = data_[cluster.index()];
95  assert(f.filled);
96 
97  auto beg = sizeData_.begin()+f.offset;
98  auto end = beg+f.size;
99 
100  return SiPixelClusterShapeData(beg, end, f.straight, f.complete, f.has);
101  }
102 #endif
103 
104 private:
105  void checkRef(const ClusterRef& cluster) const;
106 
107  std::vector<Field> data_;
108  std::vector<std::pair<int, int> > sizeData_;
110 };
111 
112 #endif
bool isFilled(const ClusterRef &cluster) const
void insert(const ClusterRef &cluster, const T &data)
std::vector< std::pair< int, int > > sizeData_
Field(unsigned off, unsigned siz, bool s, bool c, bool h)
def copy(args, dbName)
key_type index() const
Definition: Ref.h:268
SiPixelClusterShapeCache(const edm::HandleBase &handle)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::pair< const_iterator, const_iterator > Range
double f[11][100]
#define end
Definition: vmac.h:39
std::vector< std::pair< int, int > >::const_iterator const_iterator
Pixel cluster – collection of neighboring pixels above threshold.
#define begin
Definition: vmac.h:32
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void checkRef(const RP &rp, const R &r)
throw if r hasn&#39;t the same id as rp
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
SiPixelClusterShapeCache(const edm::ProductID &id)