LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
UpdateOutputCallbacks.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_UpdateOutputCallbacks_h
2 #define art_Framework_Core_UpdateOutputCallbacks_h
3 // vim: set sw=2 expandtab :
4 
5 // =====================================================================
6 // UpdateOutputCallbacks
7 //
8 // UpdateOutputCallbacks is a class that contains a list of callbacks
9 // that can be invoked to update output modules. For example, if an
10 // input file is opened and an output module needs to be updated
11 // accordingly, the output module (or EndPathExecutor) can register a
12 // callback with an object of this class. The input source's
13 // reference to that object can then invoke the callbacks whenever a
14 // new input file is opened.
15 //
16 // This class originated from the MasterProductRegistry which, in
17 // addition to owning descriptions of all products, also had a list of
18 // callbacks to invoke whenever that list of product descriptions was
19 // updated. All product descriptions are now owned by the input
20 // files/source, the event processor, and any output modules. The
21 // callback invocations are done through the UpdateOutputCallbacks
22 // class to provide the ability to synchronize product descriptions
23 // between the input/event processor and the output.
24 //
25 // While the only currently-supported callback signature is of type
26 // void(ProductTables const&), other callback signatures could be
27 // beneficial. When we get to that point, it would make sense to
28 // introduce a different model where users of this class would provide
29 // subclasses that inherent from a common base class (e.g.):
30 //
31 // outputCallbacks.registerCallback<FileBlockPacket>(...);
32 // outputCallbacks.registerCallback<ProductTablesPacket>(...);
33 //
34 // where both FileBlockPacket and ProductTablesPacket inherit from a
35 // base class of type (e.g.) IOPacket. The relevant callback would be
36 // invoked via something like:
37 //
38 // template <typename T, typename... Args>
39 // void invoke(Args&&... args) {
40 // auto& callback = dynamic_cast<T&>(entry_in_callback_list);
41 // callback.invoke(std::forward<Args>(args)...);
42 // }
43 //
44 // where 'entry_in_callback_list' refers to a pointer of type IOPacket
45 // corresponding to the desired callback to invoke.
46 // =====================================================================
47 
48 #include <functional>
49 #include <vector>
50 
51 namespace art {
52 
53  class ProductTables;
54  using ProductListUpdatedCallback = std::function<void(ProductTables const&)>;
55 
57  public:
58  explicit UpdateOutputCallbacks() = default;
60 
62 
63  void invoke(ProductTables const&);
64 
65  private:
66  std::vector<ProductListUpdatedCallback> callbacks_{};
67  };
68 
69 } // namespace art
70 
71 #endif /* art_Framework_Core_UpdateOutputCallbacks_h */
72 
73 // Local Variables:
74 // mode: c++
75 // End:
void registerCallback(ProductListUpdatedCallback cb)
std::function< void(ProductTables const &)> ProductListUpdatedCallback
std::vector< ProductListUpdatedCallback > callbacks_
void invoke(ProductTables const &)
Definition: MVAAlg.h:12