bes  Updated for version 3.20.6
AggregationElement.h
1 // 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 "AggMemberDataset.h" // agg_util
33 #include "AggregationUtil.h" // agg_util
34 #include "ArrayJoinExistingAggregation.h" // agg_util
35 #include <memory>
36 #include "NCMLElement.h"
37 #include "NCMLUtil.h"
38 
39 namespace agg_util {
40 struct Dimension;
41 }
42 
43 namespace libdap {
44 class Array;
45 class BaseType;
46 class DDS;
47 class Grid;
48 }
49 
51 using libdap::Array;
52 using libdap::BaseType;
53 using libdap::DDS;
54 using libdap::Grid;
55 
56 namespace ncml_module {
57 class NetcdfElement;
58 class NCMLParser;
59 class ScanElement;
60 
62 private:
63  AggregationElement& operator=(const AggregationElement& rhs); // disallow
64 
65 public:
66  // Name of the element
67  static const string _sTypeName;
68 
69  // All possible attributes for this element.
70  static const vector<string> _sValidAttrs;
71 
74  virtual ~AggregationElement();
75  virtual const string& getTypeName() const;
76  virtual AggregationElement* clone() const; // override clone with more specific subclass
77  virtual void setAttributes(const XMLAttributeMap& attrs);
78  virtual void handleBegin();
79  virtual void handleContent(const string& content);
80  virtual void handleEnd();
81  virtual string toString() const;
82 
83  const string& type() const
84  {
85  return _type;
86  }
87  const string& dimName() const
88  {
89  return _dimName;
90  }
91  const string& recheckEvery() const
92  {
93  return _recheckEvery;
94  }
95 
96  bool isJoinNewAggregation() const;
97  bool isUnionAggregation() const;
98  bool isJoinExistingAggregation() const;
99 
106  NetcdfElement* getParentDataset() const
107  {
108  return _parent;
109  }
110 
113  void addChildDataset(NetcdfElement* pDataset);
114 
118  void addAggregationVariable(const string& name);
119 
123  bool isAggregationVariable(const string& name) const;
124 
125  string printAggregationVariables() const;
126 
127  typedef vector<string>::const_iterator AggVarIter;
128  AggVarIter beginAggVarIter() const;
129  AggVarIter endAggVarIter() const;
130 
134  bool gotVariableAggElement() const;
135 
139  void setVariableAggElement();
140 
147  void addScanElement(ScanElement* pScanner);
148 
154 
164  void setAggregationVariableCoordinateAxisType(const std::string& cat);
165 
169  const std::string& getAggregationVariableCoordinateAxisType() const;
170 
171 private:
172  // methods
173 
174  void processUnion();
175  void processJoinNew();
176  void processJoinExisting();
177 
184  void unionAddAllRequiredNonAggregatedVariablesFrom(const DDS& templateDDS);
185 
204  void fillDimensionCacheForJoinExistingDimension(agg_util::AMDList& granuleList, const std::string& aggDimName);
205 
207  bool doesFirstGranuleSpecifyNcoords() const;
208 
210  bool doAllGranulesSpecifyNcoords() const;
211 
216  void seedDimensionCacheFromUserSpecs(agg_util::AMDList& rGranuleList) const;
217 
223  void addNewDimensionForJoinExisting(const agg_util::AMDList& rGranuleList);
224 
235  void decideWhichVariablesToJoinExist(const libdap::DDS& templateDDS);
236 
250  void findVariablesWithOuterDimensionName(vector<string>& oMatchingVars, const DDS& templateDDS,
251  const string& outerDimName) const;
252 
254  struct JoinAggParams {
255  JoinAggParams() :
256  _pAggVarTemplate(0), _pAggDim(0), _memberDatasets()
257  {
258  }
259 
260  ~JoinAggParams()
261  {
262  _pAggVarTemplate = NULL;
263  _pAggDim = NULL;
264  _memberDatasets.clear();
265  _memberDatasets.resize(0);
266  }
267 
268  libdap::BaseType* _pAggVarTemplate; // template for the granule's aggVar
269  const agg_util::Dimension* _pAggDim; // the aggregated dimension (with full size)
270  agg_util::AMDList _memberDatasets; // the granule datasets to use
271  }; // struct JoinAggParams
272 
281  void getParamsForJoinAggOnVariable(JoinAggParams* pOutParams, const DDS& aggOutputDDS, const std::string& varName,
282  const DDS& templateDDS);
283 
292  void processJoinNewOnAggVar(DDS* pAggDDS, const std::string& varName, const DDS& templateDDS);
293 
302  void processJoinExistingOnAggVar(DDS* pAggDDS, const std::string& varName, const DDS& templateDDS);
303 
324  void processAggVarJoinNewForArray(DDS& aggDDS, const Array& arrayTemplate, const agg_util::Dimension& dim,
325  const agg_util::AMDList& memberDatasets);
326 
352  void processAggVarJoinNewForGrid(DDS& aggDDS, const Grid& gridTemplate, const agg_util::Dimension& dim,
353  const agg_util::AMDList& memberDatasets);
354 
355  void processAggVarJoinExistingForArray(DDS& aggDDS, const libdap::Array& arrayTemplate,
356  const agg_util::Dimension& dim, const agg_util::AMDList& memberDatasets);
357 
358  void processAggVarJoinExistingForGrid(DDS& aggDDS, const Grid& gridTemplate, const agg_util::Dimension& dim,
359  const agg_util::AMDList& memberDatasets);
360 
365  void collectDatasetsInOrder(vector<const DDS*>& ddsList) const;
366 
375  void collectAggMemberDatasets(agg_util::AMDList& rMemberDatasets) const;
376 
381  void processAnyScanElements();
382 
394  void mergeDimensions(bool checkDimensionMismatch = true, const std::string& dimToSkip = "");
395 
397  void processParentDatasetCompleteForJoinNew();
398 
400  void processParentDatasetCompleteForJoinExisting();
401 
411  void processPlaceholderCoordinateVariableForJoinExisting(const libdap::BaseType& placeholderVar,
412  libdap::Array* pNewVar);
413 
423  libdap::Array* ensureVariableIsProperNewCoordinateVariable(libdap::BaseType* pBT, const agg_util::Dimension& dim,
424  bool throwIfInvalid) const;
425 
449  libdap::Array* findMatchingCoordinateVariable(const DDS& dds, const agg_util::Dimension& dim,
450  bool throwOnInvalidCV = true) const;
451 
474  libdap::Array* processDeferredCoordinateVariable(libdap::BaseType* pBT, const agg_util::Dimension& dim);
475 
496  auto_ptr<libdap::Array> createCoordinateVariableForNewDimension(const agg_util::Dimension& dim) const;
497 
511  libdap::Array* createAndAddCoordinateVariableForNewDimension(libdap::DDS& dds, const agg_util::Dimension& dim);
512 
528  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValue(
529  const agg_util::Dimension& dim) const;
530  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValueAsDouble(
531  const agg_util::Dimension& dim) const;
532  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValueAsString(
533  const agg_util::Dimension& dim) const;
534 
543  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingLocation(const agg_util::Dimension& dim) const;
544 
546  static void addCoordinateAxisType(libdap::Array& rCV, const std::string& cat);
547 
548  // Return the list of valid attribute names.
549  static vector<string> getValidAttributes();
550 
551 private:
552  // Data rep
553 
554  string _type; // required oneof { union | joinNew | joinExisting | forecastModelRunCollection | forecastModelSingleRunCollection }
555  string _dimName;
556  string _recheckEvery;
557 
558  // Our containing NetcdfElement, which must exist. This needs to be a weak reference to avoid ref loop....
559  NetcdfElement* _parent;
560 
561  // The vector of explicit, ordered NetcdfElement*. We assume a STRONG reference to these
562  // if they are in this container and we must deref() them on dtor.
563  vector<NetcdfElement*> _datasets;
564 
565  // The vector of scan elements
566  vector<ScanElement*> _scanners;
567 
568  // A vector containing the names of the variables to be aggregated in this aggregation.
569  // Not used for union.
570  vector<string> _aggVars;
571 
572  // Did a variableAgg element set our _aggVars or not?
573  bool _gotVariableAggElement;
574 
575  // Did we add a join existing aggregated Grid to the output yet?
576  // Needed to know if we need to add an aggregated map c.v. to output.
577  bool _wasAggregatedMapAddedForJoinExistingGrid;
578 
579  // If set, we want to create a new attribute _CoordinateAxisType
580  // with this value on each aggVar.
581  std::string _coordinateAxisType;
582 
583 };
584 
585 }
586 
587 #endif /* __NCML_MODULE__AGGREGATION_ELEMENT_H__ */
ncml_module::AggregationElement::addScanElement
void addScanElement(ScanElement *pScanner)
Definition: AggregationElement.cc:326
ncml_module::AggregationElement::handleEnd
virtual void handleEnd()
Definition: AggregationElement.cc:202
ncml_module::AggregationElement::clone
virtual AggregationElement * clone() const
Definition: AggregationElement.cc:145
ncml_module::AggregationElement::addChildDataset
void addChildDataset(NetcdfElement *pDataset)
Definition: AggregationElement.cc:254
ncml_module::AggregationElement::setAttributes
virtual void setAttributes(const XMLAttributeMap &attrs)
Definition: AggregationElement.cc:150
ncml_module::AggregationElement::setParentDataset
NetcdfElement * setParentDataset(NetcdfElement *parent)
Private Impl.
Definition: AggregationElement.cc:350
ncml_module::NetcdfElement
Concrete class for NcML <netcdf> element.
Definition: NetcdfElement.h:62
agg_util::Dimension
Definition: Dimension.h:49
ncml_module::AggregationElement::setAggregationVariableCoordinateAxisType
void setAggregationVariableCoordinateAxisType(const std::string &cat)
Definition: AggregationElement.cc:1133
ncml_module::AggregationElement::processParentDatasetComplete
void processParentDatasetComplete()
Definition: AggregationElement.cc:334
ncml_module::AggregationElement::handleBegin
virtual void handleBegin()
Definition: AggregationElement.cc:160
ncml_module::AggregationElement::addAggregationVariable
void addAggregationVariable(const string &name)
Definition: AggregationElement.cc:267
ncml_module::XMLAttributeMap
Definition: XMLHelpers.h:93
agg_util
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
Definition: AggMemberDataset.cc:38
ncml_module::ScanElement
Definition: ScanElement.h:48
libdap
Definition: BESDapFunctionResponseCache.h:35
ncml_module::AggregationElement::getAggregationVariableCoordinateAxisType
const std::string & getAggregationVariableCoordinateAxisType() const
Definition: AggregationElement.cc:1139
ncml_module::AggregationElement
Definition: AggregationElement.h:61
ncml_module::NCMLElement
Base class for NcML element concrete classes.
Definition: NCMLElement.h:61
ncml_module::AggregationElement::setVariableAggElement
void setVariableAggElement()
Definition: AggregationElement.cc:321
ncml_module::AggregationElement::gotVariableAggElement
bool gotVariableAggElement() const
Definition: AggregationElement.cc:316
agg_util::AggMemberDataset
Definition: AggMemberDataset.h:63
ncml_module
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
Definition: AggregationElement.cc:72
ncml_module::AggregationElement::isAggregationVariable
bool isAggregationVariable(const string &name) const
Definition: AggregationElement.cc:279
ncml_module::AggregationElement::getTypeName
virtual const string & getTypeName() const
Definition: AggregationElement.cc:139
ncml_module::AggregationElement::toString
virtual string toString() const
Definition: AggregationElement.cc:233