casacore
LatticeStatsDataProvider.h
Go to the documentation of this file.
1 //# Copyright (C) 2000,2001
2 //# Associated Universities, Inc. Washington DC, USA.
3 //#
4 //# This library is free software; you can redistribute it and/or modify it
5 //# under the terms of the GNU Library General Public License as published by
6 //# the Free Software Foundation; either version 2 of the License, or (at your
7 //# option) any later version.
8 //#
9 //# This library is distributed in the hope that it will be useful, but WITHOUT
10 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 //# License for more details.
13 //#
14 //# You should have received a copy of the GNU Library General Public License
15 //# along with this library; if not, write to the Free Software Foundation,
16 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 //#
18 //# Correspondence concerning AIPS++ should be addressed as follows:
19 //# Internet email: aips2-request@nrao.edu.
20 //# Postal address: AIPS++ Project Office
21 //# National Radio Astronomy Observatory
22 //# 520 Edgemont Road
23 //# Charlottesville, VA 22903-2475 USA
24 //#
25 //# $Id: Array.h 21545 2015-01-22 19:36:35Z gervandiepen $
26 
27 #ifndef LATTICES_LATTICESTATSDATAPROVIDER_H
28 #define LATTICES_LATTICESTATSDATAPROVIDER_H
29 
30 #include <casacore/lattices/Lattices/LatticeIterator.h>
31 #include <casacore/lattices/LatticeMath/LatticeStatsDataProviderBase.h>
32 
33 #include <casacore/casa/aips.h>
34 
35 namespace casacore {
36 
37 // Data provider which allows stats framework to iterate through an unmasked lattice.
38 
39 template <class T> class LatticeStatsDataProvider
40  : public LatticeStatsDataProviderBase<T> {
41 
42 public:
43 
44  // default constructor, must set lattice after construction but before
45  // using the object
47 
48  // <src>iteratorLimitBytes</src> is related to the size of the lattice.
49  // If the lattice is greater than this size, then a lattice iterator will
50  // be used to step through the lattice. If less, then all the data in the
51  // values in the lattice are retrieved in a single chunk. The advantage of
52  // the iterator is that less memory is used. The disadvantage is there is
53  // a significant performace cost, so if the lattice is small, it is better to
54  // get all its values in a single chunk and forgo the iterator. This is particularly
55  // true when looping for a large number of iterations and creating a
56  // LatticeStatsDataProvider each loop (in that case, you probably will want
57  // to create a single object before the loop and use setLattice() to update
58  // its lattice).
60  const Lattice<T>& lattice, uInt iteratorLimitBytes=4096*4096
61  );
62 
64 
65  void operator++();
66 
67  // estimated number of steps to iterate through the the lattice
68  uInt estimatedSteps() const;
69 
70  // Are there any data sets left to provide?
71  Bool atEnd() const;
72 
73  // Take any actions necessary to finalize the provider. This will be called when
74  // atEnd() returns True.
75  void finalize();
76 
77  // get the count of elements in the current data set. When implementing this method, be
78  // certain to take stride into account; ie for a data set with nominally 100 elements that
79  // is to have a stride of two, this method should return 50.
80  uInt64 getCount();
81 
82  // get the current data set
83  const T* getData();
84 
85  // Get the associated mask of the current dataset. Only called if hasMask() returns True;
86  const Bool* getMask();
87 
88  // Does the current data set have an associated mask?
89  Bool hasMask() const;
90 
91  // reset the provider to point to the first data set it manages.
92  void reset();
93 
94  // set the lattice. Automatically resets the lattice iterator
95  // <src>iteratorLimitBytes</src> is related to the size of the lattice.
96  // If the lattice is greater than this size, then a lattice iterator will
97  // be used to step through the lattice. If less, then all the data in the
98  // values in the lattice are retrieved in a single chunk. The advantage of
99  // the iterator is that less memory is used. The disadvantage is there is
100  // a significant performace cost, so if the lattice is small, it is better to
101  // get all its values in a single chunk and forgo the iterator. This is particularly
102  // true when looping for a large number of iterations and creating a
103  // LatticeStatsDataProvider each loop (in that case, you probably will want
104  // to create a single object before the loop and use setLattice() to update
105  // its lattice).
106  void setLattice(
107  const Lattice<T>& lattice, uInt iteratorLimitBytes=4096*4096
108  );
109 
110  // <group>
111  // see base class documentation.
112  void updateMaxPos(const std::pair<Int64, Int64>& maxpos);
113 
114  void updateMinPos(const std::pair<Int64, Int64>& minpos);
115  // </group>
116 
117 private:
120  const T* _currentPtr;
122 
123  void _freeStorage();
124 
125 };
126 
127 }
128 
129 #ifndef CASACORE_NO_AUTO_TEMPLATES
130 #include <casacore/lattices/LatticeMath/LatticeStatsDataProvider.tcc>
131 #endif //# CASACORE_NO_AUTO_TEMPLATES
132 
133 #endif
void reset()
reset the provider to point to the first data set it manages.
unsigned long long uInt64
Definition: aipsxtype.h:39
void operator++()
increment the data provider to the next dataset, mask, range set, and weights.
void setLattice(const Lattice< T > &lattice, uInt iteratorLimitBytes=4096 *4096)
set the lattice.
Data provider which allows stats framework to iterate through an unmasked lattice.
uInt64 getCount()
get the count of elements in the current data set.
CountedPtr< RO_LatticeIterator< T > > _iter
A templated, abstract base class for array-like objects.
Definition: Functional.h:37
Referenced counted pointer for constant data.
Definition: CountedPtr.h:86
Abstract base class of data providers which allows stats framework to iterate through a lattice...
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void updateMaxPos(const std::pair< Int64, Int64 > &maxpos)
see base class documentation.
Bool atEnd() const
Are there any data sets left to provide?
const T * getData()
get the current data set
template <class T, class U> class vector;
Definition: Array.h:169
void updateMinPos(const std::pair< Int64, Int64 > &minpos)
uInt estimatedSteps() const
estimated number of steps to iterate through the the lattice
void finalize()
Take any actions necessary to finalize the provider.
const Bool * getMask()
Get the associated mask of the current dataset.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
LatticeStatsDataProvider()
default constructor, must set lattice after construction but before using the object ...
Bool hasMask() const
Does the current data set have an associated mask?