Line data Source code
1 : /**
2 : *
3 : * @file HDF5DataStore.hpp
4 : *
5 : * Header for an implementation of the DataStore interface which writes out *.hdf5 files
6 : *
7 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
8 : * Licensing/copyright details are in the COPYING file that you should have
9 : * received with this code.
10 : */
11 :
12 : #ifndef DFMODULES_PLUGINS_HDF5DATASTORE_HPP_
13 : #define DFMODULES_PLUGINS_HDF5DATASTORE_HPP_
14 :
15 : #include "dfmodules/FileDataStoreImpl.hpp"
16 :
17 : #include "appmodel/DataStoreConf.hpp"
18 : #include "hdf5libs/HDF5RawDataFile.hpp"
19 :
20 : #include <memory>
21 : #include <string>
22 :
23 : namespace dunedaq::dfmodules {
24 :
25 : class HDF5DataStore : public FileDataStoreImpl<hdf5libs::HDF5RawDataFile>
26 : {
27 :
28 : public:
29 9 : explicit HDF5DataStore(std::string const& name,
30 : std::shared_ptr<appfwk::ConfigurationManager> mcfg,
31 : std::string const& writer_name)
32 9 : : FileDataStoreImpl(name, mcfg, writer_name)
33 : {
34 8 : }
35 :
36 : void open_new_file(const std::string& unique_filename) override;
37 : };
38 :
39 : inline void
40 16 : HDF5DataStore::open_new_file(const std::string& unique_filename)
41 : {
42 :
43 16 : auto& file_handle{ get_file_handle() };
44 16 : try {
45 :
46 16 : file_handle.reset(
47 : new hdf5libs::HDF5RawDataFile(unique_filename,
48 : get_run_number(),
49 : get_file_index(),
50 16 : get_application_name(),
51 16 : get_configuration().get_file_layout_params(),
52 48 : hdf5libs::HDF5SourceIDHandler::make_source_id_geo_id_map(get_session()),
53 : get_compression_level(),
54 : ".writing",
55 48 : HighFive::File::OpenOrCreate));
56 0 : } catch (std::exception const& excpt) {
57 0 : throw FileOperationProblem(ERS_HERE, get_name(), unique_filename, excpt);
58 0 : } catch (...) { // NOLINT(runtime/exceptions)
59 : // NOLINT here because we *ARE* re-throwing the exception!
60 0 : throw FileOperationProblem(ERS_HERE, get_name(), unique_filename);
61 0 : }
62 :
63 16 : TLOG_DEBUG(TLVL_BASIC) << get_name() << "Created HDF5 file (" << unique_filename << ").";
64 :
65 : // write attributes that aren't being handled by the HDF5RawDataFile right now
66 16 : file_handle->write_attribute("operational_environment", std::string(get_operational_environment()));
67 16 : file_handle->write_attribute("offline_data_stream", std::string(get_offline_data_stream()));
68 32 : file_handle->write_attribute("run_was_for_test_purposes",
69 48 : std::string(get_run_is_for_test_purposes() ? "true" : "false"));
70 16 : }
71 :
72 : } // namespace dunedaq::dfmodules
73 :
74 : #endif // DFMODULES_PLUGINS_HDF5DATASTORE_HPP_
|