LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::detail::SharedResources Class Reference

#include "SharedResource.h"

Public Types

using queue_ptr_t = std::shared_ptr< hep::concurrency::SerialTaskQueue >
 

Public Member Functions

 SharedResources ()
 
void registerSharedResources (std::set< std::string > const &names)
 
void registerSharedResource (detail::SharedResource_t const &)
 
void freeze (tbb::task_group &group)
 
std::vector< queue_ptr_tcreateQueues (std::vector< std::string > const &resourceNames) const
 

Private Member Functions

void register_resource (std::string const &name)
 
void ensure_not_frozen (std::string const &name)
 

Private Attributes

std::map< std::string, unsigned > resourceCounts_
 
std::vector< std::pair< std::string, queue_ptr_t > > sortedResources_
 
bool frozen_ {false}
 
unsigned nLegacy_ {}
 

Detailed Description

Definition at line 31 of file SharedResource.h.

Member Typedef Documentation

using art::detail::SharedResources::queue_ptr_t = std::shared_ptr<hep::concurrency::SerialTaskQueue>

Definition at line 39 of file SharedResource.h.

Constructor & Destructor Documentation

art::detail::SharedResources::SharedResources ( )

Definition at line 37 of file SharedResource.cc.

References art::detail::LegacyResource.

38  {
39  // Propulate queues for known shared resources. Creating these
40  // slots does *not* automatically introduce synchronization.
41  // Synchronization is enabled based on the resource-names argument
42  // presented to the 'createQueues' member function.
44  }
SharedResource_t const LegacyResource
void registerSharedResource(detail::SharedResource_t const &)

Member Function Documentation

std::vector< std::shared_ptr< SerialTaskQueue > > art::detail::SharedResources::createQueues ( std::vector< std::string > const &  resourceNames) const

Definition at line 108 of file SharedResource.cc.

References util::begin(), util::empty(), util::end(), art::detail::LegacyResource, art::detail::SharedResource_t::name, and util::values().

Referenced by art::detail::SharedModule::createQueues().

110  {
111  using namespace ::ranges;
112  if (cet::search_all(resourceNames, LegacyResource.name)) {
113  // We do not trust legacy modules as they may be accessing one
114  // of the shared resources without our knowledge. We therefore
115  // isolate them from all other shared modules (and each other).
116  return sortedResources_ | views::values | to<std::vector>();
117  }
118  std::vector<std::shared_ptr<SerialTaskQueue>> result;
119  // Not for a legacy module, get the queues for the named resources.
120  for (auto const& name : resourceNames) {
121  auto it =
122  std::find_if(begin(sortedResources_),
124  [&name](auto const& pr) { return pr.first == name; });
125  assert(it != sortedResources_.end());
126  result.push_back(it->second);
127  }
128 
129  assert(not empty(result));
130  return result;
131  }
std::vector< std::pair< std::string, queue_ptr_t > > sortedResources_
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
SharedResource_t const LegacyResource
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
void art::detail::SharedResources::ensure_not_frozen ( std::string const &  name)
private

Definition at line 47 of file SharedResource.cc.

References art::errors::LogicError.

48  {
49  if (frozen_) {
50  throw Exception{errors::LogicError, error_context(name)}
51  << "The shared-resources registry has been frozen. All 'serialize' "
52  "calls\n"
53  << "must be made in the constructor of a shared module and no later.\n";
54  }
55  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void art::detail::SharedResources::freeze ( tbb::task_group &  group)

Definition at line 80 of file SharedResource.cc.

References art::detail::LegacyResource, art::detail::SharedResource_t::name, and util::values().

Referenced by art::EventProcessor::EventProcessor().

81  {
82  frozen_ = true;
83 
84  std::vector<std::pair<unsigned, std::string>> resources_sorted_by_count;
85  for (auto const& [name, count] : resourceCounts_) {
86  // Make sure all non-legacy resources have a higher count, which
87  // makes legacy always the first queue.
88  auto const offset = (name == LegacyResource.name) ? 0u : nLegacy_;
89  resources_sorted_by_count.emplace_back(count + offset, name);
90  }
91  cet::sort_all(resources_sorted_by_count, [](auto const& a, auto const& b) {
92  return a.first < b.first;
93  });
94 
95  using namespace ::ranges;
97  resources_sorted_by_count | views::values |
98  views::transform([&group](auto const& key) {
99  return std::pair{key, std::make_shared<SerialTaskQueue>(group)};
100  }) |
101  to<std::vector>();
102 
103  // Not needed any more now that we have a sorted list of resources.
104  resourceCounts_.clear();
105  }
std::map< std::string, unsigned > resourceCounts_
std::vector< std::pair< std::string, queue_ptr_t > > sortedResources_
SharedResource_t const LegacyResource
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
void art::detail::SharedResources::register_resource ( std::string const &  name)
private

Definition at line 70 of file SharedResource.cc.

References art::detail::LegacyResource, and art::detail::SharedResource_t::name.

71  {
72  ensure_not_frozen(name);
73  ++resourceCounts_[name];
74  if (name == LegacyResource.name) {
75  ++nLegacy_;
76  }
77  }
std::map< std::string, unsigned > resourceCounts_
void ensure_not_frozen(std::string const &name)
SharedResource_t const LegacyResource
void art::detail::SharedResources::registerSharedResource ( detail::SharedResource_t const &  resource)

Definition at line 64 of file SharedResource.cc.

References art::detail::SharedResource_t::name.

65  {
66  register_resource(resource.name);
67  }
void register_resource(std::string const &name)
void art::detail::SharedResources::registerSharedResources ( std::set< std::string > const &  names)

Definition at line 58 of file SharedResource.cc.

References art::detail::SharedResource_t::name.

59  {
60  cet::for_all(names, [this](auto const& name) { register_resource(name); });
61  }
void register_resource(std::string const &name)

Member Data Documentation

bool art::detail::SharedResources::frozen_ {false}
private

Definition at line 49 of file SharedResource.h.

unsigned art::detail::SharedResources::nLegacy_ {}
private

Definition at line 50 of file SharedResource.h.

std::map<std::string, unsigned> art::detail::SharedResources::resourceCounts_
private

Definition at line 47 of file SharedResource.h.

std::vector<std::pair<std::string, queue_ptr_t> > art::detail::SharedResources::sortedResources_
private

Definition at line 48 of file SharedResource.h.


The documentation for this class was generated from the following files: