LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SharedModule.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_detail_SharedModule_h
2 #define art_Framework_Core_detail_SharedModule_h
3 // vim: set sw=2 expandtab :
4 
7 #include "hep_concurrency/SerialTaskQueueChain.h"
8 
9 #include <memory>
10 #include <set>
11 #include <string>
12 #include <type_traits>
13 
14 namespace art::detail {
15  class SharedResources;
16 
17  class SharedModule {
18  public:
19  SharedModule();
20  ~SharedModule();
21 
22  explicit SharedModule(std::string const& moduleLabel);
23 
24  hep::concurrency::SerialTaskQueueChain* serialTaskQueueChain() const;
25  std::set<std::string> const& sharedResources() const;
26 
27  void createQueues(SharedResources const& resources);
28 
29  protected:
30  template <BranchType BT = InEvent, typename... T>
31  void serialize(T const&...);
32 
33  template <BranchType BT = InEvent, typename... T>
34  void serializeExternal(T const&...);
35 
36  template <BranchType BT = InEvent>
37  void
39  {
40  static_assert(
41  BT == InEvent,
42  "async is currently supported only for the 'InEvent' level.");
43  asyncDeclared_ = true;
44  }
45 
46  private:
47  void implicit_serialize();
48  void serialize_for(std::string const& name);
49 
50  template <typename... T>
51  void
52  serialize_for_resource(T const&... t)
53  {
54  static_assert(
55  std::conjunction_v<std::is_same<detail::SharedResource_t, T>...>);
56  if (sizeof...(t) == 0) {
58  } else {
59  (serialize_for(t.name), ...);
60  }
61  }
62 
63  template <typename... T>
64  void
66  {
67  static_assert(std::conjunction_v<std::is_same<std::string, T>...>);
68  if (sizeof...(t) == 0) {
70  } else {
71  (serialize_for(t), ...);
72  }
73  }
74 
75  std::string moduleLabel_{};
76  std::set<std::string> resourceNames_{};
77  bool asyncDeclared_{false};
78  std::unique_ptr<hep::concurrency::SerialTaskQueueChain> chain_{nullptr};
79  };
80 
81  template <BranchType, typename... T>
82  void
83  SharedModule::serialize(T const&... resources)
84  {
85  serialize_for_resource(resources...);
86  }
87 
88  template <BranchType, typename... T>
89  void
90  SharedModule::serializeExternal(T const&... resources)
91  {
92  serialize_for_external_resource(resources...);
93  }
94 }
95 
96 // Local Variables:
97 // mode: c++
98 // End:
99 
100 #endif /* art_Framework_Core_detail_SharedModule_h */
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
void serializeExternal(T const &...)
std::unique_ptr< hep::concurrency::SerialTaskQueueChain > chain_
Definition: SharedModule.h:78
void serialize_for_resource(T const &...t)
Definition: SharedModule.h:52
void createQueues(SharedResources const &resources)
Definition: SharedModule.cc:34
BranchType
Definition: BranchType.h:20
void serialize(T const &...)
void serialize_for_external_resource(T const &...t)
Definition: SharedModule.h:65
hep::concurrency::SerialTaskQueueChain * serialTaskQueueChain() const
Definition: SharedModule.cc:22