5 #include "../icedb/fs.hpp" 6 #include "../icedb/compat/gsl/gsl_assert" 7 #include "../icedb/fs_backend.hpp" 8 #include "../private/hdf5_supplemental.hpp" 9 #include "../icedb/Database.hpp" 10 #include "../private/Database_impl.hpp" 11 #include "../private/hdf5_load.h" 18 size_t desiredSizeInBytes)
19 :
buffer(desiredSizeInBytes), filename(filename),
24 Expects(h5Result >= 0 &&
"H5Pset_fapl_core failed");
27 hFile = std::make_shared<H5::H5File>(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,
propertyList);
35 auto res = std::make_shared<H5::H5File>(p,
38 constexpr uint64_t dbverno = 1;
39 auto basegrp = res->openGroup(
".");
40 icedb::fs::hdf5::addAttr<uint64_t, H5::Group>(&
basegrp,
"Version", dbverno);
41 icedb::fs::hdf5::addAttr<std::string, H5::Group>(&
basegrp,
"Software",
"libicedb");
69 const std::string &location)
73 sfs::path pBase(location);
74 sfs::create_directories(pBase);
75 Expects(sfs::exists(pBase));
77 sfs::create_directory(pBase /
"3d_Structures");
78 sfs::create_directory(pBase /
"Physical_Particle_Properties");
79 sfs::create_directory(pBase /
"Extended_Scattering_Variables");
80 sfs::create_directory(pBase /
"Essential_Scattering_Variables");
81 sfs::create_directory(pBase /
"Testing");
96 const std::string &location) {
109 auto res = std::make_unique<Database_impl>();
112 res->hFile = res->hFileImage.getHFile();
114 return std::move(res);
122 if (!sfs::exists(pBaseS)) {
125 }
else throw(std::invalid_argument(
"Attempting to open a database root that does not exist. Did you mean to first create this database?"));
129 auto res = std::make_unique<Database_impl>();
133 Expects(mountFiles.size() > 0);
134 if (mountFiles.size() == 1) {
135 res->hFile = std::make_shared<H5::H5File>(
136 mountFiles.begin()->first.string().c_str(), Hflags, H5P_DEFAULT);
139 res->hFile = res->hFileImage.getHFile();
143 for (
const auto &toMount : mountFiles) {
144 std::string mountStr = toMount.second;
145 if (mountStr ==
"index.hdf5")
continue;
148 std::shared_ptr<H5::H5File> newHfile = std::make_shared<H5::H5File>(toMount.first.string(), Hflags);
153 H5::PropList pl(H5P_DEFAULT);
154 res->hFile->mount(toMount.second, *(newHfile.get()), pl);
158 return std::move(res);
165 Expects(mountFiles.size() > 0);
166 if (mountFiles.size() == 1)
return;
168 std::unique_ptr<Database_impl> res = std::make_unique<Database_impl>();
173 for (
const auto &toMount : mountFiles) {
174 std::string mountStr = toMount.second;
175 if (mountStr ==
"index.hdf5")
continue;
177 std::string linkName = *(explodedPath.rbegin());
178 explodedPath.pop_back();
183 if (explodedPath.size()) {
185 H5Lcreate_external(toMount.second.c_str(),
"/", grp.getLocId(), linkName.c_str(), H5P_DEFAULT, H5P_DEFAULT);
187 H5Lcreate_external(toMount.second.c_str(),
"/", res->hFile->getLocId(), linkName.c_str(), H5P_DEFAULT, H5P_DEFAULT);
196 std::shared_ptr<H5::Group> ngrp = std::make_shared<H5::Group>(grp);
202 std::shared_ptr<H5::Group> ngrp = std::make_shared<H5::Group>(grp);
static void indexDatabase(const std::string &location)
H5::Group createGroupStructure(const std::string &groupName, ICEDB_H5_GROUP_OWNER &base)
const std::string filename
Groups::Group::Group_ptr openGroup(const std::string &path) override
file_image hFileImage
Used if a virtual base is needed (the typical case)
file_image(const std::string &filename, size_t desiredSizeInBytes)
sfs::path resolveSymLinks(const sfs::path &base)
Finds out where a symbolic link points to.
virtual Group_ptr createGroup(const std::string &groupName)=0
Create a group.
std::shared_ptr< H5::H5File > getHFile() const
static Database_ptr createSampleDatabase(const std::string &location)
sfs::path resolveSymlinkPathandForceExists(const std::string &location)
Like resolveSymLinks, but throw if the resulting path does not exist.
std::unique_ptr< Database > Database_ptr
icedb::Groups::Group::Group_ptr basegrp
Shapes get written to this location in the output database.
static Database_ptr createSingleFileDatabase(const std::string &location)
virtual Group_ptr openGroup(const std::string &groupName) const =0
Opens a group.
std::vector< std::string > explodeHDF5groupPath(const std::string &s)
std::shared_ptr< H5::H5File > hFile
std::unique_ptr< Groups::Group > Group_ptr
std::shared_ptr< H5::H5File > hFile
std::vector< std::pair< sfs::path, std::string > > CollectedFilesRet_Type
File path, relative mount point.
static Database_ptr openVirtualDatabase(size_t memSizeInBytes)
unsigned int getHDF5IOflags(fs::IOopenFlags flags)
static Database_ptr openDatabase(const std::string &location, fs::IOopenFlags flags=fs::IOopenFlags::READ_ONLY)
static std::shared_ptr< H5::H5File > makeDatabaseFileStandard(const std::string &p)
Groups::Group::Group_ptr createGroupStructure(const std::string &groupName) override
std::vector< char > buffer
CollectedFilesRet_Type collectActualHDF5files(const sfs::path &pBaseS)
Like collectDatasetFiles for HDF5 files, but then check that these files are, indeed, HDF5 files.
Groups::Group::Group_ptr createGroup(const std::string &path) override
std::string getUniqueVROOTname()
Generate a unique string, used in memort-only HDF5 file trees.