Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
#!/bin/bash

WebDir='/eos/cms/store/group/dpg_hcal/comm_hcal/www/HcalRemoteMonitoring'
WebSite='https://cms-conddb.cern.ch/eosweb/hcal/HcalRemoteMonitoring'
HistoDir='/eos/cms/store/group/dpg_hcal/comm_hcal/www/HcalRemoteMonitoring/CMT/histos'


cmsenv 2>/dev/null
if [ $? == 0 ] ; then
    eval `scramv1 runtime -sh`
fi


# Process arguments and set the flags
fileName=$1

# Obtain the runList from a file, if needed
runList=""
if [ ${#fileName} -gt 0 ] ; then
  if [ -s ${fileName} ] ; then
      runList=`cat ${fileName}`
  else
      echo "<${fileName}> does not seem to be a valid file"
      exit 2
  fi
else
    if [ ${ignoreFile} -eq 0 ] ; then
	echo " ! no file provided"
    fi
    echo " ! will produce only the global html page"
fi


# Check the runList and correct the correctables
# Replace ',' and ';' by empty spaces
runList=`echo "${runList}" | sed 'sk,k\ kg' | sed 'sk;k\ kg'`
ok=1
for r in ${runList} ; do
    if [ ! ${#r} -eq 6 ] ; then
	echo "run numbers are expected to be of length 6. Check <$r>"
	ok=0
    fi
    debug_loc=0
    if [ "$r" -eq "$r" ] 2>/dev/null ; then
	if [ ${debug_loc} -eq 1 ] ; then echo "run variable <$r> is a number (ok)"; fi
    else
	echo "error: run variable <$r> is not an integer number"
	ok=0
    fi
done

echo "Tested `wc -w <<< "${runList}"` runs from file ${fileName}"
if [ ${ok} -eq 0 ] ; then
    echo "errors in the file ${fileName} with run numbers"
    exit 3
else
    if [ ${#fileName} -gt 0 ] ; then
	echo "run numbers in ${fileName} verified ok"
    fi
fi

echo 
echo 
echo 'Numbers of NEW runs for processing'
echo "${runList}"
echo -e "runList complete\n"

echo -e '\n\nRun numbers:'
runListEOS=`echo $runList | tee _runlist_`
echo "${runListEOS}"
echo -e "Full runList for EOS complete\n"


# copy index.html from EOS:
echo 'next message is Fine: '
rm index.html
eoscp $WebDir/CMT/index.html index.html
cp index.html OLDindex.html

# delete last line of copied index_draft.html which close the table
cat index.html | head -n -1 > index_draft.html

#extract run numbers for correct continuation
#k=0
#for i in ${runListEOSall} ; do
#let "k = k + 1"
#done


k=3


########################################## type by hands number of new runs k=k-number:
#let "k = k - 1"
echo ' ================>>>    k in old list = '$k

for i in ${runListEOS} ; do
 
#runnumber=$(echo $i | sed -e 's/[^0-9]*//g')
#runnumber=$(echo $i | awk -F 'run' '{print $2}'| awk -F '.' '{print $1}')
runnumber=${i}
#if [[ "$runnumber" > 243400 ]] ; then
let "k = k + 1"
echo
echo ' ================>>> new k in loop = '$k
echo
echo
echo 'RUN number = '$runnumber

# extract the date of file
dasInfo=${DAS_DIR}/das_${runnumber}.txt
got=0
if [ ${dasCache} == "1" ] ; then
    rm -f tmp
    if [ -s ${dasInfo} ] ; then
	cp ${dasInfo} tmp
	got=1
    else
	echo "no ${dasInfo} found. Will use dasgoclient"
    fi
fi

if [ ${got} -eq 0 ] ; then
#dasgoclient  --query="file dataset=/HcalNZS/Run2018D-v1/RAW  run=${i} | grep file.size, file.nevents, file.modification_time "  > tmp
dasgoclient  --query="file dataset=/Cosmics/Commissioning2021-v1/RAW  run=${i} | grep file.size, file.nevents, file.modification_time "  > tmp
fi


timetmp=`cat tmp | head -n 1  | awk '{print $3}'`
############################################################################################################
type='Cosmics'
timetmp2=`date -d @${timetmp} +%Y-%m-%d:%H-%M-%S`
sizetmp=`cat tmp | head -n 1  | awk '{print $1}'`
neventstmp=`cat tmp | head -n 1  | awk '{print $2}'`
commentariy='CRUZET2021'
#cat runs_info
echo 'RUN Type = '$type
echo ${sizetmp} ${neventstmp} ${timetmp2}
echo 'RUN Comment = '$commentariy



#adding entry to list of file index_draft.html
let "raw = (k % 2) + 2"
echo '<tr>'>> index_draft.html
echo '<td class="s1" align="center">'$k'</td>'>> index_draft.html
echo '<td class="s'$raw'" align="center">'$runnumber'</td>'>> index_draft.html
echo '<td class="s'$raw'" align="center">'$type'</td>'>> index_draft.html
echo '<td class="s'$raw'" align="center">'$timetmp2'</td>'>> index_draft.html
echo '<td class="s'$raw'" align="center">'$sizetmp'</td>'>> index_draft.html
echo '<td class="s'$raw'" align="center">'$neventstmp'</td>'>> index_draft.html
echo '<td class="s'$raw'" align="center"><a href="'$WebSite'/CMT/GLOBAL_'$runnumber'/LumiList.html">CMT_'$runnumber'</a></td>'>> index_draft.html
echo '<td class="s'$raw'" align="center"><a href="'$WebSite'/GlobalRMT/GLOBAL_'$runnumber'/MAP.html">RMT_'$runnumber'</a></td>'>> index_draft.html
echo '<td class="s'$raw'" align="center">'$commentariy'</td>'>> index_draft.html


rm tmp

############################################################################################################   record index_draft.html

if [ ${#comment} -gt 0 ] ; then
    #echo "runList=${runList}, check ${runnumber}"
    temp_var=${runList/${runnumber}/}
    if [ ${#temp_var} -lt ${#runList} ] ; then
	echo "adding a commentary for this run"
	echo "<td class=\"s${raw}\" align=\"center\">${comment}</td>" >> index_draft.html
    fi
fi
echo '</tr>'>> index_draft.html
prev=$i

#fi
done


# print footer to index.html 
echo `cat footer.txt`>> index_draft.html


status=0
if [ ${debug} == "1" ] ; then
    echo "debug=${debug}. No upload to eos"
    status=-1
else
###    echo "Commented by me:  eoscp index_draft.html $WebDir/CMT/index.html No upload to eos"
#  eoscp OLDindex.html $WebDir/CMT/OLDindex.html
#  eoscp index_draft.html $WebDir/CMT/index.html
    status="$?"
# rm index_draft.html
fi

# delete temp files

if [ ${debug} == "0" ] ; then
#    rm -f *.root
    rm -f _runlist_
    rm -f _runlistEOSall_
fi

# check eos-upload exit code
if [[ "${status}" == "0" ]]; then
  echo "Successfully uploaded!"
else
  echo "ERROR: Uploading failed"
  exit 1
fi

echo "index script done"