icedb  version 0.5.1
Snow particle scattering database API
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
icedb::Databases::Database Class Referenceabstract

#include <Database.hpp>

Inheritance diagram for icedb::Databases::Database:
Inheritance graph
[legend]

Public Types

typedef std::unique_ptr< DatabaseDatabase_ptr
 

Public Member Functions

virtual ~Database ()
 
virtual Groups::Group::Group_ptr openGroup (const std::string &path)=0
 
virtual Groups::Group::Group_ptr createGroup (const std::string &path)=0
 
virtual Groups::Group::Group_ptr createGroupStructure (const std::string &groupName)=0
 
virtual Groups::Group::Group_ptr createGroupStructure (const std::vector< std::string > &groupNames)=0
 

Static Public Member Functions

static Database_ptr createSampleDatabase (const std::string &location)
 
static Database_ptr createSingleFileDatabase (const std::string &location)
 
static Database_ptr openDatabase (const std::string &location, fs::IOopenFlags flags=fs::IOopenFlags::READ_ONLY)
 
static Database_ptr openVirtualDatabase (size_t memSizeInBytes)
 
static void indexDatabase (const std::string &location)
 

Protected Member Functions

 Database ()
 

Detailed Description

Definition at line 16 of file Database.hpp.

Member Typedef Documentation

◆ Database_ptr

Definition at line 20 of file Database.hpp.

Constructor & Destructor Documentation

◆ Database()

icedb::Databases::Database::Database ( )
protected

Definition at line 66 of file databases.cpp.

66 {}

◆ ~Database()

icedb::Databases::Database::~Database ( )
virtual

Definition at line 64 of file databases.cpp.

64 {}

Member Function Documentation

◆ createGroup()

virtual Groups::Group::Group_ptr icedb::Databases::Database::createGroup ( const std::string &  path)
pure virtual

◆ createGroupStructure() [1/2]

virtual Groups::Group::Group_ptr icedb::Databases::Database::createGroupStructure ( const std::string &  groupName)
pure virtual

◆ createGroupStructure() [2/2]

virtual Groups::Group::Group_ptr icedb::Databases::Database::createGroupStructure ( const std::vector< std::string > &  groupNames)
pure virtual

◆ createSampleDatabase()

Database::Database_ptr icedb::Databases::Database::createSampleDatabase ( const std::string &  location)
static

Definition at line 68 of file databases.cpp.

References icedb::fs::hdf5::getHDF5IOflags(), icedb::Databases::Database_impl::makeDatabaseFileStandard(), openDatabase(), icedb::fs::READ_WRITE, and icedb::fs::TRUNCATE.

Referenced by main().

70  {
71  const auto flag_truncate = fs::hdf5::getHDF5IOflags(fs::IOopenFlags::TRUNCATE);
72 
73  sfs::path pBase(location);
74  sfs::create_directories(pBase);
75  Expects(sfs::exists(pBase));
76 
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");
82 
83  Database_impl::makeDatabaseFileStandard((pBase / "3d_Structures" / "3dS-1.hdf5").string());
84  Database_impl::makeDatabaseFileStandard((pBase / "3d_Structures" / "3dS-2.hdf5").string());
85  Database_impl::makeDatabaseFileStandard((pBase / "3d_Structures" / "3dS-3.hdf5").string());
86  Database_impl::makeDatabaseFileStandard((pBase / "Physical_Particle_Properties" / "ppp.hdf5").string());
87  Database_impl::makeDatabaseFileStandard((pBase / "Essential_Scattering_Variables" / "esv1.hdf5").string());
88  Database_impl::makeDatabaseFileStandard((pBase / "Essential_Scattering_Variables" / "esv2.hdf5").string());
89  Database_impl::makeDatabaseFileStandard((pBase / "Testing" / "scratch.hdf5").string());
90  Database_impl::makeDatabaseFileStandard((pBase / "metadata.hdf5").string());
91 
93  }
unsigned int getHDF5IOflags(fs::IOopenFlags flags)
static Database_ptr openDatabase(const std::string &location, fs::IOopenFlags flags=fs::IOopenFlags::READ_ONLY)
Definition: databases.cpp:118
static std::shared_ptr< H5::H5File > makeDatabaseFileStandard(const std::string &p)
Definition: databases.cpp:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createSingleFileDatabase()

