Commit 364a3337 authored by Laurent Claustre's avatar Laurent Claustre

Merge branch '44-hdf5' into 'master'

Resolve "HDF5"

Closes #44

See merge request !64
parents e096a0df 407c0c47
......@@ -371,24 +371,16 @@ if(LIMA_ENABLE_HDF5)
find_library(LIB_HDF5_HL libhdf5_hl ${LIB_HDF5_DIR})
find_library(LIB_ZLIB libzlib ${LIB_HDF5_DIR})
find_library(LIB_SZIP libszip ${LIB_HDF5_DIR})
else()
set(LIB_HDF5_INCLUDE_DIR "/usr/local/hdf5/include" CACHE PATH "Path to HDF5 directories")
set(LIB_HDF5_DIR "/usr/local/hdf5/lib")
find_library(LIB_HDF5_CPP hdf5_cpp ${LIB_HDF5_DIR})
find_library(LIB_HDF5 hdf5 ${LIB_HDF5_DIR})
find_library(LIB_HDF5_HL hdf5_hl ${LIB_HDF5_DIR})
find_path(LIB_HDF5_INCLUDE_DIR H5Cpp.h)
link_directories(${LIB_HDF5_DIR})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HDF5 DEFAULT_MSG LIB_HDF5 LIB_HDF5_INCLUDE_DIR)
if(${HDF5_FOUND})
else()
find_package(HDF5 REQUIRED COMPONENTS C CXX HL )
endif()
if(${HDF5_FOUND})
add_definitions(-DWITH_HDF5_SAVING)
set(ct_srcs ${ct_srcs} control/src/CtSaving_Hdf5.cpp)
set(saving_libs ${saving_libs} ${LIB_HDF5} ${LIB_HDF5_CPP} ${LIB_HDF5_HL} ${LIB_SZIP} ${LIB_ZLIB})
set(saving_includes ${saving_includes} ${LIB_HDF5_INCLUDE_DIR})
set(saving_libs ${saving_libs} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES} ${LIB_SZIP} ${LIB_ZLIB})
set(saving_includes ${saving_includes} ${HDF5_INCLUDE_DIRS})
else()
message(FATAL_ERROR "hdf5_cpp library not found, please install or disable LIMA_ENABLE_HDF5")
message(FATAL_ERROR "HDF5 libraries not found, please install or disable LIMA_ENABLE_HDF5")
endif()
if(LIMA_ENABLE_HDF5_BS)
......
......@@ -23,11 +23,8 @@
############################################################################
if (NOT BITSHUFFLE_EXTERNALLY_CONFIGURED)
cmake_minimum_required(VERSION 2.8)
find_library(LIB_HDF5 hdf5)
find_path(LIB_HDF5_INCLUDE_DIR hdf5.h)
cmake_minimum_required(VERSION 3.1)
find_package(HDF5 REQUIRED)
endif (NOT BITSHUFFLE_EXTERNALLY_CONFIGURED)
set(BS_VERSION_MAJOR "0")
......@@ -51,9 +48,9 @@ add_library(h5bshuf SHARED ${bitshuffle_src})
target_include_directories(h5bshuf PRIVATE "${BITSHUFFLE_DIR}/src")
target_include_directories(h5bshuf PRIVATE "${BITSHUFFLE_DIR}/lz4")
target_include_directories(h5bshuf PRIVATE "${LIB_HDF5_INCLUDE_DIR}")
target_include_directories(h5bshuf PRIVATE "${HDF5_INCLUDE_DIRS}")
target_link_libraries(h5bshuf ${LIB_HDF5})
target_link_libraries(h5bshuf ${HDF5_LIBRARIES})
install(TARGETS h5bshuf LIBRARY DESTINATION lib)
......@@ -46,9 +46,10 @@ struct SaveContainerHdf5::_File
m_image_dataset(NULL),
m_file(NULL),
m_entry(NULL),
m_measurement_detector(NULL),
m_measurement(NULL),
m_instrument_detector(NULL),
m_instrument_detector_meta_data(NULL),
m_instrument_detector_data(NULL),
m_instrument_detector_data_parameters(NULL),
m_entry_index(0)
{}
......@@ -56,9 +57,10 @@ struct SaveContainerHdf5::_File
{
delete m_image_dataspace;
delete m_image_dataset;
delete m_measurement_detector;
delete m_measurement;
delete m_instrument_detector;
delete m_instrument_detector_meta_data;
delete m_instrument_detector_data;
delete m_instrument_detector_data_parameters;
delete m_entry;
delete m_file;
}
......@@ -73,9 +75,10 @@ struct SaveContainerHdf5::_File
m_image_dataset = other.m_image_dataset;
m_file = other.m_file;
m_entry = other.m_entry;
m_measurement_detector = other.m_measurement_detector;
m_measurement = other.m_measurement;
m_instrument_detector = other.m_instrument_detector;
m_instrument_detector_meta_data = other.m_instrument_detector_meta_data;
m_instrument_detector_data = other.m_instrument_detector_data;
m_instrument_detector_data_parameters = other.m_instrument_detector_data_parameters;
m_entry_index = other.m_entry_index;
m_entry_name = other.m_entry_name;
m_data_name = other.m_data_name;
......@@ -85,9 +88,10 @@ struct SaveContainerHdf5::_File
other.m_image_dataset = NULL;
other.m_file = NULL;
other.m_entry = NULL;
other.m_measurement_detector = NULL;
other.m_measurement = NULL;
other.m_instrument_detector = NULL;
other.m_instrument_detector_meta_data = NULL;
other.m_instrument_detector_data = NULL;
other.m_instrument_detector_data_parameters = NULL;
}
bool m_format_written;
......@@ -98,9 +102,10 @@ struct SaveContainerHdf5::_File
DataSet *m_image_dataset;
H5File *m_file;
Group *m_entry;
Group *m_measurement_detector;
Group *m_measurement;
Group *m_instrument_detector;
Group *m_instrument_detector_meta_data;
Group *m_instrument_detector_data;
Group *m_instrument_detector_data_parameters;
int m_entry_index;
string m_entry_name;
string m_data_name;
......@@ -359,26 +364,27 @@ void* SaveContainerHdf5::_open(const std::string &filename, std::ios_base::openm
new_file.m_instrument_detector = new Group(instrument.createGroup(m_ct_parameters.det_name));
string nxdetector = "NXdetector";
write_h5_attribute(*new_file.m_instrument_detector, "NX_class", nxdetector);
Group measurement = Group(new_file.m_entry->createGroup("measurement"));
string nxcollection = "NXcollection";
write_h5_attribute(measurement, "NX_class", nxcollection);
new_file.m_measurement_detector = new Group(measurement.createGroup(m_ct_parameters.det_name));
string nxdata = "NXdata";
write_h5_attribute(*new_file.m_measurement_detector, "NX_class", nxdata);
// Add attribute "default" for path to the NXdata
new_file.m_data_name = "image_data";
string path_to_nxdata = new_file.m_entry_name + "/measurement/" + m_ct_parameters.det_name;
new_file.m_instrument_detector_data = new Group(new_file.m_instrument_detector->createGroup("data"));
new_file.m_instrument_detector_data_parameters =
new Group(new_file.m_instrument_detector_data->createGroup("parameters"));
// set attributes for default path to data, measurement/detector is the default path but a soft-link to instrument/detector
new_file.m_data_name = "images";
string path_to_nxdata = new_file.m_entry_name + "/measurement/" + m_ct_parameters.det_name +"/data";
write_h5_attribute(*new_file.m_entry, "default", path_to_nxdata);
// Add attribute "signal" for final data path
write_h5_attribute(*new_file.m_measurement_detector, "signal", new_file.m_data_name);
new_file.m_instrument_detector_meta_data =
new Group(new_file.m_instrument_detector->createGroup("meta_data"));
string nxdata = "NXdata";
write_h5_attribute(*new_file.m_instrument_detector_data, "NX_class", nxdata);
write_h5_attribute(*new_file.m_instrument_detector_data, "signal", new_file.m_data_name);
// Finally create a measurement group, it will only contain a sof-link to intrument_detector created at _close()
new_file.m_measurement = new Group(new_file.m_entry->createGroup("measurement"));
string nxcollection = "NXcollection";
write_h5_attribute(*new_file.m_measurement, "NX_class", nxcollection);
// write the control parameters (detinfo, acq and image)
//Det Info
......@@ -447,8 +453,7 @@ void* SaveContainerHdf5::_open(const std::string &filename, std::ios_base::openm
} else {
new_file.m_entry = new Group(new_file.m_file->openGroup(strname));
Group instrument = Group(new_file.m_entry->openGroup(m_ct_parameters.instrument_name));
Group measurement = Group(new_file.m_entry->openGroup("measurement"));
new_file.m_measurement_detector = new Group(measurement.openGroup(m_ct_parameters.det_name));
new_file.m_measurement = new Group(new_file.m_entry->openGroup("measurement"));
new_file.m_instrument_detector = new Group(instrument.openGroup(m_ct_parameters.det_name));
}
} catch (FileIException &error) {
......@@ -465,13 +470,11 @@ void SaveContainerHdf5::_close(void* f) {
_File *file = (_File*)f;
if (!file->m_in_append || m_is_multiset) {
// Create soft link to the Data and NXdetector groups
string path = file->m_entry_name;
path += "/instrument/" + m_ct_parameters.det_name + "/" + file->m_data_name;
file->m_measurement_detector->link(H5L_TYPE_SOFT, path, file->m_data_name);
path = file->m_entry_name;
path += "/instrument/" + m_ct_parameters.det_name;
file->m_measurement_detector->link(H5L_TYPE_SOFT, path, "information");
// Create in measurement a soft link to the instrument detector group
string root_path = file->m_entry_name + "/" + m_ct_parameters.instrument_name+ "/";
string path = root_path + m_ct_parameters.det_name;
file->m_measurement->link(H5L_TYPE_SOFT, path, m_ct_parameters.det_name);
// ISO 8601 Time format
time_t now;
......@@ -559,12 +562,12 @@ long SaveContainerHdf5::_writeFile(void* f,Data &aData,
string key = it->first;
string value = it->second;
write_h5_dataset(*file->m_instrument_detector_meta_data,
write_h5_dataset(*file->m_instrument_detector_data_parameters,
key.c_str(),value);
}
}
delete file->m_instrument_detector_meta_data;
file->m_instrument_detector_meta_data = NULL;
delete file->m_instrument_detector_data_parameters;
file->m_instrument_detector_data_parameters = NULL;
// create the image data structure in the file
hsize_t data_dims[3], max_dims[3];
......@@ -595,7 +598,7 @@ long SaveContainerHdf5::_writeFile(void* f,Data &aData,
// create new dspace
file->m_image_dataspace = new DataSpace(RANK_THREE, data_dims, NULL);
file->m_image_dataset =
new DataSet(file->m_instrument_detector->createDataSet(file->m_data_name,
new DataSet(file->m_instrument_detector_data->createDataSet(file->m_data_name,
data_type,
*file->m_image_dataspace,
plist));
......@@ -605,7 +608,7 @@ long SaveContainerHdf5::_writeFile(void* f,Data &aData,
file->m_format_written = true;
} else if (file->m_in_append && !m_is_multiset && !file->m_dataset_extended) {
hsize_t allocated_dims[3];
file->m_image_dataset = new DataSet(file->m_instrument_detector->
file->m_image_dataset = new DataSet(file->m_instrument_detector_data->
openDataSet(file->m_data_name));
file->m_image_dataspace = new DataSpace(file->m_image_dataset->getSpace());
file->m_image_dataspace->getSimpleExtentDims(allocated_dims);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment