//*-- AUTHOR Ilse Koenig //*-- created : 15/12/2009 by Ilse Koenig //_HADES_CLASS_DESCRIPTION ////////////////////////////////////////////////////////////////////// // HTofTrb3Lookup // // Lookup table for the TRB3 unpacker of the TOF detector to map the // Trbnet address (range defined in htrbnetdef.h) and channel (0..127) // to the detector address // sector, module, cell, side. ////////////////////////////////////////////////////////////////////// using namespace std; #include "htoftrb3lookup.h" #include "hpario.h" #include "hdetpario.h" #include #include #include #include ClassImp(HTofTrb3LookupChan) ClassImp(HTofTrb3LookupBoard) ClassImp(HTofTrb3Lookup) HTofTrb3LookupBoard::HTofTrb3LookupBoard() { // constructor creates an array of 128 channels array = new TObjArray(128); for(Int_t i=0;i<128;i++) array->AddAt(new HTofTrb3LookupChan(),i); } HTofTrb3LookupBoard::~HTofTrb3LookupBoard() { // destructor deletes the array of channels array->Delete(); delete array; } void HTofTrb3LookupBoard::clear() { // calls the clear function for each channel for(Int_t i=0;i<128;i++) (*this)[i].clear(); } //--------------------------------------------------------------- HTofTrb3Lookup::HTofTrb3Lookup(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); initLookup(); } HTofTrb3Lookup::~HTofTrb3Lookup() { // destructor array->Delete(); delete array; } Bool_t HTofTrb3Lookup::init(HParIo* inp,Int_t* set) { // initializes the container from an input HDetParIo* input=inp->getDetParIo("HTofParIo"); if (input) { Bool_t rc = (input->init(this,set)); if(rc && changed) { this->initLookup(); this->fillLookup(); } return rc; } return kFALSE; } Int_t HTofTrb3Lookup::write(HParIo* output) { // writes the container to an output HDetParIo* out=output->getDetParIo("HTofParIo"); if (out) return out->write(this); return -1; } void HTofTrb3Lookup::clear() { // deletes all HTofTrb3LookupBoard objects from the array and resets the input versions array->Delete(); status=kFALSE; resetInputVersions(); } void HTofTrb3Lookup::printParam() { // prints the lookup table printf("Lookup table for the TRB3 unpacker of the TOF detector\n"); printf("trbnet-address channel sector module cell side\n"); printf("side: l-left, r-right\n"); for(Int_t i=0;i<=array->GetLast();i++) { HTofTrb3LookupBoard* b=(*this)[i]; if (b) { for(Int_t j=0;jgetSize();j++) { HTofTrb3LookupChan& chan=(*b)[j]; Int_t sector=chan.getSector(); if (sector>=0) { printf("0x%x %4i %3i%4i%4i %c\n", arrayOffset+i,j,sector, chan.getModule(),chan.getCell(),chan.getSide()); } } } } } Bool_t HTofTrb3Lookup::fill(Int_t id,Int_t chan, Int_t sec,Int_t mod,Int_t cell,Char_t side) { // creates the HTofTrb3LookupBoard objects, if not existing, and fills the channel Bool_t rc=kFALSE; HTofTrb3LookupBoard* p=getBoard(id); if (!p) { p=new HTofTrb3LookupBoard(); array->AddAt(p,id-arrayOffset); } HTofTrb3LookupChan* c=p->getChannel(chan); if (c) { c->fill(sec,mod,cell,side); rc=kTRUE; } else { Error("fill","Invalid channel number %i",chan); } return rc; } void HTofTrb3Lookup::initLookup() { for(Int_t s=0;s<6;s++){ for(Int_t m=0;m<8;m++){ for(Int_t c=0;c<8;c++){ for(Int_t si=0;si<2;si++){ lookup[s][m][c][si][0] = -1; lookup[s][m][c][si][1] = -1; } } } } } void HTofTrb3Lookup::fillLookup() { for (Int_t i = 0; i <= array->GetLast(); i++) { HTofTrb3LookupBoard* b = (*this)[i]; if (b) { for (Int_t j = 0; j < b->getSize(); j++) { HTofTrb3LookupChan& chan = (*b)[j]; Int_t m = chan.getModule(); Int_t s = chan.getSector(); Int_t c = chan.getCell(); Int_t side = chan.getSide(); Int_t si = (side == 114) ? 0 : 1; // 'r' == 114 , 'l' == 108 if(s<0||s>5||m<0||m>7||c<0||c>7||si<0||si>1) continue; lookup[s][m][c][si][0] = arrayOffset + i; lookup[s][m][c][si][1] = j; } } } } Bool_t HTofTrb3Lookup::find(Int_t s,Int_t m,Int_t c,Int_t si,Int_t& tdc,Int_t& chan) { // returns tdc and chan for address s,m,cell,side(right = 0,left =1) if(s>=0&&m>=0&&c>=0&&si>=0&& s<6&&m<8&&c<8&&si<2) { tdc =lookup[s][m][c][si][0]; chan=lookup[s][m][c][si][1]; return kTRUE; } return kFALSE; } Bool_t HTofTrb3Lookup::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; Char_t side='\0'; Int_t n=sscanf(buf," 0x%x %i %i%i%i %c",&id,&chan,&sec,&mod,&cell,&side); if (6==n) { rc=fill(id,chan,sec,mod,cell,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 HTofTrb3Lookup::putAsciiHeader(TString& header) { // puts the ASCII header to the string used in HTofParAsciiFileIo header= "# Lookup table for the TRB3 unpacker of the TOF detector\n" "# Format:\n" "# trbnet-address channel sector module cell side\n"; } void HTofTrb3Lookup::write(fstream& fout) { // writes the information of all non-zero HTofTrb3LookupBoard objects to the ASCII file for(Int_t i=0;i<=array->GetLast();i++) { HTofTrb3LookupBoard* b=(*this)[i]; if (b) { for(Int_t j=0;jgetSize();j++) { HTofTrb3LookupChan& chan=(*b)[j]; Int_t sector=chan.getSector(); if (sector>=0) { fout<<"0x"<