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