1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <hdf/HDFNewBasReader.hpp>
int HDFNewBasReader::Initialize(const std::string &hdfBasFileName)
{
//
// Initialize access to the HDF file. For reading bas files, this
// involves:
// - Opening the h5 file, and initializing the rootGroup.
//
try {
H5::Exception::dontPrint();
hdfBasFile.openFile(hdfBasFileName.c_str(), H5F_ACC_RDONLY);
} catch (H5::Exception &e) {
std::cout << "ERROR, could not open bas.h5 file" << hdfBasFileName << ", exiting."
<< std::endl;
return 0;
}
if (rootGroup.Initialize(hdfBasFile, "/") == 0) {
return 0;
}
// If /MultiPart/Parts exists, initialize and return 1;
// otherwise, return 0
if (rootGroup.ContainsObject("MultiPart") and
multiPartGroup.Initialize(rootGroup.group, "MultiPart") != 0) {
if (multiPartGroup.ContainsObject("Parts") and
partsArray.InitializeForReading(multiPartGroup, "Parts") != 0) {
basFileName = hdfBasFileName;
return 1; // Success
}
}
return 0; // Fail
}
std::vector<std::string> HDFNewBasReader::GetBaxMovieNames()
{
// Read bax.h5 names from /MultiPart/Parts, not including path prefix.
// e.g., m...._s1_p0.1.bax.h5
std::vector<std::string> baxNames;
baxNames.resize(BAXPERBAS); // 3 bax files per bas file.
for (int i = 0; i < BAXPERBAS; i++) {
partsArray.Read(i, i + 1, &baxNames[i]);
}
return baxNames;
}
std::vector<std::string> HDFNewBasReader::GetBaxFileNames()
{
// Get full paths to bax.h5 files,
// e.g., /mnt/data3/vol53/2450598/0001/Analysis_Results/m..._s1_p0.1.bax.h5
// Assumption: bax.h5 files are in the same directory as bas.h5.
std::string prefix = "";
size_t slashPos = basFileName.rfind("/");
if (slashPos != std::string::npos) {
prefix = basFileName.substr(0, slashPos + 1);
}
std::vector<std::string> baxNames = GetBaxMovieNames();
for (int i = 0; i < int(baxNames.size()); i++) {
baxNames[i] = prefix + baxNames[i];
}
return baxNames;
}
void HDFNewBasReader::Close()
{
partsArray.Close();
multiPartGroup.Close();
rootGroup.Close();
hdfBasFile.close();
basFileName = "";
}
|