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