All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fast_simulation_reconstruction_test.sh
Go to the documentation of this file.
1 #!/usr/bin/env bash
2 #
3 # Runs a fast simulation + reconstruction chain for test purposes
4 #
5 
6 #############################################################################
7 ### Tests to be executed in chain:
8 ###
9 declare -ar TestNames=(
10  'prod_eminus_0.1_0.9_sbnd'
11  'standard_g4_sbnd'
12  'standard_detsim_sbnd'
13  'standard_reco_sbnd_basic'
14 )
15 #############################################################################
16 
17 function ExecBase() {
18  local LogFile="$1"
19  shift
20  local -a Cmd=( "$@" )
21 
22  local -i res=0
23  if [[ -z "${FAKE//0}" ]]; then
24  if [[ -n "$LogFile" ]]; then
25  "${Cmd[@]}" >& "$LogFile"
26  res=$?
27  if [[ $res != 0 ]]; then
28  cat "$LogFile"
29  fi
30  else
31  "${Cmd[@]}"
32  res=$?
33  fi
34  else
35  echo " (skipped in dry run mode)"
36  fi
37  return $res
38 } # ExecBase()
39 
40 
41 function Exec() {
42  local LogFile="$1"
43  shift
44  local -a Cmd=( "$@" )
45 
46  echo "\$ ${Cmd[@]}${LogFile:+ >& ${LogFile}}"
47  ExecBase "$LogFile" "${Cmd[@]}"
48 } # Exec()
49 
50 
51 function ExecCommand() {
52  local LogFile="$1"
53  local CommandFile="$2"
54 
55  cat <<-EOH
56  \$ $(< "$CommandFile")${LogFile:+" >& ${LogFile}"}
57  ---------------------------------------------------------------------
58  EOH
59  ExecBase "$LogFile" 'sh' "$CommandFile"
60 } # ExecCommand()
61 
62 
63 function GetWorkDir() {
64  local TestName="$1"
65  echo "$TestName"
66 } # GetWorkDir()
67 
68 
69 function chdir() {
70  local DirName="$1"
71  mkdir "$DirName" && cd "$DirName"
72 } # chdir()
73 
74 function Link() {
75  local Source="$1"
76  local Target="$2"
77 
78  if [[ -d "$Target" ]]; then
79  Target="${Target%/}/$(basename "$Source")"
80  fi
81 
82  [[ -h "$Target" ]] && rm "$Target"
83  ln -s "$Source" "$Target"
84 } # Link()
85 
86 
87 function MakeCommandFile() {
88  local CommandFile="$1"
89  shift
90  rm -f "$CommandFile"
91  local Command
92  local Token
93  for Token in "$@" ; do
94  [[ -n "$Command" ]] && Command+=' '
95  Command+="'${Token}'"
96  done
97  echo "$Command" > "$CommandFile"
98  chmod a+x "$CommandFile"
99 } # MakeCommandFile()
100 
101 
102 # number of events to be generated
103 : ${NEvents:=1}
104 
105 #
106 # clean up from previous tests
107 #
108 for TestName in "${TestNames[@]}" ; do
109  WorkDir="$(GetWorkDir "$TestName")"
110  [[ -d "$WorkDir" ]] || continue
111  Exec '' rm -r "${WorkDir%/}/"
112 done
113 
114 InputFile=''
115 OutputTreeFile=''
116 BaseDir="$(pwd)"
117 declare -i iTest=0
118 declare -ir NTests="${#TestNames[@]}"
119 for TestName in "${TestNames[@]}" ; do
120  #
121  # For each test:
122  # - test name: <TestName>
123  # - working directory: <TestName>
124  # - configuration: <TestName>.fcl
125  # - input file: from the previous job
126  # - output files: <TestName>-art.root (art events)
127  # <TestName>-hist.root (TFileService)
128  # - log file: <TestName>.out
129  # - command run: run_<TestName>.cmd
130  #
131  # A link to the output file is placed into the base directory
132  #
133 
134  let ++iTest
135 
136  #
137  # move into a directory specific to the job
138  #
139  WorkDir="$(GetWorkDir "$TestName")"
140  Exec '' chdir "$WorkDir" || exit $?
141 
142  cat <<-EOH
143  =====================================================================
144  [${iTest}/${NTests}] Starting test: ${TestName}
145  =====================================================================
146  EOH
147 
148  ###
149  ### prepare the command
150  ###
151  declare -a Cmd=( 'lar' '--rethrow-all' )
152 
153  ConfigFile="${TestName}.fcl"
154  ConfigDumpFile="${ConfigFile%.fcl}.cfg"
155  Cmd=( "${Cmd[@]}" '--config' "$ConfigFile" '--config-out' "$ConfigDumpFile" )
156 
157  # prepare the input
158  if [[ -n "$OutputTreeFile" ]]; then
159  InputFile="$OutputTreeFile"
160  Cmd=( "${Cmd[@]}" '--source' "../${InputFile}" )
161  else
162  Cmd=( "${Cmd[@]}" '--nevts' "$NEvents" )
163  fi
164 
165  OutputTreeFile="${TestName}-art.root"
166  OutputHistFile="${TestName}-hist.root"
167  Cmd=( "${Cmd[@]}" '--output' "$OutputTreeFile" '--TFileName' "$OutputHistFile" )
168 
169 
170  ###
171  ### run the test
172  ###
173  LogFile="${TestName}.out"
174  CommandFile="run_${TestName}.cmd"
175  MakeCommandFile "$CommandFile" "${Cmd[@]}"
176  ExecCommand "$LogFile" "$CommandFile"
177  res=$?
178 
179  if [[ $res != 0 ]]; then
180  cat <<-EOM >&2
181  *********************************************************************
182  *** [${iTest}/${NTests}] Test '${TestName}' FAILED!!! (exit code: ${res})
183  *********************************************************************
184  EOM
185  exit $res
186  fi
187 
188  #
189  # place a link to the output in the base directory
190  #
191  Exec '' Link "${WorkDir}/${OutputTreeFile}" "${BaseDir%/}/"
192 
193  # go back to base dir
194  cd "$BaseDir"
195 
196 done
197 cat <<-EOM
198 =====================================================================
199 *** All ${NTests} tests succeeded.
200 =====================================================================
201 EOM
202 exit 0
203 
process_name opflash particleana ie ie ie z
process_name opflash particleana ie x
#define the
void Test(TFile *pFile=nullptr, bool statChecks=true)
shift
Definition: fcl_checks.sh:26
process_name gaushit a
while getopts h
then local
then shift fi
tuple dir
Definition: dropbox.py:28
do cd
then echo Work directory not specified exit fi echo Work directory
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG simSlidingORM6O6 effSlidingORW output
BEGIN_PROLOG hitmakerfive clustermakerfour pfparticlemakerthree showermakertwo END_PROLOG hitmakerfive clustermakerfour pfparticlemakerthree sequence::inline_paths sequence::inline_paths sequence::inline_paths showermakers test
esac echo uname r