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