vp1 45.5 KB
Newer Older
1
2
3
4
5
6
#!/bin/bash

# Script for constructing command which launches athena on vp1.py, with appropriate options (in the -c flag).
#
# Author: Thomas.Kittelmann@cern.ch
# First useful version: July 2007
7
#
8
# Modified: Manuel.Proissl@cern.ch, March 2012
9
#           Riccardo.Maria.Bianchi@cern.ch, multiple times
10
#           Edward.Moyse@cern.ch, multiple times
11
#
12
13
14
# Current Maintainers: 
#           - Riccardo.Maria.Bianchi@cern.ch
#           - Edward.Moyse@cern.ch
15
16
17
18
19
20
#
# Questions: Riccardo.Maria.Bianchi@cern.ch
#
#


21
22
23
24
25
26
27
28
29
#fixme/todo: option to start cruise mode (event/second)
#fixme/todo: MULTINP_CPY should not be allowed to exist beforehand!


### TERMINAL COLORS ###
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
LIGHTBLUE='\033[1;34m'
RED='\033[0;31m'
30
31
32
WHITE='\033[0;97m'
UNDERLINED='\033[4m'
BOLD='\033[1m'
33
34
35
36
NC='\033[0m' # No Color
# then use:
# - printf "I ${RED}love${NC} Stack Overflow\n"
# - echo -e "I ${RED}love${NC} Stack Overflow"
Riccardo Maria Bianchi's avatar
Riccardo Maria Bianchi committed
37

38
39


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
echo
echo "******************************************"
echo
echo "Launching VP1 - the ATLAS 3D event display"
echo
echo "******************************************"
echo
echo

##################################################
# Workaraound for LD_PRELOAD                     #
#                                                #
# Details:                                       #
# https://its.cern.ch/jira/browse/ATLASVPONE-228 #
#                                                #
##################################################
56
echo -e "${LIGHTBLUE}*** VP1 NOTE ***${NC} setting LD_PRELOAD=/usr/lib64/libGL.so.1 env var, to correctly load OpenGL before all other TLS libs. That is caused by a bug in Red Hat 6. For details, see: https://its.cern.ch/jira/browse/ATLASVPONE-228"
57
58
59
export LD_PRELOAD=/usr/lib64/libGL.so.1
##################################################

60
61
62
63
64
65
66
67
68
##################################################
# Workaraound for keyboard input issue on LXPLUS #
#                                                #
# Details:                                       #
# https://its.cern.ch/jira/browse/ATLASVPONE-380 #
#                                                #
##################################################
if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
    # We are on a GNU/Linux platform machine
69
    if [[ $(hostname) == lxplus* ]]; then
70
        # We are on a LXPLUS machine
71
72
73
        echo "uname: " "$(expr substr $(uname -s) 1 5)"
        echo "hostname: " "$(hostname)"
        echo -e "${LIGHTBLUE}*** VP1 NOTE ***${NC} you are running VP1 remotely on a LXPLUS machine. Hence, we set the 'QT_XKB_CONFIG_ROOT environment variable to fix the problem LXPLUS machine have with the new Qt5 framework, which prevent a proper detection of keyboard events. For details, see: https://its.cern.ch/jira/browse/ATLASVPONE-380."
74
75
76
77
78
        export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb
    fi # closes "lxplus"
fi # closes "Linux"
##################################################

79

80
81
82
83
84
85
86
87
88

APP=`basename $0`

which athena.py > /dev/null 2>&1
if [ $? != 0 ]; then
    echo "Error: athena.py not found in path. Please setup atlas release before running"
    exit 1
fi

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

#######################################
##         Warning Messages          ##
#######################################
MUSTQUIT=0
if [ -z ${Athena_VERSION+x} ]; then
    echo "ERROR! The variable 'Athena_VERSION' is unset! Apparently Athena is not properly set. Quitting..."
    MUSTQUIT=1
else
    if [[ ${Athena_VERSION} =~ ^21\. ]]; then
        echo; echo -e " ${RED}${BOLD}   *** WARNING! Release 21 detected! *** ${NC}"; echo
        echo -e "   Apparently, you are using the Release 21 of the Athena environment. Unfortunately, VP1 does not work in rel. 21. ${UNDERLINED}Please use a release >= 22, or the 'master' release${NC}. By using them, you can still access and visualize data produced with rel. 21, if you need that."
        echo; echo -e "   ${RED}${BOLD}--->${NC} Please refer to the instructions published at: ${NC}${BOLD}${UNDERLINED} http://atlas-vp1.web.cern.ch/atlas-vp1/home/documentation/running-the-latest-vp1-version/${NC} ${RED}${BOLD}<---${NC}"; echo; echo
        MUSTQUIT=1
    fi
fi

if [ $MUSTQUIT -eq 1 ]; then
    exit 1;
fi




113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#######################################
##       Init config variables       ##
#######################################

LIVEDEFAULTDETDESCR="ATLAS-GEO-10-00-00"
LIVEDEFAULTGLOBCOND="COMCOND-BLKPST-004-01"
LIVEDEFAULTEVENTSRC="https://atlas-live.cern.ch/event_files/L1MinBias/vp1fileinfo.txt"
LIVELOCALDEFAULTEVENTSRC="/VP1_events/"
LIVEBOOTSTRAPSRC="http://atlas-vp1.web.cern.ch/atlas-vp1/live-bootstrap/vp1fileinfo.txt"

declare -a FILES_POOLROOT
declare -a FILES_VP1CFG
declare -a FILES_EXTRAJOBOPT
declare -a LOCALEVENTSRC_AVAILDIRS
FLAG_HELP=0
FLAG_DATA=0
FLAG_TEST=0
ERRORS=""
DETDESCRTAG=""
Nicolas Koehler's avatar
Nicolas Koehler committed
132
MUONLAYOUT=""
133
NSWAGDDFILE=""
134
135
136
137
138
GLOBCONDTAG=""
SKIPEVENTS=""
CRUISEWITHTIME=""
LOGFILE=""
FILTEREVENTS=""
139
FLAG_BATCH=0
140
FLAG_BATCH_RANDOM_CONFIG=0
141
FLAG_BATCH_ALL_EVENTS=0
142
FLAG_BATCH_N_EVENTS=0
143
FLAG_BATCH_OUT_FOLDER=""
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
FLAG_LARHV=0
# FLAG_FULLTOROIDS=0
FLAG_DONTCLEANUPEVTCPY=0
FLAG_LIVE=0
FLAG_LIVELOCAL=0
FLAG_NOAUTOCONF=0
FLAG_TRIG=0
FLAG_NOCALO=0
FLAG_NOID=0
FLAG_NOSORTDBREPLICAS=0
FLAG_NOMUON=0
FLAG_LUCID=0
FLAG_ONLINE=0
FLAG_ALFA=0
FLAG_FORWARD_REGION=0
FLAG_ZDC=0
FLAG_CAVERN=0
161
162
FLAG_TOYDETECTOR=0
FLAG_GEOMODELSTATS=0
163
164
165
166
167
168
169
FLAG_EXTRAPOLATOR=0
FLAG_NOEXTRAPOLATOR=0
FLAG_FITTER=0
FLAG_MC=0
FLAG_FATRAS=0
FLAG_NOGUI=0
FLAG_CGAL=0
170
FLAG_SLHC=0
171
172
#FLAG_CUSTOMGEOMETRY=0 # currently not used
FLAG_ADVANCED_ANTIALIASING=0
173
174
175
176
177
178
179
180
181
182
MULTINP_SRC=""
MULTINP_CPY=""
TRIGDEC=""
FATRAS_TRUTHKEY=""
ATHENAOPTS=""

