- Fixed a bug fix with Fixed motor in TAS code
- Made AMOR write HDF-5 data in chunks - Added driver for a PSI-DSP magnet controller as used at SLS - Added code for directly accessing RS232 controllers connected to a terminal server, thereby bypassing the SerPortServer - A rounding problem in the PSD histogram memory was resolved.
This commit is contained in:
177
nxamor.c
177
nxamor.c
@@ -10,6 +10,7 @@
|
||||
Mark Koennecke, September 1999
|
||||
Updated, Mark Koennecke, August 2001
|
||||
--------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "fortify.h"
|
||||
@@ -35,6 +36,13 @@
|
||||
#define SOURCETYPE "Continous flux spallation source"
|
||||
#define CHOPPERNAME "Dornier Chopper System"
|
||||
|
||||
/*
|
||||
The rough size of each detector chunk to write in TOF mode
|
||||
(currently 16MB)
|
||||
#define TOFBLOCK 8192000
|
||||
*/
|
||||
#define TOFBLOCK 16384000
|
||||
|
||||
/*
|
||||
a pointer to amor2t which we need for a couple of parameters
|
||||
*/
|
||||
@@ -68,7 +76,7 @@ pAmor2T pAmor = NULL;
|
||||
float fVal;
|
||||
|
||||
/* open files */
|
||||
iRet = NXopen(file,NXACC_CREATE,&hfil);
|
||||
iRet = NXopen(file,NXACC_CREATE5,&hfil);
|
||||
if(iRet != NX_OK)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: cannot open file %s for writing",file);
|
||||
@@ -326,6 +334,135 @@ pAmor2T pAmor = NULL;
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------
|
||||
WriteTOFDetector writes the histogram memory data in TOF mode. As
|
||||
the histogram memory can become quite large at AMOR, the data is
|
||||
read and stored in chunks if it is to big. All this is handled
|
||||
in this routine.
|
||||
-------------------------------------------------------------------------*/
|
||||
static int WriteTOFDetector(char *name, pHistMem pHM, int *iDim,
|
||||
NXhandle hfil, NXdict hdict,
|
||||
SConnection *pCon)
|
||||
{
|
||||
int iLength, nChunk, chunkSize, iChunk[3], i, iStart[3];
|
||||
HistInt *lData = NULL;
|
||||
char pBueffel[132];
|
||||
|
||||
iLength = iDim[0]*iDim[1]*iDim[2];
|
||||
if( (iLength*4) < TOFBLOCK)
|
||||
{
|
||||
sprintf(pBueffel," -chunk {%d,%d,%d} ",iDim[0], iDim[1], iDim[2]);
|
||||
NXDupdate(hdict,"chunk",pBueffel);
|
||||
lData = (HistInt *)malloc(iLength*sizeof(HistInt));
|
||||
if(!lData)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"ERROR: out of memory, failed to write histogram",eError);
|
||||
return 0;
|
||||
}
|
||||
memset(lData,0,iLength*sizeof(HistInt));
|
||||
GetHistogramDirect(pHM,pCon,
|
||||
0,0,iLength,lData,iLength*sizeof(HistInt));
|
||||
NXDputalias(hfil,hdict,name,lData);
|
||||
NXDputalias(hfil,hdict,"detchunk",iDim);
|
||||
NXDaliaslink(hfil,hdict,"dana",name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
implement chunked writing. We strive to write layers in Y. The
|
||||
number of chunks needs to fulfill three conditions then:
|
||||
- multiple of xSize* timeBin;
|
||||
- close to TOFBLOCK in size
|
||||
- divide Y without remainder.
|
||||
*/
|
||||
iChunk[0] = iDim[0];
|
||||
iChunk[2] = iDim[2];
|
||||
iChunk[1] = 1;
|
||||
chunkSize = iDim[0]*iDim[2];
|
||||
for(i = 1; i < 64; i++)
|
||||
{
|
||||
if( (iDim[1] % i) == 0)
|
||||
{
|
||||
if(i*chunkSize*sizeof(HistInt) > TOFBLOCK)
|
||||
{
|
||||
iChunk[1] = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
sprintf(pBueffel,"Segmented TOF data in %d chunks",iDim[1]/iChunk[1]);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
/*
|
||||
now we have a chunkSize, lets go and write!
|
||||
*/
|
||||
NXDputalias(hfil,hdict,"detchunk",iChunk);
|
||||
chunkSize = iChunk[1]*iChunk[0]*iChunk[2];
|
||||
sprintf(pBueffel," -chunk {%d,%d,%d} ",iChunk[0], iChunk[1], iChunk[2]);
|
||||
NXDupdate(hdict,"chunk",pBueffel);
|
||||
lData = (HistInt *)malloc(chunkSize*sizeof(HistInt));
|
||||
if(!lData)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory while writing TOF data",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
NXDopenalias(hfil,hdict,name);
|
||||
for(i = 0; i < iDim[1]/iChunk[1]; i++)
|
||||
{
|
||||
memset(lData,0,chunkSize*sizeof(HistInt));
|
||||
GetHistogramDirect(pHM,pCon,
|
||||
0,i*chunkSize,chunkSize,lData,chunkSize*sizeof(HistInt));
|
||||
/*
|
||||
yield a little in order to allow other clients to receive a
|
||||
response. Also allow for interrupting.
|
||||
*/
|
||||
SicsWait(2);
|
||||
if(SCGetInterrupt(pCon) != eContinue)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"ERROR: dataset writing interrupted, data probably corrupted",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
iStart[0] = 0;
|
||||
iStart[1] = i*iChunk[1];
|
||||
iStart[2] = 0;
|
||||
NXputslab(hfil,lData,iStart, iChunk);
|
||||
sprintf(pBueffel,"Wrote chunk %d", i);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
/*
|
||||
yield a little in order to allow other clients to receive a
|
||||
response. Also allow for interrupting.
|
||||
*/
|
||||
SicsWait(2);
|
||||
if(SCGetInterrupt(pCon) != eContinue)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"ERROR: dataset writing interrupted, data probably corrupted",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
close groups till root
|
||||
*/
|
||||
NXclosedata(hfil);
|
||||
NXclosegroup(hfil);
|
||||
NXclosegroup(hfil);
|
||||
NXclosegroup(hfil);
|
||||
|
||||
/*
|
||||
make link
|
||||
*/
|
||||
NXDaliaslink(hfil,hdict,"dana",name);
|
||||
NXDaliaslink(hfil,hdict,"dana","detchunk");
|
||||
|
||||
}
|
||||
if(lData)
|
||||
free(lData);
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int WriteAmorTOF(char *file, SConnection *pCon, pHistMem pHM)
|
||||
{
|
||||
@@ -473,33 +610,33 @@ pAmor2T pAmor = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
iLength = iDim[0]*iDim[1]*iDim[2];
|
||||
lData = (HistInt *)malloc(iLength*sizeof(HistInt));
|
||||
if(!lData)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"ERROR: out of memory, failed to write histogram",eError);
|
||||
return 0;
|
||||
}
|
||||
memset(lData,0,iLength*sizeof(HistInt));
|
||||
GetHistogramDirect(pHM,pCon,
|
||||
0,0,iLength,lData,iLength*sizeof(HistInt));
|
||||
NXDputalias(hfil,hdict,"spinup",lData);
|
||||
NXDaliaslink(hfil,hdict,"dana","spinup");
|
||||
WriteTOFDetector("spinup",pHM, iDim,hfil,hdict,pCon);
|
||||
|
||||
/*
|
||||
now get and write single detectors
|
||||
*/
|
||||
GetHistogramDirect(pHM,pCon,0,iLength,2*iDim[2],
|
||||
lData, iLength*sizeof(HistInt));
|
||||
NXDputalias(hfil,hdict,"singleup",lData);
|
||||
NXDaliaslink(hfil,hdict,"singledana","singleup");
|
||||
NXDaliaslink(hfil,hdict,"singledana","singletime");
|
||||
iLength = iDim[0]*iDim[1]*iDim[2];
|
||||
lData = (HistInt *)malloc(2*iDim[2]*sizeof(HistInt));
|
||||
if(!lData)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory while writing single detectors",
|
||||
eError);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(lData,0,2*iDim[2]*sizeof(HistInt));
|
||||
GetHistogramDirect(pHM,pCon,0,iLength,2*iDim[2],
|
||||
lData, 2*iDim[2]*sizeof(HistInt));
|
||||
NXDputalias(hfil,hdict,"singleup",lData);
|
||||
NXDaliaslink(hfil,hdict,"singledana","singleup");
|
||||
NXDaliaslink(hfil,hdict,"singledana","singletime");
|
||||
}
|
||||
}
|
||||
|
||||
/* to do: add polarizing code */
|
||||
|
||||
free(lData);
|
||||
if(lData)
|
||||
free(lData);
|
||||
|
||||
NXclose(&hfil);
|
||||
NXDclose(hdict,NULL);
|
||||
|
||||
Reference in New Issue
Block a user