File indexing completed on 2024-04-06 12:04:45
0001 #ifndef DataFormats_MuonDigiCollection_h
0002 #define DataFormats_MuonDigiCollection_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <vector>
0013 #include <map>
0014 #include <iterator>
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 template <typename IndexType, typename DigiType>
0030 class DigiContainerIterator {
0031 public:
0032 typedef typename std::vector<DigiType>::const_iterator DigiRangeIterator;
0033 typedef std::map<IndexType, std::vector<DigiType> > BaseContainer;
0034 typedef typename BaseContainer::const_iterator BaseIterator;
0035
0036 typedef std::pair<IndexType, std::pair<DigiRangeIterator, DigiRangeIterator> > value_type;
0037 typedef value_type reference;
0038 typedef void pointer;
0039 typedef typename DigiRangeIterator::difference_type difference_type;
0040 typedef typename DigiRangeIterator::iterator_category iterator_category;
0041
0042 DigiContainerIterator(void) {}
0043 DigiContainerIterator(BaseIterator i) : base_(i) {}
0044
0045
0046
0047
0048 DigiContainerIterator operator++(int) { return DigiContainerIterator(base_++); }
0049
0050 DigiContainerIterator& operator++(void) {
0051 ++base_;
0052 return *this;
0053 }
0054
0055 bool operator==(const DigiContainerIterator& x) const { return x.base_ == base_; }
0056
0057 bool operator!=(const DigiContainerIterator& x) const { return x.base_ != base_; }
0058
0059 value_type operator*(void) const {
0060 return std::make_pair(base_->first, std::make_pair(base_->second.begin(), base_->second.end()));
0061 }
0062
0063 private:
0064 BaseIterator base_;
0065 };
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 template <typename IndexType, typename DigiType>
0087 class MuonDigiCollection {
0088 public:
0089 MuonDigiCollection() {}
0090
0091
0092 void swap(MuonDigiCollection& rh) { std::swap(data_, rh.data_); }
0093
0094 typedef typename std::vector<DigiType>::const_iterator const_iterator;
0095 typedef typename std::pair<const_iterator, const_iterator> Range;
0096
0097
0098 void insertDigi(const IndexType& index, const DigiType& digi) {
0099 std::vector<DigiType>& digis = data_[index];
0100 digis.push_back(digi);
0101 }
0102
0103
0104 void put(Range range, const IndexType& index) {
0105 std::vector<DigiType>& digis = data_[index];
0106 digis.reserve(digis.size() + (range.second - range.first));
0107 std::copy(range.first, range.second, std::back_inserter(digis));
0108 }
0109
0110 #ifndef CMS_NOCXX11
0111
0112 template <typename IRange>
0113 void move(IRange range, const IndexType& index) {
0114 std::vector<DigiType>& digis = data_[index];
0115 digis.reserve(digis.size() + (range.second - range.first));
0116 digis.insert(digis.end(), std::make_move_iterator(range.first), std::make_move_iterator(range.second));
0117 }
0118 #endif
0119
0120
0121 Range get(const IndexType& index) const {
0122 typename container::const_iterator it = data_.find(index);
0123 if (it == data_.end()) {
0124
0125 static const std::vector<DigiType> empty;
0126 return std::make_pair(empty.end(), empty.end());
0127 }
0128 const std::vector<DigiType>& digis = (*it).second;
0129 return std::make_pair(digis.begin(), digis.end());
0130 }
0131
0132 typedef DigiContainerIterator<IndexType, DigiType> DigiRangeIterator;
0133
0134 DigiRangeIterator begin() const { return data_.begin(); }
0135
0136 DigiRangeIterator end() const { return data_.end(); }
0137
0138 private:
0139 typedef std::map<IndexType, std::vector<DigiType> > container;
0140 container data_;
0141
0142 };
0143
0144 template <typename IndexType, typename DigiType>
0145 inline void swap(MuonDigiCollection<IndexType, DigiType>& rh, MuonDigiCollection<IndexType, DigiType>& lh) {
0146 rh.swap(lh);
0147 }
0148
0149 #endif