IFaninNode.h
Go to the documentation of this file.
1 #ifndef WIRECELL_IFANINNODE
2 #define WIRECELL_IFANINNODE
3 
4 #include "WireCellIface/INode.h"
5 
6 #include <boost/any.hpp>
7 #include <vector>
8 
9 namespace WireCell {
10 
11  /** A node which fans-in N data objects of the same, given
12  * InputType to produce the given OutputType.
13  */
14 
15  class IFaninNodeBase : public INode
16  {
17  public:
18  typedef std::shared_ptr<IFaninNodeBase> pointer;
19 
20  virtual ~IFaninNodeBase() ;
21 
22  typedef std::vector<boost::any> any_vector;
23 
24  /// The calling signature:
25  virtual bool operator()(const any_vector& anyin, boost::any& anyout) = 0;
26 
27  virtual NodeCategory category() {
28  return faninNode;
29  }
30 
31  /// Fanin nodes can usually do their thing stateless.
32  virtual int concurrency() { return 0; }
33 
34 
35  };
36 
37  // This converts between any and typed.
38  template <typename InputType, typename OutputType, int FaninMultiplicity=3>
39  class IFaninNode : public IFaninNodeBase {
40  public:
41 
42  typedef InputType input_type;
43  typedef OutputType output_type;
44  typedef std::shared_ptr<const InputType> input_pointer;
45  typedef std::shared_ptr<const OutputType> output_pointer;
46  typedef std::vector<input_pointer> input_vector;
47 
48  virtual ~IFaninNode() {}
49 
50  virtual bool operator()(const any_vector& anyv, boost::any& anyout) {
51  input_vector invec;
52  for (auto a : anyv) {
53  auto in = boost::any_cast<input_pointer>(a);
54  invec.push_back(in);
55  }
56  output_pointer out;
57  bool ok = (*this)(invec, out);
58  if (ok) {
59  anyout = out;
60  }
61  return ok;
62  }
63 
64  // The typed interface
65  virtual bool operator()(const input_vector& invec, output_pointer& out) = 0;
66 
67  // Return the names of the types this node takes as input.
68  // Note: if subclass wants to supply FaninMultiplicity at
69  // construction time, this needs to be overridden.
70  virtual std::vector<std::string> input_types() {
71  std::vector<std::string> ret(FaninMultiplicity, std::string(typeid(input_type).name()));
72  return ret;
73  }
74  // Return the names of the types this node produces as output.
75  virtual std::vector<std::string> output_types() {
76  return std::vector<std::string>{typeid(output_type).name()};
77  }
78 
79  };
80 
81 }
82 
83 #endif
static QCString name
Definition: declinfo.cpp:673
virtual bool operator()(const any_vector &anyin, boost::any &anyout)=0
The calling signature:
virtual NodeCategory category()
Return the behavior category type.
Definition: IFaninNode.h:27
std::vector< input_pointer > input_vector
Definition: IFaninNode.h:46
OutputType output_type
Definition: IFaninNode.h:43
std::string string
Definition: nybbler.cc:12
InputType input_type
Definition: IFaninNode.h:42
virtual bool operator()(const any_vector &anyv, boost::any &anyout)
The calling signature:
Definition: IFaninNode.h:50
virtual std::vector< std::string > input_types()
Definition: IFaninNode.h:70
virtual int concurrency()
Fanin nodes can usually do their thing stateless.
Definition: IFaninNode.h:32
virtual std::vector< std::string > output_types()
Definition: IFaninNode.h:75
virtual ~IFaninNode()
Definition: IFaninNode.h:48
std::shared_ptr< const InputType > input_pointer
Definition: IFaninNode.h:44
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
std::vector< boost::any > any_vector
Definition: IFaninNode.h:22
Definition: Main.h:22
std::shared_ptr< const OutputType > output_pointer
Definition: IFaninNode.h:45
std::shared_ptr< IFaninNodeBase > pointer
Definition: IFaninNode.h:18