TableExprIdAggr.h

Go to the documentation of this file.
00001 //# TableExprIdAggr.h: The Table Expression Selection id used with aggregation
00002 //# Copyright (C) 2013
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: TableExprId.h 21403 2013-12-03 20:51:02Z gervandiepen $
00028 
00029 
00030 #ifndef TABLES_TABLEEXPRIDAGGR_H
00031 #define TABLES_TABLEEXPRIDAGGR_H
00032 
00033 //# Includes
00034 #include <casacore/casa/aips.h>
00035 #include <casacore/tables/TaQL/TableExprId.h>
00036 #include <casacore/tables/TaQL/ExprGroup.h>
00037 #include <casacore/casa/Utilities/CountedPtr.h>
00038 #include <casacore/casa/Utilities/Assert.h>
00039 #include <casacore/casa/Exceptions/Error.h>
00040 #include <casacore/casa/stdvector.h>
00041 
00042 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00043 
00044   // <summary>
00045   // The Table Expression Selection id used with aggregation
00046   // </summary>
00047 
00048   // <use visibility=export>
00049 
00050   // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tExprGroup">
00051   // </reviewed>
00052 
00053   // <synopsis>
00054   // This class provides the user the ability to identify the data objects
00055   // to test in a TaQL expression using aggregate functions.
00056   // <br>
00057   // It adds a TableExprGroupResult object to the TableExprId class which
00058   // is used by the various classes derived from TableExprGroupFuncBase
00059   // to get or evaluate the aggregated value.
00060   // An aggregated value can be determined in two ways:
00061   // <ul>
00062   //  <li> An immediate aggregate function has calculated its value in its
00063   //       <src>apply</src> function.
00064   //       Each group has a TableExprGroupFuncSet containing the values
00065   //       of all immediate aggregate functions of that group.
00066   //       A vector of these objects is part of of TableExprGroupResult
00067   //       and is used by the TableExprAggrNode(Array) <src>get</src> functions
00068   //       to return the correct value.
00069   //  <li> A lazy aggregate function calculates the value as part of its
00070   //       <src>get</src> function. It uses the vector of TableExprId objects
00071   //       in TableExprGroupResult to know which rows (or records) belong to
00072   //       which group. Note that UDF aggregate functions are always lazy.
00073   // </ul>
00074   // TableExprIdAggr contains a static function to (statically) cast a
00075   // TableExprId object to TableExprIdAggr. A magic value is used to check
00076   // that the cast is valid.
00077   // <br>No dynamic_cast is used, because it requires TableExprId to contain
00078   // virtual functions making the object larger. TaQL can hold quite large
00079   // vectors of TableExprId objects, so such overhead is unacceptably large.
00080   // </synopsis>
00081 
00082   // <motivation>
00083   // This class makes it possible to retrieve aggregated values using the
00084   // standard <src>get</src> functions taking an TableExprId.
00085   // </motivation>
00086 
00087   class TableExprIdAggr: public TableExprId
00088   {
00089   public:
00090     // Construct it from the aggregation results.
00091     explicit TableExprIdAggr (const CountedPtr<TableExprGroupResult>& result)
00092       : itsMagicValue (0xabababab),
00093         itsResult     (result)
00094     {}
00095 
00096     // Get out the aggregation result object.
00097     const TableExprGroupResult& result() const
00098       { return *itsResult; }
00099 
00100     // Get the magic value (to check if it correct).
00101     uInt getMagicValue() const
00102       { return itsMagicValue; }
00103 
00104     // Cast a TableExprId object to TableExprIdAggr. It check if the cast
00105     // if correct by checking the magic value.
00106     static const TableExprIdAggr& cast (const TableExprId& id)
00107     {
00108       const TableExprIdAggr& idAggr = reinterpret_cast<const TableExprIdAggr&>(id);
00109       AlwaysAssert (idAggr.getMagicValue() == 0xabababab, AipsError);
00110       return idAggr;
00111     }
00112 
00113   private:
00114     uInt itsMagicValue;
00115     CountedPtr<TableExprGroupResult> itsResult;
00116   };
00117 
00118 
00119 } //# NAMESPACE CASACORE - END
00120 
00121 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1