Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:18:54

0001 #ifndef FWCore_ParameterSet_Registry_h
0002 #define FWCore_ParameterSet_Registry_h
0003 
0004 // ----------------------------------------------------------------------
0005 // Declaration for pset::Registry. This is an implementation detail of
0006 // the ParameterSet library.
0007 //
0008 // A Registry is used to keep track of the persistent form of all
0009 // ParameterSets used a given program, so that they may be retrieved by
0010 // ParameterSetID, and so they may be written to persistent storage.
0011 // Note that this registry is *not* directly persistable. The contents
0012 // are persisted, but not the container.
0013 // ----------------------------------------------------------------------
0014 
0015 #include <iosfwd>
0016 #include <map>
0017 #include "oneapi/tbb/concurrent_unordered_map.h"
0018 
0019 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0020 #include "DataFormats/Provenance/interface/ParameterSetBlob.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 
0023 namespace edm {
0024   namespace pset {
0025 
0026     class Registry {
0027     public:
0028       typedef edm::ParameterSetID key_type;
0029       typedef edm::ParameterSet value_type;
0030 
0031       static Registry* instance();
0032 
0033       /// Retrieve the value_type object with the given key.
0034       /// If we return 'true', then 'result' carries the
0035       /// value_type object.
0036       /// If we return 'false, no matching key was found, and
0037       /// the value of 'result' is undefined.
0038       bool getMapped(key_type const& k, value_type& result) const;
0039 
0040       /** Retrieve a pointer to the value_type object with the given key.
0041        If there is no object associated with the given key 0 is returned.
0042        */
0043       value_type const* getMapped(key_type const& k) const;
0044 
0045       /// Insert the given value_type object into the
0046       /// registry. If there was already a value_type object
0047       /// with the same key, we don't change it. This should be OK,
0048       /// since it should have the same contents if the key is the
0049       /// same.  Return 'true' if we really added the new
0050       /// value_type object, and 'false' if the
0051       /// value_type object was already present.
0052       bool insertMapped(value_type const& v, bool forceUpdate = false);
0053 
0054       ///Not thread safe
0055       void clear();
0056 
0057       struct key_hash {
0058         std::size_t operator()(key_type const& iKey) const { return iKey.smallHash(); }
0059       };
0060       typedef oneapi::tbb::concurrent_unordered_map<key_type, value_type, key_hash> map_type;
0061       typedef map_type::const_iterator const_iterator;
0062 
0063       const_iterator begin() const { return m_map.begin(); }
0064 
0065       const_iterator end() const { return m_map.end(); }
0066 
0067       bool empty() const { return m_map.empty(); }
0068 
0069       size_t size() const { return m_map.size(); }
0070 
0071       /// Fill the given map with the persistent form of each
0072       /// ParameterSet in the registry.
0073       typedef std::map<ParameterSetID, ParameterSetBlob> regmap_type;
0074       void fillMap(regmap_type& fillme) const;
0075 
0076       void print(std::ostream& os) const;
0077 
0078     private:
0079       map_type m_map;
0080     };
0081 
0082   }  // namespace pset
0083 }  // namespace edm
0084 
0085 #endif