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