CMS 3D CMS Logo

RegionalOutput.h
Go to the documentation of this file.
1 #ifndef DataFormats_L1Trigger_RegionalOutput_h
2 #define DataFormats_L1Trigger_RegionalOutput_h
3 
7 #include <vector>
8 
9 namespace l1t {
10  template <typename T>
12  public:
13  typedef typename T::value_type value_type;
14  typedef edm::Ref<T> ref;
16 
17  class iterator {
18  public:
19  typedef typename T::value_type value_type;
20  typedef ptrdiff_t difference_type;
21  iterator(const RegionalOutput<T>& src, unsigned int idx) : src_(&src), idx_(idx) {}
22  iterator(iterator const& it) : src_(it.src_), idx_(it.idx_) {}
23  iterator() : src_(nullptr), idx_(0) {}
25  ++idx_;
26  return *this;
27  }
29  iterator ci = *this;
30  ++idx_;
31  return ci;
32  }
34  --idx_;
35  return *this;
36  }
38  iterator ci = *this;
39  --idx_;
40  return ci;
41  }
42  difference_type operator-(iterator const& o) const { return idx_ - o.idx_; }
45  bool operator<(iterator const& o) const { return idx_ < o.idx_; }
46  bool operator==(iterator const& ci) const { return idx_ == ci.idx_; }
47  bool operator!=(iterator const& ci) const { return idx_ != ci.idx_; }
48  value_type const& operator*() const { return src_->objAt(idx_); }
49  value_type const* operator->() const { return &src_->objAt(idx_); }
51  idx_ += d;
52  return *this;
53  }
55  idx_ -= d;
56  return *this;
57  }
58  value_type const& operator[](difference_type d) const { return src_->objAt(idx_ + d); }
59  // interface to get EDM refs & related stuff
60  edm::Ref<T> ref() const { return src_->refAt(idx_); }
61  edm::ProductID id() const { return src_->id(); }
62  unsigned int idx() const { return idx_; }
63  unsigned int key() const { return idx_; }
64 
65  private:
67  unsigned int idx_;
68  };
70 
71  class Region {
72  public:
73  typedef typename T::value_type value_type;
76 
77  const value_type& operator[](unsigned int idx) const { return src_->objAt(ibegin_ + idx); }
78  const value_type& front() const { return src_->objAt(ibegin_); }
79  const value_type& back() const { return src_->objAt(iend_ - 1); }
80  iterator begin() const { return iterator(*src_, ibegin_); }
81  iterator end() const { return iterator(*src_, iend_); }
82  unsigned int size() const { return iend_ - ibegin_; }
83  bool empty() const { return (iend_ == ibegin_); }
84  // interface to get EDM refs & related stuff
85  ref refAt(unsigned int idx) const { return src_->refAt(ibegin_ + idx); }
86  edm::ProductID id() const { return src_->id(); }
87 
88  private:
90  unsigned int ibegin_, iend_;
91  friend class RegionalOutput<T>;
92  Region(const RegionalOutput<T>* src, unsigned int ibegin, unsigned int iend)
93  : src_(src), ibegin_(ibegin), iend_(iend) {}
94  };
95 
98 
99  void addRegion(const std::vector<int>& indices, const float eta, const float phi) {
100  regions_.emplace_back((regions_.empty() ? 0 : regions_.back()) + indices.size());
101  values_.insert(values_.end(), indices.begin(), indices.end());
102  etas_.push_back(eta);
103  phis_.push_back(phi);
104  }
105 
106  edm::ProductID id() const { return refprod_.id(); }
107  unsigned int size() const { return values_.size(); }
108  unsigned int nRegions() const { return regions_.size(); }
109  bool empty() const { return values_.empty(); }
110  void clear() {
111  values_.clear();
112  regions_.clear();
113  etas_.clear();
114  phis_.clear();
115  }
116  void shrink_to_fit() {
117  values_.shrink_to_fit();
118  regions_.shrink_to_fit();
119  etas_.shrink_to_fit();
120  phis_.shrink_to_fit();
121  }
122 
123  const_iterator begin() const { return const_iterator(this, 0); }
124  const_iterator end() const { return const_iterator(this, values_.size()); }
125 
126  Region region(unsigned int ireg) const {
127  if (ireg >= regions_.size())
128  throw cms::Exception("Region index out of bounds");
129  return Region(this, ireg == 0 ? 0 : regions_[ireg - 1], regions_[ireg]);
130  }
131 
132  const float eta(unsigned int ireg) const { return etas_[ireg]; }
133  const float phi(unsigned int ireg) const { return phis_[ireg]; }
134 
135  ref refAt(unsigned int idx) const { return ref(refprod_, values_[idx]); }
136  const value_type& objAt(unsigned int idx) const { return (*refprod_)[values_[idx]]; }
137 
138  //Used by ROOT storage
140 
141  protected:
143  std::vector<unsigned int> values_; // list of indices to objects in each region, flattened.
144  std::vector<unsigned int> regions_; // for each region, store the index of one-past the last object in values
145  std::vector<float> etas_; // floatEtaCenter of each PFregion
146  std::vector<float> phis_; // floatPhiCenter of each PFregion
147  };
148 } // namespace l1t
149 #endif
const float eta(unsigned int ireg) const
std::vector< float > etas_
edm::ProductID id() const
std::vector< unsigned int > regions_
edm::RefProd< T > refprod
bool operator<(iterator const &o) const
const_iterator begin() const
unsigned int idx() const
const value_type & back() const
std::vector< float > phis_
iterator(const RegionalOutput< T > &src, unsigned int idx)
edm::ProductID id() const
std::vector< unsigned int > values_
Region region(unsigned int ireg) const
T::value_type value_type
delete x;
Definition: CaloConfig.h:22
ref refAt(unsigned int idx) const
value_type const & operator[](difference_type d) const
Region(const RegionalOutput< T > *src, unsigned int ibegin, unsigned int iend)
value_type const * operator->() const
#define CMS_CLASS_VERSION(_version_)
iterator operator+(difference_type n) const
unsigned int key() const
iterator(iterator const &it)
difference_type operator-(iterator const &o) const
iterator & operator-=(difference_type d)
bool operator!=(iterator const &ci) const
edm::Ref< T > ref
const float phi(unsigned int ireg) const
iterator operator-(difference_type n) const
ref refAt(unsigned int idx) const
unsigned int nRegions() const
bool operator==(iterator const &ci) const
iterator & operator+=(difference_type d)
edm::Ref< T > ref() const
const_iterator end() const
value_type const & operator*() const
unsigned int size() const
const value_type & objAt(unsigned int idx) const
d
Definition: ztail.py:151
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:124
RegionalOutput< T >::const_iterator const_iterator
void addRegion(const std::vector< int > &indices, const float eta, const float phi)
const RegionalOutput< T > * src_
RegionalOutput(const edm::RefProd< T > &prod)
const value_type & operator[](unsigned int idx) const
const value_type & front() const
RegionalOutput< T >::iterator iterator
unsigned int size() const
const RegionalOutput< T > * src_
edm::ProductID id() const
long double T