Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
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 30 of file SharedResource.h.

Member Typedef Documentation

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

Definition at line 38 of file SharedResource.h.

Constructor & Destructor Documentation

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

Definition at line 35 of file SharedResource.cc.

36  {
37  // Propulate queues for known shared resources. Creating these
38  // slots does *not* automatically introduce synchronization.
39  // Synchronization is enabled based on the resource-names argument
40  // presented to the 'createQueues' member function.
42  }
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 104 of file SharedResource.cc.

106  {
107  std::vector<queue_ptr_t> result;
108  if (cet::search_all(resourceNames, LegacyResource.name)) {
109  // We do not trust legacy modules as they may be accessing one
110  // of the shared resources without our knowledge. We therefore
111  // isolate them from all other shared modules (and each other).
112  for (auto const& pr : sortedResources_) {
113  result.push_back(pr.second);
114  }
115  } else {
116  // Not for a legacy module, get the queues for the named
117  // resources.
118  for (auto const& name : resourceNames) {
119  auto it =
120  std::find_if(begin(sortedResources_),
121  end(sortedResources_),
122  [&name](auto const& pr) { return pr.first == name; });
123  assert(it != sortedResources_.end());
124  result.push_back(it->second);
125  }
126  }
127 
128  assert(not empty(result));
129  return result;
130  }
static QCString name
Definition: declinfo.cpp:673
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
static QCString result
std::vector< std::pair< std::string, queue_ptr_t > > sortedResources_
SharedResource_t const LegacyResource
bool search_all(FwdCont const &, Datum const &)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
void art::detail::SharedResources::ensure_not_frozen ( std::string const &  name)
private

Definition at line 45 of file SharedResource.cc.

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

Definition at line 78 of file SharedResource.cc.

79  {
80  frozen_ = true;
81 
82  std::vector<std::pair<unsigned, std::string>> resources_sorted_by_count;
83  for (auto const& [name, count] : resourceCounts_) {
84  // Make sure all non-legacy resources have a higher count, which
85  // makes legacy always the first queue.
86  auto const offset = (name == LegacyResource.name) ? 0u : nLegacy_;
87  resources_sorted_by_count.emplace_back(count + offset, name);
88  }
89  cet::sort_all(resources_sorted_by_count, [](auto const& a, auto const& b) {
90  return a.first < b.first;
91  });
92 
93  assert(empty(sortedResources_));
94  for (auto const& pr : resources_sorted_by_count) {
95  sortedResources_.emplace_back(pr.second,
96  std::make_shared<SerialTaskQueue>(group));
97  }
98 
99  // Not needed any more now that we have a sorted list of resources.
100  resourceCounts_.clear();
101  }
static QCString name
Definition: declinfo.cpp:673
std::map< std::string, unsigned > resourceCounts_
std::vector< std::pair< std::string, queue_ptr_t > > sortedResources_
void sort_all(RandCont &)
SharedResource_t const LegacyResource
const double a
static bool * b
Definition: config.cpp:1043
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
void art::detail::SharedResources::register_resource ( std::string const &  name)
private

Definition at line 68 of file SharedResource.cc.

69  {
72  if (name == LegacyResource.name) {
73  ++nLegacy_;
74  }
75  }
static QCString name
Definition: declinfo.cpp:673
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 62 of file SharedResource.cc.

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

Definition at line 56 of file SharedResource.cc.

57  {
58  cet::for_all(names, [this](auto const& name) { register_resource(name); });
59  }
static QCString name
Definition: declinfo.cpp:673
void register_resource(std::string const &name)
auto for_all(FwdCont &, Func)

Member Data Documentation

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

Definition at line 48 of file SharedResource.h.

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

Definition at line 49 of file SharedResource.h.

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

Definition at line 46 of file SharedResource.h.

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

Definition at line 47 of file SharedResource.h.


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