CMS 3D CMS Logo

MuonDigiCollection.h
Go to the documentation of this file.
1 #ifndef DataFormats_MuonDigiCollection_h
2 #define DataFormats_MuonDigiCollection_h
3 
12 #include <vector>
13 #include <map>
14 #include <iterator>
16 
30 template <typename IndexType, typename DigiType>
32 public:
33  typedef typename std::vector<DigiType>::const_iterator DigiRangeIterator;
34  typedef std::map<IndexType, std::vector<DigiType> > BaseContainer;
35  typedef typename BaseContainer::const_iterator BaseIterator;
36 
37  typedef std::pair<IndexType, std::pair<DigiRangeIterator, DigiRangeIterator> > value_type;
38  typedef value_type reference;
39  typedef void pointer;
40  typedef typename DigiRangeIterator::difference_type difference_type;
41  typedef typename DigiRangeIterator::iterator_category iterator_category;
42 
44  DigiContainerIterator(BaseIterator i) : base_(i) {}
45  // implicit copy constructor
46  // implicit assignment operator
47  // implicit destructor
48 
50 
52  ++base_;
53  return *this;
54  }
55 
56  bool operator==(const DigiContainerIterator& x) const { return x.base_ == base_; }
57 
58  bool operator!=(const DigiContainerIterator& x) const { return x.base_ != base_; }
59 
60  value_type operator*(void)const {
61  return std::make_pair(base_->first, std::make_pair(base_->second.begin(), base_->second.end()));
62  }
63 
64 private:
65  BaseIterator base_;
66 };
67 
87 template <typename IndexType, typename DigiType>
89 public:
91 
92  // void swap(MuonDigiCollection<IndexType,DigiType> & rh) { std::swap(data_,rh.data_);}
93  void swap(MuonDigiCollection& rh) { std::swap(data_, rh.data_); }
94 
95  typedef typename std::vector<DigiType>::const_iterator const_iterator;
96  typedef typename std::pair<const_iterator, const_iterator> Range;
97 
99  void insertDigi(const IndexType& index, const DigiType& digi) {
100  std::vector<DigiType>& digis = data_[index];
101  digis.push_back(digi);
102  }
103 
105  void put(Range range, const IndexType& index) {
106  std::vector<DigiType>& digis = data_[index];
107  digis.reserve(digis.size() + (range.second - range.first));
108  std::copy(range.first, range.second, std::back_inserter(digis));
109  }
110 
111 #ifndef CMS_NOCXX11
112  template <typename IRange>
114  void move(IRange range, const IndexType& index) {
115  std::vector<DigiType>& digis = data_[index];
116  digis.reserve(digis.size() + (range.second - range.first));
117  digis.insert(digis.end(), std::make_move_iterator(range.first), std::make_move_iterator(range.second));
118  }
119 #endif
120 
122  Range get(const IndexType& index) const {
123  typename container::const_iterator it = data_.find(index);
124  if (it == data_.end()) {
125  // if data_ is empty there is no other way to get an empty range
126  static const std::vector<DigiType> empty;
127  return std::make_pair(empty.end(), empty.end());
128  }
129  const std::vector<DigiType>& digis = (*it).second;
130  return std::make_pair(digis.begin(), digis.end());
131  }
132 
134 
135  DigiRangeIterator begin() const { return data_.begin(); }
136 
137  DigiRangeIterator end() const { return data_.end(); }
138 
139 private:
140  typedef std::map<IndexType, std::vector<DigiType> > container;
141  container data_;
142 
143 }; // MuonDigiCollection
144 
145 template <typename IndexType, typename DigiType>
147  rh.swap(lh);
148 }
149 
150 #endif
std::vector< DigiType >::const_iterator DigiRangeIterator
void swap(MuonDigiCollection &rh)
DigiContainerIterator< IndexType, DigiType > DigiRangeIterator
void swap(MuonDigiCollection< IndexType, DigiType > &rh, MuonDigiCollection< IndexType, DigiType > &lh)
std::map< IndexType, std::vector< DigiType > > BaseContainer
void insertDigi(const IndexType &index, const DigiType &digi)
insert a digi for a given DetUnit
bool int lh
Definition: SIMDVec.h:20
value_type operator*(void) const
DigiRangeIterator::iterator_category iterator_category
DigiRangeIterator::difference_type difference_type
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::map< IndexType, std::vector< DigiType > > container
bool operator==(const DigiContainerIterator &x) const
bool operator!=(const DigiContainerIterator &x) const
std::pair< IndexType, std::pair< DigiRangeIterator, DigiRangeIterator > > value_type
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
DigiContainerIterator operator++(int)
DigiContainerIterator(BaseIterator i)
DigiRangeIterator end() const
BaseContainer::const_iterator BaseIterator
def move(src, dest)
Definition: eostools.py:511
void put(Range range, const IndexType &index)
insert a range of digis for a given DetUnit
DigiContainerIterator & operator++(void)
DigiRangeIterator begin() const
A container for a generic type of digis indexed by some index, implemented with a map<IndexType...