OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
agg_util::AggregationUtil Class Reference

A static class for encapsulating the aggregation functionality on libdap. More...

#include <AggregationUtil.h>

Collaboration diagram for agg_util::AggregationUtil:
Collaboration graph

Public Types

typedef std::vector< const libdap::DDS * > ConstDDSList
 

Public Member Functions

template<class LibdapType >
LibdapType * findTypedVariableAtDDSTopLevel (const libdap::DDS &dds, const string &name)
 

Static Public Member Functions

static bool addCopyOfVariableIfNameIsAvailable (libdap::DDS *pOutDDS, const libdap::BaseType &varProto, bool add_at_top=false)
 If a variable does not exist within pOutDDS (top level) with the same name as varProto, then place a clone of varProto (using virtual ctor ptr_duplicate) into pOutDDS. More...
 
static void addDatasetArrayDataToAggregationOutputArray (libdap::Array &oOutputArray, unsigned int atIndex, const libdap::Array &constrainedTemplateArray, const string &varName, AggMemberDataset &dataset, const ArrayGetterInterface &arrayGetter, const string &debugChannel)
 Load the given dataset's DataDDS. More...
 
static void addOrReplaceVariableForName (libdap::DDS *pOutDDS, const libdap::BaseType &varProto)
 If a variable with the name varProto.name() doesn't exist, add a copy of varProto to pOutDDS. More...
 
static unsigned int collectVariableArraysInOrder (std::vector< libdap::Array * > &varArrays, const std::string &collectVarName, const ConstDDSList &datasetsInOrder)
 Fill in varArrays with Array's named collectVarName from each DDS in datasetsInOrder, in that order. More...
 
static bool couldBeCoordinateVariable (libdap::BaseType *pBT)
 
static bool doShapesMatch (const libdap::Array &lhs, const libdap::Array &rhs, bool checkDimNames)
 Do the lhs and rhs have the same shapes? Only use size for dimension compares unless checkDimNames. More...
 
static bool doTypesMatch (const libdap::Array &lhs, const libdap::Array &rhs)
 Do the lhs and rhs have the same data type? More...
 
static bool findAttribute (const libdap::AttrTable &inTable, const string &name, libdap::AttrTable::Attr_iter &attr)
 Lookup the attribute with given name in inTable and place a reference in attr. More...
 
static const libdap::Array * findMapByName (const libdap::Grid &inGrid, const std::string &findName)
 Find the given map name in the given Grid and return it if found, else NULL. More...
 
template<class LibdapType >
static LibdapType * findTypedVariableAtDDSTopLevel (const libdap::DDS &dds, const string &name)
 Template wrapper for findVariableAtDDSTopLevel() which does the find but only return non-NULL if the found BaseType* can be dynamically cast to template type LibdapType. More...
 
static libdap::BaseType * findVariableAtDDSTopLevel (const libdap::DDS &dds, const string &name)
 Find a variable with name at the top level of the DDS. More...
 
static void gatherMetadataChangesFrom (libdap::BaseType *pIntoVar, const libdap::BaseType &fromVar)
 Union fromVar's AttrTable (initially) with pIntoVar's AttrTable and replace pIntoVar's AttrTable with this union. More...
 
static libdap::Array * getAsArrayIfPossible (libdap::BaseType *pBT)
 If pBT is an Array type, cast and return it as the Array. More...
 
static libdap::BaseType * getVariableNoRecurse (const libdap::DDS &dds, const std::string &name)
 Return the variable in dds top level (no recursing, no fully qualified name dot notation) if it exists, else 0. More...
 
static libdap::BaseType * getVariableNoRecurse (const libdap::Constructor &varContainer, const std::string &name)
 Return the variable in dds top level (no recursing, no fully qualified name dot notation) if it exists, else 0. More...
 
static void joinArrayData (libdap::Array *pAggArray, const std::vector< libdap::Array * > &varArrays, bool reserveStorage=true, bool clearDataAfterUse=false)
 Copy the simple type data Vector for each Array in varArrays into pAggArray, sequentially, effectively appending all the row major data in each entry in varArray into the row major order of pAggArray. More...
 
