-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runFilesFromSAM.sh: added --locate and --experiment options
- Loading branch information
1 parent
6f25e95
commit 47d2393
Showing
1 changed file
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
# Date: March 2021 | ||
# | ||
# Changes: | ||
# 20220720 ([email protected]) [1.4] | ||
# added --locate option | ||
# 20220406 ([email protected]) [1.3] | ||
# --max option now only converts that many files | ||
# 20220126 ([email protected]) [1.2] | ||
|
@@ -25,6 +27,7 @@ SCRIPTVERSION="1.3" | |
declare -r RawType='raw' | ||
declare -r DecodeType='decoded' | ||
declare -r XRootDschema='root' | ||
declare -r LocateSchema='locate' | ||
declare -r dCacheLocation='dcache' | ||
declare -r TapeLocation='enstore' | ||
declare -r BNBstream='bnb' | ||
|
@@ -96,17 +99,21 @@ Options: | |
if the stage is explicitly selected, it is used as constraint in SAM query | ||
--schema=<${XRootDschema}|...> [${DefaultSchema}] | ||
--xrootd , --root , -X | ||
select the type of URL (XRootD, ...) | ||
--locate | ||
select the type of URL (XRootD, ...); the option \`--locate\` and the | ||
special schema value <${LocateSchema}> will cause the query to be done via | ||
SAM \`locate-file\` command instead of the default \`get-file-access-url\` | ||
--location=<${dCacheLocation}|${TapeLocation}> [${DefaultLocation}] | ||
--tape , --enstore , -T | ||
--disk , --dcache , -C | ||
select the storage type | ||
select the storage type (no effect for \`locate\` schema) | ||
--stream=<${BNBstream}|${NuMIstream}|...> [${DefaultStream}] | ||
--bnb | ||
--numi | ||
--allstreams | ||
select the stream (if empty, all streams are included) | ||
--output=OUTPUTFILE | ||
use OUTPUTFILE for all output file lists | ||
--outputdir=OUTPUTDIR | ||
|
@@ -126,6 +133,8 @@ Options: | |
--max=LIMIT | ||
retrieves only the first LIMIT files from SAM (only when querying run numbers); | ||
in all cases, it translates only LIMIT files into a location; 0 means no limit | ||
--experiment=NAME | ||
experiment name (and SAM station) passed to SAM | ||
--quiet , -q | ||
do not print non-fatal information on screen while running | ||
--debug[=LEVEL] | ||
|
@@ -226,18 +235,38 @@ function BuildOutputFilePath() { | |
|
||
# ------------------------------------------------------------------------------ | ||
function RunSAM() { | ||
local -a Cmd=( 'samweb' "$@" ) | ||
local -a Cmd=( 'samweb' ${Experiment:+--experiment="$Experiment"} "$@" ) | ||
|
||
DBG "${Cmd[@]}" | ||
"${Cmd[@]}" | ||
|
||
} # RunSAM() | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
function getFileAccessURL() { | ||
local FileName="$1" | ||
local Schema="$2" | ||
local Location="$3" | ||
|
||
RunSAM get-file-access-url ${Schema:+"--schema=${Schema}"} ${Location:+"--location=${Location}"} "$FileName" | ||
|
||
} # getFileAccessURL() | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
function locateFile() { | ||
local FileName="$1" | ||
|
||
RunSAM locate-file "$FileName" | ||
|
||
} # locateFile() | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
declare -a Specs | ||
declare -i UseDefaultOutputFile=0 DoQuiet=0 | ||
declare OutputFile | ||
declare OutputFile Experiment | ||
declare Type="$DefaultType" | ||
declare Schema="$DefaultSchema" | ||
declare Location="$DefaultLocation" | ||
|
@@ -256,11 +285,13 @@ for (( iParam=1 ; iParam <= $# ; ++iParam )); do | |
|
||
( '--schema='* | '--scheme='* ) Schema="${Param#--*=}" ;; | ||
( '--xrootd' | '--XRootD' | '--root' | '--ROOT' | '-X' ) Schema="$XRootDschema" ;; | ||
( '--locate' ) Schema="$LocateSchema" ;; | ||
|
||
( '--loc='* | '--location='* ) Location="${Param#--*=}" ;; | ||
( '--dcache' | '--dCache' | '-C' ) Location="$dCacheLocation" ;; | ||
( '--tape' | '--enstore' | '-T' ) Location="$TapeLocation" ;; | ||
|
||
|
||
( '--stream='* ) Stream="${Param#--*=}" ;; | ||
( '--bnb' | '--BNB' ) Stream="$BNBstream" ;; | ||
( '--numi' | '--NuMI' | '--NUMI' ) Stream="$NuMIstream" ;; | ||
|
@@ -271,6 +302,7 @@ for (( iParam=1 ; iParam <= $# ; ++iParam )); do | |
( "--outputdir="* ) OutputDir="${Param#--*=}" ;; | ||
( "-O" ) UseDefaultOutputFile=1 ;; | ||
( "--max="* | "--limit="* ) EntryLimit="${Param#--*=}" ;; | ||
( "--experiment="* ) Experiment="${Param#--*=}" ;; | ||
|
||
( '--debug' ) DEBUG=1 ;; | ||
( '--debug='* ) DEBUG="${Param#--*=}" ;; | ||
|
@@ -379,7 +411,14 @@ for Spec in "${Specs[@]}" ; do | |
while read FileName ; do | ||
[[ "$EntryLimit" -gt 0 ]] && [[ $iFile -ge "$EntryLimit" ]] && INFO "Limit of ${EntryLimit} reached." && break | ||
INFO "[$((++iFile))/${nFiles}] '${FileName}'" | ||
FileURL=( $(RunSAM get-file-access-url ${Schema:+"--schema=${Schema}"} ${Location:+"--location=${Location}"} "$FileName") ) | ||
case "$Schema" in | ||
( "$LocateSchema" ) | ||
FileURL=( $(locateFile "$FileName" ) ) | ||
;; | ||
( * ) | ||
FileURL=( $(getFileAccessURL "$FileName" "$Schema" "$Location" ) ) | ||
;; | ||
esac | ||
LASTFATAL "getting file '${FileName}' location from SAM." | ||
[[ "${#FileURL[@]}" == 0 ]] && FATAL 2 "failed getting file '${FileName}' location from SAM." | ||
[[ "${#FileURL[@]}" -gt 1 ]] && WARN "File '${FileName}' matched ${#FileURL[@]} locations (only the first one included):$(printf -- "\n- '%s'" "${FileURL[@]}")" | ||
|