aboutsummaryrefslogtreecommitdiff
path: root/src/dqxx.c
blob: 8aa32c0ecc0604b6d90484edecba59b6be2a56b6 (plain)
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
#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];

                /* 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 |= PMT_FLAG_DQXX;
                else if (dqch_word & KDQCH_B_PMTIC_RESISTOR)
                    ev->pmt_hits[id].flags |= PMT_FLAG_DQXX;
                else if (dqch_word & KDQCH_B_SEQUENCER)
                    ev->pmt_hits[id].flags |= PMT_FLAG_DQXX;
                else if (dqch_word & KDQCH_B_750OHM)
                    ev->pmt_hits[id].flags |= PMT_FLAG_DQXX;
                else if (dqch_word & KDQCH_B_NOT_OP)
                    ev->pmt_hits[id].flags |= PMT_FLAG_DQXX;

                if (dqcr_word & KDQCR_B_CRATE)
                    ev->pmt_hits[id].flags |= PMT_FLAG_DQXX;
                else if (dqcr_word & KDQCR_B_MB)
                    ev->pmt_hits[id].flags |= PMT_FLAG_DQXX;
                else if (dqcr_word & KDQCR_B_PMTIC)
                    ev->pmt_hits[id].flags |= PMT_FLAG_DQXX;
                else if (dqcr_word & KDQCR_B_DAQ)
                    ev->pmt_hits[id].flags |= PMT_FLAG_DQXX;
                else if (dqcr_word & KDQCR_B_GT)
                    ev->pmt_hits[id].flags |= PMT_FLAG_DQXX;
                else if (dqcr_word & (1 << (12 + k/8)))
                    ev->pmt_hits[id].flags |= PMT_FLAG_DQXX;
            }
        }
    }

    return 0;
}