Public Member Functions | Private Attributes | List of all members
WireCell::Gen::Fourdee Class Reference

#include <Fourdee.h>

Inheritance diagram for WireCell::Gen::Fourdee:
WireCell::IApplication WireCell::IConfigurable WireCell::IComponent< IApplication > WireCell::IComponent< IConfigurable > WireCell::Interface WireCell::Interface

Public Member Functions

 Fourdee ()
 
virtual ~Fourdee ()
 
virtual void execute ()
 Implement to run something. More...
 
virtual void execute_old ()
 
virtual void execute_new ()
 
virtual void configure (const WireCell::Configuration &config)
 Accept a configuration. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
- Public Member Functions inherited from WireCell::IApplication
virtual ~IApplication ()
 
- Public Member Functions inherited from WireCell::IComponent< IApplication >
virtual ~IComponent ()
 
- Public Member Functions inherited from WireCell::Interface
virtual ~Interface ()
 
- Public Member Functions inherited from WireCell::IConfigurable
virtual ~IConfigurable ()
 
- Public Member Functions inherited from WireCell::IComponent< IConfigurable >
virtual ~IComponent ()
 

Private Attributes

WireCell::IDepoSource::pointer m_depos
 
WireCell::IDepoFilter::pointer m_depofilter
 
WireCell::IDrifter::pointer m_drifter
 
WireCell::IDuctor::pointer m_ductor
 
WireCell::IFrameSource::pointer m_dissonance
 
WireCell::IFrameFilter::pointer m_digitizer
 
WireCell::IFrameFilter::pointer m_filter
 
WireCell::IFrameSink::pointer m_output
 

Additional Inherited Members

- Public Types inherited from WireCell::IComponent< IApplication >
typedef std::shared_ptr< IApplicationpointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 
- Public Types inherited from WireCell::Interface
typedef std::shared_ptr< Interfacepointer
 
- Public Types inherited from WireCell::IComponent< IConfigurable >
typedef std::shared_ptr< IConfigurablepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 

Detailed Description

Fourdee is a Wire Cell Toolkit application class which handles a chain of "the 4 D's": deposition, drifting, "ducting" (induction response) and digitization. There is an optional "5th D": "dissonance" which provides a source of noise to be summed.

Each step provided by a model implemented as an instance of the associated component class. A final sink is also provided if the digitization output is provided.

Definition at line 34 of file Fourdee.h.

Constructor & Destructor Documentation

Gen::Fourdee::Fourdee ( )

Definition at line 16 of file Fourdee.cxx.

17  : m_depos(nullptr)
18  , m_drifter(nullptr)
19  , m_ductor(nullptr)
20  , m_dissonance(nullptr)
21  , m_digitizer(nullptr)
22  , m_output(nullptr)
23 {
24 }
WireCell::IDepoSource::pointer m_depos
Definition: Fourdee.h:49
WireCell::IDuctor::pointer m_ductor
Definition: Fourdee.h:52
WireCell::IFrameSource::pointer m_dissonance
Definition: Fourdee.h:53
WireCell::IFrameSink::pointer m_output
Definition: Fourdee.h:56
WireCell::IDrifter::pointer m_drifter
Definition: Fourdee.h:51
WireCell::IFrameFilter::pointer m_digitizer
Definition: Fourdee.h:54
Gen::Fourdee::~Fourdee ( )
virtual

Definition at line 26 of file Fourdee.cxx.

27 {
28 }

Member Function Documentation

void Gen::Fourdee::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 48 of file Fourdee.cxx.

