All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
generateOverburdenConfigurations.sh
Go to the documentation of this file.
1 #!/usr/bin/env bash
2 
3 declare -r SCRIPTNAME="$(basename "$0")"
4 declare -r SCRIPTDIR="$(dirname "$0")"
5 declare -r SCRIPTVERSION="1.0"
6 
7 declare -Ar GenerationScriptNames=(
8  ['overburden']='makeOverburdenVersionOf.sh'
9  ['nooverburden']='makeNoOverburdenVersionOf.sh'
10  )
11 
12 declare -r FHiCLbaseDir="${ICARUSCODE_DIR}/fcl"
13 
14 declare -r JobListFileName="OverburdenConfigurations.txt"
15 
16 
17 # ------------------------------------------------------------------------------
18 declare -r EndLine=$'\n'
19 function STDERR() { echo "$*" >&2 ; }
20 function ERROR() { STDERR "ERROR: $*" ; }
21 function FATAL() {
22  local Code="$1"
23  shift
24  STDERR "FATAL(${Code}): $*"
25  exit "$Code"
26 } # FATAL()
27 
28 
29 # ------------------------------------------------------------------------------
30 function PrintHelp() {
31  cat <<EOH
32 Generates overburden and no-overburden versions of job file specified in
33 '${JobListFileName}'.
34 
35 Usage: ${SCRIPTNAME}
36 
37 This script must be run in a MRB development area with icarus_code checked out.
38 
39 EOH
40 
41 } # help()
42 
43 
44 # ------------------------------------------------------------------------------
45 function MakeUpName() {
46  local TemplateName="${1%.fcl}"
47  local Tag="$2"
48 
49  local Name="$TemplateName"
50 
51  while true ; do
52 
53  # policy change: always a modifier, does not replace "standard"
54  # Name="${Name/standard_/${Tag}_}"
55  # [[ "$Name" != "$TemplateName" ]] && break
56 
57  Name+="_${Tag}"
58 
59  break
60  done
61 
62  echo "${Name}.fcl"
63 
64 } # MakeUpName()
65 
66 
67 function GenerateConfigurationsFor() {
68  local FHiCLname="${1%.fcl}.fcl"
69 
70  #
71  # find the original FHiCL file (we need the full path);
72  # exclude "Deprecated" directories
73  #
74  local -a Matches=( $(find "$FHiCLbaseDir" -name "$FHiCLname" | grep -i -E -v '(/|^)Deprecated/' ) )
75  case "${#Matches[@]}" in
76  ( 0 )
77  ERROR "No configuration file '${FHiCLname}' found under '${FHiCLbaseDir}'"
78  return 2
79  ;;
80  ( 1 )
81  FHiCLpath="${Matches[0]}"
82  ;;
83  ( * )
84  ERROR "Multiple (${#Matches[@]}) configuration files '${FHiCLname}' found in '${FHiCLbaseDir}':${EndLine} ${Matches[@]/%/${EndLine} }"
85  return 2
86  esac
87 
88  #
89  # find the original FHiCL file (we need the full path)
90  #
91  local ScriptTag Script ConfName
92  local -a Cmd
93  local -i nErrors=0
94  for ScriptTag in "${!GenerationScriptPaths[@]}" ; do
95  Script="${GenerationScriptPaths["$ScriptTag"]}"
96 
97  ConfName="$(MakeUpName "$FHiCLname" "$ScriptTag")"
98 
99  echo "'${FHiCLname}' => '${ConfName}' ['${ScriptTag}']"
100  Cmd=( "$Script" "$FHiCLpath" "$ConfName" )
101  if [[ -n "${FAKE//0}" ]]; then
102  echo "$SHELL" "${Cmd[@]}"
103  else
104  "$SHELL" "${Cmd[@]}"
105  fi
106  if [[ $? != 0 ]]; then
107  ERROR "Failed to run ${ScriptTag} script on '${FHiCLpath}'"
108  let ++nErrors
109  continue
110  fi
111  done
112 
113  [[ $nErrors == 0 ]] # return value
114 } # GenerateConfigurationsFor()
115 
116 
117 # ------------------------------------------------------------------------------
118 #
119 # setup check
120 #
121 
122 # find scripts
123 declare -A GenerationScriptPaths
124 for ScriptTag in "${!GenerationScriptNames[@]}" ; do
125  ScriptName="${GenerationScriptNames[$ScriptTag]}"
126 
127  while true ; do
128 
129  ScriptPath="$(which "$ScriptName" 2> /dev/null)"
130  [[ $? == 0 ]] && break
131 
132  ScriptPath="${SCRIPTDIR}/${ScriptName}"
133  [[ $? == 0 ]] && break
134 
135  FATAL 2 "Could not locate the script '${ScriptName}'!"
136  done
137  GenerationScriptPaths+=( ["$ScriptTag"]="$ScriptPath" )
138 done
139 
140 # find job list
141 declare JobListFilePath
142 for CandidateDir in "$FHiCLbaseDir" "." ; do
143  JobListFilePath="${CandidateDir}/${JobListFileName}"
144  [[ -r "$JobListFilePath" ]] && break
145 done
146 [[ -r "$JobListFilePath" ]] || FATAL 2 "Couldn't find job list file '${JobListFileName}'"
147 
148 
149 # extract job list
150 declare Jobs
151 while read Line ; do
152  [[ -z "$Line" ]] && continue
153  [[ "${Line:0:1}" == "#" ]] && continue
154  FHiCLname="${Line%.fcl}.fcl"
155  Jobs+=( "$FHiCLname" )
156 done < "$JobListFilePath"
157 
158 
159 cat <<EOH
160 --- Setup ----------------------------------------------------------------------
161 Configuration base directory: '${FHiCLbaseDir}'
162 Job name list: '${JobListFileName}'
163 Generation scripts (${#GenerationScriptPaths[@]}):${GenerationScriptPaths[@]/#/${EndLine} }
164 Job configuration (${#Jobs[@]}):${Jobs[@]/#/${EndLine} }
165 --------------------------------------------------------------------------------
166 EOH
167 
168 # we need the full path of the FHiCL file
169 declare -i nErrors=0
170 for Job in "${Jobs[@]}"; do
171  GenerateConfigurationsFor "$Job" || let ++nErrors
172 done
173 
174 [[ "$nErrors" -gt 0 ]] && FATAL 1 "Detected ${nErrors} failures."
175 
176 
177 # ------------------------------------------------------------------------------
then echo FATAL
then echo ERROR
Definition: grid_setup.sh:42
* file
Definition: file_to_url.sh:69
SCRIPTNAME
Definition: publish.sh:21
process_name E
mrb MRB
Definition: submit_lar.sh:270
function STDERR()
Definition: utilities.sh:17
shift
Definition: fcl_checks.sh:26
then echo Sam station was not specified(use option--sam_station)." exit 1 fi if [ x$SAM_GROUP
process_name gaushit a
then local
do &&[[-z"$Line"]] continue &&[["${Line:0:1}"=="#"]] continue FHiCLname
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
BEGIN_PROLOG vertical distance to the surface Name
esac voms proxy info all source grid fermiapp products common etc setups sh source cvmfs oasis opensciencegrid org fermilab products larsoft setup setup ifdhc echo Here is the your environment in this job
Definition: run_job.sh:29
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 fcl name
esac echo uname r
list
Definition: file_to_url.sh:28
BEGIN_PROLOG don t mess with this pandoraTrackGausCryoW true