From 1ae7c0c2e23ba90cdabede99e342a5fcf510d538 Mon Sep 17 00:00:00 2001 From: koennecke Date: Tue, 1 Jun 2010 10:01:00 +0000 Subject: [PATCH] - Introduced a command history log for statistical and syntax checking input purposes - Rectified an error message in fourmess.c - HMcontrol did not check for the HM to stop before returning. This caused weird data files at AMOR as the data had not yet been downloaded from the HM. - Fixed an issue about parameters in multicounter - Temporary fix in nxscript.c to always read the Hm from the HM and not a buffer. This is prior to rethinking caching strategies for old style HM's. - Synchronize now copies fixed motors correctly. This used to cause irritation with users. This now requires a script syncdrive to exist in the sync server which takes care of handling the fixed flag when this is desired. - Added initify to sicsdata in order to copy large value timebins over properly at AMOR SKIPPED: psi/amorstat.c psi/make_gen psi/makefile_linux psi/polterwrite.c psi/sinq.c psi/sinqhttp.c psi/sinqhttpprot.c psi/sps.c psi/tdchm.c --- SCinter.c | 2 +- commandlog.c | 43 ++++++++++++++++++++++++++++++++ commandlog.h | 1 + conman.c | 6 +++++ counter.c | 9 +++++-- devexec.c | 1 + exebuf.c | 7 +++++- fourmess.c | 2 +- histmem.c | 13 ++++++++++ histmemsec.c | 26 ++++++++++++++++++- hmcontrol.c | 65 ++++++++++++++++++++++++++++++++++-------------- hmcontrol.h | 1 + macro.c | 42 ++++++++++++++++++++++++++++++- makefile_slinux | 2 +- multicounter.c | 14 +++++++++-- nxscript.c | 3 ++- sicsdata.c | 20 +++++++++++++++ synchronize.c | 4 +-- test/testini.tcl | 18 ++++++++------ 19 files changed, 239 insertions(+), 40 deletions(-) diff --git a/SCinter.c b/SCinter.c index 6404ca57..b797ef0b 100644 --- a/SCinter.c +++ b/SCinter.c @@ -464,7 +464,7 @@ int WriteSicsStatus(SicsInterp * self, char *file, int iMot) fVal = pDriv->GetValue(pDum, pServ->dummyCon); } if (fVal > -990.) { - fprintf(fd, "drive %s %f\n", pCurrent->pName, fVal); + fprintf(fd, "syncdrive %s %f\n", pCurrent->pName, fVal); } } } diff --git a/commandlog.c b/commandlog.c index b253d79f..51e97019 100644 --- a/commandlog.c +++ b/commandlog.c @@ -521,3 +521,46 @@ void CommandLogInit(void) { AddCommand(pServ->pSics, "commandlog", CommandLog, CommandLogClose, NULL); } +/*---------------------- History -----------------------------------------*/ +static FILE *comHistory = NULL; +/*-----------------------------------------------------------------------*/ +static int openHistoryLog() +{ + char *fileName = NULL; + char fileBuffer[1024]; + time_t iDate; + struct tm *psTime; + + + if (comHistory == NULL) { + fileName = IFindOption(pSICSOptions, "historylog"); + if (fileName != NULL) { + strlcpy(fileBuffer, fileName,1024); + } else { + iDate = time(NULL); + psTime = localtime(&iDate); + fileBuffer[0] = '\0'; + fileName = getenv("HOME"); + if (fileName != NULL) { + snprintf(fileBuffer, 1023, "%s/log/comhistory%4.4d.log", + fileName, psTime->tm_year + 1900); + } + } + comHistory = fopen(fileBuffer, "a+"); + } + if (comHistory == NULL) { + return 0; + } else { + return 1; + } +} +/*-----------------------------------------------------------------------*/ +void WriteCommandHistory(char *txt) +{ + if(comHistory == NULL){ + openHistoryLog(); + } + if(comHistory != NULL){ + fprintf(comHistory,"%s\n", txt); + } +} diff --git a/commandlog.h b/commandlog.h index db23bb23..920f5847 100644 --- a/commandlog.h +++ b/commandlog.h @@ -17,4 +17,5 @@ int CommandLog(SConnection * pCon, SicsInterp * pSics, void *pData, int argc, char *argv[]); void CommandLogClose(void *pData); +void WriteCommandHistory(char *txt); #endif diff --git a/conman.c b/conman.c index 4f209a2b..44301165 100644 --- a/conman.c +++ b/conman.c @@ -1416,6 +1416,12 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand) SCDeleteConnection(pCopy); StatusFileTask(NULL); /* save changed parameters */ + /* + * log successful commands for later evaluation + */ + if(iRet == 1){ + WriteCommandHistory(pCommand); + } self->inUse--; return iRet; } diff --git a/counter.c b/counter.c index f60a6776..188847f8 100644 --- a/counter.c +++ b/counter.c @@ -258,6 +258,7 @@ static int CheckCountStatus(void *pData, SConnection * pCon) notification on finish */ if (eCt == HWIdle) { + self->isUpToDate = 0; InvokeCallBack(self->pCall, COUNTEND, NULL); ReleaseCountLock(self->pCountInt); } @@ -770,7 +771,7 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, int argc, char *argv[]) { pCounter self = NULL; - int iRet, iRet2; + int iRet, iRet2, i; FuPaResult PaRes; char pBueffel[256], pError[80]; char **argx; @@ -929,9 +930,13 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, case 11: /* status */ self->pCountInt->TransferData(self, pCon); if (GetCounterMode(self) == ePreset) { + lVal = GetCounterPreset(self); + for(i = 0; i < self->iExponent; i++){ + lVal *= 10; + } sprintf(pBueffel, "%s.CountStatus = %d %d Beam: %ld E6", argv[0], - (int) nintf(GetCounterPreset(self)), + (int) nintf(lVal), (int) nintf(GetControlValue(self)), GetMonitor(self, 4, pCon) / 100000); } else { diff --git a/devexec.c b/devexec.c index 03091413..bd1e4b7d 100644 --- a/devexec.c +++ b/devexec.c @@ -1298,6 +1298,7 @@ void DevExecSignal(void *pEL, int iSignal, void *pSigData) "ERROR: Interrupting Current Hardware Operation", eError); SCSetInterrupt(pCon, *iInt); + SCSetInterrupt(self->pOwner, *iInt); SCDeleteConnection(pCon); } } diff --git a/exebuf.c b/exebuf.c index 0380a7df..665fbd3f 100644 --- a/exebuf.c +++ b/exebuf.c @@ -18,6 +18,7 @@ #include "dynstring.h" #include "exebuf.i" #include "status.h" +#include "commandlog.h" /*-----------------------------------------------------------------------*/ pExeBuf exeBufCreate(char *name) @@ -216,6 +217,7 @@ int exeBufProcess(pExeBuf self, SicsInterp * pSics, /* print only SICS commands */ SCPrintf(pCon, eLog, "%s:%d>> %s", self->name, self->lineno, cmd); + WriteCommandHistory(cmd); } else { /* debugging */ /* SCPrintf(pCon, eValue, "%s:%d>> %s",self->name,self->lineno,cmd); */ @@ -245,7 +247,10 @@ int exeBufProcess(pExeBuf self, SicsInterp * pSics, if (SCGetInterrupt(pCon) >= eAbortBatch) { SCWrite(pCon, "ERROR: batch processing interrupted", eError); SetStatus(eEager); - return 0; + if (pCall != NULL) { + InvokeCallBack(pCall, BATCHEND, self->name); + } + return 0; } else { SCSetInterrupt(pCon, eContinue); } diff --git a/fourmess.c b/fourmess.c index 05d17b03..19c95df2 100644 --- a/fourmess.c +++ b/fourmess.c @@ -286,7 +286,7 @@ static int FourMessScanPar(pSICSOBJ self, SConnection * pCon, dVal = GetFourCircleStep(priv->stepTable, stt); np = GetFourCircleScanNP(priv->stepTable, stt); preset = GetFourCirclePreset(priv->stepTable, stt); - if (strcmp(scanvar, "NOT FOUND") == 0) { + if (strcmp(scanvar, "Not found") == 0) { SCPrintf(pCon, eValue, "%s,%f,%d,%d", "om", dVal, np, preset); } else { SCPrintf(pCon, eValue, "%s,%f,%d,%d", scanvar, dVal, np, preset); diff --git a/histmem.c b/histmem.c index abaa1282..a8fe06f2 100644 --- a/histmem.c +++ b/histmem.c @@ -641,6 +641,19 @@ int GetHistDim(pHistMem self, int iDim[MAXDIM], int *nDim) { assert(self); + pDummy pDum; + hdbValue v; + pHdb node; + + pDum = (pDummy)self; + if(strcmp(pDum->pDescriptor->name,"HistMemSec") == 0){ + node = GetHipadabaNode(pDum->pDescriptor->parNode,"dim"); + assert(node != NULL); + GetHipadabaPar(node,&v,NULL); + *nDim = v.arrayLength; + memcpy(iDim,v.v.intArray, *nDim*sizeof(int)); + return 1; + } getHMDataDim(self->pDriv->data, iDim, nDim); if (isInTOFMode(self->pDriv->data)) { diff --git a/histmemsec.c b/histmemsec.c index d76f5bff..053d82cf 100644 --- a/histmemsec.c +++ b/histmemsec.c @@ -145,6 +145,27 @@ static int HMCtrTransferData(void *pData, SConnection *pCon) ReleaseHdbValue(&v); return status; } +/*------------------------------------------------------------------------- + * automatically update the last entry of the dim variable when + * setting time_binning +--------------------------------------------------------------------------*/ +static hdbCallbackReturn HMTOFCallback(pHdb currentNode, void *data, + pHdbMessage message) +{ + pHdbDataMessage update = NULL; + hdbValue dim; + pHdb dimNode = NULL; + + if((update = GetHdbUpdateMessage(message)) != NULL){ + dimNode = GetHipadabaNode(currentNode->mama,"dim"); + assert(dimNode != NULL); + GetHipadabaPar(dimNode,&dim,NULL); + dim.v.intArray[dim.arrayLength-1] = update->v->arrayLength; + UpdateHipadabaPar(dimNode, dim, NULL); + } + return hdbContinue; +} + /*-------------------------------------------------------------------------- * Usage: * MakeSecHM name rank (tof) @@ -164,7 +185,7 @@ int MakeSecHM(SConnection * pCon, SicsInterp * pSics, void *pData, rank = atoi(argv[2]); - pRes = CreateSecCounter(pCon,"HistMem", argv[1], 2); + pRes = CreateSecCounter(pCon,"HistMemSec", argv[1], 2); if(pRes == NULL){ return 0; } @@ -217,6 +238,9 @@ int MakeSecHM(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } AddHipadabaChild(node, child, NULL); + AppendHipadabaCallback(child, + MakeHipadabaCallback(HMTOFCallback, NULL, NULL)); + child = AddSICSHdbPar(node,"genbin", usMugger, MakeSICSFunc(GenbinCmd)); AddSICSHdbPar(child, "start", usMugger, MakeHdbFloat(10.)); AddSICSHdbPar(child, "step", usMugger, MakeHdbFloat(10.)); diff --git a/hmcontrol.c b/hmcontrol.c index a41067d4..e0a65263 100644 --- a/hmcontrol.c +++ b/hmcontrol.c @@ -74,6 +74,17 @@ static int HMCStart(void *pData, SConnection * pCon) return status; } } + /* + Warning: this assumes that slaves 1 - MAXSLAVE are histogram memories. + If this assumption does not hold, change this code to check if this + is really a histogram memory. + */ + for (i = 1; i < MAXSLAVE; i++) { + if (self->slaves[i] != NULL) { + HistDirty((pHistMem) self->slaveData[i]); + } + } + self->checkSlaves = 0; return OKOK; } @@ -86,26 +97,42 @@ static int HMCStatus(void *pData, SConnection * pCon) self = (pHMcontrol) pData; assert(self); - status = self->slaves[0]->CheckCountStatus(self->slaveData[0], pCon); - if (status == HWIdle || status == HWFault) { - /* - stop counting on slaves when finished or when an error - occurred. - */ - InvokeCallBack(self->pCall, COUNTEND, pCon); - HMCHalt(self); + if(self->checkSlaves == 0) { + status = self->slaves[0]->CheckCountStatus(self->slaveData[0], pCon); + /* + Warning: this assumes that slaves 1 - MAXSLAVE are histogram memories. + If this assumption does not hold, change this code to check if this + is really a histogram memory. + */ + for (i = 1; i < MAXSLAVE; i++) { + if (self->slaves[i] != NULL) { + HistDirty((pHistMem) self->slaveData[i]); + } + } + if (status == HWIdle || status == HWFault) { + /* + stop counting on slaves when finished or when an error + occurred. + */ + HMCHalt(self); + self->checkSlaves = 1; + status = HWBusy; + } + } else { + /* + * wait for the detectors to report finish too. Otherwise, with the second + * generation HM data may not be fully transferred. + */ + for(i = 1; i < self->nSlaves; i++){ + status = self->slaves[i]->CheckCountStatus(self->slaveData[i], pCon); + if(status != HWIdle || status != HWFault){ + return status; + } + } + status = HWIdle; + InvokeCallBack(self->pCall, COUNTEND, pCon); + self->checkSlaves = 0; } - /* - Warning: this assumes that salves 1 - MAXSLAVE are histogram memories. - If this assumption does not hold, change this code to check if this - is really a histogram memory. - */ - for (i = 1; i < MAXSLAVE; i++) { - if (self->slaves[i] != NULL) { - HistDirty((pHistMem) self->slaveData[i]); - } - } - return status; } diff --git a/hmcontrol.h b/hmcontrol.h index 2a14cf41..f2bf5ce5 100644 --- a/hmcontrol.h +++ b/hmcontrol.h @@ -32,6 +32,7 @@ typedef struct { float fPreset; CounterMode eMode; pICallBack pCall; + int checkSlaves; } HMcontrol, *pHMcontrol; diff --git a/macro.c b/macro.c index 7d215bb5..c58f7c1e 100644 --- a/macro.c +++ b/macro.c @@ -71,6 +71,7 @@ #include "stringdict.h" #include "exeman.h" #include "nxcopy.h" +#include "commandlog.h" #define SICSERROR "005567SICS" /*---------------------------------------------------------------------------- @@ -117,7 +118,33 @@ int MacroPop(void) } return 1; } +/*--------------------------------------------------------------------------- + * This is to suppress certain stuff from the history log in order to stop it + * from filling with garbage + -----------------------------------------------------------------------------*/ +static int historyFilter(pDummy pDum, char *command, char *fullCommand) +{ + static char *toRemove[] = {"sct", "hupdate",NULL}; + static char *typeRemove[] = {"ScriptContext",NULL}; + int i = 0; + while(toRemove[i] != NULL){ + if(strcmp(command,toRemove[i]) == 0){ + return 0; + } + i++; + } + + i = 0; + while(typeRemove[i] != NULL){ + if(strcmp(pDum->pDescriptor->name, typeRemove[i]) == 0) { + return 0; + } + i++; + } + + return 1; +} /*---------------------------------------------------------------------------*/ static int SicsUnknownProc(ClientData pData, Tcl_Interp * pInter, int argc, char *argv[]) @@ -128,7 +155,7 @@ static int SicsUnknownProc(ClientData pData, Tcl_Interp * pInter, SicsInterp *pSinter = NULL; SConnection *pCon = NULL; CommandList *pCommand = NULL; - char *lastCommand = NULL, comBuffer[132]; + char *lastCommand = NULL, comBuffer[132], comHistory[256]; int iRet = 0, i; int iMacro; Statistics *old; @@ -188,6 +215,19 @@ static int SicsUnknownProc(ClientData pData, Tcl_Interp * pInter, iRet = pCommand->OFunc(pCon, pSinter, pCommand->pData, margc, myarg); StatisticsEnd(old); SCsetMacro(pCon, iMacro); + + if(iRet == 1){ + /* + * this is OK because comBuffer is length restricted + */ + strcpy(comHistory,"SICSUNKNOWN: "); + strcat(comHistory,comBuffer); + /* This gives just to many unwanted entries.... TODO: Filter better + if(historyFilter(pCommand->pData, myarg[0], comBuffer) == 1){ + WriteCommandHistory(comHistory); + } + */ + } /* lastUnkown gets deeply stacked with each SICS command exec'd. This is not reflected in code. However, lastUnknown has already diff --git a/makefile_slinux b/makefile_slinux index b896439b..8ac74d63 100644 --- a/makefile_slinux +++ b/makefile_slinux @@ -23,7 +23,7 @@ BINTARGET = bin EXTRA=nintf.o SUBLIBS = psi/libpsi.a psi/hardsup/libhlib.a matrix/libmatrix.a \ psi/tecs/libtecsl.a -LIBS = -L$(HDFROOT)/lib $(SUBLIBS) $(NILIB)\ +LIBS = -L$(HDFROOT)/lib $(SUBLIBS) $(NILIB)\ -ltcl $(HDFROOT)/lib/libhdf5.a \ $(HDFROOT)/lib/libmfhdf.a $(HDFROOT)/lib/libdf.a \ $(HDFROOT)/lib/libjpeg.a $(HDFROOT)/lib/libsz.a \ diff --git a/multicounter.c b/multicounter.c index b9357a3f..ed129a69 100644 --- a/multicounter.c +++ b/multicounter.c @@ -314,7 +314,11 @@ static int MultiCounterSet(struct __COUNTER *pCount, char *name, pDum = (pDummy)self->slaveData[i]; if(strcmp(pDum->pDescriptor->name, "SingleCounter") == 0){ pCter = (pCounter)self->slaveData[i]; - return pCter->pDriv->Set(pCter->pDriv, name, iCter, fVal); + if(pCter->pDriv != NULL){ + return pCter->pDriv->Set(pCter->pDriv, name, iCter, fVal); + } else { + return 0; + } } } return 0; @@ -327,6 +331,8 @@ static int MultiCounterGet(struct __COUNTER *pCount, char *name, int i; pMultiCounter self = NULL; pCounter pCter; + pHdb node; + hdbValue v; self = (pMultiCounter) pCount->pData; assert(self); @@ -335,7 +341,11 @@ static int MultiCounterGet(struct __COUNTER *pCount, char *name, pDum = (pDummy)self->slaveData[i]; if(strcmp(pDum->pDescriptor->name, "SingleCounter") == 0){ pCter = (pCounter)self->slaveData[i]; - return pCter->pDriv->Get(pCter->pDriv, name, iCter, fVal); + if(pCter->pDriv != NULL){ + return pCter->pDriv->Get(pCter->pDriv, name, iCter, fVal); + } else { + return 0; + } } } return 0; diff --git a/nxscript.c b/nxscript.c index dff19f32..a74b5d12 100644 --- a/nxscript.c +++ b/nxscript.c @@ -505,7 +505,7 @@ static void putHdb(SConnection * pCon, SicsInterp * pSics, pNXScript self, return; } for (i = 0; i < v.arrayLength; i++) { - floatAr[i] = v.v.floatArray[i]; + floatAr[i] = (float)v.v.floatArray[i]; } NXDputalias(self->fileHandle, self->dictHandle, alias, floatAr); free(floatAr); @@ -733,6 +733,7 @@ static void putHistogramMemory(SConnection * pCon, SicsInterp * pSics, */ start = 0; length = GetHistLength(mem); + subset = 1; updateHMDim(self, mem); diff --git a/sicsdata.c b/sicsdata.c index 313687cc..ca707c69 100644 --- a/sicsdata.c +++ b/sicsdata.c @@ -868,6 +868,23 @@ static int copyNode(pSICSData self, int argc, char *argv[], return 1; } /*--------------------------------------------------------------------*/ +static int intify(pSICSData self, int argc, char *argv[], + SConnection * pCon, SicsInterp * pSics) +{ + int i; + float fval; + + for(i = 0; i < self->dataUsed; i++){ + if(self->dataType[i] == FLOATTYPE){ + memcpy(&fval,self->data+i,sizeof(float)); + self->data[i] = (int)fval; + self->dataType[i] = INTTYPE; + } + } + SCSendOK(pCon); + return 1; +} +/*--------------------------------------------------------------------*/ static int copyToNode(pSICSData self, int argc, char *argv[], SConnection * pCon, SicsInterp * pSics) { @@ -1051,6 +1068,9 @@ int SICSDataAction(SConnection * pCon, SicsInterp * pSics, void *pData, } else if (strcmp(argv[1], "copytonode") == 0) { /*--------- copyTonode */ return copyToNode(self, argc - 2, &argv[2], pCon, pSics); + } else if (strcmp(argv[1], "intify") == 0) { + /*--------- copyTonode */ + return intify(self, argc - 2, &argv[2], pCon, pSics); } else if (strcmp(argv[1], "writezipped") == 0) { /*--------- writezipped */ if (argc < 3) { diff --git a/synchronize.c b/synchronize.c index 1ca717e8..b8212a48 100644 --- a/synchronize.c +++ b/synchronize.c @@ -228,7 +228,7 @@ tryagain: } pServ->simMode = 1; if (!test) { - SCWrite(pCon, "WARNING: sync server may not have exectued backup", + SCWrite(pCon, "WARNING: sync server may not have executed backup", eWarning); } @@ -268,8 +268,6 @@ tryagain: tell everybody that we have sync'ed */ ServerWriteGlobal("Simulation Server has SYNCHRONIZED!", eWarning); - ServerWriteGlobal("Fixed motors may not have correct positions", - eWarning); return 1; } diff --git a/test/testini.tcl b/test/testini.tcl index 56b96b54..2998ca98 100644 --- a/test/testini.tcl +++ b/test/testini.tcl @@ -33,6 +33,7 @@ ServerOption InterruptPort 2913 # The UDP port where the server will wait for Interrupts from clients. # Obviously, clients wishing to interrupt need to know this number. +ServerOption historylog $env(HOME)/src/workspace/sics/sim/tmp/comhistorytst.txt #--------------------------------------------------------------------------- # U S E R S @@ -527,6 +528,7 @@ amorhmsct poll /sics/amorhm/collapse 20 #source ../sim/mars/julcho.tcl +MakeSinq MakeSingleX singlex configure stt a4 @@ -648,9 +650,11 @@ if {$hmhttp == 1} { set simhm 1 #if {$simhm == 1} { source ../tcl/simhm.tcl - simhm::MakeSimHM simi 2 + simhm::MakeSimHM simi 3 tof # simhm::makeSecond simi singledet 30 - simi dim 64 64 + simi dim 64 64 5 + lappend tlist 10 20 30 40 50 + simi time_binning $tlist simi init #} @@ -711,16 +715,16 @@ proc testerr {input} { } -set slsecho 1 +set slsecho 0 if {$slsecho == 1} { -makesctcontroller echo testprot testprot.dat source ../tcl/stddrive.tcl source ../tcl/slsecho.tcl -#makesctcontroller slssct slsecho taspmagnet:5001 -makesctcontroller slssct slsecho localhost:8080 -slsecho::makeslsecho ma1 0 slssct +makesctcontroller slssct slsecho taspmagnet:5001 +#makesctcontroller slssct slsecho localhost:8080 +slsecho::makeslsecho ma1 5 slssct +#slsecho::makeslsecho ma3 2 slssct }