//_HADES_CLASS_DESCRIPTION /////////////////////////////////////////////////////////////////////// // // HFRpcTrb3Lookup // // Lookup table for the TRB3 unpacker of the FRpc to map the // Trbnet address (range defined in htrbnetdef.h) and channel (0..255) // to the detector address sector, strip f-n side. // /////////////////////////////////////////////////////////////////////// #include "hfrpctrb3lookup.h" #include "hdetpario.h" #include "hpario.h" #include using namespace std; HFRpcTrb3LookupTdc::HFRpcTrb3LookupTdc() { // constructor creates an array of FRPC_TRB3_LOOKUP_SIZE channels array = new TObjArray(FRPC_TRB3_LOOKUP_SIZE); for (Int_t i = 0; i < FRPC_TRB3_LOOKUP_SIZE; i++) array->AddAt(new HFRpcTrb3LookupChan(), i); } HFRpcTrb3LookupTdc::~HFRpcTrb3LookupTdc() { // destructor deletes the array of channels array->Delete(); delete array; } void HFRpcTrb3LookupTdc::clear() { // calls the clear function for each channel for (Int_t i = 0; i < FRPC_TRB3_LOOKUP_SIZE; i++) (*this)[i].clear(); } //--------------------------------------------------------------- HFRpcTrb3Lookup::HFRpcTrb3Lookup(const Char_t *name, const Char_t *title, const Char_t *context, Int_t minTrbnetAddress, Int_t maxTrbnetAddress) : HParSet(name, title, context) { // constructor creates an empty array of size nBoards arrayOffset = minTrbnetAddress; array = new TObjArray(maxTrbnetAddress - minTrbnetAddress + 1); } HFRpcTrb3Lookup::~HFRpcTrb3Lookup() { // destructor array->Delete(); delete array; } Bool_t HFRpcTrb3Lookup::init(HParIo *inp, Int_t *set) { // initializes the container from an input HDetParIo *input = inp->getDetParIo("HFRpcParIo"); if (input) return (input->init(this, set)); return kFALSE; } Int_t HFRpcTrb3Lookup::write(HParIo *output) { // writes the container to an output HDetParIo *out = output->getDetParIo("HFRpcParIo"); if (out) return out->write(this); return -1; } void HFRpcTrb3Lookup::clear() { // deletes all HFRpcTrb3LookupTdc objects from the array and resets the input versions array->Delete(); status = kFALSE; resetInputVersions(); } void HFRpcTrb3Lookup::printParams() { // prints the lookup table printf("Lookup table for the TRB3 unpacker of the FRpc\n"); printf("trbnet-address channel -> sector column strip side\n"); for (Int_t i = 0; i <= array->GetLast(); i++) { HFRpcTrb3LookupTdc *b = (*this)[i]; if (b) { for (Int_t j = 0; j < b->getSize(); j++) { HFRpcTrb3LookupChan &chan = (*b)[j]; Int_t sector = chan.getSector(); if (sector >= 0) { printf("0x%x %4i %5i %5i %5i %c\n", arrayOffset + i, j, sector, chan.getColumn(), chan.getStrip(), chan.getSide()); } } } } } Bool_t HFRpcTrb3Lookup::fill(Int_t id, Int_t chan, Char_t sec, Char_t column, Char_t strip, Char_t side) { // creates the HFRpcTrb3LookupTdc objects, if not existing, and fills the channel Bool_t rc = kFALSE; HFRpcTrb3LookupTdc *p = getTdc(id); if (!p) { p = new HFRpcTrb3LookupTdc(); array->AddAt(p, id - arrayOffset); } HFRpcTrb3LookupChan *c = p->getChannel(chan); if (c) { c->fill(sec, column, strip, side); rc = kTRUE; } else { Error("fill", "Invalid channel number %i", chan); } return rc; } Bool_t HFRpcTrb3Lookup::readline(const Char_t *buf) { // decodes one line read from ASCII file I/O and fills the channel Bool_t rc = kFALSE; Int_t id, chan, sec, lay, strip; Char_t side; Int_t n = sscanf(buf, " 0x%x %i %i %i %i %c", &id, &chan, &sec, &lay, &strip, &side); if (6 == n) { rc = fill(id, chan, sec, lay, strip, side); } else { if (n < 6) Error("readline", "Not enough values in line %s\n", buf); else Error("readline", "Too many values in line %s\n", buf); } return rc; } void HFRpcTrb3Lookup::putAsciiHeader(TString &header) { // puts the ASCII header to the string used in HFRpcParAsciiFileIo header = "# Lookup table for the TRB3 unpacker of the FRpc\n" "# Format:\n" "# trbnet-address channel sector column strip side\n"; } void HFRpcTrb3Lookup::write(fstream &fout) { // writes the information of all non-zero HFRpcTrb3LookupTdc objects to the ASCII file for (Int_t i = 0; i <= array->GetLast(); i++) { HFRpcTrb3LookupTdc *b = (*this)[i]; if (b) { for (Int_t j = 0; j < b->getSize(); j++) { HFRpcTrb3LookupChan &chan = (*b)[j]; Int_t sector = chan.getSector(); if (sector >= 0) { fout << "0x" << hex << (arrayOffset + i) << dec << setw(5) << j << setw(5) << sector << setw(5) << (int)chan.getColumn() << setw(5) << (int)chan.getStrip() << setw(5) << chan.getSide() << '\n'; } } } } }