LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SharedModule.cc
Go to the documentation of this file.
2 // vim: set sw=2 expandtab :
3 
6 
7 #include <string>
8 #include <vector>
9 
10 using namespace hep::concurrency;
11 
12 namespace art::detail {
13 
14  SharedModule::SharedModule() = default;
15  SharedModule::~SharedModule() = default;
16 
17  SharedModule::SharedModule(std::string const& moduleLabel)
18  : moduleLabel_{moduleLabel}
19  {}
20 
21  SerialTaskQueueChain*
23  {
24  return chain_.get();
25  }
26 
27  std::set<std::string> const&
29  {
30  return resourceNames_;
31  }
32 
33  void
35  {
37  "An error occurred while processing scheduling options for a "
38  "module.\n"};
39  if (asyncDeclared_) {
40  if (empty(resourceNames_)) {
41  return;
42  }
43  throw e
44  << "async<art::InEvent>() cannot be called in combination with any "
45  "serialize<art::InEvent>(...) calls.\n";
46  }
47 
48  if (empty(resourceNames_)) {
49  throw e << "Either 'async<art::InEvent>()' or "
50  "'serialize<art::InEvent>(...)'\n"
51  "must be called in a shared module's constructor.\n";
52  }
53  std::vector<std::string> const names(cbegin(resourceNames_),
55  auto queues = resources.createQueues(names);
56  chain_ = std::make_unique<SerialTaskQueueChain>(queues);
57  }
58 
59  void
61  {
62  // This is the situation where a shared module must be serialized,
63  // but only wrt. itself--i.e. only one event call at a time.
64  // Because the shared-resources registry is not prepopulated with
65  // module names, we call the 'serialize_for_external' function to
66  // insert an entry into the registry. This is safe to do as only
67  // this module will refer to the shared resource.
69  }
70 
71  void
72  SharedModule::serialize_for(std::string const& resourceName)
73  {
74  resourceNames_.emplace(resourceName);
75  }
76 }
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:93
std::set< std::string > resourceNames_
Definition: SharedModule.h:76
void serialize_for(std::string const &name)
Definition: SharedModule.cc:72
std::set< std::string > const & sharedResources() const
Definition: SharedModule.cc:28
std::unique_ptr< hep::concurrency::SerialTaskQueueChain > chain_
Definition: SharedModule.h:78
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void createQueues(SharedResources const &resources)
Definition: SharedModule.cc:34
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
Definition: StdUtils.h:85
Float_t e
Definition: plot.C:35
hep::concurrency::SerialTaskQueueChain * serialTaskQueueChain() const
Definition: SharedModule.cc:22
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.
Definition: StdUtils.h:109