All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndpoms_genfclwithrunnumber_maker.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 #source.firstSubRun: 1
4 #Subrun follows $PROCESS+1
5 #After every 100 subruns, a new run is started
6 export NSUBRUNSPERRUN=100
7 export WORKDIR="/sbnd/app/users/dbrailsf/generated_fcls"
8 export SAMDECLARE=false
9 
10 while :; do
11  case $1 in
12  -h|-\?|--help)
13  show_help # Display a usage synopsis.
14  exit
15  ;;
16  --fcl) # Takes an option argument; ensure it has been specified.
17  if [ "$2" ]; then
18  FCL="$2"
19  shift
20  else
21  echo "$0 ERROR: fcl requires a non-empty option argument."
22  exit 1
23  fi
24  ;;
25  --outdir) # Takes an option argument; ensure it has been specified.
26  if [ "$2" ]; then
27  OUTDIR="$2"
28  shift
29  else
30  echo "$0 ERROR: outdir requires a non-empty option argument."
31  exit 1
32  fi
33  ;;
34  --samdeclare)
36  ;;
37  --nfiles) # Takes an option argument; ensure it has been specified.
38  if [ "$2" ]; then
39  NFILES="$2"
40  shift
41  else
42  echo "$0 ERROR: nfiles requires a non-empty option argument."
43  exit 1
44  fi
45  ;;
46  --workdir) # Takes an option argument; ensure it has been specified.
47  if [ "$2" ]; then
48  WORKDIR="$2"
49  shift
50  else
51  echo "$0 ERROR: workdir requires a non-empty option argument."
52  exit 1
53  fi
54  ;;
55  --mdprojver) # Takes an option argument; ensure it has been specified.
56  if [ "$2" ]; then
58  shift
59  else
60  echo "$0 ERROR: mdprojver requires a non-empty option argument."
61  exit 1
62  fi
63  ;;
64  --mdprodname) # Takes an option argument; ensure it has been specified.
65  if [ "$2" ]; then
67  shift
68  else
69  echo "$0 ERROR: mdprodname requires a non-empty option argument."
70  exit 1
71  fi
72  ;;
73  --mdprodtype) # Takes an option argument; ensure it has been specified.
74  if [ "$2" ]; then
76  shift
77  else
78  echo "$0 ERROR: mdprodtype requires a non-empty option argument."
79  exit 1
80  fi
81  ;;
82  --mdstagename) # Takes an option argument; ensure it has been specified.
83  if [ "$2" ]; then
85  shift
86  else
87  echo "$0 ERROR: mdstagename requires a non-empty option argument."
88  exit 1
89  fi
90  ;;
91 
92  -v|--verbose)
93  verbose=$((verbose + 1)) # Each -v adds 1 to verbosity.
94  ;;
95  --) # End of all options.
96  shift
97  break
98  ;;
99  -?*)
100  printf "$0 WARN: Unknown option (ignored): %s\n" "$1" >&2
101  ;;
102  *) # Default case: No more options, so break out of the loop.
103  break
104  esac
105  shift
106 done
107 
108 if [ -z "$FCL" ]; then
109  echo "$0 ERROR: fcl is mandatory"
110  exit 2
111 fi
112 if [ -z "$OUTDIR" ]; then
113  echo "$0 ERROR: outdir is mandatory"
114  exit 2
115 fi
116 if [ -z "$NFILES" ]; then
117  echo "$0 ERROR: nfiles is mandatory"
118  exit 2
119 fi
120 if [ -z "$MDSBNDPROJECTVERSION" ]; then
121  echo "$0 ERROR: mdprojver is mandatory"
122  exit 2
123 fi
124 if [ -z "$MDPRODUCTIONNAME" ]; then
125  echo "$0 ERROR: mdprodname is mandatory"
126  exit 2
127 fi
128 if [ -z "$MDPRODUCTIONTYPE" ]; then
129  echo "$0 ERROR: mdprodtype is mandatory"
130  exit 2
131 fi
132 if [ -z "$MDSTAGENAME" ]; then
133  echo "$0 ERROR: mdstagename is mandatory"
134  exit 2
135 fi
136 
137 
138 echo "Running with the following settings:"
139 echo " fcl name: $FCL"
140 echo " outdir: $OUTDIR (note this will be appended with additional directory names!)"
141 echo " workdir: $WORKDIR"
142 echo " nfiles: $NFILES"
143 echo " sbnd project version: $MDSBNDPROJECTVERSION"
144 echo " production name: $MDPRODUCTIONNAME"
145 echo " production type: $MDPRODUCTIONTYPE"
146 echo " stage name: $MDSTAGENAME"
147 echo " Declare to SAM: $SAMDECLARE"
149 OUTDIR=$OUTDIR/$MDPRODUCTIONTYPE/$MDPRODUCTIONNAME/$MDSBNDPROJECTVERSION/${FCL%.*}
150 echo "The full output path is: $OUTDIR"
151 #make the directories
152 mkdir -p $OUTDIR
153 mkdir -p $WORKDIR
154 
155 #We need to extract what the default run number is. Let's get this from running lar and dumping the config
156 lar --debug-config lar_config_dump.txt -c $FCL
157 DEFAULTRUN=`grep -r "firstRun" lar_config_dump.txt`
158 #THis line is of the form firstRun: RUN
159 #We need to extract RUN
160 #Delimit on the colon
161 IFS=\: read -a DEFAULTRUNARRAY <<<"$DEFAULTRUN"
162 #Extract the run number
163 DEFAULTRUN=${DEFAULTRUNARRAY[1]}
164 
165 #starting making the files
166 NPROCESSEDFILES=0
167 #Needed to make subruns always start at 1
168 let "SUBRUNCANDIDATE= 0"
169 while [[ $NPROCESSEDFILES -lt $NFILES ]]
170 do
171 #Do arithmetic to modulo-ise the run number and subrun number whilst making sure subrun always starts at 1
172  let "SUBRUNCANDIDATE++"
173  RUNINCREMENT=$((SUBRUNCANDIDATE/NSUBRUNSPERRUN))
174  let "RUNNUMBER= $DEFAULTRUN + $RUNINCREMENT"
175  SUBRUNNUMBER=$((SUBRUNCANDIDATE%NSUBRUNSPERRUN))
176 #Never let subrun be 0
177  if [[ $SUBRUNNUMBER -eq 0 ]]
178  then
179  continue
180  fi
181 #We now have run and subrun number
182 #make the fcl
183  OUTFCL="${FCL%.*}_run${RUNNUMBER}_subrun${SUBRUNNUMBER}.fcl"
184  if [ -e $WORKDIR/$OUTFCL ]
185  then
186  rm $WORKDIR/$OUTFCL
187  fi
188  echo "Producing $WORKDIR/$OUTFCL"
189  echo -e "#include \"$FCL\"\n" \
190  "source.firstRun: $RUNNUMBER\n" \
191  "source.firstSubRun: $SUBRUNNUMBER" >> $WORKDIR/$OUTFCL
192  #Append all of the other metadata needed for the job
193  sbndpoms_metadata_injector.sh --inputfclname ${WORKDIR}/${OUTFCL} --mdfclname ${FCL} --mdprojectname ${FCL%.*} --mdprojectstage $MDSTAGENAME --mdprojectversion ${MDSBNDPROJECTVERSION} --mdprojectsoftware sbndcode --mdproductionname ${MDPRODUCTIONNAME} --mdproductiontype ${MDPRODUCTIONTYPE} --mdappversion ${MDSBNDPROJECTVERSION} --mdfiletype mc --mdappfamily art --mdruntype physics --tfilemdjsonname hist_${MDSTAGENAME}.root.json --mdgroupname sbnd
194 
195 
196  #make the fcl have a unique name (needed for SAM)
197  ifdh addOutputFile $WORKDIR/$OUTFCL
198  ifdh renameOutput unique
199  #Bit annoying but we now need to find the fcl file again as ifdh doesn't tell us what the unique name is
200  if [[ `find $WORKDIR -name ${OUTFCL%.*}*.fcl | wc -l` -ne 1 ]]
201  then
202  echo "Found incorrect number of matching fcl files for pattern: $OUTFCL"
203  find $WORKDIR -name ${OUTFCL%.*}*.fcl
204  echo "Exiting"
205  exit 3
206  fi
207  # OK so it looks like there it exactly one pattern match, so assume that is the correct one
208  UNIQUEOUTFCL=`find $WORKDIR -name ${OUTFCL%.*}*.fcl`
209  UNIQUEOUTFCL=`basename $UNIQUEOUTFCL`
210  #Copy the fcl to the output directory (most likely dcache)
211  ifdh copyBackOutput $OUTDIR
212  #Clear up
213  ifdh cleanup
214 
215 #echo $name
216 
217  #Now make a json
218  echo -e "
219  {
220  \"file_type\": \"mc\",
221  \"group\": \"sbnd\",
222  \"fcl.name\": \"$UNIQUEOUTFCL\",
223  \"sbnd_project.name\": \"${FCL%.*}\",
224  \"sbnd_project.stage\": \"fcl\",
225  \"sbnd_project.version\": \"$MDSBNDPROJECTVERSION\",
226  \"sbnd_project.software\": \"sbndcode\",
227  \"production.name\": \"$MDPRODUCTIONNAME\",
228  \"production.type\": \"$MDPRODUCTIONTYPE\",
229  \"data_tier\": \"initial-fcl\",
230  \"file_format\": \"fcl\",
231  \"start_time\": \"`date +"%FT%T"`\",
232  \"end_time\": \"`date +"%FT%T"`\",
233  \"runs\": [ [ $RUNNUMBER, $SUBRUNNUMBER, \"physics\" ] ],
234  \"event_count\": 0,
235  \"first_event\": -9999 ,
236  \"last_event\": -9999 ,
237  \"group\": \"sbnd\",
238  \"file_name\": \"$UNIQUEOUTFCL\",
239  \"file_size\": \"`wc -c < $WORKDIR/$UNIQUEOUTFCL`\",
240  \"checksum\":
241  `ifdh checksum $WORKDIR/$UNIQUEOUTFCL`
242 
243  }
244  " >> $WORKDIR/${UNIQUEOUTFCL}.json
245  if [ "$SAMDECLARE" = true ];
246  then
247  echo "Declaring ${UNIQUEOUTFCL} to SAM"
248  samweb -e sbnd declare-file ${WORKDIR}/${UNIQUEOUTFCL}.json
249  samweb -e sbnd add-file-location ${UNIQUEOUTFCL} $OUTDIR
250  fi
251  let "NPROCESSEDFILES++"
252 done
253 
254 
255 if [ "$SAMDECLARE" = true ];
256 then
257  echo "Making SAM dataset"
258  #Need to store the chopped up FCL name in a var as samweb has trouble parsing the %
259  TRUNCFCL=${FCL%.*}
260  samweb -e sbnd create-definition ${MDPRODUCTIONTYPE}_${MDPRODUCTIONNAME}_${FCL%.*}_initialfcl_sbnd "file_name like ${TRUNCFCL}%.fcl and sbnd_project.version $MDSBNDPROJECTVERSION and production.type $MDPRODUCTIONTYPE and production.name $MDPRODUCTIONNAME"
261 
262  samweb -e sbnd create-definition ${MDPRODUCTIONTYPE}_${MDPRODUCTIONNAME}_${FCL%.*}_initialfcl_sbnd "file_name like ${TRUNCFCL}%.fcl and sbnd_project.version $MDSBNDPROJECTVERSION and production.type $MDPRODUCTIONTYPE and production.name $MDPRODUCTIONNAME"
263 fi
264 
265 ##Calculate how much to increment the run by
266 #RUNINCREMENT=`python -c "print $SUBRUNCANDIDATE//$NSUBRUNSPERRUN"`
267 ##Calculate the run number
268 #let "RUNNUMBER= $DEFAULTRUN + $RUNINCREMENT"
269 ##Now the subrun
270 #SUBRUNNUMBER=`python -c "print $SUBRUNCANDIDATE % $NSUBRUNSPERRUN"`
271 #echo "#Metadata injection by $0" >> $FCL
272 #echo "source.firstRun: $RUNNUMBER" >> $FCL
273 #echo "source.firstSubRun: $SUBRUNNUMBER" >> $FCL
process_name standard_reco_uboone fcl
process_name opflash particleana ie ie ie z
then OUTDIR
then WORKDIR
process_name drop raw::OpDetWaveforms_DataApr2016RecoStage1_saturation_ * physics
* file
Definition: file_to_url.sh:69
pdgs p
Definition: selectors.fcl:22
#define the
shift
Definition: fcl_checks.sh:26
usage
Definition: doGit.sh:21
then echo Sam station was not specified(use option--sam_station)." exit 1 fi if [ x$SAM_GROUP
process_name gaushit a
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
while getopts h
v let verbose
FCL
Definition: condor_lar.sh:205
then echo fcl sbnd_project sbnd_project sbnd_project sbnd_project production production $SUBRUNNUMBER
then shift fi
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG simSlidingORM6O6 effSlidingORW output
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker options
do i e
stream1 can override from command line with o or output services user sbnd
then echo fcl name
echo Invalid option
Definition: TrainMVA.sh:17
then echo find_global_symbol finds mangled or demangled symbols in libraries echo within LD_LIBRARY_PATH match any symbol that echo contains name echo Default
esac echo uname r
BEGIN_PROLOG don t mess with this pandoraTrackGausCryoW true
bool Update(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, PFPStruct &pfp, bool prt)
Definition: PFPUtils.cxx:1057
shift break
Definition: just_cmake.sh:60