bes Updated for version 3.20.13
AggMemberDatasetUsingLocationRef.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 "AggMemberDatasetUsingLocationRef.h"
33
34#include "BESDataDDSResponse.h" // bes
35#include <libdap/DDS.h> // libdap
36
37#include "NCMLDebug.h" // ncml_module
38#include "NCMLUtil.h" // ncml_module
39#include "BESDebug.h"
40#include "BESStopWatch.h"
41
42using namespace std;
43
44namespace agg_util {
45
46AggMemberDatasetUsingLocationRef::AggMemberDatasetUsingLocationRef(const std::string& locationToLoad,
47 const agg_util::DDSLoader& loaderToUse) :
48 AggMemberDatasetWithDimensionCacheBase(locationToLoad), _loader(loaderToUse), _pDataResponse(0)
49{
50}
51
52AggMemberDatasetUsingLocationRef::~AggMemberDatasetUsingLocationRef()
53{
54 cleanup();
55}
56
57AggMemberDatasetUsingLocationRef::AggMemberDatasetUsingLocationRef(const AggMemberDatasetUsingLocationRef& proto) :
58 RCObjectInterface(), AggMemberDatasetWithDimensionCacheBase(proto), _loader(proto._loader) // force a reload as needed for a copy
59{
60}
61
62AggMemberDatasetUsingLocationRef&
63AggMemberDatasetUsingLocationRef::operator=(const AggMemberDatasetUsingLocationRef& that)
64{
65 if (this != &that) {
66 // clear out any old loaded stuff
67 cleanup();
68 // assign
69 AggMemberDatasetWithDimensionCacheBase::operator=(that);
70 copyRepFrom(that);
71 }
72 return *this;
73}
74
75const libdap::DDS*
76AggMemberDatasetUsingLocationRef::getDDS()
77{
78
79 if (!_pDataResponse) {
80 loadDDS();
81 }
82 DDS* pDDSRet = 0;
83 if (_pDataResponse) {
84 pDDSRet = _pDataResponse->get_dds();
85 }
86 return pDDSRet;
87}
88
90void AggMemberDatasetUsingLocationRef::loadDDS()
91{
92 BESStopWatch sw;
93 if (BESDebug::IsSet(TIMING_LOG_KEY)) sw.start("AggMemberDatasetUsingLocationRef::loadDDS", "");
94
95 // We cannot load an empty location, so avoid the exception later.
96 if (getLocation().empty()) {
97 THROW_NCML_INTERNAL_ERROR("AggMemberDatasetUsingLocationRef():"
98 " got empty location! Cannot load!");
99 }
100
101 // Make a new response and store the raw ptr, noting that we need to delete it in dtor.
102 unique_ptr<BESDapResponse> newResponse = agg_util::DDSLoader::makeResponseForType(DDSLoader::eRT_RequestDataDDS);
103
104 // static_cast should work here, but I want to be sure since DataDDX is in the works...
105 _pDataResponse = dynamic_cast<BESDataDDSResponse*>(newResponse.get());
106 NCML_ASSERT_MSG(_pDataResponse,
107 "AggMemberDatasetUsingLocationRef::loadDDS(): failed to get a BESDataDDSResponse back while loading location="
108 + getLocation());
109
110 // release after potential for exception to avoid double delete. Coverity reports
111 // this as a leak, but the _loader.loadInto() method takes ownership. jhrg 2/7/17
112 (void) newResponse.release();
113
114 BESDEBUG("ncml", "Loading loadDDS for aggregation member location = " << getLocation() << endl);
115 _loader.loadInto(getLocation(), DDSLoader::eRT_RequestDataDDS, _pDataResponse);
116}
117
118void AggMemberDatasetUsingLocationRef::cleanup() noexcept
119{
120 SAFE_DELETE(_pDataResponse);
121}
122
123void AggMemberDatasetUsingLocationRef::copyRepFrom(const AggMemberDatasetUsingLocationRef& rhs)
124{
125 _loader = rhs._loader;
126 _pDataResponse = nullptr; // force this to be NULL... we want to reload if we get an assignment
127}
128
129}
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
static bool IsSet(const std::string &flagName)
see if the debug context flagName is set to true
Definition: BESDebug.h:168
virtual bool start(std::string name)
Definition: BESStopWatch.cc:67
static std::unique_ptr< BESDapResponse > makeResponseForType(ResponseType type)
Definition: DDSLoader.cc:431
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...