QMCPACK
ObservableHelper.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2022 QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 // William F. Godoy, godoywf@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 /**@file ObservableHelper.h
17  *@brief Declaration of ObservableHelper and other helper class for observables
18  */
19 #ifndef QMCPLUSPLUS_OBSERVABLEHELPER_H
20 #define QMCPLUSPLUS_OBSERVABLEHELPER_H
21 
22 #include "Configuration.h"
23 #include "hdf/hdf_archive.h"
24 #include "hdf/hdf_path.h"
25 
26 namespace qmcplusplus
27 {
29 
30 /** define ObservableHelper
31  *
32  * This is a helper class to manage a hdf5 dagroup for each collectable.
33  * The data handled by an Estimator should be presented by dense N-dim array in C.
34  * /observables/title/value
35  */
37 {
38 public:
39  /**
40  * Favored constructor
41  * \param[in] title is the ordered hdf5 group path elements of the observable
42  */
44 
45  /**
46  * delete copy constructor as hdf5 handlers must have unique owners
47  */
48  ObservableHelper(const ObservableHelper&) = delete;
50 
51  /**
52  * Move constructor.
53  * @param in input object to be moved to this
54  */
55  ObservableHelper(ObservableHelper&&) noexcept = default;
56  ObservableHelper& operator=(ObservableHelper&&) noexcept = default;
57 
58  /**
59  * Destructor closes hdf5 remaining resources
60  */
62 
63  /**
64  * set the shape of this observable
65  * @param dims dimensions
66  * @param first starting index
67  */
68  void set_dimensions(const std::vector<int>& dims, int first);
69 
70  /** add named property to describe the collectable this helper class handles
71  * @param p any intrinsic datatype including vector, basic containers
72  * @param pname property
73  */
74  template<typename T>
75  inline void addProperty(T& p, const std::string& pname, hdf_archive& file)
76  {
77  file.push(group_name, true);
78  file.write(p, pname);
79  file.pop();
80  }
81 
82  void addProperty(float& p, const std::string& pname, hdf_archive& file);
83  void addProperty(Tensor<float, OHMMS_DIM>& p, const std::string& pname, hdf_archive& file);
84  void addProperty(Matrix<float>& p, const std::string& pname, hdf_archive& file);
85  void addProperty(TinyVector<float, OHMMS_DIM>& p, const std::string& pname, hdf_archive& file);
86  void addProperty(std::vector<float>& p, const std::string& pname, hdf_archive& file);
87  void addProperty(std::vector<TinyVector<float, OHMMS_DIM>>& p, const std::string& pname, hdf_archive& file);
88 
89  void write(const value_type* const first_v, hdf_archive& file);
90 
91  ///starting index
92  hsize_t lower_bound = 0;
93 
94 private:
95  /// "file pointer" for h5d_append
96  hsize_t current = 0;
97  /// Path of this observable
99  ///my dimensions
100  std::vector<hsize_t> mydims;
101  ///offsets
102  std::vector<hsize_t> offsets;
103 };
104 } // namespace qmcplusplus
105 #endif
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
std::vector< hsize_t > offsets
offsets
void write(T &data, const std::string &aname)
write the data to the group aname and check status runtime error is issued on I/O error ...
Definition: hdf_archive.h:259
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
~ObservableHelper()
Destructor closes hdf5 remaining resources.
ObservableHelper(hdf_path title)
Favored constructor.
class to handle hdf file
Definition: hdf_archive.h:51
void write(const value_type *const first_v, hdf_archive &file)
void addProperty(T &p, const std::string &pname, hdf_archive &file)
add named property to describe the collectable this helper class handles
hsize_t current
"file pointer" for h5d_append
define ObservableHelper
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32
std::vector< hsize_t > mydims
my dimensions
hsize_t lower_bound
starting index
hdf_path group_name
Path of this observable.
void push(const std::string &gname, bool createit=true)
push a group to the group stack
void set_dimensions(const std::vector< int > &dims, int first)
set the shape of this observable
ObservableHelper & operator=(const ObservableHelper &)=delete
std::vector< int > dims
QTFull::RealType FullPrecRealType
Definition: Configuration.h:66
QMCTraits::FullPrecRealType value_type