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
27#ifndef TABLES_TABLEEXPRIDAGGR_H
28#define TABLES_TABLEEXPRIDAGGR_H
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/TaQL/TableExprId.h>
33#include <casacore/tables/TaQL/ExprGroup.h>
34#include <casacore/casa/Utilities/Assert.h>
35#include <casacore/casa/Exceptions/Error.h>
36#include <memory>
37
38namespace casacore { //# NAMESPACE CASACORE - BEGIN
39
40 // <summary>
41 // The Table Expression Selection id used with aggregation
42 // </summary>
43
44 // <use visibility=export>
45
46 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tExprGroup">
47 // </reviewed>
48
49 // <synopsis>
50 // This class provides the user the ability to identify the data objects
51 // to test in a TaQL expression using aggregate functions.
52 // <br>
53 // It adds a TableExprGroupResult object to the TableExprId class which
54 // is used by the various classes derived from TableExprGroupFuncBase
55 // to get or evaluate the aggregated value.
56 // An aggregated value can be determined in two ways:
57 // <ul>
58 // <li> An immediate aggregate function has calculated its value in its
59 // <src>apply</src> function.
60 // Each group has a TableExprGroupFuncSet containing the values
61 // of all immediate aggregate functions of that group.
62 // A vector of these objects is part of of TableExprGroupResult
63 // and is used by the TableExprAggrNode(Array) <src>get</src> functions
64 // to return the correct value.
65 // <li> A lazy aggregate function calculates the value as part of its
66 // <src>get</src> function. It uses the vector of TableExprId objects
67 // in TableExprGroupResult to know which rows (or records) belong to
68 // which group. Note that UDF aggregate functions are always lazy.
69 // </ul>
70 // TableExprIdAggr contains a static function to (statically) cast a
71 // TableExprId object to TableExprIdAggr. A magic value is used to check
72 // that the cast is valid.
73 // <br>No dynamic_cast is used, because it requires TableExprId to contain
74 // virtual functions making the object larger. TaQL can hold quite large
75 // vectors of TableExprId objects, so such overhead is unacceptably large.
76 // </synopsis>
77
78 // <motivation>
79 // This class makes it possible to retrieve aggregated values using the
80 // standard <src>get</src> functions taking an TableExprId.
81 // </motivation>
82
84 {
85 public:
86 // Construct it from the aggregation results.
87 explicit TableExprIdAggr (const std::shared_ptr<TableExprGroupResult>& result)
88 : itsMagicValue (0xabababab),
90 {}
91
92 // Get out the aggregation result object.
94 { return *itsResult; }
95
96 // Get the magic value (to check if correct).
98 { return itsMagicValue; }
99
100 // Cast a TableExprId object to TableExprIdAggr. It checks if the cast
101 // is correct by checking the magic value.
102 static const TableExprIdAggr& cast (const TableExprId& id)
103 {
104 const TableExprIdAggr& idAggr = reinterpret_cast<const TableExprIdAggr&>(id);
105 AlwaysAssert (idAggr.getMagicValue() == 0xabababab, AipsError);
106 return idAggr;
107 }
108
109 private:
111 std::shared_ptr<TableExprGroupResult> itsResult;
112 };
113
114
115} //# NAMESPACE CASACORE - END
116
117#endif
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the constructors of assert_ to allow additi...
Definition Assert.h:155
Class holding the results of groupby and aggregation.
Definition ExprGroup.h:143
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.
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49