//*-- AUTHOR : J.Wuestenfeld //*-- Modified : 13/08/2003 by J. Wuestenfeld //////////////////////////////////////////////////////////////////////////// // HMdcTdcChannel // // Container class for the TDC channle masks of the MDC // //////////////////////////////////////////////////////////////////////////// using namespace std; #include #include "hmdctdcchannel.h" #include "hades.h" #include "hruntimedb.h" #include "hspectrometer.h" #include "hmdcdetector.h" #include "hpario.h" #include "hdetpario.h" #include "hmdcrawstruct.h" #include "hmessagemgr.h" #include "hmdcmboreadout.h" #include #include ClassImp(HMdcTdcChannelTdc) ClassImp(HMdcTdcChannelMbo) ClassImp(HMdcTdcChannelMod) ClassImp(HMdcTdcChannelSec) ClassImp(HMdcTdcChannel) void HMdcTdcChannelTdc::fill(HMdcTdcChannelTdc& r) { channelMask[0]=r.getChannelMask(0); channelMask[1]=r.getChannelMask(1); } HMdcTdcChannelMbo::HMdcTdcChannelMbo(Int_t tdc, Text_t* name) { // constructor takes the number of TDCs and the name of the MBO SetName(name); array = new TObjArray(tdc); for (Int_t i=0; iAddAt(new HMdcTdcChannelTdc(),i); } HMdcTdcChannelMbo::~HMdcTdcChannelMbo() { // destructor array->Delete(); delete array; } HMdcTdcChannelMod::HMdcTdcChannelMod(Int_t sec, Int_t mod, Int_t mbo) { // constructor takes the sector, module and MBO number array = new TObjArray(mbo); HMdcRawStruct* pMdc = (HMdcRawStruct*)gHades->getRuntimeDb()->getContainer("MdcRawStruct"); if (pMdc) { HMdcRawModStru& rMod=(*pMdc)[sec][mod]; for (Int_t i=0; iAddAt(new HMdcTdcChannelMbo((Int_t)(rMod[i].getNTdcs()/8),(char*)rMbo.GetName()),i); } } else { ERROR_msg(HMessageMgr::DET_MDC,"HMdcTdcChannelMod not created, container MdcRawStruct not found"); exit(1); } } HMdcTdcChannelMod::~HMdcTdcChannelMod() { // destructor array->Delete(); delete array; } HMdcTdcChannelSec::HMdcTdcChannelSec(Int_t sec, Int_t mod) { // constructor takes the sector, module number array = new TObjArray(mod); for (Int_t i=0; iAddAt(new HMdcTdcChannelMod(sec,i),i); } HMdcTdcChannelSec::~HMdcTdcChannelSec() { // destructor array->Delete(); delete array; } HMdcTdcChannel::HMdcTdcChannel(const char* name,const char* title, const char* context,Int_t n) : HParSet(name,title,context) { // constructor strcpy(detName,"Mdc"); oraVersion=-1; calRotateByRocCode = kFALSE; array = new TObjArray(n); mapNotConnectedChannels = kFALSE; status = kTRUE; for (Int_t i=0; iAddAt(new HMdcTdcChannelSec(i),i); } HMdcTdcChannel::~HMdcTdcChannel() { // destructor array->Delete(); delete array; } Bool_t HMdcTdcChannel::init(HParIo* inp,Int_t* set) { // intitializes the container from an input if((raw_struct=(HMdcRawStruct*)gHades->getRuntimeDb()->getContainer("MdcRawStruct")) == NULL) return kFALSE; if((conWires=(HMdcConnectedWires*)gHades->getRuntimeDb()->getContainer("MdcConnectedWires")) == NULL) return kFALSE; if((mbo_readout=(HMdcMboReadout*)gHades->getRuntimeDb()->getContainer("MdcMboReadout")) == NULL) return kFALSE; if((lookupGeom = (HMdcLookupGeom *)gHades->getRuntimeDb()->getContainer("MdcLookupGeom")) == NULL) return kFALSE; HDetParIo* input=inp->getDetParIo("HMdcParIo"); if(input) if (!input->init(this,set)) return kFALSE; return kTRUE; } Int_t HMdcTdcChannel::write(HParIo* output) { // writes the container to an output HDetParIo* out=output->getDetParIo("HMdcParIo"); if (out) return out->write(this); return -1; } void HMdcTdcChannel::readline(const char* buf, Int_t* set) { // decodes one line read from ascii file I/O and calls HMdcTdcChannelTdc::fill(...) Int_t sec, mod, mbo, dbo; Int_t cal,meas; Char_t mboName[20]; sscanf(buf,"%i%i%i%s%i%x%x",&sec, &mod, &mbo, mboName, &dbo, &cal,&meas); Int_t n=sec*4+mod; if (!set[n]) return; HMdcTdcChannelMbo& rMbo=(*this)[sec][mod][mbo]; rMbo.SetName(mboName); HMdcTdcChannelTdc& tdc=rMbo[dbo]; tdc.fill(cal,0); tdc.fill(meas,1); set[n]=999; } void HMdcTdcChannel::readLineFromFile(const char* buf) { // decodes one line read from ascii file I/O and calls HMdcTdcChannelTdc::fill(...) Int_t sec, mod, mbo, dbo; Int_t cal,meas; sscanf(buf,"%i%i%i%i%x%x", &mod, &sec, &mbo, &dbo, &cal,&meas); HMdcRawModStru & rawMod=(*raw_struct)[sec][mod]; HMdcRawMothStru &rawMbo=rawMod[mbo]; if (rawMbo.getNTdcs() >= dbo*16 ) { HMdcTdcChannelMbo& rMbo=(*this)[sec][mod][mbo]; HMdcTdcChannelTdc& db=rMbo[dbo-1]; db.fill(cal,0); db.fill(meas,1); } } void HMdcTdcChannel::putAsciiHeader(TString& header) { // puts the ascii header to the string used in HMdcParAsciiFileIo header= "# Channelmasks of the MDC TDC\n" "# Format:\n" "# sector module mbo mboName TDC# cal. mask meas. mask\n"; } Bool_t HMdcTdcChannel::writeChannelMasks(char *ofilename, Int_t plane, Int_t sector) { FILE *Ofile; Int_t module = plane -1; char *buf, *bufn, *fileout; Int_t mbo, port, i, roc, lvl1; i = 0; buf = new char[256]; bufn= new char[256]; fileout= new char[256]; Bool_t isFirst; if(!status) { ERROR_msg(HMessageMgr::DET_MDC,"This version is no longer valid for DAQ!"); return kFALSE; } if(mapNotConnectedChannels) mapOutChannels(); sprintf(fileout,"%s",ofilename); switch(plane){ case 1 : strcat(fileout,"I"); break; case 2 : strcat(fileout,"II"); break; case 3 : strcat(fileout,"III"); break; case 4 : strcat(fileout,"IV"); break; } sprintf(fileout,"%s%d%s",fileout,sector+1,"/channels.conf"); Ofile = fopen(fileout,"w"); if(Ofile == NULL) return 2; sprintf(buf,"%s\t%d\n","plane",plane); fputs(buf,Ofile); sprintf(buf,"%s %d\n","channelsversion",oraVersion); fputs(buf,Ofile); sprintf(buf,"%s %d\n","RocDoesCal",getCalRotateByRocCode()); fputs(buf,Ofile); HMdcMboReadoutMod & rMod = (*mbo_readout)[sector][module]; HMdcTdcChannelMod& rModMask=(*this)[sector][module]; sprintf(buf,"-----------------------------------\n"); fputs(buf,Ofile); sprintf(buf,"%s%s%d%s\n","------------"," Plane ",plane,"--------------"); fputs(buf,Ofile); sprintf(buf,"-----------------------------------\n"); fputs(buf,Ofile); sprintf(buf,"\n"); for(roc = 1; roc <= 5; roc++){ isFirst=kTRUE; for(port = 0; port <2; port++){ for(lvl1=1;lvl1<4;lvl1++) { for(mbo =0 ; mbo < rMod.getSize() ; mbo++){ HMdcMboReadoutMoth& rMoth = rMod[mbo]; if (mbo < rModMask.getSize()){ if ((rMoth.getRoc()==roc) && (rMoth.getBusPos()==port) && (rMoth.getBus()==lvl1)) { if (isFirst) { sprintf(buf,"ROC %d\n",roc); fputs(buf,Ofile); isFirst=kFALSE; } sprintf(bufn,"mbo %s %d %x %x %x %x %x %x %x %x",rModMask[mbo].GetName(),port, rModMask[mbo][0].getChannelMask(1),rModMask[mbo][1].getChannelMask(1), rModMask[mbo][2].getChannelMask(1),rModMask[mbo][3].getChannelMask(1), rModMask[mbo][4].getChannelMask(1),rModMask[mbo][5].getChannelMask(1), rModMask[mbo][6].getChannelMask(1),rModMask[mbo][7].getChannelMask(1)); Int_t ndbo; ndbo = rModMask[mbo].getSize(); if(ndbo > 8) { if(rModMask[mbo][8].getChannelMask(1) != -1) { sprintf(buf,"%s %x %x %x %x\n",bufn, rModMask[mbo][8].getChannelMask(1),rModMask[mbo][9].getChannelMask(1), rModMask[mbo][10].getChannelMask(1),rModMask[mbo][11].getChannelMask(1)); } else sprintf(buf,"%s %d %d %d %d\n",bufn,-1,-1,-1,-1); } else sprintf(buf,"%s %d %d %d %d\n",bufn,-1,-1,-1,-1); fputs(buf,Ofile); if(!calRotateByRocCode) { sprintf(bufn,"mbo %s %d %x %x %x %x %x %x %x %x",rModMask[mbo].GetName(),port, rModMask[mbo][0].getChannelMask(0)&rModMask[mbo][0].getChannelMask(1), rModMask[mbo][1].getChannelMask(0)&rModMask[mbo][1].getChannelMask(1), rModMask[mbo][2].getChannelMask(0)&rModMask[mbo][2].getChannelMask(1), rModMask[mbo][3].getChannelMask(0)&rModMask[mbo][3].getChannelMask(1), rModMask[mbo][4].getChannelMask(0)&rModMask[mbo][4].getChannelMask(1), rModMask[mbo][5].getChannelMask(0)&rModMask[mbo][5].getChannelMask(1), rModMask[mbo][6].getChannelMask(0)&rModMask[mbo][6].getChannelMask(1), rModMask[mbo][7].getChannelMask(0)&rModMask[mbo][7].getChannelMask(1)); Int_t ndbo; ndbo = rModMask[mbo].getSize(); if(ndbo > 8) { if(rModMask[mbo][8].getChannelMask(0) != -1) { sprintf(buf,"%s %x %x %x %x\n",bufn, rModMask[mbo][8].getChannelMask(0)&rModMask[mbo][8].getChannelMask(1), rModMask[mbo][9].getChannelMask(0)&rModMask[mbo][9].getChannelMask(1), rModMask[mbo][10].getChannelMask(0)&rModMask[mbo][10].getChannelMask(1), rModMask[mbo][11].getChannelMask(0)&rModMask[mbo][11].getChannelMask(1)); } else sprintf(buf,"%s %d %d %d %d\n",bufn,-1,-1,-1,-1); } else sprintf(buf,"%s %d %d %d %d\n",bufn,-1,-1,-1,-1); fputs(buf,Ofile); } } } else cout << " Error " <getMsg()->info(10,HMessageMgr::DET_MDC,GetName(), "%1i %1i %2i %s %1i %2x %2x", s, m, l, mbo.GetName(), c, mbo[c].getChannelMask(0), mbo[c].getChannelMask(1)); } } } } SEPERATOR_msg("-",60); } void HMdcTdcChannel::mapOutChannels(void) { // Maps out all channels that have no wire connected. Test is done against HMdcLookupGeom container. for(Int_t s=0;s