g4tools  5.4.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::hdf5::pages Class Reference

Public Member Functions

 pages (std::ostream &a_out, hid_t a_group, const std::string &a_name, const std::string &a_form, bool a_write, unsigned int a_compress)
 
virtual ~pages ()
 
bool is_valid () const
 
const std::string & name () const
 
const std::string & form () const
 
tools::uint64 entries () const
 
tools::uint64 pos () const
 
void reset_pos ()
 
template<class TYPE >
bool write_page (size_t a_size, const TYPE *a_array)
 
template<class TYPE >
bool read_page (size_t a_size, TYPE *a_array)
 
template<class TYPE >
bool write_vlen (size_t a_size, const TYPE *a_array)
 
template<class TYPE >
bool read_vlen (size_t &a_size, TYPE *&a_array)
 
bool write_string (const std::string &a_string)
 
bool read_string (std::string &a_string)
 

Protected Member Functions

 pages (const pages &a_from)
 
pagesoperator= (const pages &)
 

Protected Attributes

std::ostream & m_out
 
std::string m_name
 
std::string m_form
 
hid_t m_group
 
hid_t m_dataset
 
bool m_write
 
unsigned int m_compress
 
tools::uint64 m_entries
 
tools::uint64 m_pos
 

Detailed Description

Definition at line 27 of file pages.

Constructor & Destructor Documentation

◆ pages() [1/2]

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

Definition at line 30 of file pages.

33  :m_out(a_out),m_name(a_name),m_form(a_form)
34  //,m_type(0),m_size(0)
35  ,m_group(-1),m_dataset(-1),m_write(a_write),m_compress(a_compress),m_entries(0),m_pos(0){
36 #ifdef TOOLS_MEM
37  tools::mem::increment(s_class().c_str());
38 #endif
39  if(m_write) {
40  m_group = tools_H5Gcreate(a_group,m_name.c_str(),0);
41  if(m_group<0) {
42  m_out << "pages::pages : can't create group for column " << m_name << "." << std::endl;
43  m_group = -1;
44  return;
45  }
46  if(!write_atb(m_group,"class",s_class())) {
47  m_out << "pages::pages : write_atb(class) failed." << std::endl;
48  ::H5Gclose(m_group);
49  m_group = -1;
50  return;
51  }
52  int v = 1;
53  if (!write_scalar_atb<int>(m_group,"version",v)) {
54  m_out << "pages::pages : write_scalar_atb(version) failed." << std::endl;
55  ::H5Gclose(m_group);
56  m_group = -1;
57  return;
58  }
59  } else {
60  m_group = tools_H5Gopen(a_group,m_name.c_str());
61  if(m_group<0) {
62  m_out << "pages::pages : can't open group for column " << m_name << "." << std::endl;
63  m_group = -1;
64  return;
65  }
66  if(!read_scalar<tools::uint64>(m_group,s_entries(),m_entries)) {
67  m_out << "pages::pages : read_scalar(entries) failed." << std::endl;
68  ::H5Gclose(m_group);
69  m_group = -1;
70  return;
71  }
72  }
73  }

◆ ~pages()

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

Definition at line 74 of file pages.

74  {
75  if(m_write) {
76  if(!write_scalar<tools::uint64>(m_group,s_entries(),m_entries)) {
77  m_out << "pages::~pages : write_scalar(entries) failed." << std::endl;
78  }
79  if(m_dataset>=0) ::H5Dclose(m_dataset);
80  }
81  ::H5Gclose(m_group);
82 #ifdef TOOLS_MEM
83  tools::mem::decrement(s_class().c_str());
84 #endif
85  }

◆ pages() [2/2]

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

Definition at line 87 of file pages.

87  :m_out(a_from.m_out){
88 #ifdef TOOLS_MEM
89  tools::mem::increment(s_class().c_str());
90 #endif
91  }

Member Function Documentation

◆ entries()

tools::uint64 tools::hdf5::pages::entries ( ) const
inline

Definition at line 100 of file pages.

100 {return m_entries;}

◆ form()

const std::string& tools::hdf5::pages::form ( ) const
inline

Definition at line 97 of file pages.

97 {return m_form;}

◆ is_valid()

bool tools::hdf5::pages::is_valid ( ) const
inline

Definition at line 94 of file pages.

94 {return m_group<0?false:true;}

◆ name()

