- 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
This commit is contained in:
koennecke
2010-06-01 10:01:00 +00:00
parent eaf96b1893
commit 1ae7c0c2e2
19 changed files with 239 additions and 40 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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;
}

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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,6 +247,9 @@ int exeBufProcess(pExeBuf self, SicsInterp * pSics,
if (SCGetInterrupt(pCon) >= eAbortBatch) {
SCWrite(pCon, "ERROR: batch processing interrupted", eError);
SetStatus(eEager);
if (pCall != NULL) {
InvokeCallBack(pCall, BATCHEND, self->name);
}
return 0;
} else {
SCSetInterrupt(pCon, eContinue);

View File

@ -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);

View File

@ -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)) {

View File

@ -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.));

View File

@ -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,17 +97,10 @@ static int HMCStatus(void *pData, SConnection * pCon)
self = (pHMcontrol) pData;
assert(self);
if(self->checkSlaves == 0) {
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);
}
/*
Warning: this assumes that salves 1 - MAXSLAVE are histogram memories.
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.
*/
@ -105,7 +109,30 @@ static int HMCStatus(void *pData, SConnection * pCon)
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;
}
return status;
}

View File

@ -32,6 +32,7 @@ typedef struct {
float fPreset;
CounterMode eMode;
pICallBack pCall;
int checkSlaves;
} HMcontrol, *pHMcontrol;

42
macro.c
View File

@ -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

View File

@ -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];
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];
if(pCter->pDriv != NULL){
return pCter->pDriv->Get(pCter->pDriv, name, iCter, fVal);
} else {
return 0;
}
}
}
return 0;

View File

@ -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);

View File

@ -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) {

View File

@ -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;
}

View File

@ -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
}