bes  Updated for version 3.20.8
DmrppCommon.h
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 #ifndef _dmrpp_common_h
26 #define _dmrpp_common_h 1
27 
28 #include <string>
29 #include <vector>
30 #include <memory>
31 
32 //#include <H5Ppublic.h>
33 
34 #include "dods-datatypes.h"
35 #include "Chunk.h"
36 #include "SuperChunk.h"
37 
38 #include "config.h"
39 #include "byteswap_compat.h"
40 
41 namespace libdap {
42 class DMR;
43 class BaseType;
44 class D4BaseTypeFactory;
45 class D4Group;
46 class D4Attributes;
47 class D4EnumDef;
48 class D4Dimension;
49 class XMLWriter;
50 }
51 
52 namespace dmrpp {
53 
54 void join_threads(pthread_t threads[], unsigned int num_threads);
55 
68 class DmrppCommon {
69 
70  friend class DmrppCommonTest;
71  friend class DmrppParserTest;
72  friend class DmrppTypeReadTest;
73 
74 private:
75  bool d_deflate;
76  bool d_shuffle;
77  bool d_compact;
78  std::string d_byte_order;
79  std::vector<unsigned int> d_chunk_dimension_sizes;
80  std::vector<std::shared_ptr<Chunk>> d_chunks;
81  bool d_twiddle_bytes;
82 
83 protected:
84  void m_duplicate_common(const DmrppCommon &dc) {
85  d_deflate = dc.d_deflate;
86  d_shuffle = dc.d_shuffle;
87  d_compact = dc.d_compact;
88  d_chunk_dimension_sizes = dc.d_chunk_dimension_sizes;
89  d_chunks = dc.d_chunks;
90  d_byte_order = dc.d_byte_order;
91  d_twiddle_bytes = dc.d_twiddle_bytes;
92  }
93 
96  virtual std::vector<std::shared_ptr<Chunk>> get_chunks() {
97  return d_chunks;
98  }
99 
100  virtual char *read_atomic(const std::string &name);
101 
102 public:
103  static bool d_print_chunks;
104  static std::string d_dmrpp_ns;
105  static std::string d_ns_prefix;
106 
107  DmrppCommon() : d_deflate(false), d_shuffle(false), d_compact(false),d_byte_order(""), d_twiddle_bytes(false)
108  {
109  }
110 
111  DmrppCommon(const DmrppCommon &dc)
112  {
113  m_duplicate_common(dc);
114  }
115 
116  virtual ~DmrppCommon()= default;
117 
119  virtual bool is_deflate_compression() const {
120  return d_deflate;
121  }
122 
124  void set_deflate(bool value) {
125  d_deflate = value;
126  }
127 
129  virtual bool is_shuffle_compression() const {
130  return d_shuffle;
131  }
132 
134  void set_shuffle(bool value) {
135  d_shuffle = value;
136  }
137 
139  virtual bool is_compact_layout() const {
140  return d_compact;
141  }
142 
144  void set_compact(bool value) {
145  d_compact = value;
146  }
147 
149  virtual bool twiddle_bytes() const { return d_twiddle_bytes; }
150 
153  virtual std::vector< std::shared_ptr<Chunk>> get_immutable_chunks() const {
154  return d_chunks;
155  }
156 
157  virtual const std::vector<unsigned int> &get_chunk_dimension_sizes() const {
158  return d_chunk_dimension_sizes;
159  }
160 
166  virtual unsigned int get_chunk_size_in_elements() const {
167  unsigned int elements = 1;
168  for (auto d_chunk_dimension_size : d_chunk_dimension_sizes) {
169  elements *= d_chunk_dimension_size;
170  }
171 
172  return elements;
173  }
174 
175  void print_chunks_element(libdap::XMLWriter &xml, const std::string &name_space = "");
176 
177  void print_compact_element(libdap::XMLWriter &xml, const std::string &name_space = "", const std::string &encoded = "");
178 
179  void print_dmrpp(libdap::XMLWriter &writer, bool constrained = false);
180 
181  // Replaced hsize_t with size_t. This eliminates a dependency on hdf5. jhrg 9/7/18
183  void set_chunk_dimension_sizes(const std::vector<size_t> &chunk_dims)
184  {
185  // tried using copy(chunk_dims.begin(), chunk_dims.end(), d_chunk_dimension_sizes.begin())
186  // it didn't work, maybe because of the differing element types?
187  for (auto chunk_dim : chunk_dims) {
188  d_chunk_dimension_sizes.push_back(chunk_dim);
189  }
190  }
191 
192  virtual void parse_chunk_dimension_sizes(const std::string &chunk_dim_sizes_string);
193 
194  virtual void ingest_compression_type(const std::string &compression_type_string);
195 
196  virtual void ingest_byte_order(const std::string &byte_order_string);
197  virtual std::string get_byte_order() const { return d_byte_order; }
198 
199  virtual unsigned long add_chunk(const std::string &data_url, const std::string &byte_order,
200  unsigned long long size, unsigned long long offset, const std::string &position_in_array = "");
201 
202  virtual unsigned long add_chunk(const std::string &data_url, const std::string &byte_order,
203  unsigned long long size, const unsigned long long offset, const std::vector<unsigned int> &position_in_array);
204 
205  virtual void dump(std::ostream & strm) const;
206 };
207 
208 } // namepsace dmrpp
209 
210 #endif // _dmrpp_common_h
211 
Size and offset information of data included in DMR++ files.
Definition: DmrppCommon.h:68
static std::string d_ns_prefix
The XML namespace prefix to use.
Definition: DmrppCommon.h:105
virtual bool twiddle_bytes() const
Returns true if this object utilizes shuffle compression.
Definition: DmrppCommon.h:149
virtual unsigned int get_chunk_size_in_elements() const
Get the number of elements in this chunk.
Definition: DmrppCommon.h:166
void set_chunk_dimension_sizes(const std::vector< size_t > &chunk_dims)
Set the value of the chunk dimension sizes given a vector of HDF5 hsize_t.
Definition: DmrppCommon.h:183
static bool d_print_chunks
if true, print_dap4() prints chunk elements
Definition: DmrppCommon.h:103
virtual bool is_compact_layout() const
Returns true if this object utilizes COMPACT layout.
Definition: DmrppCommon.h:139
virtual void ingest_compression_type(const std::string &compression_type_string)
Parses the text content of the XML element h4:chunkDimensionSizes into the internal vector<unsigned i...
Definition: DmrppCommon.cc:144
virtual std::vector< std::shared_ptr< Chunk > > get_immutable_chunks() const
A const reference to the vector of chunks.
Definition: DmrppCommon.h:153
virtual unsigned long add_chunk(const std::string &data_url, const std::string &byte_order, unsigned long long size, unsigned long long offset, const std::string &position_in_array="")
Add a new chunk as defined by an h4:byteStream element.
Definition: DmrppCommon.cc:199
void print_compact_element(libdap::XMLWriter &xml, const std::string &name_space="", const std::string &encoded="")
Print the Compact base64-encoded information.
Definition: DmrppCommon.cc:384
static std::string d_dmrpp_ns
The DMR++ XML namespace.
Definition: DmrppCommon.h:104
void print_chunks_element(libdap::XMLWriter &xml, const std::string &name_space="")
Print the Chunk information.
Definition: DmrppCommon.cc:302
void set_deflate(bool value)
Set the value of the deflate property.
Definition: DmrppCommon.h:124
virtual void parse_chunk_dimension_sizes(const std::string &chunk_dim_sizes_string)
Set the dimension sizes for a chunk.
Definition: DmrppCommon.cc:105
virtual std::vector< std::shared_ptr< Chunk > > get_chunks()
Returns a reference to the internal Chunk vector.
Definition: DmrppCommon.h:96
virtual void ingest_byte_order(const std::string &byte_order_string)
Parses the text content of the XML element chunks:byteOrder.
Definition: DmrppCommon.cc:170
virtual bool is_shuffle_compression() const
Returns true if this object utilizes shuffle compression.
Definition: DmrppCommon.h:129
virtual bool is_deflate_compression() const
Returns true if this object utilizes deflate compression.
Definition: DmrppCommon.h:119
void set_compact(bool value)
Set the value of the compact property.
Definition: DmrppCommon.h:144
void print_dmrpp(libdap::XMLWriter &writer, bool constrained=false)
Print the DMR++ response for the Scalar types.
Definition: DmrppCommon.cc:407
void set_shuffle(bool value)
Set the value of the shuffle property.
Definition: DmrppCommon.h:134
virtual char * read_atomic(const std::string &name)
read method for the atomic types
Definition: DmrppCommon.cc:284