bes  Updated for version 3.20.8
DmrppArray.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of the BES
4 
5 // Copyright (c) 2016 OPeNDAP, Inc.
6 // Author: James Gallagher <jgallagher@opendap.org>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23 
24 #ifndef _dmrpp_array_h
25 #define _dmrpp_array_h 1
26 
27 #include <string>
28 #include <utility>
29 #include <vector>
30 #include <memory>
31 
32 #include <Array.h>
33 
34 #include "DmrppCommon.h"
35 #include "SuperChunk.h"
36 
37 // The 'read_serial()' method is more closely related to the original code
38 // used to read data when the DMR++ handler was initially developed for NASA.
39 // I modified that code for a while when we built the prototype version of
40 // the handler, but then morphed that into a version that would support parallel
41 // access. Defining this symbol will include the old code in the handler,
42 // although the DmrppArray::read() method will still have to be hacked to
43 // use it. jhrg 5/10/18
44 #undef USE_READ_SERIAL
45 
46 namespace libdap {
47 class XMLWriter;
48 }
49 
50 namespace dmrpp {
51 
52  class SuperChunk;
64 class DmrppArray : public libdap::Array, public dmrpp::DmrppCommon {
65 
66 private:
67  void _duplicate(const DmrppArray &ts);
68 
69  bool is_projected();
70 
71  DmrppArray::dimension get_dimension(unsigned int dim_num);
72 
73  void insert_constrained_contiguous(Dim_iter dim_iter, unsigned long *target_index,
74  std::vector<unsigned int> &subset_addr,
75  const std::vector<unsigned int> &array_shape, char *data);
76 
77  void read_contiguous();
78 
79 #ifdef USE_READ_SERIAL
80  virtual void insert_chunk_serial(unsigned int dim, std::vector<unsigned int> *target_element_address,
81  std::vector<unsigned int> *chunk_source_address, Chunk *chunk);
82  virtual void read_chunks_serial();
83 #endif
84 
85  // Called from read_chunks_unconstrained() and also using pthreads
86  friend void
87  process_one_chunk_unconstrained(std::shared_ptr<Chunk> chunk, DmrppArray *array, const vector<unsigned int> &array_shape,const vector<unsigned int> &chunk_shape);
88  friend void
89  process_super_chunk_unconstrained(const std::shared_ptr<SuperChunk>& super_chunk, DmrppArray *array);
90 
91  // Called from read_chunks()
92  friend void
93  process_one_chunk(std::shared_ptr<Chunk> chunk, DmrppArray *array, const vector<unsigned int> &constrained_array_shape);
94  friend
95  void process_super_chunk(const std::shared_ptr<SuperChunk>& super_chunk, DmrppArray *array);
96 
97  // friend void SuperChunk::chunks_to_array_values(DmrppArray *array);
98  // friend void SuperChunk::chunks_to_array_values_unconstrained(DmrppArray *target_array);
99 
100  virtual void insert_chunk_unconstrained(std::shared_ptr<Chunk> chunk, unsigned int dim,
101  unsigned long long array_offset, const std::vector<unsigned int> &array_shape,
102  unsigned long long chunk_offset, const std::vector<unsigned int> &chunk_shape,
103  const std::vector<unsigned int> &chunk_origin);
104 
105  void read_chunks_unconstrained();
106 
107  unsigned long long get_chunk_start(const dimension &thisDim, unsigned int chunk_origin_for_dim);
108 
109  std::shared_ptr<Chunk> find_needed_chunks(unsigned int dim, std::vector<unsigned int> *target_element_address, std::shared_ptr<Chunk> chunk);
110 
111  virtual void insert_chunk(
112  unsigned int dim,
113  std::vector<unsigned int> *target_element_address,
114  std::vector<unsigned int> *chunk_element_address,
115  std::shared_ptr<Chunk> chunk,
116  const vector<unsigned int> &constrained_array_shape);
117 
118 
119  void read_chunks();
120 
121  public:
122  DmrppArray(const std::string &n, libdap::BaseType *v);
123 
124  DmrppArray(const std::string &n, const std::string &d, libdap::BaseType *v);
125 
126  DmrppArray(const DmrppArray &rhs);
127 
128  virtual ~DmrppArray() {
129  }
130 
131  DmrppArray &operator=(const DmrppArray &rhs);
132 
133  virtual libdap::BaseType *ptr_duplicate();
134 
135  virtual bool read();
136 
137  virtual unsigned long long get_size(bool constrained = false);
138 
139  virtual std::vector<unsigned int> get_shape(bool constrained);
140 
141  virtual void print_dap4(libdap::XMLWriter &writer, bool constrained = false);
142 
143  virtual void dump(ostream &strm) const;
144 };
145 
153  void *one_chunk_thread(void *arg_list);
154  void *one_super_chunk_unconstrained_thread(void *arg_list);
155 
160  int *fds; // pipe back to parent
161  unsigned char tid; // thread id as a byte
162  std::shared_ptr<Chunk> chunk;
163  DmrppArray *array;
164  const vector<unsigned int> &array_shape;
165 
166  one_chunk_args(int *pipe, unsigned char id, std::shared_ptr<Chunk> c, DmrppArray *a, const vector<unsigned int> &a_s)
167  : fds(pipe), tid(id), chunk(std::move(c)), array(a), array_shape(a_s) {}
168 };
169 
171  //int *fds; // pipe back to parent
172  //unsigned char tid; // thread id as a byte
173  std::shared_ptr<SuperChunk> super_chunk;
174  DmrppArray *array;
175 
176  one_super_chunk_args(/*int *pipe, unsigned char id,*/ std::shared_ptr<SuperChunk> sc, DmrppArray *a)
177  : /* fds(pipe), tid(id), */ super_chunk(std::move(sc)), array(a) {}
178 };
179 
186  int *fds; // pipe back to parent
187  unsigned char tid; // thread id as a byte
188  std::shared_ptr<Chunk> chunk;
189  DmrppArray *array;
190  const vector<unsigned int> &array_shape;
191  const vector<unsigned int> &chunk_shape;
192 
193  one_chunk_unconstrained_args(int *pipe, unsigned char id, std::shared_ptr<Chunk> c, DmrppArray *a, const vector<unsigned int> &a_s,
194  const vector<unsigned int> &c_s)
195  : fds(pipe), tid(id), chunk(std::move(c)), array(a), array_shape(a_s), chunk_shape(c_s) {}
196 };
197 
203  int *fds; // pipe back to parent
204  unsigned char tid; // thread id as a byte
205  std::shared_ptr<Chunk> child_chunk; // this chunk reads data; temporary allocation
206  std::shared_ptr<Chunk> master_chunk; // this chunk gets the data; shared memory, managed by DmrppArray
207 
208  one_child_chunk_args(int *pipe, unsigned char id, std::shared_ptr<Chunk> c_c, std::shared_ptr<Chunk> m_c)
209  : fds(pipe), tid(id), child_chunk(c_c), master_chunk(m_c) {}
210 
211  // FIXME Use smart pointers here. jhrg 9/16/20
212  // Done! ndp
213  ~one_child_chunk_args() { }
214 };
215 
216 } // namespace dmrpp
217 
218 #endif // _dmrpp_array_h
219 
Extend libdap::Array so that a handler can read data using a DMR++ file.
Definition: DmrppArray.h:64
virtual std::vector< unsigned int > get_shape(bool constrained)
Get the array shape.
Definition: DmrppArray.cc:321
friend void process_super_chunk(const std::shared_ptr< SuperChunk > &super_chunk, DmrppArray *array)
reads the super chunk, inflates/deshuffles chunks as required and copies the values into array
Definition: DmrppArray.cc:1296
friend void process_super_chunk_unconstrained(const std::shared_ptr< SuperChunk > &super_chunk, DmrppArray *array)
Insert data from one chunk in this this array.
Definition: DmrppArray.cc:831
virtual unsigned long long get_size(bool constrained=false)
Return the total number of elements in this Array.
Definition: DmrppArray.cc:305
virtual bool read()
Read data for the array.
Definition: DmrppArray.cc:1622
virtual void print_dap4(libdap::XMLWriter &writer, bool constrained=false)
Shadow libdap::Array::print_dap4() - optionally prints DMR++ chunk information.
Definition: DmrppArray.cc:1788
Size and offset information of data included in DMR++ files.
Definition: DmrppCommon.h:68