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 v06_19_00 -q e10:prof
28 echo "Usage: make_metadata35t_declare.sh <rootfiledirectory> <failedfiledirectory> <dirtofindexamplejson> <dirforfilelist>"
38 if [ $1 = "--help" ]; then
49 example=$DHDIR/exampleSlice.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, so deleting it"
68 size=`stat -c %s $root`
71 echo "$0 Failed to get filesize for $root"
75 nev=`echo "Events->GetEntriesFast()" | root -l -b $root 2>&1 | tail -1 | cut -d')' -f2`
78 echo "$0 Failed to get event count for $root"
82 run=`echo $root | cut -d_ -f2 | cut -c2- | awk '{printf "%d\n",$0}'`
85 echo "$0 Failed to get run number for $root"
89 echo "Got all my parameters"
91 egrep -v 'file_name|file_size|event_count|last_event|runs' $example | \
92 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}}" > Tempjson1.txt
98 echo "$0 Failed to replace metadata for $root"
99 mv $json $fdir/$json.failed
103 echo "Now to set the parent files"
106 while [ ${#Myrun} -ne 6 ];
110 echo '"parents": [' > TempParent1.txt
111 samweb list-definition-files rawdata35t_run_$Myrun >> TempParent2.txt
112 cat TempParent1.txt TempParent2.txt > TempParent3.txt
113 lines=$(wc -l < "TempParent3.txt")
114 echo "TempParent3.txt has $lines lines"
115 sed 's/lbne/{"file_name": "lbne/' TempParent3.txt > TempParent4.txt
116 sed 's/.root/.root"},/' TempParent4.txt > TempParent5.txt
117 sed -e "$lines s/,/\n],/" < TempParent5.txt > Tempjson2.txt
119 echo "Done the parent file"
121 $DHDIR/dbjson.py $run >> Tempjson3.txt
122 cat Tempjson1.txt Tempjson2.txt Tempjson3.txt > $json
124 if [ $? -ne 0 ]; then
126 echo "$0 Failed to query online database for $root"
127 mv $json $fdir/$json.failed
131 echo "Done all I'm happy to do so far......"
134 echo "Declaring metadata to SAM: $json"
135 #samweb -e dune declare-file --cert=/dune/app/home/dunepro/trj/service_cert_dec9_2015/duneprocert_dec2015.pem --key=/dune/app/home/dunepro/trj/service_cert_dec9_2015/duneprokey_dec2015.pem $json
136 samweb -e dune declare-file $json
137 echo "Tried to declare"
138 if [ $? -ne 0 ]; then
140 echo "$0 Failed to declare metadata to SAM"
141 mv $json $fdir/$json.failed
144 echo "Finished declaring $json"
146 mv $root /pnfs/dune/scratch/dunepro/dropbox/data/
147 echo "Moved $root to dropbox"
149 rm -f TempRunning.txt
150 echo "$root $size $run $nev" >> $filelistdir/GoodFileList.txt
151 RunningFile=/dune/data2/lbnepro/AutoSlice/GoodFileList/RunningList.txt
152 printf "%06d\n" $run >> $RunningFile
153 sort --version-sort $RunningFile > TempRunning.txt
154 uniq -u TempRunning.txt > $RunningFile
155 rm -f TempRunning.txt
156 echo "Removed $run from the Running File List in $RunningFile"