ParallelInput.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2023 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Kernel/Classes/dsp/ParallelInput.h
10 
11 #ifndef __dsp_Kernel_Classes_ParallelInput_h
12 #define __dsp_Kernel_Classes_ParallelInput_h
13 
14 #include "dsp/Operation.h"
15 #include "Registry.h"
16 #include "MJD.h"
17 
18 namespace dsp {
19 
20  class ParallelBitSeries;
21  class Observation;
22  class Input;
23 
25  class ParallelInput : public Operation
26  {
27 
28  public:
29 
31 
33  ParallelInput (const char* name);
34 
36  virtual ~ParallelInput ();
37 
39 
40  static ParallelInput* create (const std::string& descriptor);
41 
43  const Input* at (unsigned index) const;
44 
46  Input* at (unsigned index);
47 
49 
50  virtual bool matches (const std::string& descriptor) const = 0;
51 
53  virtual void open (const std::string& descriptor) = 0;
54 
56  void operation ();
57 
59  operator const Observation* () const { return get_info(); }
60 
62  virtual Observation* get_info ();
63 
65  virtual const Observation* get_info () const;
66 
68  virtual void set_output (ParallelBitSeries*);
69 
72 
74  virtual void prepare ();
75 
77  virtual void reserve ();
78 
80  virtual void reserve (ParallelBitSeries*);
81 
83  virtual bool eod() const;
84 
86  void restart ();
87 
89 
90  virtual void load (ParallelBitSeries*);
91 
93  virtual void seek (int64_t offset, int whence = 0);
94 
96  uint64_t tell () const;
97 
99  virtual void seek (const MJD& mjd);
100 
102  double tell_seconds () const;
103 
105  void set_start_seconds (double seconds);
106 
108  void set_total_seconds (double seconds);
109 
111  virtual uint64_t get_block_size () const = 0;
113  virtual void set_block_size (uint64_t _size) = 0;
114 
116  virtual uint64_t get_overlap () const = 0;
118  virtual void set_overlap (uint64_t _overlap) = 0;
119 
121  virtual unsigned get_resolution () const = 0;
122 
124  uint64_t bytes_storage() const override;
125 
127  uint64_t bytes_scratch () const override;
128 
130  virtual void set_context (ThreadContext* _context) { context = _context; }
131  bool has_context () const { return context != nullptr; }
132  ThreadContext* get_context () { return context; }
133 
136 
138  static Register& get_register();
139 
140  protected:
141 
144 
146  std::vector< Reference::To<Input> > inputs;
147 
150 
152  ThreadContext* context {NULL};
153  };
154 
155 }
156 
157 #endif // !defined(__dsp_Kernel_Classes_ParallelInput_h)
158 
void set_start_seconds(double seconds)
Set the start of observation offset in units of seconds.
Definition: ParallelInput.C:157
virtual uint64_t get_block_size() const =0
Return the number of time samples to load on each load_block.
uint64_t bytes_scratch() const override
The number of bytes of scratch space used by the operation.
Definition: ParallelInput.C:189
Pure virtual base class of all objects that can load BitSeries data.
Definition: Input.h:31
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
virtual void open(const std::string &descriptor)=0
Open the inputs.
virtual void set_context(ThreadContext *_context)
In multi-threaded programs, a mutual exclusion and a condition.
Definition: ParallelInput.h:135
uint64_t bytes_storage() const override
The number of bytes of additional storage used by the operation.
Definition: ParallelInput.C:180
virtual unsigned get_resolution() const =0
Get the time sample resolution of the data source.
virtual bool matches(const std::string &descriptor) const =0
Return true if descriptor describes data in the recognized format.
virtual void prepare()
Prepare the output with the attributes of the data source.
Definition: ParallelInput.C:48
std::string name
Operation name.
Definition: Operation.h:153
Parent * create(unsigned i) const
virtual void set_block_size(uint64_t _size)=0
Set the number of time samples to load on each load_block.
virtual Observation * get_info()
Get the information about the data source.
Definition: ParallelInput.C:28
Defines the interface by which operations are performed on data.
Definition: Operation.h:37
Stores information about digital, band-limited, time-varying signals.
Definition: Observation.h:33
virtual ~ParallelInput()
Destructor.
Definition: ParallelInput.C:20
virtual void seek(int64_t offset, int whence=0)
Seek to the specified time sample.
Definition: ParallelInput.C:131
void set_total_seconds(double seconds)
Convenience method used to set the number of seconds.
Definition: ParallelInput.C:163
virtual void load(ParallelBitSeries *)
Load BitSeries data.
Definition: ParallelInput.C:105
virtual bool eod() const
End of data.
Definition: ParallelInput.C:81
unsigned size() const
void resize(unsigned N)
Create and manage N BitSeries objects.
Definition: ParallelBitSeries.C:18
ThreadContext * context
Thread coordination used in Input::load method.
Definition: ParallelInput.h:157
void operation()
Load the current ParallelBitSeries.
Definition: ParallelInput.C:175
virtual void set_output(ParallelBitSeries *)
Set the ParallelBitSeries to which data will be loaded.
Definition: ParallelInput.C:32
A container for storing digitized (generally not floating point) data
Definition: BitSeries.h:35
ParallelBitSeries * get_output()
Get the ParallelBitSeries to which data will be loaded.
Definition: ParallelInput.C:43
virtual void set_overlap(uint64_t _overlap)=0
Set the number of time samples by which consecutive blocks overlap.
Reference::To< ParallelBitSeries > output
The output array of parallel BitSeries.
Definition: ParallelInput.h:154
virtual void reserve()
Reserve the maximum amount of output space required.
Definition: ParallelInput.C:67
std::vector< Reference::To< Input > > inputs
Array of parallel Input objects.
Definition: ParallelInput.h:151
Reference::To< Observation > info
Information about the data source (passed on to ParallelBitSeries in load)
Definition: ParallelInput.h:148
Loads multiple parallel BitSeries data from multiple files.
Definition: ParallelInput.h:30
void restart()
Return to the start of data, if possible.
Definition: ParallelInput.C:99
const std::string get_message() const
Registry::List< ParallelInput > Register
typedef used to simplify template syntax in ParallelInput_registry.C
Definition: ParallelInput.h:140
double tell_seconds() const
Convenience method used to report the offset in seconds.
Definition: ParallelInput.C:169
ParallelInput(const char *name)
Constructor.
Definition: ParallelInput.C:16
virtual uint64_t get_overlap() const =0
Return the number of time samples by which consecutive blocks overlap.
static Register & get_register()
Return the list of registered sub-classes.
Definition: ParallelInput_registry.C:37
Manages an array of BitSeries to be process in parallel.
Definition: ParallelBitSeries.h:24
static ParallelInput * create(const std::string &descriptor)
Return a pointer to a new instance of the appropriate sub-class.
Definition: ParallelInput.C:199
const Input * at(unsigned index) const
Return the Input corresponding to the specified index.
Definition: ParallelInput.C:24
uint64_t tell() const
Return the first time sample to be read on the next call to operate.
Definition: ParallelInput.C:152
BitSeries * at(unsigned i)
Get the ith BitSeries instance.
Definition: ParallelBitSeries.h:45

Generated using doxygen 1.8.17