Input.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2002 - 2011 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Kernel/Classes/dsp/Input.h
10 
11 #ifndef __Input_h
12 #define __Input_h
13 
14 #include "dsp/Operation.h"
15 #include "dsp/Observation.h"
16 
17 #include "MJD.h"
18 
19 class ThreadContext;
20 
21 namespace dsp {
22 
23  class BitSeries;
24 
26 
31  class Input : public Operation
32  {
33 
34  friend class IOManager;
35 
36  public:
37 
38  typedef BitSeries OutputType;
39 
41  Input (const char* name);
42 
44  virtual ~Input ();
45 
47  virtual const Input* get_origin () const { return this; }
48 
50  virtual void copy (const Input* input);
51 
53  void prepare ();
54 
56  void reserve ();
57 
59  void reserve (BitSeries*);
60 
62  virtual bool eod() const = 0;
63 
65  virtual void restart ();
66 
68 
69  void load (BitSeries* data);
70 
72  virtual void set_output (BitSeries* data);
73 
75  virtual BitSeries* get_output();
76 
78  virtual bool has_output () const;
79 
81  virtual void seek (int64_t offset, int whence = 0);
82 
84  uint64_t tell () const { return load_sample; }
85 
87  virtual void seek (const MJD& mjd);
88 
90  virtual uint64_t get_block_size () const { return block_size; }
92  virtual void set_block_size (uint64_t _size);
93 
95  virtual uint64_t get_overlap () const { return overlap; }
97  virtual void set_overlap (uint64_t _overlap);
98 
100  virtual uint64_t get_stride () const { return get_block_size()-get_overlap(); }
101 
103  virtual uint64_t get_total_samples () const { return get_info()->get_ndat(); }
104 
106 
107  void set_total_samples (uint64_t s) { get_info()->set_ndat(s); }
108 
110  operator const Observation* () const { return get_info(); }
111 
113  virtual Observation* get_info () { return info; }
114 
116  virtual const Observation* get_info () const { return info; }
117 
119  uint64_t get_load_sample () const { return load_sample; }
120 
122  uint64_t get_load_size () const { return load_size; }
123 
125  unsigned get_resolution () const { return resolution; }
126 
128  void set_resolution (unsigned res) { resolution = res; }
129 
131  void seek_seconds (double seconds, int whence = 0);
132 
134  double tell_seconds () const;
135 
137  void set_start_seconds (double seconds);
138 
140  void set_total_seconds (double seconds);
141 
143  void set_context (ThreadContext* context);
144 
146  bool has_context () const { return context != nullptr; }
147 
149  virtual std::string get_prefix () const;
150 
151  protected:
152 
154  virtual void set_eod (bool) = 0;
155 
158 
160 
162  virtual void load_data (BitSeries* data) = 0;
163 
165  virtual void operation ();
166 
168  virtual void mark_output ();
169 
172 
174 
178  unsigned resolution;
179 
182  uint64_t last_load_ndat;
183 
185  std::string real_source;
186 
187  private:
188 
190 
195  uint64_t block_size;
196 
198 
202  uint64_t overlap;
203 
205 
209  unsigned resolution_offset;
210 
212  uint64_t load_sample;
213 
215  uint64_t load_size;
216 
218  uint64_t start_offset;
219 
221  void set_load_size ();
222 
224  ThreadContext* context;
225  };
226 
227 }
228 
229 #endif // !defined(__Input_h)
virtual void set_ndat(uint64_t _ndat)
Set the number of time samples in container.
Definition: Observation.h:105
unsigned get_resolution() const
Get the time sample resolution of the data source.
Definition: Input.h:125
unsigned resolution
Time sample resolution of the data source.
Definition: Input.h:178
void seek_seconds(double seconds, int whence=0)
Convenience method used to seek in units of seconds.
Definition: Input.C:345
Produces TimeSeries data by integrating an Input with an Unpacker.
Definition: IOManager.h:26
Pure virtual base class of all objects that can load BitSeries data.
Definition: Input.h:31
virtual uint64_t get_block_size() const
Return the number of time samples to load on each load_block.
Definition: Input.h:90
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
void prepare()
Prepare the output with the attributes of the data source.
Definition: Input.C:55
virtual Observation * get_info()
Get the information about the data source.
Definition: Input.h:113
virtual void resize(int64_t nsamples)
Allocate the space required to store nsamples time samples.
Definition: BitSeries.C:55
Input(const char *name)
Constructor.
Definition: Input.C:16
virtual const Input * get_origin() const
The origin of the data may be re-implemented by wrappers like SerialFiles.
Definition: Input.h:47
virtual void copy(const Input *input)
Copies the behaviour and information attributes (not data)
Definition: Input.C:235
void set_context(ThreadContext *context)
In multi-threaded programs, a mutual exclusion and a condition.
Definition: Input.C:38
Reference::To< BitSeries > output
The BitSeries to which data will be loaded on next call to operate.
Definition: Input.h:157
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
virtual void load_data(BitSeries *data)=0
Load the next block of time samples into BitSeries.
virtual void set_overlap(uint64_t _overlap)
Set the number of time samples by which consecutive blocks overlap.
Definition: Input.C:49
std::string real_source
If not "" then the source of the output gets changed to this after loading [""].
Definition: Input.h:185
Defines the interface by which operations are performed on data.
Definition: Operation.h:37
uint64_t get_load_sample() const
Get the next time sample to be loaded.
Definition: Input.h:119
virtual void mark_output()
Mark the output BitSeries with sequence informatin.
Definition: Input.C:96
Stores information about digital, band-limited, time-varying signals.
Definition: Observation.h:33
virtual void set_output(BitSeries *data)
Set the BitSeries to which data will be loaded.
Definition: Input.C:203
virtual uint64_t get_stride() const
Convenience function for returning block_size-overlap.
Definition: Input.h:100
uint64_t tell() const
Return the first time sample to be read on the next call to operate.
Definition: Input.h:84
bool has_context() const
Return true if the thread context has been set.
Definition: Input.h:146
void set_total_seconds(double seconds)
Convenience method used to set the number of seconds.
Definition: Input.C:376
void set_total_samples(uint64_t s)
Set the total number of time samples available.
Definition: Input.h:107
virtual bool eod() const =0
End of data.
virtual std::string get_prefix() const
Input derived types may specify a prefix to be added to output files.
Definition: Input.C:43
virtual void seek(int64_t offset, int whence=0)
Seek to the specified time sample.
Definition: Input.C:282
virtual BitSeries * get_output()
Retrieve a pointer to the output.
Definition: Input.C:213
static bool verbose
Global verbosity flag.
Definition: Operation.h:48
A container for storing digitized (generally not floating point) data
Definition: BitSeries.h:35
virtual const Observation * get_info() const
Get the information about the data source.
Definition: Input.h:116
double tell_seconds() const
Convenience method used to report the offset in seconds.
Definition: Input.C:354
Reference::To< Observation > info
Information about the data source (passed on to BitSeries in load)
Definition: Input.h:171
void set_start_seconds(double seconds)
Set the start of observation offset in units of seconds.
Definition: Input.C:363
void set_resolution(unsigned res)
Set the time sample resolution of the data source (use with care)
Definition: Input.h:128
virtual bool has_output() const
Return true if output is set.
Definition: Input.C:221
virtual void restart()
Return to the start of data, if possible.
Definition: Input.C:268
virtual uint64_t get_total_samples() const
Return the total number of time samples available.
Definition: Input.h:103
virtual uint64_t get_overlap() const
Return the number of time samples by which consecutive blocks overlap.
Definition: Input.h:95
virtual void operation()
Load data into the BitSeries specified with set_output.
Definition: Input.C:106
virtual void set_eod(bool)=0
Set the 'end_of_data' flag in dsp::Seekable.
virtual ~Input()
Destructor.
Definition: Input.C:36
void reserve()
Reserve the maximum amount of output space required.
Definition: Input.C:83
void load(BitSeries *data)
Load BitSeries data.
Definition: Input.C:249
virtual void set_block_size(uint64_t _size)
Set the number of time samples to load on each load_block.
Definition: Input.C:399
uint64_t get_load_size() const
Get the number of samples to be loaded.
Definition: Input.h:122
uint64_t last_load_ndat
The ndat of the BitSeries last loaded Used by Seekable::recycle_data() and set by load()
Definition: Input.h:182

Generated using doxygen 1.8.17