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_config.h"
5 #include "teca_dataset.h"
6 #include "teca_variant_array.h"
7 #include "teca_metadata.h"
8 
9 #include <map>
10 #include <vector>
11 #include <string>
12 
13 #include "teca_shared_object.h"
14 TECA_SHARED_OBJECT_FORWARD_DECL(teca_cf_time_axis_data)
15 
16 /// A dataset used to read NetCDF CF2 time and metadata in parallel.
17 /** The dataset contains elements (one per file) of type:
18  * std::pair<p_teca_variant_array, teca_metadata> holding the time axis and
19  * associated NetCDF attributes.
20  */
22 {
23 public:
24  TECA_DATASET_STATIC_NEW(teca_cf_time_axis_data)
25  TECA_DATASET_NEW_INSTANCE()
26  TECA_DATASET_NEW_COPY()
27 
28  ~teca_cf_time_axis_data() override;
29 
30  using elem_t = std::pair<p_teca_variant_array, teca_metadata>;
31 
32  /** transfer the element associated with file to the dataset.
33  * after transfer the passed element is invalid in the calling context
34  */
35  void transfer(unsigned long file_id, elem_t &&data);
36 
37  /// access the file's element
38  elem_t &get(unsigned long file_id);
39  const elem_t &get(unsigned long file_id) const;
40 
41  /// given an element extract metadata
42  static
43  teca_metadata &get_metadata(elem_t&elem)
44  { return elem.second; }
45 
46  /// given an element extract metadata
47  static
48  const teca_metadata &get_metadata(const elem_t &elem)
49  { return elem.second; }
50 
52 
53  /// given an element extract the time axis
54  static
56  { return elem.first; }
57 
58  /// given an element extract the time axis
59  static
61  { return elem.first; }
62 
63  /// append the data from the other instance
64  void append(const const_p_teca_dataset &other);
65  void shallow_append(const const_p_teca_dataset &other);
66 
67  /// return a unique string identifier
68  std::string get_class_name() const override
69  { return "teca_cf_time_axis_data"; }
70 
71  /// return an integer identifier uniquely naming the dataset type
72  int get_type_code() const override;
73 
74  /// covert to boolean. @returns true if the dataset is not empty, otherwise false.
75  explicit operator bool() const noexcept
76  { return !this->empty(); }
77 
78  /// return true if the dataset is empty.
79  bool empty() const noexcept override;
80 
81  /// serialize the dataset to/from the given stream for I/O or communication
82  int to_stream(teca_binary_stream &) const override;
83  int from_stream(teca_binary_stream &) override;
84 
85  /// stream to/from human readable representation
86  int to_stream(std::ostream &) const override;
87  int from_stream(std::istream &) override;
88 
89  /// @copydoc teca_dataset::copy(const const_p_teca_dataset &,allocator)
90  void copy(const const_p_teca_dataset &other,
91  allocator alloc = allocator::malloc) override;
92 
93  /// @copydoc teca_dataset::shallow_copy(const p_teca_dataset &)
94  void shallow_copy(const p_teca_dataset &other) override;
95 
96  /// swap internals of the two objects
97  void swap(const p_teca_dataset &other) override;
98 
99 #if defined(SWIG)
100 protected:
101 #else
102 public:
103 #endif
104  /// @note This constructor is public to enable std::make_shared. Do not use.
106 
107 protected:
108  teca_cf_time_axis_data(const teca_cf_time_axis_data &other) = delete;
110  teca_cf_time_axis_data &operator=(const teca_cf_time_axis_data &other) = delete;
111 
112 private:
113  using internals_t = std::map<unsigned long, elem_t>;
114  internals_t *internals;
115 };
116 
117 #endif
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:17
A dataset used to read NetCDF CF2 time and metadata in parallel.
Definition: teca_cf_time_axis_data.h:22
std::string get_class_name() const override
return a unique string identifier
Definition: teca_cf_time_axis_data.h:68
int get_type_code() const override
return an integer identifier uniquely naming the dataset type
bool empty() const noexcept override
return true if the dataset is empty.
void append(const const_p_teca_dataset &other)
append the data from the other instance
static const_p_teca_variant_array get_variant_array(const elem_t &elem)
given an element extract the time axis
Definition: teca_cf_time_axis_data.h:60
static const teca_metadata & get_metadata(const elem_t &elem)
given an element extract metadata
Definition: teca_cf_time_axis_data.h:48
static p_teca_variant_array get_variant_array(elem_t &elem)
given an element extract the time axis
Definition: teca_cf_time_axis_data.h:55
Interface for TECA datasets.
Definition: teca_dataset.h:232
virtual teca_metadata & get_metadata() noexcept
get the dataset metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
TECA_EXPORT bool copy(teca_variant_array *varr, PyObject *obj)
Copy values from the object into variant array.
Definition: teca_py_array.h:290
auto data(V &&... args)
Definition: teca_variant_array_util.h:255
std::shared_ptr< teca_variant_array > p_teca_variant_array
Definition: teca_variant_array.h:27
std::shared_ptr< const teca_variant_array > const_p_teca_variant_array
Definition: teca_variant_array.h:27