Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:57

0001 #ifndef DataFormats_Common_DetSetNew_h
0002 #define DataFormats_Common_DetSetNew_h
0003 
0004 #include "DataFormats/Common/interface/Ref.h"
0005 #include <vector>
0006 #include <cassert>
0007 
0008 namespace edmNew {
0009   //  FIXME move it elsewhere....
0010   typedef unsigned int det_id_type;
0011 
0012   template <typename T>
0013   class DetSetVector;
0014 
0015   /* a proxy to a variable size array of T belonging to
0016    * a "channel" identified by an 32bit id
0017    *
0018    * FIXME interface to be finalized once use-cases fully identified
0019    * 
0020    */
0021   template <typename T>
0022   class DetSet {
0023   public:
0024     typedef DetSetVector<T> Container;
0025     typedef unsigned int size_type;  // for persistency
0026     typedef unsigned int id_type;
0027     typedef T data_type;
0028 
0029     typedef std::vector<data_type> DataContainer;
0030     typedef data_type *iterator;
0031     typedef data_type const *const_iterator;
0032 
0033     typedef data_type value_type;
0034     typedef id_type key_type;
0035 
0036     inline DetSet() : m_id(0), m_data(nullptr), m_offset(-1), m_size(0) {}
0037     inline DetSet(id_type i, DataContainer const &idata, size_type ioffset, size_type isize)
0038         : m_id(i), m_data(&idata), m_offset(ioffset), m_size(isize) {}
0039 
0040     inline DetSet(Container const &icont, typename Container::Item const &item, bool update)
0041         : m_id(0), m_data(nullptr), m_offset(-1), m_size(0) {
0042       set(icont, item, update);
0043     }
0044 
0045     //FIXME (it may confuse users as size_type is same type as id_type...)
0046     inline void set(Container const &icont, typename Container::Item const &item, bool update = true);
0047 
0048     bool isValid() const { return m_offset >= 0; }
0049 
0050     inline data_type &operator[](size_type i) { return data()[i]; }
0051 
0052     inline data_type operator[](size_type i) const { return data()[i]; }
0053 
0054     inline iterator begin() { return data(); }
0055 
0056     inline iterator end() { return data() + m_size; }
0057 
0058     inline const_iterator begin() const { return data(); }
0059 
0060     inline const_iterator end() const { return data() + m_size; }
0061 
0062     int offset() const { return m_offset; }
0063 
0064     inline id_type id() const { return m_id; }
0065 
0066     inline id_type detId() const { return m_id; }
0067 
0068     inline size_type size() const { return m_size; }
0069 
0070     inline bool empty() const { return m_size == 0; }
0071 
0072     template <typename HandleT>
0073     edm::Ref<typename HandleT::element_type, typename HandleT::element_type::value_type::value_type> makeRefTo(
0074         HandleT const &handle, const_iterator ci) const {
0075       return edm::Ref<typename HandleT::element_type, typename HandleT::element_type::value_type::value_type>(
0076           handle.id(), ci, ci - &(container().front()));
0077     }
0078 
0079     unsigned int makeKeyOf(const_iterator ci) const { return ci - &(container().front()); }
0080 
0081   private:
0082     DataContainer const &container() const { return *m_data; }
0083 
0084     data_type const *data() const {
0085       if (m_offset | m_size)
0086         assert(m_data);
0087       return m_data ? (&((*m_data)[m_offset])) : nullptr;
0088     }
0089 
0090     data_type *data() {
0091       assert(m_data);
0092       return const_cast<data_type *>(&((*m_data)[m_offset]));
0093     }
0094 
0095     id_type m_id;
0096     DataContainer const *m_data;
0097     int m_offset;
0098     size_type m_size;
0099   };
0100 }  // namespace edmNew
0101 
0102 #endif  // DataFormats_Common_DetSet_h