bes  Updated for version 3.20.5
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 using std::auto_ptr;
56 
57 namespace ncml_module {
58 class NetcdfElement;
59 class NCMLParser;
60 class ScanElement;
61 
63 private:
64  AggregationElement& operator=(const AggregationElement& rhs); // disallow
65 
66 public:
67  // Name of the element
68  static const string _sTypeName;
69 
70  // All possible attributes for this element.
71  static const vector<string> _sValidAttrs;
72 
75  virtual ~AggregationElement();
76  virtual const string& getTypeName() const;
77  virtual AggregationElement* clone() const; // override clone with more specific subclass
78  virtual void setAttributes(const XMLAttributeMap& attrs);
79  virtual void handleBegin();
80  virtual void handleContent(const string& content);
81  virtual void handleEnd();
82  virtual string toString() const;
83 
84  const string& type() const
85  {
86  return _type;
87  }
88  const string& dimName() const
89  {
90  return _dimName;
91  }
92  const string& recheckEvery() const
93  {
94  return _recheckEvery;
95  }
96 
97  bool isJoinNewAggregation() const;
98  bool isUnionAggregation() const;
99  bool isJoinExistingAggregation() const;
100 
107  NetcdfElement* getParentDataset() const
108  {
109  return _parent;
110  }
111 
114  void addChildDataset(NetcdfElement* pDataset);
115 
119  void addAggregationVariable(const string& name);
120 
124  bool isAggregationVariable(const string& name) const;
125 
126  string printAggregationVariables() const;
127 
128  typedef vector<string>::const_iterator AggVarIter;
129  AggVarIter beginAggVarIter() const;
130  AggVarIter endAggVarIter() const;
131 
135  bool gotVariableAggElement() const;
136 
140  void setVariableAggElement();
141 
148  void addScanElement(ScanElement* pScanner);
149 
155 
165  void setAggregationVariableCoordinateAxisType(const std::string& cat);
166 
170  const std::string& getAggregationVariableCoordinateAxisType() const;
171 
172 private:
173  // methods
174 
175  void processUnion();
176  void processJoinNew();
177  void processJoinExisting();
178 
185  void unionAddAllRequiredNonAggregatedVariablesFrom(const DDS& templateDDS);
186 
205  void fillDimensionCacheForJoinExistingDimension(agg_util::AMDList& granuleList, const std::string& aggDimName);
206 
208  bool doesFirstGranuleSpecifyNcoords() const;
209 
211  bool doAllGranulesSpecifyNcoords() const;
212 
217  void seedDimensionCacheFromUserSpecs(agg_util::AMDList& rGranuleList) const;
218 
224  void addNewDimensionForJoinExisting(const agg_util::AMDList& rGranuleList);
225 
236  void decideWhichVariablesToJoinExist(const libdap::DDS& templateDDS);
237 
251  void findVariablesWithOuterDimensionName(vector<string>& oMatchingVars, const DDS& templateDDS,
252  const string& outerDimName) const;
253 
255  struct JoinAggParams {
256  JoinAggParams() :
257  _pAggVarTemplate(0), _pAggDim(0), _memberDatasets()
258  {
259  }
260 
261  ~JoinAggParams()
262  {
263  _pAggVarTemplate = NULL;
264  _pAggDim = NULL;
265  _memberDatasets.clear();
266  _memberDatasets.resize(0);
267  }
268 
269  libdap::BaseType* _pAggVarTemplate; // template for the granule's aggVar
270  const agg_util::Dimension* _pAggDim; // the aggregated dimension (with full size)
271  agg_util::AMDList _memberDatasets; // the granule datasets to use
272  }; // struct JoinAggParams
273 
282  void getParamsForJoinAggOnVariable(JoinAggParams* pOutParams, const DDS& aggOutputDDS, const std::string& varName,
283  const DDS& templateDDS);
284 
293  void processJoinNewOnAggVar(DDS* pAggDDS, const std::string& varName, const DDS& templateDDS);
294 
303  void processJoinExistingOnAggVar(DDS* pAggDDS, const std::string& varName, const DDS& templateDDS);
304 
325  void processAggVarJoinNewForArray(DDS& aggDDS, const Array& arrayTemplate, const agg_util::Dimension& dim,
326  const agg_util::AMDList& memberDatasets);
327 
353  void processAggVarJoinNewForGrid(DDS& aggDDS, const Grid& gridTemplate, const agg_util::Dimension& dim,
354  const agg_util::AMDList& memberDatasets);
355 
356  void processAggVarJoinExistingForArray(DDS& aggDDS, const libdap::Array& arrayTemplate,
357  const agg_util::Dimension& dim, const agg_util::AMDList& memberDatasets);
358 
359  void processAggVarJoinExistingForGrid(DDS& aggDDS, const Grid& gridTemplate, const agg_util::Dimension& dim,
360  const agg_util::AMDList& memberDatasets);
361 
366  void collectDatasetsInOrder(vector<const DDS*>& ddsList) const;
367 
376  void collectAggMemberDatasets(agg_util::AMDList& rMemberDatasets) const;
377 
382  void processAnyScanElements();
383 
395  void mergeDimensions(bool checkDimensionMismatch = true, const std::string& dimToSkip = "");
396 
398  void processParentDatasetCompleteForJoinNew();
399 
401  void processParentDatasetCompleteForJoinExisting();
402 
412  void processPlaceholderCoordinateVariableForJoinExisting(const libdap::BaseType& placeholderVar,
413  libdap::Array* pNewVar);
414 
424  libdap::Array* ensureVariableIsProperNewCoordinateVariable(libdap::BaseType* pBT, const agg_util::Dimension& dim,
425  bool throwIfInvalid) const;
426 
450  libdap::Array* findMatchingCoordinateVariable(const DDS& dds, const agg_util::Dimension& dim,
451  bool throwOnInvalidCV = true) const;
452 
475  libdap::Array* processDeferredCoordinateVariable(libdap::BaseType* pBT, const agg_util::Dimension& dim);
476 
497  auto_ptr<libdap::Array> createCoordinateVariableForNewDimension(const agg_util::Dimension& dim) const;
498 
512  libdap::Array* createAndAddCoordinateVariableForNewDimension(libdap::DDS& dds, const agg_util::Dimension& dim);
513 
529  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValue(
530  const agg_util::Dimension& dim) const;
531  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValueAsDouble(
532  const agg_util::Dimension& dim) const;
533  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValueAsString(
534  const agg_util::Dimension& dim) const;
535 
544  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingLocation(const agg_util::Dimension& dim) const;
545 
547  static void addCoordinateAxisType(libdap::Array& rCV, const std::string& cat);
548 
549  // Return the list of valid attribute names.
550  static vector<string> getValidAttributes();
551 
552 private:
553  // Data rep
554 
555  string _type; // required oneof { union | joinNew | joinExisting | forecastModelRunCollection | forecastModelSingleRunCollection }
556  string _dimName;
557  string _recheckEvery;
558 
559  // Our containing NetcdfElement, which must exist. This needs to be a weak reference to avoid ref loop....
560  NetcdfElement* _parent;
561 
562  // The vector of explicit, ordered NetcdfElement*. We assume a STRONG reference to these
563  // if they are in this container and we must deref() them on dtor.
564  vector<NetcdfElement*> _datasets;
565 
566  // The vector of scan elements
567  vector<ScanElement*> _scanners;
568 
569  // A vector containing the names of the variables to be aggregated in this aggregation.
570  // Not used for union.
571  vector<string> _aggVars;
572 
573  // Did a variableAgg element set our _aggVars or not?
574  bool _gotVariableAggElement;
575 
576  // Did we add a join existing aggregated Grid to the output yet?
577  // Needed to know if we need to add an aggregated map c.v. to output.
578  bool _wasAggregatedMapAddedForJoinExistingGrid;
579 
580  // If set, we want to create a new attribute _CoordinateAxisType
581  // with this value on each aggVar.
582  std::string _coordinateAxisType;
583 
584 };
585 
586 }
587 
588 #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::AggregationElement::handleContent
virtual void handleContent(const string &content)
Definition: AggregationElement.cc:192
ncml_module::XMLAttributeMap
Definition: XMLHelpers.h:96
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:62
ncml_module::NCMLElement
Base class for NcML element concrete classes.
Definition: NCMLElement.h:63
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