3 # Define the output directories
4 # These will be appended with metadata info
5 WORKDIR=
"/pnfs/sbnd/scratch/$USER/mcp"
6 OUTDIR=
"/pnfs/sbnd/persistent/$USER/mcp"
7 # Concatenate files together up to 1GB
13 show_help # Display
a usage synopsis.
22 echo
"$0 ERROR: defname requires a non-empty option argument."
32 echo
"$0 ERROR: workdir requires a non-empty option argument."
42 echo
"$0 ERROR: outdir requires a non-empty option argument."
52 echo
"$0 ERROR: size requires a non-empty option argument."
70 echo
"$0 ERROR: defname is mandatory"
76 echo
"$0 ERROR: workdir is mandatory"
82 echo
"$0 ERROR: outdir is mandatory"
88 echo
"$0 ERROR: size is mandatory"
92 echo
"Running with settings:"
93 echo
" Definition: $DEFNAME"
94 echo
" Workdir: $WORKDIR"
95 echo
" Outdir: $OUTDIR"
96 echo
" Max Size: $(numfmt --to=si $MAXSIZE)"
97 if [ ! -
z "$FLATTEN" ]
99 echo
" Making Flat CAFS"
103 echo
" Cleaning all outputs"
108 # Assume that the metadata is roughly the same in all files, so take the first
112 # Lets change
"caf" to
"concat_caf" for the stage and defname
113 MDPRODUCTIONDEFNAME=${
DEFNAME/caf/concat_caf}
115 # Now we want to set some global vars to define the ouput path
119 MDSBNDPROJECTNAME=$(jq -
r '."sbnd_project.name"' base.json)
121 MDSBNDPROJECTSTAGE=$(jq -
r '."sbnd_project.stage"' base.json)
123 if [ $(
samweb -
e sbnd list-definitions | grep
"$MDPRODUCTIONDEFNAME") ]
127 echo
"Deleting SAM Definition $MDPRODUCTIONDEFNAME"
133 samweb delete-definition $MDPRODUCTIONDEFNAME
135 echo
"SAM Definition $MDPRODUCTIONDEFNAME already present"
139 echo
"Creating SAM Definition $MDPRODUCTIONDEFNAME"
142 if [ ! -
z "$FLATTEN" ]
144 FLATMDPRODUCTIONDEFNAME=${MDPRODUCTIONDEFNAME/concat_caf/flat_caf}
145 if [ $(
samweb -
e sbnd list-definitions | grep
"$FLATMDPRODUCTIONDEFNAME") ]
149 echo
"Deleting SAM Definition $FLATMDPRODUCTIONDEFNAME"
155 samweb delete-definition $FLATMDPRODUCTIONDEFNAME
157 echo
"SAM Definition $FLATMDPRODUCTIONDEFNAME already present"
161 echo
"Creating SAM Definition $FLATMDPRODUCTIONDEFNAME"
165 OUTDIR=
"$OUTDIR/$MDFILETYPE/$MDPRODUCTIONTYPE/$MDPRODUCTIONNAME/$MDSBNDPROJECTNAME/$MDSBNDPROJECTVERSION/$MDSBNDPROJECTSTAGE"
166 WORKDIR=
"$WORKDIR/$MDFILETYPE/$MDPRODUCTIONTYPE/$MDPRODUCTIONNAME/$MDSBNDPROJECTNAME/$MDSBNDPROJECTVERSION/$MDSBNDPROJECTSTAGE"
171 if [ -
z "$(ls -A $WORKDIR)" ]
173 echo
"WORKDIR: $WORKDIR"
174 elif [ ! -
z "$CLEAN" ]
176 echo
"Deleting WORKDIR: $WORKDIR"
177 ifdh
rmdir $WORKDIR --force=srm
179 echo
"Not Empty: $WORKDIR"
183 if [ -
z "$(ls -A $OUTDIR)" ]
185 echo
"OUTDIR: $OUTDIR"
186 elif [ ! -
z "$CLEAN" ]
188 echo
"Deleting OUTDIR: $OUTDIR"
189 ifdh
rmdir $OUTDIR --force=srm
191 echo
"Not Empty: $OUTDIR"
196 # TODO put
this into
a proper script
and pass arguments rather than rely on global variables
197 # This would allow us to run
this in a background process
and multithread
the process
202 CONCATNAME=
"concat_caf_${SLICENUM}.root"
203 CONCATFILE=
"$WORKDIR/$CONCATNAME"
204 JSONFILE=
"${CONCATFILE}.json"
206 echo
"Creating $CONCATNAME"
208 # Let ROOT run its magic
209 concat_cafs $SLICEDEFNAME $WORKDIR/$CONCATNAME
211 extractCAFMetadata
"$CONCATFILE" > $JSONFILE
213 # Steal the ifdh and sam commands from sbndpoms_genfclwithrunnumber_maker.sh (Thanks Dom)
214 # SAM needs the file to have a unique name
215 ifdh addOutputFile $CONCATFILE
216 ifdh renameOutput unique
218 # Bit annoying but we now need to find the fcl file again as ifdh doesn't tell us what the unique name is
219 if [[ `find $WORKDIR -
name "${CONCATNAME%.*}*.root" | wc -l` -ne 1 ]]
221 echo
"Found incorrect number of matching files for pattern: ${CONCATNAME%.*}*.root"
222 find $WORKDIR -
name "${CONCATNAME%.*}*.root"
226 UNIQUEOUTCONCATNAME=`find $WORKDIR -
name "${CONCATNAME%.*}*.root"`
227 UNIQUEOUTCONCATNAME=`basename $UNIQUEOUTCONCATNAME`
228 echo
"$CONCATNAME renamed to $UNIQUEOUTCONCATNAME"
231 # OK so it looks like there is exactly one pattern match, so assume that is the correct one
232 #Copy the file to the output directory (most likely dcache)
233 ifdh copyBackOutput $OUTDIR
237 sbndpoms_metadata_extractor.sh
"$WORKDIR/$UNIQUEOUTCONCATNAME"
242 # Check that we find the output file, this will tell us if SAM actually crea
243 if [[ ! -f
"$(samweb -e sbnd locate-file $UNIQUEOUTCONCATNAME | sed 's/enstore://')/$UNIQUEOUTCONCATNAME" ]]
245 echo
"Output file $UNIQUEOUTCONCATNAME not found in outdir $OUTDIR"
249 echo
"$UNIQUEOUTCONCATNAME declared and located by SAM"
251 if [ ! -
z "$FLATTEN" ]
253 echo
"Flattening $UNIQUEOUTCONCATNAME"
255 FLATNAME=
"flat_caf_${SLICENUM}.root"
256 FLATFILE=
"$WORKDIR/$FLATNAME"
257 FLATJSONFILE=
"${FLATFILE}.json"
258 flatten_caf $OUTDIR/$UNIQUEOUTCONCATNAME $FLATFILE
260 extractCAFMetadata
"$FLATFILE" >
"$FLATJSONFILE"
262 # Steal the ifdh and sam commands from sbndpoms_genfclwithrunnumber_maker.sh (Thanks Dom)
263 # SAM needs the file to have a unique name
264 ifdh addOutputFile $FLATFILE
265 ifdh renameOutput unique
267 # Bit annoying but we now need to find the fcl file again as ifdh doesn't tell us what the unique name is
268 if [[ `find $WORKDIR -
name "${FLATNAME%.*}*.root" | wc -l` -ne 1 ]]
270 echo
"Found incorrect number of matching files for pattern: ${FLATNAME%.*}*.root"
271 find $WORKDIR -
name "${FLATNAME%.*}*.root"
275 UNIQUEOUTFLATNAME=`find $WORKDIR -
name "${FLATNAME%.*}*.root"`
276 UNIQUEOUTFLATNAME=`basename $UNIQUEOUTFLATNAME`
277 echo
"$FLATNAME renamed to $UNIQUEOUTFLATNAME"
280 # OK so it looks like there it exactly one pattern match, so assume that is the correct one
281 #Copy the file to the output directory (most likely dcache)
282 ifdh copyBackOutput $OUTDIR
286 sbndpoms_metadata_extractor.sh
"$WORKDIR/$UNIQUEOUTFLATNAME"
291 # Check that we find the output file, this will tell us if SAM actually crea
292 if [[ ! -f
"$(samweb -e sbnd locate-file $UNIQUEOUTFLATNAME | sed 's/enstore://')/$UNIQUEOUTFLATNAME" ]]
294 echo
"Output file $UNIQUEOUTFLATNAME not found in outdir $OUTDIR"
298 echo
"$UNIQUEOUTFLATNAME declared and located by SAM"
309 declare -i CONCATCOUNT=0
310 declare -i SLICENUM=0
311 declare -i FILECOUNTER=0
313 # Loop over all of the files in the dataset
314 DEFSIZE=$(
samweb -
e sbnd list-definition-files --summary $DEFNAME | grep
"Total size" | tr -dc
'0-9')
317 # Work out the size of each file
318 FILESIZE=$(( $DEFSIZE / $FILECOUNT ))
319 # Work out the max number of file to concat together
320 SLICELIMIT=$(( $MAXSIZE / $FILESIZE ))
321 # Work out the number of concats this will result in
322 CONCATCOUNT=$(( $FILECOUNT / $SLICELIMIT ))
323 CONCATCOUNT=$(( CONCATCOUNT + 1 ))
324 # Spread the files evenly between the CONCATS
325 FILELIMIT=$(( $FILECOUNT / $CONCATCOUNT ))
326 FILELIMIT=$(( FILELIMIT + 1 ))
328 echo
"DefSize: $DEFSIZE and FileCount: $FILECOUNT"
329 echo
"FileSize: $FILESIZE and FileLimit: $FILELIMIT"
330 echo
"ConcatCount: $CONCATCOUNT"
332 while [[ $SLICENUM -lt $CONCATCOUNT ]]
334 FILECOUNTER=$(( $SLICENUM * $FILELIMIT ))
335 echo
"Creating Slice: $SLICENUM, starting from file: $FILECOUNTER"
337 SLICEDEFNAME=${
DEFNAME}_Slice${SLICENUM}
338 samweb -
e sbnd create-definition
"$SLICEDEFNAME" "defname: $DEFNAME with limit $FILELIMIT with offset $FILECOUNTER"
345 # Create a definition with the output files
346 samweb -
e sbnd create-definition $MDPRODUCTIONDEFNAME
"file_name like concat_caf_%.root and file_type $MDFILETYPE and production.type $MDPRODUCTIONTYPE and production.name $MDPRODUCTIONNAME and sbnd_project.name $MDSBNDPROJECTNAME and sbnd_project.version $MDSBNDPROJECTVERSION and sbnd_project.stage $MDSBNDPROJECTSTAGE and ischildof: ( defname: $DEFNAME ) and file_format concat_caf"
347 echo
"Created Concat SAM definition: $MDPRODUCTIONDEFNAME: $(samweb -e sbnd list-definition-files --summary $MDPRODUCTIONDEFNAME)"
349 if [ ! -
z "$FLATTEN" ]
351 samweb -
e sbnd create-definition $FLATMDPRODUCTIONDEFNAME
"file_name like flat_caf_%.root and file_type $MDFILETYPE and production.type $MDPRODUCTIONTYPE and production.name $MDPRODUCTIONNAME and sbnd_project.name $MDSBNDPROJECTNAME and sbnd_project.version $MDSBNDPROJECTVERSION and sbnd_project.stage $MDSBNDPROJECTSTAGE and ischildof: ( defname: $DEFNAME ) and file_format flat_caf"
352 echo
"Created Flat SAM definition: $FLATMDPRODUCTIONDEFNAME: $(samweb -e sbnd list-definition-files --summary $FLATMDPRODUCTIONDEFNAME)"
process_name opflash particleana ie ie ie z
then source cvmfs dune opensciencegrid org products dune setup_dune sh exit elif[-f/grid/fermiapp/products/dune/setup_dune_fermiapp.sh]
std::size_t size(FixedBins< T, C > const &) noexcept
then MDSBNDPROJECTVERSION
then echo Sam station was not specified(use option--sam_station)." exit 1 fi if [ x$SAM_GROUP
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
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
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
stream1 can override from command line with o or output services user sbnd
size if["$2"] then MAXSIZE
defname if["$2"] then DEFNAME
basic_json<> json
default JSON class
std::size_t count(Cont const &cont)