From 7669a9b3fbee23dfedac4ff02ba17addb22cc231 Mon Sep 17 00:00:00 2001 From: cvs Date: Wed, 23 Apr 2003 11:52:44 +0000 Subject: [PATCH] - Recovered POLDI from the land of lost files --- choco.c | 2 +- docho.c | 19 ++-- histmem.c | 33 ++++++ hmdata.c | 6 +- polterwrite.c | 295 ++++++++++++++++++++++++++++---------------------- polterwrite.h | 6 +- 6 files changed, 220 insertions(+), 141 deletions(-) diff --git a/choco.c b/choco.c index 2279446c..f8902f00 100644 --- a/choco.c +++ b/choco.c @@ -231,7 +231,7 @@ extern pCodri MakeCookerDriver(char *pHost, int iPort, int iChannel); SCWrite(pCon,pBueffel,eError); return 0; } - if(argc > 7) + if(argc > 6) { iRet = Tcl_GetInt(pSics->pTcl,argv[6],&iSingle); if(iRet != TCL_OK) diff --git a/docho.c b/docho.c index f513f5da..6a0dd96b 100644 --- a/docho.c +++ b/docho.c @@ -94,7 +94,7 @@ extern char *trim(char *pTrim); /* trim.c */ /*----------------------------------------------------------------------*/ static void SplitChopperReply(pCodri self, char *prefix, char *pBueffel) { - char pToken[30], pValue[20]; + char pToken[30], pValue[20], pEntry[80]; char *pPtr, *pTok, *pVal; int iCount, iRet; pDoCho pPriv = NULL; @@ -110,12 +110,13 @@ static void SplitChopperReply(pCodri self, char *prefix, char *pBueffel) { pTok = trim(pToken); pVal = trim(pValue); - sprintf(pToken,"%s.%s",prefix,pTok); - iRet = StringDictUpdate(pPriv->pPar,pToken,pVal); + pEntry[0] = '\0'; + sprintf(pEntry,"%s.%s",prefix,pTok); + iRet = StringDictUpdate(pPriv->pPar,pEntry,pVal); if(!iRet) { - StringDictAddPair(pPriv->pPar,pToken,pVal); - strcat(self->pParList,pToken); + StringDictAddPair(pPriv->pPar,pEntry,pVal); + strcat(self->pParList,pEntry); strcat(self->pParList,","); } } @@ -124,14 +125,14 @@ static void SplitChopperReply(pCodri self, char *prefix, char *pBueffel) /* this fixes a bug with oversized messages in dphas */ if(strstr(pPtr,"dphas") != NULL) { - sprintf(pToken,"%s.dphas",prefix); + sprintf(pEntry,"%s.dphas",prefix); iRet = StringDictUpdate(pPriv->pPar, - pToken,pPtr+5); + pEntry,pPtr+5); if(!iRet) { - StringDictAddPair(pPriv->pPar,pToken, + StringDictAddPair(pPriv->pPar,pEntry, pPtr+5); - strcat(self->pParList,pToken); + strcat(self->pParList,pEntry); strcat(self->pParList,","); } } diff --git a/histmem.c b/histmem.c index 7e61162a..aa51dd21 100644 --- a/histmem.c +++ b/histmem.c @@ -711,6 +711,15 @@ return StartDevice(GetExecutor(),"HistogramMemory", self->pDes, self, pCon, self->pDriv->fCountPreset); } +/*-------------------------------------------------------------------------*/ + int HistDoEnd(pHistMem self, SConnection *pCon) + { + assert(self); + assert(self->pCall); + + /* send a COUNTEND event */ + InvokeCallBack(self->pCall,COUNTEND,NULL); + } /*-----------------------------------------------------------------------*/ int HistBlockCount(pHistMem self, SConnection *pCon) { @@ -1171,6 +1180,30 @@ static int checkHMEnd(pHistMem self, char *text){ { return 0; } + } + /* COUNTEND signal*/ + else if(strcmp(argv[1],"countend") == 0) + { + if(SCMatchRights(pCon,self->iAccess)) + { + if(IsCounting(pServ->pExecutor)) + { + SCWrite(pCon,"WARNING: HM is counting!",eWarning); + return 1; + } + iRet = HistDoEnd(self,pCon); + if(iRet == 1) + { + SCSendOK(pCon); + } + return iRet; + } + else + { + SCWrite(pCon, + "ERROR: you are not privileged for attempted operation",eError); + return 0; + } } /* forced count, for the case several hm need to be started */ else if(strcmp(argv[1],"countf") == 0) diff --git a/hmdata.c b/hmdata.c index 89683bd6..2e4e2f77 100644 --- a/hmdata.c +++ b/hmdata.c @@ -67,7 +67,11 @@ int configureHMdata(pHMdata self, pStringDict pOpt, float fVal; char pValue[80]; - self->tofMode = 0; + if(self->nTimeChan > 2) { + self->tofMode = 1; + } else { + self->tofMode = 0; + } status = StringDictGetAsNumber(pOpt,"rank",&fVal); if(!status){ SCWrite(pCon,"ERROR: critical configuration problem: no rank found", diff --git a/polterwrite.c b/polterwrite.c index 76ed92f2..ec124cca 100644 --- a/polterwrite.c +++ b/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; } diff --git a/polterwrite.h b/polterwrite.h index 68db1bb1..e08b8cbc 100644 --- a/polterwrite.h +++ b/polterwrite.h @@ -1,14 +1,14 @@ /*-------------------------------------------------------------------------- P O L T E R W R I T E - fowrite is an object for writing POLTERDI data files. + polterwrite is an object for writing POLDI data files. copyright: see copyright.h Uwe Filges, November 2001 ----------------------------------------------------------------------------*/ -#ifndef POLTERDIWRITE -#define POLTERDIWRITE +#ifndef POLTERDI +#define POLTERDI int PolterInstall(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]);