-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateLocalRuns.sh
executable file
·135 lines (122 loc) · 3.9 KB
/
updateLocalRuns.sh
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash -e
#
# updatePedRuns.sh:
# This script will check if there are new pedestal runs and update the database if necessary.
# A CMSSW environment should be already set up before running.
# Input:
# - $1: working directory
# - $2: log file
#
# Input section
WORK_DIR="$1"
LOG_FILE="$2"
# Move to script location
cd "${WORK_DIR}"
# Initiate logging - if log file larger than 1 MB then recreate
export SCRIPT_LOG="${LOG_FILE}"
if [ -f "${SCRIPT_LOG}" ]; then
LOG_SIZE="$(stat --printf='%s' "${SCRIPT_LOG}")"
if [ "${LOG_SIZE}" -gt 1000000 ]; then
rm "${SCRIPT_LOG}"
fi
touch "${SCRIPT_LOG}"
else
touch "${SCRIPT_LOG}"
fi
SCRIPTENTRY
INFO "Setting working directory: ${WORK_DIR}"
# Initial setup
localRunsDir=/data/hcaldqm/DQMIO/LOCAL
sqlQueryFile=${WORK_DIR}/scripts/query.sql
referenceFile=${WORK_DIR}/data/localRuns_uploaded.dat
outputFile=${WORK_DIR}/data/localRunsForUpload.dat
parameterFile=${WORK_DIR}/DBUtils/localRuns.par
ctlFile=${WORK_DIR}/DBUtils/localRuns.ctl
logFile=${WORK_DIR}/DBUtils/localRuns.log
badFile=${WORK_DIR}/DBUtils/localRuns.bad
dbgOn="false"
# Help statement
usage(){
EXITUSAGE=$1
echo -e "updateLocalRuns.sh [options]\n"
echo "-d dry run option for testing. Runs the code without uploading to DB."
echo "-h display this message."
SCRIPTEXIT
exit "$EXITUSAGE"
}
# Process options
while getopts "dh" opt; do
case "$opt" in
d) dbgOn="true"
;;
h | *)
usage 0
;;
esac
done
# Compare current list of runs with list of uploaded runs
localRunsList=( "${localRunsDir}"/DQM_V0001_R0003[0-9][0-9][0-9][0-9][0-9]__*__DQMIO.root )
# Run comm and keep only first column that contains new runs
readarray -t missingRuns < <(
comm -23 <(printf "%s\n" "${localRunsList[@]}") <(sort "${referenceFile}")
)
if [[ ${#missingRuns[@]} -eq 0 ]]; then
INFO "Nothing to update this time! Exiting..."
SCRIPTEXIT
return
else
INFO "Will process ${#missingRuns[@]} run(s)."
fi
# Process runs
if [ -f "${outputFile}" ]; then
rm "${outputFile}"
fi
for run in "${missingRuns[@]}"; do
# Do something with the runs
runNumber="${run//${localRunsDir}\/DQM_V0001_R000/}"
runNumber="${runNumber:0:6}"
queryResult="$(
sqlplus64 -S "${DB_CMS_RCMS_USR}"/"${DB_CMS_RCMS_PWD}"@cms_rcms \
@"${sqlQueryFile}" "${runNumber}"
)"
rsltLineNum="$(echo -n "${queryResult}" | grep -c '^')"
queryResult="$(echo "${queryResult}" | tr '\n' '\t')"
if [ "${rsltLineNum}" = 1 ]; then
# This is result of the old type (pre run 3)
echo -e "${runNumber}\t${queryResult}\t''" >> "${outputFile}"
elif [ "${rsltLineNum}" = 2 ]; then
# This is result of the new type (circa run 3)
queryResult="$(
echo -e "${queryResult}" | sed "s|CEST|Europe/Zurich|g" | sed "s|CET|Europe/Zurich|g"
)"
echo -e "${runNumber}\t${queryResult}" >> "${outputFile}"
fi
done
# Upload them to the database and update the list of uploaded runs
# If debugging is on then just print out the command and the new runs
if [ "$dbgOn" = "false" ]; then
# Generate .par file
if [ -f "${parameterFile}" ]; then
rm "${parameterFile}"
fi
{
echo "userid=${DB_INT2R_USR}/${DB_INT2R_PWD}@int2r"
echo "control=${ctlFile}"
echo "log=${logFile}"
echo "bad=${badFile}"
echo "data=${outputFile}"
echo "direct=true"
} >> "${parameterFile}"
# Upload them to the database
DB_LOG_FILE="${LOG_DIR}/dbuploader.log"
python3 scripts/dbuploader.py -f "${outputFile}" -p "${parameterFile}" -l "${DB_LOG_FILE}"
# Update list of uploaded runs
for run in "${missingRuns[@]}"; do
echo "${run}" >> "${referenceFile}"
done
else
DEBUG "python3 scripts/dbuploader.py -f ${outputFile} -p ${parameterFile}"
DEBUG "new runs to be added:"
DEBUG "${missingRuns[@]}"
fi
SCRIPTEXIT