From 5335e8210053c299e6e147312198768ca2c9229a Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Thu, 21 Feb 2013 15:55:11 +0000 Subject: [PATCH] included setroi for multidet git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@466 951219d9-93cf-4727-9268-0efd64621fa3 --- .../slsDetector/slsDetector.cpp | 108 +++++++++++++++--- slsDetectorSoftware/slsDetector/slsDetector.h | 40 +++++-- .../slsDetector/slsDetectorCommand.cpp | 103 +++++++++++------ .../slsDetector/slsDetectorUtils.h | 25 +++- 4 files changed, 207 insertions(+), 69 deletions(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index a4b9ef7ae..f83b32450 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -3912,20 +3912,99 @@ int slsDetector::setDynamicRange(int n){ }; -/* -int slsDetector::setROI(int nroi, int *xmin, int *xmax, int *ymin, int *ymax){ - return thisDetector->nROI; -}; +int slsDetector::setROI(int n,ROI roiLimits[]){ + int ret = FAIL; + //sort ascending order + int temp; + for(int i=0;inROI; + return thisDetector->roiLimits; +} + + +int slsDetector::sendROI(int n,ROI roiLimits[]){ + int ret=FAIL; + int fnum=F_SET_ROI; + char mess[100]; + int arg = n; + int retvalsize=0; + ROI retval[MAX_ROIS]; + int nrec=-1; + + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (controlSocket) { + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&arg,sizeof(arg)); + if(arg==-1){; +#ifdef VERBOSE + cout << "Getting ROI from detector" << endl; +#endif + }else{ +#ifdef VERBOSE + cout << "Sending ROI of size " << arg << " to detector" << endl; +#endif + controlSocket->SendDataOnly(roiLimits,arg*sizeof(ROI)); + } + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + + if (ret!=FAIL){ + controlSocket->ReceiveDataOnly(&retvalsize,sizeof(retvalsize)); + nrec = controlSocket->ReceiveDataOnly(retval,retvalsize*sizeof(ROI)); + if(nrec!=(retvalsize*sizeof(ROI))){ + ret=FAIL; + std::cout << " wrong size received: received " << nrec << "but expected " << retvalsize*sizeof(ROI) << endl; + } + }else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + } + + //update client + if(ret!=FAIL){ + for(int i=0;iroiLimits[i]=retval[i]; + thisDetector->nROI = retvalsize; + } + +#ifdef VERBOSE + for(int j=0;jnROI;j++) + cout<nROI; -}; -*/ /* @@ -4727,7 +4806,7 @@ int slsDetector::setUDPConnection(){ updateReceiver(); //configure detector with udp details, -100 is so it doesnt overwrite the previous value - if(configureMAC(-1)==FAIL){ + if(configureMAC()==FAIL){ setReceiverOnline(OFFLINE_FLAG); std::cout << "could not configure mac" << endl; } @@ -4741,7 +4820,7 @@ int slsDetector::setUDPConnection(){ -int slsDetector::configureMAC(int adc){ +int slsDetector::configureMAC(){ int i; int ret=FAIL; int fnum=F_CONFIGURE_MAC; @@ -4751,12 +4830,6 @@ int slsDetector::configureMAC(int adc){ string sword; int retval=-1; - if(((adc>=-1)&&(adc<=4))||(adc==-100)); - else{ - std::cout << "configure mac failed.\nConfigure [adc]; adc should be -1, 0, 1, 2, 3 or 4" << endl; - setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); - return FAIL; - } //if udpip wasnt initialized in config file if(!(strcmp(thisDetector->receiverUDPIP,"none"))){ @@ -4782,7 +4855,7 @@ int slsDetector::configureMAC(int adc){ strcpy(arg[4],thisDetector->detectorIP); #ifdef VERBOSE - std::cout<< "Configuring MAC with adc:"<< adc << std::endl; + std::cout<< "Configuring MAC"<< std::endl; #endif @@ -4849,7 +4922,6 @@ int slsDetector::configureMAC(int adc){ if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(arg,sizeof(arg)); - controlSocket->SendDataOnly(&adc,sizeof(adc)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); if (ret==FAIL){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 266d66bb4..6210eadb0 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -308,10 +308,9 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** configures mac for gotthard readout - \param adc adc number \returns OK or FAIL */ - int configureMAC(int adc=-1); + int configureMAC(); /** Reads the configuration file fname @@ -571,16 +570,30 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** Returns the number of modules (without connecting to the detector) */ int getNMods(){return thisDetector->nMods;}; // + /** Returns the number of modules in direction d (without connecting to the detector) */ + int getNMod(dimension d){return thisDetector->nMod[d];}; // + int getChansPerMod(int imod=0){return thisDetector->nChans*thisDetector->nChips;}; + /** Returns the max number of modules in direction d (without connecting to the detector) */ + int getNMaxMod(dimension d){return thisDetector->nModMax[d];}; // + /** Returns the number of modules (without connecting to the detector) */ int getMaxMods(){return thisDetector->nModsMax;}; // int getTotalNumberOfChannels(){return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;}; + int getTotalNumberOfChannels(dimension d){return thisDetector->nChans*thisDetector->nChips*thisDetector->nMod[X];}; + int getMaxNumberOfChannels(){return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax;}; + int getMaxNumberOfChannels(dimension d){return thisDetector->nChans*thisDetector->nChips*thisDetector->nModMax[d];}; + + /** Returns number of rois */ + int getNRoi(){return thisDetector->nROI;}; + + /* Communication to server */ @@ -1038,18 +1051,23 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int getDataBytes(){return thisDetector->dataBytes;}; - - /** + /** set roi - \param nroi number of rois - \param xmin x minimum of roi - \param xmax x maximum of roi - \param ymin y minimum of roi - \param ymax y maximum of roi - \returns number of rois added + \param n number of rois + \param roiLimits array of roi + \returns success or failure */ - //int setROI(int nroi=-1, int *xmin=NULL, int *xmax=NULL, int *ymin=NULL, int *ymax=NULL); + int setROI(int n=-1,ROI roiLimits[]=NULL); + /** + get roi from each detector and convert it to the multi detector scale + \param n number of roi + \returns an array of multidetector's rois + */ + slsDetectorDefs::ROI* getROI(int &n); + + + int sendROI(int n=-1,ROI roiLimits[]=NULL); /** set/get readout flags diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 27f7f5cc1..da072758c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -383,9 +383,14 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; i++; - //descrToFuncMap[i].m_pFuncName="roi"; // - //descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; - //i++; + descrToFuncMap[i].m_pFuncName="roi"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; + i++; + + descrToFuncMap[i].m_pFuncName="detsizechan"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; + i++; + /* flags */ @@ -2513,15 +2518,12 @@ string slsDetectorCommand::cmdConfigureMac(int narg, char *args[], int action) { if (action==HELP_ACTION) { return helpConfigureMac(narg,args,action); } - int ival; int ret; char ans[1000]; if (action==PUT_ACTION){ - if (sscanf(args[1],"%d",&ival)){ - myDet->setOnline(ONLINE_FLAG); - ret=myDet->configureMAC(ival); - } + myDet->setOnline(ONLINE_FLAG); + ret=myDet->configureMAC(); } else return string("Cannot get ")+cmd; @@ -2534,7 +2536,7 @@ string slsDetectorCommand::helpConfigureMac(int narg, char *args[], int action) ostringstream os; if (action==PUT_ACTION || action==HELP_ACTION) - os << "configuremac i \n configures the MAC of the detector. i is adc number. -1 for all adcs"<< std::endl; + os << "configuremac i \n configures the MAC of the detector."<< std::endl; if (action==GET_ACTION || action==HELP_ACTION) os << "configuremac " << "Cannot get " << std::endl; @@ -2544,38 +2546,65 @@ string slsDetectorCommand::helpConfigureMac(int narg, char *args[], int action) string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) { - if (action==HELP_ACTION) - return helpDetectorSize(narg,args,action); - int ret, val=-1; - char ans[1000]; - // portType index; + if (action==HELP_ACTION) + return helpDetectorSize(narg,args,action); + int ret, val=-1, pos=-1,i; + char ans[1000], temp[100]; - if (action==PUT_ACTION) { - if (cmd=="maxmod") - return string("cannot put!"); - // else if (cmd=="roi"){ - // } else - if (sscanf(args[1],"%d",&val)) - ; - else - return string("could not scan ")+string(args[0])+string(" ")+string(args[1]); - } + if (action==PUT_ACTION) { + if (cmd=="maxmod") + return string("cannot put!"); + else if (!sscanf(args[1],"%d",&val)) + return string("could not scan ")+string(args[0])+string(" ")+string(args[1]); - myDet->setOnline(ONLINE_FLAG); + myDet->setOnline(ONLINE_FLAG); - if (cmd=="nmod") { - ret=myDet->setNumberOfModules(val); - } else if (cmd=="maxmod") { - ret=myDet->getMaxNumberOfModules(); - } else if (cmd=="dr") { - ret=myDet->setDynamicRange(val); - } else - return string("unknown detector size ")+cmd; - + if (cmd=="roi"){ + //debug number of arguments + if ((val<0) || (narg!=((val*4)+2)) ) + return helpDetectorSize(narg,args,action); + ROI allroi[val]; + pos=2; + for(int i=0;isetROI(val,allroi); + } - sprintf(ans,"%d",ret); - return string(ans); + if(cmd=="detsizechan"){ + if ((sscanf(args[1],"%d",&val)) && (val>0)) + myDet->setMaxNumberOfChannelsPerDetector(X,val); + if ((narg > 2) && (sscanf(args[2],"%d",&val)) && (val>0)) + myDet->setMaxNumberOfChannelsPerDetector(Y,val); + } + } + + if (cmd=="nmod") { + ret=myDet->setNumberOfModules(val); + } else if (cmd=="maxmod") { + ret=myDet->getMaxNumberOfModules(); + } else if (cmd=="dr") { + ret=myDet->setDynamicRange(val); + } else if (cmd=="roi") { + myDet->getROI(ret); + } else if (cmd=="detsizechan") { + sprintf(ans,"%d",myDet->getMaxNumberOfChannelsPerDetector(X)); + sprintf(temp,"%d",myDet->getMaxNumberOfChannelsPerDetector(Y)); + strcat(ans," "); + strcat(ans,temp); + return string(ans); + } + else + return string("unknown detector size ")+cmd; + + + sprintf(ans,"%d",ret); + return string(ans); } @@ -2586,12 +2615,14 @@ string slsDetectorCommand::helpDetectorSize(int narg, char *args[], int action) if (action==PUT_ACTION || action==HELP_ACTION) { os << "nmod i \n sets the number of modules of the detector"<< std::endl; os << "dr i \n sets the dynamic range of the detector"<< std::endl; + os << "roi i xmin xmax ymin ymax \n sets region of interest where i is number of rois;i=0 to clear rois"<< std::endl; } if (action==GET_ACTION || action==HELP_ACTION) { os << "nmod \n gets the number of modules of the detector"<< std::endl; os << "maxmod \n gets the maximum number of modules of the detector"<< std::endl; os << "dr \n gets the dynamic range of the detector"<< std::endl; + os << "roi \n gets region of interest"<< std::endl; } return os.str(); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 30a26a0b4..469bdf516 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -38,7 +38,6 @@ using namespace std; #include "postProcessing.h" #define MAX_TIMERS 11 -#define MAX_ROIS 100 #define MAXPOS 50 #define DEFAULT_HOSTNAME "localhost" @@ -67,6 +66,9 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { virtual int getNumberOfDetectors(){return 1; }; + virtual int getMaxNumberOfChannelsPerDetector(dimension d){return -1;}; + + virtual int setMaxNumberOfChannelsPerDetector(dimension d,int i){return -1;}; //int setPositions(int nPos, double *pos){return angularConversion::setPositions(nPos, pos);}; @@ -430,7 +432,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { virtual int getTotalNumberOfChannels()=0; virtual int getMaxNumberOfChannels()=0; - + virtual int getMaxNumberOfChannels(dimension d)=0; // virtual int getParameters(); @@ -474,11 +476,10 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { /** configures mac for gotthard readout - \param adc adc number \returns OK or FAIL */ - virtual int configureMAC(int adc=-1)=0; + virtual int configureMAC()=0; /** loads the modules settings/trimbits reading from a file @@ -656,6 +657,22 @@ virtual int enableWriteToFile(int enable=-1)=0; virtual int calibratePedestal(int frames = 0)=0; +/** + set roi + \param n number of rois + \param roiLimits array of roi + \returns success or failure +*/ +virtual int setROI(int n=-1,ROI roiLimits[]=NULL)=0; + +/** + get roi from each detector and convert it to the multi detector scale + \param n number of rois + \returns an array of multidetector's rois +*/ +virtual ROI* getROI(int &n)=0; + + protected: