Changeset 20106 for trunk/Mars/hawc


Ignore:
Timestamp:
09/07/21 14:03:51 (3 years ago)
Author:
maslowski
Message:
Fixed some bugs.
Location:
trunk/Mars/hawc/processing/DiskToDB
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/hawc/processing/DiskToDB/run-scripts.sh

    r20104 r20106  
    229229mkdir -p ./queries
    230230readonly ONDISK="./queries/insert-OnDisk-${TEL}.sql"
     231readonly AUXDISK="./queries/insert-AuxOnDisk-${TEL}.sql"
    231232readonly RAW="./queries/insert-raw-${TEL}.sql"
    232233readonly CALIB="./queries/find-calibration2-${TEL}.sql"
     
    239240
    240241# Create Database of existing files
    241 # Create SQL query with:
    242 # (Telescope, Night, RUNID, ISDRSFILE).
    243242echo "Updating file table"
    244243bash ./update-file-table2.sh -i -o "${ONDISK}" "${TEL}" "${DIR}/raw"
     
    246245echo "Uploading updated table"
    247246mysql --defaults-file="${CRED}" < "${ONDISK}"
     247
     248# Create Database of existing auxiliary files
     249bash ./update-aux-table.sh -r -o "${AUXDISK}" "${TEL}" "${DIR}/auxil"
     250# Update DataOnDisk tabel in database
     251echo "Uploading updated table"
     252mysql --defaults-file="${CRED}" < "${AUXDISK}"
    248253
    249254# get list of NIGHTS with unprocessed files
  • trunk/Mars/hawc/processing/DiskToDB/update-aux-table.sh

    r20105 r20106  
    121121
    122122
    123 echo \
    124 "\
     123        EXT=0
     124        NIGHT=`find "${DIR}"/[0-9][0-9][0-9][0-9]/ -type f \
     125                | grep -o "/[0-9]\{8\}.${AUX}.fits" \
     126                | cut -f2 -d "/" \
     127                | cut -f1 -d "."`|| EXT=1
     128
     129        if [ ${EXT} = "0" ]
     130        then
     131
     132                echo \
     133                "\
    125134INSERT INTO AuxOnDisk_tmp (Telescope, NIGHT, ${AUX})
    126135VALUES
     
    128137
    129138
    130 NIGHT=`find "${DIR}"/[0-9][0-9][0-9][0-9]/ -type f \
    131         | grep -o "/[0-9]\{8\}.${AUX}.fits" \
    132         | cut -f2 -d "/" \
    133         | cut -f1 -d "."`
    134 
    135 # Format to (Telescope, NIGHT, FAD_CONTROL_TEMPERATURE),
    136 QUERY=`paste <(for i in ${NIGHT}; do echo ${TEL}; done) \
    137         <(echo "${NIGHT}") \
    138         <(for i in ${NIGHT}; do echo "0"; done) \
    139         --delimiters "," \
    140         | sed 's/^/(/' \
    141         | sed 's/$/),/'`
    142 
    143 # Write query to OUTPUT file
    144 echo "${QUERY}" >> ${OUTPUT}
    145 # Change last comma to semicolon
    146 sed -i '$s/,$//' "${OUTPUT}"
    147 
    148 echo "ON DUPLICATE KEY UPDATE ${AUX} = 0;" >> ${OUTPUT}
    149 
    150 # 1) If there is data in the database that is not on disk then set
    151 #       ${AUX} = NULL for that night
    152 # 2) Delete all entries from the database that are not on disk
    153 # 3) ${INSERT} all entries into the database that are on disk
    154 echo \
    155 "\
    156 CREATE TEMPORARY TABLE TableNotDisk_${AUX}
    157 (
    158         Telescope tinyint UNSIGNED NOT NULL,
    159         NIGHT int UNSIGNED NOT NULL,
    160         FAD_CONTROL_TEMPERATURE tinyint UNSIGNED,
    161         BIAS_CONTROL_DYNAMIC_DATA tinyint UNSIGNED,
    162         FTM_CONTROL_DATA tinyint UNSIGNED,
    163         FTU_CONTROL_DATA tinyint UNSIGNED,
    164         Updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    165                 ON UPDATE CURRENT_TIMESTAMP,
    166         PRIMARY KEY (Telescope, NIGHT)
    167 ) SELECT * FROM AuxOnDisk
    168         WHERE (Telescope, NIGHT) NOT IN
    169         (SELECT Telescope, NIGHT FROM AuxOnDisk_tmp)
    170         AND Telescope=${TEL};
    171 
    172 UPDATE AuxOnDisk SET ${AUX} = NULL WHERE NIGHT IN
    173         (SELECT NIGHT FROM TableNotDisk_${AUX})
    174         AND Telescope=${TEL};
    175 
    176 DELETE FROM AuxOnDisk
    177         WHERE (Telescope, NIGHT) NOT IN
    178         (SELECT Telescope, NIGHT FROM AuxOnDisk_tmp)
    179         AND Telescope=${TEL};
    180 
    181 ${INSERT} AuxOnDisk (SELECT * FROM AuxOnDisk_tmp);
    182 "\ >> ${OUTPUT}
     139                # Format to (Telescope, NIGHT, FAD_CONTROL_TEMPERATURE),
     140                QUERY=`paste <(for i in ${NIGHT}; do echo ${TEL}; done) \
     141                        <(echo "${NIGHT}") \
     142                        <(for i in ${NIGHT}; do echo "0"; done) \
     143                        --delimiters "," \
     144                        | sed 's/^/(/' \
     145                        | sed 's/$/),/'`
     146
     147                # Write query to OUTPUT file
     148                echo "${QUERY}" >> ${OUTPUT}
     149                # Change last comma to semicolon
     150                sed -i '$s/,$//' "${OUTPUT}"
     151
     152                echo "ON DUPLICATE KEY UPDATE ${AUX} = 0;" >> ${OUTPUT}
     153
     154                # 1) If there is data in the database that is not on disk then set
     155                #       ${AUX} = NULL for that night
     156                # 2) Delete all entries from the database that are not on disk
     157                # 3) ${INSERT} all entries into the database that are on disk
     158                echo \
     159                "\
     160                CREATE TEMPORARY TABLE TableNotDisk_${AUX}
     161                (
     162                        Telescope tinyint UNSIGNED NOT NULL,
     163                        NIGHT int UNSIGNED NOT NULL,
     164                        FAD_CONTROL_TEMPERATURE tinyint UNSIGNED,
     165                        BIAS_CONTROL_DYNAMIC_DATA tinyint UNSIGNED,
     166                        FTM_CONTROL_DATA tinyint UNSIGNED,
     167                        FTU_CONTROL_DATA tinyint UNSIGNED,
     168                        Updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
     169                                ON UPDATE CURRENT_TIMESTAMP,
     170                        PRIMARY KEY (Telescope, NIGHT)
     171                ) SELECT * FROM AuxOnDisk
     172                        WHERE (Telescope, NIGHT) NOT IN
     173                        (SELECT Telescope, NIGHT FROM AuxOnDisk_tmp)
     174                        AND Telescope=${TEL};
     175
     176                UPDATE DataOnDisk SET auxiliary = NULL
     177                        WHERE DataOnDisk.NIGHT IN
     178                        (SELECT NIGHT FROM AuxOnDisk_tmp)
     179                        AND Telescope=${TEL};
     180
     181                DELETE FROM AuxOnDisk
     182                        WHERE (Telescope, NIGHT) NOT IN
     183                        (SELECT Telescope, NIGHT FROM AuxOnDisk_tmp)
     184                        AND Telescope=${TEL};
     185
     186                ${INSERT} AuxOnDisk (SELECT * FROM AuxOnDisk_tmp);
     187                "\ >> ${OUTPUT}
     188
     189        else
     190                # 1) If there is data in the database that is not on disk then set
     191                #       ${AUX} = NULL for that night
     192                # 2) Delete all entries from the database that are not on disk
     193                # 3) ${INSERT} all entries into the database that are on disk
     194                echo \
     195                "\
     196                CREATE TEMPORARY TABLE TableNotDisk_${AUX}
     197                (
     198                        Telescope tinyint UNSIGNED NOT NULL,
     199                        NIGHT int UNSIGNED NOT NULL,
     200                        FAD_CONTROL_TEMPERATURE tinyint UNSIGNED,
     201                        BIAS_CONTROL_DYNAMIC_DATA tinyint UNSIGNED,
     202                        FTM_CONTROL_DATA tinyint UNSIGNED,
     203                        FTU_CONTROL_DATA tinyint UNSIGNED,
     204                        Updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
     205                                ON UPDATE CURRENT_TIMESTAMP,
     206                        PRIMARY KEY (Telescope, NIGHT)
     207                ) SELECT * FROM AuxOnDisk
     208                        WHERE (Telescope, NIGHT) NOT IN
     209                        (SELECT Telescope, NIGHT FROM AuxOnDisk_tmp)
     210                        AND Telescope=${TEL};
     211
     212                UPDATE DataOnDisk SET auxiliary = NULL
     213                        WHERE DataOnDisk.NIGHT IN
     214                        (SELECT NIGHT FROM AuxOnDisk_tmp)
     215                        AND Telescope=${TEL};
     216
     217                DELETE FROM AuxOnDisk
     218                        WHERE (Telescope, NIGHT) NOT IN
     219                        (SELECT Telescope, NIGHT FROM AuxOnDisk_tmp)
     220                        AND Telescope=${TEL};
     221
     222                ${INSERT} AuxOnDisk (SELECT * FROM AuxOnDisk_tmp);
     223                "\ >> ${OUTPUT}
     224
     225
     226                echo "No Auxiliary files."
     227                continue;
     228        fi
     229
     230
    183231
    184232done
  • trunk/Mars/hawc/processing/DiskToDB/update-file-table2.sh

    r20104 r20106  
    147147sed -i '$s/,$/;/' "${OUTPUT}"
    148148
    149 # 1) If there is data in the database that is not on disk then set star = 0
    150 #    for that night
     149# 1) If there is data in the database that is not on disk then set
     150#       header = NULL for that night
    151151# 2) Delete all entries from the database that are not on disk
    152152# 3) ${INSERT} all entries into the database that are on disk
  • trunk/Mars/hawc/processing/DiskToDB/write-calibration-query.sh

    r20104 r20106  
    218218        WHERE NIGHT=${NIGHT}
    219219        AND Telescope=${TEL}
    220         ) = 0;
     220        ) = 0
     221        AND NIGHT=${NIGHT}
     222        AND Telescope=${TEL};
    221223"\ >> ${OUTPUT}
Note: See TracChangeset for help on using the changeset viewer.