g4tools  5.4.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::hdf5::store Class Reference
Inheritance diagram for tools::hdf5::store:
Inheritance graph
[legend]

Public Member Functions

 store (std::ostream &a_out, hid_t a_group, const std::string &a_name, bool a_write, unsigned int a_compress)
 
virtual ~store ()
 
std::ostream & out () const
 
bool entries (tools::uint64 &a_entries) const
 
pagescreate_pages (const std::string &a_name, const std::string &a_form)
 
hid_t group () const
 
unsigned int compress_level () const
 

Protected Member Functions

 store (const store &a_from)
 
storeoperator= (const store &)
 

Protected Attributes

std::ostream & m_out
 
std::string m_name
 
bool m_write
 
unsigned int m_compress
 
hid_t m_group
 
std::vector< pages * > m_pagess
 

Detailed Description

Definition at line 15 of file store.

Constructor & Destructor Documentation

◆ store() [1/2]

tools::hdf5::store::store ( std::ostream &  a_out,
hid_t  a_group,
const std::string &  a_name,
bool  a_write,
unsigned int  a_compress 
)
inline

Definition at line 19 of file store.

20  :m_out(a_out)
21  ,m_write(a_write)
22  ,m_compress(a_compress) //used at write.
23  ,m_group(-1)
24  {
25 #ifdef TOOLS_MEM
26  tools::mem::increment(s_class().c_str());
27 #endif
28  if(m_write) {
29  if(a_name.empty()) {
30  a_out << "tools::hdf5::store::store : string a_name is empty." << std::endl;
31  m_group = -1;
32  return;
33  }
34  m_group = tools_H5Gcreate(a_group,a_name.c_str(),0);
35  if(m_group<0) {
36  a_out << "tools::hdf5::store::store : can't create " << a_name << " group." << std::endl;
37  m_group = -1;
38  return;
39  }
40  if(!write_atb(m_group,"type","object")) {
41  m_out << "tools::hdf5::store::store : write_atb(type) failed." << std::endl;
42  ::H5Gclose(m_group);
43  m_group = -1;
44  return;
45  }
46  if(!write_atb(m_group,"class",s_class())) {
47  m_out << "tools::hdf5::store::store : write_atb(class) failed." << std::endl;
48  ::H5Gclose(m_group);
49  m_group = -1;
50  return;
51  }
52  int v = 2; //1->2 add "type" atb.
53  if(!write_scalar_atb<int>(m_group,"version",v)) {
54  m_out << "tools::hdf5::store::store : write_scalar_atb(version) failed." << std::endl;
55  ::H5Gclose(m_group);
56  m_group = -1;
57  return;
58  }
59  } else { // to read.
60  m_group = tools_H5Gopen(a_group,a_name.c_str());
61  if(m_group<0) {
62  a_out << "tools::hdf5::store::store : can't open " << a_name << " group." << std::endl;
63  m_group = -1;
64  return;
65  }
66  std::vector<std::string> names;
67  if(!read_array_string(m_group,s_names(),names)) {
68  m_out << "tools::hdf5::store::store : read_array_string(names) failed." << std::endl;
69  ::H5Gclose(m_group);
70  m_group = -1;
71  return;
72  }
73  std::vector<std::string> TFORMs;
74  if(!read_array_string(m_group,s_forms(),TFORMs)) {
75  m_out << "tools::hdf5::store::store : read_array_string(tforms) failed." << std::endl;
76  ::H5Gclose(m_group);
77  m_group = -1;
78  return;
79  }
80  if(names.size()!=TFORMs.size()) {
81  m_out << "tools::hdf5::store::store : names/TFORMs size mismatch." << std::endl;
82  m_out << "names :" << std::endl;
83  {tools_vforcit(std::string,names,it) m_out << *it << std::endl;}
84  m_out << "TFORMs :" << std::endl;
85  {tools_vforcit(std::string,TFORMs,it) m_out << *it << std::endl;}
86  ::H5Gclose(m_group);
87  m_group = -1;
88  return;
89  }
90  for(size_t index=0;index<names.size();index++) {
91  if(!create_pages(names[index],TFORMs[index])) {
92  m_out << "tools::hdf5::store::store : can't create hdf5_column "
93  << tools::sout(names[index]) << "." << std::endl;
95  ::H5Gclose(m_group);
96  m_group = -1;
97  return;
98  }
99  }
100  }
101  }

◆ ~store()

virtual tools::hdf5::store::~store ( )
inlinevirtual

Definition at line 102 of file store.

102  {
103  if(m_write) {
104  tools::uint64 _entries;
105  if(!entries(_entries)) {
106  m_out << "tools::hdf5::store::~store : not same entries on all columns. Write 0." << std::endl;
107  }
108  if(m_group<0) { //constructor may have failed.
109  } else {
110  if(!write_scalar<tools::uint64>(m_group,s_entries(),_entries)) {
111  m_out << "tools::hdf5::store::~store : write_scalar(entries) failed." << std::endl;
112  }
113  if(!write_scalar<unsigned int>(m_group,s_columns(),m_pagess.size())) {
114  m_out << "tools::hdf5::store::~store : write_scalar(columns) failed." << std::endl;
115  }
116  {std::vector<std::string> names;
117  tools_vforcit(pages*,m_pagess,it) names.push_back((*it)->name());
118  //{m_out << "debug : write : names :" << std::endl;
119  // tools_vforcit(std::string,names,it) m_out << *it << std::endl;}
120  if(!write_array_string(m_group,s_names(),names)) {
121  m_out << "tools::hdf5::store::~store : write_array_string(names) failed." << std::endl;
122  }}
123  {std::vector<std::string> TFORMs;
124  tools_vforcit(pages*,m_pagess,it) TFORMs.push_back((*it)->form());
125  //{m_out << "debug : write : TFORMs :" << std::endl;
126  // tools_vforcit(std::string,TFORMs,it) m_out << *it << std::endl;}
127  if(!write_array_string(m_group,s_forms(),TFORMs)) {
128  m_out << "tools::hdf5::store::~store : write_array_string(tforms) failed." << std::endl;
129  }}
130  }
131  }
133  if(m_group<0) { //constructor may have failed.
134  } else {
135  ::H5Gclose(m_group);
136  }
137 #ifdef TOOLS_MEM
138  tools::mem::decrement(s_class().c_str());
139 #endif
140  }

