3 #include "cetlib/container_algorithms.h" 4 #include "cetlib_except/demangle.h" 5 #include "hep_concurrency/SerialTaskQueue.h" 6 #include "range/v3/view.hpp" 20 error_context(std::string
const& name)
22 return "An error occurred while attempting to register the shared resource '"s +
28 SharedResource_t::SharedResource_t(std::string
const& resource_name,
30 : name{demangle ? cet::demangle_symbol(resource_name) : resource_name}
51 <<
"The shared-resources registry has been frozen. All 'serialize' " 53 <<
"must be made in the constructor of a shared module and no later.\n";
60 cet::for_all(names, [
this](
auto const&
name) { register_resource(
name); });
66 register_resource(resource.
name);
72 ensure_not_frozen(name);
73 ++resourceCounts_[
name];
84 std::vector<std::pair<unsigned, std::string>> resources_sorted_by_count;
85 for (
auto const& [
name, count] : resourceCounts_) {
89 resources_sorted_by_count.emplace_back(count + offset,
name);
91 cet::sort_all(resources_sorted_by_count, [](
auto const& a,
auto const& b) {
92 return a.first < b.first;
98 views::transform([&group](
auto const& key) {
99 return std::pair{key, std::make_shared<SerialTaskQueue>(group)};
104 resourceCounts_.clear();
107 std::vector<std::shared_ptr<SerialTaskQueue>>
109 std::vector<std::string>
const& resourceNames)
const 118 std::vector<std::shared_ptr<SerialTaskQueue>> result;
120 for (
auto const&
name : resourceNames) {
122 std::find_if(
begin(sortedResources_),
123 end(sortedResources_),
124 [&
name](
auto const& pr) {
return pr.first ==
name; });
125 assert(it != sortedResources_.end());
126 result.push_back(it->second);
129 assert(not
empty(result));
std::string demangle(T const *=nullptr)
Outputs a demangled name for type T.
void ensure_not_frozen(std::string const &name)
void register_resource(std::string const &name)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
void freeze(tbb::task_group &group)
SharedResource_t const LegacyResource
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
void registerSharedResources(std::set< std::string > const &names)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
std::vector< queue_ptr_t > createQueues(std::vector< std::string > const &resourceNames) const
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
void registerSharedResource(detail::SharedResource_t const &)