All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Namespaces | Macros | Functions
icarusalg/icarusalg/gallery/helpers/C++/expandInputFiles.h File Reference
#include <fstream>
#include <cctype>
#include <vector>
#include <stdexcept>
#include <string>

Go to the source code of this file.

Classes

struct  details::FileListExpansionBaseError
 
struct  details::FileNotFoundError
 
struct  details::FileListErrorWrapper
 

Namespaces

 details
 

Macros

#define HAS_STD_FILESYSTEM   0
 

Functions

template<typename T >
std::vector< T > & details::appendToVector (std::vector< T > &dest, std::vector< T > const &src)
 
template<typename StartIter , typename EndIter >
StartIter details::skipSpaces (StartIter begin, EndIter end)
 
bool isROOTfile (std::string const &filePath)
 Returns whether the specified path represents a file list. More...
 
std::vector< std::string > expandFileList (std::string const &listPath)
 Expands the content of a file list into a vector of file paths (recursive). More...
 
std::vector< std::string > expandInputFiles (std::vector< std::string > const &filePaths)
 Expands all input files into a vector of file paths. More...
 

Macro Definition Documentation

#define HAS_STD_FILESYSTEM   0

Function Documentation

std::vector<std::string> expandFileList ( std::string const &  listPath)
inline

Expands the content of a file list into a vector of file paths (recursive).

Definition at line 96 of file icarusalg/icarusalg/gallery/helpers/C++/expandInputFiles.h.

96  {
97 
98  std::ifstream list(listPath);
99  if (!list) throw details::FileNotFoundError(listPath);
100 
101  std::vector<std::string> files;
102  std::string line;
103  unsigned int iLine = 0;
104  do {
105  ++iLine; // currently unused
106  std::getline(list, line);
107  if (!list) break;
108 
109  auto const end = line.cend();
110 
111  //
112  // find the start of the file name
113  //
114  auto i = details::skipSpaces(line.cbegin(), end);
115  if (i == end) continue; // empty line
116  if (*i == '#') continue; // full comment line
117 
118  std::string filePath;
119  auto iChunk = i;
120  while(i != end) {
121  if (*i == '\\') {
122  filePath.append(iChunk, i); iChunk = i;
123  if (++i == end) break; // weird way to end a line, with a '\'
124  if ((*i == '\\') || (*i == '#')) iChunk = i; // eat the backspace
125  // the rest will be added with the next chuck
126  }
127  else if (std::isspace(*i)) {
128  filePath.append(iChunk, i); iChunk = i; // before, there were no spaces
129  auto const iAfter = details::skipSpaces(i, end);
130  if (iAfter == end) break; // spaces, then end of line: we are done
131  if (*iAfter == '#') break; // a comment starts after spaces: we are done
132  i = iAfter; // these spaces are part of file name; schedule for writing
133  continue;
134  }
135  ++i;
136  } // for
137  filePath.append(iChunk, i);
138  if (filePath.empty()) continue;
139 
140  if (isROOTfile(filePath))
141  files.push_back(filePath);
142  else {
143  try {
144  details::appendToVector(files, expandFileList(filePath));
145  }
146  catch(details::FileListExpansionBaseError const& e) {
147  throw details::FileListErrorWrapper(listPath, iLine, e);
148  }
149  }
150 
151  } while (true);
152  return files;
153 } // expandFileList()
bool isROOTfile(std::string const &filePath)
Returns whether the specified path represents a file list.
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
std::vector< T > & appendToVector(std::vector< T > &dest, std::vector< T > const &src)
std::vector< std::string > expandFileList(std::string const &listPath)
Expands the content of a file list into a vector of file paths (recursive).
do i e
list
Definition: file_to_url.sh:28
StartIter skipSpaces(StartIter begin, EndIter end)
std::vector<std::string> expandInputFiles ( std::vector< std::string > const &  filePaths)
inline

Expands all input files into a vector of file paths.

Definition at line 158 of file icarusalg/icarusalg/gallery/helpers/C++/expandInputFiles.h.

159 {
160  std::vector<std::string> expanded;
161  for (std::string const& path: filePaths) {
162  if (isROOTfile(path))
163  expanded.push_back(path);
164  else
166  } // for
167  return expanded;
168 } // expandInputFiles()
bool isROOTfile(std::string const &filePath)
Returns whether the specified path represents a file list.
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
std::vector< T > & appendToVector(std::vector< T > &dest, std::vector< T > const &src)
std::vector< std::string > expandFileList(std::string const &listPath)
Expands the content of a file list into a vector of file paths (recursive).
bool isROOTfile ( std::string const &  filePath)
inline

Returns whether the specified path represents a file list.

Definition at line 80 of file icarusalg/icarusalg/gallery/helpers/C++/expandInputFiles.h.

80  {
81  if (filePath.length() < 6) return false; // too short (".root" is not good!)
82 
83  auto iExt = filePath.rfind('.');
84  if (iExt == std::string::npos) return false; // no file extension
85 
86  auto iBaseName = filePath.rfind('/');
87  if ((iBaseName != std::string::npos) && (iBaseName > iExt))
88  return false; // still no extension
89 
90  return filePath.substr(iExt) == ".root";
91 } // isROOTfile()