- Recovered POLDI from the land of lost files
This commit is contained in:
295
polterwrite.c
295
polterwrite.c
@@ -81,91 +81,21 @@ typedef struct {
|
||||
self->tUpdate = time(NULL);
|
||||
self->iEnd = 1;
|
||||
PoldiUpdate(self,self->pCon);
|
||||
/*
|
||||
Fortify_CheckAllMemory();
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void KillPolterdi(void *pData){
|
||||
pPolterdi self = (pPolterdi)pData;
|
||||
if(!self)
|
||||
return;
|
||||
|
||||
if(self->pDes){
|
||||
DeleteDescriptor(self->pDes);
|
||||
}
|
||||
if(self->pFile){
|
||||
free(self->pFile);
|
||||
}
|
||||
if(self->dictfile){
|
||||
free(self->dictfile);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int PolterInstall(SConnection *pCon, SicsInterp *pSics,
|
||||
void *pData, int argc, char *argv[])
|
||||
{
|
||||
pPolterdi pNew = NULL;
|
||||
pICallBack pCall = NULL;
|
||||
pDummy pDum;
|
||||
pHistMem pHist = NULL;
|
||||
|
||||
/* configure fortify */
|
||||
/*
|
||||
iFortifyScope = Fortify_EnterScope();
|
||||
Fortify_CheckAllMemory();
|
||||
*/
|
||||
if(argc < 2){
|
||||
SCWrite(pCon,"ERROR: insufficient number of arguments to PolterInstall",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
pHist = (pHistMem)FindCommandData(pSics,HM,"HistMem");
|
||||
|
||||
if (!pHist)
|
||||
static void SNError(void *pData, char *text)
|
||||
{
|
||||
|
||||
}
|
||||
SConnection *pCon;
|
||||
|
||||
assert(pData);
|
||||
pCon = (SConnection *)pData;
|
||||
SCWrite(pCon,text,eError);
|
||||
}
|
||||
|
||||
pNew = (pPolterdi)malloc(sizeof(Polterdi));
|
||||
if(!pNew){
|
||||
SCWrite(pCon,"ERROR: out of memory in PolterInstall",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
memset(pNew,0,sizeof(Polterdi));
|
||||
pNew->pDes = CreateDescriptor("PolterdiWrite");
|
||||
pNew->pHist = pHist;
|
||||
pNew->dictfile = strdup(argv[1]);
|
||||
pNew->iInterval = 20*60;
|
||||
if(!pNew->pDes || !pNew->dictfile){
|
||||
SCWrite(pCon,"ERROR: out of memory in PolterInstall",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
/* install callbacks */
|
||||
pDum = (pDummy)pHist;
|
||||
pCall = (pICallBack)pDum->pDescriptor->GetInterface(pHist,CALLBACKINTERFACE);
|
||||
if(!pCall)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"ERROR: no callback interface found at your histogram memory",
|
||||
eError);
|
||||
KillPolterdi(pNew);
|
||||
return 0;
|
||||
}
|
||||
RegisterCallback(pCall,COUNTSTART,Countstartcallback,pNew,NULL);
|
||||
RegisterCallback(pCall,COUNTEND,Countendcallback,pNew,NULL);
|
||||
|
||||
AddCommand(pSics,"storedata",PolterAction,KillPolterdi,pNew);
|
||||
return 1;
|
||||
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
static void writePolterdiGlobal(NXhandle hfil, NXdict hdict,
|
||||
SConnection *pCon){
|
||||
@@ -194,10 +124,10 @@ static void writeDiaphragm1(NXhandle hfil, NXdict hdict,
|
||||
SConnection *pCon){
|
||||
float dist;
|
||||
|
||||
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"dia1x","d1m");
|
||||
SNXSPutMotorNull(pServ->pSics,pCon,hfil,hdict,"dia1x0","d1m");
|
||||
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"dia1y","d1o");
|
||||
SNXSPutMotorNull(pServ->pSics,pCon,hfil,hdict,"dia1y0","d1o");
|
||||
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"dia1x","d1hl");
|
||||
SNXSPutMotorNull(pServ->pSics,pCon,hfil,hdict,"dia1x0","d1hl");
|
||||
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"dia1y","d1hr");
|
||||
SNXSPutMotorNull(pServ->pSics,pCon,hfil,hdict,"dia1y0","d1hr");
|
||||
dist = (float)DIA1DIST;
|
||||
NXDputalias(hfil,hdict,"dia1dist",&dist);
|
||||
}
|
||||
@@ -207,14 +137,14 @@ static void writeDiaphragm1(NXhandle hfil, NXdict hdict,
|
||||
static void writeDiaphragm2(NXhandle hfil, NXdict hdict,
|
||||
SConnection *pCon){
|
||||
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2x_plus", "d2m");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2xplus0", "d2m");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2x_minus", "d2u");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2xminus0", "d2u");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2z_plus", "d2o");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2zplus0", "d2o");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2z_minus", "d2l");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2zminus0", "d2l");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2x_plus", "d2hl");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2xplus0", "d2hl");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2x_minus", "d2hr");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2xminus0", "d2hr");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2z_plus", "d2vu");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2zplus0", "d2vu");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2z_minus", "d2vl");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2zminus0", "d2vl");
|
||||
|
||||
SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"dia2dist","dia1_dia2");
|
||||
}
|
||||
@@ -227,14 +157,15 @@ static void writeSample(NXhandle hfil, NXdict hdict,
|
||||
SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"chopperdist","chopper_sample");
|
||||
SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"saname","sample");
|
||||
SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"senvir","environment");
|
||||
/*
|
||||
SNXSPutEVVar(hfil,hdict,"temperature",pCon,"stemp","stddev");
|
||||
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "srsu", "rsu");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "srsu0", "rsu");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "srsl", "rsl");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "srsl0", "rsl");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "srsa", "rsa");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "srsa0", "rsa");
|
||||
*/
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "sshu", "shu");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "sshu0", "shu");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "sshl", "shl");
|
||||
@@ -245,6 +176,8 @@ static void writeSample(NXhandle hfil, NXdict hdict,
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "ssgl0", "sgl");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "ssv", "sv");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "ssv0", "sv");
|
||||
SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "ssa", "sa");
|
||||
SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "ssa0", "sa");
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
@@ -261,7 +194,7 @@ static int PoldiStart(pPolterdi self, SConnection *pCon)
|
||||
pSicsVariable pVar = NULL;
|
||||
float det_radius, det_size, x0det, y0det, twothet;
|
||||
float pi, alpha1, alphasamp, sms, phidetav, phim;
|
||||
float phi2det, val1, val2, nodet;
|
||||
float phi2det, val1, val2, nodet,scancheck;
|
||||
int iLength, i, nzell;
|
||||
pMotor sa;
|
||||
HistInt *lData = NULL;
|
||||
@@ -275,7 +208,6 @@ static int PoldiStart(pPolterdi self, SConnection *pCon)
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* create a Nexus file */
|
||||
NXopen(self->pFile,NXACC_CREATE,&hfil);
|
||||
if(!hfil)
|
||||
@@ -283,10 +215,21 @@ static int PoldiStart(pPolterdi self, SConnection *pCon)
|
||||
SCWrite(pCon,"ERROR: cannot create data file ",eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* tell Uwe User what we are doing */
|
||||
sprintf(pBueffel,"Writing %s ......",self->pFile);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
pVar = NULL;
|
||||
pVar = FindVariable(pServ->pSics,"scancheck");
|
||||
if(pVar)
|
||||
{
|
||||
VarGetFloat(pVar, &scancheck);
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: Command not found!",eError);
|
||||
return;
|
||||
}
|
||||
if (scancheck == 0) {
|
||||
sprintf(pBueffel,"Writing %s ......",self->pFile);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
}
|
||||
|
||||
|
||||
/* write globals */
|
||||
SNXSPutGlobals(hfil,self->pFile,"POLDI",pCon);
|
||||
@@ -326,7 +269,7 @@ static int PoldiStart(pPolterdi self, SConnection *pCon)
|
||||
{
|
||||
for(i = 0;i < iLength; i++)
|
||||
{
|
||||
fTime2[i] = fTime[i]/10.;
|
||||
fTime2[i] = fTime[i]/2.;
|
||||
}
|
||||
sprintf(pBueffel,"%d",iLength);
|
||||
NXDupdate(hdict,"timebin",pBueffel);
|
||||
@@ -482,16 +425,17 @@ static int PoldiStart(pPolterdi self, SConnection *pCon)
|
||||
pSicsVariable pVar = NULL;
|
||||
float det_radius, det_size, x0det, y0det, twothet;
|
||||
float pi, alpha1, alphasamp, sms, phidetav, phim;
|
||||
float phi2det, val1, val2, nodet;
|
||||
float phi2det, val1, val2, nodet, scancheck;
|
||||
int iLength, i, nzell;
|
||||
pMotor sa;
|
||||
HistInt *lData = NULL;
|
||||
long lVal;
|
||||
time_t zeit;
|
||||
|
||||
/* open everything again */
|
||||
status = NXopen(self->pFile,NXACC_RDWR,&hfil);
|
||||
if(status != NX_OK)
|
||||
{
|
||||
{
|
||||
SCWrite(pCon,"ERROR: cannot reopen data file ",eError);
|
||||
return;
|
||||
}
|
||||
@@ -509,30 +453,38 @@ static int PoldiStart(pPolterdi self, SConnection *pCon)
|
||||
}
|
||||
|
||||
/* tell the user that something is happening */
|
||||
sprintf(pBueffel,"Updating %s",self->pFile);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
|
||||
pVar = NULL;
|
||||
pVar = FindVariable(pServ->pSics,"scancheck");
|
||||
if(pVar)
|
||||
{
|
||||
VarGetFloat(pVar, &scancheck);
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: Command not found!",eError);
|
||||
return;
|
||||
}
|
||||
if (scancheck == 0) {
|
||||
time(&zeit);
|
||||
sprintf(pBueffel,"Updating %s on %s ",self->pFile,asctime(localtime(&zeit)));
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
}
|
||||
/*
|
||||
write time binning
|
||||
*/
|
||||
|
||||
fTime = GetHistTimeBin(self->pHist,&iLength);
|
||||
fTime2 = (float *)malloc(iLength*sizeof(float));
|
||||
if(fTime2)
|
||||
{
|
||||
for(i = 0;i < iLength; i++)
|
||||
fTime = GetHistTimeBin(self->pHist,&iLength);
|
||||
fTime2 = (float *)malloc(iLength*sizeof(float));
|
||||
if(fTime2)
|
||||
{
|
||||
fTime2[i] = fTime[i]/10.;
|
||||
for(i = 0;i < iLength; i++) {
|
||||
fTime2[i] = fTime[i]/2.;
|
||||
}
|
||||
sprintf(pBueffel,"%d",iLength);
|
||||
NXDupdate(hdict,"timebin",pBueffel);
|
||||
NXDputalias(hfil,hdict,"dtime",fTime2);
|
||||
free(fTime2);
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: out of memory while writing time binning",eError);
|
||||
}
|
||||
sprintf(pBueffel,"%d",iLength);
|
||||
NXDupdate(hdict,"timebin",pBueffel);
|
||||
NXDputalias(hfil,hdict,"dtime",fTime2);
|
||||
free(fTime2);
|
||||
}
|
||||
else
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory while writing time binning",eError);
|
||||
}
|
||||
|
||||
/*
|
||||
write Histogram
|
||||
@@ -624,7 +576,7 @@ static int PoldiStart(pPolterdi self, SConnection *pCon)
|
||||
static int PoldiTask(void *pData)
|
||||
{
|
||||
pPolterdi self = NULL;
|
||||
int iWrite, iRet;
|
||||
int iWrite, iRet, ltask;
|
||||
|
||||
self = (pPolterdi)pData;
|
||||
if(!self)
|
||||
@@ -636,15 +588,20 @@ static int PoldiStart(pPolterdi self, SConnection *pCon)
|
||||
/* first case: update intervall */
|
||||
if(time(NULL) >= self->tUpdate)
|
||||
{
|
||||
self->tUpdate = time(NULL) + self->iInterval;
|
||||
iWrite = 1;
|
||||
iRet = 1;
|
||||
ltask = GetDevexecID(pServ->pExecutor);
|
||||
if (ltask > 0)
|
||||
{
|
||||
self->tUpdate = time(NULL) + self->iInterval;
|
||||
iWrite = 1;
|
||||
iRet = 1;
|
||||
} else {
|
||||
self->iEnd = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(self->iEnd)
|
||||
if(self->iEnd == 1)
|
||||
{
|
||||
self->tUpdate = 0;
|
||||
SCWrite(self->pCon,"Writing finished!",eError);
|
||||
iWrite = 0;
|
||||
iRet = 0;
|
||||
}
|
||||
@@ -659,12 +616,95 @@ static int PoldiStart(pPolterdi self, SConnection *pCon)
|
||||
}
|
||||
else
|
||||
{
|
||||
PoldiUpdate(self,self->pCon);
|
||||
PoldiLink(self,self->pCon);
|
||||
PoldiUpdate(self,self->pCon);
|
||||
}
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void KillPolterdi(void *pData){
|
||||
pPolterdi self = (pPolterdi)pData;
|
||||
if(!self)
|
||||
return;
|
||||
|
||||
if(self->pDes){
|
||||
DeleteDescriptor(self->pDes);
|
||||
}
|
||||
if(self->pFile){
|
||||
free(self->pFile);
|
||||
}
|
||||
if(self->dictfile){
|
||||
free(self->dictfile);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int PolterInstall(SConnection *pCon, SicsInterp *pSics,
|
||||
void *pData, int argc, char *argv[])
|
||||
{
|
||||
pPolterdi pNew = NULL;
|
||||
pICallBack pCall = NULL;
|
||||
pDummy pDum;
|
||||
pHistMem pHist = NULL;
|
||||
|
||||
/* configure fortify */
|
||||
/*
|
||||
iFortifyScope = Fortify_EnterScope();
|
||||
Fortify_CheckAllMemory();
|
||||
*/
|
||||
if(argc < 2){
|
||||
SCWrite(pCon,"ERROR: insufficient number of arguments to PolterInstall",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
pHist = (pHistMem)FindCommandData(pSics,HM,"HistMem");
|
||||
|
||||
if (!pHist)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: Histogram memory NOT found",eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pNew = (pPolterdi)malloc(sizeof(Polterdi));
|
||||
if(!pNew){
|
||||
SCWrite(pCon,"ERROR: out of memory in PolterInstall",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
memset(pNew,0,sizeof(Polterdi));
|
||||
pNew->pDes = CreateDescriptor("PoldiWrite");
|
||||
pNew->pHist = pHist;
|
||||
pNew->dictfile = strdup(argv[1]);
|
||||
pNew->iInterval = 20*60;
|
||||
if(!pNew->pDes || !pNew->dictfile){
|
||||
SCWrite(pCon,"ERROR: out of memory in PolterInstall",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
/* install callbacks */
|
||||
pDum = (pDummy)pHist;
|
||||
pCall = (pICallBack)pDum->pDescriptor->GetInterface(pHist,CALLBACKINTERFACE);
|
||||
if(!pCall)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"ERROR: no callback interface found at your histogram memory",
|
||||
eError);
|
||||
KillPolterdi(pNew);
|
||||
return 0;
|
||||
}
|
||||
RegisterCallback(pCall,COUNTSTART,Countstartcallback,pNew,NULL);
|
||||
RegisterCallback(pCall,COUNTEND,Countendcallback,pNew,NULL);
|
||||
|
||||
AddCommand(pSics,"storedata",PolterAction,KillPolterdi,pNew);
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
int PolterAction(SConnection *pCon, SicsInterp *pSics,
|
||||
void *pData, int argc, char *argv[])
|
||||
@@ -695,11 +735,12 @@ int PolterAction(SConnection *pCon, SicsInterp *pSics,
|
||||
if((self->iNew) || (!self->pFile))
|
||||
{
|
||||
PoldiStart(self,pCon);
|
||||
PoldiUpdate(self,pCon);
|
||||
PoldiLink(self,pCon);
|
||||
}
|
||||
else
|
||||
{
|
||||
PoldiUpdate(self,pCon);
|
||||
PoldiLink(self,pCon);
|
||||
PoldiUpdate(self,pCon);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -731,7 +772,7 @@ int PolterAction(SConnection *pCon, SicsInterp *pSics,
|
||||
}
|
||||
else /* read the value */
|
||||
{
|
||||
sprintf(pBueffel,"storefocus.interval = %d",self->iInterval/60);
|
||||
sprintf(pBueffel,"storedata.interval = %d",self->iInterval/60);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user