casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@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 //# $Id: TableExprId.h 21403 2013-12-03 20:51:02Z gervandiepen $
28 
29 
30 #ifndef TABLES_TABLEEXPRIDAGGR_H
31 #define TABLES_TABLEEXPRIDAGGR_H
32 
33 //# Includes
34 #include <casacore/casa/aips.h>
40 
41 namespace casacore { //# NAMESPACE CASACORE - BEGIN
42 
43  // <summary>
44  // The Table Expression Selection id used with aggregation
45  // </summary>
46 
47  // <use visibility=export>
48 
49  // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tExprGroup">
50  // </reviewed>
51 
52  // <synopsis>
53  // This class provides the user the ability to identify the data objects
54  // to test in a TaQL expression using aggregate functions.
55  // <br>
56  // It adds a TableExprGroupResult object to the TableExprId class which
57  // is used by the various classes derived from TableExprGroupFuncBase
58  // to get or evaluate the aggregated value.
59  // An aggregated value can be determined in two ways:
60  // <ul>
61  // <li> An immediate aggregate function has calculated its value in its
62  // <src>apply</src> function.
63  // Each group has a TableExprGroupFuncSet containing the values
64  // of all immediate aggregate functions of that group.
65  // A vector of these objects is part of of TableExprGroupResult
66  // and is used by the TableExprAggrNode(Array) <src>get</src> functions
67  // to return the correct value.
68  // <li> A lazy aggregate function calculates the value as part of its
69  // <src>get</src> function. It uses the vector of TableExprId objects
70  // in TableExprGroupResult to know which rows (or records) belong to
71  // which group. Note that UDF aggregate functions are always lazy.
72  // </ul>
73  // TableExprIdAggr contains a static function to (statically) cast a
74  // TableExprId object to TableExprIdAggr. A magic value is used to check
75  // that the cast is valid.
76  // <br>No dynamic_cast is used, because it requires TableExprId to contain
77  // virtual functions making the object larger. TaQL can hold quite large
78  // vectors of TableExprId objects, so such overhead is unacceptably large.
79  // </synopsis>
80 
81  // <motivation>
82  // This class makes it possible to retrieve aggregated values using the
83  // standard <src>get</src> functions taking an TableExprId.
84  // </motivation>
85 
87  {
88  public:
89  // Construct it from the aggregation results.
91  : itsMagicValue (0xabababab),
92  itsResult (result)
93  {}
94 
95  // Get out the aggregation result object.
97  { return *itsResult; }
98 
99  // Get the magic value (to check if correct).
101  { return itsMagicValue; }
102 
103  // Cast a TableExprId object to TableExprIdAggr. It checks if the cast
104  // is correct by checking the magic value.
105  static const TableExprIdAggr& cast (const TableExprId& id)
106  {
107  const TableExprIdAggr& idAggr = reinterpret_cast<const TableExprIdAggr&>(id);
108  AlwaysAssert (idAggr.getMagicValue() == 0xabababab, AipsError);
109  return idAggr;
110  }
111 
112  private:
115  };
116 
117 
118 } //# NAMESPACE CASACORE - END
119 
120 #endif
Class holding the results of groupby and aggregation.
Definition: ExprGroup.h:144
uInt getMagicValue() const
Get the magic value (to check if correct).
TableExprIdAggr(const CountedPtr< TableExprGroupResult > &result)
Construct it from the aggregation results.
const TableExprGroupResult & result() const
Get out the aggregation result object.
Referenced counted pointer for constant data.
Definition: CountedPtr.h:80
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the constructors of assert_ to allow additi...
Definition: Assert.h:157
The Table Expression Selection id used with aggregation.
The identification of a TaQL selection subject.
Definition: TableExprId.h:97
Base class for all Casacore library errors.
Definition: Error.h:134
CountedPtr< TableExprGroupResult > itsResult
static const TableExprIdAggr & cast(const TableExprId &id)
Cast a TableExprId object to TableExprIdAggr.
unsigned int uInt
Definition: aipstype.h:51