NeXus  4.4.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
NeXusFile.hpp
Go to the documentation of this file.
1 #ifndef NEXUSFILE_HPP
2 #define NEXUSFILE_HPP 1
3 
4 #include <map>
5 #include <string>
6 #include <utility>
7 #include <vector>
8 #include "napi.h"
9 #include "NeXusExport.hpp"
10 
18 namespace NeXus {
33  enum NXnumtype {
34  FLOAT32 = NX_FLOAT32,
35  FLOAT64 = NX_FLOAT64,
36  INT8 = NX_INT8,
37  UINT8 = NX_UINT8,
38  // BOOLEAN = NX_BOOLEAN, // NX_BOOLEAN is currently broken
39  INT16 = NX_INT16,
40  UINT16 = NX_UINT16,
41  INT32 = NX_INT32,
42  UINT32 = NX_UINT32,
43  INT64 = NX_INT64,
44  UINT64 = NX_UINT64,
45  CHAR = NX_CHAR,
46  BINARY = NX_BINARY
47  };
48 
58  CHUNK = NX_CHUNK,
59  NONE = NX_COMP_NONE,
60  LZW = NX_COMP_LZW,
61  RLE = NX_COMP_RLE,
62  HUF = NX_COMP_HUF
63  };
64 
68  typedef std::multimap<std::string, std::string> TypeMap;
69 
73  struct Info{
77  std::vector<int64_t> dims;
78  };
79 
81  struct AttrInfo{
85  unsigned length;
87  std::string name;
89  std::vector<int> dims;
90  };
91 
96  class NXDLL_EXPORT File
97  {
98  private:
100  NXhandle m_file_id;
102  bool m_close_handle;
103 
104  public:
108  std::pair<std::string, std::string> getNextEntry();
112  AttrInfo getNextAttr();
113 
114  private:
119  void compress(NXcompression comp) NEXUS_DEPRECATED_FUNCTION();
120 
124  void initGroupDir();
125 
129  void initAttrDir();
130 
138  void walkFileForTypeMap(const std::string path, const std::string class_name, TypeMap &tmap);
139 
146  const std::string makeCurrentPath(const std::string currpath, const std::string subpath);
147 
153  void initOpenFile(const std::string& filename, const NXaccess access = NXACC_READ);
154 
155  public:
162  File(const std::string& filename, const NXaccess access = NXACC_READ);
163 
170  File(const char *filename, const NXaccess access = NXACC_READ);
171 
178  File(NXhandle handle, bool close_handle = false);
179 
181  ~File();
182 
184  void close();
185 
187  void flush();
188 
189  template<typename NumT>
190  void malloc(NumT*& data, const Info& info);
191 
192  template<typename NumT>
193  void free(NumT*& data);
194 
203  void makeGroup(const std::string& name, const std::string& class_name,
204  bool open_group = false);
205 
212  void openGroup(const std::string& name, const std::string& class_name);
213 
221  void openPath(const std::string& path);
222 
230  void openGroupPath(const std::string& path);
236  std::string getPath();
237 
241  void closeGroup();
242 
247  void makeData(const std::string& name, NXnumtype type,
248  const std::vector<int>& dims, bool open_data = false);
249 
258  void makeData(const std::string& name, NXnumtype type,
259  const std::vector<int64_t>& dims, bool open_data = false);
260 
269  template <typename NumT>
270  void makeData(const std::string& name, const NXnumtype type,
271  const NumT length, bool open_data = false);
272 
279  void writeData(const std::string& name, const std::string& value);
280 
287  void writeData(const std::string& name, const char* value);
288 
296  template <typename NumT>
297  void writeData(const std::string& name, const std::vector<NumT>& value);
298 
306  template <typename NumT>
307  void writeData(const std::string& name, const NumT& value);
308 
317  template <typename NumT>
318  void writeData(const std::string& name, const std::vector<NumT>& value,
319  const std::vector<int>& dims);
320 
329  template <typename NumT>
330  void writeData(const std::string& name, const std::vector<NumT>& value,
331  const std::vector<int64_t>& dims);
332 
339  template <typename NumT>
340  void writeExtendibleData(const std::string& name, std::vector<NumT>& value);
341 
349  template <typename NumT>
350  void writeExtendibleData(const std::string& name, std::vector<NumT>& value, const int64_t chunk);
351 
360  template <typename NumT>
361  void writeExtendibleData(const std::string& name, std::vector<NumT>& value,
362  std::vector<int64_t>& dims, std::vector<int64_t> & chunk);
363 
364 
372  template <typename NumT>
373  void writeUpdatedData(const std::string& name, std::vector<NumT>& value);
374 
383  template <typename NumT>
384  void writeUpdatedData(const std::string& name, std::vector<NumT>& value,
385  std::vector<int64_t>& dims);
386 
392  void makeCompData(const std::string& name, const NXnumtype type,
393  const std::vector<int>& dims, const NXcompression comp,
394  const std::vector<int>& bufsize, bool open_data = false);
395 
406  void makeCompData(const std::string& name, const NXnumtype type,
407  const std::vector<int64_t>& dims, const NXcompression comp,
408  const std::vector<int64_t>& bufsize, bool open_data = false);
409 
416  template <typename NumT>
417  void writeCompData(const std::string & name,
418  const std::vector<NumT> & value,
419  const std::vector<int> & dims, const NXcompression comp,
420  const std::vector<int> & bufsize);
421 
432  template <typename NumT>
433  void writeCompData(const std::string & name,
434  const std::vector<NumT> & value,
435  const std::vector<int64_t> & dims, const NXcompression comp,
436  const std::vector<int64_t> & bufsize);
437 
441  void openData(const std::string& name);
442 
446  void closeData();
447 
451  void putData(const void* data);
452 
457  template <typename NumT>
458  void putData(const std::vector<NumT>& data);
459 
466  void putAttr(const AttrInfo& info, const void* data);
467 
474  void putAttr(const std::string& name, const std::vector<std::string>& array);
475 
482  template <typename NumT>
483  void putAttr(const std::string& name, const std::vector<NumT>& array);
484 
492  template <typename NumT>
493  void putAttr(const std::string& name, const NumT value);
494 
501  void putAttr(const char* name, const char* value);
502 
509  void putAttr(const std::string& name, const std::string value);
510 
515  void putSlab(const void* data, const std::vector<int>& start,
516  const std::vector<int>& size);
517 
525  void putSlab(const void* data, const std::vector<int64_t>& start,
526  const std::vector<int64_t>& size);
527 
532  template <typename NumT>
533  void putSlab(const std::vector<NumT>& data, const std::vector<int>& start,
534  const std::vector<int>& size);
535 
544  template <typename NumT>
545  void putSlab(const std::vector<NumT>& data, const std::vector<int64_t>& start,
546  const std::vector<int64_t>& size);
547 
551  template <typename NumT>
552  void putSlab(const std::vector<NumT>& data, int start, int size);
553 
562  template <typename NumT>
563  void putSlab(const std::vector<NumT>& data, int64_t start, int64_t size);
564 
568  NXlink getDataID();
569 
575  void makeLink(NXlink& link);
576 
583  void makeNamedLink(const std::string& name, NXlink& link);
584 
589  void openSourceGroup();
590 
596  void getData(void* data);
597 
606  template <typename NumT>
607  std::vector<NumT> * getData();
608 
617  template <typename NumT>
618  void getData(std::vector<NumT>& data);
619 
626  void getDataCoerce(std::vector<int> &data);
627 
633  void getDataCoerce(std::vector<double> &data);
634 
638  bool isDataInt();
639 
650  template <typename NumT>
651  void readData(const std::string & dataName, std::vector<NumT>& data);
652 
661  template <typename NumT>
662  void readData(const std::string & dataName, NumT & data);
663 
673  void readData(const std::string & dataName, std::string & data);
674 
678  std::string getStrData();
679 
683  Info getInfo();
684 
688  std::map<std::string, std::string> getEntries();
689 
695  void getEntries(std::map<std::string, std::string> & result);
696 
701  void getSlab(void* data, const std::vector<int>& start,
702  const std::vector<int>& size);
703 
712  void getSlab(void* data, const std::vector<int64_t>& start,
713  const std::vector<int64_t>& size);
714 
719  std::vector<AttrInfo> getAttrInfos();
720 
725  bool hasAttr(const std::string & name);
726 
735  void getAttr(const AttrInfo& info, void* data, int length = -1);
736 
745  template <typename NumT>
746  NumT getAttr(const AttrInfo& info);
747 
748 
756  template <typename NumT>
757  void getAttr(const std::string& name, NumT& value);
758 
759 
767  std::string getStrAttr(const AttrInfo & info);
768 
776  void getAttr(const std::string& name, std::vector<std::string>& array);
777 
781  NXlink getGroupID();
782 
791  bool sameID(NXlink& first, NXlink& second);
792 
798  void printLink(NXlink & link);
799 
807  void setNumberFormat(NXnumtype& type, const std::string& format);
808 
816  std::string inquireFile(const int buff_length = NX_MAXPATHLEN);
817 
827  std::string isExternalGroup(const std::string& name,
828  const std::string& type,
829  const unsigned buff_length = NX_MAXNAMELEN);
830 
838  void linkExternal(const std::string& name, const std::string& type,
839  const std::string& url);
844  bool isDataSetOpen();
845 
851  TypeMap *getTypeMap();
852  };
853 
858  template <typename NumT>
859  NXDLL_EXPORT NXnumtype getType(NumT number = NumT());
860 
861 
862 };
863 
864 #include "NeXusStream.hpp"
865 
866 #endif
NXcompression
The available compression types.
Definition: NeXusFile.hpp:57
std::vector< int64_t > dims
The dimensions of the file.
Definition: NeXusFile.hpp:77
NXnumtype
The primitive types published by this API.
Definition: NeXusFile.hpp:33
Header for IOStream like interface to NeXus files.
NXnumtype getType(NumT number)
This function returns the NXnumtype given a concrete number.
Definition: NeXusFile.cpp:51
unsigned length
The length of the attribute.
Definition: NeXusFile.hpp:85
Information about an attribute.
Definition: NeXusFile.hpp:81
This structure holds the type and dimensions of a primative field/array.
Definition: NeXusFile.hpp:73
std::multimap< std::string, std::string > TypeMap
Type definition for a type-keyed multimap.
Definition: NeXusFile.hpp:68
std::string name
The name of the attribute.
Definition: NeXusFile.hpp:87
The Object that allows access to the information in the file.
Definition: NeXusFile.hpp:96
NXnumtype type
The primative type for the field.
Definition: NeXusFile.hpp:75
std::vector< int > dims
The dimensions of the attribute.
Definition: NeXusFile.hpp:89
NXnumtype type
The primative type for the attribute.
Definition: NeXusFile.hpp:83