forked from SUEPPhysics/TreeMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep2.sh
executable file
·122 lines (112 loc) · 3.02 KB
/
step2.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
#!/bin/bash
# helper function to structure the ouput into folders
structuredOutput() {
RES=""
TMP=${1/.//}
IFS='_' read -r -a array <<< "$TMP"
cut=$(expr ${#array[@]} - 2)
for index in "${!array[@]}"; do
if [[ $index -lt $cut ]]; then
if [[ $index -eq 0 ]]; then
RES=${RES}${array[index]}
else
RES=${RES}"_"${array[index]}
fi
elif [[ $index -eq $cut ]]; then
RES=${RES}"/"${array[index]}
else
RES=${RES}"_"${array[index]}
fi
done
echo ${RES}
}
export JOBNAME=""
export PROCESS=""
export OUTDIR=""
export REDIR=""
export OPTIND=1
export USE_FOLDERS="false"
while [[ $OPTIND -le $# ]]; do
# getopts in silent mode, don't exit on errors
getopts ":fj:p:o:x:" opt || status=$?
case "$opt" in
f) export USE_FOLDERS="true"
;;
j) export JOBNAME=$OPTARG
;;
p) export PROCESS=$OPTARG
;;
o) export OUTDIR=$OPTARG
;;
x) export REDIR=$OPTARG
;;
# keep going if getopts had an error
\? | :) OPTIND=$((OPTIND+1))
;;
esac
done
echo "parameter set:"
echo "OUTDIR: $OUTDIR"
echo "JOBNAME: $JOBNAME"
echo "PROCESS: $PROCESS"
echo "REDIR: $REDIR"
echo "USE_FOLDERS: $USE_FOLDERS"
echo ""
# link files from CMSSW dir
ln -s ${CMSSWVER}/src/TreeMaker/Production/test/data
ln -s ${CMSSWVER}/src/TreeMaker/Production/test/runMakeTreeFromMiniAOD_cfg.py
# run CMSSW
ARGS=$(cat args_${JOBNAME}_${PROCESS}.txt)
if [[ -n "$REDIR" ]]; then
ARGS="$ARGS redir=${REDIR}"
fi
THREADS=$(getFromClassAd RequestCpus)
if [[ -n "$THREADS" ]]; then
ARGS="$ARGS threads=${THREADS}"
fi
echo "cmsRun runMakeTreeFromMiniAOD_cfg.py ${ARGS} 2>&1"
cmsRun runMakeTreeFromMiniAOD_cfg.py ${ARGS} 2>&1
CMSEXIT=$?
rm runMakeTreeFromMiniAOD_cfg.py
if [[ $CMSEXIT -ne 0 ]]; then
rm *.root
echo "exit code $CMSEXIT, skipping xrdcp"
exit $CMSEXIT
fi
# copy output to eos
echo "CMSSITE currently set to: ${CMSSITE}"
if [[ -z "$CMSSITE" ]] || [[ "$CMSSITE" == "" ]]; then
echo -e "\tGetting CMSSITE from the job ClassAd"
CMSSITE=$(getFromClassAd MachineAttrGLIDEIN_CMSSite0)
echo -e "\tCMSSITE is now set to: ${CMSSITE}"
fi
export CMDSTR="xrdcp"
export GFLAG=""
if [[ ( "$CMSSITE" == *"T1_US_FNAL"* && "${OUTDIR}" == *"root://cmseos.fnal.gov/"* ) ]]; then
export CMDSTR="gfal-copy"
export GFLAG="-g"
export GSIFTP_ENDPOINT="gsiftp://cmseos-gridftp.fnal.gov//eos/uscms/store/user/"
export OUTDIR=${GSIFTP_ENDPOINT}${OUTDIR#root://cmseos.fnal.gov//store/user/}
elif [[ "${OUTDIR}" == *"gsiftp://"* ]]; then
export CMDSTR="gfal-copy"
export GFLAG="-g"
fi
echo "$CMDSTR output for condor"
for FILE in *.root; do
FILE_DST=${FILE}
if [[ "${USE_FOLDERS}" == "true" ]]; then
echo "Changing to folder structure consisting of <era>/<sample>/<filename>.root"
echo -e "\tPrior to change: ${FILE_DST}"
FILE_DST=`structuredOutput ${FILE_DST}`
echo -e "\t After change: ${FILE_DST}"
fi
echo "${CMDSTR} -f ${FILE} ${OUTDIR}/${FILE_DST}"
stageOut ${GFLAG} -x "-f" -i ${FILE} -o ${OUTDIR}/${FILE_DST}
XRDEXIT=$?
if [[ $XRDEXIT -ne 0 ]]; then
rm *.root
echo "exit code $XRDEXIT, failure in $CMDSTR"
exit $XRDEXIT
fi
rm ${FILE}
done