InputSource.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2023 Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Kernel/Classes/dsp/InputSource.h
10 
11 #ifndef __dsp_Kernel_Classes_InputSource_h
12 #define __dsp_Kernel_Classes_InputSource_h
13 
14 #include "dsp/Source.h"
15 #include "templates.h"
16 
17 namespace dsp {
18 
20  template<class Type>
21  class InputSource : public Source
22  {
23 
24  public:
25 
27  InputSource (const char* name) : Source(name) {}
28 
30  virtual void set_input (Type* input) = 0;
31 
33  virtual const Type* get_input () const = 0;
34 
36  virtual Type* get_input () = 0;
37 
39  const Observation* get_info() const override { return get_input()->get_info(); }
40 
42  Observation* get_info() override { return get_input()->get_info(); }
43 
45  uint64_t get_total_samples () const override { return get_info()->get_ndat(); }
46 
48  uint64_t get_current_sample () const override { return get_input()->tell(); }
49 
51  double get_current_time () const override { return get_input()->tell_seconds(); }
52 
54  void seek_time (double second) override { return get_input()->set_start_seconds(second); }
55 
57  void set_total_time (double second) { return get_input()->set_total_seconds(second); }
58 
60  bool end_of_data () const override { return get_input()->eod(); }
61 
63  void restart () override { get_input()->restart(); }
64 
66  void set_block_size (uint64_t block_size) override { get_input()->set_block_size(multiple_greater(block_size,get_resolution())); }
67 
69  uint64_t get_block_size () const override { return get_input()->get_block_size(); }
70 
72  void set_overlap (uint64_t overlap) override { get_input()->set_overlap(multiple_greater(overlap,get_resolution())); }
73 
75  uint64_t get_overlap () const override { return get_input()->get_overlap(); }
76 
78  virtual uint64_t get_resolution () const { return get_input()->get_resolution(); }
79 
81  void share (Source* that) override
82  {
83  auto same = dynamic_cast<InputSource*>(that);
84  if (!same)
85  throw Error (InvalidParam, "dsp::InputSource::share",
86  "mismatch between this type=%s and that type=%s", this->get_name().c_str(), that->get_name().c_str());
87 
88  set_input(same->get_input());
89  }
90 
92  void set_context (ThreadContext* context) override { get_input()->set_context(context); }
93  };
94 
95 }
96 
97 
98 #endif // !defined(__dsp_Kernel_Classes_InputSource_h)
void seek_time(double second) override
Seek to the specified time in seconds.
Definition: InputSource.h:64
uint64_t get_overlap() const override
Set the number of time samples by which segments of output TimeSeries data overlap.
Definition: InputSource.h:85
InputSource(const char *name)
Constructor.
Definition: InputSource.h:37
const Observation * get_info() const override
Get the Observation attributes that describe the source.
Definition: InputSource.h:49
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
Source objects that have an input Type.
Definition: InputSource.h:26
void restart() override
Start again from the beginning, if possible.
Definition: InputSource.h:73
void share(Source *that) override
Share any resources that can/should be shared between threads.
Definition: InputSource.h:91
virtual const Type * get_input() const =0
Return pointer to the input.
uint64_t get_ndat() const
Return the number of time samples in container.
Definition: Observation.h:107
std::string name
Operation name.
Definition: Operation.h:153
Source(const char *name)
Constructor.
Definition: Source.h:28
std::string get_name() const
Return the unique name of this operation.
Definition: Operation.h:95
Stores information about digital, band-limited, time-varying signals.
Definition: Observation.h:33
double get_current_time() const override
Get the current time offset from the start in seconds.
Definition: InputSource.h:61
bool end_of_data() const override
Return true when the end of data has been reached.
Definition: InputSource.h:70
uint64_t get_total_samples() const override
Get the total number of time samples available (return 0 if unknown)
Definition: InputSource.h:55
void set_total_time(double second)
Truncate the time series at the specified second.
Definition: InputSource.h:67
void set_overlap(uint64_t overlap) override
Set the number of time samples by which output segments should overlap.
Definition: InputSource.h:82
uint64_t get_block_size() const override
Get the number of time samples per segment output by the source.
Definition: InputSource.h:79
void set_context(ThreadContext *context) override
In multi-threaded programs, a mutual exclusion and a condition.
Definition: InputSource.h:102
void set_block_size(uint64_t block_size) override
Set the desired number of time samples per segment output by the source.
Definition: InputSource.h:76
Abstract interface to sources of TimeSeries data.
Definition: Source.h:22
uint64_t get_current_sample() const override
Get the current time sample offset from the start.
Definition: InputSource.h:58
virtual uint64_t get_resolution() const
Get the minimum number of time samples that can be output by the source.
Definition: InputSource.h:88
virtual void set_input(Type *input)=0
Set the input.

Generated using doxygen 1.8.17