const std::string& tools::hdf5::pages::name ( ) const
inline

Definition at line 96 of file pages.

96 {return m_name;}

◆ operator=()

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

Definition at line 92 of file pages.

92 {return *this;}

◆ pos()

tools::uint64 tools::hdf5::pages::pos ( ) const
inline

Definition at line 101 of file pages.

101 {return m_pos;}

◆ read_page()

template<class TYPE >
bool tools::hdf5::pages::read_page ( size_t  a_size,
TYPE *  a_array 
)
inline

Definition at line 128 of file pages.

128  {
129  //it is assumed that a_array can contain a_size*sizeof(TYPE) bytes.
130  unsigned int _size = a_size;
131  unsigned int n = 0;
132  TYPE* array = 0;
133  if(!read_sub_array<TYPE>(m_group,s_pages(),(unsigned int)m_pos,(unsigned int)_size,n,array)) {
134  m_out << "pages::read_page : read_sub_array<TYPE>() failed." << std::endl;
135  return false;
136  }
137  if(n!=_size) {
138  m_out << "pages::read_page : size mismatch. Requested " << _size << ", got "<< n << "." << std::endl;
139  delete [] array;
140  return false;
141  }
142 
143  {TYPE* rpos = (TYPE*)array;
144  TYPE* wpos = (TYPE*)a_array;
145  for(size_t i=0;i<n;i++,rpos++,wpos++) *wpos = *rpos;
146  for(size_t i=n;i<_size;i++,rpos++,wpos++) *wpos = TYPE();}
147 
148  delete [] array;
149 
150  m_pos += n;
151  return true;
152  }

◆ read_string()

bool tools::hdf5::pages::read_string ( std::string &  a_string)
inline

Definition at line 215 of file pages.

215  {
216  if(!read_sub_string(m_group,s_pages(),(unsigned int)m_pos,a_string)) {
217  m_out << "pages::read_string : read_sub_string() failed." << std::endl;
218  a_string.clear();
219  return false;
220  }
221  m_pos++;
222  m_entries++;
223  return true;
224  }

◆ read_vlen()

template<class TYPE >
bool tools::hdf5::pages::read_vlen ( size_t &  a_size,
TYPE *&  a_array 
)
inline

Definition at line 178 of file pages.

178  {
179  //it is assumed that a_array can contain a_size*sizeof(TYPE) bytes.
180  unsigned int sz;
181  if(!read_sub_vlen<TYPE>(m_group,s_pages(),(unsigned int)m_pos,sz,a_array)) {
182  m_out << "pages::read_vlen : read_sub_vlen<TYPE>() failed." << std::endl;
183  a_size = 0;
184  a_array = 0;
185  return false;
186  }
187  a_size = sz;
188  m_pos++;
189  m_entries++;
190  return true;
191  }

◆ reset_pos()

void tools::hdf5::pages::reset_pos ( )
inline

Definition at line 102 of file pages.

102 {m_pos = 0;}

◆ write_page()

template<class TYPE >
bool tools::hdf5::pages::write_page ( size_t  a_size,
const TYPE *  a_array 
)
inline

Definition at line 105 of file pages.

105  {
106  if(!m_pos) {
107  if(!write_array<TYPE>(m_group,s_pages(),a_size,a_array,a_size?a_size:32,m_compress)) {
108  m_out << "pages::write_page : write_array<TYPE>() failed. Pos " << m_pos << std::endl;
109  return false;
110  }
111  m_dataset = tools_H5Dopen(m_group,s_pages().c_str());
112  if(m_dataset<0) {
113  m_out << "pages::write_page : H5Dopen failed. Pos " << m_pos << std::endl;
114  return false;
115  }
116  } else {
117  if(!write_append_array_dataset<TYPE>(m_dataset,a_size,a_array)) {
118  m_out << "pages::write_page : write_append_array_dataset<TYPE>() failed. Pos " << m_pos << std::endl;
119  return false;
120  }
121  }
122  m_pos += a_size;
123  m_entries = m_pos;
124  return true;
125  }

◆ write_string()

bool tools::hdf5::pages::write_string ( const std::string &  a_string)
inline

Definition at line 193 of file pages.

