CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DataFormats/MuonData/interface/MuonDigiCollection.h

Go to the documentation of this file.
00001 #ifndef DataFormats_MuonDigiCollection_h
00002 #define DataFormats_MuonDigiCollection_h
00003 
00014 #include <vector>
00015 #include <map>
00016 #include <iterator>
00017 
00031 template <typename IndexType, typename DigiType>
00032   class DigiContainerIterator {
00033   public:
00034     typedef typename std::vector<DigiType>::const_iterator  DigiRangeIterator;
00035     typedef std::map<IndexType, std::vector<DigiType> >     BaseContainer;
00036     typedef typename BaseContainer::const_iterator          BaseIterator;
00037 
00038     typedef std::pair<IndexType,
00039                       std::pair<DigiRangeIterator,
00040                                 DigiRangeIterator> >        value_type;
00041     typedef value_type                                      reference;
00042     typedef void                                            pointer;
00043     typedef typename DigiRangeIterator::difference_type     difference_type;
00044     typedef typename DigiRangeIterator::iterator_category   iterator_category;
00045 
00046     DigiContainerIterator (void) {}
00047     DigiContainerIterator (BaseIterator i) : base_ (i) {}
00048     // implicit copy constructor
00049     // implicit assignment operator
00050     // implicit destructor
00051 
00052     DigiContainerIterator operator++ (int)
00053     { return DigiContainerIterator (base_++); }
00054     
00055     DigiContainerIterator &operator++ (void)
00056     { ++base_; return *this; }
00057 
00058     bool operator== (const DigiContainerIterator &x)
00059     { return x.base_ == base_; }
00060 
00061     bool operator!= (const DigiContainerIterator &x)
00062     { return x.base_ != base_; }
00063 
00064     value_type operator* (void) const
00065     {
00066       return std::make_pair(base_->first,
00067                             std::make_pair(base_->second.begin(), 
00068                                            base_->second.end()));
00069     }
00070 
00071   private:
00072     BaseIterator base_;
00073   };
00074 
00075 
00076 
00077 
00097 template <typename IndexType, 
00098           typename DigiType>
00099 
00100 class MuonDigiCollection {
00101   
00102 public:
00103 
00104   MuonDigiCollection(){}
00105 
00106   typedef typename std::vector<DigiType>::const_iterator const_iterator;
00107   typedef typename std::pair<const_iterator,const_iterator> Range;
00108   
00109   
00111   void insertDigi(const IndexType& index, const DigiType& digi){
00112     std::vector<DigiType> &digis = data_[index];
00113     digis.push_back(digi);
00114   }
00115   
00117   void put(Range range, const IndexType& index){
00118     std::vector<DigiType> &digis = data_[index];
00119     digis.reserve (digis.size () + (range.second - range.first));
00120     std::copy (range.first, range.second, std::back_inserter (digis));
00121     
00122   }
00123  
00125   Range get(const IndexType& index) const{
00126     typename container::const_iterator it = data_.find(index);
00127     if (it==data_.end()) {
00128       // if data_ is empty there is no other way to get an empty range
00129       static std::vector<DigiType> empty;
00130       return std::make_pair(empty.end(),empty.end());
00131     } 
00132     const std::vector<DigiType>& digis = (*it).second;
00133     return std::make_pair(digis.begin(),digis.end());
00134   }
00135   
00136   typedef DigiContainerIterator<IndexType,DigiType> DigiRangeIterator;
00137   
00138   DigiRangeIterator begin() const { 
00139     return data_.begin();}
00140   
00141   DigiRangeIterator end() const {
00142     return data_.end();}
00143   
00144   
00145 private:
00146 
00147   typedef  std::map<IndexType,std::vector<DigiType> > container;  
00148   container data_;
00149   
00150 
00151 }; // MuonDigiCollection
00152 
00153 
00154 
00155 #endif
00156