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  explicit SharedModule(std::string const& moduleLabel);
21 
22  hep::concurrency::SerialTaskQueueChain* serialTaskQueueChain() const;
23  std::set<std::string> const& sharedResources() const;
24 
25  void createQueues(SharedResources const& resources);
26 
27  protected:
28  template <BranchType BT = InEvent, typename... T>
29  void serialize(T const&...);
30 
31  template <BranchType BT = InEvent, typename... T>
32  void serializeExternal(T const&...);
33 
34  template <BranchType BT = InEvent>
35  void
37  {
38  static_assert(
39  BT == InEvent,
40  "async is currently supported only for the 'InEvent' level.");
41  asyncDeclared_ = true;
42  }
43 
44  private:
45  void implicit_serialize();
46  void serialize_for(std::string const& name);
47 
48  template <typename... T>
49  void
51  {
52  static_assert(
53  std::conjunction_v<std::is_same<detail::SharedResource_t, T>...>);
54  if (sizeof...(t) == 0) {
56  } else {
57  (serialize_for(t.name), ...);
58  }
59  }
60 
61  template <typename... T>
62  void
64  {
65  static_assert(std::conjunction_v<std::is_same<std::string, T>...>);
66  if (sizeof...(t) == 0) {
68  } else {
69  (serialize_for(t), ...);
70  }
71  }
72 
74  std::set<std::string> resourceNames_{};
75  bool asyncDeclared_{false};
76  std::unique_ptr<hep::concurrency::SerialTaskQueueChain> chain_{nullptr};
77  };
78 
79  template <BranchType, typename... T>
80  void
81  SharedModule::serialize(T const&... resources)
82  {
83  serialize_for_resource(resources...);
84  }
85 
86  template <BranchType, typename... T>
87  void
88  SharedModule::serializeExternal(T const&... resources)
89  {
90  serialize_for_external_resource(resources...);
91  }
92 }
93 
94 // Local Variables:
95 // mode: c++
96 // End:
97 
98 #endif /* art_Framework_Core_detail_SharedModule_h */
static QCString name
Definition: declinfo.cpp:673
std::set< std::string > resourceNames_
Definition: SharedModule.h:74
std::string string
Definition: nybbler.cc:12
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:76
void serialize_for_resource(T const &...t)
Definition: SharedModule.h:50
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:63
hep::concurrency::SerialTaskQueueChain * serialTaskQueueChain() const
Definition: SharedModule.cc:22