MultiDuctor.h
Go to the documentation of this file.
1 /** MultiDuctor - apply one of many possible ductors based on outcome of rules applied to input depos.
2 
3  A list of independent "chains" are given. Each chain is applied
4  to an input depo. A chain is a sequence of rules. Each rule is
5  applied in turn to a depo until one matches. On a match, the
6  ductor associated with the rule is given the depo and subsequent
7  iteration of the chain is abandoned.
8  */
9 
10 #ifndef WIRECELLGEN_MULTIDUCTOR
11 #define WIRECELLGEN_MULTIDUCTOR
12 
13 #include "WireCellIface/IDuctor.h"
16 
17 #include <functional>
18 
19 namespace WireCell {
20  namespace Gen {
21 
22  class MultiDuctor : public IDuctor, public IConfigurable {
23 
24  public:
25 
26  MultiDuctor(const std::string anode = "AnodePlane");
27  virtual ~MultiDuctor();
28 
29  //virtual void reset();
30  // IDuctor
31  virtual bool operator()(const input_pointer& depo, output_queue& frames);
32 
33  // IConfigurable
34  virtual void configure(const WireCell::Configuration& config);
36 
37 
38  private:
39 
42  double m_tick;
43  double m_start_time;
47  bool m_eos;
48 
49  struct SubDuctor {
51  std::function<bool(IDepo::pointer depo)> check;
54  std::function<bool(IDepo::pointer depo)> f,
55  IDuctor::pointer d) : name(tn), check(f), ductor(d) {}
56  };
57  typedef std::vector<SubDuctor> ductorchain_t;
58  std::vector<ductorchain_t> m_chains;
59 
60  /// As sub ductors are called they will each return frames
61  /// which are not in general synchronized with the others.
62  /// Their frames must be buffered here and released as a
63  /// merged frame in order for MultiDuctor to behave just
64  /// like a monolithic ductor.
66 
67  // local
68 
69  // Accept new frames into the buffer
70  void merge(const output_queue& newframes);
71 
72  // Maybe extract output frames from the buffer. If the
73  // depo is past the next scheduled readout or if a nullptr
74  // depo (EOS) then sub-ductors are flushed with EOS and
75  // the outframes queue is filled with one or more frames.
76  // If extraction occurs not by EOS then any carryover is
77  // kept.
78  void maybe_extract(const input_pointer& depo, output_queue& outframes);
79 
80  // Return true if depo indicates it is time to start
81  // processing. Will set start time if in continuous mode.
82  bool start_processing(const input_pointer& depo);
83 
84  void dump_frame(const IFrame::pointer frame, std::string msg="Gen::MultiDuctor:");
85 
86  };
87  }
88 }
89 
90 #endif
std::shared_ptr< const IDepo > pointer
Definition: IData.h:19
void merge(const output_queue &newframes)
IAnodePlane::pointer m_anode
Definition: MultiDuctor.h:41
void msg(const char *fmt,...)
Definition: message.cpp:107
std::string string
Definition: nybbler.cc:12
virtual bool operator()(const input_pointer &depo, output_queue &frames)
The calling signature:
std::vector< SubDuctor > ductorchain_t
Definition: MultiDuctor.h:57
std::deque< output_pointer > output_queue
void dump_frame(const IFrame::pointer frame, std::string msg="Gen::MultiDuctor:")
MultiDuctor(const std::string anode="AnodePlane")
Definition: MultiDuctor.cxx:20
static Config * config
Definition: config.cpp:1054
std::shared_ptr< Interface > pointer
Definition: Interface.h:16
void maybe_extract(const input_pointer &depo, output_queue &outframes)
virtual void configure(const WireCell::Configuration &config)
Accept a configuration.
std::vector< ductorchain_t > m_chains
Definition: MultiDuctor.h:58
Definition: Main.h:22
output_queue m_frame_buffer
Definition: MultiDuctor.h:65
std::shared_ptr< IDuctor > pointer
Definition: IDuctor.h:25
Json::Value Configuration
Definition: Configuration.h:50
std::shared_ptr< const IDepo > input_pointer
bool start_processing(const input_pointer &depo)
virtual WireCell::Configuration default_configuration() const
Optional, override to return a hard-coded default configuration.
Definition: MultiDuctor.cxx:34
SubDuctor(const std::string &tn, std::function< bool(IDepo::pointer depo)> f, IDuctor::pointer d)
Definition: MultiDuctor.h:53
void function(int client, int *resource, int parblock, int *test, int p)
std::function< bool(IDepo::pointer depo)> check
Definition: MultiDuctor.h:51