34 #include "Constructor.h"
42 using libdap::BaseType;
43 using libdap::Constructor;
44 using libdap::DataDDS;
47 static const string DEBUG_CHANNEL(
"agg_util");
53 static const unsigned int DIMENSION_CACHE_INITIAL_SIZE = 4;
56 const std::string& location)
58 , _dimensionCache(DIMENSION_CACHE_INITIAL_SIZE)
65 _dimensionCache.clear();
66 _dimensionCache.resize(0);
73 , _dimensionCache(proto._dimensionCache)
84 _dimensionCache.clear();
85 _dimensionCache = rhs._dimensionCache;
93 const std::string& dimName)
const
103 std::ostringstream oss;
104 oss << __PRETTY_FUNCTION__
107 <<
" was not found in the cache!";
115 const std::string& dimName)
const
118 const_cast<AggMemberDatasetWithDimensionCacheBase*>(
this)->findDimension(dimName)
137 std::ostringstream msg;
138 msg << __PRETTY_FUNCTION__ <<
141 <<
" already exists and we were asked to set uniquely!";
147 _dimensionCache.push_back(dim);
156 DataDDS* pDDS =
const_cast<DataDDS*
>(
getDataDDS());
160 for (DataDDS::Vars_iter it = pDDS->var_begin();
161 it != pDDS->var_end();
166 addDimensionsForVariableRecursive(*pBT);
174 _dimensionCache.clear();
181 saveDimensionCacheInternal(ostr);
188 loadDimensionCacheInternal(istr);
192 AggMemberDatasetWithDimensionCacheBase::findDimension(
193 const std::string& dimName)
196 for (vector<Dimension>::iterator it = _dimensionCache.begin();
197 it != _dimensionCache.end();
200 if (it->name == dimName)
209 AggMemberDatasetWithDimensionCacheBase::addDimensionsForVariableRecursive(libdap::BaseType& var)
211 BESDEBUG_FUNC(DEBUG_CHANNEL,
"Adding dimensions for variable name="
215 if (var.type() == libdap::dods_array_c)
218 " Adding dimensions for array variable name = "
222 libdap::Array& arrVar =
dynamic_cast<libdap::Array&
>(var);
223 libdap::Array::Dim_iter it;
224 for (it = arrVar.dim_begin(); it != arrVar.dim_end(); ++it)
226 libdap::Array::dimension& dim = *it;
229 Dimension newDim(dim.name, dim.size);
233 " Adding dimension: "
235 <<
" to the dataset granule cache..."
241 else if (var.is_constructor_type())
244 " Recursing on all variables for constructor variable name = "
248 libdap::Constructor& containerVar =
dynamic_cast<libdap::Constructor&
>(var);
249 libdap::Constructor::Vars_iter it;
250 for (it = containerVar.var_begin(); it != containerVar.var_end(); ++it)
253 " Recursing on variable name="
257 addDimensionsForVariableRecursive( *(*it) );
263 static bool sIsDimNameLessThan(
const Dimension& lhs,
const Dimension& rhs)
265 return (lhs.name < rhs.name);
269 AggMemberDatasetWithDimensionCacheBase::saveDimensionCacheInternal(std::ostream& ostr)
271 BESDEBUG(
"agg_util",
"Saving dimension cache for dataset location = "
276 std::sort(_dimensionCache.begin(), _dimensionCache.end(), sIsDimNameLessThan);
283 unsigned int n = _dimensionCache.size();
285 for (
unsigned int i=0; i<n; ++i)
287 const Dimension& dim = _dimensionCache.at(i);
289 ostr << dim.name <<
'\n' << dim.size <<
'\n';
294 AggMemberDatasetWithDimensionCacheBase::loadDimensionCacheInternal(std::istream& istr)
296 BESDEBUG(
"agg_util",
"Loading dimension cache for dataset location = "
302 getline(istr, loc,
'\n');
309 ss <<
"Serialization error: the location loaded from the "
310 "dimensions cache was: \"" << loc <<
"\" but we expected it to be "
317 for (
unsigned int i=0; i<n; ++i)
320 istr >> newDim.name >> ws;
321 istr >> newDim.size >> ws;
Abstract helper superclass for allowing lazy access to the DataDDS for an aggregation.
virtual bool isDimensionCached(const std::string &dimName) const
Return whether the dimension is already cached, or would have to be loaded to be found.
#define BESDEBUG_FUNC(channel, info)
AggMemberDatasetWithDimensionCacheBase(const std::string &location)
virtual void setDimensionCacheFor(const Dimension &dim, bool throwIfFound)
Seed the dimension cache using the given dimension, so that later calls to getDimensionSize for dim...
virtual unsigned int getCachedDimensionSize(const std::string &dimName) const
Get the size of the given dimension named dimName cached within the dataset.
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
virtual void loadDimensionCache(std::istream &istr)
Load the values in the dimension cache from the input stream.
virtual ~AggMemberDatasetWithDimensionCacheBase()
Basic information subclass for cases of dimension not found in an aggregation.
AggMemberDatasetWithDimensionCacheBase & operator=(const AggMemberDatasetWithDimensionCacheBase &rhs)
const std::string & getLocation() const
The location to which the AggMemberDataset refers Note: this could be "" for some subclasses if they ...
virtual const libdap::DataDDS * getDataDDS()=0
Return the DataDDS for the location, loading it in if it hasn't yet been loaded.
Struct for holding information about a dimension of data, minimally a name and a cardinality (size)...
virtual void flushDimensionCache()
Flush out any cache for the Dimensions so that it will have to be loaded.
AggMemberDataset & operator=(const AggMemberDataset &rhs)
#define THROW_NCML_INTERNAL_ERROR(msg)
virtual void saveDimensionCache(std::ostream &ostr)
Append the values in the dimension cache to the output stream.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Exception class used by AggregationUtil and other agg_util classes to pass generic exceptions upward ...
virtual void fillDimensionCacheByUsingDataDDS()
Uses the getDataDDS() call in order to find all named dimensions within it and to seed them into the ...
Interface class for a reference counted object.