testgeo.sh
Go to the documentation of this file.
1 #!/bin/bash
2 #
3 # DUNE geometry tests.
4 # Usage:
5 #
6 # testgeo.sh [Geometry ...]
7 #
8 # Default geometries defined in DEFAULT_GEOMETRIES below.
9 #
10 # Copied from larcore/Geometry/test/testgeo.csh .
11 #
12 
13 DEFAULT_GEOMETRIES=( 'dunefd' )
14 INCLUDE_FILES=( 'geometry_dune.fcl' )
15 
16 
17 ################################################################################
18 function TestGeometry() {
19  local Geometry="$1"
20 
21  echo "Testing geometry for ${Geometry}"
22 
23  local ConfigFile="test_${Geometry}_geometry.fcl"
24 
25  # preamble and prologue
26  cat <<-EOC > "$ConfigFile"
27  #
28  # Test for ${Geometry} geometry
29  #
30  BEGIN_PROLOG
31  # this item will be included by geotest.fcl: we need a temporary fake one
32  detector_geo: {}
33  END_PROLOG
34 
35  EOC
36 
37  # add include files as needed
38  local IncludeFile
39  for IncludeFile in "${INCLUDE_FILES[@]}" ; do
40  echo "#include \"${IncludeFile}\"" >> "$ConfigFile"
41  done
42 
43  # overriding the original template file
44  cat <<-EOC >> "$ConfigFile"
45 
46  # geotest.fcl is provided by larcore (larcore/Geometry/test)
47  #include "geotest.fcl"
48 
49  services.user.Geometry: @local::${Geometry}_geo
50  services.user.ExptGeoHelperInterface: @local::dune_geometry_helper
51  EOC
52 
53  local LogFile="${ConfigFile%.fcl}.log"
54  local res
55  lar -c "$ConfigFile" 2>&1 | tee "$LogFile"
56  res=${PIPESTATUS[0]}
57 
58  echo "Test completed with exit code ${res}, log file: ${LogFile}"
59  if [[ $res == 0 ]]; then
60  rm -f "$ConfigFile" *.root
61  fi
62 
63  return "$res"
64 } # TestGeometry()
65 
66 
67 ################################################################################
68 declare -a Geometries
69 if [[ $# -gt 0 ]]; then
70  Geometries=( "$@" )
71 else
72  Geometries=( "${DEFAULT_GEOMETRIES[@]}" )
73 fi
74 
75 declare -i nTests=0 nErrors=0
76 for Geometry in "${Geometries[@]}" ; do
77  let ++nTests
78  TestGeometry "$Geometry"
79  res=$?
80  [[ $res != 0 ]] && let ++nErrors
81 done
82 
83 if [[ $nErrors == 0 ]]; then
84  echo "All ${nTests} tests successfully completed."
85 else
86  echo "${nErrors} tests out of ${nTests} failed."
87 fi
88 exit $nErrors