HDTree  0.5.2
HDTree C++ API
Writer.h
1 #pragma once
2 
3 #include <boost/core/demangle.hpp>
4 #include <utility>
5 
6 // using HighFive
7 #include <highfive/H5File.hpp>
8 
9 #include "hdtree/Atomic.h"
10 #include "hdtree/Constants.h"
11 #include "hdtree/Exception.h"
12 
13 namespace hdtree {
14 
21 class Writer {
22  public:
31  Writer(const std::pair<std::string, std::string>& file_tree_path,
32  bool inplace = false, int rows_per_chunk = 10000, bool shuffle = true,
33  int compression_level = 6);
34 
38  ~Writer();
39 
43  int getRowsPerChunk() const { return rows_per_chunk_; }
44 
50  void flush();
51 
55  void increment();
56 
60  const std::string& name() const;
61 
77  void structure(const std::string& branch_name,
78  const std::pair<std::string, int>& type);
79 
80  HighFive::DataSet createDataSet(const std::string& branch_name,
81  HighFive::DataType data_type);
82 
86  inline std::size_t entries() const { return entries_; }
87 
97  friend std::ostream& operator<<(std::ostream& s, const Writer& w) {
98  return s << "Writer(" << w.name() << ")";
99  }
100 
102  Writer(const Writer&) = delete;
104  void operator=(const Writer&) = delete;
105 
106  private:
110  HighFive::File file_;
114  HighFive::Group tree_;
116  HighFive::DataSetCreateProps create_props_;
118  HighFive::DataSpace space_;
120  std::size_t entries_;
122  std::size_t rows_per_chunk_;
123 };
124 
125 } // namespace hdtree
Definitions for names of structures required by serialization methods.
Write the fire DataSets into a deterministic structure in the output HDF5 data file.
Definition: Writer.h:21
std::size_t entries_
the expected number of entries in this file
Definition: Writer.h:120
const std::string & name() const
Get the name of this file.
Definition: Writer.cxx:44
std::size_t rows_per_chunk_
number of rows to keep in each chunk
Definition: Writer.h:122
void flush()
Flush the data to disk.
Definition: Writer.cxx:35
std::size_t entries() const
Get the number of entries in the file.
Definition: Writer.h:86
HighFive::File file_
our highfive file
Definition: Writer.h:110
Writer(const Writer &)=delete
don't allow copies of the Writer
~Writer()
Close up our file, making sure to flush contents to disk.
Definition: Writer.cxx:33
void increment()
increment the number of entries in the HDTree
Definition: Writer.cxx:46
friend std::ostream & operator<<(std::ostream &s, const Writer &w)
Stream this writer.
Definition: Writer.h:97
HighFive::DataSpace space_
the dataspace shared amongst all of our datasets
Definition: Writer.h:118
void operator=(const Writer &)=delete
don't allow copies of the Writer
void structure(const std::string &branch_name, const std::pair< std::string, int > &type)
Persist the structure of the event object at the input branch_name.
Definition: Writer.cxx:48
int getRowsPerChunk() const
get rows per chunk
Definition: Writer.h:43
HighFive::DataSetCreateProps create_props_
the creation properties to be used on datasets we are writing
Definition: Writer.h:116
Writer(const std::pair< std::string, std::string > &file_tree_path, bool inplace=false, int rows_per_chunk=10000, bool shuffle=true, int compression_level=6)
Open the file in write mode.
Definition: Writer.cxx:8
HighFive::Group tree_
handle to the HighFive group we will make be an HDTree
Definition: Writer.h:114
Geant4 does a GLOBAL definition of the keyword TRUE.
Definition: Atomic.cxx:3