1 #ifndef fhiclcpp_ParameterSetRegistry_h 2 #define fhiclcpp_ParameterSetRegistry_h 16 #include <unordered_map> 23 class ParameterSetRegistry;
26 class HashParameterSetID;
50 unordered_map<ParameterSetID, ParameterSet, detail::HashParameterSetID>;
58 static void importFrom(sqlite3* db);
59 static void exportTo(sqlite3* db);
60 static void stageIn();
70 template <
class FwdIt>
71 static std::enable_if_t<
72 std::is_same_v<typename std::iterator_traits<FwdIt>::value_type,
77 template <
class FwdIt>
78 static std::enable_if_t<
79 std::is_same_v<typename std::iterator_traits<FwdIt>::value_type,
98 sqlite3_stmt* stmt_{
nullptr};
106 std::lock_guard sentry{mutex_};
107 return instance_().registry_.empty();
113 std::lock_guard sentry{mutex_};
114 return instance_().registry_.size();
122 std::lock_guard sentry{mutex_};
123 return instance_().registry_.emplace(ps.id(), ps).first->first;
127 template <
class FwdIt>
130 std::is_same_v<typename std::iterator_traits<FwdIt>::value_type,
mapped_type>>
133 for (; b !=
e; ++b) {
139 template <
class FwdIt>
143 std::is_same_v<typename std::iterator_traits<FwdIt>::value_type,
146 std::lock_guard sentry{mutex_};
147 instance_().registry_.insert(b,
e);
155 put(c.cbegin(), c.cend());
161 std::lock_guard sentry{mutex_};
162 return instance_().registry_;
169 std::lock_guard sentry{mutex_};
170 auto it = instance_().find_(
id);
171 if (it == instance_().registry_.cend()) {
173 <<
"with ID " <<
id.to_string() <<
" in the registry.";
181 std::lock_guard sentry{mutex_};
183 auto it = instance_().find_(
id);
184 if (it != instance_().registry_.cend()) {
194 std::lock_guard sentry{mutex_};
195 auto const& reg = instance_().registry_;
196 return reg.find(
id) != reg.cend();
static ParameterSetID const & put(ParameterSet const &ps)
static collection_type const & get() noexcept
std::hash< std::string > hash_
std::string to_string(Protection p)
collection_type::const_iterator const_iterator
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
collection_type::value_type value_type
size_t operator()(ParameterSetID const &id) const
collection_type::key_type key_type
static bool has(ParameterSetID const &id)
static std::recursive_mutex mutex_
void throwOnSQLiteFailure(int rc, char *msg=nullptr)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
collection_type::size_type size_type
cet::coded_exception< error, detail::translate > exception
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
collection_type::mapped_type mapped_type
static ParameterSetRegistry & instance_()
std::unordered_map< ParameterSetID, ParameterSet, detail::HashParameterSetID > collection_type