OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
AggregationElement.h
Go to the documentation of this file.
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 {
41  struct Dimension;
42 };
43 
44 namespace libdap
45 {
46  class Array;
47  class BaseType;
48  class DDS;
49  class Grid;
50 };
51 
53 using libdap::Array;
54 using libdap::BaseType;
55 using libdap::DDS;
56 using libdap::Grid;
57 using std::auto_ptr;
58 
59 namespace ncml_module
60 {
61  class NetcdfElement;
62  class NCMLParser;
63  class ScanElement;
64 
66  {
67  private:
68  AggregationElement& operator=(const AggregationElement& rhs); // disallow
69 
70  public:
71  // Name of the element
72  static const string _sTypeName;
73 
74  // All possible attributes for this element.
75  static const vector<string> _sValidAttrs;
76 
79  virtual ~AggregationElement();
80  virtual const string& getTypeName() const;
81  virtual AggregationElement* clone() const; // override clone with more specific subclass
82  virtual void setAttributes(const XMLAttributeMap& attrs);
83  virtual void handleBegin();
84  virtual void handleContent(const string& content);
85  virtual void handleEnd();
86  virtual string toString() const;
87 
88  const string& type() const { return _type; }
89  const string& dimName() const {return _dimName; }
90  const string& recheckEvery() const { return _recheckEvery; }
91 
92  bool isJoinNewAggregation() const;
93  bool isUnionAggregation() const;
94  bool isJoinExistingAggregation() const;
95 
96 
103  NetcdfElement* getParentDataset() const { return _parent; }
104 
105 
108  void addChildDataset(NetcdfElement* pDataset);
109 
113  void addAggregationVariable(const string& name);
114 
118  bool isAggregationVariable(const string& name) const;
119 
120  string printAggregationVariables() const;
121 
122  typedef vector<string>::const_iterator AggVarIter;
123  AggVarIter beginAggVarIter() const;
124  AggVarIter endAggVarIter() const;
125 
129  bool gotVariableAggElement() const;
130 
134  void setVariableAggElement();
135 
142  void addScanElement(ScanElement* pScanner);
143 
149 
159  void setAggregationVariableCoordinateAxisType(const std::string& cat);
160 
164  const std::string& getAggregationVariableCoordinateAxisType() const;
165 
166  private: // methods
167 
168  void processUnion();
169  void processJoinNew();
170  void processJoinExisting();
171 
178  void unionAddAllRequiredNonAggregatedVariablesFrom(const DDS& templateDDS);
179 
198  void fillDimensionCacheForJoinExistingDimension(
199  agg_util::AMDList& granuleList,
200  const std::string& aggDimName
201  );
202 
204  bool doesDimensionCacheExist() const;
205 
209  void loadDimensionCacheFromCacheFile(agg_util::AMDList& rGranuleList);
210 
212  bool doesFirstGranuleSpecifyNcoords() const;
213 
215  bool doAllGranulesSpecifyNcoords() const;
216 
221  void seedDimensionCacheFromUserSpecs(agg_util::AMDList& rGranuleList) const;
222 
228  void seedDimensionCacheByQueryOfDatasets(agg_util::AMDList& rGranuleList) const;
229 
235  void addNewDimensionForJoinExisting(const agg_util::AMDList& rGranuleList);
236 
247  void decideWhichVariablesToJoinExist(const libdap::DDS& templateDDS);
248 
262  void findVariablesWithOuterDimensionName(
263  vector<string>& oMatchingVars,
264  const DDS& templateDDS,
265  const string& outerDimName) const;
266 
268  struct JoinAggParams
269  {
270  JoinAggParams()
271  : _pAggVarTemplate(0)
272  , _pAggDim(0)
273  , _memberDatasets()
274  {
275  }
276 
277  ~JoinAggParams()
278  {
279  _pAggVarTemplate = NULL;
280  _pAggDim = NULL;
281  _memberDatasets.clear();
282  _memberDatasets.resize(0);
283  }
284 
285  libdap::BaseType* _pAggVarTemplate; // template for the granule's aggVar
286  const agg_util::Dimension* _pAggDim; // the aggregated dimension (with full size)
287  agg_util::AMDList _memberDatasets; // the granule datasets to use
288  }; // struct JoinAggParams
289 
298  void getParamsForJoinAggOnVariable(
299  JoinAggParams* pOutParams,
300  const DDS& aggOutputDDS,
301  const std::string& varName,
302  const DDS& templateDDS);
303 
312  void processJoinNewOnAggVar(
313  DDS* pAggDDS,
314  const std::string& varName,
315  const DDS& templateDDS);
316 
325  void processJoinExistingOnAggVar(
326  DDS* pAggDDS,
327  const std::string& varName,
328  const DDS& templateDDS);
329 
330 
351  void processAggVarJoinNewForArray(
352  DDS& aggDDS,
353  const Array& arrayTemplate,
354  const agg_util::Dimension& dim,
355  const agg_util::AMDList& memberDatasets );
356 
382  void processAggVarJoinNewForGrid(
383  DDS& aggDDS,
384  const Grid& gridTemplate,
385  const agg_util::Dimension& dim,
386  const agg_util::AMDList& memberDatasets );
387 
388  void processAggVarJoinExistingForArray(
389  DDS& aggDDS,
390  const libdap::Array& arrayTemplate,
391  const agg_util::Dimension& dim,
392  const agg_util::AMDList& memberDatasets );
393 
394  void processAggVarJoinExistingForGrid(
395  DDS& aggDDS,
396  const Grid& gridTemplate,
397  const agg_util::Dimension& dim,
398  const agg_util::AMDList& memberDatasets );
399 
404  void collectDatasetsInOrder(vector<const DDS*>& ddsList) const;
405 
414  void collectAggMemberDatasets(agg_util::AMDList& rMemberDatasets) const;
415 
420  void processAnyScanElements();
421 
433  void mergeDimensions(bool checkDimensionMismatch=true,
434  const std::string& dimToSkip="");
435 
437  void processParentDatasetCompleteForJoinNew();
438 
440  void processParentDatasetCompleteForJoinExisting();
441 
451  void processPlaceholderCoordinateVariableForJoinExisting(
452  const libdap::BaseType& placeholderVar,
453  libdap::Array* pNewVar);
454 
464  libdap::Array* ensureVariableIsProperNewCoordinateVariable(
465  libdap::BaseType* pBT,
466  const agg_util::Dimension& dim,
467  bool throwIfInvalid) const;
468 
492  libdap::Array* findMatchingCoordinateVariable(
493  const DDS& dds,
494  const agg_util::Dimension& dim,
495  bool throwOnInvalidCV=true) const;
496 
519  libdap::Array* processDeferredCoordinateVariable(libdap::BaseType* pBT, const agg_util::Dimension& dim);
520 
541  auto_ptr<libdap::Array> createCoordinateVariableForNewDimension(const agg_util::Dimension& dim) const;
542 
556  libdap::Array* createAndAddCoordinateVariableForNewDimension(libdap::DDS& dds, const agg_util::Dimension& dim);
557 
573  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValue(const agg_util::Dimension& dim) const;
574  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValueAsDouble(const agg_util::Dimension& dim) const;
575  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingCoordValueAsString(const agg_util::Dimension& dim) const;
576 
585  auto_ptr<libdap::Array> createCoordinateVariableForNewDimensionUsingLocation(const agg_util::Dimension& dim) const;
586 
588  static void addCoordinateAxisType(libdap::Array& rCV, const std::string& cat);
589 
590  // Return the list of valid attribute names.
591  static vector<string> getValidAttributes();
592 
593  private: // Data rep
594 
595  string _type; // required oneof { union | joinNew | joinExisting | forecastModelRunCollection | forecastModelSingleRunCollection }
596  string _dimName;
597  string _recheckEvery;
598 
599  // Our containing NetcdfElement, which must exist. This needs to be a weak reference to avoid ref loop....
600  NetcdfElement* _parent;
601 
602  // The vector of explicit, ordered NetcdfElement*. We assume a STRONG reference to these
603  // if they are in this container and we must deref() them on dtor.
604  vector<NetcdfElement*> _datasets;
605 
606  // The vector of scan elements
607  vector<ScanElement*> _scanners;
608 
609  // A vector containing the names of the variables to be aggregated in this aggregation.
610  // Not used for union.
611  vector<string> _aggVars;
612 
613  // Did a variableAgg element set our _aggVars or not?
614  bool _gotVariableAggElement;
615 
616  // Did we add a join existing aggregated Grid to the output yet?
617  // Needed to know if we need to add an aggregated map c.v. to output.
618  bool _wasAggregatedMapAddedForJoinExistingGrid;
619 
620  // If set, we want to create a new attribute _CoordinateAxisType
621  // with this value on each aggVar.
622  std::string _coordinateAxisType;
623 
624  };
625 
626 }
627 
628 #endif /* __NCML_MODULE__AGGREGATION_ELEMENT_H__ */
Abstract helper superclass for allowing lazy access to the DataDDS for an aggregation.
virtual const string & getTypeName() const
Return the type of the element, which should be: the same as ConcreteClassName::getTypeName() ...
bool isAggregationVariable(const string &name) const
virtual void handleContent(const string &content)
Handle the characters content for the element.
An abstract superclass for NCMLArray that handles the non-parameterized functionality and allows u...
void setVariableAggElement()
Should only be used by the VariableAggElement class to let us know it added the vars.
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
void addScanElement(ScanElement *pScanner)
Add a child ScanElement to the Aggregation to be used to to add to the list of child datasets...
Concrete class for NcML element.
Definition: NetcdfElement.h:63
Implementation of the element used to scan directories to create the set of files for an aggre...
Definition: ScanElement.h:50
virtual string toString() const
Return a string describing the element.
static class NCMLUtil overview
void setAggregationVariableCoordinateAxisType(const std::string &cat)
If a child scan contains a dateFormatMark, then we want to add a "_CoordinateAxisType" of "Time" By s...
virtual void handleEnd()
Handle the closing of this element.
#define NULL
Definition: wcsUtil.h:65
NetcdfElement * getParentDataset() const
Struct for holding information about a dimension of data, minimally a name and a cardinality (size)...
Definition: Dimension.h:50
vector< string >::const_iterator AggVarIter
Base class for NcML element concrete classes.
Definition: NCMLElement.h:64
bool gotVariableAggElement() const
whether this aggregation contained a variableAgg element to select aggregation variables.
void processParentDatasetComplete()
Called when the enclosing dataset is closing for the aggregation to handle any post processing that i...
void addChildDataset(NetcdfElement *pDataset)
Add a new dataset to the aggregation for the parse.
static const vector< string > _sValidAttrs
std::vector< RCPtr< AggMemberDataset > > AMDList
virtual void setAttributes(const XMLAttributeMap &attrs)
Set the attributes of this from the map.
const string & dimName() const
const string & type() const
virtual void handleBegin()
Handle a begin on this element.
void addAggregationVariable(const string &name)
Set the variable with name as an aggregation variable for this aggregation.
NetcdfElement * setParentDataset(NetcdfElement *parent)
Set the parent and return the old one, which could be null.
const string & recheckEvery() const
const std::string & getAggregationVariableCoordinateAxisType() const
Return the value set by setAggregationVariableCoordinateAxisType() or "" if none was set...
virtual AggregationElement * clone() const
Make and return a copy of this.