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
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.
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  // returns something reasonable based on the lattice size.
90 
91  // Does the current data set have an associated mask?
92  Bool hasMask() const;
93 
94  // reset the provider to point to the first data set it manages.
95  void reset();
96 
97  // set the lattice. Automatically resets the lattice iterator
98  // <src>iteratorLimitBytes</src> is related to the size of the lattice.
99  // If the lattice is greater than this size, then a lattice iterator will
100  // be used to step through the lattice. If less, then all the data in the
101  // values in the lattice are retrieved in a single chunk. The advantage of
102  // the iterator is that less memory is used. The disadvantage is there is
103  // a significant performace cost, so if the lattice is small, it is better to
104  // get all its values in a single chunk and forgo the iterator. This is particularly
105  // true when looping for a large number of iterations and creating a
106  // LatticeStatsDataProvider each loop (in that case, you probably will want
107  // to create a single object before the loop and use setLattice() to update
108  // its lattice).
110  const Lattice<T>& lattice, uInt iteratorLimitBytes=4096*4096
111  );
112 
113  // <group>
114  // see base class documentation.
115  void updateMaxPos(const std::pair<Int64, Int64>& maxpos);
116 
117  void updateMinPos(const std::pair<Int64, Int64>& minpos);
118  // </group>
119 
120 private:
123  const T* _currentPtr;
126 
127  void _freeStorage();
128 
129 };
130 
131 }
132 
133 #ifndef CASACORE_NO_AUTO_TEMPLATES
134 #include <casacore/lattices/LatticeMath/LatticeStatsDataProvider.tcc>
135 #endif //# CASACORE_NO_AUTO_TEMPLATES
136 
137 #endif
Referenced counted pointer for constant data.
Definition: CountedPtr.h:81
Abstract base class of data providers which allows stats framework to iterate through a lattice.
Data provider which allows stats framework to iterate through an unmasked lattice.
void reset()
reset the provider to point to the first data set it manages.
const Bool * getMask()
Get the associated mask of the current dataset.
Bool hasMask() const
Does the current data set have an associated mask?
void updateMinPos(const std::pair< Int64, Int64 > &minpos)
CountedPtr< RO_LatticeIterator< T > > _iter
void operator++()
increment the data provider to the next dataset, mask, range set, and weights.
LatticeStatsDataProvider()
default constructor, must set lattice after construction but before using the object
Bool atEnd() const
Are there any data sets left to provide?
LatticeStatsDataProvider(const Lattice< T > &lattice, uInt iteratorLimitBytes=4096 *4096)
iteratorLimitBytes is related to the size of the lattice.
const T * getData()
get the current data set
uInt64 getCount()
get the count of elements in the current data set.
uInt getNMaxThreads() const
returns something reasonable based on the lattice size.
void updateMaxPos(const std::pair< Int64, Int64 > &maxpos)
see base class documentation.
void finalize()
Take any actions necessary to finalize the provider.
void setLattice(const Lattice< T > &lattice, uInt iteratorLimitBytes=4096 *4096)
set the lattice.
uInt estimatedSteps() const
estimated number of steps to iterate through the the lattice
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
unsigned long long uInt64
Definition: aipsxtype.h:39