CMS 3D CMS Logo

Phase2ITPixelClusterShapeCache.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 #ifndef DataFormats_Phase2ITPixelCluster_Phase2ITPixelClusterShapeData_h
3 #define DataFormats_Phase2ITPixelCluster_Phase2ITPixelClusterShapeData_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  Phase2ITPixelClusterShapeData(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 = ~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 
57  explicit Phase2ITPixelClusterShapeCache(const edm::HandleBase& handle): productId_(handle.id()) {}
58  explicit Phase2ITPixelClusterShapeCache(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() <= 16, "T::ArrayType::capacity() more than 16, 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  Phase2ITPixelClusterShapeData 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 Phase2ITPixelClusterShapeData(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
edm::Ref< edmNew::DetSetVector< Phase2ITPixelCluster >, Phase2ITPixelCluster > ClusterRef
void insert(const ClusterRef &cluster, const T &data)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
def copy(args, dbName)
Field(unsigned off, unsigned siz, bool s, bool c, bool h)
Phase2ITPixelClusterShapeData(const_iterator begin, const_iterator end, bool isStraight, bool isComplete, bool hasBigPixelsOnlyInside)
key_type index() const
Definition: Ref.h:268
std::vector< std::pair< int, int > >::const_iterator const_iterator
bool isFilled(const ClusterRef &cluster) const
Phase2ITPixelClusterShapeCache(const edm::HandleBase &handle)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double f[11][100]
Phase2ITPixelClusterShapeCache(const edm::ProductID &id)
#define end
Definition: vmac.h:39
std::pair< const_iterator, const_iterator > Range
Pixel cluster – collection of neighboring pixels above threshold.
std::vector< std::pair< int, int > > sizeData_
#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
long double T
void swap(Phase2ITPixelClusterShapeCache &other)