bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
DmrppD4Opaque.cc
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of the BES
5
6// Copyright (c) 2016 OPeNDAP, Inc.
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#include "config.h"
26
27#include <cstring>
28
29#include <string>
30#include <queue>
31
32#include <BESLog.h>
33#include <BESInternalError.h>
34#include <BESDebug.h>
35
36#include "CurlHandlePool.h"
37#include "DmrppRequestHandler.h"
38#include "DmrppD4Opaque.h"
39#include "Chunk.h"
40
41using namespace libdap;
42using namespace std;
43
44namespace dmrpp {
45
47DmrppD4Opaque::operator=(const DmrppD4Opaque &rhs)
48{
49 if (this == &rhs)
50 return *this;
51
52 dynamic_cast<D4Opaque &>(*this) = rhs; // run Constructor=
53
54 dynamic_cast<DmrppCommon &>(*this) = rhs;
55 // FIXME Remove DmrppCommon::m_duplicate_common(rhs);
56
57 return *this;
58}
59
60void DmrppD4Opaque::insert_chunk(shared_ptr<Chunk> chunk)
61{
62 // The size, in elements, of each of the chunk's dimensions.
63 const vector<unsigned long long> &chunk_shape = get_chunk_dimension_sizes();
64 if (chunk_shape.size() != 1) throw BESInternalError("Opaque variables' chunks can only have one dimension.", __FILE__, __LINE__);
65
66 // The chunk's origin point a.k.a. its "position in array".
67 const vector<unsigned long long> &chunk_origin = chunk->get_position_in_array();
68
69 char *source_buffer = chunk->get_rbuf();
70 unsigned char *target_buffer = get_buf();
71
72 memcpy(target_buffer + chunk_origin[0], source_buffer, chunk_shape[0]);
73}
74
75void DmrppD4Opaque::read_chunks()
76{
77 for (auto chunk : get_immutable_chunks()) {
78 chunk->read_chunk();
79 if (!is_filters_empty()){
80 chunk->filter_chunk(get_filters(), get_chunk_size_in_elements(), 1 /*elem width*/);
81 }
82
83 insert_chunk(chunk);
84 }
85
86 set_read_p(true);
87}
88
98bool
100{
101 if (!get_chunks_loaded())
102 load_chunks(this);
103
104 if (read_p()) return true;
105
106 // if there are no chunks, use read a single contiguous block of data
107 // and store it in the object. Note that DmrppCommon uses a single Chunk
108 // instance to hold 'contiguous' data.
109 if (get_chunk_dimension_sizes().empty()) {
110 // read_atomic() returns a pointer to the Chunk data. When the Chunk
111 // instance is freed, this memory goes away.
112 char *data = read_atomic(name());
113 val2buf(data); // yes, it's not type-safe
114 }
115 else {
116 // Handle the more complex case where the data is chunked.
117 read_chunks();
118 }
119
120 return true;
121}
122
123void
124DmrppD4Opaque::set_send_p(bool state)
125{
127 load_attributes(this);
128
129 D4Opaque::set_send_p(state);
130}
131
132void DmrppD4Opaque::dump(ostream & strm) const
133{
134 strm << BESIndent::LMarg << "DmrppD4Opaque::dump - (" << (void *) this << ")" << endl;
135 BESIndent::Indent();
136 DmrppCommon::dump(strm);
137 D4Opaque::dump(strm);
138 strm << BESIndent::LMarg << "value: " << "----" << /*d_buf <<*/ endl;
139 BESIndent::UnIndent();
140}
141
142} // namespace dmrpp
143
virtual void load_attributes(libdap::BaseType *btp)
Load the attribute information for this variable.
virtual bool get_chunks_loaded() const
Have the chunks been loaded?
virtual const std::vector< std::shared_ptr< Chunk > > & get_immutable_chunks() const
A const reference to the vector of chunks.
virtual const std::vector< unsigned long long > & get_chunk_dimension_sizes() const
The chunk dimension sizes held in a const vector.
virtual void load_chunks(libdap::BaseType *btp)
Load chunk information for this variable.
virtual unsigned long long get_chunk_size_in_elements() const
Get the number of elements in this chunk.
virtual std::string get_filters() const
Return the names of all the filters in the order they were applied.
virtual bool get_attributes_loaded() const
Have the attributes been loaded?
virtual char * read_atomic(const std::string &name)
read method for the atomic types
virtual unsigned char * get_buf()
Get a pointer to start of the Opaque data buffer.
bool read() override
Read opaque data.