29#include "GridJoinExistingAggregation.h"
31#include "AggregationUtil.h"
32#include "ArrayJoinExistingAggregation.h"
33#include <libdap/Array.h>
40#define DEBUG_CHANNEL "ncml:2"
44GridJoinExistingAggregation::GridJoinExistingAggregation(
const libdap::Grid& proto,
const AMDList& memberDatasets,
45 const DDSLoader& loaderProto,
const Dimension& joinDim)
48 GridAggregationBase(proto.name(), memberDatasets, loaderProto), _joinDim(joinDim)
50 createRep(proto, memberDatasets);
53GridJoinExistingAggregation::GridJoinExistingAggregation(
const GridJoinExistingAggregation& proto) :
54 GridAggregationBase(proto), _joinDim(proto._joinDim)
60GridJoinExistingAggregation::~GridJoinExistingAggregation()
66GridJoinExistingAggregation*
67GridJoinExistingAggregation::ptr_duplicate()
69 return new GridJoinExistingAggregation(*
this);
72GridJoinExistingAggregation&
73GridJoinExistingAggregation::operator=(
const GridJoinExistingAggregation& rhs)
77 GridAggregationBase::operator=(rhs);
83unique_ptr<ArrayJoinExistingAggregation> GridJoinExistingAggregation::makeAggregatedOuterMapVector()
const
85 BESDEBUG_FUNC(DEBUG_CHANNEL,
"Making an aggregated map " <<
"as a coordinate variable..." << endl);
87 NCML_ASSERT_MSG(pGridGranuleTemplate,
"Expected grid granule template but got null.");
89 const Array* pMapTemplate = AggregationUtil::findMapByName(*pGridGranuleTemplate, _joinDim.name);
90 NCML_ASSERT_MSG(pMapTemplate,
"Expected to find a dim map for the joinExisting agg but failed!");
97 auto pNewMap = unique_ptr<ArrayJoinExistingAggregation>(
107void GridJoinExistingAggregation::transferConstraintsToSubGridHook(Grid* pSubGrid)
110 transferConstraintsToSubGridMaps(pSubGrid);
111 transferConstraintsToSubGridArray(pSubGrid);
116GridJoinExistingAggregation::getAggregationDimension()
const
126 _joinDim = rhs._joinDim;
129void GridJoinExistingAggregation::cleanup() const noexcept
133void GridJoinExistingAggregation::createRep(
const libdap::Grid& constProtoSubGrid,
const AMDList& memberDatasets)
136 Grid& protoSubGrid =
const_cast<Grid&
>(constProtoSubGrid);
139 setShapeFrom(protoSubGrid,
false);
143 Grid::Map_iter firstIt = protoSubGrid.map_begin();
144 Grid::Map_iter endIt = protoSubGrid.map_end();
145 for (Grid::Map_iter it = firstIt; it != endIt; ++it) {
148 NCML_ASSERT_MSG((*it)->name() == _joinDim.name,
"Expected the first map to be the outer dimension "
149 "named " + _joinDim.name +
" but it was not! Logic problem.");
154 Array* pMap =
dynamic_cast<Array*
>(*it);
159 BESDEBUG_FUNC(DEBUG_CHANNEL,
"Replacing the Grid's data Array with an ArrayAggregateOnOuterDimension..." << endl);
162 Array* pArr =
static_cast<Array*
>(array_var());
163 NCML_ASSERT_MSG(pArr,
"Expected to find a contained data Array but we did not!");
166 std::unique_ptr<ArrayGetterInterface> arrayGetter(
new TopLevelGridDataArrayGetter());
170 std::unique_ptr<ArrayJoinExistingAggregation> aggDataArray(
new ArrayJoinExistingAggregation(*pArr,
171 memberDatasets, std::move(arrayGetter), _joinDim));
175 NCML_ASSERT(!(arrayGetter.get()));
178 set_array(aggDataArray.get());
182 aggDataArray.release();
185void GridJoinExistingAggregation::transferConstraintsToSubGridMaps(Grid* pSubGrid)
187 BESDEBUG(DEBUG_CHANNEL,
"Transferring constraints to the subgrid maps..." << endl);
188 Map_iter subGridMapIt = pSubGrid->map_begin();
189 for (Map_iter it = map_begin(); it != map_end(); ++it) {
191 if (it != map_begin()) {
192 Array* subGridMap =
static_cast<Array*
>(*subGridMapIt);
193 Array* superGridMap =
static_cast<Array*
>(*it);
203void GridJoinExistingAggregation::transferConstraintsToSubGridArray(Grid* )
static void transferArrayConstraints(libdap::Array *pToArray, const libdap::Array &fromArray, bool skipFirstFromDim, bool skipFirstToDim, bool printDebug=false, const std::string &debugChannel="agg_util")
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...