TECA
The Toolkit for Extreme Climate Analysis
teca_cf_time_axis_data.h
1 #ifndef teca_cf_time_axis_data_h
2 #define teca_cf_time_axis_data_h
3 
4 #include "teca_dataset.h"
5 #include "teca_variant_array.h"
6 #include "teca_metadata.h"
7 
8 #include <map>
9 #include <vector>
10 #include <string>
11 
12 #include "teca_shared_object.h"
13 TECA_SHARED_OBJECT_FORWARD_DECL(teca_cf_time_axis_data)
14 
15 /// A dataset used to read NetCDF CF2 time and metadata in parallel.
17 {
18 public:
19  TECA_DATASET_STATIC_NEW(teca_cf_time_axis_data)
20  TECA_DATASET_NEW_INSTANCE()
21  TECA_DATASET_NEW_COPY()
22 
23  ~teca_cf_time_axis_data() override;
24 
25  using elem_t = std::pair<p_teca_variant_array, teca_metadata>;
26 
27  // transfer the element associated with file to the dataset.
28  // after transfer the passed element is invalid in the calling context
29  void transfer(unsigned long file_id, elem_t &&data);
30 
31  // access the file's element
32  elem_t &get(unsigned long file_id);
33  const elem_t &get(unsigned long file_id) const;
34 
35  // given an element extract metadata
36  static
37  teca_metadata &get_metadata(elem_t&elem)
38  { return elem.second; }
39 
40  static
41  const teca_metadata &get_metadata(const elem_t &elem)
42  { return elem.second; }
43 
44  // given an element extract the time axis
45  static
46  p_teca_variant_array get_variant_array(elem_t &elem)
47  { return elem.first; }
48 
49  static
50  const_p_teca_variant_array get_variant_array(const elem_t &elem)
51  { return elem.first; }
52 
53  // append the data from the other instance
54  void append(const const_p_teca_dataset &other);
55  void shallow_append(const const_p_teca_dataset &other);
56 
57  // return a unique string identifier
58  std::string get_class_name() const override
59  { return "teca_cf_time_axis_data"; }
60 
61  // return an integer identifier uniquely naming the dataset type
62  int get_type_code() const override;
63 
64  // covert to boolean. true if the dataset is not empty.
65  // otherwise false.
66  explicit operator bool() const noexcept
67  { return !this->empty(); }
68 
69  // return true if the dataset is empty.
70  bool empty() const noexcept override;
71 
72  // serialize the dataset to/from the given stream
73  // for I/O or communication
74  int to_stream(teca_binary_stream &) const override;
75  int from_stream(teca_binary_stream &) override;
76 
77  // stream to/from human readable representation
78  int to_stream(std::ostream &) const override;
79  int from_stream(std::istream &) override;
80 
81  // copy data and metadata. shallow copy uses reference
82  // counting, while copy duplicates the data.
83  void copy(const const_p_teca_dataset &other) override;
84 
85  // deep copy a subset of row values.
86  void copy(const const_p_teca_cf_time_axis_data &other,
87  unsigned long first_row, unsigned long last_row);
88 
89  void shallow_copy(const p_teca_dataset &other) override;
90 
91  // swap internals of the two objects
92  void swap(const p_teca_dataset &other) override;
93 
94 protected:
96 
97  teca_cf_time_axis_data(const teca_cf_time_axis_data &other) = delete;
99  teca_cf_time_axis_data &operator=(const teca_cf_time_axis_data &other) = delete;
100 
101 private:
102  using internals_t = std::map<unsigned long, elem_t>;
103  internals_t *internals;
104 };
105 
106 #endif
teca_variant_array.h
teca_binary_stream
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:15
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:18
teca_dataset
Interface for TECA datasets.
Definition: teca_dataset.h:216
teca_cf_time_axis_data
A dataset used to read NetCDF CF2 time and metadata in parallel.
Definition: teca_cf_time_axis_data.h:16
const_p_teca_variant_array
std::shared_ptr< const teca_variant_array > const_p_teca_variant_array
Definition: teca_variant_array.h:22
teca_shared_object.h
p_teca_variant_array
std::shared_ptr< teca_variant_array > p_teca_variant_array
Definition: teca_variant_array.h:22
teca_py_array::append
bool append(teca_variant_array *varr, PyObject *obj)
Append values from the object to the variant array.
Definition: teca_py_array.h:213
teca_py_array::copy
bool copy(teca_variant_array *varr, PyObject *obj)
Copy values from the object into variant array.
Definition: teca_py_array.h:270