From 054e2133ee4fad714c83f4b60923b7273eac0a45 Mon Sep 17 00:00:00 2001 From: koennecke Date: Fri, 8 Jul 2005 12:32:38 +0000 Subject: [PATCH] - Added a sinq module for monitoring the Accelerator broadcast - Added automatic notification via SMS SKIPPED: psi/dgrambroadcast.c psi/dgrambroadcast.h psi/make_gen psi/psi.c psi/sinq.c psi/sinq.h --- devexec.c | 19 +++++++++++++++++++ devexec.h | 11 ++++++++--- devexec.tex | 7 ++++++- devexec.w | 7 ++++++- fourtable.c | 26 ++++++++++++++++++++++---- fourtable.h | 1 + macro.c | 21 +++++++++++++++++---- mccontrol.c | 19 ++++++++++++++++--- mccontrol.h | 1 + mcstas.tex | 1 + mcstas.w | 1 + mcstas/dmc/DataNumber | 2 +- mcstas/dmc/MKMonitor.comp | 11 +++++++++++ mcstas/dmc/dmcprecalc.instr | 2 +- mcstas/dmc/vdmccom.tcl | 6 +++--- mcstas/dmc/vdmcstatus.tcl | 6 +++--- mesure.c | 33 ++++++++++++++++++++++++++------- motor.c | 6 +++++- ofac.c | 1 + scan.c | 28 ++++++++++++++-------------- 20 files changed, 163 insertions(+), 46 deletions(-) diff --git a/devexec.c b/devexec.c index bf333406..dbff8a20 100644 --- a/devexec.c +++ b/devexec.c @@ -41,6 +41,7 @@ -----------------------------------------------------------------------------*/ #include #include +#include #include #include "fortify.h" #include "sics.h" @@ -106,6 +107,7 @@ pTaskMan pTask; int iLock; pICallBack pCall; + time_t lastRun; } ExeList; static pExeList pExecutor = NULL; @@ -141,6 +143,7 @@ pRes->lTask = -1; pRes->iLock = 0; pRes->pCall = CreateCallBackInterface(); + pRes->lastRun = time(NULL); return pRes; } /*-------------------------------------------------------------------------*/ @@ -868,6 +871,21 @@ SCWrite(pCon, "ERROR: illegal arguments for ListExe", eError); return 0; } +/*-------------------------------------------------------------------------*/ + int SicsIdle(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]) + { + pExeList self = NULL; + int idle; + char pBueffel[80]; + + self = (pExeList)pData; + assert(self); + idle = time(NULL) - self->lastRun; + snprintf(pBueffel,79,"sicsidle = %d",idle); + SCWrite(pCon,pBueffel,eValue); + return 1; + } /*-------------------------------------------------------------------------- Usage: Success @@ -985,6 +1003,7 @@ return 0; } + self->lastRun = time(NULL); iRet = CheckExeList(self); switch(iRet) { diff --git a/devexec.h b/devexec.h index 1382a460..8e00f0e4 100644 --- a/devexec.h +++ b/devexec.h @@ -1,4 +1,4 @@ - + #line 195 "devexec.w" /*---------------------------------------------------------------------------- @@ -126,10 +126,15 @@ int ListExe(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]); - /* lists all currently executing objects */ + int SicsIdle(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]); + /* + prints the seconds since the device executor was running the last time + */ + int Success(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]); /* @@ -156,7 +161,7 @@ void UnlockDeviceExecutor(pExeList self); -#line 292 "devexec.w" +#line 297 "devexec.w" /* -------------------------- Executor management -------------------------*/ diff --git a/devexec.tex b/devexec.tex index 9adef9fa..e6515b8f 100644 --- a/devexec.tex +++ b/devexec.tex @@ -320,10 +320,15 @@ to the global SICS device executor. \mbox{}\verb@ @\\ \mbox{}\verb@ int ListExe(SConnection *pCon, SicsInterp *pSics, void *pData,@\\ \mbox{}\verb@ int argc, char *argv[]);@\\ -\mbox{}\verb@@\\ \mbox{}\verb@ /*@\\ \mbox{}\verb@ lists all currently executing objects@\\ \mbox{}\verb@ */@\\ +\mbox{}\verb@ int SicsIdle(SConnection *pCon, SicsInterp *pSics, void *pData,@\\ +\mbox{}\verb@ int argc, char *argv[]);@\\ +\mbox{}\verb@ /*@\\ +\mbox{}\verb@ prints the seconds since the device executor was running the last time@\\ +\mbox{}\verb@ */@\\ +\mbox{}\verb@@\\ \mbox{}\verb@ int Success(SConnection *pCon, SicsInterp *pSics, void *pData,@\\ \mbox{}\verb@ int argc, char *argv[]);@\\ \mbox{}\verb@ /*@\\ diff --git a/devexec.w b/devexec.w index fb2a56cb..45ff782c 100644 --- a/devexec.w +++ b/devexec.w @@ -266,10 +266,15 @@ to the global SICS device executor. int ListExe(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]); - /* lists all currently executing objects */ + int SicsIdle(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]); + /* + prints the seconds since the device executor was running the last time + */ + int Success(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]); /* diff --git a/fourtable.c b/fourtable.c index e1fd281c..06157a35 100644 --- a/fourtable.c +++ b/fourtable.c @@ -21,6 +21,7 @@ typedef struct { char scanVar[30]; double step; int np; + float preset; }FourTableEntry, *pFourTableEntry; /*==================== functions =======================================*/ int MakeFourCircleTable(){ @@ -52,8 +53,8 @@ static void printList(int handle, SConnection *pCon){ status = LLDnodePtr2First(handle); while(status == 1) { LLDnodeDataTo(handle,&entry); - snprintf(pBueffel,131,"%8.3f %s %8.3f %d\n", entry.twoThetaEnd, - entry.scanVar,entry.step, entry.np); + snprintf(pBueffel,131,"%8.3f %10s %8.3f %d %8.3f\n", entry.twoThetaEnd, + entry.scanVar,entry.step, entry.np,entry.preset); Tcl_DStringAppend(&list,pBueffel,-1); printed = 1; status = LLDnodePtr2Next(handle); @@ -153,6 +154,12 @@ static int addToList(int handle, SConnection *pCon, int argc, char *argv[]){ SCWrite(pCon,pBueffel,eError); return 0; } + entry.preset = -1.0; + if(argc > 7){ + if(isNumeric(argv[7])){ + entry.preset = atof(argv[7]); + } + } insertEntry(handle,entry); return 1; } @@ -273,6 +280,17 @@ double GetFourCircleStep(int handle, double two_theta){ } } /*------------------------------------------------------------------------*/ +float GetFourCirclePreset(int handle, double two_theta){ + FourTableEntry entry; + + entry = findEntry(handle,two_theta); + if(strcmp(entry.scanVar,"NOT FOUND") == 0){ + return -999.99; + } else { + return entry.preset; + } +} +/*------------------------------------------------------------------------*/ int GetFourCircleScanNP(int handle, double two_theta){ FourTableEntry entry; @@ -292,9 +310,9 @@ int SaveFourCircleTable(int handle, char *objName, FILE *fd){ status = LLDnodePtr2Last(handle); while(status != 0) { LLDnodeDataTo(handle,&entry); - fprintf(fd,"%s table add %f %s %f %d\n",objName, + fprintf(fd,"%s table add %f %s %f %d %f\n",objName, entry.twoThetaEnd,entry.scanVar, - entry.step,entry.np); + entry.step,entry.np,entry.preset); status = LLDnodePtr2Prev(handle); } return 1; diff --git a/fourtable.h b/fourtable.h index e1a787d3..53b5f42e 100644 --- a/fourtable.h +++ b/fourtable.h @@ -18,6 +18,7 @@ char *GetFourCircleScanVar(int handle, double two_theta); int GetFourCircleScanNP(int handle, double two_theta); double GetFourCircleStep(int handle, double two_theta); + float GetFourCirclePreset(int handle, double two_theta); int SaveFourCircleTable(int handle, char *objName, FILE *fd); #endif diff --git a/macro.c b/macro.c index 78cbe346..ae5740f2 100644 --- a/macro.c +++ b/macro.c @@ -829,7 +829,7 @@ static int ProtectedExec(ClientData clientData, Tcl_Interp *interp, { char pBueffel[1024]; pPubTcl self = NULL; - int iRet; + int iRet, length; char *pPtr; Tcl_Interp *pTcl = NULL; @@ -853,9 +853,22 @@ static int ProtectedExec(ClientData clientData, Tcl_Interp *interp, iRet = Tcl_Eval(pTcl,pBueffel); if(iRet == TCL_OK) - { - strncpy(pBueffel,pTcl->result,1023); - SCWrite(pCon,pBueffel,eStatus); + { length = strlen(pTcl->result); + if(length < 1024){ + strncpy(pBueffel,pTcl->result,1023); + SCWrite(pCon,pBueffel,eStatus); + } else { + length += 10; + pPtr = (char *)malloc(length*sizeof(char)); + if(pPtr == NULL){ + SCWrite(pCon,"ERROR: out of memory in TclAction",eError); + return 0; + } + memset(pPtr,0,length*sizeof(char)); + strncpy(pPtr,pTcl->result,length-1); + SCWrite(pCon,pPtr,eStatus); + free(pPtr); + } return 1; } else diff --git a/mccontrol.c b/mccontrol.c index e30121fa..7e8f9a9a 100644 --- a/mccontrol.c +++ b/mccontrol.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "stringdict.h" #include "mccontrol.h" /*========================= life and death ==================================*/ @@ -294,14 +295,25 @@ int McStasStart(pMcStasController self, CounterMode mode, float fPreset){ static long readMonFile(pMcStasController self){ char pResult[256]; FILE *fd = NULL; + struct flock fl; long monValue = -1; + int i; if(!StringDictGet(self->scripts,"mcmonfile",pResult,255)){ return -1; } + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + fl.l_pid = getpid(); + fd = fopen(pResult,"r"); if(fd != NULL){ + fcntl(fileno(fd),F_SETLKW,&fl); fscanf(fd,"%ld", &monValue); + fl.l_type = F_UNLCK; + fcntl(fileno(fd),F_SETLK,&fl); fclose(fd); } return monValue; @@ -313,11 +325,10 @@ int McStasStatus(pMcStasController self, float *fControl){ int status, i; /* - * check at max any second, else we keep the system busy and + * check at max any second, else SICS keeps the system busy and * there is no CPU left for McStas */ - SicsWait(1); - + SicsWait(1); status = invokeScript(self,"mcisrunning",pServ->pSics,pResult, 255); if(status == 0){ strncpy(self->errorText,pResult,255); @@ -342,6 +353,7 @@ int McStasStatus(pMcStasController self, float *fControl){ * check only any three seconds, else SICS uses up all the CPU time * and the simulation has no chance. */ + *fControl = self->lastMon; if(time(NULL) < self->lastMonitorRead + 3) { return HWBusy; } @@ -362,6 +374,7 @@ int McStasStatus(pMcStasController self, float *fControl){ self->lastMonitorRead = time(NULL); monValue *= self->monitorScale; *fControl = monValue; + self->lastMon = monValue; if(monValue >= self->fPreset){ McStasStop(self); } diff --git a/mccontrol.h b/mccontrol.h index 21004fa6..43d611f5 100644 --- a/mccontrol.h +++ b/mccontrol.h @@ -28,6 +28,7 @@ time_t startTime; time_t stopTime; time_t lastMonitorRead; + float lastMon; }McStasController, *pMcStasController; /*---------------------- function prototypes -------------------------------------------*/ diff --git a/mcstas.tex b/mcstas.tex index 4455c639..e528a3c7 100644 --- a/mcstas.tex +++ b/mcstas.tex @@ -82,6 +82,7 @@ $\langle$mcconint {\footnotesize ?}$\rangle\equiv$ \mbox{}\verb@ time_t startTime;@\\ \mbox{}\verb@ time_t stopTime;@\\ \mbox{}\verb@ time_t lastMonitorRead;@\\ +\mbox{}\verb@ float lastMon;@\\ \mbox{}\verb@ }McStasController, *pMcStasController;@\\ \mbox{}\verb@ @$\diamond$ \end{list} diff --git a/mcstas.w b/mcstas.w index 57368723..51e868e1 100644 --- a/mcstas.w +++ b/mcstas.w @@ -77,6 +77,7 @@ deemed advisable to separate this logic into a separate module. The McStas contr time_t startTime; time_t stopTime; time_t lastMonitorRead; + float lastMon; }McStasController, *pMcStasController; @} The fields are: diff --git a/mcstas/dmc/DataNumber b/mcstas/dmc/DataNumber index f7ab7dfd..c020f0ef 100644 --- a/mcstas/dmc/DataNumber +++ b/mcstas/dmc/DataNumber @@ -1,3 +1,3 @@ - 71 + 81 NEVER, EVER modify or delete this file You'll risk eternal damnation and a reincarnation as a cockroach!|n \ No newline at end of file diff --git a/mcstas/dmc/MKMonitor.comp b/mcstas/dmc/MKMonitor.comp index 27274eb4..0b4303b5 100644 --- a/mcstas/dmc/MKMonitor.comp +++ b/mcstas/dmc/MKMonitor.comp @@ -47,12 +47,23 @@ OUTPUT PARAMETERS (Nsum, psum, p2sum,currentCount) STATE PARAMETERS (x,y,z,vx,vy,vz,t,s1,s2,p) SHARE %{ +#include void dumpTotal(char *ffilename, long totalCounts){ FILE *fd = NULL; + struct flock fl; + + fl.l_type = F_WRLCK; + fl.l_whence = 0; + fl.l_start = 0; + fl.l_len = 0; + fl.l_pid = getpid(); fd = fopen(ffilename,"w"); if(fd != NULL){ + fcntl(fileno(fd),F_SETLKW,&fl); fprintf(fd,"%ld\n",totalCounts); + fl.l_type = F_UNLCK; + fcntl(fileno(fd),F_SETLK,&fl); fclose(fd); } } diff --git a/mcstas/dmc/dmcprecalc.instr b/mcstas/dmc/dmcprecalc.instr index a8837bef..b7b90bb7 100644 --- a/mcstas/dmc/dmcprecalc.instr +++ b/mcstas/dmc/dmcprecalc.instr @@ -107,7 +107,7 @@ COMPONENT Bmoin_slit = Slit( AT (0,0,0.525) RELATIVE msa ROTATED (0,0,0) RELATIVE msa -COMPONENT out = Virtual_output(file=lambdafile) +COMPONENT out = Virtual_output(file=lambdafile,bufsize=100000) AT(0,0,0.64) RELATIVE msa ROTATED (0,0,0) RELATIVE msa END diff --git a/mcstas/dmc/vdmccom.tcl b/mcstas/dmc/vdmccom.tcl index 6f1d3bfd..07408040 100644 --- a/mcstas/dmc/vdmccom.tcl +++ b/mcstas/dmc/vdmccom.tcl @@ -163,7 +163,7 @@ proc copydmcdata { } { mcreader open $home/dmc.xml mcreader insertmon \ "/$mcversion/DMC_diff/dmc.xml/PSD_sample/values" \ - counter 1 [expr 1./10000] + counter 1 [expr 1./1000] mcreader insertmon \ "/$mcversion/DMC_diff/dmc.xml/Det9/det9.dat/values" \ counter 5 @@ -171,7 +171,7 @@ proc copydmcdata { } { if { $hmScale <= 0} { set hmScale 1e9 } else { - set hmScale [expr $hmScale * 1e9] + set hmScale [expr $hmScale * 1e7] } clientput "HM scale = $hmScale" mcreader inserthm \ @@ -188,7 +188,7 @@ mccontrol configure mcstart rundmcoptsim mccontrol configure mccopydata copydmcdata mccontrol configure update 60 mccontrol configure mcmonfile $home/monfile -mccontrol configure monitorscale [expr 1. /10000] +mccontrol configure monitorscale [expr 1. /1000] mccontrol configure mcdump mcstasdump #-------------------------------------------------------------------------- # A count command for VDMC diff --git a/mcstas/dmc/vdmcstatus.tcl b/mcstas/dmc/vdmcstatus.tcl index e4e015e0..31d9cfdb 100644 --- a/mcstas/dmc/vdmcstatus.tcl +++ b/mcstas/dmc/vdmcstatus.tcl @@ -14,7 +14,7 @@ sicsdatapostfix .hdf sicsdatapostfix setAccess 0 sicsdataprefix powder sicsdataprefix setAccess 0 -starttime 2005-07-01 16:19:39 +starttime 2005-07-08 10:41:56 starttime setAccess 2 comment3 UNKNOWN comment3 setAccess 2 @@ -121,9 +121,9 @@ a1 precision 0.010000 a1 AccessCode 2.000000 a1 movecount 10.000000 banana CountMode monitor -banana preset 5.000000 +banana preset 2.000000 # Counter counter -counter SetPreset 5000.000000 +counter SetPreset 2000.000000 counter SetMode Monitor # Motor twothetad twothetad sign 1.000000 diff --git a/mesure.c b/mesure.c index dc182539..49e03992 100644 --- a/mesure.c +++ b/mesure.c @@ -371,6 +371,9 @@ static void ListMesure(pMesure self, char *name, SConnection *pCon) /* loop over all scan variables */ status = 1; + memset(pHead,0,512*sizeof(char)); + memset(pStatus,0,512*sizeof(char)); + memset(pItem,0,20*sizeof(char)); for(i = 0; i < self->iScanVar; i++) { DynarGet(self->pScanVar,i,&pDings); @@ -378,7 +381,7 @@ static void ListMesure(pMesure self, char *name, SConnection *pCon) if(pVar) { fVal = pVar->pInter->GetValue(pVar->pObject,self->pCon); - AppendScanVar(pVar,fVal); + AppendScanVar(pVar,fVal); sprintf(pItem,"%-10.10s",pVar->Name); strcat(pHead,pItem); sprintf(pItem,"%-10.3f",fVal); @@ -551,12 +554,14 @@ int weakScan(pMesure self, double twoTheta) } } /*-----------------------------------------------------------------------*/ -static int PerformPSDScan(pMesure self, char *scanVar, float fStart, float step, int np) +static int PerformPSDScan(pMesure self, char *scanVar, float fStart, + float step, int np, float two_theta) { int status; char pCommand[1024]; char countMode[20]; Tcl_Interp *pTcl; + float fPreset; /* PSD scans are done by calling the routine Tcl procedure tricsscan with the @@ -570,7 +575,12 @@ static int PerformPSDScan(pMesure self, char *scanVar, float fStart, float step, { strcpy(countMode,"monitor"); } - snprintf(pCommand,1023,"tricsscan %f %f %d %s %f", fStart, step, np,countMode,self->fPreset); + fPreset = GetFourCirclePreset(self->stepTable,(double)two_theta); + if(fPreset < .0){ + fPreset = self->fPreset; + } + snprintf(pCommand,1023,"tricsscan %f %f %d %s %f", fStart, step, np, + countMode,fPreset); pTcl = InterpGetTcl(pServ->pSics); status = Tcl_Eval(pTcl,pCommand); if(status != TCL_OK) @@ -585,7 +595,7 @@ static int PerformPSDScan(pMesure self, char *scanVar, float fStart, float step, /*------------------------------------------------------------------------*/ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon) { - float fStart, stepWidth; + float fStart, stepWidth, fPreset; int iRet, np; char pBueffel[132]; char *scanVar = NULL; @@ -619,7 +629,7 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon) */ if(self->psd == 1) { - iRet = PerformPSDScan(self,scanVar,fStart, stepWidth, np); + iRet = PerformPSDScan(self,scanVar,fStart, stepWidth, np,twoTheta); free(scanVar); return iRet; } @@ -668,6 +678,14 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon) memset(self->lCounts,0,np*sizeof(long)); } + /* + * determine preset + */ + fPreset = GetFourCirclePreset(self->stepTable,(double)twoTheta); + if(fPreset < .0){ + fPreset = self->fPreset; + } + /* do the scan */ free(scanVar); if(self->iCompact) @@ -679,7 +697,7 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon) self->pScanner->ScanDrive = ScanFastDrive; } iRet = SilentScan(self->pScanner,np,self->CountMode, - self->fPreset,pServ->pSics,pCon); + fPreset,pServ->pSics,pCon); if(weakScan(self,twoTheta)) { /* @@ -701,7 +719,7 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon) */ SCWrite(pCon,"Remeasuring weak reflection",eWarning); iRet = SilentScan(self->pScanner,np,self->CountMode, - self->fPreset*5.,pServ->pSics,pCon); + fPreset*5.,pServ->pSics,pCon); } ResetScanFunctions(self->pScanner); @@ -941,6 +959,7 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon) assert(self); assert(pCon); + memset(pTime,0,132*sizeof(char)); #ifdef MESSDEBUG self->np = 90; diff --git a/motor.c b/motor.c index d8346f3c..233c5f88 100644 --- a/motor.c +++ b/motor.c @@ -327,7 +327,11 @@ static int evaluateStatus(pMotor self, SConnection *pCon) } if(newStatus == HWIdle || newStatus == OKOK) { - finishDriving(self,pCon); + newStatus = checkPosition(self,pCon); + if(newStatus != HWBusy) + { + finishDriving(self,pCon); + } } break; case HWBusy: diff --git a/ofac.c b/ofac.c index a1124076..61a8fbad 100644 --- a/ofac.c +++ b/ofac.c @@ -243,6 +243,7 @@ */ AddCommand(pInter,"StopExe",StopCommand,DeleteExeList, pExe); AddCommand(pInter,"ListExe",ListExe,NULL,pExe); + AddCommand(pInter,"sicsidle",SicsIdle,NULL,pExe); AddCommand(pInter,"Success",Success,NULL,pExe); AddCommand(pInter,"pause",PauseAction,NULL,pExe); AddCommand(pInter,"continue",ContinueAction,NULL,pExe); diff --git a/scan.c b/scan.c index 4dec8030..ddcabd49 100644 --- a/scan.c +++ b/scan.c @@ -305,20 +305,20 @@ static void ConfigureScanDict(pStringDict dict) pCount = (pCountEntry)pData; if(pCount != NULL) { - fprintf(fd,"%s storecounts %ld %f %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n", - self->objectName, - pCount->lCount, - pCount->fTime, - pCount->Monitors[0], - pCount->Monitors[1], - pCount->Monitors[2], - pCount->Monitors[3], - pCount->Monitors[4], - pCount->Monitors[5], - pCount->Monitors[6], - pCount->Monitors[7], - pCount->Monitors[8], - pCount->Monitors[9]); + fprintf(fd,"%s storecounts %ld %f %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n", + self->objectName, + pCount->lCount, + pCount->fTime, + pCount->Monitors[0], + pCount->Monitors[1], + pCount->Monitors[2], + pCount->Monitors[3], + pCount->Monitors[4], + pCount->Monitors[5], + pCount->Monitors[6], + pCount->Monitors[7], + pCount->Monitors[8], + pCount->Monitors[9]); } } if(self->iMode == eTimer){