diff options
author | tlatorre <tlatorre@uchicago.edu> | 2019-03-07 16:31:34 -0600 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2019-03-07 16:31:34 -0600 |
commit | becc37649c55bf7d673efc2d96bb099824032f42 (patch) | |
tree | 8a78a68f85ab4533e0f4dadb712c6138f3e036f5 | |
parent | a96111c8026d47147708796091ec7bef216aefd8 (diff) | |
download | sddm-becc37649c55bf7d673efc2d96bb099824032f42.tar.gz sddm-becc37649c55bf7d673efc2d96bb099824032f42.tar.bz2 sddm-becc37649c55bf7d673efc2d96bb099824032f42.zip |
update fit to automatically load DQXX file based on run number
-rw-r--r-- | src/db.c | 31 | ||||
-rw-r--r-- | src/db.h | 3 | ||||
-rw-r--r-- | src/dqxx.c | 24 | ||||
-rw-r--r-- | src/event.h | 4 | ||||
-rw-r--r-- | src/fit.c | 32 |
5 files changed, 74 insertions, 20 deletions
@@ -35,7 +35,22 @@ static dictType titleDB = { /* Add a bank to the database. * - * Returns 0 on success, -1 on error. */ + * If a bank with the same name and id already exists, it will be replaced. */ +void replace_bank(dict *db, const char name[4], uint32_t id, dbval *data) +{ + uint32_t *buf = malloc(sizeof(uint32_t)*2); + + memcpy(buf,name,4); + buf[1] = id; + + /* If the bank already exists, dictReplace will keep the old key, so we + * have to free `buf`. */ + if (!dictReplace(db, buf, data)) free(buf); +} + +/* Add a bank to the database. + * + * Returns 0 on success, -1 if the key already exists. */ int add_bank(dict *db, const char name[4], uint32_t id, dbval *data) { uint32_t *buf = malloc(sizeof(uint32_t)*2); @@ -125,8 +140,11 @@ void db_free(dict *db) /* Load a title bank file into the database `db`. * + * If `replace` is 0, then loading an already existing bank will cause an + * error. Otherwise, the bank will be replaced. + * * Returns 0 on success, -1 on error. */ -int load_file(dict *db, const char *filename) +int load_file(dict *db, const char *filename, int replace) { int i, index; char *item, *s; @@ -152,6 +170,7 @@ int load_file(dict *db, const char *filename) if (!f) { sprintf(db_err, "unable to open file '%s': %s", filename, strerror(errno)); + free(buf); return -1; } @@ -186,7 +205,9 @@ int load_file(dict *db, const char *filename) /* Save previous bank. */ buf = realloc(buf,sizeof(dbval)*index); - if (add_bank(db, idh, idn, buf) == DICT_ERR) { + if (replace) { + replace_bank(db, idh, idn, buf); + } else if (add_bank(db, idh, idn, buf) == DICT_ERR) { sprintf(db_err, "bank '%.4s' already exists in the database", idh); goto err; } @@ -240,7 +261,9 @@ int load_file(dict *db, const char *filename) buf = realloc(buf,sizeof(dbval)*index); - if (add_bank(db, idh, idn, buf) == DICT_ERR) { + if (replace) { + replace_bank(db, idh, idn, buf); + } else if (add_bank(db, idh, idn, buf) == DICT_ERR) { sprintf(db_err, "bank '%.4s' already exists in the database", idh); goto err; } @@ -33,8 +33,9 @@ extern char db_err[256]; dict *db_init(void); void db_free(dict *db); +void replace_bank(dict *db, const char name[4], uint32_t id, dbval *data); int add_bank(dict *db, const char name[4], uint32_t id, dbval *data); dbval *get_bank(dict *db, const char name[4], uint32_t id); -int load_file(dict *db, const char *filename); +int load_file(dict *db, const char *filename, int replace); #endif @@ -35,30 +35,32 @@ int dqxx_init(dict *db, event *ev) id = i*512 + j*32 + k; dqch_word = dqch[30+KDQCH_TABLE+32*j+k]; + /* Clear the PMT_FLAG_DQXX bit. */ + ev->pmt_hits[id].flags &= ~PMT_FLAG_DQXX; if (dqch_word & KDQCH_B_PMT_CABLE) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; else if (dqch_word & KDQCH_B_PMTIC_RESISTOR) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; else if (dqch_word & KDQCH_B_SEQUENCER) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; else if (dqch_word & KDQCH_B_750OHM) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; else if (dqch_word & KDQCH_B_NOT_OP) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; if (dqcr_word & KDQCR_B_CRATE) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; else if (dqcr_word & KDQCR_B_MB) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; else if (dqcr_word & KDQCR_B_PMTIC) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; else if (dqcr_word & KDQCR_B_DAQ) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; else if (dqcr_word & KDQCR_B_GT) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; else if (dqcr_word & (1 << (12 + k/8))) - ev->pmt_hits[id].flags |= 0x2; + ev->pmt_hits[id].flags |= PMT_FLAG_DQXX; } } } diff --git a/src/event.h b/src/event.h index 64e8df1..60bdbf7 100644 --- a/src/event.h +++ b/src/event.h @@ -4,6 +4,10 @@ #include <stdint.h> #include "pmt.h" +/* Bitmasks for the various PMT flags. */ +#define PMT_FLAG_DIS 0x1 +#define PMT_FLAG_DQXX 0x2 + /* Struct to hold all data from a single event used for fitting. */ typedef struct pmt_hit { @@ -5828,7 +5828,10 @@ int get_event(zebraFile *f, event *ev, zebraBank *bev) ev->pmt_hits[id].qhl = bpmt.phl; ev->pmt_hits[id].qhs = bpmt.phs; ev->pmt_hits[id].qlx = bpmt.plx; - ev->pmt_hits[id].flags |= bpmt.pf & KPF_DIS; + /* Clear the PMT_FLAG_DIS bit. */ + ev->pmt_hits[id].flags &= ~PMT_FLAG_DIS; + if (bpmt.pf & KPF_DIS) + ev->pmt_hits[id].flags |= PMT_FLAG_DIS; if (!b.next) break; @@ -5915,6 +5918,8 @@ int main(int argc, char **argv) size_t len; char tmp[256]; size_t nhit, min_nhit = 100; + int last_run; + char dqxx_file[256]; for (i = 1; i < argc; i++) { if (strlen(argv[i]) >= 2 && !strncmp(argv[i], "--", 2)) { @@ -5995,7 +6000,9 @@ int main(int argc, char **argv) init_charge(); dict *db = db_init(); - if (load_file(db, "DQXX_0000010000.dat")) { + last_run = 10000; + + if (load_file(db, "DQXX_0000010000.dat", 0)) { fprintf(stderr, "failed to load DQXX_0000010000.dat: %s\n", db_err); goto err; } @@ -6005,12 +6012,12 @@ int main(int argc, char **argv) goto err; } - if (load_file(db, "pmt_response_qoca_d2o_20060216.dat")) { + if (load_file(db, "pmt_response_qoca_d2o_20060216.dat", 0)) { fprintf(stderr, "failed to load pmt_response_qoca_d2o_20060216.dat: %s\n", db_err); goto err; } - if (load_file(db, "rsp_rayleigh.dat")) { + if (load_file(db, "rsp_rayleigh.dat", 0)) { fprintf(stderr, "failed to load rsp_rayleigh.dat: %s\n", db_err); goto err; } @@ -6171,6 +6178,23 @@ skip_mc: ev.run = bev.run; ev.gtid = bev.gtr_id; + if (ev.run != last_run) { + printf("loading DQXX file for run %010i\n", ev.run); + + sprintf(dqxx_file, "DQXX_%010i.dat", ev.run); + if (load_file(db, dqxx_file, 1)) { + fprintf(stderr, "failed to load %s: %s\n", dqxx_file, db_err); + goto err; + } + + if (dqxx_init(db, &ev)) { + fprintf(stderr, "failed to initialize DQXX bank: %s\n", dqxx_err); + goto err; + } + + last_run = ev.run; + } + rv = get_event(f,&ev,&b); nhit = get_nhit(&ev); |