static void performUnionAggregation (libdap::DDS *pOutputUnion, const ConstDDSList &datasetsInOrder)
 Perform an NCML-type union aggregation on the datasets in datasetsInOrder into pOutputUnion. More...
 
static void printConstraints (std::ostream &os, const libdap::Array &fromArray)
 Stream out the current constraints for all the dimensions in the Array. More...
 
static void printConstraintsToDebugChannel (const std::string &debugChannel, const libdap::Array &fromArray)
 Output using BESDEBUG to the debugChannel channel. More...
 
static void printDimensions (std::ostream &os, const libdap::Array &fromArray)
 Print out the dimensions name and size for the given Array into os. More...
 
static void produceOuterDimensionJoinedArray (libdap::Array *pJoinedArray, const std::string &joinedArrayName, const std::string &newOuterDimName, const std::vector< libdap::Array * > &fromVars, bool copyData)
 Basic joinNew aggregation into pJoinedArray on the array of inputs fromVars. More...
 
static void resetCVInsertionPosition ()
 Used to reset the class field that tracks where Coordinate Variables (CVs) have been inserted into the DDS. More...
 
static void transferArrayConstraints (libdap::Array *pToArray, const libdap::Array &fromArray, bool skipFirstFromDim, bool skipFirstToDim, bool printDebug=false, const std::string &debugChannel="agg_util")
 Copy the constraints from the from Array into the pToArray in Dim_iter order. More...
 
static void unionAllVariablesInto (libdap::DDS *pOutputUnion, const ConstDDSList &datasetsInOrder)
 For each variable within the top level of each dataset in datasetsInOrder (forward iteration) add a clone of it to pOutputUnion if a variable with the same name does not exist in pOutputUnion yet. More...
 
static void unionAllVariablesInto (libdap::DDS *pOutputUnion, const libdap::DDS &fromDDS, bool add_at_top=false)
 For each variable in fromDDS top level, union it into pOutputUnion if a variable with the same name isn't already there. More...
 
static void unionAttrsInto (libdap::AttrTable *pOut, const libdap::AttrTable &fromTable)
 Merge any attributes in tableToMerge whose names do not already exist within *pOut into pOut. More...
 
static bool validateArrayTypesAndShapesMatch (const std::vector< libdap::Array * > &arrays, bool enforceMatchingDimNames)
 Scan all the arrays in arrays using the first as a template and make sure that they all have the same data type and they all have the same dimensions. More...
 

Detailed Description

A static class for encapsulating the aggregation functionality on libdap.

This class should have references to libdap and STL, but should NOT contain any references to other ncml_module classes. This will allow us to potentially package the aggregation functionality into its own lib or perhaps roll it into libdap.

Definition at line 185 of file AggregationUtil.h.

Member Typedef Documentation

typedef std::vector<const libdap::DDS*> agg_util::AggregationUtil::ConstDDSList

Definition at line 196 of file AggregationUtil.h.

Member Function Documentation

bool agg_util::AggregationUtil::addCopyOfVariableIfNameIsAvailable ( libdap::DDS *  pOutDDS,
const libdap::BaseType &  varProto,
bool  add_at_top = false 
)
static

If a variable does not exist within pOutDDS (top level) with the same name as varProto, then place a clone of varProto (using virtual ctor ptr_duplicate) into pOutDDS.

Returns
whether pOutDDS changed (ie name was free).

Definition at line 461 of file AggregationUtil.cc.

References BESDEBUG, and findVariableAtDDSTopLevel().

Referenced by unionAllVariablesInto().

Here is the call graph for this function:

void agg_util::AggregationUtil::addDatasetArrayDataToAggregationOutputArray ( libdap::Array &  oOutputArray,
unsigned int  atIndex,
const libdap::Array &  constrainedTemplateArray,
const string &  varName,
AggMemberDataset dataset,
const ArrayGetterInterface arrayGetter,
const string &  debugChannel 
)
static

Load the given dataset's DataDDS.

Find the aggVar of the given name in it, must be Array. Transfer the constraints from the local template to it. Call read() on it. Stream the data into oOutputArray's output buffer at the element index nextElementIndex.

