DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
FileDataStoreImpl.hxx
Go to the documentation of this file.
1
2namespace dunedaq::dfmodules {
3
4template<FileHandleConcept FileHandleClass>
5inline std::string
6FileDataStoreImpl<FileHandleClass>::get_file_name(const daqdataformats::run_number_t run_number) const
7{
8
9 std::ostringstream work_oss;
10 work_oss << m_config_params->get_directory_path();
11 if (work_oss.str().length() > 0) {
12 work_oss << "/";
13 }
14 work_oss << m_operational_environment + "_" + m_config_params->get_filename_params()->get_file_type_prefix();
15 if (work_oss.str().length() > 0) {
16 work_oss << "_";
17 }
18
19 work_oss << m_config_params->get_filename_params()->get_run_number_prefix();
20 work_oss << std::setw(m_config_params->get_filename_params()->get_digits_for_run_number()) << std::setfill('0')
21 << run_number;
22 work_oss << "_";
23
24 work_oss << m_config_params->get_filename_params()->get_file_index_prefix();
25 work_oss << std::setw(m_config_params->get_filename_params()->get_digits_for_file_index()) << std::setfill('0')
26 << m_file_index;
27
28 work_oss << "_" << m_writer_identifier;
29 work_oss << "." << m_file_handle->get_file_name_extension();
30 return work_oss.str();
31}
32
33template<FileHandleConcept FileHandleClass>
34inline size_t
35FileDataStoreImpl<FileHandleClass>::get_free_space(const std::string& the_path) const
36{
37 struct statvfs vfs_results;
38 int retval = statvfs(the_path.c_str(), &vfs_results);
39 if (retval != 0) {
40 return 0;
41 }
42 return vfs_results.f_bsize * vfs_results.f_bavail;
43}
44
45template<FileHandleConcept FileHandleClass>
46inline void
47FileDataStoreImpl<FileHandleClass>::throw_if_insufficient_space_for_object(const size_t obj_size,
48 const std::string& obj_name) const
49{
50
51 size_t current_free_space = get_free_space(m_path);
52
53 if (current_free_space < (m_free_space_safety_factor_for_write * obj_size)) {
54 std::ostringstream msg_oss;
55 msg_oss << "a safety factor of " << m_free_space_safety_factor_for_write << " times the " << obj_name << " size";
56 InsufficientDiskSpace issue(ERS_HERE,
57 get_name(),
58 m_path,
59 current_free_space,
60 (m_free_space_safety_factor_for_write * obj_size),
61 msg_oss.str());
62 std::string msg =
63 "writing a " + obj_name + " to file" + (m_file_handle ? " " + m_file_handle->get_file_name() : "");
64 throw RetryableDataStoreProblem(ERS_HERE, get_name(), msg, issue);
65 }
66}
67
68} // namespace dunedaq::dfmodules
#define ERS_HERE
An ERS Issue for DataStore creation failure.
Definition DataStore.hpp:91