◆ store() [2/2]

tools::hdf5::store::store ( const store a_from)
inlineprotected

Definition at line 142 of file store.

143  :m_out(a_from.m_out)
144  ,m_name(a_from.m_name)
145  ,m_compress(a_from.m_compress)
146  ,m_group(-1)
147  {
148 #ifdef TOOLS_MEM
149  tools::mem::increment(s_class().c_str());
150 #endif
151  }

Member Function Documentation

◆ compress_level()

unsigned int tools::hdf5::store::compress_level ( ) const
inline

Definition at line 193 of file store.

193 {return m_compress;}

◆ create_pages()

pages* tools::hdf5::store::create_pages ( const std::string &  a_name,
const std::string &  a_form 
)
inline

Definition at line 171 of file store.

171  {
172  //::printf("debug : create_pages %s %s\n",a_name.c_str(),a_form.c_str());
173  pages* _pages = new pages(m_out,m_group,a_name,a_form,m_write,m_compress);
174  if(!_pages->is_valid()) {
175  m_out << "tools::hdf5::store::create_column : can't create pages." << std::endl;
176  delete _pages;
177  return 0;
178  }
179  m_pagess.push_back(_pages);
180  return _pages;
181  }

◆ entries()

bool tools::hdf5::store::entries ( tools::uint64 a_entries) const
inline

Definition at line 157 of file store.

157  {
158  if(m_pagess.empty()) {a_entries = 0;return true;}
159  a_entries = m_pagess.front()->entries();
160  tools_vforcit(pages*,m_pagess,it) {
161  if((*it)->entries()!=a_entries) {
162  m_out << "tools::hdf5::store::entries : not same entries on all columns."
163  << " Front " << a_entries << ", it " << (*it)->entries() << "." << std::endl;
164  a_entries = 0;
165  return false;
166  }
167  }
168  return true;
169  }

◆ group()

hid_t tools::hdf5::store::group ( ) const
inline

Definition at line 192 of file store.

192 {return m_group;}

◆ operator=()

store& tools::hdf5::store::operator= ( const store )
inlineprotected

Definition at line 152 of file store.

152 {return *this;}

◆ out()

std::ostream& tools::hdf5::store::out ( ) const
inline

Definition at line 154 of file store.

154 {return m_out;}

Member Data Documentation

◆ m_compress

unsigned int tools::hdf5::store::m_compress
protected

Definition at line 198 of file store.

◆ m_group

hid_t tools::hdf5::store::m_group
protected

Definition at line 199 of file store.

◆ m_name

std::string tools::hdf5::store::m_name
protected

Definition at line 196 of file store.

◆ m_out

std::ostream& tools::hdf5::store::m_out
protected

Definition at line 195 of file store.

◆ m_pagess

std::vector<pages*> tools::hdf5::store::m_pagess
protected

Definition at line 200 of file store.

◆ m_write

bool tools::hdf5::store::m_write
protected

Definition at line 197 of file store.


The documentation for this class was generated from the following file:
tools::uint64
unsigned long long uint64
Definition: typedefs:72
tools_H5Gcreate
#define tools_H5Gcreate
Definition: hdf5_h:30
tools::hdf5::store::entries
bool entries(tools::uint64 &a_entries) const
Definition: store:157
tools::hdf5::store::m_out
std::ostream & m_out
Definition: store:195
tools::hdf5::store::m_compress
unsigned int m_compress
Definition: store:198
tools::hdf5::read_array_string
bool read_array_string(hid_t a_loc, const std::string &a_name, std::vector< std::string > &a_array)
Definition: tools:995
tools::hdf5::write_atb
bool write_atb(hid_t a_id, const std::string &a_name, const std::string &a_data)
Definition: tools:320
tools::safe_clear
void safe_clear(std::map< K, V * > &a_m)
Definition: mapmanip:12
tools::hdf5::store::m_pagess
std::vector< pages * > m_pagess
Definition: store:200
tools::sout
Definition: sout:17
tools::hdf5::store::m_write
bool m_write
Definition: store:197
tools::hdf5::store::m_name
std::string m_name
Definition: store:196
tools::hdf5::store::m_group
hid_t m_group
Definition: store:199
tools::hdf5::store::create_pages
pages * create_pages(const std::string &a_name, const std::string &a_form)
Definition: store:171
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools_H5Gopen
#define tools_H5Gopen
Definition: hdf5_h:31
tools::hdf5::write_array_string
bool write_array_string(hid_t a_loc, const std::string &a_name, const std::vector< std::string > &a_array)
Definition: tools:594