22 #include <type_traits>
26 using std::filesystem::current_path;
29 auto dir_path = dir.empty() ? current_path() :
path(dir);
30 if (
exists(dir_path) and not is_directory(dir_path)) {
31 throw std::runtime_error(
"'" + dir +
32 "' already exists but is not a directory");
34 create_directories(dir_path);
43 return dir +
'/' +
name;
52 snprintf(prefix,
sizeof(prefix),
"event%09zu-", event);
57 return dir +
'/' + prefix +
name;
63 using std::filesystem::current_path;
64 using std::filesystem::directory_iterator;
71 auto dir_path = dir.empty() ? current_path() :
path(dir);
72 if (not
exists(dir_path)) {
73 throw std::runtime_error(
"'" + dir_path.native() +
"' does not exists");
75 if (not is_directory(dir_path)) {
76 throw std::runtime_error(
"'" + dir_path.native() +
"' is not a directory");
80 size_t eventMin = SIZE_MAX;
85 std::regex re(
"^event([0-9]+)-" + name +
"$");
88 for (
const auto&
f : directory_iterator(dir_path)) {
89 if ((not
exists(
f.status())) or (not is_regular_file(
f.status()))) {
93 filename =
f.path().filename().native();
94 if (std::regex_match(filename.c_str(), match, re)) {
99 auto ret = std::from_chars(match[1].first, match[1].second,
event);
100 if (ret.ptr == match[1].first) {
101 throw std::runtime_error(
102 "Could not extract event number from filename");
106 eventMax = std::max(eventMax,
event);
109 ACTS_VERBOSE(
"Detected event range [" << eventMin <<
"," << eventMax <<
"]");
112 if (eventMax < eventMin) {
113 return std::make_pair(0
u, 0
u);
115 return std::make_pair(eventMin, eventMax + 1);