19 #include <boost/filesystem.hpp>
22 using boost::filesystem::current_path;
23 using boost::filesystem::path;
25 auto dir_path = dir.empty() ? current_path() : path(dir);
26 if (
exists(dir_path) and not is_directory(dir_path)) {
27 throw std::runtime_error(
"'" + dir +
28 "' already exists but is not a directory");
30 create_directories(dir_path);
31 return canonical(dir_path).native();
35 const std::string&
name) {
39 return dir +
'/' +
name;
44 const std::string&
name,
48 snprintf(prefix,
sizeof(prefix),
"event%09zu-", event);
53 return dir +
'/' + prefix +
name;
58 const std::string& dir,
const std::string&
name) {
59 using boost::filesystem::current_path;
60 using boost::filesystem::directory_iterator;
61 using boost::filesystem::path;
67 auto dir_path = dir.empty() ? current_path() : path(dir);
68 if (not
exists(dir_path)) {
69 throw std::runtime_error(
"'" + dir_path.native() +
"' does not exists");
71 if (not is_directory(dir_path)) {
72 throw std::runtime_error(
"'" + dir_path.native() +
"' is not a directory");
76 size_t eventMin = SIZE_MAX;
81 std::regex re(
"^event([0-9]+)-" + name +
"$");
84 for (
const auto& f : directory_iterator(dir_path)) {
85 if ((not
exists(f.status())) or (not is_regular_file(f.status()))) {
89 filename = f.path().filename().native();
90 if (std::regex_match(filename.c_str(), match, re)) {
95 auto ret = std::from_chars(match[1].first, match[1].second, event);
96 if (ret.ptr == match[1].first) {
97 throw std::runtime_error(
98 "Could not extract event number from filename");
101 eventMin =
std::min(eventMin, event);
102 eventMax =
std::max(eventMax, event);
105 ACTS_VERBOSE(
"Detected event range [" << eventMin <<
"," << eventMax <<
"]");
108 if (eventMax < eventMin) {
109 return std::make_pair(0
u, 0
u);
111 return std::make_pair(eventMin, eventMax + 1);