bes  Updated for version 3.20.6
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 
31 //#include <H5Ppublic.h>
32 
33 #include "Chunk.h"
34 
35 namespace libdap {
36 class DMR;
37 class BaseType;
38 class D4BaseTypeFactory;
39 class D4Group;
40 class D4Attributes;
41 class D4EnumDef;
42 class D4Dimension;
43 class XMLWriter;
44 }
45 
46 namespace dmrpp {
47 
48 void join_threads(pthread_t threads[], unsigned int num_threads);
49 
62 class DmrppCommon {
63 
64  friend class DmrppCommonTest;
65  friend class DmrppParserTest;
66 
67 private:
68  bool d_deflate;
69  bool d_shuffle;
70  std::vector<unsigned int> d_chunk_dimension_sizes;
71  std::vector<Chunk> d_chunks;
72 
73 protected:
74  void m_duplicate_common(const DmrppCommon &dc) {
75  d_deflate = dc.d_deflate;
76  d_shuffle = dc.d_shuffle;
77  d_chunk_dimension_sizes = dc.d_chunk_dimension_sizes;
78  d_chunks = dc.d_chunks;
79  }
80 
82  virtual std::vector<Chunk> &get_chunk_vec() {
83  return d_chunks;
84  }
85 
86  virtual char *read_atomic(const std::string &name);
87 
88 public:
89  static bool d_print_chunks;
90  static std::string d_dmrpp_ns;
91  static std::string d_ns_prefix;
92 
93  DmrppCommon() : d_deflate(false), d_shuffle(false)
94  {
95  }
96 
97  DmrppCommon(const DmrppCommon &dc)
98  {
99  m_duplicate_common(dc);
100  }
101 
102  virtual ~DmrppCommon()
103  {
104  }
105 
107  virtual bool is_deflate_compression() const {
108  return d_deflate;
109  }
110 
112  void set_deflate(bool value) {
113  d_deflate = value;
114  }
115 
117  virtual bool is_shuffle_compression() const {
118  return d_shuffle;
119  }
120 
122  void set_shuffle(bool value) {
123  d_shuffle = value;
124  }
125 
126  virtual const std::vector<Chunk> &get_immutable_chunks() const {
127  return d_chunks;
128  }
129 
130  virtual const std::vector<unsigned int> &get_chunk_dimension_sizes() const {
131  return d_chunk_dimension_sizes;
132  }
133 
139  virtual unsigned int get_chunk_size_in_elements() const {
140  unsigned int elements = 1;
141  for (std::vector<unsigned int>::const_iterator i = d_chunk_dimension_sizes.begin(),
142  e = d_chunk_dimension_sizes.end(); i != e; ++i) {
143  elements *= *i;
144  }
145 
146  return elements;
147  }
148 
149  void print_chunks_element(libdap::XMLWriter &xml, const std::string &name_space = "");
150 
151  void print_dmrpp(libdap::XMLWriter &writer, bool constrained = false);
152 
153  // Replaced hsize_t with size_t. This eliminates a dependency on hdf5. jhrg 9/7/18
155  void set_chunk_dimension_sizes(const std::vector<size_t> &chunk_dims)
156  {
157  // tried using copy(chunk_dims.begin(), chunk_dims.end(), d_chunk_dimension_sizes.begin())
158  // it didn't work, maybe because of the differing element types?
159  for (std::vector<size_t>::const_iterator i = chunk_dims.begin(), e = chunk_dims.end(); i != e; ++i) {
160  d_chunk_dimension_sizes.push_back(*i);
161  }
162  }
163 
164  virtual void parse_chunk_dimension_sizes(std::string chunk_dim_sizes_string);
165 
166  virtual void ingest_compression_type(std::string compression_type_string);
167 
168  virtual unsigned long add_chunk(const std::string &data_url, unsigned long long size, unsigned long long offset,
169  std::string position_in_array = "");
170 
171  virtual unsigned long add_chunk(const std::string &data_url, unsigned long long size, unsigned long long offset,
172  const std::vector<unsigned int> &position_in_array);
173 
174  virtual void dump(std::ostream & strm) const;
175 };
176 
177 } // namepsace dmrpp
178 
179 #endif // _dmrpp_common_h
180 
dmrpp::DmrppCommon::get_chunk_vec
virtual std::vector< Chunk > & get_chunk_vec()
Returns a reference to the internal Chunk vector.
Definition: DmrppCommon.h:82
dmrpp::DmrppCommon::d_ns_prefix
static std::string d_ns_prefix
The XML namespace prefix to use.
Definition: DmrppCommon.h:91
dmrpp::DmrppCommon::parse_chunk_dimension_sizes
virtual void parse_chunk_dimension_sizes(std::string chunk_dim_sizes_string)
Set the dimension sizes for a chunk.
Definition: DmrppCommon.cc:90
dmrpp::DmrppCommon
Size and offset information of data included in DMR++ files.
Definition: DmrppCommon.h:62
dmrpp::DmrppCommon::is_shuffle_compression
virtual bool is_shuffle_compression() const
Returns true if this object utilizes shuffle compression.
Definition: DmrppCommon.h:117
dmrpp::DmrppCommon::get_chunk_size_in_elements
virtual unsigned int get_chunk_size_in_elements() const
Get the number of elements in this chunk.
Definition: DmrppCommon.h:139
dmrpp::DmrppCommon::add_chunk
virtual unsigned long add_chunk(const std::string &data_url, unsigned long long size, unsigned long long offset, std::string position_in_array="")
Add a new chunk as defined by an h4:byteStream element.
Definition: DmrppCommon.cc:153
dmrpp::DmrppCommon::is_deflate_compression
virtual bool is_deflate_compression() const
Returns true if this object utilizes deflate compression.
Definition: DmrppCommon.h:107
libdap
Definition: BESDapFunctionResponseCache.h:35
dmrpp::DmrppCommon::d_dmrpp_ns
static std::string d_dmrpp_ns
The DMR++ XML namespace.
Definition: DmrppCommon.h:90
dmrpp::DmrppCommon::set_deflate
void set_deflate(bool value)
Set the value of the deflate property.
Definition: DmrppCommon.h:112
dmrpp::DmrppCommon::set_shuffle
void set_shuffle(bool value)
Set the value of the shuffle property.
Definition: DmrppCommon.h:122
dmrpp::DmrppCommon::read_atomic
virtual char * read_atomic(const std::string &name)
read method for the atomic types
Definition: DmrppCommon.cc:187
dmrpp::DmrppCommon::set_chunk_dimension_sizes
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:155
dmrpp::DmrppCommon::print_dmrpp
void print_dmrpp(libdap::XMLWriter &writer, bool constrained=false)
Print the DMR++ response for the Scalar types.
Definition: DmrppCommon.cc:282
dmrpp::DmrppCommon::print_chunks_element
void print_chunks_element(libdap::XMLWriter &xml, const std::string &name_space="")
Print the Chunk information.
Definition: DmrppCommon.cc:205
dmrpp::DmrppCommon::ingest_compression_type
virtual void ingest_compression_type(std::string compression_type_string)
Parses the text content of the XML element h4:chunkDimensionSizes into the internal vector<unsigned i...
Definition: DmrppCommon.cc:128
dmrpp::DmrppCommon::d_print_chunks
static bool d_print_chunks
if true, print_dap4() prints chunk elements
Definition: DmrppCommon.h:89