bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
AggregationElement.h
1
2// This file is part of the "NcML Module" project, a BES module designed
3// to allow NcML files to be used to be used as a wrapper to add
4// AIS to existing datasets of any format.
5//
6// Copyright (c) 2009 OPeNDAP, Inc.
7// Author: Michael Johnson <m.johnson@opendap.org>
8//
9// For more information, please also see the main website: http://opendap.org/
10//
11// This library is free software; you can redistribute it and/or
12// modify it under the terms of the GNU Lesser General Public
13// License as published by the Free Software Foundation; either
14// version 2.1 of the License, or (at your option) any later version.
15//
16// This library is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19// Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public
22// License along with this library; if not, write to the Free Software
23// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24//
25// Please see the files COPYING and COPYRIGHT for more information on the GLPL.
26//
27// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
29#ifndef __NCML_MODULE__AGGREGATION_ELEMENT_H__
30#define __NCML_MODULE__AGGREGATION_ELEMENT_H__
31
32#include <memory>
33
34#include "AggMemberDataset.h" // agg_util
35#include "AggregationUtil.h" // agg_util
36#include "ArrayJoinExistingAggregation.h" // agg_util
37
38#include "NCMLElement.h"
39#include "NCMLUtil.h"
40
41namespace agg_util {
42struct Dimension;
43}
44
45namespace libdap {
46class Array;
47class BaseType;
48class DDS;
49class Grid;
50}
51
53using libdap::Array;
54using libdap::BaseType;
55using libdap::DDS;
56using libdap::Grid;
57
58namespace ncml_module {
59class NetcdfElement;
60class NCMLParser;
61class ScanElement;
62
63class AggregationElement: public NCMLElement {
64private:
65 AggregationElement& operator=(const AggregationElement& rhs); // disallow
66
67public:
68 // Name of the element
69 static const string _sTypeName;
70
71 // All possible attributes for this element.
72 static const vector<string> _sValidAttrs;
73
74 AggregationElement();
75 AggregationElement(const AggregationElement& proto);
76 virtual ~AggregationElement();
77 virtual const string& getTypeName() const;
78 virtual AggregationElement* clone() const; // override clone with more specific subclass
79 virtual void setAttributes(const XMLAttributeMap& attrs);
80 virtual void handleBegin();
81 virtual void handleContent(const string& content);
82 virtual void handleEnd();
83 virtual string toString() const;
84
85 const string& type() const
86 {
87 return _type;
88 }
89 const string& dimName() const
90 {
91 return _dimName;
92 }
93 const string& recheckEvery() const
94 {
95 return _recheckEvery;
96 }
97
98 bool isJoinNewAggregation() const;
99 bool isUnionAggregation() const;
100 bool isJoinExistingAggregation() const;
101
108 NetcdfElement* getParentDataset() const
109 {
110 return _parent;
111 }
112
116
120 void addAggregationVariable(const string& name);
121
125 bool isAggregationVariable(const string& name) const;
126
127 string printAggregationVariables() const;
128
129 typedef vector<string>::const_iterator AggVarIter;
130 AggVarIter beginAggVarIter() const;
131 AggVarIter endAggVarIter() const;
132
137
142
150
156
166 void setAggregationVariableCoordinateAxisType(const std::string& cat);
167
172
173private:
174 // methods
175
176 void processUnion();
177 void processJoinNew();
178 void processJoinExisting();
179
186 void unionAddAllRequiredNonAggregatedVariablesFrom(const DDS& templateDDS);
187
206 void fillDimensionCacheForJoinExistingDimension(agg_util::AMDList& granuleList, const std::string& aggDimName);
207
209 bool doesFirstGranuleSpecifyNcoords() const;
210
212 bool doAllGranulesSpecifyNcoords() const;
213
218 void seedDimensionCacheFromUserSpecs(agg_util::AMDList& rGranuleList) const;
219
225 void addNewDimensionForJoinExisting(const agg_util::AMDList& rGranuleList);
226
237 void decideWhichVariablesToJoinExist(const libdap::DDS& templateDDS);
238
252 void findVariablesWithOuterDimensionName(vector<string>& oMatchingVars, const DDS& templateDDS,
253 const string& outerDimName) const;
254
256 struct JoinAggParams {
257 JoinAggParams() :
258 _pAggVarTemplate(0), _pAggDim(0), _memberDatasets()
259 {
260 }
261
262 ~JoinAggParams()
263 {
264 _pAggVarTemplate = NULL;
265 _pAggDim = NULL;
266 _memberDatasets.clear();
267 _memberDatasets.resize(0);
268 }
269
270 libdap::BaseType* _pAggVarTemplate; // template for the granule's aggVar
271 const agg_util::Dimension* _pAggDim; // the aggregated dimension (with full size)
272 agg_util::AMDList _memberDatasets; // the granule datasets to use
273 }; // struct JoinAggParams
274
283 void getParamsForJoinAggOnVariable(JoinAggParams* pOutParams, const DDS& aggOutputDDS, const std::string& varName,
284 const DDS& templateDDS);
285
294 void processJoinNewOnAggVar(DDS* pAggDDS, const std::string& varName, const DDS& templateDDS);
295
304 void processJoinExistingOnAggVar(DDS* pAggDDS, const std::string& varName, const DDS& templateDDS);
305
326 static void processAggVarJoinNewForArray(DDS& aggDDS, const Array& arrayTemplate, const agg_util::Dimension& dim,
327 const agg_util::AMDList& memberDatasets);
328
354 void processAggVarJoinNewForGrid(DDS& aggDDS, const Grid& gridTemplate, const agg_util::Dimension& dim,
355 const agg_util::AMDList& memberDatasets);
356
357 static void processAggVarJoinExistingForArray(DDS& aggDDS, const libdap::Array& arrayTemplate,
358 const agg_util::Dimension& dim, const agg_util::AMDList& memberDatasets);
359
360 void processAggVarJoinExistingForGrid(DDS& aggDDS, const Grid& gridTemplate, const agg_util::Dimension& dim,
361 const agg_util::AMDList& memberDatasets);
362
367 void collectDatasetsInOrder(vector<const DDS*>& ddsList) const;
368
377 void collectAggMemberDatasets(agg_util::AMDList& rMemberDatasets) const;
378
383 void processAnyScanElements();
384
396 void mergeDimensions(bool checkDimensionMismatch = true, const std::string& dimToSkip = "");
397
399 void processParentDatasetCompleteForJoinNew();
400
402 void processParentDatasetCompleteForJoinExisting();
403
413 void processPlaceholderCoordinateVariableForJoinExisting(const libdap::BaseType& placeholderVar,
414 libdap::Array* pNewVar);
415
425 libdap::Array* ensureVariableIsProperNewCoordinateVariable(libdap::BaseType* pBT, const agg_util::Dimension& dim,
426 bool throwIfInvalid) const;
427
451 libdap::Array* findMatchingCoordinateVariable(const DDS& dds, const agg_util::Dimension& dim,
452 bool throwOnInvalidCV = true) const;
453
476 libdap::Array* processDeferredCoordinateVariable(libdap::BaseType* pBT, const agg_util::Dimension& dim);
477
498 std::unique_ptr<libdap::Array> createCoordinateVariableForNewDimension(const agg_util::Dimension& dim) const;
499
513 libdap::Array* createAndAddCoordinateVariableForNewDimension(libdap::DDS& dds, const agg_util::Dimension& dim);
514
530 std::unique_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValue(
531 const agg_util::Dimension& dim) const;
532 std::unique_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValueAsDouble(
533 const agg_util::Dimension& dim) const;
534 std::unique_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValueAsString(
535 const agg_util::Dimension& dim) const;
536
545 std::unique_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingLocation(const agg_util::Dimension& dim) const;
546
548 static void addCoordinateAxisType(libdap::Array& rCV, const std::string& cat);
549
550 // Return the list of valid attribute names.
551 static vector<string> getValidAttributes();
552
553private:
554 // Data rep
555
556 string _type; // required oneof { union | joinNew | joinExisting | forecastModelRunCollection | forecastModelSingleRunCollection }
557 string _dimName;
558 string _recheckEvery;
559
560 // Our containing NetcdfElement, which must exist. This needs to be a weak reference to avoid ref loop....
561 NetcdfElement* _parent;
562
563 // The vector of explicit, ordered NetcdfElement*. We assume a STRONG reference to these
564 // if they are in this container and we must deref() them on dtor.
565 vector<NetcdfElement*> _datasets;
566
567 // The vector of scan elements
568 vector<ScanElement*> _scanners;
569
570 // A vector containing the names of the variables to be aggregated in this aggregation.
571 // Not used for union.
572 vector<string> _aggVars;
573
574 // Did a variableAgg element set our _aggVars or not?
575 bool _gotVariableAggElement;
576
577 // Did we add a join existing aggregated Grid to the output yet?
578 // Needed to know if we need to add an aggregated map c.v. to output.
579 bool _wasAggregatedMapAddedForJoinExistingGrid;
580
581 // If set, we want to create a new attribute _CoordinateAxisType
582 // with this value on each aggVar.
583 std::string _coordinateAxisType;
584
585};
586
587}
588
589#endif /* __NCML_MODULE__AGGREGATION_ELEMENT_H__ */
virtual void setAttributes(const XMLAttributeMap &attrs)
const std::string & getAggregationVariableCoordinateAxisType() const
void setAggregationVariableCoordinateAxisType(const std::string &cat)
void addChildDataset(NetcdfElement *pDataset)
NetcdfElement * setParentDataset(NetcdfElement *parent)
virtual string toString() const
void addScanElement(ScanElement *pScanner)
bool isAggregationVariable(const string &name) const
virtual const string & getTypeName() const
void addAggregationVariable(const string &name)
virtual AggregationElement * clone() const
Concrete class for NcML <netcdf> element.
STL iterator class.
STL class.
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...