47 sampleDepth (
int val_sampleDepth)
57 absSampleDepth (
int val_absSampleDepth)
67 sampleName (
const std::string& val_sampleName)
76 minDepth (std::size_t val_minDepth)
85 maxDepth (std::size_t val_maxDepth)
94 filePattern (
const std::string& val_filePattern)
103 fileRegex (
const std::string& val_fileRegex)
112 directoryPattern (
const std::string& val_directoryPattern)
121 directoryRegex (
const std::string& val_directoryRegex)
130 samplePattern (
const std::string& val_samplePattern)
139 samplePostfix (
const std::string& val_samplePostfix)
149 sampleRename (
const std::string& pattern,
const std::string& name)
158 extraNameComponent (
int val_relSampleDepth)
190 std::vector<std::string> hierarchy;
191 hierarchy.push_back (list.dirname());
193 std::map<std::string,std::shared_ptr<Sample>> samples;
194 recurse (samples, list, hierarchy);
195 for (
const auto& sample : samples)
197 if (sample.second !=
nullptr)
199 sh.add (sample.second);
208 recurse (std::map<std::string,std::shared_ptr<Sample>>& samples,
210 const std::vector<std::string>& hierarchy)
const
212 using namespace msgScanDir;
217 std::unique_ptr<DiskList> sublist (list.openDirUnique());
219 if (sublist.get() != 0)
223 ANA_MSG_DEBUG (
"directory does not match pattern, skipping directory " << list.path());
226 ANA_MSG_DEBUG (
"maxDepth exceeded, skipping directory " << list.path());
227 }
else if (hierarchy.size() >= 100)
232 ANA_MSG_WARNING (
"directory nesting exceeds 100 levels, not descending further (possible symlink loop): " << list.path());
236 std::vector<std::string> subhierarchy = hierarchy;
237 subhierarchy.push_back (list.fileName());
238 recurse (samples, *sublist, subhierarchy);
246 std::vector<std::string> subhierarchy = hierarchy;
247 subhierarchy.push_back (list.fileName());
260 addSampleFile (std::map<std::string,std::shared_ptr<Sample>>& samples,
261 const std::vector<std::string>& hierarchy,
262 const std::string& path)
const
279 for (std::size_t iter = 0, end =
sampleName.size();
280 iter != end && !done; ++ iter)
285 throw std::runtime_error (
"sample name matches entire postfix pattern: \"" +
sampleName +
"\"");
296 if (component.empty())
319 if (iter == samples.end())
321 auto sample = std::make_shared<SampleLocal> (
sampleName);
332 std::string ScanDir ::
333 findPathComponent (
const std::vector<std::string>& hierarchy,
335 int relSampleDepth)
const
340 if (relSampleDepth < 0)
341 myindex = relSampleDepth + hierarchy.size();
347 if (myindex >= 0 && std::size_t (myindex) >= hierarchy.size())
366 if (
split == std::string::npos)
378 if (
split != std::string::npos)
a DiskList implementation for EOS
a DiskList implementation for local directories
an interface for listing directory contents, locally or on a file server
A class that manages a list of Sample objects.
A Sample based on a simple file list.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
void scan(TDirectory *td=0, int depth=0)
This module defines a variety of assert style macros.
bool match_expr(const std::regex &expr, std::string_view str)
returns: whether we can match the entire string with the regular expression guarantee: strong failure...
std::string glob_to_regexp(std::string_view glob)
returns: a string that is the regular expression equivalent of the given glob expression guarantee: s...
This module provides a lot of global definitions, forward declarations and includes that are used by ...
std::vector< std::pair< std::regex, std::string > >::const_iterator SampleRenameIter
the list of entries from sampleRename
std::regex m_directoryPattern
the value set by directoryPattern, converted to a regular expression
ScanDir & sampleName(const std::string &val_sampleName)
a single sample name into which all found files should be placed.
std::string m_sampleName
the value set by sampleName
bool m_samplePostfixEmpty
whether samplePostfix has been set to the empty string
std::regex m_filePattern
the value set by filePattern, converted to a regular expression
std::string findPathComponent(const std::vector< std::string > &hierarchy, int absSampleDepth, int relSampleDepth) const
find the path component at the given depth
int m_relSampleDepth
if this is negative it is the depth at which we take the sample name, counting from the end
int m_extraNameComponent
the depth set with extraNameComponent, or 0 otherwise
std::vector< std::pair< std::regex, std::string > > m_sampleRename
int m_absSampleDepth
if m_relSampleDepth is not negative, it is the depth at which we take the sample name,...
ScanDir & absSampleDepth(int val_absSampleDepth)
the index of the file hierarchy at which we gather the sample name.
std::size_t m_maxDepth
the value set by maxDepth
std::regex m_samplePattern
the value set by samplePattern, converted to a regular expression
ScanDir()
standard constructor
std::size_t m_minDepth
the value set by minDepth
std::regex m_samplePostfix
the value set by samplePostfix, converted to a regular expression
void recurse(std::map< std::string, std::shared_ptr< Sample > > &samples, DiskList &list, const std::vector< std::string > &hierarchy) const
perform the recursive scanning of the directory tree
void addSampleFile(std::map< std::string, std::shared_ptr< Sample > > &samples, const std::vector< std::string > &hierarchy, const std::string &path) const
add the given file to the sample based on the hierarchy, creating the sample if necessary