//_HADES_CLASS_DESCRIPTION /////////////////////////////////////////////////////////////////////// // HWallTrb3Lookup // // Lookup table for the TRB3 unpacker of the Wall detector to map the // Trbnet address (range defined in htrbnetdef.h) and TDC channel // to the detector address cell. /////////////////////////////////////////////////////////////////////// #include "hdetpario.h" #include "hpario.h" #include "hwalltrb3lookup.h" #include using namespace std; ClassImp(HWallTrb3LookupChan) ClassImp(HWallTrb3LookupTdc) ClassImp(HWallTrb3Lookup) HWallTrb3LookupTdc::HWallTrb3LookupTdc() { // constructor creates an array of 65 channels array = new TObjArray(128); for (Int_t i = 0; i < 128; i++) array->AddAt(new HWallTrb3LookupChan(), i); } HWallTrb3LookupTdc::~HWallTrb3LookupTdc() { // destructor deletes the array of channels array->Delete(); delete array; } void HWallTrb3LookupTdc::clear() { // calls the clear function for each channel for (Int_t i = 0; i < getSize(); i++)(*this)[i].clear(); } //--------------------------------------------------------------- HWallTrb3Lookup::HWallTrb3Lookup(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 nTdcs strcpy(detName,"Wall"); arrayOffset = minTrbnetAddress; array = new TObjArray(maxTrbnetAddress - minTrbnetAddress + 1); initLookup(); } HWallTrb3Lookup::~HWallTrb3Lookup() { // destructor array->Delete(); delete array; } Bool_t HWallTrb3Lookup::init(HParIo* inp, Int_t* set) { // initializes the container from an input HDetParIo* input = inp->getDetParIo("HWallParIo"); if (input) { Bool_t rc = (input->init(this, set)); if (rc && changed){ // fill reverse lookup this->initLookup(); this->fillLookup(); return rc; } } return kFALSE; } Int_t HWallTrb3Lookup::write(HParIo* output) { // writes the container to an output HDetParIo* out = output->getDetParIo("HWallParIo"); if (out) return out->write(this); return -1; } void HWallTrb3Lookup::clear() { // deletes all HWallTrb3LookupTdc objects from the array and resets the input versions array->Delete(); status = kFALSE; resetInputVersions(); } void HWallTrb3Lookup::printParam() { // prints the lookup table printf("Lookup table for the TRB3 unpacker of the Wall detector\n"); printf("trbnet-address channel cell\n"); for (Int_t i = 0; i <= array->GetLast(); i++) { HWallTrb3LookupTdc* b = (*this)[i]; if (b) { for (Int_t j = 0; j < b->getSize(); j++) { HWallTrb3LookupChan& chan = (*b)[j]; //Int_t module = chan.getModule(); //Int_t sector = chan.getSector(); Int_t cell = chan.getCell(); if (cell >= 0) { printf("0x%x %4i %5i\n", arrayOffset + i, j, cell); } } } } } Bool_t HWallTrb3Lookup::fill(Int_t id, Int_t chan, Int_t cell) { // creates the HWallTrb3LookupTdc objects, if not existing, and fills the channel Bool_t rc = kFALSE; HWallTrb3LookupTdc* p = getTdc(id); if (!p) { p = new HWallTrb3LookupTdc(); array->AddAt(p, id - arrayOffset); } HWallTrb3LookupChan* c = p->getChannel(chan); if (c) { c->fill(cell); rc = kTRUE; } else { Error("fill", "Invalid channel number %i", chan); } return rc; } void HWallTrb3Lookup::initLookup() { //?? for(Int_t c=0;c<303;c++){ lookup[c][0] = -1; lookup[c][1] = -1; } } void HWallTrb3Lookup::fillLookup() { for (Int_t i = 0; i <= array->GetLast(); i++) { HWallTrb3LookupTdc* b = (*this)[i]; if (b) { for (Int_t j = 0; j < b->getSize(); j++) { HWallTrb3LookupChan& chan = (*b)[j]; Int_t c = chan.getCell(); if(c<0) continue; lookup[c][0] = arrayOffset + i; lookup[c][1] = j; } } } } Bool_t HWallTrb3Lookup::find(Int_t c,Int_t& tdc,Int_t& chan) { if(c>=0 && c<303) { tdc =lookup[c][0]; chan=lookup[c][1]; return kTRUE; } return kFALSE; } Bool_t HWallTrb3Lookup::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, cell; Int_t n = sscanf(buf, " 0x%x %i %i", &id, &chan, &cell); if (3 == n) { rc = fill(id, chan, cell); } else { if (n < 3) Error("readline", "Not enough values in line %s\n", buf); else Error("readline", "Too many values in line %s\n", buf); } return rc; } void HWallTrb3Lookup::putAsciiHeader(TString& header) { // puts the ASCII header to the string used in HWallParAsciiFileIo header = "# Lookup table for the TRB3 unpacker of the Wall detector\n" "# Format:\n" "# trbnet-address channel cell\n"; } void HWallTrb3Lookup::write(fstream& fout) { // writes the information of all non-zero HWallTrb3LookupTdc objects to the ASCII file for (Int_t i = 0; i <= array->GetLast(); i++) { HWallTrb3LookupTdc* b = (*this)[i]; if (b) { for (Int_t j = 0; j < b->getSize(); j++) { HWallTrb3LookupChan& chan = (*b)[j]; //Int_t sector = chan.getSector(); //Int_t module = chan.getModule(); Int_t cell = chan.getCell(); if (cell >= 0) { fout << "0x" << hex << (arrayOffset + i) << dec << setw(5) << j << setw(5) << chan.getCell() << '\n'; } } } } }