Skip to content

Commit cd1431b

Browse files
authored
Merge pull request #478 from DUNE-DAQ/kbiery/improved_creation_timestamp_consistency
Improved creation timestamp consistency
2 parents 079adad + 8c9c2f0 commit cd1431b

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

plugins/HDF5DataStore.hpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -477,20 +477,6 @@ class HDF5DataStore : public DataStore
477477
if (m_file_handle.get() == nullptr || m_basic_name_of_open_file.compare(file_name) ||
478478
m_open_flags_of_open_file != open_flags) {
479479

480-
// 04-Feb-2021, KAB: adding unique substrings to the filename
481-
std::string unique_filename = file_name;
482-
time_t now = time(0);
483-
std::string file_creation_timestamp = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(now));
484-
if (!m_disable_unique_suffix) {
485-
// timestamp substring
486-
size_t ufn_len = unique_filename.length();
487-
if (ufn_len > 6) { // len GT 6 gives us some confidence that we have at least x.hdf5
488-
std::string timestamp_substring = "_" + file_creation_timestamp;
489-
TLOG_DEBUG(TLVL_BASIC) << get_name() << ": timestamp substring for filename: " << timestamp_substring;
490-
unique_filename.insert(ufn_len - 5, timestamp_substring);
491-
}
492-
}
493-
494480
// close an existing open file
495481
if (m_file_handle.get() != nullptr) {
496482
std::string open_filename = m_file_handle->get_file_name();
@@ -504,6 +490,26 @@ class HDF5DataStore : public DataStore
504490
}
505491
}
506492

493+
// 04-Feb-2021, KAB: adding unique substrings to the filename
494+
// 05-Feb-2026, KAB: moved this block of code *after* the block that closes an
495+
// existing open file. When the two blocks were executed in the opposite order,
496+
// it was possible that the closing of the currently-open file could take a
497+
// non-trivial amount of time, and then the timestamp in the filename (determined
498+
// here) and the timestamp in the creation_timestamp HDF5 file Attribute
499+
// (determined inside the HDF5RawDataFile constructor) could disagree.
500+
std::string unique_filename = file_name;
501+
if (!m_disable_unique_suffix) {
502+
time_t now = time(0);
503+
std::string file_creation_timestamp = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(now));
504+
// timestamp substring
505+
size_t ufn_len = unique_filename.length();
506+
if (ufn_len > 6) { // len GT 6 gives us some confidence that we have at least x.hdf5
507+
std::string timestamp_substring = "_" + file_creation_timestamp;
508+
TLOG_DEBUG(TLVL_BASIC) << get_name() << ": timestamp substring for filename: " << timestamp_substring;
509+
unique_filename.insert(ufn_len - 5, timestamp_substring);
510+
}
511+
}
512+
507513
// opening file for the first time OR something changed in the name or the way of opening the file
508514
TLOG_DEBUG(TLVL_BASIC) << get_name() << ": going to open file " << unique_filename << " with open_flags "
509515
<< std::to_string(open_flags);

0 commit comments

Comments
 (0)