ParentageRegistry

key_hash

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#ifndef DataFormats_Provenance_ParentageRegistry_h
#define DataFormats_Provenance_ParentageRegistry_h

#include "oneapi/tbb/concurrent_unordered_map.h"

#include "DataFormats/Provenance/interface/Parentage.h"
#include "DataFormats/Provenance/interface/ParentageID.h"

// Note that this registry is *not* directly persistable. The contents
// are persisted, but not the container.
namespace edm {
  class ParentageRegistry {
  public:
    typedef edm::ParentageID key_type;
    typedef edm::Parentage value_type;

    static ParentageRegistry* instance();

    /// Retrieve the value_type object with the given key.
    /// If we return 'true', then 'result' carries the
    /// value_type object.
    /// If we return 'false, no matching key was found, and
    /// the value of 'result' is undefined.
    bool getMapped(key_type const& k, value_type& result) const;

    /** Retrieve a pointer to the value_type object with the given key.
     If there is no object associated with the given key 0 is returned.
     */
    value_type const* getMapped(key_type const& k) const;

    /// Insert the given value_type object into the
    /// registry. If there was already a value_type object
    /// with the same key, we don't change it. This should be OK,
    /// since it should have the same contents if the key is the
    /// same.  Return 'true' if we really added the new
    /// value_type object, and 'false' if the
    /// value_type object was already present.
    bool insertMapped(value_type const& v);
    bool insertMapped(value_type&& v);

    ///Not thread safe
    void clear();

    struct key_hash {
      std::size_t operator()(key_type const& iKey) const { return iKey.smallHash(); }
    };

  private:
    oneapi::tbb::concurrent_unordered_map<key_type, value_type, key_hash> m_map;
  };

}  // namespace edm

#endif