casacore
Loading...
Searching...
No Matches
StatisticsDataset.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: casa-feedback@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
26#ifndef SCIMATH_STATISTICSDATASET_H
27#define SCIMATH_STATISTICSDATASET_H
28
29#include <casacore/casa/aips.h>
30
31#include <casacore/scimath/StatsFramework/StatisticsTypes.h>
32
33namespace casacore {
34
35// Representation of a statistics dataset used in statistics framework
36// calculatations.
37//
38// This class is used internally by StatisticsAlgorithm and its derived classes.
39// There should be no need for an API developer to make direct use of this
40// class. It encapsulates the data-related portions of StatisticsAlgorithm and
41// derived classes. To add and set data or to set a data provider, one should
42// call the relevant methods in StatisticsAlgorithm which have been left
43// unchanged for the convenience of the API developer. Those methods call the
44// analogous methods in this class (and the methods in StatisticsAlgorithm also
45// do necessary bookkeeping for the StatisticsAlgorithm and derived objects).
46
47template <class AccumType, class DataIterator, class MaskIterator = const Bool*,
48 class WeightsIterator = DataIterator>
50 public:
51 // holds information about a data chunk. A data chunk is either an
52 // individual underlying dataset (if no data provider), or a chunk of data
53 // served by the data provider if it exists.
54 struct ChunkData {
55 // start of data
56 DataIterator data;
57 // total number of points
59 // data stride
61 // associated ranges. If nullptr, then there are none. If not, the
62 // second member of the pair indicates if they are include ranges.
63 std::unique_ptr<std::pair<DataRanges, Bool>> ranges;
64 // associated mask. If nullptr, then there is no mask.
65 // If there is a mask, the second member is the mask stride.
66 std::unique_ptr<std::pair<MaskIterator, uInt>> mask;
67 // associated weights. If nullptr, then there are no weights.
68 std::unique_ptr<WeightsIterator> weights;
69 };
70
72
74
76
77 // use copy semantics, except for the data provider which uses reference
78 // semantics
80
81 // <group>
82 // Add a dataset to an existing set of datasets on which statistics are to
83 // be calculated. nr is the number of points to be considered. If
84 // <src>dataStride</src> is greater than 1, when
85 // <src>nrAccountsForStride</src>=True indicates that the stride has been
86 // taken into account in the value of <src>nr</src>. Otherwise, it has not
87 // so that the actual number of points to include is nr/dataStride if
88 // nr % dataStride == 0 or (int)(nr/dataStride) + 1 otherwise. If one calls
89 // this method after a data provider has been set, an exception will be
90 // thrown. In this case, one should call setData(), rather than addData(),
91 // to indicate that the underlying data provider should be removed.
92 // <src>dataRanges</src> provide the ranges of data to include if
93 // <src>isInclude</src> is True, or ranges of data to exclude if
94 // <src>isInclude</src> is False. If a datum equals the end point of a data
95 // range, it is considered good (included) if <src>isInclude</src> is True,
96 // and it is considered bad (excluded) if <src>isInclude</src> is False.
97
98 void addData(const DataIterator& first, uInt nr, uInt dataStride = 1,
99 Bool nrAccountsForStride = False);
100
101 void addData(const DataIterator& first, uInt nr, const DataRanges& dataRanges,
102 Bool isInclude = True, uInt dataStride = 1, Bool nrAccountsForStride = False);
103
104 void addData(const DataIterator& first, const MaskIterator& maskFirst, uInt nr,
105 uInt dataStride = 1, Bool nrAccountsForStride = False, uInt maskStride = 1);
106
107 void addData(const DataIterator& first, const MaskIterator& maskFirst, uInt nr,
108 const DataRanges& dataRanges, Bool isInclude = True, uInt dataStride = 1,
109 Bool nrAccountsForStride = False, uInt maskStride = 1);
110
111 void addData(const DataIterator& first, const WeightsIterator& weightFirst, uInt nr,
112 uInt dataStride = 1, Bool nrAccountsForStride = False);
113
114 void addData(const DataIterator& first, const WeightsIterator& weightFirst, uInt nr,
115 const DataRanges& dataRanges, Bool isInclude = True, uInt dataStride = 1,
116 Bool nrAccountsForStride = False);
117
118 void addData(const DataIterator& first, const WeightsIterator& weightFirst,
119 const MaskIterator& maskFirst, uInt nr, uInt dataStride = 1,
120 Bool nrAccountsForStride = False, uInt maskStride = 1);
121
122 void addData(const DataIterator& first, const WeightsIterator& weightFirst,
123 const MaskIterator& maskFirst, uInt nr, const DataRanges& dataRanges,
124 Bool isInclude = True, uInt dataStride = 1, Bool nrAccountsForStride = False,
125 uInt maskStride = 1);
126 // </group>
127
128 // returns ! dataProvider && _data.empty()
129 Bool empty() const;
130
131 // get data counts associated with the underlying data sets
132 const std::vector<Int64>& getCounts() const { return _counts; }
133
135
137
138 Int64 iDataset() const { return _idataset; }
139
140 Bool increment(Bool includeIDataset);
141
142 void incrementThreadIters(DataIterator& dataIter, MaskIterator& maskIter,
143 WeightsIterator& weightsIter, uInt64& offset, uInt nthreads) const;
144
146
147 // used for threaded methods
148 void initLoopVars(uInt64& chunkCount, uInt& chunkStride, Bool& chunkHasRanges,
149 DataRanges& chunkRanges, Bool& chunkIsIncludeRanges, Bool& chunkHasMask,
150 uInt& chunkMaskStride, Bool& chunkHasWeights);
151
152 // used for unthreaded methods
153 void initLoopVars(DataIterator& chunkData, uInt64& chunkCount, uInt& chunkStride,
154 Bool& chunkHasRanges, DataRanges& chunkRanges, Bool& chunkIsIncludeRanges,
155 Bool& chunkHasMask, MaskIterator& chunkMask, uInt& chunkMaskStride,
156 Bool& chunkHasWeights, WeightsIterator& chunkWeights);
157
159
160 void initThreadVars(uInt& nBlocks, uInt64& extra, uInt& nthreads,
161 std::unique_ptr<DataIterator[]>& dataIter,
162 std::unique_ptr<MaskIterator[]>& maskIter,
163 std::unique_ptr<WeightsIterator[]>& weightsIter,
164 std::unique_ptr<uInt64[]>& offset, uInt nThreadsMax) const;
165
166 void reset();
167
168 void resetIDataset() { _idataset = 0; }
169
170 // <group>
171 // setdata() clears any current datasets or data provider and then adds the
172 // specified data set as the first dataset in the (possibly new) set of data
173 // sets for which statistics are to be calculated. See addData() for
174 // parameter meanings.
175 void setData(const DataIterator& first, uInt nr, uInt dataStride = 1,
176 Bool nrAccountsForStride = False);
177
178 void setData(const DataIterator& first, uInt nr, const DataRanges& dataRanges,
179 Bool isInclude = True, uInt dataStride = 1, Bool nrAccountsForStride = False);
180
181 void setData(const DataIterator& first, const MaskIterator& maskFirst, uInt nr,
182 uInt dataStride = 1, Bool nrAccountsForStride = False, uInt maskStride = 1);
183
184 void setData(const DataIterator& first, const MaskIterator& maskFirst, uInt nr,
185 const DataRanges& dataRanges, Bool isInclude = True, uInt dataStride = 1,
186 Bool nrAccountsForStride = False, uInt maskStride = 1);
187
188 void setData(const DataIterator& first, const WeightsIterator& weightFirst, uInt nr,
189 uInt dataStride = 1, Bool nrAccountsForStride = False);
190
191 void setData(const DataIterator& first, const WeightsIterator& weightFirst, uInt nr,
192 const DataRanges& dataRanges, Bool isInclude = True, uInt dataStride = 1,
193 Bool nrAccountsForStride = False);
194
195 void setData(const DataIterator& first, const WeightsIterator& weightFirst,
196 const MaskIterator& maskFirst, uInt nr, uInt dataStride = 1,
197 Bool nrAccountsForStride = False, uInt maskStride = 1);
198
199 void setData(const DataIterator& first, const WeightsIterator& weightFirst,
200 const MaskIterator& maskFirst, uInt nr, const DataRanges& dataRanges,
201 Bool isInclude = True, uInt dataStride = 1, Bool nrAccountsForStride = False,
202 uInt maskStride = 1);
203 // </group>
204
205 // instead of setting and adding data "by hand", set the data provider that
206 // will provide all the data sets. Calling this method will clear any other
207 // data sets that have previously been set or added.
209
210 private:
211 std::vector<DataIterator> _data{};
212 // maps data to weights. maps are used rather than vectors because only some
213 // (or none) of the data sets in the _data vector may have associated
214 // weights, masks, and/or ranges.
215 std::map<uInt, WeightsIterator> _weights{};
216 // maps data to masks
217 std::map<uInt, MaskIterator> _masks{};
218 std::vector<Int64> _counts{};
219 std::vector<uInt> _dataStrides{};
220 std::map<uInt, uInt> _maskStrides{};
221 std::map<uInt, Bool> _isIncludeRanges{};
222 std::map<uInt, DataRanges> _dataRanges{};
224
226 typename std::vector<DataIterator>::const_iterator _dend{}, _diter{};
227 std::vector<Int64>::const_iterator _citer{};
228 std::vector<uInt>::const_iterator _dsiter{};
231
233};
234
235} // namespace casacore
236
237#ifndef CASACORE_NO_AUTO_TEMPLATES
238#include <casacore/scimath/StatsFramework/StatisticsDataset.tcc>
239#endif
240
241#endif
#define DataRanges
void initLoopVars(uInt64 &chunkCount, uInt &chunkStride, Bool &chunkHasRanges, DataRanges &chunkRanges, Bool &chunkIsIncludeRanges, Bool &chunkHasMask, uInt &chunkMaskStride, Bool &chunkHasWeights)
used for threaded methods
void addData(const DataIterator &first, uInt nr, const DataRanges &dataRanges, Bool isInclude=True, uInt dataStride=1, Bool nrAccountsForStride=False)
void setDataProvider(StatsDataProvider< CASA_STATP > *dataProvider)
instead of setting and adding data "by hand", set the data provider that will provide all the data se...
void addData(const DataIterator &first, const WeightsIterator &weightFirst, const MaskIterator &maskFirst, uInt nr, uInt dataStride=1, Bool nrAccountsForStride=False, uInt maskStride=1)
std::vector< uInt >::const_iterator _dsiter
void setData(const DataIterator &first, const MaskIterator &maskFirst, uInt nr, const DataRanges &dataRanges, Bool isInclude=True, uInt dataStride=1, Bool nrAccountsForStride=False, uInt maskStride=1)
void addData(const DataIterator &first, const WeightsIterator &weightFirst, uInt nr, const DataRanges &dataRanges, Bool isInclude=True, uInt dataStride=1, Bool nrAccountsForStride=False)
void setData(const DataIterator &first, const WeightsIterator &weightFirst, const MaskIterator &maskFirst, uInt nr, const DataRanges &dataRanges, Bool isInclude=True, uInt dataStride=1, Bool nrAccountsForStride=False, uInt maskStride=1)
const ChunkData & initLoopVars()
void addData(const DataIterator &first, const MaskIterator &maskFirst, uInt nr, uInt dataStride=1, Bool nrAccountsForStride=False, uInt maskStride=1)
void setData(const DataIterator &first, const WeightsIterator &weightFirst, uInt nr, uInt dataStride=1, Bool nrAccountsForStride=False)
std::map< uInt, Bool > _isIncludeRanges
StatisticsDataset< CASA_STATP > & operator=(const StatisticsDataset< CASA_STATP > &other)
use copy semantics, except for the data provider which uses reference semantics
std::vector< DataIterator > _data
StatsDataProvider< CASA_STATP > * getDataProvider()
void setData(const DataIterator &first, const MaskIterator &maskFirst, uInt nr, uInt dataStride=1, Bool nrAccountsForStride=False, uInt maskStride=1)
std::vector< DataIterator >::const_iterator _dend
std::vector< Int64 >::const_iterator _citer
std::map< uInt, uInt > _maskStrides
std::vector< uInt > _dataStrides
void incrementThreadIters(DataIterator &dataIter, MaskIterator &maskIter, WeightsIterator &weightsIter, uInt64 &offset, uInt nthreads) const
Bool increment(Bool includeIDataset)
Bool empty() const
returns !
std::map< uInt, DataRanges > _dataRanges
void addData(const DataIterator &first, const MaskIterator &maskFirst, uInt nr, const DataRanges &dataRanges, Bool isInclude=True, uInt dataStride=1, Bool nrAccountsForStride=False, uInt maskStride=1)
void addData(const DataIterator &first, const WeightsIterator &weightFirst, uInt nr, uInt dataStride=1, Bool nrAccountsForStride=False)
std::map< uInt, MaskIterator > _masks
maps data to masks
void setData(const DataIterator &first, const WeightsIterator &weightFirst, const MaskIterator &maskFirst, uInt nr, uInt dataStride=1, Bool nrAccountsForStride=False, uInt maskStride=1)
void initLoopVars(DataIterator &chunkData, uInt64 &chunkCount, uInt &chunkStride, Bool &chunkHasRanges, DataRanges &chunkRanges, Bool &chunkIsIncludeRanges, Bool &chunkHasMask, MaskIterator &chunkMask, uInt &chunkMaskStride, Bool &chunkHasWeights, WeightsIterator &chunkWeights)
used for unthreaded methods
const std::vector< Int64 > & getCounts() const
get data counts associated with the underlying data sets
void initThreadVars(uInt &nBlocks, uInt64 &extra, uInt &nthreads, std::unique_ptr< DataIterator[]> &dataIter, std::unique_ptr< MaskIterator[]> &maskIter, std::unique_ptr< WeightsIterator[]> &weightsIter, std::unique_ptr< uInt64[]> &offset, uInt nThreadsMax) const
StatsDataProvider< CASA_STATP > * _dataProvider
const StatsDataProvider< CASA_STATP > * getDataProvider() const
void setData(const DataIterator &first, uInt nr, const DataRanges &dataRanges, Bool isInclude=True, uInt dataStride=1, Bool nrAccountsForStride=False)
void _throwIfDataProviderDefined() const
void setData(const DataIterator &first, uInt nr, uInt dataStride=1, Bool nrAccountsForStride=False)
setdata() clears any current datasets or data provider and then adds the specified data set as the fi...
void addData(const DataIterator &first, const WeightsIterator &weightFirst, const MaskIterator &maskFirst, uInt nr, const DataRanges &dataRanges, Bool isInclude=True, uInt dataStride=1, Bool nrAccountsForStride=False, uInt maskStride=1)
std::vector< DataIterator >::const_iterator _diter
std::map< uInt, WeightsIterator > _weights
maps data to weights.
StatisticsDataset(const StatisticsDataset &other)
void setData(const DataIterator &first, const WeightsIterator &weightFirst, uInt nr, const DataRanges &dataRanges, Bool isInclude=True, uInt dataStride=1, Bool nrAccountsForStride=False)
void addData(const DataIterator &first, uInt nr, uInt dataStride=1, Bool nrAccountsForStride=False)
Add a dataset to an existing set of datasets on which statistics are to be calculated.
Abstract base class which defines interface for providing "datasets" to the statistics framework in c...
struct Node * first
Definition malloc.h:325
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
int offset(int, int) const
compute a linear offset from array indicies
unsigned int uInt
Definition aipstype.h:49
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
unsigned long long uInt64
Definition aipsxtype.h:37
holds information about a data chunk.
std::unique_ptr< std::pair< DataRanges, Bool > > ranges
associated ranges.
std::unique_ptr< WeightsIterator > weights
associated weights.
std::unique_ptr< std::pair< MaskIterator, uInt > > mask
associated mask.
uInt64 count
total number of points