Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:05:00

0001 #!/bin/bash
0002 
0003 # check parameters
0004 if [[ "$#" != "2" ]] ; then
0005   echo "Usage: ./cmpr.sh test.dat [html|text]" >&2
0006   exit 1
0007 fi
0008 
0009 TEST_DAT="$1"
0010 FORMAT="$2"
0011 REFERENCE_DAT="reference.dat"
0012 
0013 if ! [ -f ${TEST_DAT} ] || ! [ -s ${TEST_DAT} ] ; then
0014   echo "ERROR: $0: ${TEST_DAT} doesn't exist or empty." >&2
0015   exit 1
0016 fi
0017 
0018 #----------------------------
0019 
0020 top_text () {
0021   printf "%-15s %5s | %-12s %-12s   %-12s %-12s | %10s %-10s\n" "Routine" "Test"  "Y" "dY"  "Yref" "dYref"  "Pull" "Status"
0022   echo "-------------------------------------------------------------------------------------------------"
0023 }
0024 
0025 top_html () {
0026 cat << EOT
0027 <html>
0028 <head>
0029   <title>Test results</title>
0030   <style>
0031     tr#good {}
0032     .switchlink {color: #0055CC; cursor: pointer; margin: 4px; border-bottom: 1px dashed #0055CC; }
0033   </style>
0034   
0035   <script language="javascript">
0036 <!--
0037 function turn_good()
0038 {
0039   var rows = document.getElementsByTagName('tr');
0040   for (var i = 0; i < rows.length; i++)
0041   {
0042     var row = rows[i];
0043 
0044     if (row.id == "good") {
0045       if (row.style.display != "none")
0046         row.style.display = "none";
0047       else
0048         row.style.display = "table-row";
0049     }
0050   }
0051 }
0052 -->
0053   </script>
0054 </head>
0055 <body>
0056 <h1>Test results</h1>
0057 <p>
0058 Platform: ${PLATFORM}<br>
0059 Test date: $(date)<br>
0060 <hr>
0061 <h4>Notation:</h4>
0062 <table cellpadding=3>
0063 <tr>
0064   <td align=left> Y , &nbsp; &nbsp; &nbsp; dY </td>
0065   <td> -- value of an observable and its stat. error  </td>
0066 </tr>
0067 <tr>
0068   <td align=left> Y<sub>ref</sub> ,  dY<sub>ref</ref> </td> 
0069   <td> -- reference value of an observable and its stat. error  </td>
0070 </tr>
0071 <tr>
0072   <td align=left> Pull  </td> 
0073   <td> -- ( Y - Y<sub>ref</sub> ) / ( dY<sup> 2</sup> + dY<sup> 2</sup><sub>ref</sub> )<sup> 1/2</sup> </td>
0074 </tr>
0075 <tr>
0076   <td bgcolor="#00ff00" align=center>ok</td> 
0077   <td> -- test is succesfully compiled and executed with <i>pull</i> &lt; 3 </td>
0078 </tr>
0079 <tr>
0080   <td bgcolor="#4aa1ff" align=center>badstat</td>
0081   <td> -- as above, but statistics is insufficient: Y<sub>ref</sub> &lt; 5dY<sub>ref</sub> or Y &lt; 4dY </td>
0082 </tr>
0083 <tr>
0084   <td bgcolor="#ffaa00" align=center> deviation</td> 
0085   <td> -- <i>pull</i> &gt; 3 </td>
0086 </tr>
0087 <tr>
0088   <td bgcolor="#ff0000" align=center> failed </td>
0089   <td> -- test crashed </td>
0090 </tr>
0091 <tr>
0092   <td bgcolor="#ff0000" align=center> errors </td>
0093   <td> -- test failed to compile </td>
0094 </tr>
0095 </table>
0096 <hr>
0097 
0098 <p>
0099   <span class="switchlink" onClick="turn_good()">Show/Hide rows with Status = [OK]</span>
0100 </p>
0101 
0102 <table border=1>
0103 <tr>
0104   <td>Generator</td>
0105   <td>Test</td>
0106   <td>Y</td>
0107   <td>dY</td>
0108   <td>Y<sub>ref</sub></td>
0109   <td>dY<sub>ref</sub></td>
0110   <td>Pull</td>
0111   <td>Status</td>
0112 </tr>
0113 
0114 EOT
0115 }
0116 
0117 bottom_html () {
0118   echo "</table>";
0119   return;
0120 }
0121 
0122 print_text () {
0123   printf "%-15s %5s | %-12s %-12s   %-12s %-12s | %10s %-10s\n" $*
0124 }
0125 
0126 print_html () {
0127   local g=$(echo $* | cut -d ' ' -f 1)
0128   local n=$(echo $* | cut -d ' ' -f 2)
0129   local end=$(echo $* | cut -d ' ' -f 3-)
0130   
0131   local rowid="bad"
0132   if [ "x$end" != "x${end/OK/}" ] ; then
0133     rowid="good"
0134   fi
0135   
0136   local color
0137   if   [[ "$end" != "${end/OK/}" ]] ; then
0138     color="#00ff00"
0139   elif [[ "$end" != "${end/NO_REFERENCE/}" ]] ; then
0140     color="#FFD91C"
0141   elif [[ "$end" != "${end/BADSTAT/}" ]] ; then
0142     color="#4aa1ff"
0143   elif [[ "$end" != "${end/DEVIATION/}" ]] ; then
0144     color="#ffaa00"
0145   else
0146     color="#ff0000"
0147   fi
0148   
0149   echo "<tr id=\"$rowid\">"
0150   echo "  <td> <a href=\"#${g}\"> ${g} </a> </td>"
0151   echo "  <td align=right> $n </td>"
0152   
0153   printf "<td>%s</td> <td>%s</td>   <td>%s</td> <td>%s</td>  <td align=right>%s</td> <td align=center bgcolor=\"$color\">%s</td> </tr>\n" $end
0154 }
0155 
0156 process_tests () {
0157   cc -o chi.exe chi.c -lm >&2
0158   
0159   # TODO: check the case of empty $TEST_DAT file = [GENERATOR FAILED!]
0160   
0161   {
0162     # print the list of tested generators
0163     # [output]:
0164     #   "generator name"
0165     
0166     cat $TEST_DAT | cut -d _ -f 1 | sort | uniq
0167   } | \
0168   {
0169     # print the list of all available tests for
0170     # generators from the input stream
0171     # [output]:
0172     #   "test name" "test #"
0173     
0174     while read gen ; do
0175       cat $TEST_DAT $REFERENCE_DAT | sed 's,!.*$,,' | grep "^${gen}_" | sed 's,  *, ,g' | cut -d ' ' -f 1-2 | sort -u
0176     done
0177   } | \
0178   {
0179     # print the list of test results for
0180     # the tests from the input stream
0181     # [output]:
0182     #   "test name" "test #" "y" "dy" "y0" "dy0" "chi2" "result"
0183     
0184     while read gentest no ; do
0185       
0186       output="$gentest $no "
0187 
0188       # get test and reference values
0189 #      echo "DBG:^$gentest $no:" >&2
0190       ydy=$(cat $TEST_DAT | sed 's,  *, ,g; s,!.*$,,;' | grep -E "^${gentest} ${no} " | cut -d ' ' -f 3-4)
0191 #      echo "DBG ydy:$ydy:">&2
0192       y0dy0=$(cat $REFERENCE_DAT | sed 's,  *, ,g; s,!.*$,,;' | grep -E "^${gentest} ${no} " | cut -d ' ' -f 3-4)
0193 #      echo "DBG y0dy0:$y0dy0:">&2
0194       
0195       if [[ "$ydy" != "" && "$y0dy0" != "" ]] ; then
0196 #             echo "DBG: --- echo $ydy $y0dy0 | chi --- " >&2
0197         output1=`echo "$ydy $y0dy0" | ./chi.exe`
0198         echo "$output $output1"
0199       else
0200         if [[ "$y0dy0" == "" ]] ; then
0201           # reference is missing
0202           y0dy0="- -"
0203           result="[NO_REFERENCE]"
0204         fi
0205         
0206         if [[ "$ydy" == "" ]] ; then
0207           # test is missing
0208           ydy="- -"
0209           result="[TEST_FAILED]"
0210         fi
0211         
0212         # NOTE: if both - reference and test is missing
0213         #       then the test will be marked as FAILED
0214         
0215         echo "$output $ydy $y0dy0 - $result"
0216       fi
0217     done
0218   }
0219   
0220   rm -f chi.exe >&2
0221 }
0222 
0223 # print test dependencies
0224 print_tests_info() {
0225   # find library dependencies tool
0226   if which ldd >& /dev/null ; then
0227     # linux machine:
0228     LDD="ldd "
0229   elif which otool >& /dev/null ; then
0230     # mac machine:
0231     LDD="otool -L "
0232   else
0233     echo "WARNING: can't find ldd routine. Can't get dynamically linked libraries the tests are compiled against." >&2
0234     LDD="true "
0235   fi
0236   
0237 }
0238 
0239 #---------------------
0240 
0241 if [[ "${FORMAT}" == "text" ]] ; then
0242   top_text
0243   process_tests | while read line ; do print_text $line ; done
0244 else
0245   top_html
0246   process_tests | while read line ; do print_html $line ; done
0247   bottom_html
0248   print_tests_info
0249 fi