FileHDF5::FileHDF5(const string &name, FileMode mode, Compression compression, OpenFlags flags) { if (!fileExists(name)) { mode = FileMode::Overwrite; } this->mode = mode; this->compr = compression; //we want hdf5 to keep track of the order in which links were created so that //the order for indexed based accessors is stable cf. issue #387 H5Object fcpl = H5Pcreate(H5P_FILE_CREATE); fcpl.check("Could not create file creation plist"); HErr res = H5Pset_link_creation_order(fcpl.h5id(), H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED); res.check("Unable to create file (H5Pset_link_creation_order failed.)"); unsigned int h5mode = map_file_mode(mode); bool is_create = !fileExists(name) || h5mode == H5F_ACC_TRUNC; if (is_create) { hid = H5Fcreate(name.c_str(), h5mode, fcpl.h5id(), H5P_DEFAULT); } else { hid = H5Fopen(name.c_str(), h5mode, H5P_DEFAULT); } if (!H5Iis_valid(hid)) { throw H5Exception("Could not open/create file"); } openRoot(); if (is_create) { createHeader(); } else if (!checkHeader(mode) && (flags & OpenFlags::Force) != OpenFlags::Force) { throw nix::InvalidFile("FileHDF5::open_existing!"); } metadata = root.openGroup("metadata"); data = root.openGroup("data"); setCreatedAt(); setUpdatedAt(); }
void LocID::deleteLink(std::string name, hid_t plist) { HErr res = H5Ldelete(hid, name.c_str(), plist); res.check("LocIDL::deleteLink: Could not delete link: " + name); }
void LocID::removeAttr(const std::string &name) const { HErr res = H5Adelete(hid, name.c_str()); res.check("LocID::removeAttr(): could not delete attribute"); }
void DataType::sign(H5T_sign_t sign) { HErr res = H5Tset_sign(hid, sign); res.check("DataType::sign(): H5Tset_sign failed"); }
void DataType::size(size_t t) { HErr res = H5Tset_size(hid, t); res.check("DataType::size: Could not set size"); }
void DataType::insert(const std::string &name, size_t offset, const DataType &dtype) { HErr res = H5Tinsert(hid, name.c_str(), offset, dtype.hid); res.check("DataType::insert(): H5Tinsert failed."); }
unsigned int LocID::referenceCount() const { H5O_info_t oInfo; HErr res = H5Oget_info(hid, &oInfo); res.check("LocID:referenceCount: Coud not get object info"); return oInfo.rc; }
bool FileHDF5::flush() { HErr err = H5Fflush(hid, H5F_SCOPE_GLOBAL); return !err.isError(); }