ATLAS Offline Software
Loading...
Searching...
No Matches
ScanDir.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8#ifndef SAMPLE_HANDLER__SCAN_DIR_H
9#define SAMPLE_HANDLER__SCAN_DIR_H
10
11
13
15#include <map>
16#include <memory>
17#include <vector>
18
19namespace SH
20{
37
38 struct ScanDir
39 {
40 //
41 // public interface
42 //
43
49 public:
50 ScanDir ();
51
52
62 public:
63 const ScanDir& scan (SampleHandler& sh, const std::string& dir) const;
64
65
75 public:
76 const ScanDir& scanEOS (SampleHandler& sh, const std::string& eosDir) const;
77
78
80 public:
81 const ScanDir& scan (SampleHandler& sh, DiskList& list) const;
82
83
90 public:
91 ScanDir& sampleDepth (int val_sampleDepth);
92
100 public:
101 ScanDir& absSampleDepth (int val_absSampleDepth);
102
105 public:
106 ScanDir& sampleName (const std::string& val_sampleName);
107
109 public:
110 ScanDir& minDepth (std::size_t val_minDepth);
111
113 public:
114 ScanDir& maxDepth (std::size_t val_maxDepth);
115
118 public:
119 ScanDir& filePattern (const std::string& val_filePattern);
120
123 public:
124 ScanDir& fileRegex (const std::string& val_fileRegex);
125
128 public:
129 ScanDir& directoryPattern (const std::string& val_directoryPattern);
130
133 public:
134 ScanDir& directoryRegex (const std::string& val_directoryRegex);
135
137 public:
138 ScanDir& samplePattern (const std::string& val_samplePattern);
139
142 public:
143 ScanDir& samplePostfix (const std::string& val_samplePostfix);
144
146 public:
147 ScanDir& sampleRename (const std::string& pattern, const std::string& name);
148
152 public:
153 ScanDir& extraNameComponent (int val_relSampleDepth);
154
155
156
157 //
158 // private interface
159 //
160
163 private:
165
169 private:
171
173 private:
174 std::string m_sampleName;
175
177 private:
178 std::size_t m_minDepth;
179
181 private:
182 std::size_t m_maxDepth;
183
186 private:
187 std::regex m_filePattern;
188
191 private:
193
196 private:
197 std::regex m_samplePattern;
198
201 private:
202 std::regex m_samplePostfix;
203
206 private:
208
210 private:
211 typedef std::vector<std::pair<std::regex,std::string> >::const_iterator SampleRenameIter;
212 std::vector<std::pair<std::regex,std::string> > m_sampleRename;
213
215 private:
217
218
225 private:
226 void recurse (std::map<std::string,std::shared_ptr<Sample>>& samples,
227 DiskList& list,
228 const std::vector<std::string>& hierarchy) const;
229
230
237 private:
238 void addSampleFile (std::map<std::string,std::shared_ptr<Sample>>& samples,
239 const std::vector<std::string>& hierarchy,
240 const std::string& path) const;
241
242
249 private:
250 std::string
251 findPathComponent (const std::vector<std::string>& hierarchy,
252 int absSampleDepth,
253 int relSampleDepth) const;
254 };
255}
256
257#endif
an interface for listing directory contents, locally or on a file server
Definition DiskList.h:24
A class that manages a list of Sample objects.
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition PrunDriver.h:15
std::regex m_directoryPattern
the value set by directoryPattern, converted to a regular expression
Definition ScanDir.h:192
ScanDir & sampleName(const std::string &val_sampleName)
a single sample name into which all found files should be placed.
Definition ScanDir.cxx:67
std::string m_sampleName
the value set by sampleName
Definition ScanDir.h:174
ScanDir & samplePattern(const std::string &val_samplePattern)
the pattern for samples to be accepted
Definition ScanDir.cxx:130
ScanDir & directoryPattern(const std::string &val_directoryPattern)
the pattern for directories to be visited
Definition ScanDir.cxx:112
const ScanDir & scan(SampleHandler &sh, const std::string &dir) const
scan the given directory and put the created samples into the sample handler
Definition ScanDir.cxx:168
std::vector< std::pair< std::regex, std::string > >::const_iterator SampleRenameIter
the list of entries from sampleRename
Definition ScanDir.h:211
ScanDir & sampleDepth(int val_sampleDepth)
the index of the file hierarchy at which we gather the sample name.
Definition ScanDir.cxx:47
bool m_samplePostfixEmpty
whether samplePostfix has been set to the empty string
Definition ScanDir.h:207
std::regex m_filePattern
the value set by filePattern, converted to a regular expression
Definition ScanDir.h:187
ScanDir & maxDepth(std::size_t val_maxDepth)
the maximum depth for files to make it into the sample
Definition ScanDir.cxx:85
std::string findPathComponent(const std::vector< std::string > &hierarchy, int absSampleDepth, int relSampleDepth) const
find the path component at the given depth
Definition ScanDir.cxx:328
ScanDir & fileRegex(const std::string &val_fileRegex)
the regular expression for files to be accepted
Definition ScanDir.cxx:103
int m_relSampleDepth
if this is negative it is the depth at which we take the sample name, counting from the end
Definition ScanDir.h:164
int m_extraNameComponent
the depth set with extraNameComponent, or 0 otherwise
Definition ScanDir.h:216
ScanDir & directoryRegex(const std::string &val_directoryRegex)
the regular expression for directories to be visited
Definition ScanDir.cxx:121
std::vector< std::pair< std::regex, std::string > > m_sampleRename
Definition ScanDir.h:212
ScanDir & samplePostfix(const std::string &val_samplePostfix)
the pattern for the postfix to be stripped from the sampleName
Definition ScanDir.cxx:139
int m_absSampleDepth
if m_relSampleDepth is not negative, it is the depth at which we take the sample name,...
Definition ScanDir.h:170
ScanDir & minDepth(std::size_t val_minDepth)
the minimum depth for files to make it into the sample
Definition ScanDir.cxx:76
ScanDir & absSampleDepth(int val_absSampleDepth)
the index of the file hierarchy at which we gather the sample name.
Definition ScanDir.cxx:57
std::size_t m_maxDepth
the value set by maxDepth
Definition ScanDir.h:182
std::regex m_samplePattern
the value set by samplePattern, converted to a regular expression
Definition ScanDir.h:197
const ScanDir & scanEOS(SampleHandler &sh, const std::string &eosDir) const
scan the given directory in EOS and put the created samples into the sample handler
Definition ScanDir.cxx:178
ScanDir()
standard constructor
Definition ScanDir.cxx:33
ScanDir & extraNameComponent(int val_relSampleDepth)
attach an extra name component to the sample based on a second component of the path
Definition ScanDir.cxx:158
ScanDir & sampleRename(const std::string &pattern, const std::string &name)
rename any sample matching pattern to name
Definition ScanDir.cxx:149
std::size_t m_minDepth
the value set by minDepth
Definition ScanDir.h:178
std::regex m_samplePostfix
the value set by samplePostfix, converted to a regular expression
Definition ScanDir.h:202
ScanDir & filePattern(const std::string &val_filePattern)
the pattern for files to be accepted
Definition ScanDir.cxx:94
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
Definition ScanDir.cxx:209
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
Definition ScanDir.cxx:255