-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathbatch_convert.sh
More file actions
64 lines (53 loc) · 2.25 KB
/
batch_convert.sh
File metadata and controls
64 lines (53 loc) · 2.25 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
#!/bin/bash
# Script to run Run 2 to Run 3 conversion in jobs
LISTINPUT="$1"
LISTOUTPUT="$2"
INPUT_IS_MC=$3
USEALIEVCUTS=$4
DEBUG=$5
NFILESPERJOB=$6
FILEOUT="AO2D.root"
[ "$DEBUG" -eq 1 ] && echo "Running $0"
# This directory
DIR_THIS="$(dirname "$(realpath "$0")")"
# Load utilities.
# shellcheck disable=SC1091 # Ignore not following.
source "$DIR_THIS/utilities.sh" || { echo "Error: Failed to load utilities."; exit 1; }
LogFile="log_convert.log"
ListIn="list_convert.txt"
IndexFile=0
IndexJob=0
DirOutMain="output_conversion"
CMDPARALLEL="cd \"$DirOutMain/{}\" && bash \"$DIR_THIS/run_convert.sh\" \"$ListIn\" $INPUT_IS_MC $USEALIEVCUTS \"$LogFile\""
# Clean before running.
rm -rf "$LISTOUTPUT" "$DirOutMain" || ErrExit "Failed to delete output files."
CheckFile "$LISTINPUT"
echo "Output directory: $DirOutMain (logfiles: $LogFile)"
# Loop over input files
while read -r FileIn; do
CheckFile "$FileIn"
FileIn="$(realpath "$FileIn")"
IndexJob=$((IndexFile / NFILESPERJOB))
DirOut="$DirOutMain/$IndexJob"
# New job
if [ $((IndexFile % NFILESPERJOB)) -eq 0 ]; then
mkdir -p $DirOut || ErrExit "Failed to mkdir $DirOut."
echo "$DirOut/$FILEOUT" >> "$LISTOUTPUT" || ErrExit "Failed to echo to $LISTOUTPUT."
fi
echo "$FileIn" >> "$DirOut/$ListIn" || ErrExit "Failed to echo to $DirOut/$ListIn."
[ "$DEBUG" -eq 1 ] && echo "Input file ($IndexFile, job $IndexJob): $FileIn"
((IndexFile++))
done < "$LISTINPUT"
echo "Running conversion jobs... ($((IndexJob+1)) jobs, $NFILESPERJOB files/job)"
OPT_PARALLEL="--halt soon,fail=100%"
if [ "$DEBUG" -eq 0 ]; then
# shellcheck disable=SC2086 # Ignore unquoted options.
parallel $OPT_PARALLEL "$CMDPARALLEL" ::: $(seq 0 $IndexJob) > $LogFile 2>&1
else
# shellcheck disable=SC2086 # Ignore unquoted options.
parallel $OPT_PARALLEL --will-cite --progress "$CMDPARALLEL" ::: $(seq 0 $IndexJob) > $LogFile
fi || ErrExit "\nCheck $(realpath $LogFile)"
grep -q -e '^'"W-" -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)"
exit 0