Changeset 20103 for trunk/Mars/hawc/processing/DiskToDB/run-scripts.sh
- Timestamp:
- 09/01/21 07:56:42 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/hawc/processing/DiskToDB/run-scripts.sh
r20093 r20103 77 77 readonly DATE=`date +%Y%m%d_%H%M` 78 78 readonly LOG="./log/${SCRPTN}_${DATE}.log" 79 exec 3>&1 1>>${LOG}80 exec 4>>${LOG}81 #exec 3>&182 #exec 4>&179 # exec 3>&1 1>>${LOG} 80 # exec 4>>${LOG} 81 exec 3>&1 82 exec 4>&1 83 83 84 84 echo "Start processing data" … … 88 88 # Delete entries form table ${3} for a given Telescope and Night 89 89 # Arguments: Credentials Telescope Table Night 90 mysql --defaults-file="${1}" \ 90 local cred="${1}" 91 local tel="${2}" 92 local table="${3}" 93 local night="${4}" 94 95 mysql --defaults-file="${cred}" \ 91 96 --skip-column-names \ 92 97 --batch \ 93 98 --raw \ 94 99 --compress \ 95 -e "DELETE FROM ${3} WHERE Telescope = ${2} AND NIGHT = ${4};" 100 -e "DELETE FROM ${table} WHERE Telescope = ${tel} \ 101 AND NIGHT = ${night};" 96 102 } 97 103 98 104 function SetStatus() 99 105 { 100 # Query with process update 101 # Arguments: Credentials Telescope Status Night 102 mysql --defaults-file="${1}" \ 106 # Status update for one Column, Night and Telescope 107 # Arguments: Credentials Telescope Column Value Night 108 local cred="${1}" 109 local tel="${2}" 110 local col="${3}" 111 local val="${4}" 112 local night="${5}" 113 114 # Check if a valid Column was selected 115 if [ ${col} != "header" ] \ 116 && [ ${col} != "calibration" ] \ 117 && [ ${col} != "auxiliary" ] \ 118 && [ ${col} != "callisto" ] \ 119 && [ ${col} != "star" ] 120 then 121 echo "ERROR: ${col} is not a valid column." 122 exit 1 123 fi 124 125 mysql --defaults-file="${cred}" \ 103 126 --skip-column-names \ 104 127 --batch \ 105 128 --raw \ 106 129 --compress \ 107 -e "UPDATE DataOnDisk SET STATUS = ${3} WHERE NIGHT = ${4}\108 AND Telescope = ${2};"130 -e "UPDATE DataOnDisk SET ${col} = ${val}\ 131 WHERE NIGHT = ${night} AND Telescope = ${tel};" 109 132 } 110 133 111 134 function GetStatus() 112 135 { 113 # Return status of Night from database 114 # Arguments: Credentials Telescope Night 115 local STATUS=`mysql --defaults-file="${1}" \ 136 # Return status of Night for a given Column and Telescope 137 # Arguments: Credentials Telescope Column Night 138 local cred="${1}" 139 local tel="${2}" 140 local col="${3}" 141 local night="${4}" 142 143 # Check if a valid Column was selected 144 if [ ${col} != "header" ] \ 145 && [ ${col} != "calibration" ] \ 146 && [ ${col} != "auxiliary" ] \ 147 && [ ${col} != "callisto" ] \ 148 && [ ${col} != "star" ] 149 then 150 echo "ERROR: ${col} is not a valid column." 151 exit 1 152 fi 153 154 local STATUS=`mysql --defaults-file="${cred}" \ 116 155 --skip-column-names \ 117 156 --batch \ 118 157 --raw \ 119 158 --compress \ 120 -e "SELECT DISTINCT STATUS FROM DataOnDisk WHERE NIGHT = ${3} \ 121 AND Telescope = ${2};"` 122 123 if [ -z ${STATUS} ] 124 then 125 echo "ERROR: Status does not exist for telescope: ${2} and night: ${3}" >&2 159 -e "SELECT DISTINCT ${col} FROM DataOnDisk \ 160 WHERE NIGHT = ${night} \ 161 AND Telescope = ${tel} \ 162 AND ${col} IS NULL;"` 163 164 echo "${STATUS}" 165 } 166 167 168 function DoesDirExists() 169 { 170 local thing="${1}" 171 # Check if thing exists 172 if [ ! -d "${thing}" ] 173 then 174 echo "${thing} is not a valid Path. Please change variable in script ${SCRPTN}." 126 175 exit 1 127 176 fi 128 129 if [ `echo "${STATUS}" | wc -l` -ne "1" ] 130 then 131 echo "ERROR: Not all status values are the same for the night: ${3}!" >&2 177 } 178 179 function DoesFileExists() 180 { 181 local thing="${1}" 182 # Check if thing exists 183 if [ ! -f "${thing}" ] 184 then 185 echo "${thing} is not a valid File. Please change variable in script ${SCRPTN}." 132 186 exit 1 133 187 fi 134 135 echo "${STATUS}" 136 } 188 } 189 137 190 138 191 # Define variables … … 147 200 # Credentials for root2sql for star 148 201 readonly STARRC='../root2sql-star.rc' 202 203 # Check if variable paths point to something sensible 204 DoesDirExists "${DIR}" 205 DoesFileExists "${CRED}" 206 DoesFileExists "${CALLISTORC}" 207 DoesFileExists "${STARRC}" 208 149 209 # SQL outputs 150 210 mkdir -p ./queries … … 156 216 # Create Database of existing files 157 217 # Create SQL query with: 158 # (Telescope, Night, RUNID, ISDRSFILE , ISPROCESSED).218 # (Telescope, Night, RUNID, ISDRSFILE). 159 219 echo "Updating file table" 160 220 bash ./update-file-table2.sh -i -o "${ONDISK}" "${TEL}" "${DIR}/raw" … … 170 230 --raw \ 171 231 --compress \ 172 -e "SELECT DISTINCT NIGHT FROM DataOnDisk WHERE STATUS != 5 \ 232 -e "SELECT DISTINCT NIGHT FROM DataOnDisk \ 233 WHERE header IS NULL \ 234 OR calibration IS NULL \ 235 OR auxiliary IS NULL \ 236 OR callisto IS NULL \ 237 OR star IS NULL \ 173 238 AND Telescope = ${TEL};"` 174 239 … … 182 247 echo "Updating database" 183 248 249 NIGHTS=20201111 250 184 251 echo "Nights to process:" 185 252 echo "${NIGHTS}" … … 191 258 for NIGHT in ${NIGHTS} 192 259 do 193 STATUS=`GetStatus ${CRED} ${TEL} ${NIGHT}` 194 echo "Status = ${STATUS} for night = ${NIGHT}" 195 echo " " 196 197 if [ ${STATUS} -lt "1" ] 260 HEAD_S=`GetStatus ${CRED} ${TEL} "header" ${NIGHT}` 261 CALI_S=`GetStatus ${CRED} ${TEL} "calibration" ${NIGHT}` 262 AUXI_S=`GetStatus ${CRED} ${TEL} "auxiliary" ${NIGHT}` 263 CALL_S=`GetStatus ${CRED} ${TEL} "callisto" ${NIGHT}` 264 STAR_S=`GetStatus ${CRED} ${TEL} "star" ${NIGHT}` 265 266 echo "header = ${HEAD_S} for night = ${NIGHT}" 267 echo " " 268 269 # If header is null 270 if [ ! -z ${HEAD_S} ] && [ ${HEAD_S} = "NULL" ] 198 271 then 199 272 # Get raw data headers … … 205 278 echo "Uploading raw headers for night: ${NIGHT}" 206 279 mysql --defaults-file="${CRED}" < "${RAW}" 207 SetStatus ${CRED} ${TEL} "1" ${NIGHT}208 280 echo "Finished uploading raw headers for night: ${NIGHT}" 209 281 echo " " 210 282 fi 211 283 212 if [ ${STATUS} -lt "2" ] 284 echo "calibration = ${CALI_S} for night = ${NIGHT}" 285 echo " " 286 287 # If header is null and or calibration is null 288 if ([ ! -z ${HEAD_S} ] && [ ${HEAD_S} = "NULL" ]) \ 289 || ([ ! -z ${CALI_S} ] && [ ${CALI_S} = "NULL" ]) 213 290 then 214 291 # Get calibration files … … 219 296 echo "Uploading calibration for night: ${NIGHT}" 220 297 mysql --defaults-file="${CRED}" < "${CALIB}" 221 SetStatus ${CRED} ${TEL} "2" ${NIGHT}222 298 echo "Finished uploading calibration for night: ${NIGHT}" 223 299 echo " " 224 300 fi 225 301 226 if [ ${STATUS} -lt "3" ] 302 echo "auxiliary = ${AUXI_S} for night = ${NIGHT}" 303 echo " " 304 305 # If header is null and or calibration is null and or auxiliary is null 306 if ([ ! -z ${HEAD_S} ] && [ ${HEAD_S} = "NULL" ]) \ 307 || ([ ! -z ${CALI_S} ] && [ ${CALI_S} = "NULL" ]) \ 308 || ([ ! -z ${AUXI_S} ] && [ ${AUXI_S} = "NULL" ]) 227 309 then 228 310 # Get aux data … … 235 317 echo "Uploading aux data for night: ${NIGHT}" 236 318 mysql --defaults-file="${CRED}" < "${AUX}" 237 SetStatus ${CRED} ${TEL} "3" ${NIGHT}238 319 echo "Finished uploading aux data for night: ${NIGHT}" 239 320 echo " " 240 321 fi 241 322 242 if [ ${STATUS} -lt "4" ] 323 echo "callisto = ${CALL_S} for night = ${NIGHT}" 324 echo " " 325 326 # If header is null and or calibration is null and or callisto is null 327 if ([ ! -z ${HEAD_S} ] && [ ${HEAD_S} = "NULL" ]) \ 328 || ([ ! -z ${CALI_S} ] && [ ${CALI_S} = "NULL" ]) \ 329 || ([ ! -z ${CALL_S} ] && [ ${CALL_S} = "NULL" ]) 243 330 then 244 331 # Get callisto data … … 260 347 "${DIR}"/callisto \ 261 348 ${NIGHT} 262 SetStatus ${CRED} ${TEL} "4" ${NIGHT}263 349 echo "Finished uploading callisto entries for night: ${NIGHT}" 264 350 echo " " 265 351 fi 266 352 267 if [ ${STATUS} -lt "5" ] 353 echo "star = ${STAR_S} for night = ${NIGHT}" 354 echo " " 355 356 # If header is null and or calibration is null and or callisto is null 357 # and or star is null 358 if ([ ! -z ${HEAD_S} ] && [ ${HEAD_S} = "NULL" ]) \ 359 || ([ ! -z ${CALI_S} ] && [ ${CALI_S} = "NULL" ]) \ 360 || ([ ! -z ${CALL_S} ] && [ ${CALL_S} = "NULL" ]) \ 361 || ([ ! -z ${STAR_S} ] && [ ${STAR_S} = "NULL" ]) 268 362 then 269 363 # Get star data … … 281 375 "${DIR}"/star \ 282 376 ${NIGHT} 283 SetStatus ${CRED} ${TEL} "5" ${NIGHT}284 377 echo "Finished uploading star entries for night: ${NIGHT}" 285 378 echo " "
Note:
See TracChangeset
for help on using the changeset viewer.