/* Copyright (c) 2019, Anthony Latorre * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) * any later version. * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ #include "dqxx.h" #include "db.h" #include /* for uint32_t */ #include "event.h" #include /* 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; }