- Refactored histogram memory code a little

- motor driver for ECB now fully working
- Fixed an anticollider bug
- Untested version of a driver for the Risoe TDC histogram memory
This commit is contained in:
cvs
2003-01-31 16:23:54 +00:00
parent b1fd8e77ac
commit f51588e2a7
26 changed files with 1602 additions and 784 deletions

View File

@@ -68,6 +68,57 @@
self->iLastHMError = 0;
self->iLastCTError = 0;
}
/*------------------------------------------------------------------------*/
static char *pHistMode[] = {
"transparent",
"normal",
"tof",
"strobo",
"hrpt",
"psd",
"sanstof",
NULL
};
static HistMode Text2Mode(char *text)
{
int i = 0;
while(pHistMode[i] != NULL)
{
if(strcmp(pHistMode[i],text) == 0)
{
return i;
}
i++;
}
/* not found */
return -1;
}
/*------------------------------------------------------------------------*/
static char *pFlowMode[] = {
"ignore",
"ceil",
"count",
"reflect",
NULL
};
static OverFlowMode Text2Flow(char *text)
{
int i = 0;
while(pFlowMode[i] != NULL)
{
if(strcmp(pFlowMode[i],text) == 0)
{
return i;
}
i++;
}
/* not found */
return -1;
}
/*--------------------------------------------------------------------------
Configure deconfigures first, in order to have a clean state. Than the HM
is configured and a client connection will be built. Configure requires,
@@ -80,14 +131,14 @@
SinqHMDriv *pInternal;
int status, iMode;
char pError[132];
char pHMComputer[256];
char pHMComputer[256], pValue[80], pBueffel[256];
float fVal;
char pcCounter[256];
CommandList *pCom = NULL;
int iStart = 0;
int iInit = 0, i;
int iInit = 0, i, iRet;
int xOff, xFac, yOff, yFac;
int iPort;
int iPort, iLength;
assert(self);
assert(self->pPriv);
@@ -97,9 +148,70 @@
pInternal = (SinqHMDriv *)self->pPriv;
ErrInit(pInternal);
/* enter histmode */
iRet = StringDictGet(pOpt,"histmode",pValue,79);
if(!iRet)
{
SCWrite(pCon,"ERROR: internal Value not found!",eError);
return 0;
}
strtolower(pValue);
iRet = Text2Mode(pValue);
if(iRet < 0)
{
sprintf(pBueffel,"ERROR: Invalid parameter %s to HistMode",pValue);
SCWrite(pCon,pBueffel,eError);
return 0;
}
pInternal->eHistMode = iRet;
/* handle overflowmode */
iRet = StringDictGet(pOpt,"overflowmode",pValue,79);
if(!iRet)
{
SCWrite(pCon,"ERROR: internal Value not found!",eError);
return 0;
}
strtolower(pValue);
iRet = Text2Flow(pValue);
if(iRet < 0)
{
sprintf(pBueffel,"ERROR: Invalid parameter %s to OverflowMode",pValue);
SCWrite(pCon,pBueffel,eError);
return 0;
}
pInternal->eFlow = iRet;
/* BinWidth */
iRet = StringDictGetAsNumber(pOpt,"binwidth",&fVal);
if(!iRet)
{
iRet = StringDictGet(pOpt,"binwidth",pValue,79);
if(iRet)
{
sprintf(pBueffel,"ERROR: %s not valid for BinWidth ",pValue);
SCWrite(pCon,pBueffel,eError);
return 0;
}
else
{
SCWrite(pCon,"ERROR: internal Value not found!",eError);
return 0;
}
}
if(fVal < 1)
{
sprintf(pBueffel,"ERROR: %f is invalid for BinWidth",fVal);
SCWrite(pCon,pBueffel,eError);
return 0;
}
pInternal->iBinWidth = (int)fVal;
/* check BinWidth */
if( (self->iBinWidth != 1) && (self->iBinWidth != 2)
&& (self->iBinWidth != 4))
if( (pInternal->iBinWidth != 1) && (pInternal->iBinWidth != 2)
&& (pInternal->iBinWidth != 4))
{
PrintHMError("Unsuported BinWidth specified, 1,2,4 are permissable",pCon);
return 0;
@@ -137,7 +249,7 @@
pCom = FindCommand(pSics,pcCounter);
if(!pCom)
{
PrintHMError("WARNING: no EL737 counter for HM found! ",
PrintHMError("WARNING: no counter for HM found! ",
pCon);
pInternal->pCounter = NULL;
}
@@ -147,7 +259,7 @@
if(!pInternal->pCounter->pDes->GetInterface(pInternal->pCounter,
COUNTID))
{
PrintHMError("EL737 counter for histogram memory is invalid",
PrintHMError("Counter for histogram memory is invalid",
pCon);
return 0;
}
@@ -170,8 +282,10 @@
/* in any case let us propagate the state of affairs to
SINQHM
*/
SINQHMSetPar(pInternal->pMaster,self->iRank, self->iLength,
self->iBinWidth);
SINQHMSetPar(pInternal->pMaster,self->data->rank,
getHMDataLength(self->data),
pInternal->iBinWidth);
/* actual configuration. On first call, check for flag INIt in
@@ -205,8 +319,8 @@
return 0;
}
if( (self->iBinWidth != 1) && (self->iBinWidth != 2)
&& (self->iBinWidth != 4))
if( (pInternal->iBinWidth != 1) && (pInternal->iBinWidth != 2)
&& (pInternal->iBinWidth != 4))
{
PrintHMError("Unsuported BinWidth specified, 1,2,4 are permissable",
pCon);
@@ -215,7 +329,7 @@ pCon);
/* configure */
switch(self->eHistMode)
switch(pInternal->eHistMode)
{
case eHTransparent:
iMode = SQHM__TRANS;
@@ -226,22 +340,25 @@ pCon);
case eHTOF:
iMode = SQHM__TOF;
/* recalculate some parameters */
self->iLength = 1;
for(i = 0; i < self->iRank; i++)
iLength = 1;
for(i = 0; i < self->data->rank; i++)
{
self->iLength *= self->iDims[i];
iLength *= self->data->iDim[i];
}
self->iLength *= self->iTimeChan;
SINQHMDefineBank(pInternal->pMaster,0,0,self->iDims[0],
self->fTime,self->iTimeChan);
iLength *= self->data->nTimeChan;
SINQHMDefineBank(pInternal->pMaster,0,0,self->data->iDim[0],
self->data->timeBinning,
self->data->nTimeChan);
break;
case eSANSTOF:
iMode = SQHM__TOF;
self->iLength = self->iDims[0]*self->iDims[1];
self->iLength *= self->iTimeChan;
iLength = self->data->iDim[0]*self->data->iDim[1];
iLength *= self->data->nTimeChan;
SINQHMDefineBank(pInternal->pMaster,0,0,
(self->iDims[0]*self->iDims[1]) + 3,
self->fTime,self->iTimeChan);
(self->data->iDim[0]*self->data->iDim[1])
+ 3,
self->data->timeBinning,
self->data->nTimeChan);
break;
case eHStrobo:
iMode = SQHM__HM_PSD | SQHM__STROBO;
@@ -256,7 +373,7 @@ pCon);
PrintHMError("Unsupported mode requested",pCon);
return 0;
}
switch(self->eFlow)
switch(pInternal->eFlow)
{
case eOIgnore:
iMode = iMode | SQHM__BO_IGN;
@@ -274,13 +391,13 @@ pCon);
PrintHMError("Unsupported overflowmode requested",pCon);
return 0;
}
if(self->eHistMode != ePSD)
if(pInternal->eHistMode != ePSD)
{
status = SINQHMConfigure(pInternal->pMaster,
iMode,
self->iRank,
self->iLength,
self->iBinWidth,
self->data->rank,
getHMDataLength(self->data),
pInternal->iBinWidth,
0,0);
}
else
@@ -320,15 +437,15 @@ pCon);
/* xSize and ySize are supposed to be in dim */
status = SINQHMConfigurePSD(pInternal->pMaster,
iMode,
self->iDims[0],
self->data->iDim[0],
xOff,
xFac,
self->iDims[1],
self->data->iDim[1],
yOff,
yFac,
self->iBinWidth,
self->fTime,
self->iTimeChan);
pInternal->iBinWidth,
self->data->timeBinning,
self->data->nTimeChan);
}
if(status < 0)
@@ -380,15 +497,17 @@ pCon);
}
/* first zero the HM */
if(self->eHistMode == ePSD && self->iTimeChan > 2){
if(pInternal->eHistMode == ePSD && self->data->nTimeChan > 2){
/*
this is special for AMOR and should be replaced by -1, -1, -1
logic ASAP
*/
nHist = (self->iDims[0]*self->iDims[1] + 2) *self->iTimeChan;
nHist = (self->data->iDim[0]*self->data->iDim[1] + 2) *
self->data->nTimeChan;
status = SINQHMZero(pInternal->pMaster,-1,-1,-1);
}else{
status = SINQHMZero(pInternal->pMaster,-1,0,self->iRank*self->iLength);
status = SINQHMZero(pInternal->pMaster,-1,0,
self->data->rank*getHMDataLength(self->data));
}
/*
status = SINQHMZero(pInternal->pMaster,-1,-1,-1);
@@ -745,8 +864,8 @@ pCon);
pInternal = self->pPriv;
/* we do not need to do a lot of copying when datasizes match! */
iByte = (iEnd - iStart) * self->iBinWidth;
if(self->iBinWidth == sizeof(HistInt))
iByte = (iEnd - iStart) * pInternal->iBinWidth;
if(pInternal->iBinWidth == sizeof(HistInt))
{
/* read HM */
status = SINQHMRead(pInternal->pMaster,
@@ -779,7 +898,7 @@ pCon);
}
/* convert to correct datasize */
switch(self->iBinWidth)
switch(pInternal->iBinWidth)
{
case 1:
pPtr = (char *)pData;
@@ -831,7 +950,7 @@ pCon);
pInternal = self->pPriv;
/* allocate storage */
iByte = iEnd * self->iBinWidth;
iByte = iEnd * pInternal->iBinWidth;
pData = (void *)malloc(iByte*sizeof(char));
if(!pData)
{
@@ -841,7 +960,7 @@ pCon);
memset(pData,0,iByte);
/* convert from long to supported binwidth */
switch(self->iBinWidth)
switch(pInternal->iBinWidth)
{
case 1:
pPtr = (char *)pData;
@@ -926,10 +1045,10 @@ pCon);
pInternal = self->pPriv;
/* get memory */
if(self->eHistMode == ePSD && self->iTimeChan > 2){
nHist = self->iDims[0]*self->iDims[1]*self->iTimeChan;
if(pInternal->eHistMode == ePSD && self->data->nTimeChan > 2){
nHist = self->data->iDim[0]*self->data->iDim[1]*self->data->nTimeChan;
} else {
nHist = self->iRank*self->iLength;
nHist = getHMDataLength(self->data);
}
plData = (HistInt *)malloc(nHist*sizeof(HistInt));
if(!plData)
@@ -989,7 +1108,10 @@ pCon);
StringDictAddPair(pOption,"yoff","100");
StringDictAddPair(pOption,"yfac","10");
StringDictAddPair(pOption,"init","1");
StringDictAddPair(pOption,"histmode","normal");
StringDictAddPair(pOption,"overflowmode","ceil");
StringDictAddPair(pOption,"binwidth","4");
/* initialise our private data structure */
pInternal = (SinqHMDriv *)malloc(sizeof(SinqHMDriv));
if(!pInternal)
@@ -999,7 +1121,11 @@ pCon);
}
memset(pInternal,0,sizeof(SinqHMDriv));
pNew->pPriv = pInternal;
pInternal->eHistMode = eHNormal;
pInternal->eFlow = eOCeil;
pInternal->iBinWidth = 4;
/* configure all those functions */
pNew->Configure = SQConfigure;
pNew->Start = SQStart;