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