#######################################
##    Decode command line options    ##
#######################################

183
184
185
#echo -e "\nnumber of positional parameters (args): " $# # for DEBUG only

# index init
186
i=1
187
188

# start looping over the number of positional parameters ($#)
189
while [ $i -le $# ]; do
190
191
    
    # get the i-positional parameter
192
    arg=${!i}
193
194
195
196
197
198
    
    #echo -e "\nevaluating arg: " $arg # for DEBUG only
    
    ################
    # HELP / USAGE #
    ################
199
200
    if [ "x${arg}" == "x-h" -o "x${arg}" == "x-help" -o "x${arg}" == "x--help" ]; then
	FLAG_HELP=1
201
202
    
    
203
204
205
206
    ########################
    # COMMAND-LINE OPTIONS #
    ########################
    
207
208
209
210
211
212
213
214
    elif [ "x${arg}" == "x-larhv" ]; then
	FLAG_LARHV=1
  #     elif [ "x${arg}" == "x-fulltoroids" ]; then
  # FLAG_FULLTOROIDS=1
    elif [ "x${arg}" == "x-live" ]; then
	FLAG_LIVE=1
    elif [ "x${arg}" == "x-livelocal" ]; then
	FLAG_LIVELOCAL=1
215
216
217
	#
	#
	#
218
219
220
	#-----------
	# BATCH MODE 
    #-----------
221
222
223
224
225
226
227
228
	# check if the user provided config files with -batch/-b options
	elif [ "x${arg}" == "x-batch" -o "x${arg}" == "x-b" ]; then 
		if [[ "$*" == *.vp1* ]]
        then
			FLAG_BATCH=1
			# text in bold, note in bold and red. at the end we reset the text style
			echo ""
			echo -e "\e[1m\e[31m\e[4mNote!\e[24m You chose to run VP1 in 'batch-mode' ('${arg}').\e[39m"
229
			echo -e "Thus, the main VP1 window will be not shown, but in the end you will get a PNG file with the rendered image of the 3D window, based on the configuration file you provided.\e[0m"
230
231
			echo ""
		else
232
			ERRORS="$ERRORS\nBatch mode needs at least one configuration file ('.vp1')"
233
234
235
		fi
	elif [ "x${arg}" == "x-batch-all-events" ]; then 
		FLAG_BATCH_ALL_EVENTS=1
236
237
	elif [ "x${arg}" == "x-batch-random-config" ]; then 
		FLAG_BATCH_RANDOM_CONFIG=1
238
239
240
241
242
243
244
245
246
247
	elif [ "x${arg:0:21}" == "x-batch-output-folder=" ]; then
    	FLAG_BATCH_OUT_FOLDER=${arg:21:$((${#arg}-21))}
	    if [ "x$FLAG_BATCH_OUT_FOLDER" == "x" ]; then
	   	ERRORS="$ERRORS\nNeed argument to -batch-output-folder. Ex: -batch-output-folder=myFolder"
	    fi
	elif [ "x${arg:0:21}" == "x-batch-output-folder" ]; then # catch arg without '=' character
    	FLAG_BATCH_OUT_FOLDER_2=${arg:20:$((${#arg}-20))}
	    if [ "x$FLAG_BATCH_OUT_FOLDER_2" == "x" ]; then
	   	ERRORS="$ERRORS\nNeed argument to -batch-output-folder. Ex: -batch-output-folder=path/to/myFolder"
	    fi
248
249
	elif [ "x${arg:0:16}" == "x-batch-n-events=" ]; then
	FLAG_BATCH_N_EVENTS=${arg:16:$((${#arg}-16))}
250
	echo -e "\e[1m\e[31m\e[4mNote!\e[24m You chose to run VP1 in 'batch-mode' over ${FLAG_BATCH_N_EVENTS} events ('${arg}'). VP1 will exit after having processed the given number of events.\e[39m"
251
252
253
254
255
256
257
258
259
260
	if [ "x$FLAG_BATCH_N_EVENTS" == "x" ]; then
	    ERRORS="$ERRORS\nNeed a numeric argument to -batch-n-events"
	else
	    #check it is integer:
	    echo "$FLAG_BATCH_N_EVENTS" | grep '^[0-9][0-9]*$' > /dev/null 2>&1 || \
		ERRORS="$ERRORS\nArgument to -batch-n-events must be an integer!"
	fi
	#echo "(sleeping for 2 secs...)"
	echo ""
	sleep 2s # to let the user read the warning messages about the batch mode
261
262
263
	### end of batch mode settings
	#
	#
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
    elif [ "x${arg}" == "x-noautoconf" ]; then
	FLAG_NOAUTOCONF=1
    elif [ "x${arg}" == "x-nocleanupeventcpy" ]; then
	FLAG_DONTCLEANUPEVTCPY=1
    elif [ "x${arg}" == "x-data" ]; then
	FLAG_DATA=1
    elif [ "x${arg}" == "x-test" ]; then
	FLAG_TEST=1
    elif [ "x${arg}" == "x-trig" ]; then
        FLAG_TRIG=1
    elif [ "x${arg}" == "x-nocalo" ]; then
	FLAG_NOCALO=1
    elif [ "x${arg}" == "x-noid" ]; then
	FLAG_NOID=1
    elif [ "x${arg}" == "x-nomuon" ]; then
	FLAG_NOMUON=1
    elif [ "x${arg}" == "x-nosortdbreplicas" ]; then
	FLAG_NOSORTDBREPLICAS=1
    elif [ "x${arg}" == "x-lucid" ]; then
	FLAG_LUCID=1
    elif [ "x${arg}" == "x-online" ]; then
	FLAG_ONLINE=1
    elif [ "x${arg}" == "x-alfa" ]; then
	FLAG_ALFA=1
    elif [ "x${arg}" == "x-forwardregion" ]; then
	FLAG_FORWARD_REGION=1
    elif [ "x${arg}" == "x-zdc" ]; then
	FLAG_ZDC=1
    elif [ "x${arg}" == "x-cavern" ]; then
	FLAG_CAVERN=1
294
295
296
297
    elif [ "x${arg}" == "x-toy-detector" ]; then
	FLAG_TOYDETECTOR=1
    elif [ "x${arg}" == "x-geomodel-stats" ]; then
	FLAG_GEOMODELSTATS=1
298
299
300
301
302
303
304
305
306
307
308
309
    elif [ "x${arg}" == "x-extrapolator" ]; then
	FLAG_EXTRAPOLATOR=1
    elif [ "x${arg}" == "x-noextrapolator" ]; then
	FLAG_NOEXTRAPOLATOR=1
    elif [ "x${arg}" == "x-refit" ]; then
	FLAG_FITTER=1
    elif [ "x${arg}" == "x-fatras" ]; then
	FLAG_FATRAS=1
    elif [ "x${arg}" == "x-nogui" ]; then
	FLAG_NOGUI=1
    elif [ "x${arg}" == "x-cgal" ]; then
	FLAG_CGAL=1
310
311
312
    elif [ "x${arg}" == "x-slhc" ]; then
        echo "SLHC"
        FLAG_SLHC=1
313
314
315
316
317
    #elif [ "x${arg}" == "x-customgeom" ]; then
    #    FLAG_CUSTOMGEOMETRY=1
    elif [ "x${arg}" == "x-advanced-aa" ]; then
        FLAG_ADVANCED_ANTIALIASING=1
        export VP1_ADVANCED_ANTIALIASING=1
318
319
320
321
322
323
324
325
326
    elif [ "x${arg}" == "x-mc" ]; then
	FLAG_MC=1
    elif [ "x${arg}" == "x-multinp" ]; then
	echo "IGNORING OBSOlETE FLAG -multinp"
    elif [ "x${arg:0:10}" == "x-detdescr=" ]; then
	DETDESCRTAG=${arg:10:$((${#arg}-10))}
	if [ "x$DETDESCRTAG" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -detdescr"
	fi
Nicolas Koehler's avatar
Nicolas Koehler committed
327
    elif [ "x${arg:0:9}" == "x-detdescr" ]; then
328
329
330
331
	DETDESCRTAG_2=${arg:9:$((${#arg}-9))}
	if [ "x$DETDESCRTAG_2" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -detdescr. Example: -detdescr=ATLAS-GEO-20-00-01"
	fi
Nicolas Koehler's avatar
Nicolas Koehler committed
332
333
334
335
336
    elif [ "x${arg:0:12}" == "x-muonLayout=" ]; then
	MUONLAYOUT=${arg:12:$((${#arg}-12))}
	if [ "x$MUONLAYOUT" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -muonLayout. Example: -muonLayout=MuonSpectrometer-R.09.00.AsymNSW"
	fi
Nicolas Koehler's avatar
Nicolas Koehler committed
337
    elif [ "x${arg:0:9}" == "x-nswagdd=" ]; then
338
339
340
341
	NSWAGDDFILE=${arg:9:$((${#arg}-9))}
	if [ "x$NSWAGDDFILE" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -nswagdd. Example: -nswagdd=stations.v2.06.xml"
	fi
Nicolas Koehler's avatar
Nicolas Koehler committed
342
343
344
345
346
    elif [ "x${arg:0:8}" == "x-nswagdd" ]; then
	NSWAGDDFILE=${arg:8:$((${#arg}-8))}
	if [ "x$NSWAGDDFILE" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -nswagdd. Example: -nswagdd=stations.v2.06.xml"
	fi
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
    elif [ "x${arg:0:10}" == "x-globcond=" ]; then
	GLOBCONDTAG=${arg:10:$((${#arg}-10))}
	if [ "x$GLOBCONDTAG" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -globcond"
	fi
    elif [ "x${arg:0:10}" == "x-eventsrc=" ]; then
	MULTINP_SRC=${arg:10:$((${#arg}-10))}
	if [ "x$MULTINP_SRC" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -eventsrc"
	fi
    elif [ "x${arg:0:10}" == "x-eventcpy=" ]; then
	MULTINP_CPY=${arg:10:$((${#arg}-10))}
	if [ "x$MULTINP_CPY" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -eventcpy"
	fi
    elif [ "x${arg:0:9}" == "x-logfile=" ]; then
	LOGFILE=${arg:9:$((${#arg}-9))}
	if [ "x$LOGFILE" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -logfile"
	fi
    elif [ "x${arg:0:9}" == "x-trigdec=" ]; then
	TRIGDEC=${arg:9:$((${#arg}-9))}
	if [ "x$TRIGDEC" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -trigdec"
	fi
    elif [ "x${arg:0:11}" == "x-fatraskey=" ]; then
	FATRAS_TRUTHKEY=${arg:11:$((${#arg}-11))}
	if [ "x$FATRAS_TRUTHKEY" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -fatraskey"
	fi
    elif [ "x${arg:0:12}" == "x-skipevents=" ]; then
	SKIPEVENTS=${arg:12:$((${#arg}-12))}
	if [ "x$SKIPEVENTS" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -skipevents"
	else
	    #check it is integer:
	    echo "$SKIPEVENTS" | grep '^[0-9][0-9]*$' > /dev/null 2>&1 || \
		ERRORS="$ERRORS\nArgument to -skipevents must be an integer!"
	fi
    elif [ "x${arg:0:11}" == "x-evtfilter=" ]; then
	FILTEREVENTS=${arg:11:$((${#arg}-11))}
	if [ "x$FILTEREVENTS" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -evtfilter"
	fi
    elif [ "x${arg:0:8}" == "x-cruise=" ]; then
	CRUISEWITHTIME=${arg:8:$((${#arg}-8))}
	if [ "x$CRUISEWITHTIME" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -cruise"
	else
	    #check it is integer:
	    echo "$CRUISEWITHTIME" | grep '^[0-9][0-9]*$' > /dev/null 2>&1 || \
		ERRORS="$ERRORS\nArgument to -cruise must be an integer!"
	    if [ "x$CRUISEWITHTIME" == "x0" ]; then
		ERRORS="$ERRORS\nArgument to -cruise must be positive!"
	    fi
	fi
    elif [ "x${arg:0:12}" == "x-athenaopts=" ]; then
	ATHENAOPTS=${arg:12:$((${#arg}-12))}
	if [ "x$ATHENAOPTS" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -athenaopts"
	fi
    elif [ "x${arg:0:16}" == "x-extraevtsrcdir=" ]; then
	EXTRADIR=${arg:16:$((${#arg}-16))}
	if [ "x$EXTRADIR" == "x" ]; then
	    ERRORS="$ERRORS\nNeed argument to -extraevtsrcdir"
	else
	    if [ ! -d $EXTRADIR ]; then
		ERRORS="$ERRORS\nExtra event source directory $EXTRADIR does not exist"
	    else
		LOCALEVENTSRC_AVAILDIRS[${#LOCALEVENTSRC_AVAILDIRS[@]}]="$EXTRADIR"
	    fi
	fi
419
420
421


 	###################
422
423
    # VP1 CONFIG FILE #
    ###################
424
425
    elif [ ${#arg} -gt 4 -a ${arg:$((${#arg}-4)):4} == ".vp1" ]; then
	FILES_VP1CFG[${#FILES_VP1CFG[@]}]="${arg}"
426
427
	
	    
428
429
430
    #####################
    # EXTRA JOB OPTIONS #
    #####################
431
432
    elif [ ${#arg} -gt 3 -a ${arg:$((${#arg}-3)):3} == ".py" ]; then
	FILES_EXTRAJOBOPT[${#FILES_EXTRAJOBOPT[@]}]="${arg}"
433
    
434
    
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
    ########################
    # EOS / LFN INPUT DATA #
    ########################
    
    # NOTES:
    # - about reg-exp matching: https://its.cern.ch/jira/browse/ATLASVPONE-314
    # - 'elif' first checks if argument length is > 3 and if not begins with "-", 
    #   then it checks the match with the reg-exp
    
    elif [[ ${#arg} -gt 3 && ${arg:0:1} != "-" && ( "${arg}" =~ ^LFN: ) ]]; then
        echo -e "\n\e[1;94mOpening a file through the \e[4m'LFN:'\e[24m protocol...\e[0m"
        FILES_POOLROOT[${#FILES_POOLROOT[@]}]="${arg}"
        echo -e "\e[94mOpening the file: " $FILES_POOLROOT "\e[0m\n"

    elif [[ ${#arg} -gt 3 && ${arg:0:1} != "-" && ( "${arg}" =~ ^root: ) ]]; then
        echo -e "\n\e[1;94mOpening a file through the \e[4m'root:'\e[24m protocol...\e[0m"
        FILES_POOLROOT[${#FILES_POOLROOT[@]}]="${arg}"
        echo -e "\e[94mOpening the file: " $FILES_POOLROOT "\e[0m\n" 
    
    ####################
    # LOCAL INPUT DATA #
    ####################

    # NOTES:
    # - 'elif' first checks if argument length is > 3 and if not begins with "-", 
    #   then it checks if the file exists

    elif [[ ${#arg} -gt 3 && ${arg:0:1} != "-" && ( -f "${arg}" ) ]]; then
        FILES_POOLROOT[${#FILES_POOLROOT[@]}]="${arg}"
        echo -e "\n\e[94mOpening the local file: " $FILES_POOLROOT "\e[0m\n" 


    ###################
    # DEFAULT (ERROR) #
    ###################
470
471
472
    else
	ERRORS="$ERRORS\nUnknown argument: ${arg}"
    fi
473
474
    
    # INCREMENT THE INDEX
475
476
477
    i=$((i+1))
done

478
479
480
481
482
483
484
485




########################
###     SETTINGS     ###
########################

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500

# batch mode
if [ "x$FLAG_BATCH_N_EVENTS" != "x0" -a "x$FLAG_BATCH" == "x0" ]; then
	ERRORS="$ERRORS\nOption '-batch-n-events' can't be used without '-batch'..."
fi
if [ "x$FLAG_BATCH_N_EVENTS" != "x0" -a "x$FLAG_BATCH_ALL_EVENTS" == "x1" ]; then
	ERRORS="$ERRORS\nOption '-batch-n-events' can't be used together with '-batch-all-events'... Please choose one or the other."
fi
if [ "x$FLAG_BATCH_ALL_EVENTS" == "x1" -a "x$FLAG_BATCH" == "x0" ]; then
	ERRORS="$ERRORS\nOption '-batch-all-events' can't be used without '-batch'..."
fi
if [ "x$FLAG_BATCH_RANDOM_CONFIG" == "x1" -a "x$FLAG_BATCH" == "x0" ]; then
	ERRORS="$ERRORS\nOption '-batch-random-config' can't be used without '-batch'..."
fi
if [ "x$FLAG_BATCH_RANDOM_CONFIG" == "x1" ]; then
501
	echo -e "\e[1m\e[31m\e[4mNote!\e[24m You chose the option '-batch-random-config'.\e[39m"
502
503
504
505
506
507
508
509
	echo -e "Thus, for each event a different configuration file will be used, randomly picked from the configuration files (.vp1) you provided:\e[0m"
	printf "["; printf '"%s", ' "${FILES_VP1CFG[@]}"; printf "]\n"; echo
fi
if [ "x$FLAG_BATCH_OUT_FOLDER" != "x" -a "x$FLAG_BATCH" == "x0" ]; then
	ERRORS="$ERRORS\nOption '-batch-output-folder' can't be used without '-batch'..."
fi
    	
    			
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
#live & noautoconf flags (AutoConfiguration is disabled in live and livelocal modes)

if [ "x$FLAG_LIVE" == "x1" ]; then
    if [ "x$FLAG_MC" == "x1" ]; then
	echo "Notice: -mc flag is ignored when -live is present"
    fi
    FLAG_MC=0
    if [ "x$FLAG_NOAUTOCONF" == "x1" ]; then
	echo "Notice: -noautoconf flag is redundant when -live is present"
    fi
    FLAG_NOAUTOCONF=1
    if [ "x$MULTINP_SRC" == "x" ]; then
	MULTINP_SRC="$LIVEDEFAULTEVENTSRC"
    fi
    if [ "x$DETDESCRTAG" == "x" ]; then
	DETDESCRTAG="$LIVEDEFAULTDETDESCR"
    fi
    if [ "x$GLOBCONDTAG" == "x" ]; then
	GLOBCONDTAG="$LIVEDEFAULTGLOBCOND"
    fi
elif [ "x$FLAG_LIVELOCAL" == "x1" ]; then
    if [ "x$FLAG_MC" == "x1" ]; then
	echo "Notice: -mc flag is ignored when -livelocal is present"
    fi
    FLAG_MC=0
    if [ "x$FLAG_NOAUTOCONF" == "x1" ]; then
	echo "Notice: -noautoconf flag is redundant when -livelocal is present"
    fi
    FLAG_NOAUTOCONF=1
    if [ "x$MULTINP_SRC" == "x" ]; then
	MULTINP_SRC="$LIVELOCALDEFAULTEVENTSRC"
    fi
    if [ "x$DETDESCRTAG" == "x" ]; then
	DETDESCRTAG="$LIVEDEFAULTDETDESCR"
    fi
    if [ "x$GLOBCONDTAG" == "x" ]; then
	GLOBCONDTAG="$LIVEDEFAULTGLOBCOND"
    fi
elif [ "x$FLAG_NOAUTOCONF" == "x0" -a ${#FILES_POOLROOT[@]} != 0 ]; then
    if [ "x$FLAG_MC" == "x1" ]; then
	echo "Notice: -mc flag is ignored when autoconfiguration is ON"
    fi
    FLAG_MC=0
fi

if [ "x$FLAG_LIVE" == "x1" -a "x$FLAG_LIVELOCAL" == "x1" ]; then
    ERRORS="$ERRORS\nDon't specify both -live and -livelocal"
fi

#default:
if [ "x$MULTINP_SRC" != "x" -a "x$MULTINP_CPY" == "x" ]; then
    MULTINP_CPY="/tmp/$USER/vp1events/$RANDOM"
fi

# Sanity checks:
if [ "x$MULTINP_SRC" == "x" -a "x$FLAG_DONTCLEANUPEVTCPY" == "x1" ]; then
    ERRORS="$ERRORS\nOption -nocleanupeventcpy can't be set without -eventsrc=..."
fi
if [ "x$MULTINP_CPY" != "x" -a "x$MULTINP_SRC" == "x" ]; then
    ERRORS="$ERRORS\nOption -eventcpy=... can't be set without -eventsrc=..."
fi

if [ "x$FLAG_NOID" == "x1" -a "x$FLAG_FATRAS" == "x1" ]; then
    ERRORS="$ERRORS\nOptions -fatras and -noid can not be applied simultaneously"
fi

if [ "x$FLAG_LIVE" == "x1" -a "x$FLAG_FATRAS" == "x1" ]; then
    ERRORS="$ERRORS\nOptions -fatras and -live can not be applied simultaneously"
fi

if [ "x$FLAG_LIVELOCAL" == "x1" -a "x$FLAG_FATRAS" == "x1" ]; then
    ERRORS="$ERRORS\nOptions -fatras and -livelocal can not be applied simultaneously"
fi

if [ "x$FLAG_NOID" == "x1" -a "x$FLAG_NOMUON" == "x1" -a "x$FLAG_EXTRAPOLATOR" == "x1" ]; then
    ERRORS="$ERRORS\nOptions -extrapolator can not be used when both -noid and -nomuon are specified"
fi

if [ "x$FLAG_EXTRAPOLATOR" == "x1" -a "x$FLAG_NOEXTRAPOLATOR" == "x1" ]; then
    ERRORS="$ERRORS\nOptions -extrapolator and -noextrapolator are incompatible"
fi

if [ "x$FLAG_NOID" == "x1" -a "x$FLAG_NOMUON" == "x1" -a "x$FLAG_FITTER" == "x1" ]; then
    ERRORS="$ERRORS\nOptions -refit can not be used when both -noid and -nomuon are specified"
fi

if [ "x$MULTINP_CPY" != "x" -a -f "$MULTINP_CPY" ]; then
    ERRORS="$ERRORS\n-eventcpy directory set to point to a file"
fi

600
# TODO: Check this "bootstrap": what is it? Is it still needed?
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
BOOTSTRAPNAME="bootstrapevent.pool.root"
BOOTSTRAPFILE="${MULTINP_CPY}/${BOOTSTRAPNAME}"
BOOTSTRAP_HTTPFILEINFO="${MULTINP_CPY}/bootstrap_fileinfo.txt"
HTTPMODE=0
if [ "x$MULTINP_SRC" != "x" ]; then
    if [ ${#FILES_POOLROOT[@]} != 0 ]; then
            #cant have input files.
	ERRORS="$ERRORS\nPlease don't specify input files when running with -live, -livelocal or -eventsrc=..."
    else
	FILES_POOLROOT[${#FILES_POOLROOT[@]}]="${BOOTSTRAPFILE}"
    fi
    HTTPMODE=1
    echo $MULTINP_SRC|grep '^https://..*/..*' > /dev/null || HTTPMODE=0
    echo $MULTINP_SRC|grep '/$' > /dev/null && HTTPMODE=0
    if [ "x$HTTPMODE" == "x0" ]; then
	if [ "x$MULTINP_SRC" != "x" -a ! -d "$MULTINP_SRC" ]; then
	    ERRORS="$ERRORS\n-eventsrc directory does not exists"
	fi
    elif [ "x$MULTINP_CPY" == "x$MULTINP_SRC" ]; then
        #Fixme: Could probably cheat this check by presense of trailing '/', symlinks, etc.
	ERRORS="$ERRORS\n-eventsrc and -eventcpy directories must be different"
    fi
fi

if [ ${#LOCALEVENTSRC_AVAILDIRS[@]} != 0 ]; then
    if [ "x$MULTINP_SRC" == "x" ]; then
	ERRORS="$ERRORS\n-extraevtsrcdir can not be specified without the -eventsrc flag"
    fi
    if [ "x$HTTPMODE" != "x0" ]; then
	ERRORS="$ERRORS\n-extraevtsrcdir can not be used when -eventsrc is not a local directory"
    fi
fi

if [ "x$FLAG_EXTRAPOLATOR" == "x0" -a "x$FLAG_EXTRAPOLATOR" == "x0" ]; then
    if [ "x$FLAG_NOID" == "x1" -a "x$FLAG_NOMUON" == "x1" ]; then
	FLAG_NOEXTRAPOLATOR=1
    else
	FLAG_EXTRAPOLATOR=1
    fi
fi


#######################################
##  Possibly print out errors/usage  ##
#######################################

if [ "x$ERRORS" != "x" ]; then
    echo "================================================================="
    echo "Errors found in commandline options!!!:"
    echo -e "$ERRORS"
    echo
    echo "Run 'vp1 -h' for more information"
    echo "================================================================="
    echo
    exit 1
fi

if [ "x$FLAG_HELP" != "x0" ]; then
    echo "The $APP script serves as a frontend which runs athena with vp1.py and appropriate options."
    echo
    echo "Usage: "
    echo
    echo "$APP [inputfiles] [configfiles] [jobopt fragments] [options]"
    echo
    echo "Config files must have the .vp1 extension, joboption fragments the .py extension,"
    echo "and any other argument which doesn't start with '-' is assumed to be an input file if such a file exists."
    echo
    echo "  -h, -help, --help           : Display this help (with examples) and exit."
    echo
670
671
672
673
    echo "  -batch                      : Run VP1 in 'batch' mode with a given configuration file."
    echo
    echo "  -batch-all-events           : Process all events in the input data file in '-batch' mode. Use this together with '-batch'."
    echo
674
675
    echo "  -batch-n-events=N           : Process 'N' events in the input data file in '-batch' mode. Use this together with '-batch'."
    echo
676
677
    echo "  -batch-output-folder        : Specify an output folder to store the event displays produced with the '-batch' option."
    echo
678
679
    echo "  -batch-random-config        : Run VP1 in 'batch' mode; for each single event a configuration file will be randomly picked out of the configuration files provided by the user. Use this together with '-batch'."
    echo
680
    echo "  -larhv                      : Access current LAr HV data in the DCS_OFL database via VP1 CaloReadout system."
681
    echo
682
683
684
685
686
687
688
689
690
691
692
693
    echo "  -data                       : Input files are data [default assumption is simulation]. "
    echo
    echo "  -detdescr=TAG               : Set global geometry tag. Overrides autoconfiguration"
    echo
    echo "  -globcond=TAG               : Set global conditions tag. Overrides autoconfiguration"
    echo
    echo "  -skipevents=N               : Skip the first N events"
    echo
    echo "  -evtfilter=FILTER           : Only process the events in the FILTER list."
    echo "                                Format is a comma separated list of event numbers, where each event number"
    echo "                                can optionally be preceeded by a run number and a semicolon."
    echo "                                Prepend the list with an \"%\" to instead exclude the events."
694
695
    echo "                                For instance select a few nice events like: -evtfilter=7,13,5300:26,54"
    echo "                                Or exclude a few bad events like: -evtfilter=%7,13,5300:26,54"
696
697
    echo
    echo "                                It is also possible to specify one or more files with run/evt numbers"
698
    echo "                                specified on each line: -evtfilter=%7,13,5300:26,54,myevents1.txt"
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
    echo
    echo "  -cruise=N                   : Start in cruise mode, changing events after N seconds"
    echo
    echo "  -logfile=mylogfile.txt      : Leave a copy of the output in mylogfile.txt (both stdout and stderr)"
    echo
    echo "  -trig                       : Init trigger information to be displayed with the Trigger Plugin"
    echo
    echo "  -nocalo                     : Don't init geometry and converters for calorimeter systems."
    echo "  -noid                       : Don't init geometry and converters for the inner detector."
    echo "  -nomuon                     : Don't init geometry and converters for muon systems."
    # echo "  -fulltoroids                : Build complete and rather heavyweight description of muon dead materials."
    # echo "                                A lightweight version is built by default"
    echo "  -lucid                      : Init geometry and converters for the LUCID forward detector."
    echo "  -alfa                       : Init geometry and converters for the ALFA forward detector."
    echo "  -forwardregion              : Init geometry and converters for the FrwardRegion."
    echo "  -zdc                        : Init geometry and converters for the ZDC forward detector."
    echo "  -cavern                     : Init geometry for the cavern infrastructure."
    echo
717
718
719
    echo "  -toy-detector               : Let VP1 visualize the "ToyDetector" volumes of GeoModelExamples (as 'Other unrecognized volumes.' in the Geo system)"
    echo
    echo "  -geomodel-stats             : Write GeoModel stats to a file."
720
    echo
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
    echo "  -extrapolator               : Whether to configure an extrapolator for more precise track representation."
    echo "  -noextrapolator               Default is -extrapolator unless both -nomuon and -noid are specified."
    echo
    echo "  -refit                      : Allows VP1-controlled refit from PrepRawData."
    echo
    echo "  -online                     : Use this flag for running VP1 at P1."
    echo
    echo "  -mc                         : Tell VP1 that it is running over MC data. The flag is ignored when autoconfiguration is ON"
    echo "                                (default mode when running over data files)"
    echo
    echo "  -fatras                     : Use Fatras (in single-track-simulation mode if no input file with generated event)"
    echo "  -fatraskey=KEY              : Optionally override truth key used by Fatras (typical values are GEN_EVENT or TruthEvent)"
    echo
    echo "  -eventsrc=DIR               : Directory to take single event files from (do not specify input files in this case)."
    echo "                                To get files from a web server (i.e. live events), put instead the url to the file"
    echo "                                residing in the same directory (most users should just use the -live option instead)."
    echo
    echo "  -extraevtsrcdir=DIR         : Directory to add to the menu to allow user to change eventsrc on the fly."
    echo "                                This argument can appear several times and should only be used when eventsrc is"
    echo "                                a local directory"
    echo
    echo "  -eventcpy=DIR               : Directory to keep local copies of processed event files."
    echo "                                If -eventsrc is set, then -eventcpy will default to /tmp/$USER/vp1events/$RANDOM "
    echo "  -nocleanupeventcpy          : Prevent removal of eventcpy directory after athena process finishes."
    echo
    echo "  -live                       : Run on live events from point 1. This is a convenience option which implies"
    echo "                                other options [unless explicitly set]:"
    echo "                                  -noautoconf"
    echo "                                  -eventsrc=$LIVEDEFAULTEVENTSRC"
    echo "                                  -detdescr=$LIVEDEFAULTDETDESCR"
    echo "                                  -globcond=$LIVEDEFAULTGLOBCOND"
    echo
    echo "  -livelocal                  : Run on live events from point 1 in local directory. This is a convenience option"
    echo "                                which implies other options [unless explicitly set]:"
    echo "                                  -noautoconf"
    echo "                                  -eventsrc=$LIVELOCALDEFAULTEVENTSRC"
    echo "                                  -detdescr=$LIVEDEFAULTDETDESCR"
    echo "                                  -globcond=$LIVEDEFAULTGLOBCOND"
    echo
    echo "  -noautoconf                 : Disable AutoConfiguration. VP1 runs in the 'data' mode by default"
    echo "                                use '-mc' flag for switching to the MC mode"
    echo
    echo "  -nosortdbreplicas           : Do not attempt to sort DB replicas according to geographical proximity."
    echo
    echo "  -trigdec=file.xml           : Use file.xml as source of trigger decision category data."
    echo "  -trigdec=embedded           : Trigger decision category data is embedded in the input file(s)."
    echo "  -trigdec=someserver.cern.ch : Trigger decision category data is available from the server someserver.cern.ch."
    echo
    echo "  -athenaopts=<options>       : Pass <options> onto athena invocation (type 'athena.py -h' to see available options)."
    echo "                                NB: You can not use the -c option."
    echo
    echo "  -cgal                       : Use CGAL boolean instead of vp1 boolean."
    echo
774
775
    echo "  -nsw                        : Enable the Muon New Small Wheel geometry (and disable the existing small wheel)."
    echo
776
    echo "  -slhc                       : Enable special configurations for SLHC studies."
777
778
779
    echo
    echo "  -customgeom                 : Enable a custom geometry."
    echo
780
781
    echo "  -advanced-aa                : Enable advanced anti-aliasing for crisper, higher-quality images. DOES NOT WORK ON LXPLUS MACHINES!!!"
    echo
782
783
784
785
786
787
    echo "  -test                       : Show the athena command instead of executing it."
    echo
    echo "Note that the order of specified files/options is not important, and that they can in general be mixed quite"
    echo "liberally (when it makes sense - of course dont put e.g. both -trigdec=file.xml and -trigdec=embedded)"
    echo
    echo
788
    echo "*********"
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
    echo "Examples:"
    echo
    echo "  * Simply run on the input files myevents1.pool.root and myevents2.pool.root"
    echo
    echo "     \$>$APP myevents1.pool.root myevents2.pool.root"
    echo
    echo "  * Simply run on the input file myevents.pool.root and have the joboption fragments myopts1.py and myopts2.py"
    echo "     included after the standard vp1 setup"
    echo
    echo "     \$>$APP myevents.pool.root myopts1.py myopts2.py"
    echo
    echo "  * Run on myevents1.pool.root, and use a file, mytrigger.xml, as source of trigger decision data:"
    echo
    echo "     \$>$APP myevents1.pool.root -trigdec=mytrigger.xml"
    echo
    echo "  * Run on myevents1.pool.root, don't init geometry and converters for the calorimeter systems:"
    echo
    echo "     \$>$APP myevents1.pool.root -nocalo"
    echo
    echo "  * Run on myevents1.pool.root, and use detector description tag \"ATLAS-GEO-10-00-00\":"
    echo
    echo "     \$>$APP myevents1.pool.root -detdescr=ATLAS-GEO-10-00-00"
    echo
    echo "  * Run on myevents1.pool.root, and pass on a couple of options to the athena invocation (in this case"
    echo "     we want to run with a debugger and also set the loglevel to WARNING):"
    echo
    echo "     \$>$APP myevents1.pool.root -athenaopts='-d -l WARNING'"
    echo
    echo "  * Run on myevents1.pool.root, and preload the tab/channel configuration files myconfig1.vp1 and myconfig2.vp1:"
    echo
    echo "     \$>$APP myevents1.pool.root myconfig1.vp1 myconfig2.vp1"
    echo
821
    echo "  * Run on myevents1.pool.root, and preload two tab/channel configuration files: myconfig1.vp1 and myconfig2.vp1; at start, VP1 will create multiple tabs, from the pieces of configuration information contained in both files:"
822
823
824
    echo
    echo "     \$>$APP myevents1.pool.root myconfig1.vp1 myconfig2.vp1"
    echo
825
826
827
828
829
    echo "  * Run in 'batch mode' on 'myevents1.pool.root' with the configuration file 'myconfig1.vp1'."
    echo "    No graphical window will appear, but in the end you will get the PNG file containing the render of the 3D window."
    echo
    echo "     \$>$APP -batch myevents.pool.root myconfig1.vp1"
    echo
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
    echo "  * Some more advanced examples, using several options at once:"
    echo
    echo "     \$>$APP -detdescr=ATLAS-GEO-10-00-00 myevents1.pool.root myevents2.pool.root myconfig1.vp1 -athenaopts='-d'"
    echo "     \$>$APP -detdescr=ATLAS-GEO-10-00-00 myevents1.pool.root myconfig1.vp1 -nocalo -nomuon -trigdec=embedded"
    echo
    exit 0
fi

########################################
##  Setup & run according to options  ##
########################################

if [ "x$FLAG_DONTCLEANUPEVTCPY" != "x1" -a "x$MULTINP_CPY" != "x" ]; then
    if [ ${#MULTINP_CPY} -lt 8 -o "x$MULTINP_CPY" == "$HOME" -o "x$MULTINP_CPY" == "$HOME/" ]; then
	echo "NOTICE: Turning off removal of ${MULTINP_CPY} since it seems to be too short or pointing at $HOME."
	FLAG_DONTCLEANUPEVTCPY=1
    fi
fi

if [ "x$FLAG_DATA" != "x0" ]; then
    echo "Error: Support for the -data flag is actually not implemented yet!"
    exit 1
fi

PYTHONFILES=""
i=0
while [ $i -le $((${#FILES_VP1CFG[@]}-1)) ]; do
    if [ "x$PYTHONFILES" == "x" ]; then
	PYTHONFILES='vp1CfgFiles=["'"${FILES_VP1CFG[$i]}"'"'
    else
860
	PYTHONFILES="${PYTHONFILES}"',"'"${FILES_VP1CFG[$i]}"'"'
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
    fi
    i=$((i+1))
done
if [ "x$PYTHONFILES" != "x" ]; then
    PYTHONFILES="${PYTHONFILES}"']'
fi


POOLROOTFILES=""
i=0
while [ $i -le $((${#FILES_POOLROOT[@]}-1)) ]; do
    if [ "x$POOLROOTFILES" == "x" ]; then
	POOLROOTFILES='vp1InputFiles=["'"${FILES_POOLROOT[$i]}"'"'
    else
	POOLROOTFILES="${POOLROOTFILES}"',"'"${FILES_POOLROOT[$i]}"'"'
    fi
    i=$((i+1))
done
if [ "x$POOLROOTFILES" != "x" ]; then
    POOLROOTFILES="${POOLROOTFILES}"']'
fi

EXTRAINPUTDIRS=""
i=0
while [ $i -le $((${#LOCALEVENTSRC_AVAILDIRS[@]}-1)) ]; do
    if [ "x$EXTRAINPUTDIRS" == "x" ]; then
	EXTRAINPUTDIRS='vp1MultiAvailableSrcDirs=["'"${LOCALEVENTSRC_AVAILDIRS[$i]}"'"'
    else
	EXTRAINPUTDIRS="${EXTRAINPUTDIRS}"',"'"${LOCALEVENTSRC_AVAILDIRS[$i]}"'"'
    fi
    i=$((i+1))
done
if [ "x$EXTRAINPUTDIRS" != "x" ]; then
    EXTRAINPUTDIRS="${EXTRAINPUTDIRS}"']'
fi

EXTRAJOBOPT=""
i=0
while [ $i -le $((${#FILES_EXTRAJOBOPT[@]}-1)) ]; do
    if [ "x$EXTRAJOBOPT" == "x" ]; then
	EXTRAJOBOPT="${FILES_EXTRAJOBOPT[$i]}"
    else
	EXTRAJOBOPT="${EXTRAJOBOPT} ${FILES_EXTRAJOBOPT[$i]}"
    fi
    i=$((i+1))
done

JOBOPT="VP1Algs/vp1.py"
if [ -f vp1.py ]; then
    JOBOPT=vp1.py
fi

OPTS="$PYTHONFILES"
if [ "x$POOLROOTFILES" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}$POOLROOTFILES"
fi
if [ "x$EXTRAINPUTDIRS" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}$EXTRAINPUTDIRS"
fi
if [ "x$DETDESCRTAG" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}DetDescrVersion=\"$DETDESCRTAG\""
fi
Nicolas Koehler's avatar
Nicolas Koehler committed
926
927
928
929
if [ "x$MUONLAYOUT" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1MuonLayout=\"$MUONLAYOUT\""
fi
930
931
if [ "x$NSWAGDDFILE" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
932
    OPTS="${OPTS}vp1NSWAGDDFiles=[\"${NSWAGDDFILE}\"]"
933
fi
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
if [ "x$GLOBCONDTAG" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1GlobCond=\"$GLOBCONDTAG\""
fi
if [ "x$SKIPEVENTS" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}skipEvents=$SKIPEVENTS"
fi
if [ "x$FILTEREVENTS" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1FilterEvents=\"$FILTEREVENTS\""
fi
if [ "x$CRUISEWITHTIME" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1CruiseTime=$CRUISEWITHTIME"
fi
if [ "x$FLAG_TRIG" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Trig=True"
fi
if [ "x$FLAG_NOCALO" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Calo=False"
fi
if [ "x$FLAG_NOID" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1ID=False"
fi
if [ "x$FLAG_NOMUON" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Muon=False"
fi
if [ "x$FLAG_NOSORTDBREPLICAS" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1NoSortDBReplicas=True"
fi
970
971
972
973
974
975
976
977
if [ "x$FLAG_BATCH" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Batch=True"
fi
if [ "x$FLAG_BATCH_ALL_EVENTS" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1BatchAllEvents=True"
fi
978
979
980
981
if [ "x$FLAG_BATCH_N_EVENTS" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1BatchNEvents=$FLAG_BATCH_N_EVENTS"
fi
982
983
984
985
if [ "x$FLAG_BATCH_OUT_FOLDER" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1BatchOutFolder=\"$FLAG_BATCH_OUT_FOLDER\""
fi
986
987
988
989
if [ "x$FLAG_BATCH_RANDOM_CONFIG" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1BatchRandomConfiguration=True"
fi
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
if [ "x$FLAG_LARHV" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1LarHvData=True"
fi
# if [ "x$FLAG_FULLTOROIDS" != "x0" ]; then
#     if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
#     OPTS="${OPTS}vp1FullToroids=True"
# fi
if [ "x$FLAG_ONLINE" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Online=True"
fi
if [ "x$FLAG_LUCID" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1LUCID=True"
fi
if [ "x$FLAG_ALFA" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1ALFA=True"
fi
if [ "x$FLAG_FORWARD_REGION" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1ForwardRegion=True"
fi
if [ "x$FLAG_ZDC" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1ZDC=True"
fi
if [ "x$FLAG_CAVERN" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Cavern=True"
fi
1022
1023
1024
1025
1026
1027
1028
1029
if [ "x$FLAG_TOYDETECTOR" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1ToyDetector=True"
fi
if [ "x$FLAG_GEOMODELSTATS" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1GeoModelStats=True"
fi
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
if [ "x$FLAG_EXTRAPOLATOR" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Extrapolator=True"
fi
if [ "x$FLAG_NOEXTRAPOLATOR" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Extrapolator=False"
fi
if [ "x$FLAG_NOAUTOCONF" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1NoAutoConf=True"
fi
if [ "x$FLAG_FITTER" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
Edward Moyse's avatar
Edward Moyse committed
1044
    ERRORS="$ERRORS\nOption -refit is not currently supported."    
1045
1046
1047
1048
1049
fi
if [ "x$FLAG_FATRAS" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Fatras=True"
fi
1050
1051
1052
1053
if [ "x$FLAG_SLHC" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1SLHC=True"
fi
1054
1055
1056
1057
1058
1059
1060
1061
#if [ "x$FLAG_CUSTOMGEOMETRY" != "x0" ]; then
#    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
#    OPTS="${OPTS}vp1CustomGeometry=True"
#fi
#if [ "x$FLAG_ADVANCED_ANTIALIASING" != "x0" ]; then
#    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
#    OPTS="${OPTS}vp1AdvancedAntialiasing=True"
#fi
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
if [ "x$FLAG_NOGUI" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1NoGui=True"
fi
if [ "x$FLAG_MC" != "x0" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Mc=True"
fi
if [ "x$MULTINP_SRC" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Multinp=True"
fi
if [ "x$MULTINP_SRC" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Multinpsrc=\"$MULTINP_SRC\""
fi
if [ "x$MULTINP_CPY" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1Multinpcpy=\"$MULTINP_CPY\""
fi
if [ "x$TRIGDEC" != "x" ]; then
    if [ ${#TRIGDEC} -gt 5 -a ${TRIGDEC:$((${#TRIGDEC}-4)):4} == ".xml" ]; then
	if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
	OPTS="${OPTS}vp1TrigDecXML=\"$TRIGDEC\""
    else
	echo "Error: Support for the -trigdec flag for embedded or server is actually not implemented in this script yet! So far only .xml sources work"
	exit 1
    fi
fi
if [ "x$FATRAS_TRUTHKEY" != "x" ]; then
    if [ "x$OPTS" != "x" ]; then OPTS="$OPTS;"; fi
    OPTS="${OPTS}vp1FatrasTruthKey=\"$FATRAS_TRUTHKEY\""
fi

if [ "x$LOGFILE" != "x" ]; then
    #Fixme: Check that this actually redirects stderr correctly!!
    CMD="$CMD 2>&1|tee $LOGFILE"
fi
#Test mode:
if [ "x$FLAG_TEST" != "x0" ]; then
    if [ "x$HTTPMODE" == "x1" ]; then
	echo "--> Start by downloading a fresh file from $MULTINP_SRC to $BOOTSTRAPFILE"
    fi
    if [ "x$MULTINP_CPY" != "x" -a ! -d "$MULTINP_CPY" ]; then
	echo mkdir -p $MULTINP_CPY
    fi
    if [ "x$LOGFILE" != "x" ]; then
	echo athena.py $ATHENAOPTS  -c "'$OPTS'" $JOBOPT $EXTRAJOBOPT "2>&1|tee $LOGFILE"
    else
	echo athena.py $ATHENAOPTS  -c "'$OPTS'" $JOBOPT $EXTRAJOBOPT
    fi
    exit 0
fi

##################################################
##  Possibly get boot-strap file for http mode  ##
##################################################

if [ "x$MULTINP_CPY" != "x" -a ! -d "$MULTINP_CPY" ]; then
    mkdir -p $MULTINP_CPY
    if [ $? != 0 ]; then
	echo
	echo "Failed to create $MULTINP_CPY"
	echo
	exit 1
    fi
fi


if [ "x$HTTPMODE" == "x1" ]; then
    if [ -f $BOOTSTRAPFILE ]; then
	echo
	echo
	echo "Using existing $BOOTSTRAPFILE as first event."
	echo
	echo "In case of problems, try first to remove this file and then restart"
	echo
	echo
    else
	echo "Need to acquire $BOOTSTRAPFILE"
	while [ 1 ]; do
	    rm -f $BOOTSTRAP_HTTPFILEINFO
	    echo
	    echo "Executing wget $LIVEBOOTSTRAPSRC --output-document=$BOOTSTRAP_HTTPFILEINFO"
	    wget $LIVEBOOTSTRAPSRC --output-document=$BOOTSTRAP_HTTPFILEINFO
	    if [ $? != 0 ]; then
		echo
		echo "Download failed!"
		echo
		rm -f $BOOTSTRAP_HTTPFILEINFO
		exit 1
	    fi
	    echo "Download succesful"
	    #Check integrity of downloaded file:
	    OK=1
	    grep '^vp1_.*_.*_.*.pool.root' $BOOTSTRAP_HTTPFILEINFO |grep -v "copy " > /dev/null || OK=0
	    grep 'begin_checksums' $BOOTSTRAP_HTTPFILEINFO > /dev/null || OK=0
	    grep 'end_checksums' $BOOTSTRAP_HTTPFILEINFO > /dev/null || OK=0
	    if [ "x$OK" == "x1" ]; then
		echo "Downloaded info file content seems sane."
		break
	    else
		echo "Problems with content of downloaded info file. Will retry in 5 seconds."
		sleep 5
	    fi
	done
	#Decode to find recent file:
	FILELINE=`grep '^vp1_.*_.*_.*.pool.root' $BOOTSTRAP_HTTPFILEINFO |grep -v "copy "|head -1|tr '\t' ' '`
	FILE=`echo $FILELINE|awk '{print $1}'`
	SUM=`echo $FILELINE|awk '{print $2}'`
	FILEURL=`echo $LIVEBOOTSTRAPSRC|sed 's#http://\(.*\)/.*$#http://\1/#'`$FILE
	echo FILE=$FILE
	echo FILEURL=$FILEURL
	echo SUM=$SUM
	OK=1
	BOOTSTRAPFILE_SUMFILE=$BOOTSTRAPFILE.md5sum
	rm -f $BOOTSTRAPFILE $BOOTSTRAPFILE_SUMFILE
	echo "Executing wget ${FILEURL} --output-document=$BOOTSTRAP_HTTPFILEINFO"
	wget ${FILEURL} --output-document=$BOOTSTRAPFILE || OK=0
	if [ $? != 0 ]; then
	    echo
	    echo "Download failed!"
	    echo
	    rm -f $BOOTSTRAPFILE $BOOTSTRAPFILE_SUMFILE
	    exit 1
	fi
	echo "$SUM  $BOOTSTRAPFILE" > $BOOTSTRAPFILE_SUMFILE
	if [ $? != 0 ]; then
	    echo
	    echo "Could not create md5sum check file"
	    echo
	    rm -f $BOOTSTRAPFILE $BOOTSTRAPFILE_SUMFILE
	    exit 1
	fi
	md5sum --status --check $BOOTSTRAPFILE_SUMFILE
	if [ $? != 0 ]; then
	    echo
	    echo "md5sum check of downloaded bootstrap event file failed!"
	    echo
	    rm -f $BOOTSTRAPFILE $BOOTSTRAPFILE_SUMFILE
	    exit 1
	fi
	echo "Checksum of downloaded Bootstrap event file is OK. Proceeding to launch athena."
    fi
elif [ "x$MULTINP_SRC" != "x" ]; then
    NEWEST=`ls -1rt $MULTINP_SRC/*_*_*.pool.root |tail -1`
    if [ ! -f $NEWEST ]; then
	echo
	echo "Could not find event file in $MULTINP_SRC to use to bootstrap athena. "
	echo
	exit 1
    fi
    cp $NEWEST -f $BOOTSTRAPFILE
    if [ $? != 0 -o ! -f $BOOTSTRAPFILE ]; then
	echo
	echo "Could not copy newest event file $BOOTSTRAPFILE!"
	echo
	rm -f $BOOTSTRAPFILE
	exit 1
    fi
fi

if [ "x$LOGFILE" != "x" ]; then
    athena.py $ATHENAOPTS  -c "$OPTS" $JOBOPT $EXTRAJOBOPT 2>&1|tee $LOGFILE
else
    athena.py $ATHENAOPTS  -c "$OPTS" $JOBOPT $EXTRAJOBOPT
fi

if [ "x$FLAG_DONTCLEANUPEVTCPY" != "x1" -a "x$MULTINP_CPY" != "x" ]; then
    if [ -d "${MULTINP_CPY}" -a -f "${MULTINP_CPY}/${BOOTSTRAPNAME}" ]; then
	rm -rf "${MULTINP_CPY}"
    fi
fi