33 #include <Constructor.h>
35 #include <InternalErr.h>
41 using libdap::BaseType;
44 using libdap::D4Group;
45 using libdap::Constructor;
46 using libdap::InternalErr;
52 static const string DEBUG_CHANNEL(
"agg_util");
53 static const bool PRINT_CONSTRAINTS(
true);
58 const libdap::Grid& proto,
62 , _loader(loaderProto.getDHI())
63 , _pSubGridProto(cloneSubGridProto(proto))
64 , _memberDatasets(memberDatasets)
73 , _loader(loaderProto.getDHI())
75 , _memberDatasets(memberDatasets)
81 , _loader(proto._loader.getDHI())
100 Grid::operator=(rhs);
110 BaseType *btp = array_var()->transform_to_dap4(root, container);
111 Array *coverage =
static_cast<Array*
>(btp);
112 if (!coverage)
throw InternalErr(__FILE__, __LINE__,
"Expected an Array while transforming a Grid (coverage)");
114 coverage->set_parent(container);
119 for (Map_iter i = map_begin(), e = map_end(); i != e; ++i) {
120 btp = (*i)->transform_to_dap4(root, container);
121 Array *map =
static_cast<Array*
>(btp);
122 if (!map)
throw InternalErr(__FILE__, __LINE__,
"Expected an Array while transforming a Grid (map)");
129 if (!root->var(map->name())) {
130 map->set_parent(container);
131 container->add_var_nocopy(map);
133 D4Map *dap4_map =
new D4Map(map->name(), map, coverage);
134 coverage->maps()->add_map(dap4_map);
137 throw InternalErr(__FILE__, __LINE__,
138 "transform_to_dap4() returned a null value where there can be no Grid.");
142 container->add_var_nocopy(coverage);
156 Grid& protoSubGrid =
const_cast<Grid&
>(constProtoSubGrid);
160 _pSubGridProto = auto_ptr<Grid>(cloneSubGridProto(protoSubGrid));
163 Array* pDataArrayTemplate = protoSubGrid.get_array();
165 set_array( static_cast<Array*>(pDataArrayTemplate->ptr_duplicate()) );
170 Grid::Map_iter endIt = protoSubGrid.map_end();
171 for (Grid::Map_iter it = protoSubGrid.map_begin();
176 Array* pMap =
dynamic_cast<Array*
>(*it);
187 return _memberDatasets;
202 if (PRINT_CONSTRAINTS)
212 Array* pAggArray = get_array();
216 if (pAggArray->send_p() || pAggArray->is_in_selection())
232 return _pSubGridProto.get();
240 std::auto_ptr<Grid> pGridTemplateClone(( (rhs._pSubGridProto.get()) ?
241 (static_cast<Grid*>(rhs._pSubGridProto->ptr_duplicate())) :
243 _pSubGridProto = pGridTemplateClone;
245 _memberDatasets = rhs._memberDatasets;
249 GridAggregationBase::cleanup() throw()
253 _memberDatasets.clear();
254 _memberDatasets.resize(0);
271 GridAggregationBase::cloneSubGridProto(
const libdap::Grid& proto)
273 return static_cast<Grid*
>(
const_cast<Grid&
>(proto).ptr_duplicate() );
281 BESDEBUG(
"ncml:2",
"Constraints for Grid: " << name() <<
": " << oss.str() << endl);
294 pSubGridTemplate->set_send_p(send_p());
295 pSubGridTemplate->set_in_selection(is_in_selection());
298 pSubGridTemplate->read();
301 pSubGridTemplate->set_read_p(
true);
311 Map_iter mapEndIt = map_end();
312 for (mapIt = map_begin();
316 Array* pOutMap =
static_cast<Array*
>(*mapIt);
320 if (! (pOutMap->send_p() || pOutMap->is_in_selection()) )
327 if (pOutMap->name() == aggDim.
name)
329 if (PRINT_CONSTRAINTS)
332 "About to call read() on the map for the new outer dimension name=" <<
334 " It's constraints are:" << endl);
346 "Couldn't find map in prototype grid for map name=" + pOutMap->name() );
348 "About to call read() on prototype map vector name="
349 << pOutMap->name() <<
" and calling transfer constraints..." << endl);
353 "Expected the prototype map to have been read but it wasn't.");
357 "Expected the prototype and output maps to have same length() "
358 "after transfer of constraints, but they were not so we can't "
365 pOutMap->reserve_value_capacity();
366 pOutMap->set_value_slice_from_row_major_vector(*pProtoGridMap, 0);
367 pOutMap->set_read_p(
true);
virtual const AMDList & getDatasetList() const
Accessor for the dataset description list that describes this aggregation.
#define BESDEBUG_FUNC(channel, info)
void copyProtoMapsIntoThisGrid(const Dimension &aggDim)
Copy the template's read in subgrid maps into this.
void setShapeFrom(const libdap::Grid &protoSubGrid, bool addMaps)
Use the data array and maps from protoSubGrid as the initial point for the shape of the Grid...
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...
#define NCML_ASSERT_MSG(cond, msg)
GridAggregationBase(const libdap::Grid &proto, const AMDList &memberDatasets, const DDSLoader &loaderProto)
BESDataHandlerInterface & getDHI() const
Return a reference to the dhi we are using.
virtual bool read()
Read in only those datasets that are in the constrained output making sure to apply the internal dime...
void readProtoSubGrid()
Transfer constraints properly from this object's maps and read in the proto subgrid entirely (respect...
void printConstraints(const libdap::Array &fromArray)
Struct for holding information about a dimension of data, minimally a name and a cardinality (size)...
virtual ~GridAggregationBase()
virtual const Dimension & getAggregationDimension() const =0
Get the contained aggregation dimension info.
#define THROW_NCML_INTERNAL_ERROR(msg)
virtual void readAndAggregateConstrainedMapsHook()
Called from read()! Invokes the user hooks eventually.
std::vector< RCPtr< AggMemberDataset > > AMDList
virtual void transferConstraintsToSubGridHook(Grid *pSubGrid)
To be specialized in subclass to copy constraints on this object properly into the given pSubGrid map...
Grid * getSubGridTemplate()
Reveals the raw ptr, but only to subclasses.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
GridAggregationBase & operator=(const GridAggregationBase &rhs)
BaseType * transform_to_dap4(libdap::D4Group *root, libdap::Constructor *container)
static void printConstraints(std::ostream &os, const libdap::Array &fromArray)
Stream out the current constraints for all the dimensions in the Array.
void cleanup()
restore dhi to clean state