TECA
The Toolkit for Extreme Climate Analysis
teca_cf_space_time_time_step_mapper.h
1 #ifndef teca_cf_space_time_time_step_mapper_h
2 #define teca_cf_space_time_time_step_mapper_h
3 
4 #include "teca_config.h"
5 #include "teca_metadata.h"
6 #include "teca_cf_layout_manager.h"
7 #include "teca_cf_time_step_mapper.h"
8 #include "teca_calendar_util.h"
9 #include "teca_mpi.h"
10 #include "teca_coordinate_util.h"
11 
12 #include <iostream>
13 #include <sstream>
14 #include <cstring>
15 #include <cerrno>
16 #include <string>
17 #include <unordered_map>
18 #include <vector>
19 #include <memory>
20 
22 using p_teca_cf_space_time_time_step_mapper = std::shared_ptr<teca_cf_space_time_time_step_mapper>;
23 
24 /// NetCDF CF2 files time step mapper.
26 {
27 public:
28 
29  /// allocate and return a new object
30  static p_teca_cf_space_time_time_step_mapper New()
31  { return p_teca_cf_space_time_time_step_mapper(new teca_cf_space_time_time_step_mapper); }
32 
34 
35  /** initialize based on input metadata. this is a collective call creates
36  * communicator groups for each file and creates the file layout managers
37  * for the local rank. After this call one can access file managers to
38  * create, define and write local datasets to the NetCDF files in cf
39  * format.
40  *
41  * @param[in] comm the MPI communicator to parallelize execution across
42  * @param[in] first_step the first step to process
43  * @param[in] last_step the last step to process
44  * @param[in] number_of_temporal_partitons the number of temporal
45  * partitions or zero to use the
46  * temporal_partiton_size parameter
47  * @param[in] temporal_partition_size number of time steps per partition or
48  * zero to use the number_of_temporal
49  * partitons parameter.
50  * @param[in] extent the spatial extent to partition [i0, i1, j0, j1, k0, k1]
51  * @param[in] number_of_spatial_partitons the number of spatial partitons
52  * @param[in] partition_x if zero skip splitting in the x-direction
53  * @param[in] partition_y if zero skip splitting in the y-direction
54  * @param[in] partition_z if zero skip splitting in the z-direction
55  * @param[in] min_block_size_x sets the minimum block size in the x-direction
56  * @param[in] min_block_size_y sets the minimum block size in the y-direction
57  * @param[in] min_block_size_z sets the minimum block size in the z-direction
58  * @param[in] it a teca_interval_iterator used to define the temporal layout
59  * of the files
60  * @param[in] index_executive_compatability forces temporal_partion_size to 1
61  * @param[in] index_request_key the name of the key to use when making requests
62  *
63  * @returns zero if successful
64  */
65  int initialize(MPI_Comm comm,
66  unsigned long first_step, unsigned long last_step,
67  unsigned long number_of_temporal_partitions,
68  unsigned long temporal_partition_size, unsigned long *extent,
69  unsigned long number_of_spatial_partitions,
70  int partition_x, int partition_y, int partition_z,
71  unsigned long min_block_size_x, unsigned long min_block_size_y,
72  unsigned long min_block_size_z,
73  const teca_calendar_util::p_interval_iterator &it,
74  int index_executive_compatability, const std::string &index_request_key);
75 
77  std::vector<teca_metadata> &up_reqs) override;
78 
79  p_teca_cf_layout_manager get_layout_manager(long time_step) override;
80 
81  int get_layout_manager(const unsigned long temporal_extent[2],
82  std::vector<p_teca_cf_layout_manager> &managers) override;
83 
84  int to_stream(std::ostream &os) override;
85 
86  void write_partitions();
87 
88 protected:
90  {}
91 
92  // remove these for convenience
95  void operator=(const teca_cf_space_time_time_step_mapper&) = delete;
96  void operator=(const teca_cf_space_time_time_step_mapper&&) = delete;
97 
98  /// given a time step, get the corresponding file id
99  int get_file_id(long time_step, long &file_id);
100 
101 protected:
102  using step_bracket_t = std::pair<long, long>;
103  using temporal_extent_t = teca_coordinate_util::temporal_extent_t;
104  using spatial_extent_t = teca_coordinate_util::spatial_extent_t;
105 
106  int index_executive_compatability;
107  std::string index_request_key;
108  std::vector<step_bracket_t> file_steps;
109  spatial_extent_t whole_extent;
110  std::vector<temporal_extent_t> temporal_partitions;
111  std::deque<spatial_extent_t> spatial_partitions;
112 };
113 
114 #endif
NetCDF CF2 files time step mapper.
Definition: teca_cf_space_time_time_step_mapper.h:26
int to_stream(std::ostream &os) override
print a summary to the stream
static p_teca_cf_space_time_time_step_mapper New()
allocate and return a new object
Definition: teca_cf_space_time_time_step_mapper.h:30
int get_file_id(long time_step, long &file_id)
given a time step, get the corresponding file id
int get_layout_manager(const unsigned long temporal_extent[2], std::vector< p_teca_cf_layout_manager > &managers) override
int initialize(MPI_Comm comm, unsigned long first_step, unsigned long last_step, unsigned long number_of_temporal_partitions, unsigned long temporal_partition_size, unsigned long *extent, unsigned long number_of_spatial_partitions, int partition_x, int partition_y, int partition_z, unsigned long min_block_size_x, unsigned long min_block_size_y, unsigned long min_block_size_z, const teca_calendar_util::p_interval_iterator &it, int index_executive_compatability, const std::string &index_request_key)
p_teca_cf_layout_manager get_layout_manager(long time_step) override
given a time step returns the associated layout manager
int get_upstream_requests(teca_metadata base_req, std::vector< teca_metadata > &up_reqs) override
construct requests for this rank
Defines the interface for mapping time steps to files.
Definition: teca_cf_time_step_mapper.h:23
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
std::array< unsigned long, 2 > temporal_extent_t
Definition: teca_coordinate_util.h:1094
std::array< unsigned long, 6 > spatial_extent_t
Definition: teca_coordinate_util.h:1089
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.