Database::Database_ptr icedb::Databases::Database::createSingleFileDatabase ( const std::string &  location)
static

Definition at line 95 of file databases.cpp.

References icedb::fs::hdf5::getHDF5IOflags(), icedb::Databases::Database_impl::makeDatabaseFileStandard(), openDatabase(), icedb::fs::READ_WRITE, and icedb::fs::TRUNCATE.

Referenced by openDatabase().

96  {
97  const auto flag_truncate = fs::hdf5::getHDF5IOflags(fs::IOopenFlags::TRUNCATE);
98 
99  //sfs::path pBase(location);
100  //sfs::create_directories(pBase);
101  //Expects(sfs::exists(pBase));
103 
105  }
unsigned int getHDF5IOflags(fs::IOopenFlags flags)
static Database_ptr openDatabase(const std::string &location, fs::IOopenFlags flags=fs::IOopenFlags::READ_ONLY)
Definition: databases.cpp:118
static std::shared_ptr< H5::H5File > makeDatabaseFileStandard(const std::string &p)
Definition: databases.cpp:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ indexDatabase()

void icedb::Databases::Database::indexDatabase ( const std::string &  location)
static
Todo:
createGroupStructure cannot currently handle passing back an H5File (in the no groups case). It is a bug in HDF5. Once fixed, the if-else cases should be collapsed into one.

Definition at line 161 of file databases.cpp.

References icedb::fs::impl::collectActualHDF5files(), icedb::fs::hdf5::createGroupStructure(), icedb::fs::hdf5::explodeHDF5groupPath(), icedb::Databases::Database_impl::makeDatabaseFileStandard(), and icedb::fs::impl::resolveSymlinkPathandForceExists().

Referenced by main().

162  {
163  sfs::path pBaseS = fs::impl::resolveSymlinkPathandForceExists(location);
165  Expects(mountFiles.size() > 0);
166  if (mountFiles.size() == 1) return;
167 
168  std::unique_ptr<Database_impl> res = std::make_unique<Database_impl>();
169  res->hFile = Database_impl::makeDatabaseFileStandard(location + "/index.hdf5");
170 
171  // Check for the existence of the appropriate groups in the relative path tree
172  // Create any missing groups in the relative path tree, and then make the link.
173  for (const auto &toMount : mountFiles) {
174  std::string mountStr = toMount.second;
175  if (mountStr == "index.hdf5") continue;
176  auto explodedPath = fs::hdf5::explodeHDF5groupPath(mountStr);
177  std::string linkName = *(explodedPath.rbegin());
178  explodedPath.pop_back();
179 
183  if (explodedPath.size()) {
184  auto grp = fs::hdf5::createGroupStructure(explodedPath, *(res->hFile.get()));
185  H5Lcreate_external(toMount.second.c_str(), "/", grp.getLocId(), linkName.c_str(), H5P_DEFAULT, H5P_DEFAULT);
186  } else {
187  H5Lcreate_external(toMount.second.c_str(), "/", res->hFile->getLocId(), linkName.c_str(), H5P_DEFAULT, H5P_DEFAULT);
188  }
189  }
190 
191  }
H5::Group createGroupStructure(const std::string &groupName, ICEDB_H5_GROUP_OWNER &base)
sfs::path resolveSymlinkPathandForceExists(const std::string &location)
Like resolveSymLinks, but throw if the resulting path does not exist.
Definition: fs_backend.cpp:73
std::vector< std::string > explodeHDF5groupPath(const std::string &s)
std::vector< std::pair< sfs::path, std::string > > CollectedFilesRet_Type
File path, relative mount point.
Definition: fs_backend.hpp:45
static std::shared_ptr< H5::H5File > makeDatabaseFileStandard(const std::string &p)
Definition: databases.cpp:34
CollectedFilesRet_Type collectActualHDF5files(const sfs::path &pBaseS)
Like collectDatasetFiles for HDF5 files, but then check that these files are, indeed, HDF5 files.
Definition: fs_backend.cpp:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ openDatabase()

