Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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     bool isValid() const { return m_offset >= 0; }
0046 
0047     inline data_type &operator[](size_type i) { return data()[i]; }
0048 
0049     inline data_type operator[](size_type i) const { return data()[i]; }
0050 
0051     inline iterator begin() { return data(); }
0052 
0053     inline iterator end() { return data() + m_size; }
0054 
0055     inline const_iterator begin() const { return data(); }
0056 
0057     inline const_iterator end() const { return data() + m_size; }
0058 
0059     int offset() const { return m_offset; }
0060 
0061     inline id_type id() const { return m_id; }
0062 
0063     inline id_type detId() const { return m_id; }
0064 
0065     inline size_type size() const { return m_size; }
0066 
0067     inline bool empty() const { return m_size == 0; }
0068 
0069     template <typename HandleT>
0070     edm::Ref<typename HandleT::element_type, typename HandleT::element_type::value_type::value_type> makeRefTo(
0071         HandleT const &handle, const_iterator ci) const {
0072       return edm::Ref<typename HandleT::element_type, typename HandleT::element_type::value_type::value_type>(
0073           handle.id(), ci, ci - &(container().front()));
0074     }
0075 
0076     unsigned int makeKeyOf(const_iterator ci) const { return ci - &(container().front()); }
0077 
0078   private:
0079     //FIXME (it may confuse users as size_type is same type as id_type...)
0080     inline void set(Container const &icont, typename Container::Item const &item, bool update = true);
0081 
0082     DataContainer const &container() const { return *m_data; }
0083 
0084     data_type const *data() const {
0085       if (isValid() || !empty())
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