areaDetector  3-14
EPICS areaDetector framework
NDFileHDF5Layout.h
Go to the documentation of this file.
1 /*
2  * NDFileHDF5Layout.h
3  *
4  * Created on: 23 Jan 2012
5  * Author: up45
6  */
7 
8 #ifndef NDFILEHDF5LAYOUT_H_
9 #define NDFILEHDF5LAYOUT_H_
10 
11 #include <ostream>
12 #include <string>
13 #include <vector>
14 #include <map>
15 #include <set>
16 
17 namespace hdf5
18 {
19 
20  typedef enum {
24  } When_t;
25 
26  typedef enum {
30  constant
32 
33  typedef enum {
44  string
46 
49  class DataSource
50  {
51  public:
52  // Default constructor
53  DataSource();
54  // Initialising constructor
55  DataSource(DataSrc_t src, const std::string& val);
56  DataSource(DataSrc_t src);
57  DataSource(DataSrc_t src, DataType_t type);
58  // Copy constructor
59  DataSource( const DataSource& src);
60  // Assignment operator
61  DataSource& operator=(const DataSource& src);
63  void set_datatype(DataType_t type);
64  bool is_src_detector();
65  bool is_src_ndattribute();
66  bool is_src_constant();
67  bool is_src(DataSrc_t src);
68 
71  size_t datatype_size();
72  void set_const_datatype_value(DataType_t dtype, const std::string& str_val);
73 
74  void set_when_to_save(When_t when);
76 
77  private:
78  DataSrc_t data_src;
79  std::string val;
80  DataType_t datatype;
81  When_t when_to_save;
82  };
83 
84 
87  class Attribute
88  {
89  public:
90  Attribute(){};
91  Attribute(const Attribute& src); // Copy constructor
92  Attribute(std::string& name);
93  Attribute(const char* name);
94  Attribute(const char* name, DataSource& src);
96  Attribute& operator=(const Attribute& src);
98  void setOnFileOpen(bool onOpen);
99  bool is_onFileOpen();
100  bool is_onFileClose();
101 
103  private:
104  void _copy(const Attribute& src);
105  std::string name;
106  bool onFileOpen;
107  };
108 
114  class Element
115  {
116  public:
117  Element();
118  Element(const Element& src);
119  Element(const std::string& name);
120  ~Element(){};
121  Element& operator=(const Element& src);
122 
123  const std::string& get_name();
124  virtual std::string get_full_name();
125  virtual std::string get_path(bool trailing_slash=false);
126  int add_attribute(Attribute& attr);
127  bool has_attribute(const std::string& attr_name);
128  int tree_level();
129  Element *get_parent();
130  typedef std::map<std::string, Attribute> MapAttributes_t;
132 
133  protected:
134  void _copy(const Element& src);
137 
138  public:
139  friend class Group;
140 
141  private:
142  Element *parent;
143  };
144 
145 
148  class Dataset: public Element
149  {
150  public:
151  Dataset();
152  Dataset(const std::string& name);
153  Dataset(const Dataset& src);
154  Dataset& operator=(const Dataset& src);
155  virtual ~Dataset();
156 
158  inline friend std::ostream& operator<<(std::ostream& out, Dataset& dset)
159  { out << dset._str_(); return out; }
160  std::string _str_();
162  void set_data_source(DataSource& src);
163  void set_data_source(DataSource& src, size_t max_elements);
165 
166  void data_alloc_max_elements(size_t max_elements);
167  size_t data_append_value(void * val);
168  size_t data_num_elements();
169  size_t data_store_size();
170  void data_stored();
171  const void * data();
172  void set_src_default(bool def);
173  bool is_src_default();
174  void set_ndattr_name(const std::string& name);
175  bool has_ndattr_name(const std::string& name);
176 
177  private:
178  void _copy(const Dataset& src);
179  DataSource datasource;
180 
181  void data_clear();
182  void * data_ptr;
183  size_t data_nelements;
184  size_t data_current_element;
185  size_t data_max_bytes;
186  size_t data_nelements_stored;
187  bool data_default;
188  std::string ndattr_name;
189  };
190 
193  class HardLink: public Element
194  {
195  public:
196  HardLink();
197  HardLink(const std::string& name);
198  HardLink(const HardLink& src);
199  HardLink& operator=(const HardLink& src);
200  virtual ~HardLink();
201 
203  inline friend std::ostream& operator<<(std::ostream& out, HardLink& hardLink)
204  { out << hardLink._str_(); return out; }
205  std::string _str_();
207  void set_target(const std::string& target);
209 
210  private:
211  void _copy(const HardLink& src);
212  std::string target;
213  };
214 
220  class Group: public Element
221  {
222  public:
223  Group();
224  Group(const std::string& name);
225  Group(const char * name);
226  Group(const Group& src);
227  virtual ~Group();
228  Group& operator=(const Group& src);
229 
230  Dataset* new_dset(const std::string& name);
231  Dataset* new_dset(const char * name);
232  Group* new_group(const std::string& name);
233  Group* new_group(const char * name);
235  HardLink* new_hardlink(const char * name);
236  int find_dset_ndattr(const std::string& ndattr_name, Dataset** dset);
237  int find_dset_ndattr(const char * ndattr_name, Dataset** dset);
238  int find_dset( std::string& dsetname, Dataset** dest);
239  int find_dset( const char* dsetname, Dataset** dest);
243  int num_groups();
244  int num_datasets();
245 
247  inline friend std::ostream& operator<<(std::ostream& out, Group& grp)
248  { out << grp._str_(); return out; }
249  std::string _str_();
251  typedef std::map<std::string, Group*> MapGroups_t;
252  typedef std::map<std::string, Dataset*> MapDatasets_t;
253  typedef std::map<std::string, HardLink*> MapHardLinks_t;
257  void find_dsets(DataSrc_t source, MapDatasets_t& dsets);
259  typedef std::map<std::string, DataSource*> MapNDAttrSrc_t;
260  virtual void merge_ndattributes(MapNDAttrSrc_t::const_iterator it_begin,
261  MapNDAttrSrc_t::const_iterator it_end,
262  std::set<std::string>& used_ndattribute_srcs);
263 
264  private:
265  void _copy(const Group& src);
266  bool name_exist(const std::string& name);
267  bool ndattr_default_container;
268  std::map<std::string, Dataset*> datasets;
269  std::map<std::string, Group*> groups;
270  std::map<std::string, HardLink*> hardlinks;
271  };
272 
275  class Root: public Group
276  {
277  public:
278  Root();
279  Root(const std::string& name);
280  Root(const char *name);
281  virtual ~Root(){};
282  virtual void merge_ndattributes(MapNDAttrSrc_t::const_iterator it_begin,
283  MapNDAttrSrc_t::const_iterator it_end,
284  std::set<std::string>& used_ndattribute_srcs);
285  std::string get_full_name(){ return ""; };
286  std::string get_path(bool trailing_slash=false){ return ""; };
287  };
288 
289 } // hdf5
290 
291 
292 #endif /* LAYOUT_H_ */
Class used for writing an Attribute with the NDFileHDF5 plugin.
Definition: NDFileHDF5Layout.h:88
DataSource source
Definition: NDFileHDF5Layout.h:102
bool is_onFileOpen()
Definition: NDFileHDF5Layout.cpp:54
~Attribute()
Definition: NDFileHDF5Layout.h:95
bool is_onFileClose()
Definition: NDFileHDF5Layout.cpp:60
void setOnFileOpen(bool onOpen)
Definition: NDFileHDF5Layout.cpp:49
Attribute()
Definition: NDFileHDF5Layout.h:90
std::string get_name()
Definition: NDFileHDF5Layout.cpp:44
Attribute & operator=(const Attribute &src)
Definition: NDFileHDF5Layout.cpp:38
Class used for writing a DataSource with the NDFileHDF5 plugin.
Definition: NDFileHDF5Layout.h:50
~DataSource()
Definition: NDFileHDF5Layout.h:62
bool is_src_ndattribute()
Definition: NDFileHDF5Layout.cpp:121
std::string get_src_def()
Definition: NDFileHDF5Layout.cpp:131
size_t datatype_size()
Definition: NDFileHDF5Layout.cpp:141
void set_const_datatype_value(DataType_t dtype, const std::string &str_val)
Definition: NDFileHDF5Layout.cpp:172
void set_datatype(DataType_t type)
Definition: NDFileHDF5Layout.cpp:106
void set_when_to_save(When_t when)
Definition: NDFileHDF5Layout.cpp:179
DataType_t get_datatype()
return the string that define the source: either name of NDAttribute or constant value
Definition: NDFileHDF5Layout.cpp:136
When_t get_when_to_save()
Definition: NDFileHDF5Layout.cpp:184
bool is_src_constant()
Definition: NDFileHDF5Layout.cpp:111
DataSource & operator=(const DataSource &src)
Assignment operator Copies the sources private data members to this object.
Definition: NDFileHDF5Layout.cpp:97
bool is_src_detector()
Definition: NDFileHDF5Layout.cpp:116
DataSource()
Definition: NDFileHDF5Layout.cpp:73
bool is_src(DataSrc_t src)
Definition: NDFileHDF5Layout.cpp:126
Class used for writing a DataSet with the NDFileHDF5 plugin.
Definition: NDFileHDF5Layout.h:149
void data_alloc_max_elements(size_t max_elements)
Definition: NDFileHDF5Layout.cpp:756
bool is_src_default()
Definition: NDFileHDF5Layout.cpp:826
Dataset & operator=(const Dataset &src)
Definition: NDFileHDF5Layout.cpp:701
void set_data_source(DataSource &src)
Return a string representation of the object.
Definition: NDFileHDF5Layout.cpp:739
std::string _str_()
Definition: NDFileHDF5Layout.cpp:711
void set_ndattr_name(const std::string &name)
Definition: NDFileHDF5Layout.cpp:831
friend std::ostream & operator<<(std::ostream &out, Dataset &dset)
Stream operator: use to prints a string representation of this class.
Definition: NDFileHDF5Layout.h:158
size_t data_num_elements()
Definition: NDFileHDF5Layout.cpp:786
void set_src_default(bool def)
Definition: NDFileHDF5Layout.cpp:821
Dataset()
Definition: NDFileHDF5Layout.cpp:679
DataSource & data_source()
Definition: NDFileHDF5Layout.cpp:751
size_t data_append_value(void *val)
Definition: NDFileHDF5Layout.cpp:765
size_t data_store_size()
Definition: NDFileHDF5Layout.cpp:791
const void * data()
Definition: NDFileHDF5Layout.cpp:804
virtual ~Dataset()
Definition: NDFileHDF5Layout.cpp:693
void data_stored()
Definition: NDFileHDF5Layout.cpp:796
bool has_ndattr_name(const std::string &name)
Definition: NDFileHDF5Layout.cpp:836
Describe a generic structure element with the NDFileHDF5 plugin.
Definition: NDFileHDF5Layout.h:115
void _copy(const Element &src)
Definition: NDFileHDF5Layout.cpp:278
const std::string & get_name()
Definition: NDFileHDF5Layout.cpp:236
bool has_attribute(const std::string &attr_name)
Definition: NDFileHDF5Layout.cpp:261
Element()
Definition: NDFileHDF5Layout.cpp:190
std::map< std::string, Attribute > MapAttributes_t
Definition: NDFileHDF5Layout.h:130
Element * get_parent()
Definition: NDFileHDF5Layout.cpp:241
~Element()
Definition: NDFileHDF5Layout.h:120
int add_attribute(Attribute &attr)
Definition: NDFileHDF5Layout.cpp:251
std::string name
Definition: NDFileHDF5Layout.h:136
virtual std::string get_path(bool trailing_slash=false)
Definition: NDFileHDF5Layout.cpp:214
virtual std::string get_full_name()
Definition: NDFileHDF5Layout.cpp:207
MapAttributes_t attributes
Definition: NDFileHDF5Layout.h:135
int tree_level()
Definition: NDFileHDF5Layout.cpp:266
MapAttributes_t & get_attributes()
Definition: NDFileHDF5Layout.cpp:246
Element & operator=(const Element &src)
Definition: NDFileHDF5Layout.cpp:226
Describe a group element.
Definition: NDFileHDF5Layout.h:221
std::string _str_()
Definition: NDFileHDF5Layout.cpp:530
int num_datasets()
Definition: NDFileHDF5Layout.cpp:520
Group & operator=(const Group &src)
Definition: NDFileHDF5Layout.cpp:319
std::map< std::string, DataSource * > MapNDAttrSrc_t
return a map of datasets [string name, Dataset dset] which contains all datasets, marked as [source] ...
Definition: NDFileHDF5Layout.h:259
void set_default_ndattr_group()
Definition: NDFileHDF5Layout.cpp:497
Dataset * new_dset(const std::string &name)
Definition: NDFileHDF5Layout.cpp:329
MapGroups_t & get_groups()
Definition: NDFileHDF5Layout.cpp:554
virtual ~Group()
Definition: NDFileHDF5Layout.cpp:310
Group()
Definition: NDFileHDF5Layout.cpp:287
std::map< std::string, Dataset * > MapDatasets_t
Definition: NDFileHDF5Layout.h:252
MapHardLinks_t & get_hardlinks()
Definition: NDFileHDF5Layout.cpp:559
void find_dsets(DataSrc_t source, MapDatasets_t &dsets)
Definition: NDFileHDF5Layout.cpp:564
int find_detector_default_dset(Dataset **dset)
<< search through subgroups to return a pointer to the NDAttribute default container group
Definition: NDFileHDF5Layout.cpp:451
MapDatasets_t & get_datasets()
Definition: NDFileHDF5Layout.cpp:549
int find_dset_ndattr(const std::string &ndattr_name, Dataset **dset)
Definition: NDFileHDF5Layout.cpp:430
int num_groups()
Definition: NDFileHDF5Layout.cpp:525
HardLink * new_hardlink(const std::string &name)
Create a new HardLink, insert it into the group list, set the full path name, and finally return a po...
Definition: NDFileHDF5Layout.cpp:396
std::map< std::string, Group * > MapGroups_t
Return a string representation of the object.
Definition: NDFileHDF5Layout.h:251
Group * find_ndattr_default_group()
Definition: NDFileHDF5Layout.cpp:502
virtual void merge_ndattributes(MapNDAttrSrc_t::const_iterator it_begin, MapNDAttrSrc_t::const_iterator it_end, std::set< std::string > &used_ndattribute_srcs)
Definition: NDFileHDF5Layout.cpp:583
std::map< std::string, HardLink * > MapHardLinks_t
Definition: NDFileHDF5Layout.h:253
Group * new_group(const std::string &name)
Create a new group, insert it into the group list, set the full path name, and finally return a point...
Definition: NDFileHDF5Layout.cpp:363
int find_dset(std::string &dsetname, Dataset **dest)
Definition: NDFileHDF5Layout.cpp:477
friend std::ostream & operator<<(std::ostream &out, Group &grp)
Stream operator: use to prints a string representation of this class.
Definition: NDFileHDF5Layout.h:247
Class used for writing the root of the file with the NDFileHDF5 plugin.
Definition: NDFileHDF5Layout.h:276
virtual void merge_ndattributes(MapNDAttrSrc_t::const_iterator it_begin, MapNDAttrSrc_t::const_iterator it_end, std::set< std::string > &used_ndattribute_srcs)
Definition: NDFileHDF5Layout.cpp:639
std::string get_path(bool trailing_slash=false)
Definition: NDFileHDF5Layout.h:286
Root()
Definition: NDFileHDF5Layout.cpp:627
virtual ~Root()
Definition: NDFileHDF5Layout.h:281
std::string get_full_name()
Definition: NDFileHDF5Layout.h:285
Definition: NDFileHDF5Layout.cpp:17
DataSrc_t
Definition: NDFileHDF5Layout.h:26
@ constant
Definition: NDFileHDF5Layout.h:30
@ notset
Definition: NDFileHDF5Layout.h:27
@ ndattribute
Definition: NDFileHDF5Layout.h:29
@ detector
Definition: NDFileHDF5Layout.h:28
When_t
Definition: NDFileHDF5Layout.h:20
@ OnFrame
Definition: NDFileHDF5Layout.h:21
@ OnFileClose
Definition: NDFileHDF5Layout.h:23
@ OnFileOpen
Definition: NDFileHDF5Layout.h:22
DataType_t
Definition: NDFileHDF5Layout.h:33
@ int8
Definition: NDFileHDF5Layout.h:34
@ int64
Definition: NDFileHDF5Layout.h:40
@ int16
Definition: NDFileHDF5Layout.h:36
@ uint8
Definition: NDFileHDF5Layout.h:35
@ float32
Definition: NDFileHDF5Layout.h:42
@ uint32
Definition: NDFileHDF5Layout.h:39
@ uint64
Definition: NDFileHDF5Layout.h:41
@ uint16
Definition: NDFileHDF5Layout.h:37
@ string
Definition: NDFileHDF5Layout.h:44
@ float64
Definition: NDFileHDF5Layout.h:43
@ int32
Definition: NDFileHDF5Layout.h:38