Database::Database_ptr icedb::Databases::Database::openDatabase ( const std::string &  location,
fs::IOopenFlags  flags = fs::IOopenFlags::READ_ONLY 
)
static
Note
HDF5 C++ bug in constness on 1.8.5, CentOS 6. I cannot directly pass H5P_DEFAULT to the trivial constructor for H5::PropList as an rvalue

Definition at line 118 of file databases.cpp.

References icedb::fs::impl::collectActualHDF5files(), icedb::fs::CREATE, icedb::fs::hdf5::createGroupStructure(), createSingleFileDatabase(), icedb::fs::hdf5::getHDF5IOflags(), icedb::fs::impl::resolveSymLinks(), and icedb::fs::TRUNCATE.

Referenced by createSampleDatabase(), createSingleFileDatabase(), and main().

120  {
121  sfs::path pBaseS = fs::impl::resolveSymLinks(location);
122  if (!sfs::exists(pBaseS)) {
123  if (flags == fs::IOopenFlags::TRUNCATE || flags == fs::IOopenFlags::CREATE) {
124  return createSingleFileDatabase(location);
125  } else throw(std::invalid_argument("Attempting to open a database root that does not exist. Did you mean to first create this database?"));
126  }
128  unsigned int Hflags = fs::hdf5::getHDF5IOflags(flags);
129  auto res = std::make_unique<Database_impl>();
130  //std::unique_ptr<Database_impl, mem::icedb_delete<Database_impl> > res(new Database_impl);
131  //= std::make_unique(<Database_impl, mem::icedb_delete<Database_impl> >();
132 
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);
137  }
138  else {
139  res->hFile = res->hFileImage.getHFile();
140 
141  // Check for the existence of the appropriate groups in the relative path tree
142  // Create any missing groups in the relative path tree
143  for (const auto &toMount : mountFiles) {
144  std::string mountStr = toMount.second;
145  if (mountStr == "index.hdf5") continue;
146  H5::Group grp = icedb::fs::hdf5::createGroupStructure(mountStr, *(res->hFile.get()));
147  // Open files and mount in the relative path tree
148  std::shared_ptr<H5::H5File> newHfile = std::make_shared<H5::H5File>(toMount.first.string(), Hflags);
149  //res._impl->mappedFiles[toMount.second] = newHfile;
150 
153  H5::PropList pl(H5P_DEFAULT);
154  res->hFile->mount(toMount.second, *(newHfile.get()), pl);
155  }
156  }
157 
158  return std::move(res);
159  }
H5::Group createGroupStructure(const std::string &groupName, ICEDB_H5_GROUP_OWNER &base)
sfs::path resolveSymLinks(const sfs::path &base)
Finds out where a symbolic link points to.
Definition: fs_backend.cpp:16
static Database_ptr createSingleFileDatabase(const std::string &location)
Definition: databases.cpp:95
std::vector< std::pair< sfs::path, std::string > > CollectedFilesRet_Type
File path, relative mount point.
Definition: fs_backend.hpp:45
unsigned int getHDF5IOflags(fs::IOopenFlags flags)
CollectedFilesRet_Type collectActualHDF5files(const sfs::path &pBaseS)
Like collectDatasetFiles for HDF5 files, but then check that these files are, indeed, HDF5 files.
Definition: fs_backend.cpp:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ openGroup()

virtual Groups::Group::Group_ptr icedb::Databases::Database::openGroup ( const std::string &  path)
pure virtual

◆ openVirtualDatabase()

Database::Database_ptr icedb::Databases::Database::openVirtualDatabase ( size_t  memSizeInBytes)
static

Definition at line 107 of file databases.cpp.

108  {
109  auto res = std::make_unique<Database_impl>();
110  //std::unique_ptr<Database_impl, mem::icedb_delete<Database_impl> > res(new Database_impl);
111  //= std::make_unique(<Database_impl, mem::icedb_delete<Database_impl> >();
112  res->hFile = res->hFileImage.getHFile();
113 
114  return std::move(res);
115  }

The documentation for this class was generated from the following files: