bes  Updated for version 3.20.6
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 <vector>
29 
30 #include <Array.h>
31 
32 #include "DmrppCommon.h"
33 
34 // The 'read_serial()' method is more closely related to the original code
35 // used to read data when the DMR++ handler was initially developed for NASA.
36 // I modified that code for a while when we built the prototype version of
37 // the handler, but then morphed that into a version that would support parallel
38 // access. Defining this symbol will include the old code in the handler,
39 // although the DmrppArray::read() method will still have to be hacked to
40 // use it. jhrg 5/10/18
41 #undef USE_READ_SERIAL
42 
43 namespace libdap {
44 class XMLWriter;
45 }
46 
47 namespace dmrpp {
48 
60 class DmrppArray: public libdap::Array, public DmrppCommon {
61 
62 private:
63  void _duplicate(const DmrppArray &ts);
64 
65  bool is_projected();
66 
67  DmrppArray::dimension get_dimension(unsigned int dim_num);
68 
69  void insert_constrained_contiguous(Dim_iter p, unsigned long *target_index, std::vector<unsigned int> &subsetAddress,
70  const std::vector<unsigned int> &array_shape, char *data);
71  virtual void read_contiguous();
72 
73 #ifdef USE_READ_SERIAL
74  virtual void insert_chunk_serial(unsigned int dim, std::vector<unsigned int> *target_element_address,
75  std::vector<unsigned int> *chunk_source_address, Chunk *chunk);
76  virtual void read_chunks_serial();
77 #endif
78 
79  unsigned long long get_chunk_start(const dimension &thisDim, unsigned int chunk_origin_for_dim);
80 
81  Chunk *find_needed_chunks(unsigned int dim, std::vector<unsigned int> *target_element_address, Chunk *chunk);
82  void insert_chunk(unsigned int dim, std::vector<unsigned int> *target_element_address, std::vector<unsigned int> *chunk_element_address,
83  Chunk *chunk, const vector<unsigned int> &constrained_array_shape);
84  void read_chunks();
85 
86  void insert_chunk_unconstrained(Chunk *chunk, unsigned int dim,
87  unsigned long long array_offset, const std::vector<unsigned int> &array_shape,
88  unsigned long long chunk_offset, const std::vector<unsigned int> &chunk_shape, const std::vector<unsigned int> &chunk_origin);
89  void read_chunks_unconstrained();
90 
91  // Called from read_chunks_unconstrained() and also using pthreads
92  friend void process_one_chunk_unconstrained(Chunk *chunk, DmrppArray *array, const vector<unsigned int> &array_shape,
93  const vector<unsigned int> &chunk_shape);
94 
95 public:
96  DmrppArray(const std::string &n, libdap::BaseType *v);
97  DmrppArray(const std::string &n, const std::string &d, libdap::BaseType *v);
98  DmrppArray(const DmrppArray &rhs);
99 
100  virtual ~DmrppArray()
101  {
102  }
103 
104  DmrppArray &operator=(const DmrppArray &rhs);
105 
106  virtual libdap::BaseType *ptr_duplicate();
107 
108  virtual bool read();
109 
110  virtual unsigned long long get_size(bool constrained = false);
111  virtual std::vector<unsigned int> get_shape(bool constrained);
112 
113  virtual void print_dap4(libdap::XMLWriter &writer, bool constrained = false);
114 
115  virtual void dump(ostream & strm) const;
116 };
117 
120  int *fds; // pipe back to parent
121  unsigned char tid; // thread id as a byte
122  Chunk *chunk;
123  DmrppArray *array;
124  const vector<unsigned int> &array_shape;
125  const vector<unsigned int> &chunk_shape;
126 
127  one_chunk_unconstrained_args(int *pipe, unsigned char id, Chunk *c, DmrppArray *a, const vector<unsigned int> &a_s, const vector<unsigned int> &c_s)
128  : fds(pipe), tid(id), chunk(c), array(a), array_shape(a_s), chunk_shape(c_s) {}
129 };
130 
134  int *fds; // pipe back to parent
135  unsigned char tid; // thread id as a byte
136  Chunk *child_chunk; // this chunk reads data; temporary allocation
137  Chunk *master_chunk; // this chunk gets the data; shared memory, managed by DmrppArray
138 
139  one_child_chunk_args(int *pipe, unsigned char id, Chunk *c_c, Chunk *m_c)
140  : fds(pipe), tid(id), child_chunk(c_c), master_chunk(m_c) {}
141 
143  delete child_chunk;
144  }
145 
146 };
147 
148 } // namespace dmrpp
149 
150 #endif // _dmrpp_array_h
151 
dmrpp::Chunk
Definition: Chunk.h:43
dmrpp::DmrppCommon
Size and offset information of data included in DMR++ files.
Definition: DmrppCommon.h:62
dmrpp::DmrppArray::read
virtual bool read()
Read data for the array.
Definition: DmrppArray.cc:1224
libdap
Definition: BESDapFunctionResponseCache.h:35
dmrpp::one_chunk_unconstrained_args
Chunk data insert args for use with pthreads.
Definition: DmrppArray.h:119
dmrpp::DmrppArray
Extend libdap::Array so that a handler can read data using a DMR++ file.
Definition: DmrppArray.h:60
dmrpp::one_child_chunk_args
Definition: DmrppArray.h:133
dmrpp::DmrppArray::get_size
virtual unsigned long long get_size(bool constrained=false)
Return the total number of elements in this Array.
Definition: DmrppArray.cc:163
dmrpp::DmrppArray::print_dap4
virtual void print_dap4(libdap::XMLWriter &writer, bool constrained=false)
Shadow libdap::Array::print_dap4() - optionally prints DMR++ chunk information.
Definition: DmrppArray.cc:1350
dmrpp::DmrppArray::get_shape
virtual std::vector< unsigned int > get_shape(bool constrained)
Get the array shape.
Definition: DmrppArray.cc:179