casacore
Loading...
Searching...
No Matches
TableExprIdAggr.h
Go to the documentation of this file.
1// # TableExprIdAggr.h: The Table Expression Selection id used with aggregation
2// # Copyright (C) 2013
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef TABLES_TABLEEXPRIDAGGR_H
27#define TABLES_TABLEEXPRIDAGGR_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/TaQL/TableExprId.h>
32#include <casacore/tables/TaQL/ExprGroup.h>
33#include <casacore/casa/Utilities/Assert.h>
34#include <casacore/casa/Exceptions/Error.h>
35#include <memory>
36
37namespace casacore { // # NAMESPACE CASACORE - BEGIN
38
39// <summary>
40// The Table Expression Selection id used with aggregation
41// </summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tExprGroup">
46// </reviewed>
47
48// <synopsis>
49// This class provides the user the ability to identify the data objects
50// to test in a TaQL expression using aggregate functions.
51// <br>
52// It adds a TableExprGroupResult object to the TableExprId class which
53// is used by the various classes derived from TableExprGroupFuncBase
54// to get or evaluate the aggregated value.
55// An aggregated value can be determined in two ways:
56// <ul>
57// <li> An immediate aggregate function has calculated its value in its
58// <src>apply</src> function.
59// Each group has a TableExprGroupFuncSet containing the values
60// of all immediate aggregate functions of that group.
61// A vector of these objects is part of of TableExprGroupResult
62// and is used by the TableExprAggrNode(Array) <src>get</src> functions
63// to return the correct value.
64// <li> A lazy aggregate function calculates the value as part of its
65// <src>get</src> function. It uses the vector of TableExprId objects
66// in TableExprGroupResult to know which rows (or records) belong to
67// which group. Note that UDF aggregate functions are always lazy.
68// </ul>
69// TableExprIdAggr contains a static function to (statically) cast a
70// TableExprId object to TableExprIdAggr. A magic value is used to check
71// that the cast is valid.
72// <br>No dynamic_cast is used, because it requires TableExprId to contain
73// virtual functions making the object larger. TaQL can hold quite large
74// vectors of TableExprId objects, so such overhead is unacceptably large.
75// </synopsis>
76
77// <motivation>
78// This class makes it possible to retrieve aggregated values using the
79// standard <src>get</src> functions taking an TableExprId.
80// </motivation>
81
83 public:
84 // Construct it from the aggregation results.
85 explicit TableExprIdAggr(const std::shared_ptr<TableExprGroupResult>& result)
86 : itsMagicValue(0xabababab), itsResult(result) {}
87
88 // Get out the aggregation result object.
89 const TableExprGroupResult& result() const { return *itsResult; }
90
91 // Get the magic value (to check if correct).
92 uInt getMagicValue() const { return itsMagicValue; }
93
94 // Cast a TableExprId object to TableExprIdAggr. It checks if the cast
95 // is correct by checking the magic value.
96 static const TableExprIdAggr& cast(const TableExprId& id) {
97 const TableExprIdAggr& idAggr = reinterpret_cast<const TableExprIdAggr&>(id);
98 AlwaysAssert(idAggr.getMagicValue() == 0xabababab, AipsError);
99 return idAggr;
100 }
101
102 private:
104 std::shared_ptr<TableExprGroupResult> itsResult;
105};
106
107} // namespace casacore
108
109#endif
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the assert_ function directly.
Definition Assert.h:133
Class holding the results of groupby and aggregation.
Definition ExprGroup.h:129
std::shared_ptr< TableExprGroupResult > itsResult
TableExprIdAggr(const std::shared_ptr< TableExprGroupResult > &result)
Construct it from the aggregation results.
static const TableExprIdAggr & cast(const TableExprId &id)
Cast a TableExprId object to TableExprIdAggr.
uInt getMagicValue() const
Get the magic value (to check if correct).
const TableExprGroupResult & result() const
Get out the aggregation result object.
TableExprId()
Default constructor sets rownr to -1.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49