Skip to content

Commit

Permalink
runFilesFromSAM.sh: added --locate and --experiment options
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrilloAtWork committed Aug 26, 2022
1 parent 6f25e95 commit 47d2393
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions scripts/runFilesFromSAM.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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"
Expand All @@ -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" ;;
Expand All @@ -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#--*=}" ;;
Expand Down Expand Up @@ -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[@]}")"
Expand Down

0 comments on commit 47d2393

Please sign in to comment.