forked from AliceO2Group/Run3AnalysisValidation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtest.sh
223 lines (189 loc) · 10 KB
/
runtest.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
#!/bin/bash
# shellcheck disable=SC1090,SC1091,SC2034 # Ignore non-constant source, not following, unused triggers and DIR_TASKS.
# Steering script to run Run 2 to Run 3 conversion, AliPhysics tasks, O2 tasks, and postprocessing
####################################################################################################
# Declarations of global parameters and their default values
# Main directories
DIR_EXEC="$(dirname "$(realpath "$0")")" # Directory of this script (and other execution code)
DIR_TASKS="$PWD" # Directory with task configuration
# Configuration scripts
CONFIG_INPUT="config_input.sh" # Input specification (Modifies input parameters.)
CONFIG_TASKS="config_tasks.sh" # Task configuration (Cleans directory, modifies step activation, modifies JSON and generates step scripts via functions Clean, AdjustJson, MakeScriptAli, MakeScriptO2, MakeScriptPostprocess.)
# Steps
DOCLEAN=1 # Delete created files (before and after running tasks).
DOCONVERT=1 # Convert AliESDs.root to AO2D.root.
DOALI=1 # Run AliPhysics tasks.
DOO2=1 # Run O2 tasks.
DOPOSTPROCESS=1 # Run output postprocessing. (Compare AliPhysics and O2 output.)
# Input parameters
INPUT_CASE=-1 # Input case
INPUT_LABEL="nothing" # Input description
INPUT_DIR="$PWD" # Input directory
INPUT_FILES="AliESDs.root" # Input file pattern
INPUT_SYS="pp" # Collision system ("pp", "PbPb")
INPUT_RUN=2 # LHC Run (2, 3, 5)
INPUT_IS_O2=0 # Input files are in O2 format.
INPUT_IS_MC=0 # Input files are MC data.
INPUT_PARENT_MASK="" # Path replacement mask for the input directory of parent files in case of linked derived O2 input. Set to ";" if no replacement needed.
INPUT_TASK_CONFIG="" # Input-specific task configuration (e.g. enabling converters), overriding the task configuration in CONFIG_TASKS. String of space-separated commands.
JSON="dpl-config.json" # O2 device configuration
# Processing
NFILESMAX=1 # Maximum number of processed input files. (Set to -0 to process all; to -N to process all but the last N files.)
NFILESPERJOB_CONVERT=1 # Number of input files per conversion job
NFILESPERJOB_ALI=1 # Number of input files per AliPhysics job
NFILESPERJOB_O2=1 # Number of input files per O2 job
# Performance
NCORES=$(nproc) # Ideal number of used cores
NCORESPERJOB_ALI=1 # Average number of cores used by one AliPhysics job
NCORESPERJOB_O2=1.6 # Average number of cores used by one O2 job
NJOBSPARALLEL_O2=$(nproc) # Maximum number of simultaneously running O2 jobs
# Other options
SAVETREES=0 # Save O2 tables to trees.
DEBUG=0 # Print out more information.
USEALIEVCUTS=0 # Use AliEventCuts in AliPhysics (as used by conversion task)
# Lists of input files
LISTFILES_ALI="list_ali.txt" # conversion and AliPhysics input
LISTFILES_O2="list_o2.txt" # O2 input
# Output files
FILEOUT="AnalysisResults.root"
FILEOUT_ALI="AnalysisResults_ALI.root"
FILEOUT_O2="AnalysisResults_O2.root"
FILEOUT_TREES="AnalysisResults_trees.root"
FILEOUT_TREES_O2="AnalysisResults_trees_O2.root"
# Steering commands (loading aliBuild environments)
ENV_ALI="alienv setenv AliPhysics/latest -c"
ENV_O2="alienv setenv O2Physics/latest -c"
ENV_POST="alienv setenv ROOT/latest -c"
# Step scripts
SCRIPT_O2="script_o2.sh"
SCRIPT_ALI="script_ali.sh"
SCRIPT_POSTPROCESS="script_postprocess.sh"
# End of declarations of global parameters and their default values
####################################################################################################
# Load utilities.
source "$DIR_EXEC/utilities.sh" || { echo "Error: Failed to load utilities."; exit 1; }
# Parse command line options.
function Help { echo "Usage: bash [<path>/]$(basename "$0") [-h] [-i <input config>] [-t <task config>] [-d]"; }
while getopts ":hi:t:d" opt; do
case ${opt} in
h)
Help; exit 0;;
i)
CONFIG_INPUT="$OPTARG";;
t)
CONFIG_TASKS="$OPTARG";;
d)
DEBUG=1;;
\?)
MsgErr "Invalid option: $OPTARG" 1>&2; Help; exit 1;;
:)
MsgErr "Invalid option: $OPTARG requires an argument." 1>&2; Help; exit 1;;
esac
done
# Load input specification.
source "$CONFIG_INPUT" || ErrExit "Failed to load input specification."
# Load task configuration.
source "$CONFIG_TASKS" || ErrExit "Failed to load tasks configuration."
DIR_TASKS="$(dirname "$(realpath "$CONFIG_TASKS")")"
########## END OF CONFIGURATION ##########
####################################################################################################
########## START OF EXECUTION ##########
[ $DEBUG -eq 1 ] && { echo "$0"; echo "Input specification: $CONFIG_INPUT"; echo "Tasks configuration: $CONFIG_TASKS"; }
# Print out input description.
MsgStep "Processing case $INPUT_CASE: $INPUT_LABEL"
# Adjust task configuration with input-specific configuration.
if [ "$INPUT_TASK_CONFIG" ]; then
for cmd in $INPUT_TASK_CONFIG; do
MsgWarn "Evaluating $cmd"
eval "$cmd"
done
fi
# Clean before running.
if [ $DOCLEAN -eq 1 ]; then
MsgStep "Cleaning..."
Clean 1 || ErrExit "Clean failed."
fi
# Generate list of input files.
MsgStep "Generating list of input files..."
[ $INPUT_IS_O2 -eq 1 ] && LISTFILES="$LISTFILES_O2" || LISTFILES="$LISTFILES_ALI"
INPUT_DIR="$(realpath "$INPUT_DIR")"
[ $DEBUG -eq 1 ] && { echo "Searching for $INPUT_FILES in $INPUT_DIR"; }
find "$INPUT_DIR" -name "$INPUT_FILES" | sort | head -n $NFILESMAX > "$LISTFILES"
[[ ${PIPESTATUS[0]} -eq 0 || ${PIPESTATUS[0]} -eq 141 ]] || ErrExit "Failed to make a list of input files."
[ "$(wc -l < "$LISTFILES")" -eq 0 ] && { ErrExit "No input files!"; }
# Modify the JSON file.
MsgStep "Modifying JSON file..."
CheckFile "$JSON"
AdjustJson || ErrExit "AdjustJson failed."
CheckFile "$JSON"
# Convert AliESDs.root to AO2D.root.
if [ $DOCONVERT -eq 1 ]; then
CheckFile "$LISTFILES_ALI"
NFILES=$(wc -l < "$LISTFILES_ALI")
[ "$NFILES" -eq 0 ] && { ErrExit "No input conversion files!"; }
NFILESPERJOB_CONVERT=$(python3 -c "n = $NFILESPERJOB_CONVERT; print(n if n > 0 else max(1, round($NFILES * $NCORESPERJOB_ALI / $NCORES)))")
MsgStep "Converting... ($NFILES files)"
[ $INPUT_IS_MC -eq 1 ] && MsgWarn "Using MC mode"
[ $DEBUG -eq 1 ] && echo "Loading AliPhysics..."
# Run the batch script in the ALI environment.
[ "$O2_ROOT" ] && { MsgWarn "O2 environment is loaded - expect errors!"; }
[ "$ALICE_PHYSICS" ] && { MsgWarn "AliPhysics environment is already loaded."; ENV_ALI=""; }
$ENV_ALI bash "$DIR_EXEC/batch_convert.sh" "$LISTFILES_ALI" "$LISTFILES_O2" $INPUT_IS_MC $USEALIEVCUTS $DEBUG "$NFILESPERJOB_CONVERT" || exit 1
fi
# Run AliPhysics tasks.
if [ $DOALI -eq 1 ]; then
CheckFile "$LISTFILES_ALI"
NFILES=$(wc -l < "$LISTFILES_ALI")
[ "$NFILES" -eq 0 ] && { ErrExit "No input AliPhysics files!"; }
NFILESPERJOB_ALI=$(python3 -c "n = $NFILESPERJOB_ALI; print(n if n > 0 else max(1, round($NFILES * $NCORESPERJOB_ALI / $NCORES)))")
MsgStep "Running AliPhysics tasks... ($NFILES files)"
rm -f "$FILEOUT" "$FILEOUT_ALI" || ErrExit "Failed to rm $FILEOUT $FILEOUT_ALI."
MakeScriptAli || ErrExit "MakeScriptAli failed."
CheckFile "$SCRIPT_ALI"
[ $DEBUG -eq 1 ] && echo "Loading AliPhysics..."
# Run the batch script in the ALI environment.
[ "$O2_ROOT" ] && { MsgWarn "O2 environment is loaded - expect errors!"; }
[ "$ALICE_PHYSICS" ] && { MsgWarn "AliPhysics environment is already loaded."; ENV_ALI=""; }
$ENV_ALI bash "$DIR_EXEC/batch_ali.sh" "$LISTFILES_ALI" "$JSON" "$SCRIPT_ALI" $DEBUG "$NFILESPERJOB_ALI" || exit 1
mv "$FILEOUT" "$FILEOUT_ALI" || ErrExit "Failed to mv $FILEOUT $FILEOUT_ALI."
fi
# Run O2 tasks.
if [ $DOO2 -eq 1 ]; then
CheckFile "$LISTFILES_O2"
NFILES=$(wc -l < "$LISTFILES_O2")
[ "$NFILES" -eq 0 ] && { ErrExit "No input O2 files!"; }
NFILESPERJOB_O2=$(python3 -c "n = $NFILESPERJOB_O2; print(n if n > 0 else min(16, max(1, round($NFILES * $NCORESPERJOB_O2 / $NCORES))))") # FIXME: Jobs with more than 16 files per job lose data.
MsgStep "Running O2 tasks... ($NFILES files)"
rm -f "$FILEOUT" "$FILEOUT_O2" || ErrExit "Failed to rm $FILEOUT $FILEOUT_O2."
MakeScriptO2 || ErrExit "MakeScriptO2 failed."
CheckFile "$SCRIPT_O2"
[ $SAVETREES -eq 1 ] || FILEOUT_TREES=""
[ $DEBUG -eq 1 ] && echo "Loading O2Physics..."
# Run the batch script in the O2 environment.
[ "$ALICE_PHYSICS" ] && { MsgWarn "AliPhysics environment is loaded - expect errors!"; }
[ "$O2_ROOT" ] && { MsgWarn "O2 environment is already loaded."; ENV_O2=""; }
$ENV_O2 bash "$DIR_EXEC/batch_o2.sh" "$LISTFILES_O2" "$JSON" "$SCRIPT_O2" $DEBUG "$NFILESPERJOB_O2" "$FILEOUT_TREES" "$NJOBSPARALLEL_O2" || exit 1
mv "$FILEOUT" "$FILEOUT_O2" || ErrExit "Failed to mv $FILEOUT $FILEOUT_O2."
[[ $SAVETREES -eq 1 && "$FILEOUT_TREES" ]] && { mv "$FILEOUT_TREES" "$FILEOUT_TREES_O2" || ErrExit "Failed to mv $FILEOUT_TREES $FILEOUT_TREES_O2."; }
fi
# Run output postprocessing. (Compare AliPhysics and O2 output.)
if [ $DOPOSTPROCESS -eq 1 ]; then
LogFile="log_postprocess.log"
MsgStep "Postprocessing... (logfile: $LogFile)"
MakeScriptPostprocess || ErrExit "MakeScriptPostprocess failed."
CheckFile "$SCRIPT_POSTPROCESS"
[ $DEBUG -eq 1 ] && echo "Loading ROOT..."
# Run the batch script in the postprocessing environment.
[ "$ROOTSYS" ] && { MsgWarn "ROOT environment is already loaded."; ENV_POST=""; }
$ENV_POST bash "$SCRIPT_POSTPROCESS" "$FILEOUT_O2" "$FILEOUT_ALI" > $LogFile 2>&1 || ErrExit "\nCheck $(realpath $LogFile)"
grep -q -e '^'"W-" -e '^'"Warning" -e "warning" "$LogFile" && MsgWarn "There were warnings!\nCheck $(realpath $LogFile)"
grep -q -e '^'"E-" -e '^'"Error" "$LogFile" && MsgErr "There were errors!\nCheck $(realpath $LogFile)"
grep -q -e '^'"F-" -e '^'"Fatal" -e "segmentation" -e "Segmentation" "$LogFile" && ErrExit "There were fatal errors!\nCheck $(realpath $LogFile)"
fi
# Clean after running.
if [ $DOCLEAN -eq 1 ]; then
MsgStep "Cleaning..."
Clean 2 || ErrExit "Clean failed."
fi
MsgStep "Done"
exit 0