forked from kmcdermo/TkRelVal
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetFiles.sh
More file actions
executable file
·80 lines (67 loc) · 2.55 KB
/
getFiles.sh
File metadata and controls
executable file
·80 lines (67 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
######################################
# Script to download ROOT files from CMS DQM RelValData repository based on specified criteria.
# Usage: ./getFiles.sh <web_dir> <run> <rel> <sample> [add_key] [optional_arg]
# Example: ./getFiles.sh CMSSW_16_0_x 392294 pre1 ZeroBias
# notes:
# - This script is designed to download ROOT files from the CMS DQM RelValData repository based
# on specified criteria such as run number, sample type, and release version.
# - Uses `curl` to fetch the directory listing and filter files using `grep` and `sed`. Wget is not used directly due to the need for authentication and handling of the file list.
# - Future alternatives: files do live in /eos/cms/store/relval/ but it's a bit more complicated to get them.
######################################
# -----------------------------
# Arguments
# -----------------------------
web_dir=${1} # es: CMSSW_16_0_x
run=${2} # es: 392294
rel=${3} # es: pre1
sample=${4} # es: ZeroBias
add_key=${5:-.*}
optional_arg=${6:-.*}
## check certificate and proxy
if ! voms-proxy-info -exists; then
echo "No valid proxy found. Please create a proxy using 'voms-proxy-init command before running this script."
exit 1
fi
export X509_USER_PROXY=$(voms-proxy-info -path)
BASE="https://cmsweb.cern.ch/dqm/relval/data/browse/ROOT/RelValData/${web_dir}/"
echo "Getting sample: $sample"
echo "From: $BASE"
PATTERN="${run}.*${sample}.*${rel}.*${add_key}.*${optional_arg}.*root"
# -----------------------------
# Download files
# -----------------------------
curl -s --insecure \
--cert "$X509_USER_PROXY" \
--key "$X509_USER_PROXY" \
"$BASE" \
| grep -oE "href=['\"][^'\"]+\.root['\"]" \
| sed -E "s/href=['\"]//;s/['\"]$//" \
| grep -E "$PATTERN" \
| xargs -r -I{} -P 6 bash -c '
echo "Downloading https://cmsweb.cern.ch{}"
curl -L --insecure \
--cert "'"$X509_USER_PROXY"'" \
--key "'"$X509_USER_PROXY"'" \
-O "https://cmsweb.cern.ch{}"
sleep 1
'
# -----------------------------
# File organization
# -----------------------------
if [ "$sample" == "Cosmics" ] ; then
if ls *${sample}*.root >/dev/null 2>&1; then
mkdir -p cosmics
mv *${sample}*.root cosmics/
else
echo "File not found for sample: $sample"
fi
else
if ls *${run}*${sample}*.root >/dev/null 2>&1; then
TARGET="DQM/${web_dir}/${rel}/${run}/${sample}"
mkdir -p "$TARGET"
mv -f *${run}*${sample}*.root "$TARGET"/ 2>/dev/null
else
echo "File not found for sample: $sample"
fi
fi