2 #------------------------------------------------------------------
6 # Purpose: Using an initial .json sam metadata file as an example,
7 # make additional metadata files for all .root files in a
12 # make_json.sh <example-json-file>
15 #------------------------------------------------------------------
20 echo "Usage: make_json.sh <example-json-file>"
32 while [ $# -gt 0 ]; do
43 if [ x$example = x ]; then
46 echo "Too many arguments."
56 # Make sure example file exists.
58 if [ ! -f $example ]; then
59 echo "Example file $example does not exist."
63 # Loop over .root files.
65 ls | grep '.root$' | while read root
68 # Construct the name of the .json file corresponding to this root file.
72 # If this .json file already exist, skip this file.
75 echo "$json already exists."
79 # Get the size in bytes of this root file.
81 size=`stat -c %s $root`
83 # Get number of events.
85 nev=`echo "Events->GetEntriesFast()" | root -l $root 2>&1 | tail -1 | cut -d')' -f2`
89 run=`echo $root | cut -d_ -f2 | cut -c2- | awk '{printf "%d\n",$0}'`
91 # Generate new .json file using example.
93 egrep -v 'file_name|file_size|event_count|last_event|runs' $example | \
94 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