Parameters
oOutputArraythe Array to output the data into
atIndexwhere in the output buffer of rOutputArray to stream it (note: not byte, element!)
constrainedTemplateArraythe Array to use as the template for the constraints on loading the dataset.
namethe name of the aggVar to find in the DDS
datasetthe dataset to load for this element.
arrayGetterthe class to use to get the member Array by name from DDS
debugChannelif not empty(), BESDEBUG channel to use

Definition at line 1005 of file AggregationUtil.cc.

References doShapesMatch(), doTypesMatch(), agg_util::AggMemberDataset::getDataDDS(), agg_util::AggMemberDataset::getLocation(), NCML_ASSERT_MSG, and agg_util::ArrayGetterInterface::readAndGetArray().

Referenced by agg_util::ArrayJoinExistingAggregation::readConstrainedGranuleArraysAndAggregateDataHook(), and agg_util::ArrayAggregateOnOuterDimension::readConstrainedGranuleArraysAndAggregateDataHook().

Here is the call graph for this function:

void agg_util::AggregationUtil::addOrReplaceVariableForName ( libdap::DDS *  pOutDDS,
const libdap::BaseType &  varProto 
)
static

If a variable with the name varProto.name() doesn't exist, add a copy of varProto to pOutDDS.

If the variable already exists, REPLACE it with a copy of varProto.

Parameters
pOutDDSthe DDS to change
varProtoprototype to clone and add to pOutDDS.

Definition at line 496 of file AggregationUtil.cc.

References findVariableAtDDSTopLevel().

Here is the call graph for this function:

unsigned int agg_util::AggregationUtil::collectVariableArraysInOrder ( std::vector< libdap::Array * > &  varArrays,
const std::string &  collectVarName,
const ConstDDSList datasetsInOrder 
)
static

Fill in varArrays with Array's named collectVarName from each DDS in datasetsInOrder, in that order.

In other words, the ordering found in datasetsInOrder will be preserved in varArrays.

Returns
the number of variables added to varArrays.
Parameters
varArraysthe array to push the found variables onto. Will NOT be cleared, so can be added to.
collectVarNamethe name of the variable to find at top level DDS in datasetsInOrder
datasetsInOrderthe datasets to search for the Array's within.

Definition at line 673 of file AggregationUtil.cc.

References findVariableAtDDSTopLevel(), and VALID_PTR.

Here is the call graph for this function:

bool agg_util::AggregationUtil::couldBeCoordinateVariable ( libdap::BaseType *  pBT)
static
Returns
whether this is a 1D Array whose dimension name is the same as its variable name. We consider this to define a "coordinate variable" in the sense of an NCML dataset and will use it as a Grid map vector.

Definition at line 696 of file AggregationUtil.cc.

References NCML_ASSERT_MSG.

bool agg_util::AggregationUtil::doShapesMatch ( const libdap::Array &  lhs,
const libdap::Array &  rhs,
bool  checkDimNames 
)
static

Do the lhs and rhs have the same shapes? Only use size for dimension compares unless checkDimNames.

Definition at line 643 of file AggregationUtil.cc.

Referenced by addDatasetArrayDataToAggregationOutputArray(), and validateArrayTypesAndShapesMatch().

bool agg_util::AggregationUtil::doTypesMatch ( const libdap::Array &  lhs,
const libdap::Array &  rhs 
)
static

Do the lhs and rhs have the same data type?

Definition at line 634 of file AggregationUtil.cc.

Referenced by addDatasetArrayDataToAggregationOutputArray(), and validateArrayTypesAndShapesMatch().

bool agg_util::AggregationUtil::findAttribute ( const libdap::AttrTable &  inTable,
const string &  name,
libdap::AttrTable::Attr_iter &  attr 
)
static

Lookup the attribute with given name in inTable and place a reference in attr.

Returns
whether it was found and attr is validly effected.

Definition at line 408 of file AggregationUtil.cc.

Referenced by unionAttrsInto().

const Array * agg_util::AggregationUtil::findMapByName ( const libdap::Grid &  inGrid,
const std::string &  findName 
)
static
template<class LibdapType >
static LibdapType* agg_util::AggregationUtil::findTypedVariableAtDDSTopLevel ( const libdap::DDS &  dds,
const string &  name 
)
static

