HistUnpacker.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2005 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Kernel/Classes/dsp/HistUnpacker.h
10 
11 #ifndef __HistUnpacker_h
12 #define __HistUnpacker_h
13 
14 #include "dsp/Unpacker.h"
15 #include <vector>
16 
17 namespace dsp {
18 
20  class HistUnpacker: public Unpacker
21  {
22 
23  public:
24 
26  static bool keep_histogram;
27 
29  HistUnpacker (const char* name = "HistUnpacker");
30 
32  virtual ~HistUnpacker ();
33 
35  void combine (const Operation*);
36 
38  void reset ();
39 
41  virtual double get_optimal_variance ();
42 
44  virtual void set_ndig (unsigned ndig);
46  virtual unsigned get_ndig () const;
47 
49  virtual unsigned get_ndim_per_digitizer () const;
50 
52  virtual void set_nstate (unsigned nstate);
54  unsigned get_nstate () const { return nstate; }
55 
57  virtual unsigned get_output_offset (unsigned idig) const;
58 
60  virtual unsigned get_output_ipol (unsigned idig) const;
61 
63  virtual unsigned get_output_ichan (unsigned idig) const;
64 
66  virtual void get_histogram (std::vector<unsigned long>&, unsigned) const;
67 
69  template <typename T>
70  void get_histogram (std::vector<T>& data, unsigned idig) const;
71 
73  unsigned long* get_histogram (unsigned idig, unsigned expect = 0);
74  const unsigned long* get_histogram (unsigned idig) const;
75 
77  double get_histogram_mean (unsigned idig) const;
78 
80  unsigned long get_histogram_total (unsigned idig) const;
81 
83  void zero_histogram ();
84 
85  protected:
86 
88  virtual void set_default_ndig ();
89 
90  void set_nstate_internal (unsigned _nstate);
91  unsigned get_nstate_internal () const;
92 
93  private:
94 
96  unsigned nstate;
97 
99  unsigned nstate_internal;
100 
102  unsigned ndig;
103 
105  std::vector< std::vector< unsigned long > > histograms;
106 
108  void resize ();
109 
110  bool resize_needed;
111  };
112 
113 }
114 
115 template <typename T> void
116 dsp::HistUnpacker::get_histogram (std::vector<T>& data, unsigned idig) const
117 {
118  std::vector<unsigned long> hist;
119  get_histogram (hist, idig);
120 
121  data.resize( hist.size() );
122 
123  for (unsigned i=0; i<hist.size(); i++)
124  data[i] = T(hist[i]);
125 }
126 
127 #endif
Bit unpacker that keeps a histogram and optimal statistics.
Definition: HistUnpacker.h:25
virtual void reset()
Reset accumulated results to intial values.
Definition: Operation.C:161
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
virtual void set_ndig(unsigned ndig)
Set the number of digitizers (histograms)
Definition: HistUnpacker.C:64
virtual void combine(const Operation *)
Combine accumulated results with another operation.
Definition: Operation.C:149
void zero_histogram()
Reset histogram counts to zero.
Definition: HistUnpacker.C:161
static bool keep_histogram
Maintain a diagnostic histogram of digitizer statistics.
Definition: HistUnpacker.h:36
virtual void set_default_ndig()
Compute the default number of digitizers.
Definition: HistUnpacker.C:48
Operation(const char *name)
All sub-classes must specify a unique name.
Definition: Operation.C:46
std::string name
Operation name.
Definition: Operation.h:153
Defines the interface by which operations are performed on data.
Definition: Operation.h:37
HistUnpacker(const char *name="HistUnpacker")
Default constructor.
Definition: HistUnpacker.C:18
virtual unsigned get_output_ichan(unsigned idig) const
Get the output frequency channel for the given digitizer;.
Definition: HistUnpacker.C:132
virtual unsigned get_output_ipol(unsigned idig) const
Get the output polarization for the given digitizer.
Definition: HistUnpacker.C:123
void combine(const Operation *)
If Operation is a HistUnpacker, integrate its histograms.
Definition: HistUnpacker.C:258
virtual void get_histogram(std::vector< unsigned long > &, unsigned) const
Get the histogram for the specified digitizer.
Definition: HistUnpacker.C:183
Abstract base class of Transformations that convert n-bit to float.
Definition: Unpacker.h:42
virtual unsigned get_ndig() const
Get the number of digitizers (histograms)
Definition: HistUnpacker.C:38
unsigned get_nstate() const
Get the number of states in the histogram.
Definition: HistUnpacker.h:64
virtual ~HistUnpacker()
Virtual destructor.
Definition: HistUnpacker.C:27
virtual double get_optimal_variance()
Get the optimal value of the time series variance.
Definition: HistUnpacker.C:32
double get_histogram_mean(unsigned idig) const
Get the centroid of the histogram for the given digitizer.
Definition: HistUnpacker.C:197
unsigned long get_histogram_total(unsigned idig) const
Get the total number of samples in the histogram.
Definition: HistUnpacker.C:215
virtual unsigned get_ndim_per_digitizer() const
Get the dimension of the digitizer outputs (real or complex)
Definition: HistUnpacker.C:82
virtual unsigned get_output_offset(unsigned idig) const
Get the offset (number of floats) into output for the given digitizer.
Definition: HistUnpacker.C:114
void set_nstate_internal(unsigned _nstate)
Set the number of states in the internal representation of the histogram.
Definition: HistUnpacker.C:101
void reset()
Reset the histograms.
Definition: HistUnpacker.C:287
virtual void set_nstate(unsigned nstate)
Set the number of states in the histogram.
Definition: HistUnpacker.C:88

Generated using doxygen 1.8.17