CARMA C++
SelfCalStage.h
1 // $Id: SelfCalStage.h,v 1.2 2013/05/15 15:23:00 abeard Exp $
2 
3 #ifndef CARMA_PIPELINE_UTIL_SELFCALSTAGE_H
4 #define CARMA_PIPELINE_UTIL_SELFCALSTAGE_H
5 
6 
7 #include "carma/monitor/PipelineMonitorInput.h"
8 #include "carma/pipeline/pipelineUtils.h"
9 #include "carma/pipeline/Stage.h"
10 #include "carma/services/Selfcal.h"
11 #include "carma/util/PthreadMutex.h"
12 
13 #include <map>
14 #include <set>
15 #include <utility>
16 
17 namespace carma {
18 
19  namespace correlator {
20  namespace lib {
21  class CorrelatorBaseline;
22  class CorrelatorData;
23  } // namespace lib
24  } // namespace correlator
25 
26  namespace monitor {
27  class AstroSubsystem;
28  class PipelineMonitorInput;
29  class PipelineSubsystem;
30  class Input;
31  class SelfCal;
32  }
33 
34  namespace pipeline {
35 
36  class TsysStage;
37 
38  class SelfCalStage : public Stage {
39  public:
40 
46  SelfCalStage(
48  const carma::pipeline::TsysStage& tsys,
49  carma::monitor::AstroSubsystem & astro,
50  const carma::monitor::PipelineMonitorInput & plmi,
51  carma::pipeline::PipelineType plType );
52 
56  virtual ~SelfCalStage();
57 
61  void setReferenceAntNo( int antNo );
62 
63  private:
64 
65  typedef int SidebandIndex;
66  typedef int AntIndex;
67  typedef ::std::vector< carma::services::Complex > ComplexVector;
68  typedef ::std::vector< double > SnrVector;
69  typedef ::std::set< int > AntSet;
70  typedef ::std::pair< int, carma::monitor::PolType > AstroBandPolPair;
71 
72  class SelfCalSidebandInfo {
73  public:
74 
75  SelfCalSidebandInfo( );
76 
77  SelfCalSidebandInfo( int antennas, int maxIterations, bool usb,
78  carma::monitor::SelfCal * mon,
79  SelfCalStage * mom );
80 
81  SelfCalSidebandInfo( const SelfCalSidebandInfo & rhs );
82  SelfCalSidebandInfo &
83  operator=( const SelfCalSidebandInfo & rhs );
84 
85  void reset( ); // Reset for next frame/integration
86 
87  void setVis( int antenna1No, int antenna2No,
88  const std::complex< float > & avgVis,
89  double weight );
90 
91  void setBandPol( int bandNo, carma::monitor::PolType pol );
92 
93  AstroBandPolPair getBandPol() const;
94 
95  void calculateSelfCal( double rootbtau );
96 
97  void fillMonitorData( );
98 
99  std::pair< bool, ComplexVector > getVis( ) const;
100 
101  SnrVector getSnr( ) const;
102 
103  void setRefAnt( int antNo );
104 
105  private:
106 
107  carma::services::Selfcal selfCal_;
108  bool solutionValid_;
109 
110  ComplexVector vis_; // Indexed by input index
111  ComplexVector visErrors_; // Ditto
112  SnrVector snr_; // Ditto
113 
114  AntSet seenAnts_;
115  int referenceAntennaNo_;
116  bool explicitRefAnt_;
117  carma::util::PthreadMutex refAntMutex_;
118 
119  // Note the following change dynamically based on setVis
120  int bandNo_;
121  carma::monitor::PolType pol_;
122 
123  const int nAnts_;
124  const int maxIter_;
125  const bool usb_; // usb if true lsb if false.
126  carma::monitor::SelfCal * mon_;
127  SelfCalStage * mom_;
128  };
129 
130  typedef ::std::pair< SelfCalSidebandInfo,
131  SelfCalSidebandInfo > UsbLsbInfoPair;
132  typedef ::std::vector< UsbLsbInfoPair > SelfCalInfoVec;
133  typedef ::std::map< AstroBandPolPair,
134  SelfCalInfoVec::size_type > AstroBandPolInfoIdxMap;
135 
136  void
137  preprocess( const carma::correlator::lib::CorrelatorDataPtr cd );
138 
139  void
140  processBand( carma::correlator::lib::CorrelatorBand * cb );
141 
142  carma::correlator::lib::CorrelatorDataPtr
143  postprocess( carma::correlator::lib::CorrelatorDataPtr cd );
144 
145  void fillMonitorData( );
146 
147  void processBaseline(
148  int bandNumber,
150  std::set< SelfCalInfoVec::size_type > & seenInfos,
151  double & iTime );
152 
153  void writeChannelAvgsToMonitorSystem( );
154 
155  double calculateWeight( int input1Num,
156  int input2Num,
157  int bandNum,
158  bool usb,
159  double intTime ) const;
160 
161  double calculateSystemNoise( double rootbtau,
162  int inputNum,
163  int bandNum,
164  bool usb ) const;
165 
166  void zeroSelfcalSolutions( );
167 
168  SelfCalInfoVec::size_type
169  getInfoIdx( int astroBandNo, carma::monitor::PolType pol ) const;
170 
171  SelfCalInfoVec selfCalInfo_;
172 
174  carma::monitor::AstroSubsystem & astroMonitor_;
175  AstroBandPolInfoIdxMap bandPolToInfoIdx_;
176  const carma::pipeline::TsysStage & tsys_;
177  const carma::monitor::PipelineMonitorInput & plmi_;
178  const int maxIterations_;
179  const int nBands_;
180  const int nAnts_;
181  unsigned errors_;
182  const carma::pipeline::PipelineType plType_;
183 
184  }; // End class SelfCalStage
185 
186  } // End namespace pipeline
187 } // End namespace carma
188 #endif // End #ifndef CARMA_PIPELINE_UTIL_SELFCALSTAGE_H
Class to hold a Band of Correlator Data.
Tagged: Wed Jun 29 11:00:27 PDT 2005.
Computes an amplitude or phase selfcal solution on a set of visibilities.
Definition: Selfcal.h:40
Class to hold Correlator Baseline data.
Abstract base class for retrieving pipeline monitor system components common between the spectral lin...
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41