source: ZHANGProjects/ICOSIM/CPP/trunk/script/runwithfluka.sh.sample @ 2

Last change on this file since 2 was 2, checked in by zhangj, 10 years ago

Initial import

File size: 3.3 KB
Line 
1#!/bin/bash
2
3#Script to run ICOSIM++ with Fluka collimators
4#Warning: do not forget to do: 'chmod +rx run.sh' the first time before running the script!!
5
6PROJECT_PATH=/afs/cern.ch/user/j/jclivaz/private/ICOSIM++svn/icosimplusplus/trunk
7FLUKASERVER_PATH=/afs/cern.ch/user/j/jclivaz/private/ICOSIM++
8FLUKA_TEST_PATH=./trunk/samples
9FLUKA_PATH=/afs/cern.ch/user/j/jclivaz/private/fluka
10FLUKA_EXE=$FLUKASERVER_PATH/fluka-icosim++/fluka/flukaserver
11COUPLING_PATH=$FLUKASERVER_PATH/fluka-icosim++
12SRC_PATH=$PROJECT_PATH/source
13SAMPLE_PATH=$PROJECT_PATH/sample
14OUTPUT_PATH=$PROJECT_PATH/outputs
15QUEUE=long
16
17TMPDIR=
18FLUKAFLAGS="-e ${FLUKA_EXE} -M 1"
19RFIRST=1
20RLAST=1
21RUN_IN_CURRENT=false
22CURRENT=$PWD
23
24die() {
25  echo >&2 "$1"
26  exit $E_BADARGS
27}
28
29
30
31INFILE=$COUPLING_PATH/tools/$1.inp
32
33if [ ! -f $INFILE ]; then
34  die "The first argument must be the input file name (without .inp)"
35fi
36
37#if [ ! -d $TRACKER_PATH/build ]; then
38 # die "Tracker build not found, please run make on the tracker folder"
39#fi
40
41if [ ! -f $FLUKA_EXE ]; then
42  die "Fluka build not found, please run make on the fluka folder"
43fi
44
45PROJECT_NAME=$(echo $(basename $INFILE) | cut -d\- -f1 | cut -d\. -f1)
46
47
48if [ $RFIRST -lt 1 ]; then
49  echo "first dir < 1 !"
50  exit 1
51fi
52
53if [ $RLAST -gt 100 ]; then
54  echo "last dir > 99 !"
55  exit 1
56fi
57
58cd $OUTPUT_PATH
59
60if $RUN_IN_CURRENT ; then
61  RUNDIR=$CURRENT
62else
63  RUNDIR=$(mktemp -d -p $OUTPUT_PATH ${1}.XXX) || exit 1
64  cd $RUNDIR
65fi
66
67
68echo
69echo " ** Running tracker simulation under directory:"
70echo "    $RUNDIR"
71echo
72echo "    Cycles: $RFIRST - $RLAST"
73echo
74
75
76for ((  i = $RFIRST ;  i <= $RLAST;  i++  ))
77do
78  # numerical directory:
79  mkdir $i || exit 1
80
81  cd $i
82
83  cp $SAMPLE_PATH/collimatorfile_${2}.csv collimatorfile_${2}.csv
84  cp $SAMPLE_PATH/opticsfile_${2}.csv opticsfile_${2}.csv
85  cp $SAMPLE_PATH/initial.dat initial.dat
86  cp $SAMPLE_PATH/crystalinfo.csv crystalinfo.csv
87  cp $SAMPLE_PATH/infoPlotLossSpectra.csv infoPlotLossSpectra.csv
88
89 # Copy input file and replace the Random seed by the "cycle" number ($i)
90  sed 's/^\(RANDOMIZ *\).*$/\1'"$i"'.0/' $INFILE > $(basename $INFILE)
91
92  NAME=$(basename $RUNDIR).$i
93
94cd $RUNDIR/$i
95
96echo " ** Host: \$HOST" > $RUNDIR/server_$i.log
97echo " ** Original directory: $RUNDIR/$i" >> $RUNDIR/server_$i.log
98
99echo " \$HOST" > network.nfo
100
101echo Running ICOSIM++ with Fluka
102
103#Run ServerTestin background
104echo " - Running Fluka in background..." >> $RUNDIR/server_$i.log
105$FLUPRO/flutil/rfluka ${1} ${FLUKAFLAGS}  >> $RUNDIR/server_$i.log 2>&1 &
106
107echo $i > seed.txt
108
109#TMPDIR=\$(mktemp -d /tmp/tracker.XXXXXX) || exit 1
110
111echo " ** Host: \$HOST" > $RUNDIR/tracker_$i.log
112echo " ** Original directory: $RUNDIR/$i" >> $RUNDIR/tracker_$i.log
113echo " ** Running in: \$TMPDIR" >> $RUNDIR/tracker_$i.log
114
115#echo " - Moving tracker to temporary directory..." >> $RUNDIR/tracker_$i.log
116#cp -R -L $RUNDIR/tracker/* \$TMPDIR/
117#ln -s \$TMPDIR tracker
118
119
120# Wait until FLUKA is initialized
121while [ ! -f network.nfo ]; do
122 echo "Fluka still not running, waiting..."
123 sleep 10
124done
125
126#Fluka job started, wait until completely initialized
127sleep 10
128
129cd $SRC_PATH
130
131#Run ICOSIM++ in foreground
132echo " - Running the Tracker..." >> $RUNDIR/tracker_$i.log
133./icosim++ $SAMPLE_PATH/collimatorfile_${2}.csv $RUNDIR >> $RUNDIR/tracker_$i.log 2>&1
134
135cd $RUNDIR/$i
136
137rm -rf \$TMPDIR
138
139  cd $PROJECT_PATH
140done
141
142pkill flukaserver
143
144echo End of the run
145
146exit 0
Note: See TracBrowser for help on using the repository browser.