IHydraNode.h
Go to the documentation of this file.
1 /** A hydra has N input queues and M output queues each of a specified
2  * type. Not all queues may have elements. The implementation
3  * callable may leave elements in input queues for subsequent calls
4  * when new data exists.
5  */
6 
7 #ifndef WIRECELL_IHYDRANODE
8 #define WIRECELL_IHYDRANODE
9 
10 #include "WireCellIface/INode.h"
12 
13 #include <boost/any.hpp>
14 #include <vector>
15 #include <deque>
16 
17 namespace WireCell {
18 
19 
20  /** Base hydra node class.
21  *
22  */
23  class IHydraNodeBase : public INode
24  {
25  public:
26  typedef std::shared_ptr<IHydraNodeBase> pointer;
27 
28  virtual ~IHydraNodeBase() ;
29 
30  typedef std::deque<boost::any> any_queue;
31  typedef std::vector< any_queue > any_queue_vector;
32 
33  /// The calling signature:
34  virtual bool operator()(any_queue_vector& anyinq,
35  any_queue_vector& anyoutq) = 0;
36 
37  virtual NodeCategory category() {
38  return hydraNode;
39  }
40 
41  /// By default assume hydra nodes can do their thing stateless.
42  virtual int concurrency() { return 0; }
43 
44 
45  };
46 
47  /** A hydra with input and output fixed at compile-time with tuples.
48  */
49  template <typename InputTuple, typename OutputTuple>
50  class IHydraNode : public IHydraNodeBase {
51  public:
52 
53  typedef InputTuple input_tuple_type;
54  typedef OutputTuple output_tuple_type;
55 
58 
59  typedef typename input_shqed::shared_queued_tuple_type input_queues_type;
60  typedef typename output_shqed::shared_queued_tuple_type output_queues_type;
61 
62  virtual ~IHydraNode() {}
63 
64  /// Translate call from any to types and back.
65  virtual bool operator()(any_queue_vector& anyinq,
66  any_queue_vector& anyoutq) {
67  input_shqed ih;
68  output_shqed oh;
69 
70  auto inq = ih.from_any_queue(anyinq);
71  output_queues_type outq;
72 
73  bool ok = (*this)(inq, outq);
74  if (ok) {
75  anyoutq = oh.as_any_queue(outq);
76  }
77 
78  // (re)set input queue
79  anyinq = ih.as_any_queue(inq);
80  return ok;
81  }
82 
83  /// Typed interface for subclass to implement.
84  virtual bool operator()(input_queues_type& inqs,
85  output_queues_type& outqs) = 0;
86 
87  // Return the names of the types this node takes as input.
88  virtual std::vector<std::string> input_types() {
90  return ih.type_names();
91  }
92  // Return the names of the types this node produces as output.
93  virtual std::vector<std::string> output_types() {
95  return oh.type_names();
96  }
97 
98  };
99 
100 }
101 
102 #endif
std::shared_ptr< IHydraNodeBase > pointer
Definition: IHydraNode.h:26
virtual std::vector< std::string > input_types()
Definition: IHydraNode.h:88
OutputTuple output_tuple_type
Definition: IHydraNode.h:54
virtual int concurrency()
By default assume hydra nodes can do their thing stateless.
Definition: IHydraNode.h:42
virtual bool operator()(any_queue_vector &anyinq, any_queue_vector &anyoutq)
Translate call from any to types and back.
Definition: IHydraNode.h:65
virtual ~IHydraNode()
Definition: IHydraNode.h:62
input_shqed::shared_queued_tuple_type input_queues_type
Definition: IHydraNode.h:59
virtual bool operator()(any_queue_vector &anyinq, any_queue_vector &anyoutq)=0
The calling signature:
shared_queued< InputTuple > input_shqed
Definition: IHydraNode.h:56
std::vector< any_queue > any_queue_vector
Definition: IHydraNode.h:31
Definition: Main.h:22
output_shqed::shared_queued_tuple_type output_queues_type
Definition: IHydraNode.h:60
std::deque< boost::any > any_queue
Definition: IHydraNode.h:30
virtual std::vector< std::string > output_types()
Definition: IHydraNode.h:93
virtual NodeCategory category()
Return the behavior category type.
Definition: IHydraNode.h:37
shared_queued< OutputTuple > output_shqed
Definition: IHydraNode.h:57
InputTuple input_tuple_type
Definition: IHydraNode.h:53