OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
ArrayAggregationBase.cc
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) 2010 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 
30 #include "ArrayAggregationBase.h"
31 #include "NCMLDebug.h"
32 
33 // BES debug channel we output to
34 static const string DEBUG_CHANNEL("agg_util");
35 
36 // Local flag for whether to print constraints, to help debugging
37 static const bool PRINT_CONSTRAINTS = true;
38 
39 using libdap::Array;
40 
41 namespace agg_util
42 {
44  const libdap::Array& proto,
45  const AMDList& aggMembers,
46  std::auto_ptr<ArrayGetterInterface>& arrayGetter)
47  : Array(proto)
48  , _pSubArrayProto(static_cast<Array*>(const_cast<Array&>(proto).ptr_duplicate()))
49  , _pArrayGetter(arrayGetter)
50  , _datasetDescs(aggMembers)
51  {
52  }
53 
55  : Array(rhs)
56  , _pSubArrayProto(0) // duplicate() handles this
57  , _pArrayGetter(0) // duplicate() handles this
58  , _datasetDescs()
59  {
60  BESDEBUG(DEBUG_CHANNEL,
61  "ArrayAggregationBase() copy ctor called!" <<
62  endl);
63  duplicate(rhs);
64  }
65 
66  /* virtual */
68  {
69  cleanup();
70  }
71 
74  {
75  if (this != &rhs)
76  {
77  cleanup();
78  Array::operator=(rhs);
79  duplicate(rhs);
80  }
81  return *this;
82  }
83 
84  /* virtual */
87  {
88  return new ArrayAggregationBase(*this);
89  }
90 
91  /* virtual */
92  bool
94  {
95  BESDEBUG_FUNC(DEBUG_CHANNEL, " function entered..." << endl);
96 
97  // Early exit if already done, avoid doing it twice!
98  if (read_p())
99  {
100  BESDEBUG_FUNC(DEBUG_CHANNEL, "read_p() set, early exit!");
101  return true;
102  }
103 
104  // Only continue if we are supposed to serialize this object at all.
105  if (! (send_p() || is_in_selection()) )
106  {
107  BESDEBUG_FUNC(DEBUG_CHANNEL,
108  "Object not in output, skipping... name=" <<
109  name() <<
110  endl);
111  return true;
112  }
113 
114  if (PRINT_CONSTRAINTS)
115  {
116  BESDEBUG_FUNC(DEBUG_CHANNEL,
117  "Constraints on this Array are:" <<
118  endl);
119  printConstraints(*this);
120  }
121 
122  // call subclass impl
124 
125  if (PRINT_CONSTRAINTS)
126  {
127  BESDEBUG_FUNC(DEBUG_CHANNEL,
128  "After transfer, constraints on the member template Array are: " <<
129  endl);
131  }
132 
133  // Call the subclass specific algorithms to do the read
134  // and stream
136 
137  // Set the cache bit to avoid recomputing
138  set_read_p(true);
139  return true;
140  }
141 
142 
143  const AMDList&
145  {
146  return _datasetDescs;
147  }
148 
150 
151  void
153  {
154  ostringstream oss;
155  AggregationUtil::printConstraints(oss, fromArray);
156  BESDEBUG(DEBUG_CHANNEL, "Constraints for Array: " << name() << ": " << oss.str() << endl);
157  }
158 
159  libdap::Array&
161  {
162  VALID_PTR(_pSubArrayProto.get());
163  return *(_pSubArrayProto.get());
164  }
165 
166 
167  const ArrayGetterInterface&
169  {
170  VALID_PTR(_pArrayGetter.get());
171  return *(_pArrayGetter.get());
172  }
173 
174  void
175  ArrayAggregationBase::duplicate(const ArrayAggregationBase& rhs)
176  {
177  // Clone the template if it isn't null.
178  std::auto_ptr<Array> pTemplateClone( ( (rhs._pSubArrayProto.get()) ?
179  (static_cast<Array*>(rhs._pSubArrayProto->ptr_duplicate())) :
180  (0) ));
181  _pSubArrayProto = pTemplateClone;
182 
183  // Clone the ArrayGetterInterface as well.
184  std::auto_ptr<ArrayGetterInterface> pGetterClone(
185  (rhs._pArrayGetter.get()) ?
186  ( rhs._pArrayGetter->clone() ) :
187  (0) );
188  _pArrayGetter = pGetterClone;
189 
190  // full copy, will do the proper thing with refcounts.
191  _datasetDescs = rhs._datasetDescs;
192  }
193 
194  void
195  ArrayAggregationBase::cleanup() throw()
196  {
197  _datasetDescs.clear();
198  _datasetDescs.resize(0);
199  }
200 
201  /* virtual */
202  void
204  {
205  NCML_ASSERT_MSG(false,
206  "** Unimplemented function: "
207  "ArrayAggregationBase::transferOutputConstraintsIntoGranuleTemplateHook(): "
208  "needs to be overridden and implemented in a base class.");
209  }
210 
211  /* virtual */
212  void
214  {
215  NCML_ASSERT_MSG(false,
216  "** Unimplemented function: "
217  "ArrayAggregationBase::readConstrainedGranuleArraysAndAggregateData(): "
218  "needs to be overridden and implemented in a base class.");
219  }
220 
221 }
virtual bool read()
Base implementation that works for both joinNew and joinExisting.
ArrayAggregationBase & operator=(const ArrayAggregationBase &rhs)
#define BESDEBUG_FUNC(channel, info)
Definition: NCMLDebug.h:58
libdap::Array & getGranuleTemplateArray()
Accessor for subclasses Note this is protected, so not const! Subclasses may mutate the return hence ...
virtual ArrayAggregationBase * ptr_duplicate()
virtual constructor i.e.
void printConstraints(const Array &fromArray)
Print out the constraints on fromArray to the debug channel.
ArrayAggregationBase(const libdap::Array &granuleProto, const AMDList &memberDatasets, std::auto_ptr< ArrayGetterInterface > &arrayGetter)
Construct the base class using the given parameters.
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
#define NCML_ASSERT_MSG(cond, msg)
Definition: NCMLDebug.h:83
Helper class hierarchy for acquiring variable of a certain type from a DDS.
Base class for subclasses of libdap::Array which perform aggregation on a list of AggMemberDatasets w...
const ArrayGetterInterface & getArrayGetterInterface() const
Accessor for subclasses Note this is protected, so not const! Subclasses may mutate the return hence ...
std::vector< RCPtr< AggMemberDataset > > AMDList
const AMDList & getDatasetList() const
Get the list of AggMemberDataset's that comprise this aggregation.
#define VALID_PTR(ptr)
Definition: NCMLDebug.h:88
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
virtual void readConstrainedGranuleArraysAndAggregateDataHook()
The meat of the subclass impl of read().
virtual void transferOutputConstraintsIntoGranuleTemplateHook()
subclass hook from read() to setup constraints on inner dims correctly
static void printConstraints(std::ostream &os, const libdap::Array &fromArray)
Stream out the current constraints for all the dimensions in the Array.