-
Notifications
You must be signed in to change notification settings - Fork 1
/
JLab_macro_handler.sh
executable file
·352 lines (301 loc) · 8.89 KB
/
JLab_macro_handler.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/bin/bash
#
############################
##### Define Functions #####
#####
# Run jobs
iterator () {
setBuildDir
cd $BUILD
modReader
outLocation=$PWD/output/
cd $outLocation
initial=1
if [ $changeInclude -eq 1 ];
then
read -p 'Number of jobs: ' final
fi
if [ $changeInclude -eq 0 ];
then
let initial=0
read -p 'Minimum value of included.xml variable: ' min
read -p 'Maximum value of included.xml variable: ' max
read -p 'Step size of included.xml variable: ' step
let final=$(printf "%.0f\n" "$(bc -l <<< \($max-$min\)/$step)")
fi
for i in `seq $initial $final`;
do
name=out_${mod}${i}
mkdir $name
cd $name
mkdir geometry
cp -rp "${BUILD}"/geometry/*${mod}* "./geometry/"
cp -rp "${BUILD}"/geometry/mollerParallel.gdml "./geometry/"
cp -rp "${BUILD}"/geometry/materials.xml "./geometry/"
cp -rp "${BUILD}"/geometry/schema "./geometry/"
cp -rp "${BUILD}"/remoll "./remoll"
cp -rp "${BUILD}"/macros/runscript_${mod}.sh "./runscript_${mod}.sh"
cp -rp "${BUILD}"/macros/runscript_${mod}.xml "./runscript_${mod}.xml"
cp -rp "${BUILD}"/macros/runexample_${mod}.mac "./runexample_${mod}.mac"
if [ $changeInclude -eq 0 ];
then
changeIncludes $i $mod $min $max $final
fi
swif add-jsub -workflow remoll -script runscript_${mod}.xml
#qsub ./runscript_${mod}.sh
sleep 1
cd ..
done
}
#####
# Read the user's modifier input from the command line, only if the user hasn't already done so or if the input was null
modReader(){
if [[ $modSet -eq 1 ]] || [[ -z "$mod" ]]
then
modSet=0
read -p 'Modifier for iterator, macro and runscript creation: ' mod
fi
}
#####
# Set the current build directory by looking up at most 3 directories (including the current working directory) and searching in each one for a directory named build who position is assigned to a variable $BUILD
setBuildDir () {
sourceDir = /work/halla/parity/disk1/moller12gev/cameronc/remoll
outputDir = /lustre/expphy/volatile/halla/parity/cameronc/remoll/output/${mod}
cd $sourceDir/build
BUILD=$PWD
OUTDIR=$outputDir
#if [ -d ./build ]
# then
# pushd ./build > /dev/null
# BUILD=$PWD
# popd > /dev/null
# elif [ -d ../build ]
# then
# pushd ../build > /dev/null
# BUILD=$PWD;
# popd > /dev/null
# elif [ -d ../../build ]
# then
# pushd ../../build > /dev/null
# BUILD=$PWD;
# popd > /dev/null
# fi
}
#####
# Create a new included .xml file to be read in by whatever the ${mod} files expect - not intended for standalone command line use - called by iterator only if needed.
changeIncludes () {
n=$(printf "%.2f\n" "$(bc -l <<< ${3}+\(\(${1}\)*\(${4}-${3}\)/${5}\))") #initial parameter + (iterator parameter-1) * (final - initial parameter limits) / number of steps
modifier=${2}
include_name=geometry/include_${modifier}_variable.xml
/bin/cat <<EOM >$include_name
<!-- $include_name include file for ${n} parameter, $((${1}+1)) step of $((${5}+1)), running from ${3} to ${4} -->
EOM
# Take the number n and use it to print (in ./geometry/) a schematically identical included .xml file that gets placed next to the rest of the gdml files
}
#####
# Create runexample_${mod}.mac file
macroPrinter () {
setBuildDir
cd $BUILD
modReader
macroFileName="macros/runexample_${mod}.mac"
/bin/cat <<EOM >$macroFileName
# Macrofile
# This must be called before initialize
/remoll/setgeofile geometry/mollerMother_${mod}.gdml
# This must be explicitly called
/run/initialize
/remoll/addfield $BUILD/map_directory/blockyHybrid_rm_3.0.txt
/remoll/addfield $BUILD/map_directory/blockyUpstream_rm_1.1.txt
# Raster and initial angle stuff
/remoll/oldras false
/remoll/rasx 5 mm
/remoll/rasy 5 mm
/remoll/beamene 11 GeV
/remoll/evgen/set beam
/remoll/beamcurr 85 microampere
# Make interactions with W, Cu, and Pb
# realistic rather than pure absorbers
/remoll/kryptonite/set false
/process/list
# Specify random number seed - DO NOT USE THE SAME SEED OVER AND OVER AGAIN
#/remoll/seed 123456
/remoll/filename remoll_${mod}_1M.root
/run/beamOn 1000000
EOM
}
#####
# Create runscript_${mod}.sh file
runscriptPrinter () {
setBuildDir
cd $BUILD
modReader
mkdir -p xmlJobs
xmlFileName="xmlJobs/${mod}.xml"
vi $xmlFileName <<EndOfCommands
i
<Request>
<Email email="[email protected]" request="false" job="true"/>
<Project name="moller12gev"/>
<Track name="simulation"/>
<Name name="${mod}"/>
<OS name="centos7"/>
<Memory space="3500" unit="MB"/>
<Command><![CDATA[
pwd
tar -zxvf z_config.tar.gz
./remoll runexample_${mod}.mac
]]></Command>
^[
ZZ
EndOfCommands
for nr in `seq $initial $final`;
do
vi $xmlFileName <<EndOfCommands
i
idName=$OUTDIR/${mod}_$nr
<Job>
<Input src="$idName/runexample_${mod}.mac" dest="runexample_${mod}.mac"/>
<Input src="$idName/z_config.tar.gz" dest="z_config.tar.gz"/>
<Output src="remoll_${mod}_1M.root" dest="$idName/remoll_${mod}_1M.root"/>
<Stdout dest="$idName/log/log.out"/>
<Stderr dest="$idName/log/log.err"/>
</Job>
^[
ZZ
EndOfCommands
done
vi $xmlFileName <<EndOfCommands
i
</Request>
^[
ZZ
EndOfCommands
# now print mocha qsub .sh file
qsubFileName="macros/runscript_${mod}.sh"
/bin/cat <<EOM >$qsubFileName
#!/bin/bash
#
#$ -cwd
#$ -j y
#$ -S /bin/bash
./remoll ./runexample_${mod}.mac
EOM
}
#####
# create mollerMother_${mod}.gdml file
motherGDMLPrinter () {
setBuildDir
cd $BUILD
modReader
motherFileName="geometry/mollerMother_${mod}.gdml"
# Be prepared to remove the ${mod}s from the superfluous sub files each time
# Hard code the ones hat I know work for each application.
/bin/cat <<EOM >$motherFileName
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema/gdml.xsd">
<define>
<position name="hallCenter" x="0" y="0" z="4000"/>
<position name="targetCenter" x="0" y="0" z="0"/>
<position name="upstreamCenter" x="0" y="0" z="7000."/>
<position name="hybridCenter" x="0" y="0" z="13366.57"/>
<position name="detectorCenter" x="0" y="0" z="28500."/>
<position name="dumpCenter" x="0" y="0" z="28500."/>
<rotation name="identity"/>
</define>
<materials>
<material Z="1" name="Vacuum" state="gas">
<T unit="K" value="2.73"/>
<P unit="pascal" value="3e-18"/>
<D unit="g/cm3" value="1e-25"/>
<atom unit="g/mole" value="1.01"/>
</material>
</materials>
<solids>
<box lunit="mm" name="boxMother" x="200000" y="200000" z="200000"/>
</solids>
<structure>
<volume name="logicMother">
<materialref ref="Vacuum"/>
<solidref ref="boxMother"/>
<physvol>
<file name="geometry/targetDaughter_${mod}.gdml"/>
<positionref ref="targetCenter"/>
<rotationref ref="identity"/>
</physvol>
<physvol>
<file name="geometry/hallDaughter_${mod}.gdml"/>
<positionref ref="hallCenter"/>
<rotationref ref="identity"/>
</physvol>
<physvol>
<file name="geometry/detectorDaughter_${mod}.gdml"/>
<positionref ref="detectorCenter"/>
<rotationref ref="identity"/>
</physvol>
<physvol>
<file name="geometry/upstreamDaughter_${mod}.gdml"/>
<positionref ref="upstreamCenter"/>
<rotationref ref="identity"/>
</physvol>
<physvol>
<file name="geometry/hybridDaughter_${mod}.gdml"/>
<positionref ref="hybridCenter"/>
<rotationref ref="identity"/>
</physvol>
<!--
<physvol>
<file name="geometry/dumpDaughter_${mod}.gdml"/>
<positionref ref="hybridCenter"/>
<rotationref ref="identity"/>
</physvol>
-->
</volume>
</structure>
<setup name="Default" version="1.0">
<world ref="logicMother"/>
</setup>
</gdml>
EOM
}
########################
##### Main Program #####
changeInclude=1
modSet=1
if [ $# != 0 ]; then
read -p 'Modifier: ' mod
for input in $@; do
case $input in
-c|--changeIncludes)
let changeInclude=0
echo "Be sure to place changeIncludes before iterator flag"
;;
-m|--macro)
macroPrinter
;;
-r|--runscript)
runscriptPrinter
;;
-g|--gdml|--GDML)
motherGDMLPrinter
;;
-i|--submit|-s|--iterator)
iterator
echo "Be sure to place iterator at the end of the list of flags"
;;
--help|-h|help|*)
echo "Usage: Execute from a folder either containing, or one or two directories below a folder containing the 'build' directory you intend to run from
Usage: -m macro printing, -c include file printing (not standalone), -r runscript printing, -g GDML printing, or -i iterator running"
;;
esac
#shift
done
elif [ $# == 0 ]; then
#read -p 'Modifier for iterator, macro and runscript creation: ' mod
#changeInclude=0
#motherGDMLPrinter
macroPrinter
runscriptPrinter
#modReader
iterator
fi