bes Updated for version 3.20.13
DMZ.h
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of the BES
5
6// Copyright (c) 2021 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 h_dmz_h
26#define h_dmz_h 1
27
28#include <string>
29#include <vector>
30#include <set>
31#include <stack>
32#include <memory>
33
34#define PUGIXML_NO_XPATH
35#define PUGIXML_HEADER_ONLY
36#include <pugixml.hpp>
37
38#include <libdap/Type.h>
39
40namespace libdap {
41class DMR;
42class BaseType;
43class Array;
44class D4Group;
45class D4Attributes;
46class Constructor;
47}
48
49namespace http {
50class url;
51}
52
53namespace dmrpp {
54
55using shape = std::vector<unsigned long long>;
56
57class Chunk;
58class DmrppCommon;
59
72class DMZ {
73
74private:
75 pugi::xml_document d_xml_doc;
76 std::shared_ptr<http::url> d_dataset_elem_href;
77
79 static const std::set<std::string> variable_elements;
80
81 void process_dataset(libdap::DMR *dmr, const pugi::xml_node &xml_root);
82 static pugi::xml_node get_variable_xml_node(libdap::BaseType *btp);
83 void process_chunk(dmrpp::DmrppCommon *dc, const pugi::xml_node &chunk) const;
84 void process_chunks(dmrpp::DmrppCommon *dc, const pugi::xml_node &chunks) const;
85
86 static void process_fill_value_chunks(dmrpp::DmrppCommon *dc, const std::set<shape> &chunk_map, const shape &chunk_shape,
87 const shape &array_shape, unsigned long long chunk_size);
88
89 static std::vector<unsigned long long int> get_array_dims(libdap::Array *array);
90 static size_t logical_chunks(const std::vector<unsigned long long> &array_dim_sizes, const dmrpp::DmrppCommon *dc);
91 static std::set< std::vector<unsigned long long> > get_chunk_map(const std::vector<std::shared_ptr<Chunk>> &chunks);
92
93 static void process_compact(libdap::BaseType *btp, const pugi::xml_node &compact);
94
95 static pugi::xml_node get_variable_xml_node_helper(const pugi::xml_node &var_node, std::stack<libdap::BaseType*> &bt);
96 static void build_basetype_chain(libdap::BaseType *btp, std::stack<libdap::BaseType*> &bt);
97
98 static void process_group(libdap::DMR *dmr, libdap::D4Group *parent, const pugi::xml_node &var_node);
99 static void process_dimension(libdap::D4Group *grp, const pugi::xml_node &dimension_node);
100 static void process_variable(libdap::DMR *dmr, libdap::D4Group *grp, libdap::Constructor *parent, const pugi::xml_node &var_node);
101 static void process_dim(libdap::DMR *dmr, libdap::D4Group *grp, libdap::Array *array, const pugi::xml_node &dim_node);
102 static void process_map(libdap::DMR *dmr, libdap::D4Group *grp, libdap::Array *array, const pugi::xml_node &map_node);
103 static libdap::BaseType *build_variable(libdap::DMR *dmr, libdap::D4Group *group, libdap::Type t, const pugi::xml_node &var_node);
104 static libdap::BaseType *add_scalar_variable(libdap::DMR *dmr, libdap::D4Group *group, libdap::Constructor *parent, libdap::Type t, const pugi::xml_node &var_node);
105 static libdap::BaseType *add_array_variable(libdap::DMR *dmr, libdap::D4Group *grp, libdap::Constructor *parent, libdap::Type t, const pugi::xml_node &var_node);
106 static void process_attribute(libdap::D4Attributes *attributes, const pugi::xml_node &dap_attr_node);
107
108 static void process_cds_node(dmrpp::DmrppCommon *dc, const pugi::xml_node &chunks);
109
110 void load_attributes(libdap::BaseType *btp, pugi::xml_node var_node) const;
111
112 friend class DMZTest;
113
114public:
115
117 DMZ() = default;
118
119 explicit DMZ(const std::string &file_name);
120
121 virtual ~DMZ() = default;
122
123 // This is not virtual because we call it from a ctor
124 void parse_xml_doc(const std::string &filename);
125
126 virtual void build_thin_dmr(libdap::DMR *dmr);
127
128 virtual void load_attributes(libdap::BaseType *btp);
129 virtual void load_attributes(libdap::Constructor *constructor);
130 virtual void load_attributes(libdap::D4Group *group);
131
132 virtual void load_chunks(libdap::BaseType *btp);
133
134 virtual void load_all_attributes(libdap::DMR *dmr);
135};
136
137} // namespace dmrpp
138
139#endif // h_dmz_h
140
Interface to hide the DMR++ information storage format.
Definition: DMZ.h:72
DMZ()=default
Build a DMZ without simultaneously parsing an XML document.
virtual void load_chunks(libdap::BaseType *btp)
Load the chunk information into a variable.
Definition: DMZ.cc:1161
void parse_xml_doc(const std::string &filename)
Build the DOM tree for a DMR++ XML document.
Definition: DMZ.cc:146
virtual void build_thin_dmr(libdap::DMR *dmr)
populate the DMR instance as a 'thin DMR'
Definition: DMZ.cc:578
Size and offset information of data included in DMR++ files.
Definition: DmrppCommon.h:94
utility class for the HTTP catalog module
Definition: AllowedHosts.cc:55