4 #include "boost/date_time/posix_time/posix_time.hpp" 5 #include "boost/filesystem.hpp" 12 namespace bfs = boost::filesystem;
17 using boost::regex_match;
18 using boost::regex_search;
22 boost::regex
const rename_re{
23 "%[lp]|%(\\d+)?([#rRsS])|%t([ocrRsS])|%if([bnedp])|%" 24 "ifs%([^%]*)%([^%]*)%([ig]*)%|%.",
30 if (pt == boost::posix_time::ptime{}) {
33 return boost::posix_time::to_iso_string(pt);
44 std::string
const& filePattern)
const 48 auto sb =
cbegin(filePattern), sid = sb, se =
cend(filePattern);
49 while (regex_search(sid, se, match, rename_re)) {
52 assert(match.size() == 8);
69 result += match.prefix();
72 switch (*(match[0].first + 1)) {
86 if (match[2].matched) {
90 <<
"Unrecognized substitution %" << *(match[0].first + 1)
91 <<
" in pattern " << filePattern
92 <<
" -- typo or misconstructed regex?\n";
96 sid = match[0].second;
98 result.append(sid, se);
110 if (match[4].matched) {
111 switch (*(match[4].first)) {
114 result = ifp.stem().native();
118 result = canonical(ifp.parent_path()).native();
122 result = ifp.extension().native();
126 result = ifp.filename().native();
130 result = (canonical(ifp.parent_path()) / ifp.filename()).native();
134 <<
"Internal error: subInputFileName_() did not recognize " 135 "substitution code %if" 136 << *(match[4].first) <<
".\n";
139 }
else if (match[5].matched) {
141 syntax_option_type sflags{ECMAScript};
142 match_flag_type mflags{match_default};
144 if (match[7].matched) {
145 for (
auto c : match[7].str()) {
155 <<
"Internal error: subInputFileName_() did not recognize " 163 mflags |= format_first_only;
165 boost::regex
const dsub{match[5].str(), sflags};
166 result = regex_replace(
170 <<
"Internal error: subInputFileName_() called for unknown reasons " 172 << match[0].str() <<
".\n";
184 switch (*(match[3].first)) {
205 <<
"Internal error: subTimestamp_() did not recognize substitution " 207 << *(match[3].first) <<
".\n";
215 boost::smatch
const& match)
const 217 bool const did_match = match[1].matched;
218 std::string
const format_string = match[1].str();
219 auto zero_fill = [did_match, &format_string](std::ostringstream& os,
222 os << std::setfill(
'0') << std::setw(std::stoul(format_string));
228 std::ostringstream num_str;
230 switch (*(match[2].first)) {
236 num_str <<
"%" << match[1].str() <<
"#";
261 result = num_str.str();
262 if (result.empty()) {
281 return components.fileNameWithIndex(index);
286 std::string
const& toPattern)
289 boost::system::error_code ec;
290 bfs::rename(inPath, newFile, ec);
294 bfs::copy_file(inPath, newFile, bfs::copy_options::overwrite_existing);
std::string subFilledNumericNoIndex_(boost::smatch const &match) const
std::map< detail::FileNameComponents, std::size_t > indexForProcessedPattern_
std::string const & processName() const
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
SubRunID const & lowestSubRunID() const
std::string const & moduleLabel() const
boost::posix_time::ptime lowestRunStartTime() const
std::string applySubstitutionsNoIndex_(std::string const &filePattern) const
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
RunID highestRunID() const
PostCloseFileRenamer(FileStatsCollector const &stats)
boost::posix_time::ptime outputFileOpenTime() const
FileStatsCollector const & stats_
SubRunID const & highestSubRunID() const
FileNameComponents componentsFromPattern(std::string const &pattern)
boost::posix_time::ptime highestRunStartTime() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
RunID lowestRunID() const
boost::posix_time::ptime highestSubRunStartTime() const
std::string const & lastOpenedInputFile() const
std::string applySubstitutions(std::string const &filePattern)
std::string maybeRenameFile(std::string const &inPath, std::string const &toPattern)
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
boost::posix_time::ptime lowestSubRunStartTime() const
bool fileCloseRecorded() const
SubRunNumber_t subRun() const
std::string subTimestamp_(boost::smatch const &match) const
std::string to_string(ModuleType const mt)
std::string subInputFileName_(boost::smatch const &match) const
boost::posix_time::ptime outputFileCloseTime() const