32#include "ArrayAggregateOnOuterDimension.h"
33#include "AggregationException.h"
35#include <libdap/DataDDS.h>
36#include <libdap/Marshaller.h>
41#include "BESStopWatch.h"
43#define DEBUG_CHANNEL "agg_util"
48 AMDList memberDatasets, unique_ptr<ArrayGetterInterface> arrayGetter,
const Dimension& newDim) :
52 BESDEBUG(DEBUG_CHANNEL,
"ArrayAggregateOnOuterDimension: ctor called!" << endl);
55 BESDEBUG(DEBUG_CHANNEL,
"ArrayAggregateOnOuterDimension: adding new outer dimension: " << _newDim.name << endl);
56 prepend_dim(_newDim.size, _newDim.name);
62 BESDEBUG(DEBUG_CHANNEL,
"ArrayAggregateOnOuterDimension() copy ctor called!" << endl);
68 BESDEBUG(DEBUG_CHANNEL,
"~ArrayAggregateOnOuterDimension() dtor called!" << endl);
83 ArrayAggregationBase::operator=(rhs);
114 libdap::Marshaller &m,
bool ce_eval)
121 if (!(send_p() || is_in_selection())) {
122 BESDEBUG_FUNC(DEBUG_CHANNEL,
"Object not in output, skipping... name=" << name() << endl);
128 delete bes_timing::elapsedTimeToReadStart;
129 bes_timing::elapsedTimeToReadStart = 0;
135 const Array::dimension& outerDim = *(dim_begin());
136 BESDEBUG(DEBUG_CHANNEL,
137 "Aggregating datasets array with outer dimension constraints: " <<
" start=" << outerDim.start <<
" stride=" << outerDim.stride <<
" stop=" << outerDim.stop << endl);
140 if (
static_cast<unsigned int>(outerDim.size) !=
getDatasetList().size()) {
142 THROW_NCML_PARSE_ERROR(-1,
"The new outer dimension of the joinNew aggregation doesn't "
143 " have the same size as the number of datasets in the aggregation!");
148 m.put_vector_start(length());
150 reserve_value_capacity();
156 int nextElementIndex = 0;
159 for (
int i = outerDim.start; i <= outerDim.stop && i < outerDim.size; i += outerDim.stride) {
166 delete bes_timing::elapsedTimeToTransmitStart;
167 bes_timing::elapsedTimeToTransmitStart = 0;
171 this->set_value_slice_from_row_major_vector(*pDatasetArray, nextElementIndex);
174 pDatasetArray->clear_local_data();
177 std::ostringstream oss;
178 oss <<
"Got AggregationException while streaming dataset index=" << i <<
" data for location=\""
179 << dataset.
getLocation() <<
"\" The error msg was: " << std::string(ex.what());
180 THROW_NCML_PARSE_ERROR(-1, oss.str());
188 NCML_ASSERT_MSG(nextElementIndex == length(),
"Logic error:\n"
189 "ArrayAggregateOnOuterDimension::read(): "
190 "At end of aggregating, expected the nextElementIndex to be the length of the "
191 "aggregated array, but it wasn't!");
200 delete bes_timing::elapsedTimeToTransmitStart;
201 bes_timing::elapsedTimeToTransmitStart = 0;
202 status = libdap::Array::serialize(eval, dds, m, ce_eval);
206 status = libdap::Array::serialize(eval, dds, m, ce_eval);
217 _newDim = rhs._newDim;
220void ArrayAggregateOnOuterDimension::cleanup() const noexcept
247 sw.
start(
"ArrayAggregateOnOuterDimension::readConstrainedGranuleArraysAndAggregateDataHook",
"");
250 const Array::dimension& outerDim = *(dim_begin());
251 BESDEBUG(DEBUG_CHANNEL,
252 "Aggregating datasets array with outer dimension constraints: " <<
" start=" << outerDim.start <<
" stride=" << outerDim.stride <<
" stop=" << outerDim.stop << endl);
255 if (
static_cast<unsigned int>(outerDim.size) !=
getDatasetList().size()) {
257 THROW_NCML_PARSE_ERROR(-1,
"The new outer dimension of the joinNew aggregation doesn't "
258 " have the same size as the number of datasets in the aggregation!");
262 reserve_value_capacity();
266 int nextElementIndex = 0;
269 for (
int i = outerDim.start; i <= outerDim.stop && i < outerDim.size; i += outerDim.stride) {
281 std::ostringstream oss;
282 oss <<
"Got AggregationException while streaming dataset index=" << i <<
" data for location=\""
283 << dataset.
getLocation() <<
"\" The error msg was: " << std::string(ex.what());
284 THROW_NCML_PARSE_ERROR(-1, oss.str());
292 NCML_ASSERT_MSG(nextElementIndex == length(),
"Logic error:\n"
293 "ArrayAggregateOnOuterDimension::read(): "
294 "At end of aggregating, expected the nextElementIndex to be the length of the "
295 "aggregated array, but it wasn't!");
static bool IsSet(const std::string &flagName)
see if the debug context flagName is set to true
virtual bool start(std::string name)
const std::string & getLocation() const
static void addDatasetArrayDataToAggregationOutputArray(libdap::Array &oOutputArray, unsigned int atIndex, const libdap::Array &constrainedTemplateArray, const string &varName, AggMemberDataset &dataset, const ArrayGetterInterface &arrayGetter, const string &debugChannel)
static void transferArrayConstraints(libdap::Array *pToArray, const libdap::Array &fromArray, bool skipFirstFromDim, bool skipFirstToDim, bool printDebug=false, const std::string &debugChannel="agg_util")
static libdap::Array * readDatasetArrayDataForAggregation(const libdap::Array &constrainedTemplateArray, const std::string &varName, AggMemberDataset &dataset, const ArrayGetterInterface &arrayGetter, const std::string &debugChannel)
void readConstrainedGranuleArraysAndAggregateDataHook() override
void transferOutputConstraintsIntoGranuleTemplateHook() override
ArrayAggregateOnOuterDimension & operator=(const ArrayAggregateOnOuterDimension &rhs)
ArrayAggregateOnOuterDimension(const libdap::Array &proto, AMDList memberDatasets, std::unique_ptr< ArrayGetterInterface > arrayGetter, const Dimension &newDim)
ArrayAggregateOnOuterDimension * ptr_duplicate() override
bool serialize(libdap::ConstraintEvaluator &eval, libdap::DDS &dds, libdap::Marshaller &m, bool ce_eval) override
~ArrayAggregateOnOuterDimension() override
const AMDList & getDatasetList() const
libdap::Array & getGranuleTemplateArray()
const ArrayGetterInterface & getArrayGetterInterface() const
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...