TECA
The Toolkit for Extreme Climate Analysis
teca_cartesian_mesh_reader.h
1 #ifndef teca_cartesian_mesh_reader_h
2 #define teca_cartesian_mesh_reader_h
3 
4 #include "teca_config.h"
5 #include "teca_algorithm.h"
6 #include "teca_metadata.h"
7 #include "teca_shared_object.h"
8 #include "teca_cartesian_mesh.h"
9 
10 #include <vector>
11 #include <string>
12 #include <mutex>
13 
14 
15 TECA_SHARED_OBJECT_FORWARD_DECL(teca_cartesian_mesh_reader)
16 
17 /// A reader for data stored in binary cartesian_mesh format.
18 /**
19  * A reader for data stored in binary cartesian_mesh format. By default
20  * the reader reads and returns the entire cartesian_mesh on rank 0.
21  * The reader can partition the data accross an "index column".
22  * The index column assigns a unique id to rows that should be
23  * returned together. The reader reports the number of unique
24  * ids to the pipeline which can then be requested by the pipeline
25  * during parallel or sequential execution.
26  *
27  * output:
28  * generates a cartesian_mesh containing the data read from the file.
29  */
31 {
32 public:
33  TECA_ALGORITHM_STATIC_NEW(teca_cartesian_mesh_reader)
34  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_cartesian_mesh_reader)
35  TECA_ALGORITHM_CLASS_NAME(teca_cartesian_mesh_reader)
37 
38  // report/initialize to/from Boost program options
39  // objects.
40  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
41  TECA_SET_ALGORITHM_PROPERTIES()
42 
43  // the file from which data will be read.
44  TECA_ALGORITHM_PROPERTY(std::string, file_name)
45 
46  // name of the column containing index values.
47  // if this is not empty the reader will operate
48  // in parallel mode serving up requested indices
49  // on demand. otherwise rank 0 reads the entire
50  // cartesian_mesh regardless of what is requested.
51  TECA_ALGORITHM_PROPERTY(std::string, index_column)
52 
53  // when set a column named "original_ids" is placed
54  // into the output. values map back to the row number
55  // of the source dataset. By default this is off.
56  TECA_ALGORITHM_PROPERTY(int, generate_original_ids)
57 
58  // name of columns to copy directly into metadata
59  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, metadata_column_name)
60 
61  // keys that identify metadata columns
62  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, metadata_column_key)
63 
64  // add a metadata column with the given key
65  void add_metadata_column(const std::string &column, const std::string &key)
66  {
67  this->append_metadata_column_name(column);
68  this->append_metadata_column_key(key);
69  }
70 
71  // removes all metadata columns
72  void clear_metadata_columns()
73  {
74  this->clear_metadata_column_names();
75  this->clear_metadata_column_keys();
76  }
77 
78 protected:
80 
81 private:
83 
84  teca_metadata get_output_metadata(unsigned int port,
85  const std::vector<teca_metadata> &input_md) override;
86 
87  const_p_teca_dataset execute(unsigned int port,
88  const std::vector<const_p_teca_dataset> &input_data,
89  const teca_metadata &request) override;
90 
91  void set_modified() override;
92  void clear_cached_metadata();
93 
94 private:
95  std::string file_name;
96  std::string index_column;
97  int generate_original_ids;
98  std::vector<std::string> metadata_column_names;
99  std::vector<std::string> metadata_column_keys;
100 
101  struct teca_cartesian_mesh_reader_internals;
102  teca_cartesian_mesh_reader_internals *internals;
103 };
104 
105 #endif
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:244
virtual teca_metadata get_output_metadata(unsigned int port, const std::vector< teca_metadata > &input_md)
A reader for data stored in binary cartesian_mesh format.
Definition: teca_cartesian_mesh_reader.h:31
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.