12 #ifndef EXPANDINPUTFILES_H
13 #define EXPANDINPUTFILES_H
19 #if __cpp_lib_filesystem
20 # define HAS_STD_FILESYSTEM 1
21 # include <filesystem>
23 # define HAS_STD_FILESYSTEM 0
37 (std::vector<T>& dest, std::vector<T>
const& src)
38 { dest.insert(dest.end(), src.begin(), src.end());
return dest; }
40 template <
typename StartIter,
typename EndIter>
42 for (
auto i = begin; i !=
end; ++i)
if (!std::isspace(*i))
return i;
47 struct FileListExpansionBaseError:
public std::runtime_error
48 {
using std::runtime_error::runtime_error; };
50 struct FileNotFoundError:
public FileListExpansionBaseError {
56 struct FileListErrorWrapper:
public FileListExpansionBaseError {
61 std::string
const&
fileName,
unsigned int line,
65 (
std::string(error.what()) +
"\n " +
formatMsg(fileName, line))
70 {
return "Error from file list '" + fname +
"' line " +
std::to_string(line); }
76 #if HAS_STD_FILESYSTEM
78 {
return (filePath.extension() ==
".root") && !filePath.stem().empty(); }
79 #else // no STL filesystem library:
81 if (filePath.length() < 6)
return false;
83 auto iExt = filePath.rfind(
'.');
84 if (iExt == std::string::npos)
return false;
86 auto iBaseName = filePath.rfind(
'/');
87 if ((iBaseName != std::string::npos) && (iBaseName > iExt))
90 return filePath.substr(iExt) ==
".root";
93 #endif // STL filesystem library?
96 inline std::vector<std::string>
expandFileList(std::string
const& listPath) {
98 std::ifstream
list(listPath);
101 std::vector<std::string> files;
103 unsigned int iLine = 0;
106 std::getline(list, line);
109 auto const end = line.cend();
115 if (i ==
end)
continue;
116 if (*i ==
'#')
continue;
118 std::string filePath;
122 filePath.append(iChunk, i); iChunk = i;
123 if (++i ==
end)
break;
124 if ((*i ==
'\\') || (*i ==
'#')) iChunk = i;
127 else if (std::isspace(*i)) {
128 filePath.append(iChunk, i); iChunk = i;
130 if (iAfter ==
end)
break;
131 if (*iAfter ==
'#')
break;
137 filePath.append(iChunk, i);
138 if (filePath.empty())
continue;
141 files.push_back(filePath);
158 (std::vector<std::string>
const& filePaths)
160 std::vector<std::string> expanded;
161 for (std::string
const&
path: filePaths) {
163 expanded.push_back(
path);
171 #endif // EXPANDINPUTFILES_H
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
FileListErrorWrapper(std::string const &fileName, unsigned int line, FileListExpansionBaseError const &error)
static std::string formatMsg(std::string const &fname, unsigned int line)
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
auto end(FixedBins< T, C > const &) noexcept
FileNotFoundError(std::string const &fileName)
std::vector< T > & appendToVector(std::vector< T > &dest, std::vector< T > const &src)
FileListErrorWrapper(std::string const &fileName, unsigned int line)
auto begin(FixedBins< T, C > const &) noexcept
std::string to_string(WindowPattern const &pattern)
services TFileService fileName
StartIter skipSpaces(StartIter begin, EndIter end)