Template wrapper for findVariableAtDDSTopLevel() which does the find but only return non-NULL if the found BaseType* can be dynamically cast to template type LibdapType.

Parameters
ddsthe dds to search
namethe name of the variable to find
Returns
the pointer to the found object if it's dynamically castable to LibdapType*, else NULL.
See also
findVariableAtDDSTopLevel()
template<class LibdapType >
LibdapType* agg_util::AggregationUtil::findTypedVariableAtDDSTopLevel ( const libdap::DDS &  dds,
const string &  name 
)

Definition at line 531 of file AggregationUtil.cc.

References findVariableAtDDSTopLevel().

Here is the call graph for this function:

libdap::BaseType * agg_util::AggregationUtil::findVariableAtDDSTopLevel ( const libdap::DDS &  dds,
const string &  name 
)
static

Find a variable with name at the top level of the DDS.

Do not recurse. DDS::var() will look inside containers, so we can't use that.

Returns
the variable within dds or null if not found.

Definition at line 511 of file AggregationUtil.cc.

Referenced by addCopyOfVariableIfNameIsAvailable(), addOrReplaceVariableForName(), collectVariableArraysInOrder(), and findTypedVariableAtDDSTopLevel().

void agg_util::AggregationUtil::gatherMetadataChangesFrom ( libdap::BaseType *  pIntoVar,
const libdap::BaseType &  fromVar 
)
static

Union fromVar's AttrTable (initially) with pIntoVar's AttrTable and replace pIntoVar's AttrTable with this union.

Essentially uses fromVar's AttrTable as a set of changes to pIntoVar's table.

Parameters
pIntoVarthe var whose AttrTable is the output
fromVarthe var to use as changes to the output

Definition at line 1069 of file AggregationUtil.cc.

References unionAttrsInto().

Here is the call graph for this function:

Array * agg_util::AggregationUtil::getAsArrayIfPossible ( libdap::BaseType *  pBT)
static

If pBT is an Array type, cast and return it as the Array.

If pBT is a Grid type, return the data Array field. Otherwise, return NULL.

Parameters
pBTthe variable to adapt
Returns
the array pointer or null if it cannot be adapted.

Definition at line 957 of file AggregationUtil.cc.

BaseType * agg_util::AggregationUtil::getVariableNoRecurse ( const libdap::DDS &  dds,
const std::string &  name 
)
static

Return the variable in dds top level (no recursing, no fully qualified name dot notation) if it exists, else 0.

The name IS ALLOWED to contain a dot '.', but this is interpreted as PART OF THE NAME and not as a field separator!

Definition at line 915 of file AggregationUtil.cc.

Referenced by agg_util::TopLevelArrayGetter::readAndGetArray(), agg_util::TopLevelGridDataArrayGetter::readAndGetArray(), and agg_util::TopLevelGridMapArrayGetter::readAndGetArray().

BaseType * agg_util::AggregationUtil::getVariableNoRecurse ( const libdap::Constructor &  varContainer,
const std::string &  name 
)
static

Return the variable in dds top level (no recursing, no fully qualified name dot notation) if it exists, else 0.

The name IS ALLOWED to contain a dot '.', but this is interpreted as PART OF THE NAME and not as a field separator!

Definition at line 937 of file AggregationUtil.cc.

void agg_util::AggregationUtil::joinArrayData ( libdap::Array *  pAggArray,
const std::vector< libdap::Array * > &  varArrays,
bool  reserveStorage = true,
bool  clearDataAfterUse = false 
)
static

Copy the simple type data Vector for each Array in varArrays into pAggArray, sequentially, effectively appending all the row major data in each entry in varArray into the row major order of pAggArray.

If the data in varArray's has not been read, it calls read() on each Array first.

If reserveStorage is set, pAggArray will first have enough its capacity reserved to store all the data within varArray's (the sum of all lengths). This should be false if the caller already reserved the proper capacity.

