Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:29

0001 #ifndef DataFormats_Provenance_ElementID_h
0002 #define DataFormats_Provenance_ElementID_h
0003 
0004 #include "DataFormats/Provenance/interface/ProductID.h"
0005 
0006 #include <iosfwd>
0007 
0008 namespace edm {
0009   /**
0010    * ElementID is a unique identifier for an element within a
0011    * container. It extends the ProductID concept by adding an index to
0012    * an object within a container.
0013    *
0014    * It provides both index() and key() methods so that it can be used
0015    * in place of Ref/Ptr in the interfaces of e.g. ValueMap or Association.
0016    */
0017   class ElementID {
0018   public:
0019     using key_type = unsigned int;
0020 
0021     ElementID() = default;
0022     explicit ElementID(edm::ProductID id, key_type ind) : index_(ind), id_(id) {}
0023 
0024     bool isValid() const { return id_.isValid(); }
0025     ProductID id() const { return id_; }
0026     key_type index() const { return index_; }
0027     key_type key() const { return index_; }
0028     void reset() {
0029       index_ = 0;
0030       id_.reset();
0031     }
0032 
0033     void swap(ElementID& other);
0034 
0035   private:
0036     key_type index_ = 0;
0037     ProductID id_;
0038   };
0039 
0040   inline void swap(ElementID& a, ElementID& b) { a.swap(b); }
0041 
0042   inline bool operator==(ElementID const& lh, ElementID const& rh) {
0043     return lh.index() == rh.index() && lh.id() == rh.id();
0044   }
0045 
0046   inline bool operator!=(ElementID const& lh, ElementID const& rh) { return !(lh == rh); }
0047 
0048   bool operator<(ElementID const& lh, ElementID const& rh);
0049 
0050   std::ostream& operator<<(std::ostream& os, ElementID const& id);
0051 }  // namespace edm
0052 
0053 #endif