areaDetector  3-5-0
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 {
31  } DataSrc_t;
32 
33  typedef enum {
42  string
43  } DataType_t;
44 
47  class DataSource
48  {
49  public:
50  // Default constructor
51  DataSource();
52  // Initialising constructor
53  DataSource(DataSrc_t src, const std::string& val);
54  DataSource(DataSrc_t src);
55  DataSource(DataSrc_t src, DataType_t type);
56  // Copy constructor
57  DataSource( const DataSource& src);
58  // Assignment operator
59  DataSource& operator=(const DataSource& src);
61  void set_datatype(DataType_t type);
62  bool is_src_detector();
63  bool is_src_ndattribute();
64  bool is_src_constant();
65  bool is_src(DataSrc_t src);
66 
69  size_t datatype_size();
70  void set_const_datatype_value(DataType_t dtype, const std::string& str_val);
71 
72  void set_when_to_save(When_t when);
74 
75  private:
76  DataSrc_t data_src;
77  std::string val;
78  DataType_t datatype;
79  When_t when_to_save;
80  };
81 
82 
85  class Attribute
86  {
87  public:
88  Attribute(){};
89  Attribute(const Attribute& src); // Copy constructor
90  Attribute(std::string& name);
91  Attribute(const char* name);
92  Attribute(const char* name, DataSource& src);
94  Attribute& operator=(const Attribute& src);
96  void setOnFileOpen(bool onOpen);
97  bool is_onFileOpen();
98  bool is_onFileClose();
99 
101  private:
102  void _copy(const Attribute& src);
103  std::string name;
104  bool onFileOpen;
105  };
106 
112  class Element
113  {
114  public:
115  Element();
116  Element(const Element& src);
117  Element(const std::string& name);
118  ~Element(){};
119  Element& operator=(const Element& src);
120 
121  const std::string& get_name();
122  virtual std::string get_full_name();
123  virtual std::string get_path(bool trailing_slash=false);
124  int add_attribute(Attribute& attr);
125  bool has_attribute(const std::string& attr_name);
126  int tree_level();
127  Element *get_parent();
128  typedef std::map<std::string, Attribute> MapAttributes_t;
130 
131  protected:
132  void _copy(const Element& src);
135 
136  public:
137  friend class Group;
138 
139  private:
140  Element *parent;
141  };
142 
143 
146  class Dataset: public Element
147  {
148  public:
149  Dataset();
150  Dataset(const std::string& name);
151  Dataset(const Dataset& src);
152  Dataset& operator=(const Dataset& src);
153  virtual ~Dataset();
154 
156  inline friend std::ostream& operator<<(std::ostream& out, Dataset& dset)
157  { out << dset._str_(); return out; }
158  std::string _str_();
160  void set_data_source(DataSource& src);
161  void set_data_source(DataSource& src, size_t max_elements);
163 
164  void data_alloc_max_elements(size_t max_elements);
165  size_t data_append_value(void * val);
166  size_t data_num_elements();
167  size_t data_store_size();
168  void data_stored();
169  const void * data();
170  void set_src_default(bool def);
171  bool is_src_default();
172  void set_ndattr_name(const std::string& name);
173  bool has_ndattr_name(const std::string& name);
174 
175  private:
176  void _copy(const Dataset& src);
177  DataSource datasource;
178 
179  void data_clear();
180  void * data_ptr;
181  size_t data_nelements;
182  size_t data_current_element;
183  size_t data_max_bytes;
184  size_t data_nelements_stored;
185  bool data_default;
186  std::string ndattr_name;
187  };
188 
191  class HardLink: public Element
192  {
193  public:
194  HardLink();
195  HardLink(const std::string& name);
196  HardLink(const HardLink& src);
197  HardLink& operator=(const HardLink& src);
198  virtual ~HardLink();
199 
201  inline friend std::ostream& operator<<(std::ostream& out, HardLink& hardLink)
202  { out << hardLink._str_(); return out; }
203  std::string _str_();
205  void set_target(const std::string& target);
207 
208  private:
209  void _copy(const HardLink& src);
210  std::string target;
211  };
212 
218  class Group: public Element
219  {
220  public:
221  Group();
222  Group(const std::string& name);
223  Group(const char * name);
224  Group(const Group& src);
225  virtual ~Group();
226  Group& operator=(const Group& src);
227 
228  Dataset* new_dset(const std::string& name);
229  Dataset* new_dset(const char * name);
230  Group* new_group(const std::string& name);
231  Group* new_group(const char * name);
233  HardLink* new_hardlink(const char * name);
234  int find_dset_ndattr(const std::string& ndattr_name, Dataset** dset);
235  int find_dset_ndattr(const char * ndattr_name, Dataset** dset);
236  int find_dset( std::string& dsetname, Dataset** dest);
237  int find_dset( const char* dsetname, Dataset** dest);
241  int num_groups();
242  int num_datasets();
243 
245  inline friend std::ostream& operator<<(std::ostream& out, Group& grp)
246  { out << grp._str_(); return out; }
247  std::string _str_();
249  typedef std::map<std::string, Group*> MapGroups_t;
250  typedef std::map<std::string, Dataset*> MapDatasets_t;
251  typedef std::map<std::string, HardLink*> MapHardLinks_t;
255  void find_dsets(DataSrc_t source, MapDatasets_t& dsets);
257  typedef std::map<std::string, DataSource*> MapNDAttrSrc_t;
258  virtual void merge_ndattributes(MapNDAttrSrc_t::const_iterator it_begin,
259  MapNDAttrSrc_t::const_iterator it_end,
260  std::set<std::string>& used_ndattribute_srcs);
261 
262  private:
263  void _copy(const Group& src);
264  bool name_exist(const std::string& name);
265  bool ndattr_default_container;
266  std::map<std::string, Dataset*> datasets;
267  std::map<std::string, Group*> groups;
268  std::map<std::string, HardLink*> hardlinks;
269  };
270 
273  class Root: public Group
274  {
275  public:
276  Root();
277  Root(const std::string& name);
278  Root(const char *name);
279  virtual ~Root(){};
280  virtual void merge_ndattributes(MapNDAttrSrc_t::const_iterator it_begin,
281  MapNDAttrSrc_t::const_iterator it_end,
282  std::set<std::string>& used_ndattribute_srcs);
283  std::string get_full_name(){ return ""; };
284  std::string get_path(bool trailing_slash=false){ return ""; };
285  };
286 
287 } // hdf5
288 
289 
290 #endif /* LAYOUT_H_ */
int num_groups()
Definition: NDFileHDF5Layout.cpp:525
Class used for writing an Attribute with the NDFileHDF5 plugin.
Definition: NDFileHDF5Layout.h:85
Element * get_parent()
Definition: NDFileHDF5Layout.cpp:241
Definition: NDFileHDF5Layout.h:36
Definition: NDFileHDF5Layout.h:27
virtual ~Dataset()
Definition: NDFileHDF5Layout.cpp:693
friend std::ostream & operator<<(std::ostream &out, Dataset &dset)
Stream operator: use to prints a string representation of this class.
Definition: NDFileHDF5Layout.h:156
MapGroups_t & get_groups()
Definition: NDFileHDF5Layout.cpp:554
int add_attribute(Attribute &attr)
Definition: NDFileHDF5Layout.cpp:251
MapDatasets_t & get_datasets()
Definition: NDFileHDF5Layout.cpp:549
size_t data_store_size()
Definition: NDFileHDF5Layout.cpp:791
Dataset * new_dset(const std::string &name)
Definition: NDFileHDF5Layout.cpp:329
Root()
Definition: NDFileHDF5Layout.cpp:627
void data_stored()
Definition: NDFileHDF5Layout.cpp:796
Definition: NDFileHDF5Layout.h:22
Definition: NDFileHDF5Layout.h:41
const std::string & get_name()
Definition: NDFileHDF5Layout.cpp:236
bool is_src_constant()
Definition: NDFileHDF5Layout.cpp:111
size_t data_append_value(void *val)
Definition: NDFileHDF5Layout.cpp:765
Definition: NDFileHDF5Layout.h:38
void setOnFileOpen(bool onOpen)
Definition: NDFileHDF5Layout.cpp:49
std::string get_path(bool trailing_slash=false)
Definition: NDFileHDF5Layout.h:284
DataSource()
Definition: NDFileHDF5Layout.cpp:73
void set_ndattr_name(const std::string &name)
Definition: NDFileHDF5Layout.cpp:831
Attribute()
Definition: NDFileHDF5Layout.h:88
DataSource & operator=(const DataSource &src)
Assignment operator Copies the sources private data members to this object.
Definition: NDFileHDF5Layout.cpp:97
Definition: NDFileHDF5Layout.h:40
size_t datatype_size()
Definition: NDFileHDF5Layout.cpp:141
std::string get_src_def()
Definition: NDFileHDF5Layout.cpp:131
Definition: NDFileHDF5Layout.h:37
bool has_ndattr_name(const std::string &name)
Definition: NDFileHDF5Layout.cpp:836
virtual std::string get_path(bool trailing_slash=false)
Definition: NDFileHDF5Layout.cpp:214
bool has_attribute(const std::string &attr_name)
Definition: NDFileHDF5Layout.cpp:261
MapHardLinks_t & get_hardlinks()
Definition: NDFileHDF5Layout.cpp:559
int num_datasets()
Definition: NDFileHDF5Layout.cpp:520
Definition: NDFileHDF5Layout.h:34
bool is_src_default()
Definition: NDFileHDF5Layout.cpp:826
DataSource & data_source()
Definition: NDFileHDF5Layout.cpp:751
MapAttributes_t attributes
Definition: NDFileHDF5Layout.h:133
virtual ~Root()
Definition: NDFileHDF5Layout.h:279
DataType_t
Definition: NDFileHDF5Layout.h:33
Definition: NDFileHDF5Layout.h:39
~Attribute()
Definition: NDFileHDF5Layout.h:93
void set_default_ndattr_group()
Definition: NDFileHDF5Layout.cpp:497
When_t
Definition: NDFileHDF5Layout.h:20
Class used for writing a DataSet with the NDFileHDF5 plugin.
Definition: NDFileHDF5Layout.h:146
Definition: NDFileHDF5Layout.h:30
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:257
Attribute & operator=(const Attribute &src)
Definition: NDFileHDF5Layout.cpp:38
bool is_src_detector()
Definition: NDFileHDF5Layout.cpp:116
Definition: NDFileHDF5Layout.h:23
std::map< std::string, Attribute > MapAttributes_t
Definition: NDFileHDF5Layout.h:128
int find_dset(std::string &dsetname, Dataset **dest)
Definition: NDFileHDF5Layout.cpp:477
int tree_level()
Definition: NDFileHDF5Layout.cpp:266
Definition: NDFileHDF5Layout.cpp:16
Element & operator=(const Element &src)
Definition: NDFileHDF5Layout.cpp:226
Class used for writing the root of the file with the NDFileHDF5 plugin.
Definition: NDFileHDF5Layout.h:273
size_t data_num_elements()
Definition: NDFileHDF5Layout.cpp:786
void set_datatype(DataType_t type)
Definition: NDFileHDF5Layout.cpp:106
void find_dsets(DataSrc_t source, MapDatasets_t &dsets)
Definition: NDFileHDF5Layout.cpp:564
bool is_onFileOpen()
Definition: NDFileHDF5Layout.cpp:54
Group * find_ndattr_default_group()
Definition: NDFileHDF5Layout.cpp:502
friend std::ostream & operator<<(std::ostream &out, Group &grp)
Stream operator: use to prints a string representation of this class.
Definition: NDFileHDF5Layout.h:245
int find_dset_ndattr(const std::string &ndattr_name, Dataset **dset)
Definition: NDFileHDF5Layout.cpp:430
Definition: NDFileHDF5Layout.h:29
Element()
Definition: NDFileHDF5Layout.cpp:190
Definition: NDFileHDF5Layout.h:28
Group & operator=(const Group &src)
Definition: NDFileHDF5Layout.cpp:319
std::string _str_()
Definition: NDFileHDF5Layout.cpp:711
DataType_t get_datatype()
return the string that define the source: either name of NDAttribute or constant value
Definition: NDFileHDF5Layout.cpp:136
virtual std::string get_full_name()
Definition: NDFileHDF5Layout.cpp:207
~Element()
Definition: NDFileHDF5Layout.h:118
Dataset & operator=(const Dataset &src)
Definition: NDFileHDF5Layout.cpp:701
void data_alloc_max_elements(size_t max_elements)
Definition: NDFileHDF5Layout.cpp:756
const void * data()
Definition: NDFileHDF5Layout.cpp:804
std::string _str_()
Definition: NDFileHDF5Layout.cpp:530
Describe a group element.
Definition: NDFileHDF5Layout.h:218
Definition: NDFileHDF5Layout.h:35
std::map< std::string, HardLink * > MapHardLinks_t
Definition: NDFileHDF5Layout.h:251
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
virtual ~Group()
Definition: NDFileHDF5Layout.cpp:310
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
bool is_onFileClose()
Definition: NDFileHDF5Layout.cpp:60
std::string get_name()
Definition: NDFileHDF5Layout.cpp:44
int find_detector_default_dset(Dataset **dset)
<< search through subgroups to return a pointer to the NDAttribute default container group
Definition: NDFileHDF5Layout.cpp:451
bool is_src_ndattribute()
Definition: NDFileHDF5Layout.cpp:121
~DataSource()
Definition: NDFileHDF5Layout.h:60
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
std::string name
Definition: NDFileHDF5Layout.h:134
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
Definition: NDFileHDF5Layout.h:42
Describe a generic structure element with the NDFileHDF5 plugin.
Definition: NDFileHDF5Layout.h:112
When_t get_when_to_save()
Definition: NDFileHDF5Layout.cpp:184
std::string get_full_name()
Definition: NDFileHDF5Layout.h:283
DataSource source
Definition: NDFileHDF5Layout.h:100
std::map< std::string, Dataset * > MapDatasets_t
Definition: NDFileHDF5Layout.h:250
void set_data_source(DataSource &src)
Return a string representation of the object.
Definition: NDFileHDF5Layout.cpp:739
void set_src_default(bool def)
Definition: NDFileHDF5Layout.cpp:821
Definition: NDFileHDF5Layout.h:21
void set_when_to_save(When_t when)
Definition: NDFileHDF5Layout.cpp:179
void _copy(const Element &src)
Definition: NDFileHDF5Layout.cpp:278
std::map< std::string, Group * > MapGroups_t
Return a string representation of the object.
Definition: NDFileHDF5Layout.h:249
MapAttributes_t & get_attributes()
Definition: NDFileHDF5Layout.cpp:246
Class used for writing a DataSource with the NDFileHDF5 plugin.
Definition: NDFileHDF5Layout.h:47
Group()
Definition: NDFileHDF5Layout.cpp:287
bool is_src(DataSrc_t src)
Definition: NDFileHDF5Layout.cpp:126
void set_const_datatype_value(DataType_t dtype, const std::string &str_val)
Definition: NDFileHDF5Layout.cpp:172
Dataset()
Definition: NDFileHDF5Layout.cpp:679
DataSrc_t
Definition: NDFileHDF5Layout.h:26