4 #include "boost/date_time/posix_time/posix_time.hpp" 5 #include "boost/filesystem.hpp" 6 #include "boost/regex.hpp" 13 namespace bfs = boost::filesystem;
22 using boost::regex_match;
23 using boost::regex_search;
29 std::string
const& filePattern)
const 33 auto sb = cbegin(filePattern), si = sb, se = cend(filePattern);
38 boost::regex{
"%[lp]|%(\\d+)?([#rRsS])|%t([oc])|%if([bnedp])|%" 39 "ifs%([^%]*)%([^%]*)%([ig]*)%|%.",
43 assert(match.size() == 8);
60 result += match.prefix();
63 switch (*(match[0].first + 1)) {
77 if (match[2].matched) {
81 <<
"Unrecognized substitution %" << *(match[0].first + 1)
82 <<
" in pattern " << filePattern
83 <<
" -- typo or misconstructed regex?\n";
89 result.append(si, se);
101 if (match[4].matched) {
102 switch (*(match[4].first)) {
105 result = ifp.stem().native();
109 result = canonical(ifp.parent_path()).native();
113 result = ifp.extension().native();
117 result = ifp.filename().native();
121 result = (canonical(ifp.parent_path()) / ifp.filename()).native();
125 <<
"Internal error: subInputFileName_() did not recognize " 126 "substitution code %if" 127 << *(match[4].first) <<
".\n";
130 }
else if (match[5].matched) {
132 syntax_option_type sflags{ECMAScript};
133 match_flag_type mflags{match_default};
135 if (match[7].matched) {
136 for (
auto c : match[7].str()) {
146 <<
"Internal error: subInputFileName_() did not recognize " 154 mflags |= format_first_only;
156 boost::regex
const dsub{match[5].str(), sflags};
157 result = regex_replace(
161 <<
"Internal error: subInputFileName_() called for unknown reasons " 163 << match[0].str() <<
".\n";
175 switch (*(match[3].first)) {
184 <<
"Internal error: subTimestamp_() did not recognize substitution " 186 << *(match[3].first) <<
".\n";
194 boost::smatch
const& match)
const 196 bool const did_match = match[1].matched;
197 std::string
const format_string = match[1].str();
198 auto zero_fill = [did_match, &format_string](std::ostringstream& os,
201 os << std::setfill(
'0') << std::setw(std::stoul(format_string));
207 std::ostringstream num_str;
209 switch (*(match[2].first)) {
215 num_str <<
"%" << match[1].str() <<
"#";
240 result = num_str.str();
241 if (result.empty()) {
260 return components.fileNameWithIndex(index);
265 std::string
const& toPattern)
268 boost::system::error_code ec;
269 bfs::rename(inPath, newFile, ec);
273 bfs::copy_file(inPath, newFile, bfs::copy_option::overwrite_if_exists);
std::string subFilledNumericNoIndex_(boost::smatch const &match) const
std::map< detail::FileNameComponents, std::size_t > indexForProcessedPattern_
std::string const & processName() const
SubRunID const & lowestSubRunID() const
std::string const & moduleLabel() const
RunID const & runID() const
std::string applySubstitutionsNoIndex_(std::string const &filePattern) const
PostCloseFileRenamer(FileStatsCollector const &stats)
boost::posix_time::ptime outputFileOpenTime() const
FileStatsCollector const & stats_
SubRunID const & highestSubRunID() const
FileNameComponents componentsFromPattern(std::string const &pattern)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::string const & lastOpenedInputFile() const
std::string applySubstitutions(std::string const &filePattern)
std::string maybeRenameFile(std::string const &inPath, std::string const &toPattern)
bool fileCloseRecorded() const
SubRunNumber_t subRun() const
std::string subTimestamp_(boost::smatch const &match) const
std::string subInputFileName_(boost::smatch const &match) const
boost::posix_time::ptime outputFileCloseTime() const