bes  Updated for version 3.20.6
ArrayAggregationBase.cc
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 #include "BESDebug.h"
33 #include "BESStopWatch.h"
34 #include "Marshaller.h"
35 #include "ConstraintEvaluator.h"
36 
37 // BES debug channel we output to
38 static const string DEBUG_CHANNEL("agg_util");
39 
40 // Local flag for whether to print constraints, to help debugging
41 static const bool PRINT_CONSTRAINTS = false;
42 
43 //using libdap::Array;
44 
45 using namespace libdap;
46 
47 namespace agg_util {
48 ArrayAggregationBase::ArrayAggregationBase(const libdap::Array& proto, const AMDList& aggMembers,
49  std::auto_ptr<ArrayGetterInterface>& arrayGetter) :
50  Array(proto), _pSubArrayProto(static_cast<Array*>(const_cast<Array&>(proto).ptr_duplicate())),
51  _pArrayGetter(arrayGetter), _datasetDescs(aggMembers)
52 {
53 }
54 
56  Array(rhs), _pSubArrayProto(0) // duplicate() handles this
57  , _pArrayGetter(0) // duplicate() handles this
58  , _datasetDescs()
59 {
60  BESDEBUG(DEBUG_CHANNEL, "ArrayAggregationBase() copy ctor called!" << endl);
61  duplicate(rhs);
62 }
63 
64 /* virtual */
65 ArrayAggregationBase::~ArrayAggregationBase()
66 {
67  cleanup();
68 }
69 
70 ArrayAggregationBase&
71 ArrayAggregationBase::operator=(const ArrayAggregationBase& rhs)
72 {
73  if (this != &rhs) {
74  cleanup();
75  Array::operator=(rhs);
76  duplicate(rhs);
77  }
78  return *this;
79 }
80 
81 /* virtual */
82 ArrayAggregationBase*
84 {
85  return new ArrayAggregationBase(*this);
86 }
87 
88 /* virtual */
89 // In child classes we specialize the BaseType::serialize() method so that
90 // as data are read they are also set (using Marshaller::put_vector_part()).
91 // In those cases this method is actually not called. We keep this version
92 // so that code that depends on read() actually reading in all of the data
93 // will still work.
95 {
96  BESStopWatch sw;
97  if (BESISDEBUG(TIMING_LOG)) sw.start("ArrayAggregationBase::read", "");
98 
99  BESDEBUG_FUNC(DEBUG_CHANNEL, " function entered..." << endl);
100 
101  // Early exit if already done, avoid doing it twice!
102  if (read_p()) {
103  BESDEBUG_FUNC(DEBUG_CHANNEL, "read_p() set, early exit!");
104  return true;
105  }
106 
107  // Only continue if we are supposed to serialize this object at all.
108  if (!(send_p() || is_in_selection())) {
109  BESDEBUG_FUNC(DEBUG_CHANNEL, "Object not in output, skipping... name=" << name() << endl);
110  return true;
111  }
112 
113  if (PRINT_CONSTRAINTS) {
114  BESDEBUG_FUNC(DEBUG_CHANNEL, "Constraints on this Array are:" << endl);
115  printConstraints(*this);
116  }
117 
118  // call subclass impl
120 
121  if (PRINT_CONSTRAINTS) {
122  BESDEBUG_FUNC(DEBUG_CHANNEL, "After transfer, constraints on the member template Array are: " << endl);
124  }
125 
126  // Call the subclass specific algorithms to do the read
127  // and stream
129 
130  // Set the cache bit to avoid recomputing
131  set_read_p(true);
132  return true;
133 }
134 
135 const AMDList&
137 {
138  return _datasetDescs;
139 }
140 
142 
143 void ArrayAggregationBase::printConstraints(const Array& fromArray)
144 {
145  ostringstream oss;
146  AggregationUtil::printConstraints(oss, fromArray);
147  BESDEBUG(DEBUG_CHANNEL, "Constraints for Array: " << name() << ": " << oss.str() << endl);
148 }
149 
150 libdap::Array&
152 {
153  VALID_PTR(_pSubArrayProto.get());
154  return *(_pSubArrayProto.get());
155 }
156 
159 {
160  VALID_PTR(_pArrayGetter.get());
161  return *(_pArrayGetter.get());
162 }
163 
164 void ArrayAggregationBase::duplicate(const ArrayAggregationBase& rhs)
165 {
166  // Clone the template if it isn't null.
167  std::auto_ptr<Array> pTemplateClone(
168  ((rhs._pSubArrayProto.get()) ? (static_cast<Array*>(rhs._pSubArrayProto->ptr_duplicate())) : (0)));
169  _pSubArrayProto = pTemplateClone;
170 
171  // Clone the ArrayGetterInterface as well.
172  std::auto_ptr<ArrayGetterInterface> pGetterClone((rhs._pArrayGetter.get()) ? (rhs._pArrayGetter->clone()) : (0));
173  _pArrayGetter = pGetterClone;
174 
175  // full copy, will do the proper thing with refcounts.
176  _datasetDescs = rhs._datasetDescs;
177 }
178 
179 void ArrayAggregationBase::cleanup() throw ()
180 {
181  _datasetDescs.clear();
182  _datasetDescs.resize(0);
183 }
184 
185 /* virtual */
187 {
188  NCML_ASSERT_MSG(false, "** Unimplemented function: "
189  "ArrayAggregationBase::transferOutputConstraintsIntoGranuleTemplateHook(): "
190  "needs to be overridden and implemented in a base class.");
191 }
192 
193 /* virtual */
195 {
196  NCML_ASSERT_MSG(false, "** Unimplemented function: "
197  "ArrayAggregationBase::readConstrainedGranuleArraysAndAggregateData(): "
198  "needs to be overridden and implemented in a base class.");
199 }
200 
201 }
agg_util::ArrayAggregationBase::printConstraints
void printConstraints(const Array &fromArray)
Definition: ArrayAggregationBase.cc:143
BESStopWatch::start
virtual bool start(std::string name)
Definition: BESStopWatch.cc:58
agg_util::ArrayAggregationBase::ptr_duplicate
virtual ArrayAggregationBase * ptr_duplicate()
Definition: ArrayAggregationBase.cc:83
agg_util::ArrayAggregationBase::getGranuleTemplateArray
libdap::Array & getGranuleTemplateArray()
Definition: ArrayAggregationBase.cc:151
agg_util::ArrayAggregationBase::readConstrainedGranuleArraysAndAggregateDataHook
virtual void readConstrainedGranuleArraysAndAggregateDataHook()
Definition: ArrayAggregationBase.cc:194
agg_util
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
Definition: AggMemberDataset.cc:38
agg_util::AggregationUtil::printConstraints
static void printConstraints(std::ostream &os, const libdap::Array &fromArray)
Definition: AggregationUtil.cc:706
agg_util::ArrayAggregationBase
Definition: ArrayAggregationBase.h:49
libdap
Definition: BESDapFunctionResponseCache.h:35
agg_util::ArrayAggregationBase::getArrayGetterInterface
const ArrayGetterInterface & getArrayGetterInterface() const
Definition: ArrayAggregationBase.cc:158
agg_util::ArrayGetterInterface
Definition: AggregationUtil.h:59
agg_util::ArrayAggregationBase::transferOutputConstraintsIntoGranuleTemplateHook
virtual void transferOutputConstraintsIntoGranuleTemplateHook()
Definition: ArrayAggregationBase.cc:186
BESStopWatch
Definition: BESStopWatch.h:55
agg_util::ArrayAggregationBase::read
virtual bool read()
Definition: ArrayAggregationBase.cc:94
agg_util::ArrayAggregationBase::getDatasetList
const AMDList & getDatasetList() const
Definition: ArrayAggregationBase.cc:136
agg_util::ArrayAggregationBase::ArrayAggregationBase
ArrayAggregationBase(const libdap::Array &granuleProto, const AMDList &memberDatasets, std::auto_ptr< ArrayGetterInterface > &arrayGetter)
Definition: ArrayAggregationBase.cc:48