193  {
194  if(!m_pos) {
195  if(!hdf5::write_string_dataset(m_group,s_pages(),a_string,128,m_compress)) { //32=>enforce extendable.
196  m_out << "pages::write_string : hdf5::write_string() failed. Pos " << m_pos << std::endl;
197  return false;
198  }
199  m_dataset = tools_H5Dopen(m_group,s_pages().c_str());
200  if(m_dataset<0) {
201  m_out << "pages::write_string : H5Dopen failed. Pos " << m_pos << std::endl;
202  return false;
203  }
204  } else {
205  if(!write_append_string_dataset(m_dataset,a_string)) {
206  m_out << "pages::write_string : write_append_string_dataset() failed. Pos " << m_pos << std::endl;
207  return false;
208  }
209  }
210  m_pos++;
211  m_entries++;
212  return true;
213  }

◆ write_vlen()

template<class TYPE >
bool tools::hdf5::pages::write_vlen ( size_t  a_size,
const TYPE *  a_array 
)
inline

Definition at line 155 of file pages.

155  {
156  if(!m_pos) {
157  if(!hdf5::write_vlen<TYPE>(m_group,s_pages(),a_size,a_array,a_size?a_size:32,m_compress)) {
158  m_out << "pages::write_vlen : write_vlen<TYPE>() failed. Pos " << m_pos << std::endl;
159  return false;
160  }
161  m_dataset = tools_H5Dopen(m_group,s_pages().c_str());
162  if(m_dataset<0) {
163  m_out << "pages::write_vlen : H5Dopen failed. Pos " << m_pos << std::endl;
164  return false;
165  }
166  } else {
167  if(!write_append_vlen_dataset<TYPE>(m_dataset,a_size,a_array)) {
168  m_out << "pages::write_vlen : write_append_vlen_dataset<TYPE>() failed. Pos " << m_pos << std::endl;
169  return false;
170  }
171  }
172  m_pos++;
173  m_entries++;
174  return true;
175  }

Member Data Documentation

◆ m_compress

unsigned int tools::hdf5::pages::m_compress
protected

Definition at line 312 of file pages.

◆ m_dataset

hid_t tools::hdf5::pages::m_dataset
protected

Definition at line 310 of file pages.

◆ m_entries

tools::uint64 tools::hdf5::pages::m_entries
protected

Definition at line 313 of file pages.

◆ m_form

std::string tools::hdf5::pages::m_form
protected

Definition at line 306 of file pages.

◆ m_group

hid_t tools::hdf5::pages::m_group
protected

Definition at line 309 of file pages.

◆ m_name

std::string tools::hdf5::pages::m_name
protected

Definition at line 305 of file pages.

◆ m_out

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

Definition at line 304 of file pages.

◆ m_pos

tools::uint64 tools::hdf5::pages::m_pos
protected

Definition at line 314 of file pages.

◆ m_write

bool tools::hdf5::pages::m_write
protected

Definition at line 311 of file pages.


The documentation for this class was generated from the following file:
tools::hdf5::pages::m_write
bool m_write
Definition: pages:311
tools_H5Gcreate
#define tools_H5Gcreate
Definition: hdf5_h:30
tools::hdf5::pages::m_form
std::string m_form
Definition: pages:306
tools::hdf5::pages::m_pos
tools::uint64 m_pos
Definition: pages:314
tools_H5Dopen
#define tools_H5Dopen
Definition: hdf5_h:25
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::hdf5::write_string_dataset
bool write_string_dataset(hid_t a_loc, const std::string &a_name, unsigned int a_chunked, unsigned int a_compress, const std::string &a_string)
Definition: tools:442
tools::hdf5::pages::m_name
std::string m_name
Definition: pages:305
tools::hdf5::pages::m_group
hid_t m_group
Definition: pages:309
tools::hdf5::pages::m_entries
tools::uint64 m_entries
Definition: pages:313
tools::hdf5::pages::m_dataset
hid_t m_dataset
Definition: pages:310
tools::hdf5::pages::m_out
std::ostream & m_out
Definition: pages:304
tools::hdf5::pages::m_compress
unsigned int m_compress
Definition: pages:312
tools::hdf5::write_append_string_dataset
bool write_append_string_dataset(hid_t a_dataset, const std::string &a_string)
Definition: tools:525
tools_H5Gopen
#define tools_H5Gopen
Definition: hdf5_h:31
tools::hdf5::read_sub_string
bool read_sub_string(hid_t a_loc, const std::string &a_name, unsigned int a_offset, std::string &a_string)
Definition: tools:771