CARMA C++
CorrelatorSideband.h
Go to the documentation of this file.
1 #ifndef CORRELATORSIDEBAND_H
2 #define CORRELATORSIDEBAND_H
3 
4 #include <complex>
5 #include <vector>
9 
17 namespace carma {
18 namespace correlator {
19 namespace lib {
20 
21  class CorrelatorSideband;
22 
23  typedef ::std::vector< CorrelatorSideband > SidebandVector;
24  typedef ::std::vector< ::std::complex< float > > DataVector;
25  typedef ::std::vector< int > DataValidVector;
26 
31  public:
32  typedef enum {
33  AUTO_FLAVOR,
34  UPPER_FLAVOR,
35  LOWER_FLAVOR
36  } Flavor;
37 
38  typedef enum {
39  NO_REASON = 0x00000000,
40  A1_PHASELOCK = 0x00000001,
41  A2_PHASELOCK = 0x00000002,
42  A1_MAJOR_TRACKING = 0x00000004, // > 20% of integration
43  A2_MAJOR_TRACKING = 0x00000008, // > 20% of integration
44  A1_TSYS_BAD = 0x00000010,
45  A2_TSYS_BAD = 0x00000020,
46  A1_SHADOWED = 0x00000040,
47  A2_SHADOWED = 0x00000080,
48  A1_OFFLINE = 0x00000100,
49  A2_OFFLINE = 0x00000200,
50  A1_MINOR_TRACKING = 0x00000400,
51  A2_MINOR_TRACKING = 0x00000800,
52  A1_CALSTATE = 0x00001000,
53  A2_CALSTATE = 0x00002000,
54  UNKNOWN12 = 0x00004000,
55  UNKNOWN13 = 0x00008000,
56  UNKNOWN14 = 0x00010000,
57  UNKNOWN15 = 0x00020000,
58  UNKNOWN16 = 0x00040000,
59  UNKNOWN17 = 0x00080000,
60  UNKNOWN18 = 0x00100000,
61  UNKNOWN19 = 0x00200000,
62  UNKNOWN20 = 0x00400000,
63  MANUAL_FLAG = 0x00800000,
64  BAND_OFFLINE = 0x01000000,
65  UNMAPPED_SIGNAL = 0x02000000,
66  MONITOR_DATA_BAD = 0x04000000,
67  BAD_CHANNEL_COUNT = 0x08000000,
68  NO_RX_IN_SIDEBAND = 0x10000000,
69  CORR_DATA_MISSING = 0x20000000,
70  CORR_DATA_INVALID = 0x40000000,
71  DO_NOT_USE = 0x80000000,
72  } ValidReason;
73 
77  explicit CorrelatorSideband( Flavor initialFlavor );
78 
83 
87  virtual ~CorrelatorSideband( );
88 
92  void swap( CorrelatorSideband & rhs );
93 
97  void mySerialize( char * byteArray, int * offset ) const;
98 
102  void deserializeVer0( const char * byteArray,
103  int * offset,
104  int byteArraySize );
105 
106  void deserializeVer1( const char * byteArray,
107  int * offset,
108  int byteArraySize );
109 
113  void deserializeSwapVer0( const char * byteArray,
114  int * offset,
115  int byteArraySize );
116 
117  void deserializeSwapVer1( const char * byteArray,
118  int * offset,
119  int byteArraySize );
120 
124  int getSizeInBytes( ) const;
125 
129  bool isAuto( ) const;
130 
134  bool isUSB( ) const;
135 
139  bool isLSB( ) const;
140 
144  Flavor getFlavor( ) const;
145 
150  bool isValid(int channelIndex) const;
151 
157  bool isValid( ) const;
158 
163  void setValid(int channelIndex, bool val);
164 
168  void setValidAll(bool val);
169 
173  DataVector & getData( ) const;
174 
178  const DataValidVector & getDataValid( ) const;
179 
183  int getNumberOfChans( ) const;
184 
192  int getNumberOfLags( ) const;
193 
201  void setNumberOfLags(int numLags);
202 
206  float getSkyFrequency( ) const;
207 
211  float getRxOutFrequency( ) const;
212 
217  float getOffsetFrequency( ) const;
218 
222  void setSkyFrequency(float freq);
223 
227  void setRxOutFrequency(float freq);
228 
233  void setOffsetFrequency(float offsetFreq);
234 
238  float getDeltaFrequency( ) const;
239 
243  void setDeltaFrequency(float freq);
244 
248  void setData( const ::std::vector< ::std::complex< float > > & data );
249 
250  void swapData( ::std::vector< ::std::complex< float > > & data );
251 
256 
261 
266  void computeStats(bool keepEndChannels = true);
267 
272  void normalize( );
273 
278 
282  void addIn( const CorrelatorSideband & rhs );
283 
288  void flagData( unsigned int reason );
289  void unflagData( unsigned int reason );
290 
295  void blankData( unsigned int reason );
296 
302  getBlankFlagStatus() const;
303 
307  unsigned int getValidReason() const;
308 
313  std::pair< unsigned int, unsigned int >
314  getMinorTrackBfCount( ) const;
315 
316  std::string getSummary() const;
317 
318  std::string getSpectra() const;
319 
320  private:
321 
322  void setDataValidAllPrivate(bool b);
323  void setBlankFlagStatus( unsigned int reason );
324  void unsetBlankFlagStatus( unsigned int reason );
325 
326 
327  bool autoSideband_;
328  bool usb_;
329  bool dataHasBeenSet_;
330  bool dataValidAllHasBeenSet_;
331  bool dataValidAllValue_;
332  int numberOfChans_;
333 
334  // Next variable is needed to indicated the actual number of lags
335  // used before any zero padding (if needed) is done before the FFT.
336  // This will be used later when decimation of the spectra is done
337  // and the Hanning window must be applied to only the acutal data
338  // points, not the zero padded values.
339  int numberOfLags_;
340 
342  float frequency_; // sky freq. of 1st channel(GHz)
343  float deltaFrequency_; // delta freq.(MHz)
344  float offsetFrequency_; // band edge to center of 1st channel(MHz)
345  mutable DataVector data_;
346  // dataValid_ is an array which indicates which channels
347  // of data_ are valid. This is most useful for the pseudo-band
348  // comprised of all the real band averages. For example, 16 bands
349  // of data will be band averaged to produce a pseudo-band of
350  // 16 channels which represents the average of each band. These
351  // 16 channles can be marked as valid(1) or invalid(0). This
352  // vector will also be used to accumulate sums of the data for
353  // proper normalization. Thus an entry of 0 means invalid and > 0
354  // valid.
355  // Note: not using a vector<bool> since this is a special
356  // construct is C++ just to screw you up!!!
357  DataValidVector dataValid_;
358  unsigned int validReason_;
360  std::pair< unsigned int, unsigned int > minorTrackBfCountNoSerialize_;
361 
362  }; // End class CorrelatorSideband
363 
364 } // End namespace lib
365 } // End namespace correlator
366 } // End namespace carma
367 
368 
369 inline
371  const Flavor initialFlavor ) :
372  autoSideband_( initialFlavor == AUTO_FLAVOR ),
373  usb_( initialFlavor == UPPER_FLAVOR ),
374 dataHasBeenSet_( false ),
375 dataValidAllHasBeenSet_( false ),
376 dataValidAllValue_( false ),
377 numberOfChans_( 0 ),
378 numberOfLags_( 0 ),
379 stats_(),
380 frequency_( 0.0 ),
381 deltaFrequency_( 0.0 ),
382 offsetFrequency_( 0.0 ),
383 data_(),
384 dataValid_(),
385 validReason_(0),
386 bfStatus_(monitor::MonitorPoint::UNDETERMINED ),
387 minorTrackBfCountNoSerialize_( 0, 0 )
388 {
389 }
390 
391 
392 inline
394  const CorrelatorSideband & rhs ):
395 autoSideband_( rhs.autoSideband_ ),
396 usb_( rhs.usb_ ),
397 dataHasBeenSet_( rhs.dataHasBeenSet_ ),
398 dataValidAllHasBeenSet_( rhs.dataValidAllHasBeenSet_ ),
399 dataValidAllValue_( rhs.dataValidAllValue_ ),
400 numberOfChans_( rhs.numberOfChans_ ),
401 numberOfLags_( rhs.numberOfLags_ ),
402 stats_( rhs.stats_ ),
403 frequency_( rhs.frequency_ ),
404 deltaFrequency_( rhs.deltaFrequency_ ),
405 offsetFrequency_( rhs.offsetFrequency_ ),
406 data_( rhs.data_ ),
407 dataValid_( rhs.dataValid_ ),
408 validReason_( rhs.validReason_ ),
409 bfStatus_(rhs.bfStatus_),
410 minorTrackBfCountNoSerialize_( rhs.minorTrackBfCountNoSerialize_ )
411 {
412 }
413 
414 
415 inline void
417 {
418  ::std::swap( autoSideband_, rhs.autoSideband_ );
419  ::std::swap( usb_, rhs.usb_ );
420  ::std::swap( dataHasBeenSet_, rhs.dataHasBeenSet_ );
421  ::std::swap( dataValidAllHasBeenSet_, rhs.dataValidAllHasBeenSet_ );
422  ::std::swap( dataValidAllValue_, rhs.dataValidAllValue_ );
423  ::std::swap( numberOfChans_, rhs.numberOfChans_ );
424  ::std::swap( numberOfLags_, rhs.numberOfLags_ );
425  stats_.swap( rhs.stats_ );
426  ::std::swap( frequency_, rhs.frequency_ );
427  ::std::swap( deltaFrequency_, rhs.deltaFrequency_ );
428  ::std::swap( offsetFrequency_, rhs.offsetFrequency_ );
429  data_.swap( rhs.data_ );
430  dataValid_.swap( rhs.dataValid_ );
431  ::std::swap( validReason_, rhs.validReason_ );
432  ::std::swap( bfStatus_, rhs.bfStatus_ );
433  ::std::swap( minorTrackBfCountNoSerialize_,
434  rhs.minorTrackBfCountNoSerialize_ );
435 }
436 
437 
440  const CorrelatorSideband & rhs )
441 {
442  if ( &rhs != this ) {
443  autoSideband_ = rhs.autoSideband_;
444  usb_ = rhs.usb_;
445  dataHasBeenSet_ = rhs.dataHasBeenSet_;
446  dataValidAllHasBeenSet_ = rhs.dataValidAllHasBeenSet_;
447  dataValidAllValue_ = rhs.dataValidAllValue_;
448  numberOfChans_ = rhs.numberOfChans_;
449  numberOfLags_ = rhs.numberOfLags_;
450  frequency_ = rhs.frequency_;
451  deltaFrequency_ = rhs.deltaFrequency_;
452  offsetFrequency_ = rhs.offsetFrequency_;
453  stats_ = rhs.stats_;
454  data_ = rhs.data_;
455  dataValid_ = rhs.dataValid_;
456  validReason_ = rhs.validReason_;
457  bfStatus_ = rhs.bfStatus_;
458  minorTrackBfCountNoSerialize_ = rhs.minorTrackBfCountNoSerialize_;
459  }
460 
461  return *this;
462 }
463 
464 
465 inline
467 {
468 }
469 
470 
471 inline bool
473 {
474  return autoSideband_;
475 }
476 
477 
478 inline bool
480 {
481  return usb_;
482 }
483 
484 
485 inline bool
487 {
488  return ((usb_ != true) && (autoSideband_ != true));
489 }
490 
491 inline carma::correlator::lib::CorrelatorSideband::Flavor
493 {
494  if ( autoSideband_ ) {
495  return carma::correlator::lib::CorrelatorSideband::AUTO_FLAVOR;
496  } else {
497  if ( usb_ )
498  return carma::correlator::lib::CorrelatorSideband::UPPER_FLAVOR;
499  else
500  return carma::correlator::lib::CorrelatorSideband::LOWER_FLAVOR;
501  }
502 }
503 
504 inline ::std::vector< ::std::complex< float > > &
506 {
507  return data_;
508 }
509 
510 
511 inline const ::std::vector< int > &
513 {
514  return dataValid_;
515 }
516 
517 
518 inline int
520 {
521  return numberOfChans_;
522 }
523 
524 
525 inline int
527 {
528  return numberOfLags_;
529 }
530 
531 
532 inline float
534 {
535  return frequency_;
536 }
537 
538 
539 inline float
541 {
542  return frequency_;
543 }
544 
545 
546 inline float
548 {
549  return offsetFrequency_;
550 }
551 
552 
553 inline float
555 {
556  return deltaFrequency_;
557 }
558 
559 
562 {
563  return stats_;
564 }
565 
566 
567 inline void
569  const int numLags )
570 {
571  numberOfLags_ = numLags;
572 }
573 
574 
575 inline void
577  const float freq )
578 {
579  frequency_ = freq;
580 }
581 
582 
583 inline void
585  const float freq )
586 {
587  frequency_ = freq;
588 }
589 
590 
591 inline void
593  const float offsetFreq )
594 {
595  offsetFrequency_ = offsetFreq;
596 }
597 
598 
599 inline void
601  const float delFreq )
602 {
603  deltaFrequency_ = delFreq;
604 }
605 
606 
607 inline void
610 {
611  stats_ = stats;
612 }
613 
616 {
617  return bfStatus_;
618 }
619 
620 #endif
void blankData(unsigned int reason)
Blank data with specified reason (removes all data).
Abstract Class used to allow object to serialize themselves into a byte array.
Definition: Serializable.h:32
void setRxOutFrequency(float freq)
Set receiver output freq.
Abstract base class for all monitor points.
Class to hold some statistics related to Sideband data.
void setNumberOfLags(int numLags)
Set the number of Lags used to create Spectra.
float getSkyFrequency() const
Return sky freq.
int getNumberOfLags() const
Get Number of Lags used to create Spectra.
float getOffsetFrequency() const
Return the offset frquency the center of the first channel is from the edge of the band...
void deserializeVer0(const char *byteArray, int *offset, int byteArraySize)
Uset to deserialize contents.
BLANKING_FLAGGING
Blanking/flagging status of the data.
Definition: MonitorPoint.h:159
const DataValidVector & getDataValid() const
Get valid channel vector.
DataVector & getData() const
Get Spectra.
void swap(CorrelatorSideband &rhs)
Swap this instance with another CorrelatorSideband instance.
void setOffsetFrequency(float offsetFreq)
Set the offset frquency the center of the first channel is from the edge of the band.
unsigned int getValidReason() const
Get reason for blanking &amp; flagging.
void computeStats(bool keepEndChannels=true)
Convenience method to compute the Stats from the internally stored spectra.
void deserializeSwapVer0(const char *byteArray, int *offset, int byteArraySize)
Uset to deserialize contents.
void mySerialize(char *byteArray, int *offset) const
Use to serialize contents.
float getDeltaFrequency() const
Get delta freq.
CorrelatorSideband & operator=(const CorrelatorSideband &rhs)
Assignment.
bool isUSB() const
True if Sideband is an UpperSideband Spectra.
void setDeltaFrequency(float freq)
Set delta freq.
int getSizeInBytes() const
Return size in bytes.
::std::vector< ::carma::canbus::byteType > DataVector
Alias for CAN data.
Definition: Types.h:72
void setValidAll(bool val)
Set all channels to same validity.
bool isAuto() const
True if Sideband is an Auto-Spectra.
void setValid(int channelIndex, bool val)
Set validity for channel index.
void setSkyFrequency(float freq)
Set sky freq.
carma::monitor::MonitorPoint::BLANKING_FLAGGING getBlankFlagStatus() const
Get blank flag status for this baseline.
int getNumberOfChans() const
Get Number of Channels in Spectra.
CorrelatorSideband(Flavor initialFlavor)
Constructor.
void setStats(const carma::correlator::lib::CorrelatorStats &stats)
Set the Stats object.
bool isLSB() const
True if Sideband is an UpperSideband Spectra.
void flagData(unsigned int reason)
Flag data with specified reason.
bool isValid() const
True if this sideband is valid which means at least 1 channel is valid.
void addIn(const CorrelatorSideband &rhs)
Add a CorrelatorSideband into this one.
void setData(const ::std::vector< ::std::complex< float > > &data)
Set Spectra.
const carma::correlator::lib::CorrelatorStats & getStats() const
Get the Stats object.
float getRxOutFrequency() const
Return receiver output freq.
Base class for Correlator Sideband data.
std::pair< unsigned int, unsigned int > getMinorTrackBfCount() const
Retrieve the minor track blanking and flagging counters.