HDTree  0.5.2
HDTree C++ API
Reader.h
1 #pragma once
2 
3 #include <utility>
4 
5 // using HighFive
6 #include <highfive/H5File.hpp>
7 
8 #include "hdtree/AbstractBranch.h"
9 #include "hdtree/Atomic.h"
10 #include "hdtree/Writer.h"
11 
12 namespace hdtree {
13 
24 class Reader {
25  public:
39  Reader(const std::pair<std::string, std::string>& file_tree_path,
40  bool inplace = false);
41 
52  virtual std::vector<std::pair<std::string, std::string>> availableObjects();
53 
65  virtual std::pair<std::string, int> type(const std::string& branch_name);
66 
71  virtual std::string name() const;
72 
83  std::vector<std::string> list(const std::string& group_path) const;
84 
88  HighFive::DataSet getDataSet(const std::string& branch_name) const;
89 
99  HighFive::DataType getDataSetType(const std::string& dataset) const;
100 
106  HighFive::ObjectType getH5ObjectType(const std::string& path) const;
107 
120  std::string getTypeName(const std::string& obj_name) const;
121 
129  inline std::size_t entries() const { return entries_; }
130 
135  virtual bool canCopy() const { return true; }
136 
149  virtual void copy(unsigned long int i_entry, const std::string& branch_name,
150  Writer& output);
151 
153  Reader(const Reader&) = delete;
155  void operator=(const Reader&) = delete;
156 
157  private:
165  void mirror(const std::string& branch_name, Writer& output);
166 
167  private:
178  class MirrorObject {
180  std::unique_ptr<BaseBranch> data_;
182  std::unique_ptr<BaseBranch> size_member_;
184  std::vector<std::unique_ptr<MirrorObject>> obj_members_;
186  unsigned long int last_entry_{0};
187 
188  public:
192  MirrorObject(const std::string& branch_name, Reader& reader,
193  Writer& writer);
194 
198  void copy(unsigned long int i_entry, unsigned long int n);
199  };
200 
201  private:
203  HighFive::File file_;
205  HighFive::Group tree_;
207  std::size_t entries_;
210  std::unordered_map<std::string, std::unique_ptr<MirrorObject>>
212 }; // Reader
213 
214 } // namespace hdtree
A mirror event object.
Definition: Reader.h:178
unsigned long int last_entry_
the last entry that was copied
Definition: Reader.h:186
MirrorObject(const std::string &branch_name, Reader &reader, Writer &writer)
Construct this mirror object and any of its (data or object) children.
Definition: Reader.cxx:98
std::unique_ptr< BaseBranch > size_member_
handle to the size member of this object (if it exists)
Definition: Reader.h:182
std::vector< std::unique_ptr< MirrorObject > > obj_members_
list of sub-objects within this object
Definition: Reader.h:184
std::unique_ptr< BaseBranch > data_
handle to the atomic data type once we get down to that point
Definition: Reader.h:180
void copy(unsigned long int i_entry, unsigned long int n)
Copy the n entries starting from i_entry.
Definition: Reader.cxx:156
Reading a file generated by fire.
Definition: Reader.h:24
virtual std::string name() const
Get the name of this file.
Definition: Reader.cxx:17
HighFive::File file_
our highfive file
Definition: Reader.h:203
HighFive::DataSet getDataSet(const std::string &branch_name) const
Get data set.
Definition: Reader.cxx:25
HighFive::ObjectType getH5ObjectType(const std::string &path) const
Get the H5 type of object at the input path.
Definition: Reader.cxx:33
virtual void copy(unsigned long int i_entry, const std::string &branch_name, Writer &output)
Copy the input data set to the output file.
Definition: Reader.cxx:72
virtual bool canCopy() const
We can copy.
Definition: Reader.h:135
std::size_t entries_
the number of entries in this file, set in constructor
Definition: Reader.h:207
Reader(const Reader &)=delete
never want to copy a reader
std::size_t entries() const
Get the number of entries in the file.
Definition: Reader.h:129
HighFive::Group tree_
the HighFive group that is our HDTree
Definition: Reader.h:205
virtual std::pair< std::string, int > type(const std::string &branch_name)
Get the type of the input object.
Definition: Reader.cxx:42
std::unordered_map< std::string, std::unique_ptr< MirrorObject > > mirror_objects_
our in-memory mirror objects for data being copied to the output file without processing
Definition: Reader.h:211
virtual std::vector< std::pair< std::string, std::string > > availableObjects()
Get the event objects available in the file.
Definition: Reader.cxx:37
void mirror(const std::string &branch_name, Writer &output)
Mirror the structure of the passed branch_name from us into the output file.
Definition: Reader.cxx:62
Reader(const std::pair< std::string, std::string > &file_tree_path, bool inplace=false)
Open the file in read mode.
Definition: Reader.cxx:8
HighFive::DataType getDataSetType(const std::string &dataset) const
Deduce the type of the dataset requested.
Definition: Reader.cxx:29
std::vector< std::string > list(const std::string &group_path) const
List the entries inside of a group.
Definition: Reader.cxx:19
std::string getTypeName(const std::string &obj_name) const
Get the 'type' attribute from the input group name.
void operator=(const Reader &)=delete
never want to copy a reader
Write the fire DataSets into a deterministic structure in the output HDF5 data file.
Definition: Writer.h:21
Geant4 does a GLOBAL definition of the keyword TRUE.
Definition: Atomic.cxx:3