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