aboutsummaryrefslogtreecommitdiff
path: root/src/dqxx.c
diff options
context:
space:
mode:
authortlatorre <tlatorre@uchicago.edu>2018-08-14 10:08:27 -0500
committertlatorre <tlatorre@uchicago.edu>2018-08-14 10:08:27 -0500
commit24c8bcfe7f76b20124e2862ea050f815c0f768e7 (patch)
treee5bdbd638a2c7f38f1c094cc9e95cbdfe05b9481 /src/dqxx.c
parent0b7f199c0d93074484ea580504485a32dc29f5e2 (diff)
downloadsddm-24c8bcfe7f76b20124e2862ea050f815c0f768e7.tar.gz
sddm-24c8bcfe7f76b20124e2862ea050f815c0f768e7.tar.bz2
sddm-24c8bcfe7f76b20124e2862ea050f815c0f768e7.zip
move everything to src directory
Diffstat (limited to 'src/dqxx.c')
-rw-r--r--src/dqxx.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/dqxx.c b/src/dqxx.c
new file mode 100644
index 0000000..07b6037
--- /dev/null
+++ b/src/dqxx.c
@@ -0,0 +1,67 @@
+#include "dqxx.h"
+#include "db.h"
+#include <stdint.h> /* for uint32_t */
+#include "event.h"
+#include <stdio.h> /* for sprintf() */
+
+char dqxx_err[256];
+
+/* Flag PMTs which are not operational based on the DQCH and DQCR banks.
+ *
+ * Returns 0 on success or -1 on error. */
+int dqxx_init(dict *db, event *ev)
+{
+ int i, j, k, id;
+ uint32_t *dqch, *dqcr, dqch_word, dqcr_word;
+
+ for (i = 0; i < 19; i++) {
+ dqch = (uint32_t *) get_bank(db, "DQCH", i);
+ dqcr = (uint32_t *) get_bank(db, "DQCR", i);
+
+ if (!dqch) {
+ sprintf(dqxx_err, "failed to load DQCH for crate %i\n", i);
+ return -1;
+ }
+
+ if (!dqcr) {
+ sprintf(dqxx_err, "failed to load DQCR for crate %i\n", i);
+ return -1;
+ }
+
+ for (j = 0; j < 16; j++) {
+ dqcr_word = dqcr[30+KDQCR_TABLE+j];
+
+ for (k = 0; k < 32; k++) {
+ id = i*512 + j*32 + k;
+ dqch_word = dqch[30+KDQCH_TABLE+32*j+k];
+
+
+ if (dqch_word & KDQCH_B_PMT_CABLE)
+ ev->pmt_hits[id].flags |= 0x2;
+ else if (dqch_word & KDQCH_B_PMTIC_RESISTOR)
+ ev->pmt_hits[id].flags |= 0x2;
+ else if (dqch_word & KDQCH_B_SEQUENCER)
+ ev->pmt_hits[id].flags |= 0x2;
+ else if (dqch_word & KDQCH_B_750OHM)
+ ev->pmt_hits[id].flags |= 0x2;
+ else if (dqch_word & KDQCH_B_NOT_OP)
+ ev->pmt_hits[id].flags |= 0x2;
+
+ if (dqcr_word & KDQCR_B_CRATE)
+ ev->pmt_hits[id].flags |= 0x2;
+ else if (dqcr_word & KDQCR_B_MB)
+ ev->pmt_hits[id].flags |= 0x2;
+ else if (dqcr_word & KDQCR_B_PMTIC)
+ ev->pmt_hits[id].flags |= 0x2;
+ else if (dqcr_word & KDQCR_B_DAQ)
+ ev->pmt_hits[id].flags |= 0x2;
+ else if (dqcr_word & KDQCR_B_GT)
+ ev->pmt_hits[id].flags |= 0x2;
+ else if (dqcr_word & (1 << (12 + k/8)))
+ ev->pmt_hits[id].flags |= 0x2;
+ }
+ }
+ }
+
+ return 0;
+}