excision_unpack.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2008 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Kernel/Classes/dsp/excision_unpack.h
10 
11 #ifndef __ExcisionUnpacker_excision_unpack_h
12 #define __ExcisionUnpacker_excision_unpack_h
13 
14 #include "dsp/ExcisionUnpacker.h"
15 
16 #include <iostream>
17 #include <assert.h>
18 
19 using namespace std;
20 
21 template<class U, class Iter>
23  Iter& input_data,
24  float* output_data,
25  uint64_t nfloat,
26  unsigned long* hist,
27  unsigned* weights,
28  unsigned nweights)
29 {
30 #ifndef _DEBUG
31  if (verbose)
32 #endif
33  cerr << "dsp::ExcisionUnpacker::excision_unpack in=" << input_data.ptr()
34  << " out=" << output_data << " nfloat=" << nfloat << "\n\t"
35  << " hist=" << hist << " weights=" << weights
36  << " nweights=" << nweights << endl;
37 
38  const unsigned ndim_dig = get_ndim_per_digitizer();
39  const unsigned nfloat_per_weight = get_ndat_per_weight() * ndim_dig;
40  const unsigned long n_weights = nfloat / nfloat_per_weight;
41 
42  assert (nfloat % nfloat_per_weight == 0);
43 
44  if (weights && n_weights > nweights)
45  throw Error (InvalidParam, "dsp::ExcisionUnpacker::excision_unpack",
46  "weights array size=%d < nweights=%d", nweights, n_weights);
47 
48  const unsigned output_incr = get_output_incr ();
49 
50  const unsigned hist_size = get_ndat_per_weight();
51 
52  unsigned n_low = 0;
53 
54  for (unsigned long wt=0; wt<n_weights; wt++)
55  {
56 #ifdef _DEBUG
57  cerr << wt << " ";
58 #endif
59 
60  // the prepare method should not modify the iterator
61  unpack.prepare (input_data, nfloat_per_weight);
62 
63  // the unpack method should modify the iterator
64  unpack.unpack (input_data, nfloat_per_weight,
65  output_data, output_incr, n_low);
66 
67  // if data are complex, quickly divide n_low by two
68  if (ndim_dig == 2)
69  n_low >>= 1;
70 
71  if (hist && n_low < hist_size)
72  hist [n_low] ++;
73 
74  /*
75  Data are flagged as bad and set to zero if:
76 
77  1) the unpacker says it is bad;
78  2) the number of low voltage states is outside thresholds; or
79  3) this section of data has been previously flagged bad
80  (e.g. due to bad data in the other polarization).
81  */
82 
83  if ( unpack.bad ||
84  n_low<nlow_min || n_low>nlow_max ||
85  (weights && weights[wt] == 0) )
86  {
87 #ifdef _DEBUG2
88  cerr << "w[" << wt << "]=0 ";
89 #endif
90  if (weights)
91  weights[wt] = 0;
92 
93  // reduce the risk of other functions accessing un-initialized
94  // segments of the array
95  for (unsigned ifloat=0; ifloat<nfloat_per_weight; ifloat++)
96  output_data [ifloat * output_incr] = 0.0;
97  }
98 
99  output_data += nfloat_per_weight * output_incr;
100  }
101 
102 #ifdef _DEBUG
103  cerr << "DONE!" << endl;
104 #endif
105 
106 }
107 
108 #endif
void excision_unpack(U &unpack, Iterator &input, float *output_data, uint64_t ndat, unsigned long *hist, unsigned *weights, unsigned nweights)
Template method can be used to implement pure virtual dig_unpack.

Generated using doxygen 1.8.17