forked from jan-kaspar/analysis_ctpps_alignment_2017_preTS2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·182 lines (146 loc) · 3.36 KB
/
run
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
#!/bin/bash
#----------------------------------------------------------------------------------------------------
function PrintUsage()
{
echo -e "USAGE: run <option> <src file> <option> <dir> <dir> ... <option> ..."
echo -e "OPTIONS:"
echo -e " -h, --help print this help and exit"
echo -e " -O <option> pass the option to the program"
echo -e " -batch prepare job for BATCH instead of executing locally"
echo -e " -submit submit job to BATCH, implies -batch option"
}
#----------------------------------------------------------------------------------------------------
# defaults
src_file=""
work_dirs=()
run_options=""
batch="n"
submit="n"
condor_file_sub="condor.sub"
#----------------------------------------------------------------------------------------------------
# parse command line input
if [ $# -le 0 ]
then
PrintUsage
exit 1
fi
while [ -n "$1" ]
do
case "$1" in
"-h" | "--help")
PrintUsage
exit 1
;;
"-O")
shift
run_options="$1"
;;
"-batch")
batch="y"
;;
"-submit")
batch="y"
submit="y"
;;
*)
if [ ! -d "$1" ]
then
if [ -s "$1" ]
then
if [ -n "$src_file" ]
then
echo "ERROR: multiple definition of source file. Previous '$src_file', current '$1'."
PrintUsage
exit 1
fi
src_file="$1"
else
echo "ERROR: '$1' is neither source file, neither directory neither parameter."
PrintUsage
exit 1
fi
else
if [ -f "$1/config.py" ]
then
work_dirs+=("$1")
else
echo "ERROR: directory '$1' does not have config.py."
PrintUsage
exit 1
fi
fi
;;
esac
shift
done
#----------------------------------------------------------------------------------------------------
# build
src_file=${src_file%.*}
make "$src_file" || exit 2
#----------------------------------------------------------------------------------------------------
# execute
if [ "$batch" == "y" ]
then
# initiate submission script
(
base_dir_full="$(pwd -P)"
echo "executable = $base_dir_full/\$(dir)/.${src_file}.job"
echo "arguments = \$(ClusterId) \$(ProcId) \\\"\$(dir)\\\""
echo "output = $base_dir_full/\$(dir)/.${src_file}.out"
echo "error = $base_dir_full/\$(dir)/.${src_file}.err"
echo "log = $base_dir_full/condor.log"
echo "+MaxRuntime = 7200"
#echo "+JobBatchName = \"$job_name\""
echo "requirements = (OpSysAndVer =?= \"SLCern6\")"
#echo "requirements = (OpSysAndVer =?= \"CentOS7\")"
) > "$condor_file_sub"
fi
function ExecuteOneWithStatus()
{
echo "* $label: running"
cd "$d"
"$cwd/$src_file" $run_options &> "$src_file.log"
if [ $? -ne 0 ]
then
echo "* $label: run error"
else
echo "* $label: done"
fi
cd - > /dev/null
}
function ExecuteOne()
{
dir="$1"
cwd="`pwd -P`"
label="'$src_file' in '$d'"
if [ "$batch" == "n" ]
then
ExecuteOneWithStatus &
else
cat "job_template" | sed " \
s|\$CMSSW_BASE|$CMSSW_BASE|;\
s|\$JOB_DIR|$cwd/$dir|;\
s|\$COMMAND|{ time \"$cwd/$src_file\" ; } \&> \"$src_file.log\"|;\
" > "$dir/.${src_file}.job"
chmod u+x "$dir/.${src_file}.job"
(
echo ""
echo "dir=$dir"
echo "queue"
) >> "$condor_file_sub"
fi
}
for d in ${work_dirs[*]}
do
ExecuteOne "$d"
done
if [ "$batch" == "y" ]
then
if [ "$submit" == "y" ]
then
condor_submit "$condor_file_sub"
else
echo "In order to submit do:"
echo " condor_submit \"$condor_file_sub"\"
fi
fi