forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim_challenge.sh
More file actions
executable file
·238 lines (192 loc) · 7.02 KB
/
Copy pathsim_challenge.sh
File metadata and controls
executable file
·238 lines (192 loc) · 7.02 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
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
#!/bin/bash
# chain of algorithms from MC and reco
# ----------- START WITH UTILITY FUNCTIONS ----------------------------
child_pid_list=
# finds out all the (recursive) child process starting from a parent
# output includes the parent
# output is saved in child_pid_list
childprocs() {
local parent=$1
if [ "$parent" ] ; then
child_pid_list="$child_pid_list $parent"
for childpid in $(pgrep -P ${parent}); do
childprocs $childpid
done;
fi
}
# accumulate return codes
RC_ACUM=0
taskwrapper() {
# A simple task wrapper launching a DPL workflow in the background
# and checking the output for exceptions. If exceptions are found,
# all participating processes will be sent a termination signal.
# The rational behind this function is to be able to determine failing
# conditions early and prevent longtime hanging executables
# (until DPL offers signal handling and automatic shutdown)
local logfile=$1
shift 1
local command="$*"
# launch the actual command in the background
echo "Launching task: ${command} &> $logfile &"
command="TIME=\"#walltime %e\" ${O2_ROOT}/share/scripts/monitor-mem.sh /usr/bin/time --output=${logfile}_time '${command}'"
eval ${command} &> $logfile &
# THE NEXT PART IS THE SUPERVISION PART
# get the PID
PID=$!
while [ 1 ]; do
# We don't like to see critical problems in the log file.
# We need to grep on multitude of things:
# - all sorts of exceptions (may need to fine-tune)
# - segmentation violation
# - there was a crash
pattern="-e \"xception\" \
-e \"segmentation violation\" \
-e \"error while setting up workflow\" \
-e \"There was a crash.\""
grepcommand="grep -H ${pattern} $logfile >> encountered_exceptions_list 2>/dev/null"
eval ${grepcommand}
grepcommand="grep -h --count ${pattern} $logfile 2>/dev/null"
# using eval here since otherwise the pattern is translated to a
# a weirdly quoted stringlist
RC=$(eval ${grepcommand})
# if we see an exception we will bring down the DPL workflow
# after having given it some chance to shut-down itself
# basically --> send kill to all children
if [ "$RC" != "" -a "$RC" != "0" ]; then
echo "Detected critical problem in logfile $logfile"
sleep 2
# query processes still alive
child_pid_list=
childprocs ${PID}
for p in $child_pid_list; do
echo "killing child $p"
kill $p
done
RC_ACUM=$((RC_ACUM+1))
return 1
fi
# check if command returned which may bring us out of the loop
ps -p $PID > /dev/null
[ $? == 1 ] && break
# sleep for some time
sleep 5
done
# wait for PID and fetch return code
# ?? should directly exit here?
wait $PID
# return code
RC=$?
RC_ACUM=$((RC_ACUM+RC))
[ ! "${RC} -eq 0" ] && echo "command ${command} had nonzero exit code ${RC}"
return ${RC}
}
# ----------- START WITH ACTUAL SCRIPT ----------------------------
# default number of events
nevPP=10
nevPbPb=10
# default interaction rates in kHz
intRatePP=400
intRatePbPb=50
# default collision system
collSyst="pp"
generPP="pythia8"
generPbPb="pythia8hi"
# default sim engine
engine="TGeant3"
# options to pass to every workflow
gloOpt=" -b --run "
Usage()
{
echo "Usage: ${0##*/} [-s system /pp[Def] or pbpb/] [-r IR(kHz) /Def = $intRatePP(pp)/$intRatePbPb(pbpb)] [-n Number of events /Def = $nevPP(pp) or $nevPbPb(pbpb)/] [-e TGeant3|TGeant4] [-f fromstage sim|digi|reco /Def = sim]"
exit
}
fromstage="sim"
while [ $# -gt 0 ] ; do
case $1 in
-n) nev=$2; shift 2 ;;
-s) collSyst=$2; shift 2 ;;
-r) intRate=$2; shift 2 ;;
-e) engine=$2; shift 2 ;;
-f) fromstage=$2; shift 2 ;;
-h) Usage ;;
*) echo "Wrong input"; Usage;
esac
done
collSyst="${collSyst,,}" # convert to lower case
if [ "$collSyst" == "pp" ]; then
gener="$generPP"
[[ "nev" -lt "1" ]] && nev="$nevPP"
[[ "intRate" -lt "1" ]] && intRate="$intRatePP"
elif [ "$collSyst" == "pbpb" ]; then
gener="$generPbPb"
[[ "nev" -lt "1" ]] && nev="$nevPbPb"
[[ "intRate" -lt "1" ]] && intRate="$intRatePbPb"
else
echo "Wrong collision system $collSyst provided, should be pp or pbpb"
Usage
fi
dosim="0"
dodigi="0"
doreco="0"
fromstage="${fromstage,,}"
if [ "$fromstage" == "sim" ]; then
dosim="1"
dodigi="1"
doreco="1"
elif [ "$fromstage" == "digi" ]; then
dodigi="1"
doreco="1"
elif [ "$fromstage" == "reco" ]; then
doreco="1"
else
echo "Wrong stage string $fromstage provided, should be sim or digi or reco"
Usage
fi
if [ "$dosim" == "1" ]; then
#---------------------------------------------------
echo "Running simulation for $nev $collSyst events with $gener generator and engine $engine"
taskwrapper sim.log o2-sim -n"$nev" --configKeyValue "Diamond.width[2]=6." -g "$gener" -e "$engine"
##------ extract number of hits
root -q -b -l ${O2_ROOT}/share/macro/analyzeHits.C > hitstats.log
fi
if [ "$dodigi" == "1" ]; then
echo "Running digitization for $intRate kHz interaction rate"
intRate=$((1000*(intRate)));
taskwrapper digi.log o2-sim-digitizer-workflow $gloOpt --interactionRate $intRate
echo "Return status of digitization: $?"
# existing checks
#root -b -q O2/Detectors/ITSMFT/ITS/macros/test/CheckDigits.C+
fi
if [ "$doreco" == "1" ]; then
echo "Running TPC reco flow"
#needs TPC digitized data
taskwrapper tpcreco.log o2-tpc-reco-workflow $gloOpt --tpc-digit-reader \"--infile tpcdigits.root\" --input-type digits --output-type clusters,tracks --tpc-track-writer \"--treename events --track-branch-name Tracks --trackmc-branch-name TracksMCTruth\"
echo "Return status of tpcreco: $?"
echo "Running ITS reco flow"
taskwrapper itsreco.log o2-its-reco-workflow $gloOpt
echo "Return status of itsreco: $?"
# existing checks
# root -b -q O2/Detectors/ITSMFT/ITS/macros/test/CheckClusters.C+
# root -b -q O2/Detectors/ITSMFT/ITS/macros/test/CheckTracks.C+
echo "Running MFT reco flow"
#needs MFT digitized data
taskwrapper mftreco.log o2-mft-reco-workflow $gloOpt
echo "Return status of mftreco: $?"
echo "Running FIT(FT0) reco flow"
#needs FIT digitized data
taskwrapper fitreco.log o2-fit-reco-workflow $gloOpt
echo "Return status of fitreco: $?"
echo "Running ITS-TPC macthing flow"
#needs results of o2-tpc-reco-workflow, o2-its-reco-workflow and o2-fit-reco-workflow
taskwrapper itstpcMatch.log o2-tpcits-match-workflow $gloOpt --tpc-track-reader \"tpctracks.root\" --tpc-native-cluster-reader \"--infile tpc-native-clusters.root\"
echo "Return status of itstpcMatch: $?"
echo "Running ITSTPC-TOF macthing flow"
#needs results of TOF digitized data and results of o2-tpcits-match-workflow
taskwrapper tofMatch.log o2-tof-reco-workflow $gloOpt
echo "Return status of its-tpc-tof match: $?"
echo "Running TOF matching QA"
#need results of ITSTPC-TOF matching (+ TOF clusters and ITS-TPC tracks)
root -b -q -l $O2_ROOT/share/macro/checkTOFMatching.C 1>tofmatch_qa.log 2>&1
echo "Return status of TOF matching qa: $?"
fi
exit ${RC_ACUM}