49 {
50  std::string tn="";
51  Configuration cfg = thecfg;
52 
53  cerr << "Gen::Fourdee:configure:\n";
54 
55  tn = get<string>(cfg, "DepoSource");
56  cerr << "\tDepoSource: " << tn << endl;
57  m_depos = Factory::find_maybe_tn<IDepoSource>(tn);
58 
59  tn = get<string>(cfg, "DepoFilter");
60  if (tn.empty()) {
61  m_depofilter = nullptr;
62  cerr << "\tDepoFilter: none\n";
63  }
64  else {
65  cerr << "\tDepoFilter: " << tn << endl;
66  m_depofilter = Factory::find_maybe_tn<IDepoFilter>(tn);
67  }
68 
69  tn = get<string>(cfg, "Drifter");
70  cerr << "\tDrifter: " << tn << endl;
71  m_drifter = Factory::find_maybe_tn<IDrifter>(tn);
72 
73  tn = get<string>(cfg, "Ductor");
74  cerr << "\tDuctor: " << tn << endl;
75  m_ductor = Factory::find_maybe_tn<IDuctor>(tn);
76 
77 
78  tn = get<string>(cfg, "Dissonance","");
79  if (tn.empty()) { // noise is optional
80  m_dissonance = nullptr;
81  cerr << "\tDissonance: none\n";
82  }
83  else {
84  m_dissonance = Factory::find_maybe_tn<IFrameSource>(tn);
85  cerr << "\tDissonance: " << tn << endl;
86  }
87 
88  tn = get<string>(cfg, "Digitizer","");
89  if (tn.empty()) { // digitizer is optional, voltage saved w.o. it.
90  m_digitizer = nullptr;
91  cerr << "\tDigitizer: none\n";
92  }
93  else {
94  m_digitizer = Factory::find_maybe_tn<IFrameFilter>(tn);
95  cerr << "\tDigitizer: " << tn << endl;
96  }
97 
98  tn = get<string>(cfg, "Filter","");
99  if (tn.empty()) { // filter is optional
100  m_filter = nullptr;
101  cerr << "\tFilter: none\n";
102  }
103  else {
104  m_filter = Factory::find_maybe_tn<IFrameFilter>(tn);
105  cerr << "\tFilter: " << tn << endl;
106  }
107 
108  tn = get<string>(cfg, "FrameSink","");
109  if (tn.empty()) { // sink is optional
110  m_output = nullptr;
111  cerr << "\tSink: none\n";
112  }
113  else {
114  m_output = Factory::find_maybe_tn<IFrameSink>(tn);
115  cerr << "\tSink: " << tn << endl;
116  }
117 }
WireCell::IDepoSource::pointer m_depos
Definition: Fourdee.h:49
std::string string
Definition: nybbler.cc:12
cfg
Definition: dbjson.py:29
WireCell::IDepoFilter::pointer m_depofilter
Definition: Fourdee.h:50
WireCell::IDuctor::pointer m_ductor
Definition: Fourdee.h:52
WireCell::IFrameSource::pointer m_dissonance
Definition: Fourdee.h:53
WireCell::IFrameSink::pointer m_output
Definition: Fourdee.h:56
Json::Value Configuration
Definition: Configuration.h:50
WireCell::IDrifter::pointer m_drifter
Definition: Fourdee.h:51
WireCell::IFrameFilter::pointer m_filter
Definition: Fourdee.h:55
WireCell::IFrameFilter::pointer m_digitizer
Definition: Fourdee.h:54
QTextStream & endl(QTextStream &s)
WireCell::Configuration Gen::Fourdee::default_configuration ( ) const
virtual

Optional, override to return a hard-coded default configuration.

Reimplemented from WireCell::IConfigurable.

Definition at line 30 of file Fourdee.cxx.

31 {
33 
34  // the 4 d's and proof the developer can not count:
35  put(cfg, "DepoSource", "TrackDepos");
36  put(cfg, "DepoFilter", "");
37  put(cfg, "Drifter", "Drifter");
38  put(cfg, "Ductor", "Ductor");
39  put(cfg, "Dissonance", "SilentNoise");
40  put(cfg, "Digitizer", "Digitizer");
41  put(cfg, "Filter", "");
42  put(cfg, "FrameSink", "DumpFrames");
43 
44  return cfg;
45 }
void put(Configuration &cfg, const std::string &dotpath, const T &val)
Put value in configuration at the dotted path.
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
void Gen::Fourdee::execute ( )
virtual

Implement to run something.

Implements WireCell::IApplication.

Definition at line 254 of file Fourdee.cxx.

255 {
256  execute_new();
257  //execute_old();
258 }
virtual void execute_new()
Definition: Fourdee.cxx:260
void Gen::Fourdee::execute_new ( )
virtual

