//_HADES_CLASS_DESCRIPTION ////////////////////////////////////////////////////////////////////// // HRpcTrb3Lookup // // Lookup table for the TRB3 unpacker of the RPC detector to map the // Trbnet address to the detector address // sector, column, cell, side, front-end address. ////////////////////////////////////////////////////////////////////// using namespace std; #include "hrpctrb3lookup.h" #include "hpario.h" #include "hdetpario.h" #include #include #include #include ClassImp(HRpcTrb3LookupChan) ClassImp(HRpcTrb3LookupBoard) ClassImp(HRpcTrb3Lookup) HRpcTrb3LookupBoard::HRpcTrb3LookupBoard() { // constructor creates an array of 128 channels array = new TObjArray(65); for(Int_t i=0;i<65;i++) array->AddAt(new HRpcTrb3LookupChan(),i); } HRpcTrb3LookupBoard::~HRpcTrb3LookupBoard() { // destructor deletes the array of channels array->Delete(); delete array; } void HRpcTrb3LookupBoard::clear() { // calls the clear function for each channel for(Int_t i=0;i<65;i++) (*this)[i].clear(); } //--------------------------------------------------------------- HRpcTrb3Lookup::HRpcTrb3Lookup(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(); } HRpcTrb3Lookup::~HRpcTrb3Lookup() { // destructor array->Delete(); delete array; } Bool_t HRpcTrb3Lookup::init(HParIo* inp,Int_t* set) { // initializes the container from an input HDetParIo* input=inp->getDetParIo("HRpcParIo"); if (input){ Bool_t rc = (input->init(this,set)); if(rc && changed){ this->initLookup(); this->fillLookup(); } return rc; } return kFALSE; } Int_t HRpcTrb3Lookup::write(HParIo* output) { // writes the container to an output HDetParIo* out=output->getDetParIo("HRpcParIo"); if (out) return out->write(this); return -1; } void HRpcTrb3Lookup::clear() { // deletes all HRpcTrb3LookupBoard objects from the array and resets the input versions array->Delete(); status=kFALSE; resetInputVersions(); } void HRpcTrb3Lookup::printParam() { // prints the lookup table printf("Lookup table for the TRB2 unpacker of the RPC detector\n"); printf("trbnet-address channel sector column cell side front-end address geomname\n"); printf("side: l-left, r-right\n"); for(Int_t i=0;i<=array->GetLast();i++) { HRpcTrb3LookupBoard* b=(*this)[i]; if (b) { for(Int_t j=0;jgetSize();j++) { HRpcTrb3LookupChan& chan=(*b)[j]; Int_t sector=chan.getSector(); if (sector>=0) { TString n = chan.getGeomName(); printf("0x%x %4i %3i%4i%4i %c %i %s\n", arrayOffset+i,j,sector, chan.getColumn(),chan.getCell(),chan.getSide(),chan.getFeAddress(),n.Data()); } } } } } Bool_t HRpcTrb3Lookup::fill(Int_t id,Int_t chan, Int_t sec,Int_t mod,Int_t cell,Char_t side,Int_t fea, TString& n) { // creates the HRpcTrb3LookupBoard objects, if not existing, and fills the channel Bool_t rc=kFALSE; HRpcTrb3LookupBoard* p=getBoard(id); if (!p) { p=new HRpcTrb3LookupBoard(); array->AddAt(p,id-arrayOffset); } HRpcTrb3LookupChan* c=p->getChannel(chan); if (c) { c->fill(sec,mod,cell,side,fea,n); rc=kTRUE; } else { Error("fill","Invalid channel number %i",chan); } return rc; } void HRpcTrb3Lookup::initLookup() { for(Int_t s=0;s<6;s++){ for(Int_t col=0;col<6;col++){ for(Int_t c=0;c<50;c++){ for(Int_t si=0;si<2;si++){ lookup[s][col][c][si][0] = -1; lookup[s][col][c][si][1] = -1; } } } } } void HRpcTrb3Lookup::fillLookup() { for (Int_t i = 0; i <= array->GetLast(); i++) { HRpcTrb3LookupBoard* b = (*this)[i]; if (b) { for (Int_t j = 0; j < b->getSize(); j++) { HRpcTrb3LookupChan& chan = (*b)[j]; Int_t col = chan.getColumn(); 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||col<0||col>5||c<0||c>49||si<0||si>1) continue; lookup[s][col][c][si][0] = arrayOffset + i; lookup[s][col][c][si][1] = j; } } } } Bool_t HRpcTrb3Lookup::find(Int_t s,Int_t col,Int_t c,Int_t si,Int_t& tdc,Int_t& chan) { // returns tdc and chan for address s,col,cell,side (right = 0,left =1) if(s>=0&&col>=0&&c>=0&&si>=0&& s<6&&col<6&&c<50&&si<2) { tdc =lookup[s][col][c][si][0]; chan=lookup[s][col][c][si][1]; return kTRUE; } return kFALSE; } Bool_t HRpcTrb3Lookup::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, feAddress; Char_t side='\0'; Char_t gn[100]; Int_t n=sscanf(buf," 0x%x %i %i %i %i %c %i %s",&id,&chan,&sec,&mod,&cell,&side,&feAddress,gn); if (8==n) { TString gN=gn; rc=fill(id,chan,sec,mod,cell,side,feAddress,gN); } else { if (n<8) Error("readline","Not enough values in line %s\n",buf); else Error("readline","Too many values in line %s\n",buf); } return rc; } void HRpcTrb3Lookup::putAsciiHeader(TString& header) { // puts the ASCII header to the string used in HRpcParAsciiFileIo header= "# Lookup table for the TRB2 unpacker of the RPC detector\n" "# Format:\n" "# trbnet-address channel sector column cell side front-end-address geomname\n"; } void HRpcTrb3Lookup::write(fstream& fout) { // writes the information of all non-zero HRpcTrb3LookupBoard objects to the ASCII file for(Int_t i=0;i<=array->GetLast();i++) { HRpcTrb3LookupBoard* b=(*this)[i]; if (b) { for(Int_t j=0;jgetSize();j++) { HRpcTrb3LookupChan& chan=(*b)[j]; Int_t sector=chan.getSector(); if (sector>=0) { fout<<"0x"<