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