Definition at line 260 of file Fourdee.cxx.

261 {
262  if (!m_depos) {
263  cerr << "Fourdee: no depos, can't do much" << endl;
264  return;
265  }
266 
267  if (!m_ductor and (m_digitizer or m_dissonance or m_digitizer or m_filter or m_output) ) {
268  std::cerr <<"Fourdee: a Ductor is required for subsequent pipeline stages\n";
269  return;
270  }
271 
272  Pipeline pipeline;
273  auto source = new SourceNodeProc(m_depos);
274  Proc* last_proc = source;
275 
276  if (m_drifter) { // depo in, depo out
277  cerr << "Pipeline adding #"<<pipeline.size()<<": " << type(*m_drifter) << endl;
278  auto proc = new QueuedNodeProc(m_drifter);
279  last_proc = join(pipeline, last_proc, proc);
280  }
281  if (m_depofilter) { // depo in, depo out
282  cerr << "Pipeline adding #"<<pipeline.size()<<": " << type(*m_depofilter) << endl;
283  auto proc = new FunctionNodeProc(m_depofilter);
284  last_proc = join(pipeline, last_proc, proc);
285  }
286 
287  if (m_ductor) { // depo in, zero or more frames out
288  cerr << "Pipeline adding #"<<pipeline.size()<<": " << type(*m_ductor) << endl;
289  auto proc = new QueuedNodeProc(m_ductor);
290  last_proc = join(pipeline, last_proc, proc);
291  }
292 
293  if (m_dissonance) { // frame in, frame out
294  cerr << "Pipeline adding #"<<pipeline.size()<<": " << type(*m_dissonance) << endl;
295  auto proc = new NoiseAdderProc(m_dissonance);
296  last_proc = join(pipeline, last_proc, proc);
297  }
298 
299  if (m_digitizer) { // frame in, frame out
300  cerr << "Pipeline adding #"<<pipeline.size()<<": " << type(*m_digitizer) << endl;
301  auto proc = new FunctionNodeProc(m_digitizer);
302  last_proc = join(pipeline, last_proc, proc);
303  }
304 
305  if (m_filter) { // frame in, frame out
306  cerr << "Pipeline adding #"<<pipeline.size()<<": " << type(*m_filter) << endl;
307  auto proc = new FunctionNodeProc(m_filter);
308  last_proc = join(pipeline, last_proc, proc);
309  }
310 
311  if (m_output) { // frame in, full stop.
312  cerr << "Pipeline adding #"<<pipeline.size()<<": " << type(*m_output) << endl;
313  auto proc = new SinkNodeProc(m_output);
314  last_proc = join(pipeline, last_proc, proc);
315  }
316  else {
317  cerr << "Pipeline adding #"<<pipeline.size()<<": sink\n";
318  auto sink = new DropSinkProc;
319  last_proc = join(pipeline, last_proc, sink);
320  }
321 
322  // truly last proc needs to be added by hand.
323  pipeline.push_back(last_proc);
324 
325 
326 
327  // A "drain end first" strategy gives attention to draining
328  // queues the more toward the the end of the pipeline they are.
329  // This keeps the overall pipeline empty and leads to "pulse" type
330  // data movement. It's stupid for multiprocessing but in a single
331  // thread will keep memory usage low.
332  size_t pipelen = pipeline.size();
333  while (true) {
334  bool did_something = false;
335  for (size_t ind = pipelen-1; ind > 0; --ind) { // source has no input
336  SinkProc* proc = dynamic_cast<SinkProc*>(pipeline[ind]);
337  if (proc->input_pipe().empty()) {
338  continue;
339  }
340  bool ok = (*proc)();
341  if (!ok) {
342  std::cerr << "Pipeline failed\n";
343  return;
344  }
345  //std::cerr << "Executed process " << ind << std::endl;
346  did_something = true;
347  break;
348  }
349  if (!did_something) {
350  bool ok = (*pipeline[0])();
351  if (!ok) {
352  std::cerr << "Source empty\n";
353  return;
354  }
355  //std::cerr << "Executed source\n";
356  }
357  // otherwise, go through pipeline again
358  }
359 
360 }
std::vector< Proc * > Pipeline
Definition: GenPipeline.h:32
WireCell::IDepoSource::pointer m_depos
Definition: Fourdee.h:49
const CharType(& source)[N]
Definition: pointer.h:1147
virtual Pipe & input_pipe()=0
WireCell::IDepoFilter::pointer m_depofilter
Definition: Fourdee.h:50
WireCell::IDuctor::pointer m_ductor
Definition: Fourdee.h:52
Proc * join(Pipeline &pipeline, Proc *src, Proc *dst)
Definition: GenPipeline.h:218
WireCell::IFrameSource::pointer m_dissonance
Definition: Fourdee.h:53
WireCell::IFrameSink::pointer m_output
Definition: Fourdee.h:56
std::string type(const T &t)
Definition: Type.h:20
WireCell::IDrifter::pointer m_drifter
Definition: Fourdee.h:51
WireCell::IFrameFilter::pointer m_filter
Definition: Fourdee.h:55
WireCell::IFrameFilter::pointer m_digitizer
Definition: Fourdee.h:54
QTextStream & endl(QTextStream &s)
void Gen::Fourdee::execute_old ( )
virtual

