From 47d23931906af3f9e764c73ff948f0e81c1aedb6 Mon Sep 17 00:00:00 2001 From: Gianluca Petrillo Date: Fri, 26 Aug 2022 01:50:56 -0500 Subject: [PATCH] runFilesFromSAM.sh: added --locate and --experiment options --- scripts/runFilesFromSAM.sh | 49 ++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/scripts/runFilesFromSAM.sh b/scripts/runFilesFromSAM.sh index ea466458f..2fcddf140 100755 --- a/scripts/runFilesFromSAM.sh +++ b/scripts/runFilesFromSAM.sh @@ -8,6 +8,8 @@ # Date: March 2021 # # Changes: +# 20220720 (petrillo@slac.stanford.edu) [1.4] +# added --locate option # 20220406 (petrillo@slac.stanford.edu) [1.3] # --max option now only converts that many files # 20220126 (petrillo@slac.stanford.edu) [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,7 +235,7 @@ function BuildOutputFilePath() { # ------------------------------------------------------------------------------ function RunSAM() { - local -a Cmd=( 'samweb' "$@" ) + local -a Cmd=( 'samweb' ${Experiment:+--experiment="$Experiment"} "$@" ) DBG "${Cmd[@]}" "${Cmd[@]}" @@ -234,10 +243,30 @@ function RunSAM() { } # 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[@]}")"