Parameters
pAggArraythe output to place the appended data
varArraysthe Array's whose data is to be copied into pAggArray, in the order of the vector.
reserveStorageif true, sets the capacity of pAggArray to be enough to contain all the elements in varArrays. Note: this might not match the length of the ouput, so the caller really should do this!
clearDayaAfterUseif true, Vector::clear_local_data() will be called on each member of varArray's after it is copied into the output. this should tighten up memory if its known the data will no longer be needed.
Exceptions
ifany Array in varArray's does not have the same element type as pAggArray.
ifthere is not enough storage in pAggArray to collect all the data.
onany problems will a read() call on any Array in varArrays.

Definition at line 716 of file AggregationUtil.cc.

References NCML_ASSERT_MSG, and VALID_PTR.

Referenced by produceOuterDimensionJoinedArray().

void agg_util::AggregationUtil::performUnionAggregation ( libdap::DDS *  pOutputUnion,
const ConstDDSList datasetsInOrder 
)
static

Perform an NCML-type union aggregation on the datasets in datasetsInOrder into pOutputUnion.

The first named instance of a variable or attribute in a forward iteration of datasetsInOrder ends up in pOutputUnion. Not that named containers are considered as a unit, so we do not recurse into their children.

Definition at line 335 of file AggregationUtil.cc.

References resetCVInsertionPosition(), unionAllVariablesInto(), unionAttrsInto(), and VALID_PTR.

Here is the call graph for this function:

void agg_util::AggregationUtil::printConstraints ( std::ostream &  os,
const libdap::Array &  fromArray 
)
static

Stream out the current constraints for all the dimensions in the Array.

Parameters
osthe output stream
fromArraythe array whose dimensions to print.

Definition at line 806 of file AggregationUtil.cc.

Referenced by agg_util::ArrayJoinExistingAggregation::ArrayJoinExistingAggregation(), agg_util::ArrayAggregationBase::printConstraints(), agg_util::GridAggregationBase::printConstraints(), and printConstraintsToDebugChannel().

void agg_util::AggregationUtil::printConstraintsToDebugChannel ( const std::string &  debugChannel,
const libdap::Array &  fromArray 
)
static

Output using BESDEBUG to the debugChannel channel.

Prints the constraints on the dimensions of fromArray.

Parameters
debugChannelname of the output channel
fromArraythe Array whose constraints should be printed to the debugChannel

Definition at line 826 of file AggregationUtil.cc.

References BESDEBUG, and printConstraints().

Referenced by transferArrayConstraints().

Here is the call graph for this function:

void agg_util::AggregationUtil::printDimensions ( std::ostream &  os,
const libdap::Array &  fromArray 
)
static

Print out the dimensions name and size for the given Array into os.

Definition at line 788 of file AggregationUtil.cc.

Referenced by agg_util::ArrayJoinExistingAggregation::ArrayJoinExistingAggregation().

void agg_util::AggregationUtil::produceOuterDimensionJoinedArray ( libdap::Array *  pJoinedArray,
const std::string &  joinedArrayName,
const std::string &  newOuterDimName,
const std::vector< libdap::Array * > &  fromVars,
bool  copyData 
)
static

Basic joinNew aggregation into pJoinedArray on the array of inputs fromVars.

If all the Arrays in fromVars are rank D, then the joined Array will be rank D+1 with the new outer dimension with dimName which will be of cardinality fromVars.size(). The row major order of the data in the new Array will be assumed in the order the fromVars are given.

Data values will ONLY be copied if copyData is set.

fromVars[0] will be used as the "prototype" in terms of attribute metadata, so only its Attributes will be copied into the resulting new Array.

Errors: The shape and type of all vars in fromVars MUST match each other or an exception is thrown! There must be at least one array in fromVars or an exception is thrown.

Parameters
pJoinedArraythe array to make into the new array. It is assumed to have no dimensions to start and should be an empty prototype.
joinedArrayNamethe name of pJoinedArray will be set to this
newOuterDimNamethe name of the new outer dimension will be set to this
fromVarsthe input Array's the first of which will be the "template"
copyDatawhether to copy the data from the Array's in fromVars or just create the shape.

Definition at line 545 of file AggregationUtil.cc.

References joinArrayData(), NCML_ASSERT_MSG, VALID_PTR, and validateArrayTypesAndShapesMatch().

Here is the call graph for this function:

