|
ATLAS Offline Software
|
Go to the documentation of this file.
35 using namespace msgGridTools;
42 typedef std::chrono::steady_clock clock;
47 std::recursive_mutex
mutex;
50 bool haveProxy =
false;
57 std::lock_guard<std::recursive_mutex> lock (
mutex);
59 if (haveProxy ==
false)
76 std::istringstream str2 (
output.substr(
output.rfind(
'\n',
output.size()-2)+1,std::string::npos));
95 proxyExpiration >
clock::now() + std::chrono::minutes (20);
100 std::lock_guard<std::recursive_mutex> lock (
mutex);
119 ProxyData& proxyData ()
130 std::vector<std::string>
131 readLineList (
const std::string&
text,
132 const std::string&
begin)
134 std::vector<std::string>
result;
136 for (std::string::size_type
split = 0;
144 if (split2 == std::string::npos)
145 split2 =
text.size();
147 while (isspace (subresult.front()))
148 subresult = subresult.substr (1);
149 while (isspace (subresult.back()))
150 subresult.pop_back();
151 result.push_back (std::move (subresult));
161 std::string readLine (
const std::string&
text,
162 const std::string&
begin)
167 if (
lines.size() > 1)
176 unsigned readLineUnsigned (
const std::string&
text,
177 const std::string&
begin)
190 std::string rucioSetupCommand ()
192 return "source $ATLAS_LOCAL_ROOT_BASE/user/atlasLocalSetup.sh -q && lsetup --force 'rucio -w'";
200 static const std::string
result =
"SAMPLEHANDLER_RUCIO_DOWNLOAD";
208 return proxyData().checkVomsProxy();
215 proxyData().ensureVomsProxy();
220 std::vector<std::string>
223 #pragma GCC diagnostic push
224 #pragma GCC diagnostic ignored "-Wpragmas"
225 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
226 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
228 #pragma GCC diagnostic pop
233 std::vector<std::string>
242 static const std::string separator =
"------- SampleHandler Split -------";
243 std::vector<std::string>
result;
246 std::string
output =
sh::exec_read (
"source $ATLAS_LOCAL_ROOT_BASE/user/atlasLocalSetup.sh -q && lsetup --force fax && echo " + separator +
" && fax-get-gLFNs " +
sh::quote (
name));
248 if (
split == std::string::npos)
251 std::istringstream
str (
output.substr (
split + separator.size() + 1));
254 while (std::getline (
str,
line))
258 if (
line.find (
"root:") != 0)
261 std::string::size_type split1 =
line.rfind (
":");
262 std::string::size_type split2 =
line.rfind (
"/");
265 if (split1 != std::string::npos)
274 RCU_WARN_MSG (
"dataset " +
name +
" did not contain any files. this is likely not right");
280 std::vector<std::string>
282 const std::string& selectOptions)
290 std::vector<std::string>
292 const std::string& selectOptions)
300 static const std::string separator =
"------- SampleHandler Split -------";
303 std::string
output =
sh::exec_read (rucioSetupCommand() +
" && echo " + separator +
" && rucio list-file-replicas --pfns --protocols root " + selectOptions +
" " +
sh::quote (
name));
305 if (
split == std::string::npos)
307 std::istringstream
str (
output.substr (
split + separator.size() + 1));
312 std::map<std::string,std::string> resultMap;
317 while (std::getline (
str,
line))
327 std::string::size_type
split =
line.rfind (
"/");
328 if (
split != std::string::npos)
338 std::vector<std::string>
result;
339 for (
const auto&
file : resultMap)
342 ANA_MSG_WARNING (
"dataset " +
name +
" did not contain any files. this is likely not right");
354 static const std::string separator =
"------- SampleHandler Split -------";
355 std::vector<RucioListDidsEntry>
result;
360 if (
split == std::string::npos)
363 std::istringstream
str (
output.substr (
split + separator.size() + 1));
364 boost::regex pattern (
"^\\| ([a-zA-Z0-9_.-]+):([a-zA-Z0-9_.-]+) +\\| ([a-zA-Z0-9_.-]+) +\\| *$");
366 while (std::getline (
str,
line))
383 std::vector<RucioListFileReplicasEntry>
390 static const std::string separator =
"------- SampleHandler Split -------";
391 std::vector<RucioListFileReplicasEntry>
result;
393 std::string
command = rucioSetupCommand() +
" && echo " + separator +
" && rucio list-file-replicas --protocols root " +
sh::quote (
dataset);
398 if (
split == std::string::npos)
401 std::istringstream
str (
output.substr (
split + separator.size() + 1));
402 boost::regex pattern (
"^\\| +([^ ]+) +\\| +([^ ]+) +\\| +([^ ]+ [^ ]+) +\\| +([^ ]+) +\\| +([^: ]+): ([^ ]+) +\\| *$");
404 while (std::getline (
str,
line))
425 std::map<std::string,std::unique_ptr<MetaObject> >
432 static const std::string separator =
"------- SampleHandler Split -------";
433 std::map<std::string,std::unique_ptr<MetaObject> >
result;
435 std::string
command = rucioSetupCommand() +
" && echo " + separator +
" && rucio get-metadata";
445 if (
split == std::string::npos)
448 std::istringstream
str (
output.substr (
split + separator.size() + 1));
451 std::unique_ptr<MetaObject> meta (
new MetaObject);
453 auto addMeta = [&] ()
461 while (std::getline (
str,
line))
464 if (
line ==
"------")
471 throw std::runtime_error (
"duplicate entry: " +
what[1]);
473 }
else if (!
line.empty())
480 for (
auto& subresult :
result)
482 if (datasets.find (subresult.first) == datasets.end())
483 RCU_THROW_MSG (
"received result for dataset not requested: " + subresult.first);
501 const std::string separator =
"------- SampleHandler Split -------";
502 std::string
command = rucioSetupCommand() +
" && echo " + separator +
" && cd " +
sh::quote (location) +
" && rucio download " +
sh::quote (
dataset) +
" 2>&1";
507 if (
split == std::string::npos)
513 result.totalFiles = readLineUnsigned (
output,
"Total files (DID): ");
514 result.downloadedFiles = readLineUnsigned (
output,
"Downloaded files: ");
515 result.alreadyLocal = readLineUnsigned (
output,
"Files already found locally: ");
516 result.notDownloaded = readLineUnsigned (
output,
"Files that cannot be downloaded: ");
522 std::vector<RucioDownloadResult>
524 const std::vector<std::string>& datasets)
526 std::vector<RucioDownloadResult>
result;
534 std::vector<std::string>
537 const std::string& fileGlob)
539 std::vector<std::string>
result;
541 std::string
path = location;
542 if (
path.back() !=
'/')
544 if (
dataset.find (
':') != std::string::npos)
548 const std::string finished {
553 if (gSystem->AccessPathName (finished.c_str()) != 0)
557 throw std::runtime_error (
"failed to download all files of " +
dataset);
559 std::ofstream (finished.c_str());
565 while (std::getline (
str,
line))
path
python interpreter configuration --------------------------------------—
std::vector< std::string > faxListFilesRegex(const std::string &name, const std::string &filter)
list the FAX URLs for all the files in the dataset or dataset container matching the given filter (as...
std::vector< RucioListDidsEntry > rucioListDids(const std::string &dataset)
run rucio-list-dids for the given dataset
bool checkVomsProxy()
return whether we have a valid VOMS proxy available
std::vector< std::string > rucioDirectAccessRegex(const std::string &name, const std::string &filter, const std::string &selectOptions)
list the rucio URLs for all the files in the dataset or dataset container matching the given filter (...
std::vector< RucioListFileReplicasEntry > rucioListFileReplicas(const std::string &dataset)
run rucio-list-file-replicas for the given dataset
one entry from the rucio-list-file-replicas command
std::vector< std::string > rucioDirectAccessGlob(const std::string &name, const std::string &filter, const std::string &selectOptions)
list the rucio URLs for all the files in the dataset or dataset container matching the given filter (...
one entry from the rucio-list-dids command
#define RCU_WARN_MSG(message)
#define RCU_REQUIRE_SOFT(x)
bool match_expr(const boost::regex &expr, const std::string &str)
returns: whether we can match the entire string with the regular expression guarantee: strong failure...
std::map< std::string, std::unique_ptr< MetaObject > > rucioGetMetadata(const std::set< std::string > &datasets)
run rucio-get-metadata for the given list of datasets
RucioDownloadResult rucioDownload(const std::string &location, const std::string &dataset)
run rucio-download
void ensureVomsProxy()
ensure that we have a valid VOMS proxy available
std::vector< std::string > rucioCacheDatasetGlob(const std::string &location, const std::string &dataset, const std::string &fileGlob)
download the dataset, and return a list matching the pattern
std::string exec_read(const std::string &cmd)
effects: execute the given command and return the output returns: the output of the command guarantee...
the result from rucio_download
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
const std::string & downloadStageEnvVar()
the name of the environment variable containing the directory for staging files from the grid
This module provides a lot of global definitions, forward declarations and includes that are used by ...
#define RCU_THROW_MSG(message)
#define ATLAS_THREAD_SAFE
std::string quote(const std::string &sentence)
Enclose a string in ".
Define macros for attributes used to control the static checker.
std::vector< RucioDownloadResult > rucioDownloadList(const std::string &location, const std::vector< std::string > &datasets)
run rucio-download with multiple datasets
std::vector< std::string > faxListFilesGlob(const std::string &name, const std::string &filter)
list the FAX URLs for all the files in the dataset or dataset container matching the given filter (as...
std::string glob_to_regexp(const std::string &glob)
returns: a string that is the regular expression equivalent of the given glob expression guarantee: s...