3 #------------------------------------------------------------------
5 # Name: make_metadata_35t.sh
7 # Purpose: Using an initial .json sam metadata file as an example,
8 # make additional metadata files for all .root files in a
13 # make_metadata35t.sh <rootfiledirectory> <failedfiledirectory>
14 # if the metadata extraction procedure fails, then move the rootfile to the failedfiledirectory
16 # Tom Junk, using the make_json.sh example from Qizhong Li
17 #------------------------------------------------------------------
19 source /grid/fermiapp/products/dune/setup_dune.sh
20 setup dunetpc v04_29_00 -q e9:prof
28 echo "Usage: make_metadata35t_declare.sh <rootfiledirectory> <failedfiledirectory> <dirtofindexamplejson> <dirforfilelist>"
38 if [ $1 = "--help" ]; then
49 example=$DHDIR/example2.json
53 ls | grep lbne_r | grep '.root$' | while read root
58 # If this .json file already exist, skip this file.
61 echo "$json already exists."
66 size=`stat -c %s $root`
69 echo "$0 Failed to get filesize for $root"
73 nev=`echo "Events->GetEntriesFast()" | root -l -b $root 2>&1 | tail -1 | cut -d')' -f2`
76 echo "$0 Failed to get event count for $root"
80 run=`echo $root | cut -d_ -f2 | cut -c2- | awk '{printf "%d\n",$0}'`
83 echo "$0 Failed to get run number for $root"
88 egrep -v 'file_name|file_size|event_count|last_event|runs' $example | \
89 awk '{print $0}/^{ *$/{printf " \"file_name\": \"%s\",\n \"file_size\": %d,\n \"event_count\": %d,\n \"last_event\": %d,\n \"runs\": [ [ %d, \"test\" ] ],\n",'"\"$root\",${size},${nev},${nev},${run}}" > $json
93 echo "$0 Failed to replace metadata for $root"
94 mv $json $fdir/$json.failed
99 $DHDIR/dbjson.py $run >> $json
100 if [ $? -ne 0 ]; then
102 echo "$0 Failed to query online database for $root"
103 mv $json $fdir/$json.failed
108 echo "Declaring metadata to SAM: $json"
109 # old certificate -- switch to new one Dec. 11, 2015
110 # samweb -e lbne declare-file --cert=${DHDIR}/duneprocert.pem --key=${DHDIR}/duneprokey.pem $json
111 samweb -e lbne declare-file --cert=${DHDIR}/duneprocert_dec2015.pem --key=${DHDIR}/duneprokey_dec2015.pem $json
112 if [ $? -ne 0 ]; then
114 echo "$0 Failed to declare metadata to SAM"
115 mv $json $fdir/$json.failed
118 echo "Finished declaring $json"
120 echo "$root $size $run $nev" >> $filelistdir/filelist.txt
121 cp $filelistdir/filelist.txt /web/sites/dune-data.fnal.gov/htdocs/data/35t/testfiles/