12 #include <boost/filesystem.hpp>
20 using namespace boost::filesystem;
22 auto dir_path = dir.empty() ? current_path() : path(dir);
23 if (
exists(dir_path) and not is_directory(dir_path)) {
24 throw std::runtime_error(
"'" + dir +
25 "' already exists but is not a directory");
27 create_directories(dir_path);
28 return canonical(dir_path).native();
35 return dir +
'/' +
name;
40 const std::string&
name,
size_t event) {
43 snprintf(prefix,
sizeof(prefix),
"event%09zu-", event);
48 return dir +
'/' + prefix +
name;
53 const std::string&
dir,
const std::string&
name) {
54 using namespace boost::filesystem;
60 auto dir_path = dir.empty() ? current_path() : path(dir);
61 if (not
exists(dir_path)) {
62 throw std::runtime_error(
"'" + dir_path.native() +
"' does not exists");
64 if (not is_directory(dir_path)) {
65 throw std::runtime_error(
"'" + dir_path.native() +
"' is not a directory");
69 size_t eventMin = SIZE_MAX;
74 std::regex re(
"^event([0-9]+)-" + name +
"$");
77 for (
const auto&
f : directory_iterator(dir_path)) {
78 if ((not
exists(
f.status())) or (not is_regular_file(
f.status()))) {
83 if (std::regex_match(
filename.c_str(), match, re)) {
88 auto ret = std::from_chars(match[1].first, match[1].
second, event);
89 if (ret.ptr == match[1].first) {
90 throw std::runtime_error(
91 "Could not extract event number from filename");
94 eventMin =
std::min(eventMin, event);
95 eventMax =
std::max(eventMax, event);
98 ACTS_VERBOSE(
"Detected event range [" << eventMin <<
"," << eventMax <<
"]");
101 if (eventMax < eventMin) {
102 return std::make_pair(0
u, 0
u);
104 return std::make_pair(eventMin, eventMax + 1);