CARMA C++
CorrelatorData.h
Go to the documentation of this file.
1 
7 #ifndef CORRELATORDATA_H
8 #define CORRELATORDATA_H
9 
10 #include "carma/correlator/lib/CorrelatorBand.h"
12 #include "carma/util/PthreadMutex.h"
14 
15 #include <vector>
16 
17 namespace carma {
18 namespace correlator {
19 namespace lib {
20 
21  class CorrelatorConfigChecker;
22 
27  public:
28  // need this to allow the use of overloaded method deserialize
30  using carma::util::Serializable::deserializeVer1;
31 
32  class ScopedRef;
33 
37  explicit CorrelatorData( );
38 
42  CorrelatorData( const CorrelatorData & rhs );
43 
47  virtual ~CorrelatorData( );
48 
52  CorrelatorData & operator=( const CorrelatorData & rhs );
53 
57  void mySerialize( char * byteArray, int * offset ) const;
58 
62  int getSizeInBytes( ) const;
63 
68  void deserializeVer0( const char * byteArray, int * offset,
69  int byteArraySize );
70  void deserializeVer1( const char * byteArray, int * offset,
71  int byteArraySize );
76  void deserializeSwapVer0( const char * byteArray, int * offset,
77  int byteArraySize );
78  void deserializeSwapVer1( const char * byteArray, int * offset,
79  int byteArraySize );
80 
84  int getNumberOfBands( ) const;
85 
90 
99 
103  const std::vector<carma::correlator::lib::CorrelatorBand>&
104  getBands() const;
105 
106  std::vector<carma::correlator::lib::CorrelatorBand> & getBands( );
107 
114  getBand(int bandNumber) const;
115 
117  getBand( int bandNumber );
118 
119  bool hasBand( int bandNumber ) const;
120 
125 
127 
132 
133  void setHeaderMJD( double mjd );
134  void setHeaderTransmissionMJD( double mjd );
135  void setHeaderReceivedMJD( double mjd );
136 
140  void addIn( const CorrelatorData & rhs );
141 
147  void addIn( const CorrelatorBand & band );
148 
155  bool addInIgnoringDups( const CorrelatorBand & band );
156 
161  void normalize();
162 
166  void incrementRefCount( );
167 
172  void decrementRefCount( );
173 
174  bool incrementRefCountIfZero( );
175 
179  int getRefCount( ) const;
180 
181  void reserveBands( size_t numBands );
182 
183  void setBandMJD( int bandNumber, double mjd );
184 
185  bool baselineCountsPhysicallyValid( ) const;
186 
187  private:
188  CorrelatorBand & getBandNonconst( int bandNumber );
189 
190  int refCount_; // this variable is NOT serialized
191  mutable carma::util::PthreadMutex refCountGuard_; // this variable is NOT serialized
193  std::vector<carma::correlator::lib::CorrelatorBand> band_;
194  }; // End class CorrelatorData
195 
196 } // End namespace lib
197 } // End namespace correlator
198 } // End namespace carma
199 
200 
201 class carma::correlator::lib::CorrelatorData::ScopedRef {
202  public:
203  explicit ScopedRef( CorrelatorData & cd );
204 
205  /* virtual */ ~ScopedRef( );
206 
207  private:
208  ScopedRef( const ScopedRef & rhs );
209  ScopedRef & operator=( const ScopedRef & rhs );
210 
211  CorrelatorData & cd_;
212 };
213 
214 
215 inline
217 refCount_( 1 ),
218 refCountGuard_(),
219 header_(),
220 band_()
221 {
222 }
223 
224 
225 inline
228 refCount_( 1 ),
229 refCountGuard_(),
230 header_( rhs.header_ ),
231 band_( rhs.band_ )
232 {
233 }
234 
235 
236 inline
238 {
239 }
240 
241 
245 {
246  if ( &rhs != this ) {
247  // Pretty sure we don't want to copy the refCount_ - TWC 30 July 2007
248  // refCount_ = rhs.refCount_;
249  header_ = rhs.header_;
250  band_ = rhs.band_;
251  }
252 
253  return *this;
254 }
255 
256 
257 inline int
259 {
260  return band_.size();
261 }
262 
263 
264 
267 {
268  return header_;
269 }
270 
273 {
274  return header_;
275 }
276 
277 
278 inline const ::std::vector< carma::correlator::lib::CorrelatorBand > &
280 {
281  return band_;
282 }
283 
284 inline ::std::vector< carma::correlator::lib::CorrelatorBand > &
286 {
287  return band_;
288 }
289 
290 
291 inline void
294 {
295  header_ = h;
296 }
297 
298 
299 inline void
300 carma::correlator::lib::CorrelatorData::setHeaderMJD( const double mjd )
301 {
302  header_.setMJD( mjd );
303 }
304 
305 
306 inline void
307 carma::correlator::lib::CorrelatorData::setHeaderTransmissionMJD(
308  const double mjd )
309 {
310  header_.setTransmissionMJD( mjd );
311 }
312 
313 inline void
314 carma::correlator::lib::CorrelatorData::setHeaderReceivedMJD(
315  const double mjd )
316 {
317  header_.setReceivedMJD( mjd );
318 }
319 
320 inline void
321 carma::correlator::lib::CorrelatorData::reserveBands( const size_t numBands )
322 {
323  band_.reserve( numBands );
324 }
325 
326 
327 inline
328 carma::correlator::lib::CorrelatorData::ScopedRef::ScopedRef(
329  CorrelatorData & cd ) :
330 cd_( cd )
331 {
332  cd_.incrementRefCount();
333 }
334 
335 
336 inline
337 carma::correlator::lib::CorrelatorData::ScopedRef::~ScopedRef( )
338 try {
339  cd_.decrementRefCount();
340 } catch ( ... ) {
341  // Just stifle any exceptions
342 
343  return;
344 }
345 
346 
347 #endif
Abstract Class used to allow object to serialize themselves into a byte array.
Definition: Serializable.h:32
void incrementRefCount()
Increment the reference count.
int getNumberOfBands() const
Get number of Correlator Bands.
CorrelatorData & operator=(const CorrelatorData &rhs)
Assignment.
void deserializeSwapVer0(const char *byteArray, int *offset, int byteArraySize)
Used to reconstruct object.
const carma::correlator::lib::CorrelatorBand & getBand(int bandNumber) const
Get a single Correlator Band bandNumber is the number assigned to this band.
Class to hold a Band of Correlator Data.
void mySerialize(char *byteArray, int *offset) const
Used to serialize data.
int getRefCount() const
Return the refCount.
bool addInIgnoringDups(const CorrelatorBand &band)
Add a CorrelatorBand but ignore duplicates.
virtual void deserializeVer0(const char *byteArray, int *offset, int byteArraySize)=0
Called to continue the reconstruction of member objects from the byte Array.
Class containing header information for Correlator Data.
Class used to represents bands of Correlator Data.
void addIn(const CorrelatorData &rhs)
Add a CorrelatorData into this one.
void decrementRefCount()
Decrement the reference count.
void deserializeVer0(const char *byteArray, int *offset, int byteArraySize)
Used to reconstruct object.
void setHeader(const carma::correlator::lib::CorrelatorHeader &h)
Set Correlator Header.
const carma::correlator::lib::CorrelatorHeader & getHeader() const
Get Correlator Header.
int getSizeInBytes() const
Return size in bytes of object.
void addBand(const carma::correlator::lib::CorrelatorBand &band)
Add a Correlator Band.
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41
const std::vector< carma::correlator::lib::CorrelatorBand > & getBands() const
Get Correlator Bands.
void addBandViaSwap(carma::correlator::lib::CorrelatorBand &band)
Add a correlator band using a swap.