32 #include "ArrayAggregateOnOuterDimension.h"
33 #include "AggregationException.h"
35 #include <libdap/DataDDS.h>
36 #include <libdap/Marshaller.h>
39 #include "NCMLDebug.h"
42 #include "BESStopWatch.h"
45 static const string DEBUG_CHANNEL(
"agg_util");
48 static const bool PRINT_CONSTRAINTS =
false;
51 extern BESStopWatch *bes_timing::elapsedTimeToTransmitStart;
55 #undef USE_LOCAL_TIMEOUT_SCHEME
60 const AMDList& memberDatasets, std::auto_ptr<ArrayGetterInterface>& arrayGetter,
const Dimension& newDim) :
64 BESDEBUG(DEBUG_CHANNEL,
"ArrayAggregateOnOuterDimension: ctor called!" << endl);
67 BESDEBUG(DEBUG_CHANNEL,
"ArrayAggregateOnOuterDimension: adding new outer dimension: " << _newDim.name << endl);
68 prepend_dim(_newDim.size, _newDim.name);
74 BESDEBUG(DEBUG_CHANNEL,
"ArrayAggregateOnOuterDimension() copy ctor called!" << endl);
80 BESDEBUG(DEBUG_CHANNEL,
"~ArrayAggregateOnOuterDimension() dtor called!" << endl);
95 ArrayAggregationBase::operator=(rhs);
126 libdap::Marshaller &m,
bool ce_eval)
133 if (!(send_p() || is_in_selection())) {
134 BESDEBUG_FUNC(DEBUG_CHANNEL,
"Object not in output, skipping... name=" << name() << endl);
140 delete bes_timing::elapsedTimeToReadStart;
141 bes_timing::elapsedTimeToReadStart = 0;
145 if (PRINT_CONSTRAINTS) {
146 BESDEBUG_FUNC(DEBUG_CHANNEL,
"Constraints on this Array are:" << endl);
153 if (PRINT_CONSTRAINTS) {
154 BESDEBUG_FUNC(DEBUG_CHANNEL,
"After transfer, constraints on the member template Array are: " << endl);
159 const Array::dimension& outerDim = *(dim_begin());
160 BESDEBUG(DEBUG_CHANNEL,
161 "Aggregating datasets array with outer dimension constraints: " <<
" start=" << outerDim.start <<
" stride=" << outerDim.stride <<
" stop=" << outerDim.stop << endl);
164 if (
static_cast<unsigned int>(outerDim.size) !=
getDatasetList().size()) {
166 THROW_NCML_PARSE_ERROR(-1,
"The new outer dimension of the joinNew aggregation doesn't "
167 " have the same size as the number of datasets in the aggregation!");
172 m.put_vector_start(length());
174 reserve_value_capacity();
180 int nextElementIndex = 0;
183 for (
int i = outerDim.start; i <= outerDim.stop && i < outerDim.size; i += outerDim.stride) {
187 #if USE_LOCAL_TIMEOUT_SCHEME
192 #if USE_LOCAL_TIMEOUT_SCHEME
196 delete bes_timing::elapsedTimeToTransmitStart;
197 bes_timing::elapsedTimeToTransmitStart = 0;
201 this->set_value_slice_from_row_major_vector(*pDatasetArray, nextElementIndex);
204 pDatasetArray->clear_local_data();
207 std::ostringstream oss;
208 oss <<
"Got AggregationException while streaming dataset index=" << i <<
" data for location=\""
209 << dataset.
getLocation() <<
"\" The error msg was: " << std::string(ex.what());
210 THROW_NCML_PARSE_ERROR(-1, oss.str());
218 NCML_ASSERT_MSG(nextElementIndex == length(),
"Logic error:\n"
219 "ArrayAggregateOnOuterDimension::read(): "
220 "At end of aggregating, expected the nextElementIndex to be the length of the "
221 "aggregated array, but it wasn't!");
230 delete bes_timing::elapsedTimeToTransmitStart;
231 bes_timing::elapsedTimeToTransmitStart = 0;
232 status = libdap::Array::serialize(eval, dds, m, ce_eval);
236 status = libdap::Array::serialize(eval, dds, m, ce_eval);
247 _newDim = rhs._newDim;
250 void ArrayAggregateOnOuterDimension::cleanup() throw ()
276 sw.
start(
"ArrayAggregateOnOuterDimension::readConstrainedGranuleArraysAndAggregateDataHook",
"");
279 const Array::dimension& outerDim = *(dim_begin());
280 BESDEBUG(DEBUG_CHANNEL,
281 "Aggregating datasets array with outer dimension constraints: " <<
" start=" << outerDim.start <<
" stride=" << outerDim.stride <<
" stop=" << outerDim.stop << endl);
284 if (
static_cast<unsigned int>(outerDim.size) !=
getDatasetList().size()) {
286 THROW_NCML_PARSE_ERROR(-1,
"The new outer dimension of the joinNew aggregation doesn't "
287 " have the same size as the number of datasets in the aggregation!");
291 reserve_value_capacity();
295 int nextElementIndex = 0;
298 for (
int i = outerDim.start; i <= outerDim.stop && i < outerDim.size; i += outerDim.stride) {
314 this->set_value_slice_from_row_major_vector(*pDatasetArray, nextElementIndex);
318 std::ostringstream oss;
319 oss <<
"Got AggregationException while streaming dataset index=" << i <<
" data for location=\""
320 << dataset.
getLocation() <<
"\" The error msg was: " << std::string(ex.what());
321 THROW_NCML_PARSE_ERROR(-1, oss.str());
329 NCML_ASSERT_MSG(nextElementIndex == length(),
"Logic error:\n"
330 "ArrayAggregateOnOuterDimension::read(): "
331 "At end of aggregating, expected the nextElementIndex to be the length of the "
332 "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)
virtual void transferOutputConstraintsIntoGranuleTemplateHook()
virtual void readConstrainedGranuleArraysAndAggregateDataHook()
ArrayAggregateOnOuterDimension & operator=(const ArrayAggregateOnOuterDimension &rhs)
ArrayAggregateOnOuterDimension(const libdap::Array &proto, const AMDList &memberDatasets, std::auto_ptr< ArrayGetterInterface > &arrayGetter, const Dimension &newDim)
virtual bool serialize(libdap::ConstraintEvaluator &eval, libdap::DDS &dds, libdap::Marshaller &m, bool ce_eval)
virtual ~ArrayAggregateOnOuterDimension()
virtual ArrayAggregateOnOuterDimension * ptr_duplicate()
const AMDList & getDatasetList() const
libdap::Array & getGranuleTemplateArray()
void printConstraints(const Array &fromArray)
const ArrayGetterInterface & getArrayGetterInterface() const
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...