void agg_util::AggregationUtil::resetCVInsertionPosition ( )
static

Used to reset the class field that tracks where Coordinate Variables (CVs) have been inserted into the DDS.

This helps ensure that the CVs appear in the order they were listed in the .ncml file.

Definition at line 454 of file AggregationUtil.cc.

Referenced by performUnionAggregation().

void agg_util::AggregationUtil::transferArrayConstraints ( libdap::Array *  pToArray,
const libdap::Array &  fromArray,
bool  skipFirstFromDim,
bool  skipFirstToDim,
bool  printDebug = false,
const std::string &  debugChannel = "agg_util" 
)
static

Copy the constraints from the from Array into the pToArray in Dim_iter order.

if skipFirstFromDim, the first dimension of fromArray will be skipped, for the case of copying from a joinNew aggregated array to a granule subset array

if skipFirstToDim the first dimension of toArray will be skipped, for the case where presumably both first dims are skipped for a joinExisting aggregation where constraints on outer dim will be calculated by the caller.

Parameters
pToArrayarray to put constraints into
fromArrayarray to take constraints from
skipFirstFromDimwhether the first dim of fromArray is aggregated and should be skipped.
skipFirstToDimwhether the first dim of toArray is aggregated and should be skipped.

Definition at line 837 of file AggregationUtil.cc.

References BESDEBUG, NCML_ASSERT_MSG, printConstraintsToDebugChannel(), and VALID_PTR.

Referenced by agg_util::TopLevelArrayGetter::readAndGetArray(), agg_util::TopLevelGridDataArrayGetter::readAndGetArray(), agg_util::TopLevelGridMapArrayGetter::readAndGetArray(), agg_util::ArrayJoinExistingAggregation::transferOutputConstraintsIntoGranuleTemplateHook(), and agg_util::ArrayAggregateOnOuterDimension::transferOutputConstraintsIntoGranuleTemplateHook().

Here is the call graph for this function:

void agg_util::AggregationUtil::unionAllVariablesInto ( libdap::DDS *  pOutputUnion,
const ConstDDSList datasetsInOrder 
)
static

For each variable within the top level of each dataset in datasetsInOrder (forward iteration) add a clone of it to pOutputUnion if a variable with the same name does not exist in pOutputUnion yet.

Definition at line 416 of file AggregationUtil.cc.

Referenced by performUnionAggregation().

void agg_util::AggregationUtil::unionAllVariablesInto ( libdap::DDS *  pOutputUnion,
const libdap::DDS &  fromDDS,
bool  add_at_top = false 
)
static

For each variable in fromDDS top level, union it into pOutputUnion if a variable with the same name isn't already there.

See also
addCopyOfVariableIfNameIsAvailable().

Definition at line 427 of file AggregationUtil.cc.

References addCopyOfVariableIfNameIsAvailable(), and BESDEBUG.

Here is the call graph for this function:

void agg_util::AggregationUtil::unionAttrsInto ( libdap::AttrTable *  pOut,
const libdap::AttrTable &  fromTable 
)
static

Merge any attributes in tableToMerge whose names do not already exist within *pOut into pOut.

Parameters
pOutthe table to merge into. On exit it will contain its previous contents plus any new attributes from fromTable
fromTable

Definition at line 365 of file AggregationUtil.cc.

References BESDEBUG, findAttribute(), NCML_ASSERT_MSG, and VALID_PTR.

Referenced by gatherMetadataChangesFrom(), and performUnionAggregation().

Here is the call graph for this function:

bool agg_util::AggregationUtil::validateArrayTypesAndShapesMatch ( const std::vector< libdap::Array * > &  arrays,
bool  enforceMatchingDimNames 
)
static

Scan all the arrays in arrays using the first as a template and make sure that they all have the same data type and they all have the same dimensions.

(NOTE: we only use the sizes to validate dimensions, not the "name", unless enforceMatchingDimNames is set)

Definition at line 603 of file AggregationUtil.cc.

References doShapesMatch(), doTypesMatch(), NCML_ASSERT, and VALID_PTR.

Referenced by produceOuterDimensionJoinedArray().

Here is the call graph for this function:


The documentation for this class was generated from the following files: