forked from fgolf/ProjectMetis
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcondor_cmssw_exe.sh
executable file
·240 lines (206 loc) · 8.03 KB
/
condor_cmssw_exe.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
OUTPUTDIR=$1
OUTPUTNAME=$2
INPUTFILENAMES=$3
IFILE=$4
PSET=$5
CMSSWVERSION=$6
SCRAMARCH=$7
NEVTS=$8
FIRSTEVT=$9
EXPECTEDNEVTS=${10}
OTHEROUTPUTS=${11}
PSETARGS="${@:12}" # since args can have spaces, we take 10th-->last argument as one
function getjobad {
grep -i "^$1" "$_CONDOR_JOB_AD" | cut -d= -f2- | xargs echo
}
# Make sure OUTPUTNAME doesn't have .root since we add it manually
OUTPUTNAME=$(echo $OUTPUTNAME | sed 's/\.root//')
echo -e "\n--- begin header output ---\n" # <----- section division
echo "OUTPUTDIR: $OUTPUTDIR"
echo "OUTPUTNAME: $OUTPUTNAME"
echo "INPUTFILENAMES: $INPUTFILENAMES"
echo "IFILE: $IFILE"
echo "PSET: $PSET"
echo "CMSSWVERSION: $CMSSWVERSION"
echo "SCRAMARCH: $SCRAMARCH"
echo "NEVTS: $NEVTS"
echo "EXPECTEDNEVTS: $EXPECTEDNEVTS"
echo "OTHEROUTPUTS: $OTHEROUTPUTS"
echo "PSETARGS: $PSETARGS"
# echo CLASSAD: $(cat "$_CONDOR_JOB_AD")
echo "GLIDEIN_CMSSite: $GLIDEIN_CMSSite"
echo "hostname: $(hostname)"
echo "uname -a: $(uname -a)"
echo "time: $(date +%s)"
echo "args: $@"
echo "tag: $(getjobad tag)"
echo "taskname: $(getjobad taskname)"
echo -e "\n--- end header output ---\n" # <----- section division
if [ -r "$OSGVO_CMSSW_Path"/cmsset_default.sh ]; then
echo "sourcing environment: source $OSGVO_CMSSW_Path/cmsset_default.sh"
source "$OSGVO_CMSSW_Path"/cmsset_default.sh
elif [ -r "$OSG_APP"/cmssoft/cms/cmsset_default.sh ]; then
echo "sourcing environment: source $OSG_APP/cmssoft/cms/cmsset_default.sh"
source "$OSG_APP"/cmssoft/cms/cmsset_default.sh
elif [ -r /cvmfs/cms.cern.ch/cmsset_default.sh ]; then
echo "sourcing environment: source /cvmfs/cms.cern.ch/cmsset_default.sh"
source /cvmfs/cms.cern.ch/cmsset_default.sh
else
echo "ERROR! Couldn't find $OSGVO_CMSSW_Path/cmsset_default.sh or /cvmfs/cms.cern.ch/cmsset_default.sh or $OSG_APP/cmssoft/cms/cmsset_default.sh"
exit 1
fi
export SCRAM_ARCH=${SCRAMARCH}
# holy crap this is a mess. :( why does PAT code have to do such insane
# things with paths?
# if the first file in the tarball filelist starts with CMSSW, then it is
# a tarball made outside of the full CMSSW directory, and must be handled
# differently
tarfile=package.tar.gz
if [ ! -z $(tar -tf ${tarfile} | head -n 1 | grep "^CMSSW") ]; then
echo "this is a full cmssw tar file"
tar xf ${tarfile}
cd $CMSSWVERSION
echo $PWD
echo "Running ProjectRename"
scramv1 b ProjectRename
echo "Running `scramv1 runtime -sh`"
eval `scramv1 runtime -sh`
mv ../$PSET pset.py
mv ../${tarfile} .
else
echo "this is a selective cmssw tar file"
eval `scramv1 project CMSSW $CMSSWVERSION`
cd $CMSSWVERSION
eval `scramv1 runtime -sh`
mv ../$PSET pset.py
if [ -e ../${tarfile} ]; then
mv ../${tarfile} ${tarfile};
tar xf ${tarfile};
fi
scram b
[ -e package.tar.gz ] && tar xf package.tar.gz
fi
# # logging every 45 seconds gives ~100kb log file/3 hours
# dstat -cdngytlmrs --float --nocolor -T --output dsout.csv 180 >& /dev/null &
echo "process.maxEvents.input = cms.untracked.int32(${NEVTS})" >> pset.py
echo "if hasattr(process,'externalLHEProducer'):" >> pset.py
echo " process.externalLHEProducer.nEvents = cms.untracked.uint32(${NEVTS})" >> pset.py
echo "set_output_name(\"${OUTPUTNAME}.root\")" >> pset.py
if [ "$INPUTFILENAMES" != "dummyfile" ]; then
echo "process.source.fileNames = cms.untracked.vstring([" >> pset.py
for INPUTFILENAME in $(echo "$INPUTFILENAMES" | sed -n 1'p' | tr ',' '\n'); do
INPUTFILENAME=$(echo $INPUTFILENAME | sed 's|^/hadoop/cms||')
# INPUTFILENAME="root://xrootd.unl.edu/${INPUTFILENAME}"
echo "\"${INPUTFILENAME}\"," >> pset.py
done
echo "])" >> pset.py
fi
if [ "$FIRSTEVT" -ge 0 ]; then
# events to skip, event number to assign to first event
echo "try:" >> pset.py
echo " if not 'Empty' in str(process.source): process.source.skipEvents = cms.untracked.uint32(max(${FIRSTEVT}-1,0))" >> pset.py
echo "except: pass" >> pset.py
echo "try:" >> pset.py
echo " process.source.firstEvent = cms.untracked.uint32(${FIRSTEVT})" >> pset.py
echo "except: pass" >> pset.py
fi
echo "before running: ls -lrth"
ls -lrth
echo -e "\n--- begin running ---\n" # <----- section division
cmsRun pset.py ${PSETARGS}
if [ "$?" != "0" ]; then
echo "Removing output file because cmsRun crashed with exit code $?"
rm ${OUTPUTNAME}.root
exit 1
fi
if [ -z "$(getjobad metis_dontchecktree)" ]; then
# Add some metadata
# Right now, total/negative event counts, but obviously extensible
python << EOL
import ROOT as r
fin = r.TFile("${OUTPUTNAME}.root","update")
t = fin.Get("Events")
t.GetUserInfo().Clear()
nevts = t.GetEntries()
nevts_neg = nevts - t.GetEntries("genps_weight > 0")
evts = r.TParameter(int)("nevts", nevts)
evts_neg = r.TParameter(int)("nevts_neg", nevts_neg)
print "Writing metadata. Nevents = {0} ({1} negative)".format(nevts, nevts_neg)
t.GetUserInfo().Add(evts)
t.GetUserInfo().Add(evts_neg)
t.Write("",r.TObject.kOverwrite)
t.GetUserInfo().Print()
EOL
# Rigorous sweeproot which checks ALL branches for ALL events.
# If GetEntry() returns -1, then there was an I/O problem, so we will delete it
# Special consideration to ignore stupid CMSSW errors and old root versions
python << EOL
import ROOT as r
import os
import traceback
foundBad = False
try:
f1 = r.TFile("${OUTPUTNAME}.root")
t = f1.Get("Events")
nevts = t.GetEntries()
expectednevts = ${EXPECTEDNEVTS}
print "[RSR] ntuple has %i events and expected %i" % (t.GetEntries(), expectednevts)
if int(expectednevts) > 0 and int(t.GetEntries()) != int(expectednevts):
print "[RSR] nevents mismatch"
foundBad = True
if not "root/5.3" in r.__file__:
for i in range(0,t.GetEntries(),1):
if t.GetEntry(i) < 0:
foundBad = True
print "[RSR] found bad event %i" % i
break
except Exception as ex:
msg = traceback.format_exc()
if "EDProductGetter" not in msg:
foundBad = True
if foundBad:
print "[RSR] removing output file because it does not deserve to live"
os.system("rm ${OUTPUTNAME}.root")
else: print "[RSR] passed the rigorous sweeproot"
EOL
else
echo "Not checking tree or adding metadata";
fi
echo -e "\n--- end running ---\n" # <----- section division
echo "after running: ls -lrth"
ls -lrth
echo -e "\n--- begin copying output ---\n" # <----- section division
echo "Sending output file $OUTPUTNAME.root"
if [ ! -e "$OUTPUTNAME.root" ]; then
echo "ERROR! Output $OUTPUTNAME.root doesn't exist"
exit 1
fi
COPY_SRC="file://`pwd`/${OUTPUTNAME}.root"
COPY_DEST="gsiftp://gftp.t2.ucsd.edu${OUTPUTDIR}/${OUTPUTNAME}_${IFILE}.root"
echo "Running: env -i X509_USER_PROXY=${X509_USER_PROXY} gfal-copy -p -f -t 4200 --verbose --checksum ADLER32 ${COPY_SRC} ${COPY_DEST}"
env -i X509_USER_PROXY=${X509_USER_PROXY} gfal-copy -p -f -t 4200 --verbose --checksum ADLER32 ${COPY_SRC} ${COPY_DEST}
COPY_STATUS=$?
if [[ $COPY_STATUS != 0 ]]; then
echo "Removing output file because gfal-copy crashed with code $COPY_STATUS"
env -i X509_USER_PROXY=${X509_USER_PROXY} gfal-rm --verbose ${COPY_DEST}
REMOVE_STATUS=$?
if [[ $REMOVE_STATUS != 0 ]]; then
echo "Uhh, gfal-copy crashed and then the gfal-rm also crashed with code $REMOVE_STATUS"
exit 1
fi
fi
for OTHEROUTPUT in $(echo "$OTHEROUTPUTS" | sed -n 1'p' | tr ',' '\n'); do
[ -e ${OTHEROUTPUT} ] && {
NOROOT=$(echo $OTHEROUTPUT | sed 's/\.root//')
gfal-copy -p -f -t 4200 --verbose file://`pwd`/${NOROOT}.root gsiftp://gftp.t2.ucsd.edu${OUTPUTDIR}/${NOROOT}_${IFILE}.root --checksum ADLER32
}
done
echo -e "\n--- end copying output ---\n" # <----- section division
echo -e "\n--- begin dstat output ---\n" # <----- section division
# cat dsout.csv
echo -e "\n--- end dstat output ---\n" # <----- section division
# kill %1 # kill dstat
# cd ../
# echo "cleaning up"
# rm -rf CMSSW*