All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndpoms_artroot_metadata_extractor.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 
5 OUTPUTFILE="${1}.json"
6 
7 #dump the output to a json file
8 sam_metadata_dumper $INPUTFILE > $OUTPUTFILE
9 
10 #we need to remove the 2nd line from the json file (the name of the file without the file_name label, we will re-add the filename using the argument later on
11 sed -i '2d' $OUTPUTFILE
12 
13 #we need to remove the 2nd to last line of the file which contains the additional curly brace that went with the incorrect syntax filename
14 #Get the number of lines in the file
15 NLINES=`cat $OUTPUTFILE | wc -l`
16 let SECONDLASTLINENO=NLINES-1
17 sed -i "${SECONDLASTLINENO}d" $OUTPUTFILE
18 
19 #We need to remove the braces at the end of the file as we are going to append more information
20 sed -i '$ d' $OUTPUTFILE
21 #We also need to add a comma to the end of the last line now that we are going to add more line
22 sed -i '$ s/$/\,/g' $OUTPUTFILE
23 
24 #Remove the lines that are bad
25 #run_type
26 sed -i '/run_type/d' $OUTPUTFILE
27 ##applicationVersion
28 #sed -i '/applicationVersion/d' $OUTPUTFILE
29 ##applicationFamily
30 #sed -i '/applicationFamily/d' $OUTPUTFILE
31 ##process_name
32 #sed -i '/process_name/d' $OUTPUTFILE
33 ##fclVersion
34 sed -i '/fclVersion/d' $OUTPUTFILE
35 ##file_format_era
36 sed -i '/file_format_era/d' $OUTPUTFILE
37 ##file_format_version
38 sed -i '/file_format_version/d' $OUTPUTFILE
39 
40 #Define the application object
41 #First collect application name
42 APPNAME=`grep "process_name" $OUTPUTFILE`
43 #Now remove it from the json
44 sed -i '/process_name/d' $OUTPUTFILE
45 #Separate APPNAME on the comma
46 FS=\: read -a APPNAMEARRAY <<<"$APPNAME"
47 #Collect the value of the process_name i.e. SinglesGen
48 APPNAME=${APPNAMEARRAY[1]}
49 #Remove the comma if there is one
50 APPNAME=`echo ${APPNAME} | sed 's/,//g'`
51 #Do the same for application family
52 APPFAMILY=`grep "application.family" $OUTPUTFILE`
53 sed -i '/application.family/d' $OUTPUTFILE
54 FS=\: read -a APPFAMILYARRAY <<<"$APPFAMILY"
55 APPFAMILY=${APPFAMILYARRAY[1]}
56 APPFAMILY=`echo ${APPFAMILY} | sed 's/,//g'`
57 #and the app version
58 APPVERSION=`grep "application.version" $OUTPUTFILE`
59 sed -i '/application.version/d' $OUTPUTFILE
60 FS=\: read -a APPVERSIONARRAY <<<"$APPVERSION"
61 APPVERSION=${APPVERSIONARRAY[1]}
62 APPVERSION=`echo ${APPVERSION} | sed 's/,//g'`
63 #Now constrcut the application object
64 echo "\"application\" : {" >> $OUTPUTFILE
65 echo "\"name\": $APPNAME," >> $OUTPUTFILE
66 echo "\"family\": $APPFAMILY," >> $OUTPUTFILE
67 echo "\"version\": $APPVERSION" >> $OUTPUTFILE
68 echo "}," >> $OUTPUTFILE
69 
70 #Correct first_event
71 #Get the line
72 FIRSTEVENTLINE=`grep "first_event" $OUTPUTFILE`
73 #extract the number from the line
74 FIRSTEVENTNO=`echo $FIRSTEVENTLINE | cut -d "[" -f2 | cut -d "]" -f1 | cut -d "," -f3`
75 #Replace the old line with a newly constructed one
76 sed -i "s/.*first_event.*/\"first_event\": $FIRSTEVENTNO,/" $OUTPUTFILE
77 
78 #Correct last_event
79 #Get the line
80 LASTEVENTLINE=`grep "last_event" $OUTPUTFILE`
81 #extract the number from the line
82 LASTEVENTNO=`echo $LASTEVENTLINE | cut -d "[" -f2 | cut -d "]" -f1 | cut -d "," -f3`
83 #Replace the old line with a newly constructed one
84 sed -i "s/.*last_event.*/\"last_event\": $LASTEVENTNO,/" $OUTPUTFILE
85 
86 #Add the filename back in
87 echo "\"file_name\": \"`basename $INPUTFILE`\"," >> $OUTPUTFILE
88 #Add the file size
89 FILESIZE=`wc -c < $INPUTFILE`
90 echo "\"file_size\": \"$FILESIZE\"," >> $OUTPUTFILE
91 
92 #production.name, which is a string, can contain only numbers. sam_metadata_dumper will convert this value to a double which makes the metadata invalid.
93 #We need to ensure that production.name's value is a string
94 #Store production.name
95 PRODUCTIONNAME=`grep "production.name" $OUTPUTFILE`
96 #Split the Key : Value on the colon
97 IFS=\: read -a PRODUCTIONNAMEARRAY <<<"$PRODUCTIONNAME"
98 #Remove the trailing , if there is one
99 PRODUCTIONNAMEARRAY[1]=`echo ${PRODUCTIONNAMEARRAY[1]} | sed 's/,//g'`
100 #Remove quotes if there are any
101 PRODUCTIONNAMEARRAY[1]=`echo ${PRODUCTIONNAMEARRAY[1]} | sed 's/\"//g'`
102 #Now reconstruct the key value pair
103 PRODUCTIONNAME="${PRODUCTIONNAMEARRAY[0]}: \"${PRODUCTIONNAMEARRAY[1]}\","
104 #Remove the old production.name from the json
105 sed -i '/production.name/d' $OUTPUTFILE
106 #and add the new one
107 echo $PRODUCTIONNAME >> $OUTPUTFILE
108 
109 #calculate checksum
110 CHECKSUM=`samweb -e sbnd file-checksum $INPUTFILE`
111 echo "\"checksum\": $CHECKSUM," >> $OUTPUTFILE
112 
113 ##Get the CRC Format from fileEnstoreChecsum is {'crc_value': '3325351510', 'crc_type': 'adler 32 crc type'}
114 #CRC=`python -c "import root_metadata; print root_metadata.fileEnstoreChecksum(\"$INPUTFILE\")"`
115 ##Drop the Curly braces
116 #CRC=`echo $CRC | sed 's/{//'`
117 #CRC=`echo $CRC | sed 's/}//'`
118 ##Replace single quotes with double quotes
119 #CRC=`echo $CRC | sed s/\'/\"/g`
120 ##Now split the CRC lines on the commas
121 #IFS=\, read -a CRCARRAY <<<"$CRC"
122 ##Now add the CRC info to the json
123 #echo "\"crc\": {" >> $OUTPUTFILE
124 #echo "${CRCARRAY[0]}," >> $OUTPUTFILE
125 #echo "${CRCARRAY[1]}" >> $OUTPUTFILE
126 #echo "}" >> $OUTPUTFILE
127 
128 
129 #Make sure that the last entry does not have a comma at the end of its line
130 sed -i '$ s/,//g' $OUTPUTFILE
131 #
132 ##re-add the closing brace
133 echo "}" >> $OUTPUTFILE
134 
135 #Dump the json to std::out, needed for metadata_extractor
136 cat $OUTPUTFILE
* file
Definition: file_to_url.sh:69
then echo fcl sbnd_project sbnd_project sbnd_project sbnd_project production production checksum
process_name gaushit a
do i e
stream1 can override from command line with o or output services user sbnd