Definition at line 361 of file Fourdee.cxx.

362 {
363  if (!m_depos) cerr << "Fourdee: no depos" << endl;
364  if (!m_drifter) cerr << "Fourdee: no drifter" << endl;
365  if (!m_ductor) cerr << "Fourdee: no ductor" << endl;
366  if (!m_dissonance) cerr << "Fourdee: no dissonance" << endl;
367  if (!m_digitizer) cerr << "Fourdee: no digitizer" << endl;
368  if (!m_filter) cerr << "Fourdee: no filter" << endl;
369  if (!m_output) cerr << "Fourdee: no sink" << endl;
370 
371  // here we make a manual pipeline. In a "real" app this might be
372  // a DFP executed by TBB.
373  int count=0;
374  int ndepos = 0;
375  int ndrifted = 0;
376  ExecMon em;
377  cerr << "Gen::Fourdee: starting\n";
378  while (true) {
379  ++count;
380 
381  IDepo::pointer depo;
382  if (!(*m_depos)(depo)) {
383  cerr << "DepoSource is empty\n";
384  }
385  if (!depo) {
386  cerr << "Got null depo from source at loop iteration " << count << endl;
387  }
388  else {
389  ++ndepos;
390  }
391  //cerr << "Gen::FourDee: seen " << ndepos << " depos\n";
392 
393  IDrifter::output_queue drifted;
394  if (!(*m_drifter)(depo, drifted)) {
395  cerr << "Stopping on " << type(*m_drifter) << endl;
396  goto bail;
397  }
398  if (drifted.empty()) {
399  continue;
400  }
401  if (m_depofilter) {
402  IDrifter::output_queue fdrifted;
403  for (auto drifted_depo : drifted) {
404  IDepo::pointer fdepo;
405  if ((*m_depofilter)(drifted_depo, fdepo)) {
406  fdrifted.push_back(fdepo);
407  }
408  }
409  drifted = fdrifted;
410  }
411 
412  ndrifted += drifted.size();
413  cerr << "Gen::FourDee: seen " << ndrifted << " drifted\n";
414  dump(drifted);
415 
416  for (auto drifted_depo : drifted) {
417  IDuctor::output_queue frames;
418  if (!(*m_ductor)(drifted_depo, frames)) {
419  cerr << "Stopping on " << type(*m_ductor) << endl;
420  goto bail;
421  }
422  if (frames.empty()) {
423  continue;
424  }
425  cerr << "Gen::FourDee: got " << frames.size() << " frames\n";
426 
427  for (IFrameFilter::input_pointer voltframe : frames) {
428  em("got frame");
429  cerr << "voltframe: ";
430  dump(voltframe);
431 
432  if (m_dissonance) {
433  cerr << "Gen::FourDee: including noise\n";
434  IFrame::pointer noise;
435  if (!(*m_dissonance)(noise)) {
436  cerr << "Stopping on " << type(*m_dissonance) << endl;
437  goto bail;
438  }
439  if (noise) {
440  cerr << "noiseframe: ";
441  dump(noise);
442  voltframe = Gen::sum(IFrame::vector{voltframe,noise}, voltframe->ident());
443  em("got noise");
444  }
445  else {
446  cerr << "Noise source is empty\n";
447  }
448  }
449 
451  if (m_digitizer) {
452  if (!(*m_digitizer)(voltframe, adcframe)) {
453  cerr << "Stopping on " << type(*m_digitizer) << endl;
454  goto bail;
455  }
456  em("digitized");
457  cerr << "digiframe: ";
458  dump(adcframe);
459  }
460  else {
461  adcframe = voltframe;
462  }
463 
464  if (m_filter) {
466  if (!(*m_filter)(adcframe, filtframe)) {
467  cerr << "Stopping on " << type(*m_filter) << endl;
468  goto bail;
469  }
470  adcframe = filtframe;
471  em("filtered");
472  }
473 
474  if (m_output) {
475  if (!(*m_output)(adcframe)) {
476  cerr << "Stopping on " << type(*m_output) << endl;
477  goto bail;
478  }
479  em("output");
480  }
481  cerr << "Gen::Fourdee: frame with " << adcframe->traces()->size() << " traces\n";
482  }
483  }
484  }
485  bail: // what's this weird syntax? What is this, BASIC?
486  cerr << em.summary() << endl;
487 }
WireCell::IDepoSource::pointer m_depos
Definition: Fourdee.h:49
std::shared_ptr< const IDepo > pointer
Definition: IData.h:19
std::vector< pointer > vector
Definition: IData.h:21
WireCell::IDepoFilter::pointer m_depofilter
Definition: Fourdee.h:50
std::deque< output_pointer > output_queue
std::shared_ptr< const IFrame > input_pointer
Definition: IFunctionNode.h:39
WireCell::IDuctor::pointer m_ductor
Definition: Fourdee.h:52
const int ndepos
WireCell::IFrameSource::pointer m_dissonance
Definition: Fourdee.h:53
std::shared_ptr< const IFrame > output_pointer
Definition: IFunctionNode.h:40
IFrame::pointer sum(std::vector< IFrame::pointer > frames, int ident)
Definition: FrameUtil.cxx:15
WireCell::IFrameSink::pointer m_output
Definition: Fourdee.h:56
std::string type(const T &t)
Definition: Type.h:20
WireCell::IDrifter::pointer m_drifter
Definition: Fourdee.h:51
WireCell::IFrameFilter::pointer m_filter
Definition: Fourdee.h:55
void dump(const IFrame::pointer frame)
Definition: Fourdee.cxx:120
std::string summary() const
Return summary up to now.
Definition: ExecMon.cxx:21
WireCell::IFrameFilter::pointer m_digitizer
Definition: Fourdee.h:54
QTextStream & endl(QTextStream &s)

Member Data Documentation

WireCell::IDepoFilter::pointer WireCell::Gen::Fourdee::m_depofilter
private

Definition at line 50 of file Fourdee.h.

WireCell::IDepoSource::pointer WireCell::Gen::Fourdee::m_depos
private

Definition at line 49 of file Fourdee.h.

WireCell::IFrameFilter::pointer WireCell::Gen::Fourdee::m_digitizer
private

Definition at line 54 of file Fourdee.h.

WireCell::IFrameSource::pointer WireCell::Gen::Fourdee::m_dissonance
private

Definition at line 53 of file Fourdee.h.

WireCell::IDrifter::pointer WireCell::Gen::Fourdee::m_drifter
private

Definition at line 51 of file Fourdee.h.

WireCell::IDuctor::pointer WireCell::Gen::Fourdee::m_ductor
private

Definition at line 52 of file Fourdee.h.

WireCell::IFrameFilter::pointer WireCell::Gen::Fourdee::m_filter
private

Definition at line 55 of file Fourdee.h.

WireCell::IFrameSink::pointer WireCell::Gen::Fourdee::m_output
private

Definition at line 56 of file Fourdee.h.


The documentation for this class was generated from the following files: