Changed HM-configuration at FOCUS
This commit is contained in:
228
fowrite.c
228
fowrite.c
@@ -30,6 +30,7 @@
|
||||
#include "scan.h"
|
||||
#include "sicsvar.h"
|
||||
#include "fitcenter.h"
|
||||
#include "hmcontrol.h"
|
||||
#include "fomerge.h"
|
||||
|
||||
/* histogram memory names */
|
||||
@@ -50,10 +51,12 @@
|
||||
int iInterval;
|
||||
int iEnd;
|
||||
SConnection *pCon;
|
||||
pCounter pCount;
|
||||
char *pFile;
|
||||
char *pDictFile;
|
||||
pFit pFitter;
|
||||
float fElastic;
|
||||
pICallBack pCall;
|
||||
int iUpper, iMiddle, iLower;
|
||||
/* detector availability flags */
|
||||
} FoWrite, *pFoWrite;
|
||||
@@ -92,7 +95,9 @@
|
||||
assert(self);
|
||||
self->tUpdate = time(NULL);
|
||||
self->iEnd = 1;
|
||||
/*
|
||||
FoUpdate(self,self->pCon);
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
@@ -362,7 +367,7 @@
|
||||
if(self->iMiddle)
|
||||
{
|
||||
NXDupdate(pDict,"bank","bank1");
|
||||
iLength = getFMdim(MIDDLE);
|
||||
iLength = 150;
|
||||
sprintf(pBuffer,"%d",iLength);
|
||||
NXDupdate(pDict,"noofdetectors",pBuffer);
|
||||
fArray = getFMBankTheta(MIDDLE);
|
||||
@@ -371,7 +376,7 @@
|
||||
if(self->iLower)
|
||||
{
|
||||
NXDupdate(pDict,"bank","lowerbank");
|
||||
iLength = getFMdim(LOWER);
|
||||
iLength = 115;
|
||||
sprintf(pBuffer,"%d",iLength);
|
||||
NXDupdate(pDict,"noofdetectors",pBuffer);
|
||||
fArray = getFMBankTheta(LOWER);
|
||||
@@ -380,7 +385,7 @@
|
||||
if(self->iUpper)
|
||||
{
|
||||
NXDupdate(pDict,"bank","upperbank");
|
||||
iLength = getFMdim(UPPER);
|
||||
iLength = 110;
|
||||
sprintf(pBuffer,"%d",iLength);
|
||||
NXDupdate(pDict,"noofdetectors",pBuffer);
|
||||
fArray = getFMBankTheta(UPPER);
|
||||
@@ -389,7 +394,7 @@
|
||||
if(self->iMiddle && ( self->iLower || self->iUpper) )
|
||||
{
|
||||
NXDupdate(pDict,"bank","merged");
|
||||
iLength = getFMdim(MERGED);
|
||||
iLength = 375;
|
||||
sprintf(pBuffer,"%d",iLength);
|
||||
NXDupdate(pDict,"noofdetectors",pBuffer);
|
||||
fArray = getFMBankTheta(MERGED);
|
||||
@@ -415,7 +420,7 @@
|
||||
static void FoUpdate(pFoWrite self, SConnection *pCon)
|
||||
{
|
||||
char pBueffel[512];
|
||||
int iInt, iStat, iTime, i, j, iDet, iIndex;
|
||||
int iInt, iStat, iTime, i,ii, j, iDet, iIndex;
|
||||
pSicsVariable var1 = NULL;
|
||||
pSicsVariable var2 = NULL;
|
||||
pSicsVariable var3 = NULL;
|
||||
@@ -492,7 +497,7 @@
|
||||
var1 = FindVariable(pServ->pSics,"lbank");
|
||||
if(var1)
|
||||
{
|
||||
VarGetInt(var2,&lbank);
|
||||
VarGetInt(var1,&lbank);
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: lbank value not found!",eError);
|
||||
}
|
||||
@@ -526,7 +531,13 @@
|
||||
iTime = iInt;
|
||||
sprintf(pBueffel,"%d",iInt);
|
||||
NXDupdate(pDict,"timebin",pBueffel);
|
||||
|
||||
var1 = FindVariable(pServ->pSics,"lbank");
|
||||
if(var1)
|
||||
{
|
||||
VarGetInt(var1,&lbank);
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: lbank value not found!",eError);
|
||||
}
|
||||
if (var1)
|
||||
{
|
||||
lData = GetHistogramPointer(self->pHistogram1,pCon);
|
||||
@@ -550,7 +561,7 @@
|
||||
}
|
||||
}
|
||||
var3 = FindVariable(pServ->pSics,"ubank");
|
||||
if(var1)
|
||||
if(var3)
|
||||
{
|
||||
VarGetInt(var3,&ubank);
|
||||
} else {
|
||||
@@ -567,39 +578,9 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
setFMDataPointer(lData,iTime);
|
||||
setFMDataPointer(mData,iTime);
|
||||
setFMDataPointer(uData,iTime);
|
||||
if(self->iUpper)
|
||||
{
|
||||
NXDupdate(pDict,"bank","upperbank");
|
||||
iDet = 117;
|
||||
sprintf(pBueffel,"%d",iDet);
|
||||
NXDupdate(pDict,"noofdetectors",pBueffel);
|
||||
uData = getFMBankPointer(UPPER);
|
||||
NXDputalias(pFile,pDict,"dcounts",uData);
|
||||
/* summed counts for each detector */
|
||||
iSum = (int *)malloc(iDet*sizeof(int));
|
||||
if(iSum)
|
||||
{
|
||||
memset(iSum,0,iDet*sizeof(int));
|
||||
for(i = 0; i < iDet; i++)
|
||||
{
|
||||
iIndex = i * iTime;
|
||||
for(j = 0; j < iTime; j++)
|
||||
{
|
||||
iSum[i] += uData[iIndex+j];
|
||||
}
|
||||
}
|
||||
NXDputalias(pFile,pDict,"dsums",iSum);
|
||||
free(iSum);
|
||||
}
|
||||
else
|
||||
{
|
||||
SCWrite(pCon,"WARNING: out of memory, failed to do sums",
|
||||
eWarning);
|
||||
}
|
||||
}
|
||||
setFMDataPointer(lData,iTime,3);
|
||||
setFMDataPointer(mData,iTime,1);
|
||||
setFMDataPointer(uData,iTime,2);
|
||||
/* middle bank */
|
||||
if(self->iMiddle)
|
||||
{
|
||||
@@ -631,10 +612,40 @@
|
||||
eWarning);
|
||||
}
|
||||
}
|
||||
if(self->iUpper)
|
||||
{
|
||||
NXDupdate(pDict,"bank","upperbank");
|
||||
iDet = 110;
|
||||
sprintf(pBueffel,"%d",iDet);
|
||||
NXDupdate(pDict,"noofdetectors",pBueffel);
|
||||
uData = getFMBankPointer(UPPER);
|
||||
NXDputalias(pFile,pDict,"dcounts",uData);
|
||||
/* summed counts for each detector */
|
||||
iSum = (int *)malloc(iDet*sizeof(int));
|
||||
if(iSum)
|
||||
{
|
||||
memset(iSum,0,iDet*sizeof(int));
|
||||
for(i = 0; i < iDet; i++)
|
||||
{
|
||||
iIndex = i * iTime;
|
||||
for(j = 0; j < iTime; j++)
|
||||
{
|
||||
iSum[i] += uData[iIndex+j];
|
||||
}
|
||||
}
|
||||
NXDputalias(pFile,pDict,"dsums",iSum);
|
||||
free(iSum);
|
||||
}
|
||||
else
|
||||
{
|
||||
SCWrite(pCon,"WARNING: out of memory, failed to do sums",
|
||||
eWarning);
|
||||
}
|
||||
}
|
||||
if(self->iLower)
|
||||
{
|
||||
NXDupdate(pDict,"bank","lowerbank");
|
||||
iDet = 116;
|
||||
iDet = 115;
|
||||
sprintf(pBueffel,"%d",iDet);
|
||||
NXDupdate(pDict,"noofdetectors",pBueffel);
|
||||
lData = getFMBankPointer(LOWER);
|
||||
@@ -659,13 +670,30 @@
|
||||
{
|
||||
SCWrite(pCon,"WARNING: out of memory, failed to do sums",
|
||||
eWarning);
|
||||
}
|
||||
}
|
||||
/*
|
||||
now get and write tof_monitor
|
||||
*/
|
||||
|
||||
lData = (HistInt *)malloc(iTime*sizeof(HistInt));
|
||||
if(!lData)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory while writing tof-monitor",
|
||||
eError);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(lData,0,iTime*sizeof(HistInt));
|
||||
GetHistogramDirect(self->pHistogram1,pCon,0,115*iTime,
|
||||
116*iTime, lData, iTime*sizeof(HistInt));
|
||||
NXDputalias(pFile,pDict,"tofmon",lData);
|
||||
}
|
||||
}
|
||||
/* merged data */
|
||||
if( (self->iUpper || self->iLower) && self->iMiddle)
|
||||
{
|
||||
NXDupdate(pDict,"bank","merged");
|
||||
iDet = getFMdim(MERGED);
|
||||
iDet = 375;
|
||||
sprintf(pBueffel,"%d",iDet);
|
||||
NXDupdate(pDict,"noofdetectors",pBueffel);
|
||||
lData = getFMBankPointer(MERGED);
|
||||
@@ -696,8 +724,8 @@
|
||||
|
||||
/* calculate elastic peak position */
|
||||
NXDupdate(pDict,"bank","bank1");
|
||||
lData = getFMBankPointer(MIDDLE);
|
||||
if(lData)
|
||||
mData = getFMBankPointer(MIDDLE);
|
||||
if(mData)
|
||||
{
|
||||
lSum = (long *)malloc(iTime *sizeof(long));
|
||||
fAxis = (float *)malloc(iTime *sizeof(float));
|
||||
@@ -710,7 +738,7 @@
|
||||
iIndex = i * iTime;
|
||||
for(j = 0; j < iTime; j++)
|
||||
{
|
||||
lSum[j] += lData[iIndex+j];
|
||||
lSum[j] += mData[iIndex+j];
|
||||
}
|
||||
}
|
||||
for(i = 0; i < iTime; i++)
|
||||
@@ -858,6 +886,7 @@
|
||||
self->tUpdate = 0;
|
||||
iWrite = 0;
|
||||
iRet = 0;
|
||||
FoUpdate(self,self->pCon);
|
||||
}
|
||||
|
||||
if(iWrite)
|
||||
@@ -910,7 +939,8 @@
|
||||
pFoWrite pNew = NULL;
|
||||
pICallBack pCall = NULL;
|
||||
pDummy pDum;
|
||||
|
||||
pHMcontrol pHMC = NULL;
|
||||
|
||||
/* check arguments */
|
||||
if(argc < 4 )
|
||||
{
|
||||
@@ -918,22 +948,52 @@
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
/* find things in interpreter */
|
||||
pCom = FindCommand(pSics,HM1);
|
||||
if(pCom)
|
||||
|
||||
/* allocate data structure */
|
||||
pNew = (pFoWrite)malloc(sizeof(FoWrite));
|
||||
if(!pNew)
|
||||
{
|
||||
pNew->pHistogram1 = (pHistMem)pCom->pData;
|
||||
SCWrite(pCon,"ERROR: out of memory in FoInstall",eError);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
memset(pNew,0,sizeof(FoWrite));
|
||||
pNew->pDes = CreateDescriptor("FocusWrite");
|
||||
pNew->pCall = CreateCallBackInterface();
|
||||
pNew->pFitter = CreateFitCenter(NULL);
|
||||
if( (!pNew->pDes) || (!pNew->pFitter) )
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory in FoInstall",eError);
|
||||
free(pNew);
|
||||
return 0;
|
||||
}
|
||||
pNew->pDictFile = strdup(argv[2]);
|
||||
pNew->iInterval = 20*60;
|
||||
|
||||
pHMC = FindCommandData(pSics,argv[1],"HMcontrol");
|
||||
if(!pHMC){
|
||||
SCWrite(pCon,"ERROR: no histogram memory control found!",eError);
|
||||
free(pNew);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* find things in interpreter */
|
||||
pCom = FindCommand(pSics,"hm1");
|
||||
if(!pCom)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: Histogram memory for lower detector bank NOT found",eError);
|
||||
pNew->pHistogram1 = NULL;
|
||||
}
|
||||
} else
|
||||
{
|
||||
pNew->pHistogram1 = (pHistMem)pCom->pData;
|
||||
pNew->iLower =1;
|
||||
}
|
||||
|
||||
|
||||
pCom = FindCommand(pSics,HM2);
|
||||
if(pCom)
|
||||
{
|
||||
pNew->pHistogram2 = (pHistMem)pCom->pData;
|
||||
pNew->iMiddle =1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -944,73 +1004,29 @@
|
||||
pCom = FindCommand(pSics,HM3);
|
||||
if(pCom)
|
||||
{
|
||||
pNew->pHistogram3 = (pHistMem)pCom->pData;
|
||||
pNew->pHistogram3 = (pHistMem)pCom->pData;
|
||||
pNew->iUpper =1;
|
||||
}
|
||||
else
|
||||
{
|
||||
SCWrite(pCon,"ERROR: Histogram memory for upper detector bank NOT found",eError);
|
||||
pNew->pHistogram3 = NULL;
|
||||
}
|
||||
if(!initializeFM(argv[2]))
|
||||
|
||||
if(!initializeFM(argv[3]))
|
||||
{
|
||||
SCWrite(pCon,"ERROR: bad merge data file",eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* allocate data structure */
|
||||
pNew = (pFoWrite)malloc(sizeof(FoWrite));
|
||||
if(!pNew)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory in FoInstall",eError);
|
||||
return 0;
|
||||
}
|
||||
memset(pNew,0,sizeof(FoWrite));
|
||||
pNew->pDes = CreateDescriptor("FocusWrite");
|
||||
pNew->pFitter = CreateFitCenter(NULL);
|
||||
if( (!pNew->pDes) || (!pNew->pFitter) )
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory in FoInstall",eError);
|
||||
free(pNew);
|
||||
return 0;
|
||||
}
|
||||
pNew->pDictFile = strdup(argv[1]);
|
||||
pNew->iInterval = 20*60;
|
||||
pNew->iMiddle =1;
|
||||
|
||||
/* install callbacks */
|
||||
pCom = FindCommand(pSics,HM2);
|
||||
pCom = FindCommand(pSics,"counter");
|
||||
if(pCom)
|
||||
{
|
||||
pDum = (pDummy)pNew->pHistogram2;
|
||||
pCall = (pICallBack)pDum->pDescriptor->GetInterface(pNew->pHistogram2,
|
||||
CALLBACKINTERFACE);
|
||||
}
|
||||
else
|
||||
{
|
||||
pCom = FindCommand(pSics,HM1);
|
||||
if(pCom)
|
||||
{
|
||||
pDum = (pDummy)pNew->pHistogram1;
|
||||
pCall = (pICallBack)pDum->pDescriptor->GetInterface(pNew->pHistogram1,
|
||||
CALLBACKINTERFACE);
|
||||
}
|
||||
else
|
||||
{
|
||||
pDum = (pDummy)pNew->pHistogram3;
|
||||
pCall = (pICallBack)pDum->pDescriptor->GetInterface(pNew->pHistogram3, CALLBACKINTERFACE);
|
||||
}
|
||||
pNew->pCount = (pCounter)pCom->pData;
|
||||
}
|
||||
|
||||
if(!pCall)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"ERROR: no callback interface found at your histogram memories",
|
||||
eError);
|
||||
KillFoWrite(pNew);
|
||||
return 0;
|
||||
}
|
||||
RegisterCallback(pCall,COUNTSTART,Countstartcallback,pNew,NULL);
|
||||
RegisterCallback(pCall,COUNTEND,Countendcallback,pNew,NULL);
|
||||
RegisterCallback(pHMC->pCall,COUNTSTART,Countstartcallback,pNew,NULL);
|
||||
RegisterCallback(pHMC->pCall,COUNTEND,Countendcallback,pNew,NULL);
|
||||
|
||||
/* install command */
|
||||
AddCommand(pSics,"StoreFocus",FoAction,KillFoWrite,pNew);
|
||||
|
||||
Reference in New Issue
Block a user