29 #ifndef __AGG_UTIL__AGGREGATION_UTIL_H__
30 #define __AGG_UTIL__AGGREGATION_UTIL_H__
32 #include <AttrTable.h>
49 class AggMemberDataset;
89 const std::string& name,
90 const libdap::DataDDS& dds,
91 const libdap::Array*
const pConstraintTemplate,
92 const std::string& debugChannel
117 const std::string& name,
118 const libdap::DataDDS& dds,
119 const libdap::Array*
const pConstraintTemplate,
120 const std::string& debugChannel
143 const std::string& name,
144 const libdap::DataDDS& dds,
145 const libdap::Array*
const pConstraintTemplate,
146 const std::string& debugChannel
168 const std::string& name,
169 const libdap::DataDDS& dds,
170 const libdap::Array*
const pConstraintTemplate,
171 const std::string& debugChannel
191 static int d_last_added_cv_position;
205 libdap::DDS* pOutputUnion,
206 const ConstDDSList& datasetsInOrder);
214 static void unionAttrsInto(libdap::AttrTable* pOut,
const libdap::AttrTable& fromTable);
220 static bool findAttribute(
const libdap::AttrTable& inTable,
const string& name, libdap::AttrTable::Attr_iter& attr);
240 static void unionAllVariablesInto(libdap::DDS* pOutputUnion,
const libdap::DDS& fromDDS,
bool add_at_top =
false);
303 const std::string& joinedArrayName,
304 const std::string& newOuterDimName,
305 const std::vector<libdap::Array*>& fromVars,
315 bool enforceMatchingDimNames);
318 static bool doTypesMatch(
const libdap::Array& lhs,
const libdap::Array& rhs);
323 static bool doShapesMatch(
const libdap::Array& lhs,
const libdap::Array& rhs,
bool checkDimNames);
334 std::vector<libdap::Array*>& varArrays,
335 const std::string& collectVarName,
336 const ConstDDSList& datasetsInOrder);
367 const std::vector<libdap::Array*>& varArrays,
368 bool reserveStorage=
true,
369 bool clearDataAfterUse=
false);
372 static void printDimensions(std::ostream& os,
const libdap::Array& fromArray);
379 static void printConstraints(std::ostream& os,
const libdap::Array& fromArray);
409 libdap::Array* pToArray,
410 const libdap::Array& fromArray,
411 bool skipFirstFromDim,
413 bool printDebug =
false,
414 const std::string& debugChannel =
"agg_util");
423 const libdap::DDS& dds,
424 const std::string& name);
433 const libdap::Constructor& varContainer,
434 const std::string& name);
446 static const libdap::Array*
findMapByName(
const libdap::Grid& inGrid,
const std::string& findName);
467 libdap::Array& oOutputArray,
468 unsigned int atIndex,
469 const libdap::Array& constrainedTemplateArray,
470 const string& varName,
473 const string& debugChannel
485 libdap::BaseType* pIntoVar,
486 const libdap::BaseType& fromVar);
496 template <
typename T>
499 while (!vecToClear.empty())
501 T* pElt = vecToClear.back();
503 vecToClear.pop_back();
511 while (!vecToClear.empty())
513 T* pElt = vecToClear.back();
515 vecToClear.pop_back();
522 const std::vector<T*>& fromVec)
524 class std::vector<T*>::const_iterator it;
525 class std::vector<T*>::const_iterator endIt = fromVec.end();
526 for (it = fromVec.begin(); it != endIt; ++it)
533 intoVec.push_back(pElt);
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...
virtual libdap::Array * readAndGetArray(const std::string &name, const libdap::DataDDS &dds, const libdap::Array *const pConstraintTemplate, const std::string &debugChannel) const
Lookup name within the top level of DDS ONLY and return it as an Array* if it is a subclass of Array...
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 ...
Abstract helper superclass for allowing lazy access to the DataDDS for an aggregation.
virtual ~TopLevelGridMapArrayGetter()
virtual ~TopLevelArrayGetter()
TopLevelGridDataArrayGetter()
TopLevelGridMapArrayGetter(const std::string &gridName)
virtual libdap::Array * readAndGetArray(const std::string &name, const libdap::DataDDS &dds, const libdap::Array *const pConstraintTemplate, const std::string &debugChannel) const
Find's the Array using name as the name of a map to find within a top level Grid names in the constru...
virtual TopLevelGridDataArrayGetter * clone() const
Virtual constructor idiom.
static libdap::BaseType * findVariableAtDDSTopLevel(const libdap::DDS &dds, const string &name)
Find a variable with name at the top level of the DDS.
std::vector< const libdap::DDS * > ConstDDSList
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.
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
static bool couldBeCoordinateVariable(libdap::BaseType *pBT)
void appendVectorOfRCObject(std::vector< T * > &intoVec, const std::vector< T * > &fromVec)
Assumes T has ref()
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...
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...
static class NCMLUtil overview
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.
static void performUnionAggregation(libdap::DDS *pOutputUnion, const ConstDDSList &datasetsInOrder)
Perform an NCML-type union aggregation on the datasets in datasetsInOrder into pOutputUnion.
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...
Helper class hierarchy for acquiring variable of a certain type from a DDS.
A static class for encapsulating the aggregation functionality on libdap.
Concrete impl that simply finds the Array by looking for a variable of the given name at the top leve...
virtual libdap::Array * readAndGetArray(const std::string &name, const libdap::DataDDS &dds, const libdap::Array *const pConstraintTemplate, const std::string &debugChannel) const =0
Find, constrain, read, and return an Array inside the DDS using the given name information (somehow...
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.
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 exist...
virtual ~TopLevelGridDataArrayGetter()
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.
static void resetCVInsertionPosition()
Used to reset the class field that tracks where Coordinate Variables (CVs) have been inserted into th...
static bool doTypesMatch(const libdap::Array &lhs, const libdap::Array &rhs)
Do the lhs and rhs have the same data type?
virtual TopLevelGridMapArrayGetter * clone() const
Virtual constructor idiom.
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...
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 c...
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.
virtual TopLevelArrayGetter * clone() const
Virtual constructor idiom.
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.
virtual libdap::Array * readAndGetArray(const std::string &name, const libdap::DataDDS &dds, const libdap::Array *const pConstraintTemplate, const std::string &debugChannel) const
Find the array as the data Array of a TOP-LEVEL Grid with name.
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.
void clearAndUnrefAllElements(std::vector< T * > &vecToClear)
Assumes T has unref()
virtual ArrayGetterInterface * clone() const =0
Virtual constructor idiom.
static void printDimensions(std::ostream &os, const libdap::Array &fromArray)
Print out the dimensions name and size for the given Array into os.
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.
static libdap::Array * getAsArrayIfPossible(libdap::BaseType *pBT)
If pBT is an Array type, cast and return it as the Array.
virtual ~ArrayGetterInterface()
static void printConstraintsToDebugChannel(const std::string &debugChannel, const libdap::Array &fromArray)
Output using BESDEBUG to the debugChannel channel.
static void printConstraints(std::ostream &os, const libdap::Array &fromArray)
Stream out the current constraints for all the dimensions in the Array.
void clearVectorAndDeletePointers(std::vector< T * > &vecToClear)
For each ptr element pElt in vecToClear, delete pElt and remove it from vecToClear.