Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:50

0001 #ifndef DataFormats_Common_DetSet_h
0002 #define DataFormats_Common_DetSet_h
0003 
0004 /*----------------------------------------------------------------------
0005   
0006 DetSet: A struct which combines a collection of homogeneous objects
0007 associated with a common DetId with a DetId instance, holding the
0008 common DetId value. The collected objects may or may not contain their
0009 own copy of the common DetId.
0010 
0011 
0012 ----------------------------------------------------------------------*/
0013 
0014 #include <vector>
0015 #include <cstdint>
0016 #include <cstddef>
0017 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
0018 
0019 namespace edm {
0020   typedef uint32_t det_id_type;
0021 
0022   template <class T>
0023   struct DetSet {
0024     typedef std::vector<T> collection_type;
0025     // We don't just use T as value-type, in case we switch to a
0026     // fancier underlying container.
0027     typedef typename collection_type::value_type value_type;
0028     typedef typename collection_type::reference reference;
0029     typedef typename collection_type::const_reference const_reference;
0030     typedef typename collection_type::iterator iterator;
0031     typedef typename collection_type::const_iterator const_iterator;
0032     typedef typename collection_type::size_type size_type;
0033 
0034     /// default constructor
0035     DetSet() : id(0), data() {}
0036     /// constructor by detector identifier
0037     explicit DetSet(det_id_type i) : id(i), data() {}
0038 
0039 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
0040     DetSet(DetSet<T> const& rh) : id(rh.id), data(rh.data) {}
0041 
0042     DetSet<T>& operator=(DetSet<T> const& rh) {
0043       id = rh.id;
0044       data = rh.data;
0045       return *this;
0046     }
0047 
0048     DetSet(DetSet<T>&& rh) noexcept : id(rh.id), data(std::move(rh.data)) {}
0049 
0050     DetSet<T>& operator=(DetSet<T>&& rh) noexcept {
0051       id = rh.id;
0052       data = std::move(rh.data);
0053       return *this;
0054     }
0055 #endif
0056 
0057     iterator begin() { return data.begin(); }
0058     iterator end() { return data.end(); }
0059     const_iterator begin() const { return data.begin(); }
0060     const_iterator end() const { return data.end(); }
0061     size_type size() const { return data.size(); }
0062     bool empty() const { return data.empty(); }
0063     reference operator[](size_type i) { return data[i]; }
0064     const_reference operator[](size_type i) const { return data[i]; }
0065     void reserve(size_t s) { data.reserve(s); }
0066     void push_back(const T& t) { data.push_back(t); }
0067     template <class... Args>
0068     decltype(auto) emplace_back(Args&&... args) {
0069       return data.emplace_back(std::forward<Args>(args)...);
0070     }
0071     void clear() { data.clear(); }
0072     void swap(DetSet<T>& other) noexcept;
0073 
0074     det_id_type detId() const { return id; }
0075 
0076     //Used by ROOT storage
0077     CMS_CLASS_VERSION(10)
0078 
0079     det_id_type id;
0080     collection_type data;
0081   };  // template struct DetSet
0082 
0083   // TODO: If it turns out that it is confusing to have operator<
0084   // defined for DetSet, because this op< ignores the data member
0085   // 'data', we could instead specialize the std::less class template
0086   // directly.
0087 
0088   template <class T>
0089   inline bool operator<(DetSet<T> const& x, DetSet<T> const& y) {
0090     return x.detId() < y.detId();
0091   }
0092 
0093   template <class T>
0094   inline bool operator<(DetSet<T> const& x, det_id_type y) {
0095     return x.detId() < y;
0096   }
0097 
0098   template <class T>
0099   inline bool operator<(det_id_type x, DetSet<T> const& y) {
0100     return x < y.detId();
0101   }
0102 
0103   template <class T>
0104   inline void DetSet<T>::swap(DetSet<T>& other) noexcept {
0105     data.swap(other.data);
0106     std::swap(id, other.id);
0107   }
0108 
0109   template <class T>
0110   inline void swap(DetSet<T>& a, DetSet<T>& b) {
0111     a.swap(b);
0112   }
0113 
0114 }  // namespace edm
0115 
0116 #endif