SKAParallelUnpacker.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2023 by Willem van Straten and Andrew Jameson
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 #ifndef __dsp_Kernel_Formats_ska1_SKAParallelUnpacker
10 #define __dsp_Kernel_Formats_ska1_SKAParallelUnpacker
11 
12 #include "dsp/ParallelUnpacker.h"
13 #include <assert.h>
14 
15 namespace dsp {
16 
21  class SKAParallelUnpacker : public ParallelUnpacker
22  {
23  public:
24 
27 
30 
31  void configure (const Observation* observation);
32 
34  bool matches (const Observation* observation) const override;
35 
37  void match (const Observation* observation);
38 
39  protected:
40 
42  void unpack ();
43 
44  private:
45 
47  float get_scale_factor(const unsigned char * weights, uint32_t packet_number);
48 
58  template <typename T>
59  void unpack_samples(const T* in, const unsigned char * weights, uint32_t nheaps)
60  {
61  const uint32_t nval_per_packet = nsamp_per_packet * ndim;
62  const uint32_t nsamp = nheaps * nsamp_per_packet;
63 
64  assert (output->get_ndat() == nsamp);
65  assert (output->get_nchan() == nchan);
66  assert (output->get_ndim() == ndim);
67  assert (nchan == npackets_per_heap * nchan_per_packet);
68 
69  // Unpack quantised data store in heap, packet, pol, chan_block, samp_block ordering used in CBF/PSR formats
70  uint32_t packet_number = 0;
71  for (uint32_t iheap=0; iheap<nheaps; iheap++)
72  {
73  // number of values that are offset for the heap
74  const uint32_t heap_val_offset = (iheap * nsamp_per_packet) * ndim;
75 
76  for (uint32_t ipacket=0; ipacket<npackets_per_heap; ipacket++)
77  {
78  const float scale_factor = get_scale_factor(weights, packet_number);
79  const float multiplier = (std::isnan(scale_factor) || scale_factor<=0.0) ? 0.0 : 1.0 / scale_factor;
80 
81  if (std::isnan(scale_factor))
82  {
83  invalid_packets++;
84  }
85 
86  for (uint32_t ichan=0; ichan<nchan_per_packet; ichan++)
87  {
88  const uint32_t ochan = (ipacket * nchan_per_packet) + ichan;
89  for (uint32_t ipol=0; ipol<npol; ipol++)
90  {
91  float * into = output->get_datptr (ochan, ipol) + heap_val_offset;
92  for (uint32_t ival=0; ival<nval_per_packet; ival++)
93  {
94  into[ival] = static_cast<float>(in[0]) * multiplier;
95  in++;
96  }
97  }
98  }
99  packet_number++;
100  }
101  }
102  }
103 
105  bool configured{false};
106 
108  uint32_t nchan_per_packet{0};
109 
111  uint32_t nsamp_per_packet{0};
112 
114  uint32_t nsamp_per_weight{0};
115 
117  uint32_t npackets_per_heap{0};
118 
120  uint32_t weights_packet_stride{0};
121 
123  uint32_t scale_nbyte{4};
124 
126  uint32_t weight_nbyte{2};
127 
129  unsigned ndim{0};
130 
132  unsigned npol{0};
133 
135  unsigned nbit{0};
136 
138  unsigned nchan{0};
139 
141  std::string machine;
142 
144  uint64_t invalid_packets{0};
145 
146  };
147 
148 } // namespace dsp
149 
150 #endif // __dsp_Kernel_Formats_ska1_SKAParallelUnpacker
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
~SKAParallelUnpacker()
Destructor.
Definition: SKAParallelUnpacker.C:19
virtual unsigned char * get_rawptr()
Return pointer to the raw data buffer.
Definition: BitSeries.h:64
unsigned get_ndim() const
Return the dimension of each datum.
Definition: Observation.h:80
unsigned get_nbit() const
Return the number of bits per value.
Definition: Observation.h:95
bool matches(const Observation *observation) const override
Return true if descriptor describes a file that can be opened.
Definition: SKAParallelUnpacker.C:68
uint64_t get_ndat() const
Return the number of time samples in container.
Definition: Observation.h:107
unsigned get_npol() const
Return the number of polarizations.
Definition: Observation.h:90
Stores information about digital, band-limited, time-varying signals.
Definition: Observation.h:33
void match(const Observation *observation)
Specialize the unpackers for the Observation.
Definition: SKAParallelUnpacker.C:91
A container for storing digitized (generally not floating point) data
Definition: BitSeries.h:35
Manages an array of Unpacker objects to be process in parallel.
Definition: ParallelUnpacker.h:28
SKAParallelUnpacker()
Constructor.
Definition: SKAParallelUnpacker.C:17
void unpack()
The unpacking routine.
Definition: SKAParallelUnpacker.C:98
Parses Observation attributes from an ASCII header.
Definition: ASCIIObservation.h:29
std::string get_machine() const
Return the instrument used to record signal.
Definition: Observation.h:194
Reference::To< TimeSeries > output
Container into which output data will be written.
Definition: HasOutput.h:49
unsigned get_nchan() const
Return the number of channels into which the band is divided.
Definition: Observation.h:85

Generated using doxygen 1.8.17