//_HADES_CLASS_DESCRIPTION /////////////////////////////////////////////////////////////////////// // // HStsTrb3Lookup // // Lookup table for the TRB3 unpacker of the Sts to map the // Trbnet address (range defined in htrbnetdef.h) and channel (0..255) // to the detector address module, cell. // /////////////////////////////////////////////////////////////////////// #include "hststrb3lookup.h" #include "hdetpario.h" #include "hpario.h" #include using namespace std; ClassImp(HStsTrb3Lookup) ClassImp(HStsTrb3LookupTdc) HStsTrb3LookupTdc::HStsTrb3LookupTdc() { // constructor creates an array of STS_TRB3_LOOKUP_SIZE channels array = new TObjArray(STS_TRB3_LOOKUP_SIZE); for (Int_t i = 0; i < STS_TRB3_LOOKUP_SIZE; i++) array->AddAt(new HStsTrb3LookupChan(), i); } HStsTrb3LookupTdc::~HStsTrb3LookupTdc() { // destructor deletes the array of channels array->Delete(); delete array; } void HStsTrb3LookupTdc::clear() { // calls the clear function for each channel for (Int_t i = 0; i < STS_TRB3_LOOKUP_SIZE; i++) (*this)[i].clear(); } //--------------------------------------------------------------- HStsTrb3Lookup::HStsTrb3Lookup(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); } HStsTrb3Lookup::~HStsTrb3Lookup() { // destructor array->Delete(); delete array; } Bool_t HStsTrb3Lookup::init(HParIo *inp, Int_t *set) { // initializes the container from an input HDetParIo *input = inp->getDetParIo("HStsParIo"); if (input) return (input->init(this, set)); return kFALSE; } Int_t HStsTrb3Lookup::write(HParIo *output) { // writes the container to an output HDetParIo *out = output->getDetParIo("HStsParIo"); if (out) return out->write(this); return -1; } void HStsTrb3Lookup::clear() { // deletes all HStsTrb3LookupTdc objects from the array and resets the input versions array->Delete(); status = kFALSE; resetInputVersions(); } void HStsTrb3Lookup::printParams() { // prints the lookup table printf("Lookup table for the TRB3 unpacker of the Sts\n"); printf("trbnet-address channel -> module layer cell subcell\n"); for (Int_t i = 0; i <= array->GetLast(); i++) { HStsTrb3LookupTdc *b = (*this)[i]; if (b) { for (Int_t j = 0; j < b->getSize(); j++) { HStsTrb3LookupChan &chan = (*b)[j]; Int_t module = chan.getModule(); if (module >= 0) { printf("0x%x %4i %5i %5i %5i %5i\n", arrayOffset + i, j, module, chan.getLayer(), chan.getCell(), chan.getSubCell()); } } } } } Bool_t HStsTrb3Lookup::fill(Int_t id, Int_t chan, Char_t mod, Char_t layer, Int_t cell, Char_t subcell) { // creates the HStsTrb3LookupTdc objects, if not existing, and fills the channel Bool_t rc = kFALSE; HStsTrb3LookupTdc *p = getTdc(id); if (!p) { p = new HStsTrb3LookupTdc(); array->AddAt(p, id - arrayOffset); } HStsTrb3LookupChan *c = p->getChannel(chan); if (c) { c->fill(mod, layer, cell, subcell); rc = kTRUE; } else { Error("fill", "Invalid channel number %i", chan); } return rc; } Bool_t HStsTrb3Lookup::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, mod, lay, cell, subcell; Int_t n = sscanf(buf, " 0x%x %i %i %i %i %i", &id, &chan, &mod, &lay, &cell, &subcell); if (6 == n) { rc = fill(id, chan, mod, lay, cell, subcell); } 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 HStsTrb3Lookup::putAsciiHeader(TString &header) { // puts the ASCII header to the string used in HStsParAsciiFileIo header = "# Lookup table for the TRB3 unpacker of the Sts\n" "# Format:\n" "# trbnet-address channel module layer cell subcell\n"; } void HStsTrb3Lookup::write(fstream &fout) { // writes the information of all non-zero HStsTrb3LookupTdc objects to the ASCII file for (Int_t i = 0; i <= array->GetLast(); i++) { HStsTrb3LookupTdc *b = (*this)[i]; if (b) { for (Int_t j = 0; j < b->getSize(); j++) { HStsTrb3LookupChan &chan = (*b)[j]; Int_t module = chan.getModule(); if (module >= 0) { fout << "0x" << hex << (arrayOffset + i) << dec << setw(5) << j << setw(5) << module << setw(5) << (Int_t)chan.getLayer() << setw(5) << (Int_t)chan.getCell() << setw(5) << (Int_t)chan.getSubCell() << '\n'; } } } } }