Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:02

0001 #ifndef DataFormats_Provenance_ParentageRegistry_h
0002 #define DataFormats_Provenance_ParentageRegistry_h
0003 
0004 #include "oneapi/tbb/concurrent_unordered_map.h"
0005 
0006 #include "DataFormats/Provenance/interface/Parentage.h"
0007 #include "DataFormats/Provenance/interface/ParentageID.h"
0008 
0009 // Note that this registry is *not* directly persistable. The contents
0010 // are persisted, but not the container.
0011 namespace edm {
0012   class ParentageRegistry {
0013   public:
0014     typedef edm::ParentageID key_type;
0015     typedef edm::Parentage value_type;
0016 
0017     static ParentageRegistry* instance();
0018 
0019     /// Retrieve the value_type object with the given key.
0020     /// If we return 'true', then 'result' carries the
0021     /// value_type object.
0022     /// If we return 'false, no matching key was found, and
0023     /// the value of 'result' is undefined.
0024     bool getMapped(key_type const& k, value_type& result) const;
0025 
0026     /** Retrieve a pointer to the value_type object with the given key.
0027      If there is no object associated with the given key 0 is returned.
0028      */
0029     value_type const* getMapped(key_type const& k) const;
0030 
0031     /// Insert the given value_type object into the
0032     /// registry. If there was already a value_type object
0033     /// with the same key, we don't change it. This should be OK,
0034     /// since it should have the same contents if the key is the
0035     /// same.  Return 'true' if we really added the new
0036     /// value_type object, and 'false' if the
0037     /// value_type object was already present.
0038     bool insertMapped(value_type const& v);
0039     bool insertMapped(value_type&& v);
0040 
0041     ///Not thread safe
0042     void clear();
0043 
0044     struct key_hash {
0045       std::size_t operator()(key_type const& iKey) const { return iKey.smallHash(); }
0046     };
0047 
0048   private:
0049     oneapi::tbb::concurrent_unordered_map<key_type, value_type, key_hash> m_map;
0050   };
0051 
0052 }  // namespace edm
0053 
0054 #endif