IODA Bundle
WriterDispatchingIterator.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 ///
12 /// \file WriterDispatchingIterator.h
13 ///
14 /// @author Piotr Kuchta, June 2009
15 
16 #ifndef odc_WriterDispatchingIterator_H
17 #define odc_WriterDispatchingIterator_H
18 
19 #include <map>
20 #include <cstdint>
21 
22 #include "eckit/sql/SQLTypedefs.h"
23 
24 #include "odc/api/ColumnType.h"
25 #include "odc/TemplateParameters.h"
26 #include "odc/Writer.h"
27 
28 namespace eckit { class PathName; }
29 namespace eckit { class DataHandle; }
30 
31 namespace odc {
32 
33 class TemplateParameters;
34 
35 template <typename WRITE_ITERATOR, typename OWNER >
37 {
38  typedef std::vector<double> Values;
39  typedef std::map<Values,int> Values2IteratorIndex;
40  typedef std::vector<WRITE_ITERATOR *> Iterators;
41 public:
42  WriterDispatchingIterator (OWNER &owner, int maxOpenFiles, bool append = false);
44 
45  int open();
46 
47  double* data();
48  double& data(size_t i);
49 
50  int setColumn(size_t index, std::string name, api::ColumnType type);
51  int setBitfieldColumn(size_t index, std::string name, api::ColumnType type, eckit::sql::BitfieldDef b);
52 
53  void missingValue(size_t i, double);
54 
55  template <typename T> unsigned long pass1(T&, const T&);
56  template <typename T> void verify(T&, const T&);
57  unsigned long gatherStats(const double* values, unsigned long count);
58 
59  int close();
60 
61  api::ColumnType columnType(size_t index);
62  const std::string& columnName(size_t index) const;
63  const std::string& codecName(size_t index) const;
64  double columnMissingValue(size_t index);
65 
66  const core::MetaData& columns() const { return columns_; }
67  const core::MetaData& columns(const core::MetaData& md);
68 
69  OWNER& owner() { return owner_; }
70 
71  void property(std::string key, std::string value);
72  std::string property(std::string);
73 
74  //std::vector<eckit::PathName> getFiles();
75  std::vector<eckit::PathName> outputFiles();
77 
78  size_t rowDataSizeDoubles() const;
79 
80  /// The offset of a given column in the doubles[] data array
81  size_t dataOffset(size_t i) const { ASSERT(columnOffsets_); return columnOffsets_[i]; }
82 
83 //protected:
84  void writeHeader();
85 
86  int writeRow(const double* values, unsigned long count);
87 
88 protected:
89  bool next();
90 
91  /// Find iterator data should be dispatched to.
92  WRITE_ITERATOR& dispatch(const double* values, unsigned long count);
93  int dispatchIndex(const double* values, unsigned long count);
94  int createIterator(const Values& dispatchedValues, const std::string& fileName);
95 
96  std::string generateFileName(const double* values, unsigned long count);
97 
98  OWNER& owner_;
101  double* lastValues_;
102  double* nextRow_;
103  size_t* columnOffsets_;
104  unsigned long long nrows_;
105  std::string outputFileTemplate_;
106 
108 
109  std::vector<int> dispatchedIndexes_;
111  std::vector<unsigned long long> lastDispatch_;
112  std::vector<std::string> iteratorIndex2fileName_;
113 
117  bool append_;
118 
119 private:
120 // No copy allowed.
123 
125 
127 
129  std::vector<eckit::PathName> files_;
130 
133 
134  std::map<std::string,int> filesCreated_;
135 
137 };
138 
139 } // namespace odc
140 
142 
143 #endif
static void count(void *counter, const double *data, size_t n)
Definition: UnitTests.cc:531
Writer< WRITE_ITERATOR > iteratorsOwner_
WriterDispatchingIterator & operator=(const WriterDispatchingIterator &)
WRITE_ITERATOR & dispatch(const double *values, unsigned long count)
Find iterator data should be dispatched to.
unsigned long gatherStats(const double *values, unsigned long count)
std::vector< eckit::PathName > files_
const core::MetaData & columns() const
std::vector< unsigned long long > lastDispatch_
std::vector< WRITE_ITERATOR * > Iterators
std::string generateFileName(const double *values, unsigned long count)
std::map< Values, int > Values2IteratorIndex
api::ColumnType columnType(size_t index)
std::vector< eckit::PathName > outputFiles()
int writeRow(const double *values, unsigned long count)
WriterDispatchingIterator(OWNER &owner, int maxOpenFiles, bool append=false)
int createIterator(const Values &dispatchedValues, const std::string &fileName)
WriterDispatchingIterator(const WriterDispatchingIterator &)
size_t dataOffset(size_t i) const
The offset of a given column in the doubles[] data array.
int setColumn(size_t index, std::string name, api::ColumnType type)
int setBitfieldColumn(size_t index, std::string name, api::ColumnType type, eckit::sql::BitfieldDef b)
void verify(T &, const T &)
unsigned long pass1(T &, const T &)
double columnMissingValue(size_t index)
int dispatchIndex(const double *values, unsigned long count)
std::map< std::string, int > filesCreated_
const std::string & codecName(size_t index) const
void property(std::string key, std::string value)
const std::string & columnName(size_t index) const
std::vector< std::string > iteratorIndex2fileName_
std::map< std::string, std::string > Properties
Definition: Header.h:35
Definition: ColumnInfo.h:23