iceberg_metadata.sh
Go to the documentation of this file.
1 #!/bin/sh
2 
3 # creates metadata for one or more iceberg raw data files. Puts JSON files in the
4 # current working directory.
5 
6 # invoke this as iceberg_metadata.sh <input>
7 # where <input> is a file path, or a directory. It is the input to a find command
8 
9 function iceberg_metadata_single_file {
10 
11 CFNAME=`mktemp`
12 config_dumper -P $1 | sed -e "s/\\\n/\n/g" > ${CFNAME}
13 
14 TMPMD=`mktemp`
15 sam_metadata_dumper $1 > ${TMPMD}
16 
17 CMPFILE=`mktemp`
18 grep Component $CFNAME | awk '{print $3}' > $CMPFILE
19 
20 gain=`grep "gain:" $CFNAME | head -1 | awk '{print $2}'`
21 shapetime=`grep "peak_time:" $CFNAME | head -1 | awk '{print $2}'`
22 accouple=`grep "ac_couple:" $CFNAME | head -1 | awk '{print $2}'`
23 baselineHigh=`grep "baseline:" $CFNAME | head -1 | awk '{print $2}'`
24 leakHigh=`grep "leak:" $CFNAME | head -1 | awk '{print $2}'`
25 leak10x=`grep "leak_10x:" $CFNAME | head -1 | awk '{print $2}'`
26 if [[ ${leak10x} = false ]]; then
27  leak10x=0
28 else
29  leak10x=1
30 fi
31 pulsemode=`grep "enable_pulser:" $CFNAME | head -1 | awk '{print $2}'`
32 if [[ ${pulsemode} = false ]]; then
33  pulsemode=0
34 else
35  pulsemode=1
36 fi
37 configname=`grep "Config name:" $CFNAME | head -1 | awk '{print $3}'`
38 
39 runno=`grep first_event $TMPMD | head -1 | awk '{print $3}' | sed -e "s/,//g"`
40 firstevent=`grep first_event $TMPMD | head -1 | awk '{print $5}'`
41 lastevent=`grep last_event $TMPMD | head -1 | awk '{print $5}'`
42 eventcountline=`grep event_count $TMPMD | head -1 | sed -e "s/,//g"`
43 starttimeline=`grep start_time $TMPMD | head -1 | sed -e "s/,//g"`
44 endtimeline=`grep end_time $TMPMD | head -1 | sed -e "s/,//g"`
45 
46 echo "{"
47 echo \ \"file_name\": \"`basename $1`\",
48 echo \ \"file_type\": \"detector\",
49 echo \ \"data_tier\": \"raw\",
50 echo \ \"file_size\": `stat -c%s $1`,
51 echo \ ${starttimeline},
52 echo \ ${endtimeline},
53 echo \ ${eventcountline},
54 echo \ \"first_event\": ${firstevent},
55 echo \ \"last_event\": ${lastevent},
56 echo \ \"runs\": [
57 echo \ \ [
58 echo \ \ ${runno},
59 echo \ \ 1,
60 echo \ \ \"iceberg\"
61 echo \ \ ]
62 echo \ ],
63 echo \ \"DUNE.campaign\": \"iceberg\",
64 echo \ \"data_stream\": \"cosmics\",
65 echo \ \"DUNE_data.fegain\": ${gain},
66 echo \ \"DUNE_data.feshapingtime\": ${shapetime},
67 echo \ \"DUNE_data.acCouple\": ${accouple},
68 echo \ \"DUNE_data.febaselineHigh\": ${baselineHigh},
69 echo \ \"DUNE_data.feleakHigh\": ${leakHigh},
70 echo \ \"DUNE_data.feleak10x\": ${leak10x},
71 echo \ \"DUNE_data.calibpulsemode\": ${pulsemode},
72 echo \ \"DUNE_data.DAQConfigName\": \"${configname}\",
73 cat $CMPFILE |
74 {
75 while read line2
76 do
77  if [ "$components" = "" ]; then
78  components=$line2
79  else
80  components=${line2}:${components}
81  fi
82 done
83  echo \ \"DUNE_data.detector_config\": \"${components}\"
84 }
85 echo "}"
86 
87 rm ${CFNAME}
88 rm ${TMPMD}
89 rm ${CMPFILE}
90 
91 }
92 
93 source /home/nfs/dunecet/offlsetup.sh
94 source /cvmfs/oasis.opensciencegrid.org/mis/osg-wn-client/current/el7-x86_64/setup.sh
95 setup_fnal_security
96 
97 find $1 | grep iceberg | grep root | grep -v decode | grep -v json | grep -v anal | while read line
98 do
99  echo Making metadata json for $line
100  jsonfile=`basename $line`.json
101  if [ -e $jsonfile ]; then
102  echo $jsonfile already exists, not re-making it.
103  else
104  iceberg_metadata_single_file $line > $jsonfile
105  samweb declare-file $jsonfile
106  fi
107  echo "mv'ing $line to the dropbox"
108  mv $line /data1/dropbox/
109 done