- Fixed conflicts in ascon.c

- Supressed superfluous message from fmess
- Expanded multicounter to deal with threshold commands nicely
- Fixed an an issue with an uninitialized dummy connection in nserver
- Many changes to simidex to make it work in a more reliable way.
- Added hdbfactory path alias targetpath
- Extended frame to deal with sinqhttp HM
This commit is contained in:
koennecke
2009-03-09 08:28:08 +00:00
parent de4ca7a5e9
commit 10a475f020
21 changed files with 469 additions and 102 deletions

View File

@ -172,6 +172,7 @@ static void AsconConnect(Ascon * a)
return; return;
} }
int AsconReadGarbage(int fd) int AsconReadGarbage(int fd)
{ {
fd_set rmask; fd_set rmask;

View File

@ -30,6 +30,10 @@
#include "matrix/matrix.h" #include "matrix/matrix.h"
#include "cell.h" #include "cell.h"
#include "fourlib.h" #include "fourlib.h"
#include "counter.h"
#include "scanvar.h"
#include "scan.i"
#include "sdynar.h"
extern void SNXFormatTime(char *pBueffel, int iLen); extern void SNXFormatTime(char *pBueffel, int iLen);
@ -226,7 +230,6 @@ static int FourMessStart(pSICSOBJ self, SConnection * pCon,
priv->count = 0; priv->count = 0;
return 1; return 1;
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
static int FourMessScanPar(pSICSOBJ self, SConnection * pCon, static int FourMessScanPar(pSICSOBJ self, SConnection * pCon,
pHdb commandNode, pHdb par[], int nPar) pHdb commandNode, pHdb par[], int nPar)
@ -255,7 +258,52 @@ static int FourMessScanPar(pSICSOBJ self, SConnection * pCon,
} }
return 1; return 1;
} }
/*--------------------------------------------------------------------------*/
static int FourMessPrepareScan(pScanData self)
{
pVarEntry pVar = NULL;
void *pDings;
int i, iRet;
float fVal;
char pBueffel[512];
char pMessage[1024];
assert(self);
assert(self->pCon);
/* check boundaries of scan variables and allocate storage */
for (i = 0; i < self->iScanVar; i++) {
DynarGet(self->pScanVar, i, &pDings);
pVar = (pVarEntry) pDings;
if (pVar) {
iRet = CheckScanVar(pVar, self->pCon, self->iNP - 1);
if (!iRet) {
return 0;
}
InitScanVar(pVar);
} else {
SCWrite(self->pCon,
"WARNING: Internal error, no scan variable, I try to continue",
eLog);
}
pVar = NULL;
} /* end for */
/* configure counter */
SetCounterMode((pCounter) self->pCounterData, self->iMode);
SetCounterPreset((pCounter) self->pCounterData, self->fPreset);
self->iCounts = 0;
return 1;
}
/*-----------------------------------------------------------------------------*/
static int FourMessPrepareCmd(pSICSOBJ self, SConnection * pCon,
pHdb commandNode, pHdb par[], int nPar)
{
pFourMess priv = self->pPrivate;
return FourMessPrepareScan(priv->pScanner);
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
static hdbCallbackReturn SetScannerCB(pHdb node, void *userData, static hdbCallbackReturn SetScannerCB(pHdb node, void *userData,
pHdbMessage mm) pHdbMessage mm)
@ -780,6 +828,10 @@ void InstallFourMess(SConnection * pCon, SicsInterp * pSics)
AddSICSHdbPar(pNew->objectNode, "close", usUser, AddSICSHdbPar(pNew->objectNode, "close", usUser,
MakeSICSFunc(FourMessClose)); MakeSICSFunc(FourMessClose));
cmd =
AddSICSHdbPar(pNew->objectNode, "prepare", usUser,
MakeSICSFunc(FourMessPrepareCmd));
cmd = cmd =
AddSICSHdbPar(pNew->objectNode, "scanpar", usUser, AddSICSHdbPar(pNew->objectNode, "scanpar", usUser,
MakeSICSFunc(FourMessScanPar)); MakeSICSFunc(FourMessScanPar));

49
frame.c
View File

@ -19,19 +19,23 @@
#include "HistMem.h" #include "HistMem.h"
#include "HistMem.i" #include "HistMem.i"
#include "HistDriv.i" #include "HistDriv.i"
#include "hardsup/sinqhm.h" #include "psi/hardsup/sinqhm.h"
#include "sinqhmdriv.i" #include "psi/sinqhmdriv.i"
#include "nxdict.h" #include "nxdict.h"
#include "frame.h" #include "frame.h"
extern int isSINQHTTP(pHistDriver self);
/*======================================================================*/ /*======================================================================*/
static int readHMFrame(SConnection * pCon, pHistMem pHM, int nFrame) static int readHMFrame(SConnection * pCon, pHistMem pHM,
int nFrame, int sansflag)
{ {
HistInt *buffer = NULL; HistInt *buffer = NULL, *subbuf = NULL;
int iDim[MAXDIM], rank, length, status, i, noTimeBins; int iDim[MAXDIM], rank, length, status, i, noTimeBins;
pSINQHM pHist; pSINQHM pHist;
SinqHMDriv *pTata; SinqHMDriv *pTata;
const float *timeBin; const float *timeBin;
char histCommand[132];
/* /*
find dimensions and allocate data find dimensions and allocate data
*/ */
@ -56,17 +60,17 @@ static int readHMFrame(SConnection * pCon, pHistMem pHM, int nFrame)
buffer[0] = htonl(iDim[0]); buffer[0] = htonl(iDim[0]);
buffer[1] = htonl(iDim[1]); buffer[1] = htonl(iDim[1]);
if (nFrame < 0) {
nFrame = 0;
}
if (nFrame >= noTimeBins) {
nFrame = noTimeBins - 1;
}
if (isSINQHMDriv(pHM->pDriv) && noTimeBins > 2) { if (isSINQHMDriv(pHM->pDriv) && noTimeBins > 2) {
/* /*
read from HM. The 5 is PROJECT__FRAME in Sinqhm_def.h read from HM. The 5 is PROJECT__FRAME in Sinqhm_def.h
Again: be friendly: fix out of range frames Again: be friendly: fix out of range frames
*/ */
if (nFrame < 0) {
nFrame = 0;
}
if (nFrame >= noTimeBins) {
nFrame = noTimeBins - 1;
}
pTata = (SinqHMDriv *) pHM->pDriv->pPriv; pTata = (SinqHMDriv *) pHM->pDriv->pPriv;
pHist = (pSINQHM) pTata->pMaster; pHist = (pSINQHM) pTata->pMaster;
status = SINQHMProject(pHist, 0x0005, 0, nFrame, status = SINQHMProject(pHist, 0x0005, 0, nFrame,
@ -77,6 +81,21 @@ static int readHMFrame(SConnection * pCon, pHistMem pHM, int nFrame)
free(buffer); free(buffer);
return 0; return 0;
} }
} else if(isSINQHTTP(pHM->pDriv) && noTimeBins > 2){
if(sansflag){
snprintf(histCommand,132,"sample:0:%d:%d:%d", iDim[0]*iDim[1], nFrame, nFrame+1);
} else {
snprintf(histCommand,132,"sample:0:%d:0:%d:%d:%d", iDim[0], iDim[1], nFrame, nFrame+1);
}
if(pHM->pDriv->SubSample != NULL){
subbuf = pHM->pDriv->SubSample(pHM->pDriv, pCon,0,histCommand);
if(subbuf == NULL){
SCWrite(pCon,"ERROR: subsampling failed ", eError);
return 0;
}
memcpy(buffer+2,subbuf, length *sizeof(HistInt));
free(subbuf);
}
} else { } else {
/* /*
be friendly, just read the 2D data which is there be friendly, just read the 2D data which is there
@ -210,6 +229,7 @@ int PSDFrameAction(SConnection * pCon, SicsInterp * pSics, void *pData,
{ {
pHistMem pHM; pHistMem pHM;
int nFrame; int nFrame;
int sansflag; /* this is unique and special for the SANS at PSI */
if (argc < 2) { if (argc < 2) {
SCWrite(pCon, "ERROR: Insufficient number of arguments to PSDFrame", SCWrite(pCon, "ERROR: Insufficient number of arguments to PSDFrame",
@ -230,7 +250,12 @@ int PSDFrameAction(SConnection * pCon, SicsInterp * pSics, void *pData,
return 0; return 0;
} }
nFrame = atoi(argv[3]); nFrame = atoi(argv[3]);
return readHMFrame(pCon, pHM, nFrame); if(argc > 3 && (strcmp(argv[4],"sans") == 0) ){
sansflag = 1;
} else {
sansflag = 0;
}
return readHMFrame(pCon, pHM, nFrame, sansflag);
} else if (strcmp(argv[1], "file") == 0) { } else if (strcmp(argv[1], "file") == 0) {
if (argc < 6) { if (argc < 6) {
SCWrite(pCon, SCWrite(pCon,

View File

@ -931,13 +931,13 @@ int copyHdbValue(hdbValue * source, hdbValue * target)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int SendDataMessage(pHdb node, char *type, static int SendDataMessage(pHdb node, char *type,
hdbValue v, void *callData) hdbValue *v, void *callData)
{ {
hdbDataMessage dataMes; hdbDataMessage dataMes;
assert(type == set || type == get || type == update); assert(type == set || type == get || type == update);
dataMes.type = type; dataMes.type = type;
dataMes.v = &v; dataMes.v = v;
dataMes.callData = callData; dataMes.callData = callData;
return InvokeCallbackChain(node, (pHdbMessage) & dataMes); return InvokeCallbackChain(node, (pHdbMessage) & dataMes);
} }
@ -945,7 +945,7 @@ static int SendDataMessage(pHdb node, char *type,
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
int SetHipadabaPar(pHdb node, hdbValue v, void *callData) int SetHipadabaPar(pHdb node, hdbValue v, void *callData)
{ {
return SendDataMessage(node, set, v, callData); return SendDataMessage(node, set, &v, callData);
} }
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -953,7 +953,7 @@ int UpdateHipadabaPar(pHdb node, hdbValue v, void *callData)
{ {
int status; int status;
status = SendDataMessage(node, update, v, callData); status = SendDataMessage(node, update, &v, callData);
if (status == 1) { if (status == 1) {
copyHdbValue(&v, &node->value); copyHdbValue(&v, &node->value);
} }
@ -963,12 +963,12 @@ int UpdateHipadabaPar(pHdb node, hdbValue v, void *callData)
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
int NotifyHipadabaPar(pHdb node, void *callData) int NotifyHipadabaPar(pHdb node, void *callData)
{ {
SendDataMessage(node, update, node->value, callData); SendDataMessage(node, update, &node->value, callData);
return 1; return 1;
} }
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
int GetHipadabaPar(pHdb node, hdbValue * v, void *callData) int GetHipadabaPar(pHdb node, hdbValue *v, void *callData)
{ {
int status; int status;
@ -976,7 +976,7 @@ int GetHipadabaPar(pHdb node, hdbValue * v, void *callData)
v->doNotFree = 0; v->doNotFree = 0;
v->v.text = NULL; /* this sets all pointers in the union to NULL */ v->v.text = NULL; /* this sets all pointers in the union to NULL */
status = SendDataMessage(node, get, *v, callData); status = SendDataMessage(node, get, v, callData);
copyHdbValue(&node->value, v); copyHdbValue(&node->value, v);
if (status != 1) { if (status != 1) {
return status; return status;

1
lld.c
View File

@ -69,7 +69,6 @@ static int ListInit(int List, int ItemSize)
if (0 != ItemSize) { if (0 != ItemSize) {
/* create dummy head node /* create dummy head node
*/ */
(void)Fortify_CheckAllMemory();
Tmp = NODE_MALLOC(List); Tmp = NODE_MALLOC(List);
if (NULL == Tmp) { if (NULL == Tmp) {
return ERR_MEMORY; return ERR_MEMORY;

36
macro.c
View File

@ -1062,3 +1062,39 @@ int TransactAction(SConnection * pCon, SicsInterp * pSics, void *pData,
SCWrite(pCon, "TRANSACTIONFINISHED", eLog); SCWrite(pCon, "TRANSACTIONFINISHED", eLog);
return iRet; return iRet;
} }
/*-----------------------------------------------------------------------------*/
int CaptureAction(SConnection *pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
SConnection *comCon = NULL;
char buffer[1024];
char *command;
int status;
pDynString reply = NULL;
if (argc < 2) {
SCWrite(pCon, "ERROR: insufficient arguments to capture", eError);
return 0;
}
comCon = SCCopyConnection(pCon);
if (comCon == NULL) {
SCWrite(pCon, "EROOR: out of memory in capture", eError);
return 0;
}
memset(buffer, 0, sizeof(buffer));
command = Arg2Tcl(argc - 1, &argv[1], buffer, sizeof buffer);
if (!command) {
SCWrite(pCon, "ERROR: no more memory", eError);
return 0;
}
SCStartBuffering(comCon);
status = InterpExecute(pSics, comCon, command);
if (command != buffer)
free(command);
reply = SCEndBuffering(comCon);
SCWrite(pCon,GetCharArray(reply), eValue);
SCDeleteConnection(comCon);
return status;
}

View File

@ -37,6 +37,8 @@ int Broadcast(SConnection * pCon, SicsInterp * pInter, void *pData,
int argc, char *argv[]); int argc, char *argv[]);
int TransactAction(SConnection * pCon, SicsInterp * pSics, void *pData, int TransactAction(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[]); int argc, char *argv[]);
int CaptureAction(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[]);
int TclPublish(SConnection * pCon, SicsInterp * pInter, void *pData, int TclPublish(SConnection * pCon, SicsInterp * pInter, void *pData,
int argc, char *argv[]); int argc, char *argv[]);

View File

@ -35,7 +35,7 @@ SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \
savehdb.o statusfile.o sicshdbfactory.o proxy.o devser.o \ savehdb.o statusfile.o sicshdbfactory.o proxy.o devser.o \
moregress.o multicounter.o regresscter.o histregress.o \ moregress.o multicounter.o regresscter.o histregress.o \
sicshdbadapter.o polldriv.o sicspoll.o statemon.o hmslave.o \ sicshdbadapter.o polldriv.o sicspoll.o statemon.o hmslave.o \
nwatch.o asyncqueue.o asyncprotocol.o sicsobj.o \ nwatch.o asyncqueue.o asyncprotocol.o sicsobj.o frame.o\
nxcopy.o nxinterhelper.o nxinter_wrap.o genericcontroller.o nxstack.o \ nxcopy.o nxinterhelper.o nxinter_wrap.o genericcontroller.o nxstack.o \
sctdriveadapter.o sctdriveobj.o reflist.o singlex.o fourmess.o \ sctdriveadapter.o sctdriveobj.o reflist.o singlex.o fourmess.o \
sgclib.o sgfind.o sgio.o sgsi.o sghkl.o singlediff.o singlebi.o \ sgclib.o sgfind.o sgio.o sgsi.o sghkl.o singlediff.o singlebi.o \

View File

@ -608,6 +608,7 @@ pMotor SecMotorInit(char *name)
free(pM); free(pM);
return NULL; return NULL;
} }
/* TODO: give it a sicsdev here */
node = pM->pDescriptor->parNode; node = pM->pDescriptor->parNode;
pM->objectNode = node; pM->objectNode = node;
AppendHipadabaCallback(pM->pDescriptor->parNode, AppendHipadabaCallback(pM->pDescriptor->parNode,

View File

@ -14,6 +14,10 @@
* copyright: see file COPYRIGHT * copyright: see file COPYRIGHT
* *
* Mark Koennecke, September 2006 * Mark Koennecke, September 2006
*
* extended to forward parameter setting requests to the single counter driver
*
* Mark Koennecke, February 2009
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
@ -290,30 +294,68 @@ static void MMCCParameter(void *pData, float fPreset, CounterMode eMode)
} }
/*======================= Driver Interface ==============================*/ /*======================= Driver Interface ==============================*/
static int MultiCounterSet(struct __COUNTER *self, char *name, static int MultiCounterSet(struct __COUNTER *pCount, char *name,
int iCter, float fVal) int iCter, float fVal)
{ {
pDummy pDum;
int i;
pMultiCounter self = NULL;
pCounter pCter;
self = (pMultiCounter) pCount->pData;
assert(self);
return 0; for (i = 0; i < self->nSlaves; i++) {
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);
}
}
return 0;
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static int MultiCounterGet(struct __COUNTER *self, char *name, static int MultiCounterGet(struct __COUNTER *pCount, char *name,
int iCter, float *fVal) int iCter, float *fVal)
{ {
pDummy pDum;
int i;
pMultiCounter self = NULL;
pCounter pCter;
self = (pMultiCounter) pCount->pData;
assert(self);
return 0; for (i = 0; i < self->nSlaves; i++) {
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);
}
}
return 0;
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static int MultiCounterSend(struct __COUNTER *self, char *pText, static int MultiCounterSend(struct __COUNTER *pCount, char *pText,
char *reply, int replylen) char *reply, int replylen)
{ {
pDummy pDum;
int i;
pMultiCounter self = NULL;
pCounter pCter;
self = (pMultiCounter) pCount->pData;
assert(self);
strncpy(reply, "NOT Implemented", replylen); for (i = 0; i < self->nSlaves; i++) {
return 0; pDum = (pDummy)self->slaveData[i];
if(strcmp(pDum->pDescriptor->name, "SingleCounter") == 0){
pCter = (pCounter)self->slaveData[i];
return pCter->pDriv->Send(pCter->pDriv,pText, reply, replylen);
}
}
return 0;
} }
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
static int MultiCounterError(struct __COUNTER *pDriv, int *iCode, static int MultiCounterError(struct __COUNTER *pDriv, int *iCode,
char *error, int errlen) char *error, int errlen)

View File

@ -107,6 +107,8 @@ int InitServer(char *file, pServer * pServ)
/* interpreter */ /* interpreter */
self->pSics = InitInterp(); self->pSics = InitInterp();
self->dummyCon = SCCreateDummyConnection(self->pSics);
assert(self->dummyCon != NULL);
assert(self->pSics); assert(self->pSics);
/* initialise tasker */ /* initialise tasker */

1
ofac.c
View File

@ -217,6 +217,7 @@ static void InitIniCommands(SicsInterp * pInter, pTaskMan pTask)
AddCommand(pInter, "InternEval", InternalFileEval, NULL, NULL); AddCommand(pInter, "InternEval", InternalFileEval, NULL, NULL);
AddCommand(pInter, "ClientPut", ClientPut, NULL, NULL); AddCommand(pInter, "ClientPut", ClientPut, NULL, NULL);
AddCommand(pInter, "Capture", CaptureAction, NULL, NULL);
AddCommand(pInter, "GumPut", GumPut, NULL, NULL); AddCommand(pInter, "GumPut", GumPut, NULL, NULL);
AddCommand(pInter, "broadcast", Broadcast, NULL, NULL); AddCommand(pInter, "broadcast", Broadcast, NULL, NULL);
AddCommand(pInter, "transact", TransactAction, NULL, NULL); AddCommand(pInter, "transact", TransactAction, NULL, NULL);

View File

@ -305,7 +305,6 @@ static hdbCallbackReturn CommandSetCallback(pHdb node, void *userData,
} }
return hdbContinue; return hdbContinue;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static hdbCallbackReturn CommandGetCallback(pHdb node, void *userData, static hdbCallbackReturn CommandGetCallback(pHdb node, void *userData,
pHdbMessage message) pHdbMessage message)
@ -361,7 +360,106 @@ static int MakeCommandNode(pHdb parent, char *name, SConnection * pCon,
SCSendOK(pCon); SCSendOK(pCon);
return 1; return 1;
} }
/*---------------------------------------------------------------------------*/
static hdbCallbackReturn AliasSourceCallback(pHdb node, void *userData,
pHdbMessage message)
{
SConnection *pCon = NULL;
pHdb targetNode = NULL;
pHdbDataMessage mm;
if((mm = GetHdbSetMessage(message)) != NULL){
pCon = mm->callData;
targetNode = FindHdbNode(NULL,(char *)userData, pCon);
if(targetNode == NULL){
if(pCon != NULL){
SCPrintf(pCon,eError,"ERROR: link target %s not found, deleting link callbacks",
(char *)userData);
}
return hdbKill;
}
SetHipadabaPar(targetNode,*mm->v,pCon);
return hdbContinue;
}
if((mm = GetHdbGetMessage(message)) != NULL){
pCon = mm->callData;
targetNode = FindHdbNode(NULL,(char *)userData, pCon);
if(targetNode == NULL){
if(pCon != NULL){
SCPrintf(pCon,eError,"ERROR: link target %s not found, deleting link callbacks",
(char *)userData);
}
return hdbKill;
}
GetHipadabaPar(targetNode,mm->v,pCon);
copyHdbValue(mm->v,&node->value);
return hdbContinue;
}
return hdbContinue;
}
/*---------------------------------------------------------------------------*/
static hdbCallbackReturn AliasTargetCallback(pHdb node, void *userData,
pHdbMessage message)
{
SConnection *pCon = NULL;
pHdb targetNode = NULL;
pHdbDataMessage mm;
if((mm = GetHdbUpdateMessage(message)) != NULL){
pCon = mm->callData;
targetNode = FindHdbNode(NULL,(char *)userData, pCon);
if(targetNode == NULL){
if(pCon != NULL){
SCPrintf(pCon,eError,"ERROR: link source %s not found, deleting link callbacks",
(char *)userData);
}
return hdbKill;
}
UpdateHipadabaPar(targetNode,*mm->v,pCon);
return hdbContinue;
}
return hdbContinue;
}
/*--------------------------------------------------------------------------*/
static int MakeAliasNode(pHdb parent, char *name, SConnection *pCon,
int argc, char *argv[])
{
hdbValue v;
pHdb targetNode = NULL, child = NULL;
if(argc < 4){
SCWrite(pCon,"ERROR: hdbfactory alias needs 4 arguments, not enough supplied",
eError);
return 0;
}
targetNode = FindHdbNode(NULL,argv[3], pCon);
if(targetNode == NULL){
SCPrintf(pCon,eError,"ERROR: alias target %s not found",
argv[3]);
return 0;
}
child = MakeHipadabaNode(name,targetNode->value.dataType,
targetNode->value.arrayLength);
if(child == NULL){
SCWrite(pCon,"ERROR: out of memory in hdbfactory alias", eError);
return 0;
}
AppendHipadabaCallback(child,
MakeHipadabaCallback(AliasSourceCallback,
strdup(argv[3]),free));
AddHipadabaChild(parent,child, pCon);
AppendHipadabaCallback(targetNode,
MakeHipadabaCallback(AliasTargetCallback,
strdup(argv[1]),free));
SCSendOK(pCon);
return 1;
}
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int HdbNodeFactory(SConnection * pCon, SicsInterp * pSics, void *pData, int HdbNodeFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[]) int argc, char *argv[])
@ -390,6 +488,8 @@ int HdbNodeFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
return MakeScriptNode(parent, name, pCon, argc, argv); return MakeScriptNode(parent, name, pCon, argc, argv);
} else if (strcmp(argv[2], "link") == 0) { } else if (strcmp(argv[2], "link") == 0) {
return MakeLinkNode(parent, name, pCon, argc, argv); return MakeLinkNode(parent, name, pCon, argc, argv);
} else if (strcmp(argv[2], "alias") == 0) {
return MakeAliasNode(parent, name, pCon, argc, argv);
} else if (strcmp(argv[2], "command") == 0) { } else if (strcmp(argv[2], "command") == 0) {
return MakeCommandNode(parent, name, pCon, argc, argv); return MakeCommandNode(parent, name, pCon, argc, argv);
} else { } else {

View File

@ -198,7 +198,7 @@ static hdbCallbackReturn SICSSetUpdateCallback(pHdb node, void *userData,
return hdbContinue; return hdbContinue;
} }
status = UpdateHipadabaPar(node, *(mm->v), mm->callData); status = UpdateHipadabaPar(node, *(mm->v), mm->callData);
if (status) { if (status && mm->callData != NULL) {
SCSendOK(mm->callData); SCSendOK(mm->callData);
} }
return hdbContinue; return hdbContinue;

View File

@ -30,7 +30,7 @@
#define MAXCANDIDATES 20 #define MAXCANDIDATES 20
#define MAXREF 20 #define MAXREF 20
#define MAXIDX 20 #define MAXIDX 20
#define MAXSOLUTION 20 #define MAXSOLUTION 50
#define ABS(x) (x < 0 ? -(x) : (x)) #define ABS(x) (x < 0 ? -(x) : (x))
/*======================== types =============================*/ /*======================== types =============================*/
typedef struct { typedef struct {
@ -250,7 +250,10 @@ static int calcIndexes()
mink = -MAXIDX; mink = -MAXIDX;
minl = -MAXIDX; minl = -MAXIDX;
SetListMin_hkl(spgrp, MAXIDX, MAXIDX, &minh, &mink, &minl); SetListMin_hkl(spgrp, MAXIDX, MAXIDX, &minh, &mink, &minl);
for(i = 0; i < nReflections; i++){
reflections[i].nHKL = 0;
}
for (h = MAXIDX; h > -MAXIDX; h--) { for (h = MAXIDX; h > -MAXIDX; h--) {
for (k = MAXIDX; k > -MAXIDX; k--) { for (k = MAXIDX; k > -MAXIDX; k--) {
for (l = MAXIDX; l > -MAXIDX; l--) { for (l = MAXIDX; l > -MAXIDX; l--) {
@ -269,7 +272,14 @@ static int calcIndexes()
} }
} }
mat_free(B); mat_free(B);
return 1; status = 1;
for(i = 0; i < nReflections; i++){
if(reflections[i].nHKL < 1) {
SimIdxPrint(10,"Failed to find candidate indices for %4d", reflections[i].originalID);
status = 0;
}
}
return status;
} }
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
@ -346,13 +356,27 @@ static int areCoplanar(MATRIX v1, MATRIX v2, MATRIX v3)
} else { } else {
dot = .0; dot = .0;
} }
if (ABS(dot) > .00001) { if (ABS(dot) > .01) {
return 0; return 0;
} else { } else {
return 1; return 1;
} }
} }
/*-------------------------------------------------------------*/
static double calcCoplanar(MATRIX v1, MATRIX v2, MATRIX v3)
{
MATRIX norm;
double dot;
norm = vectorCrossProduct(v1, v2);
if (norm != NULL) {
dot = vectorDotProduct(norm, v3);
mat_free(norm);
} else {
dot = .0;
}
return ABS(dot);
}
/*-------------------------------------------------------------- /*--------------------------------------------------------------
* - We want the shortest vectors * - We want the shortest vectors
* - We do not want vectors at 180 to each other * - We do not want vectors at 180 to each other
@ -361,15 +385,17 @@ static int areCoplanar(MATRIX v1, MATRIX v2, MATRIX v3)
static int chooseTriplet(int triplet[3]) static int chooseTriplet(int triplet[3])
{ {
double angle, vol; double angle, vol;
int idx = 1; int idx = 1, coIdx = 0;
double coplanarVector[MAXREF], coMax = -9999999.99;
memset(coplanarVector,0,MAXREF*sizeof(double));
triplet[0] = 0; triplet[0] = 0;
/* /*
* test for 180 * test for 180
*/ */
while (idx < nReflections) { while (idx < nReflections) {
angle = angleBetweenScatVec(reflections[0].UVW, reflections[idx].UVW); angle = angleBetweenScatVec(reflections[0].UVW, reflections[idx].UVW);
if (angle < 160 && angle > -160) { if (angle < 140 && angle > -140) {
triplet[1] = idx; triplet[1] = idx;
break; break;
} }
@ -380,16 +406,28 @@ static int chooseTriplet(int triplet[3])
return 0; return 0;
} }
/*
* Try to find a reflection which is most out of the plane build by the first
* two. A good angular separation will give a better UB
*/
for (idx = 1; idx < nReflections; idx++) { for (idx = 1; idx < nReflections; idx++) {
if (idx != triplet[1]) { if (idx != triplet[1]) {
if (!areCoplanar(reflections[triplet[0]].UVW, coplanarVector[idx] = calcCoplanar(reflections[triplet[0]].UVW,
reflections[triplet[1]].UVW, reflections[triplet[1]].UVW,
reflections[idx].UVW)) { reflections[idx].UVW);
triplet[2] = idx;
return 1;
}
} }
} }
for(idx = 0; idx < nReflections; idx++){
if(coplanarVector[idx] > coMax){
coMax = coplanarVector[idx];
coIdx = idx;
}
}
if(coMax > .01){
triplet[2] = coIdx;
return 1;
}
SimIdxPrint(1, "ERROR: no three non coplanar reflections found"); SimIdxPrint(1, "ERROR: no three non coplanar reflections found");
return 0; return 0;
} }
@ -464,10 +502,9 @@ static int testRightHandedness(int r1, int r1idx,
vol = mat_det(T); vol = mat_det(T);
mat_free(T); mat_free(T);
if (vol > .0) { if (vol > .0) {
return 1;
} else {
return 0; return 0;
} }
return 1;
} }
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
@ -502,8 +539,12 @@ static void storeSolution(int r1, int r1idx,
} }
is.diff += diff; is.diff += diff;
solutions[nSolutions] = is; if(nSolutions < MAXSOLUTION){
nSolutions++; solutions[nSolutions] = is;
nSolutions++;
} else {
SimIdxPrint(10,"WARNING: more solutions then solution space");
}
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
@ -685,6 +726,7 @@ int SimIdxRun()
calcRefTheta(); calcRefTheta();
if (!calcIndexes()) { if (!calcIndexes()) {
SimIdxPrint(10,"ERROR: Problems finding candidate indices for reflections\nCannot continue\nCheck limits, cell and spacegroup");
return 0; return 0;
} }
@ -720,12 +762,18 @@ int SimIdxRun()
return status; return status;
} }
/*=========================== solution retrieval ===================*/ /*=========================== solution management ===================*/
int SimIdxGetNSolutions() int SimIdxGetNSolutions()
{ {
return nSolutions; return nSolutions;
} }
/*------------------------------------------------------------------*/
void SimIdxRemoveSolution(int id){
if(id >= 0 && id < nSolutions){
solutions[id] = solutions[nSolutions-1];
nSolutions--;
}
}
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
IndexSolution SimIdxGetSolution(int id) IndexSolution SimIdxGetSolution(int id)
{ {

View File

@ -4,7 +4,7 @@
* - Candidate indices are calculated from the lattice constants * - Candidate indices are calculated from the lattice constants
* - Permutations of the generated indices are changed for a couple * - Permutations of the generated indices are changed for a couple
* of conditions: * of conditions:
* -- Does the angle between the reflections matches the expectaions * -- Does the angle between the reflections matches the expectations
* -- Do the reflections form a right handed set * -- Do the reflections form a right handed set
* UB matrics matching these conditions are calculated and stored * UB matrics matching these conditions are calculated and stored
* for later retrieval. * for later retrieval.
@ -98,5 +98,12 @@ int SimIdxGetNSolutions();
* \return A IndexSolution structure * \return A IndexSolution structure
*/ */
IndexSolution SimIdxGetSolution(int id); IndexSolution SimIdxGetSolution(int id);
/**
* Remove the solution with the id given. This allows
* for solution filtering though upper level code. Please
* note that this changes the number of available solutions
* @param id The solution to remove
*/
void SimIdxRemoveSolution(int id);
#endif #endif

View File

@ -21,10 +21,9 @@ static void SicsOutFunc(void *data, char *text)
{ {
SConnection *pCon = (SConnection *) data; SConnection *pCon = (SConnection *) data;
if (pCon != NULL) { if (pCon != NULL) {
SCWrite(pCon, text, eWarning); SCWrite(pCon, text, eLog);
} }
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static hdbCallbackReturn SetSttLim(pHdb node, void *userData, static hdbCallbackReturn SetSttLim(pHdb node, void *userData,
pHdbMessage mm) pHdbMessage mm)
@ -54,16 +53,68 @@ static hdbCallbackReturn SetAngLim(pHdb node, void *userData,
} }
return hdbContinue; return hdbContinue;
} }
/*-----------------------------------------------------------------------*/
MATRIX calcUBForSolution(IndexSolution is, int *err)
{
pSingleDiff diffi;
pSICSOBJ reflist;
int i;
MATRIX UB;
double hkl[3];
diffi = SXGetDiffractometer();
reflist = SXGetReflectionList();
assert(reflist != NULL && diffi != NULL);
for (i = 0; i < 3; i++) {
if (is.originalID[i] != 999) {
hkl[0] = (double) is.h[i];
hkl[1] = (double) is.k[i];
hkl[2] = (double) is.l[i];
SetRefIndex(reflist, is.originalID[i], hkl);
}
}
if (is.originalID[2] == 999) {
UB = diffi->calcUBFromTwo(diffi, GetRefName(reflist, is.originalID[0]),
GetRefName(reflist, is.originalID[1]), err);
} else {
UB = diffi->calcUBFromThree(diffi,
GetRefName(reflist, is.originalID[0]),
GetRefName(reflist, is.originalID[1]),
GetRefName(reflist, is.originalID[2]),
err);
}
return UB;
}
/*-----------------------------------------------------------------------*/
static void filterSolutions(){
int i, err;
IndexSolution is;
MATRIX UB;
for(i = 0; i < SimIdxGetNSolutions(); i++){
is = SimIdxGetSolution(i);
if(is.originalID[0] != -999){
UB = calcUBForSolution(is,&err);
if(UB != NULL){
mat_free(UB);
} else {
SimIdxRemoveSolution(i);
i--;
}
}
}
}
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static int RunIndexCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode, static int RunIndexCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode,
pHdb par[], int nPar) pHdb par[], int nPar)
{ {
int i, j, status; int i, j, status, err;
pSingleDiff diffi; pSingleDiff diffi;
pSICSOBJ reflist; pSICSOBJ reflist;
double ang[4], z1[3]; double ang[4], z1[3];
IndexSolution is; IndexSolution is;
MATRIX ub;
SimIdxSetLambda(SXGetLambda()); SimIdxSetLambda(SXGetLambda());
SimIdxSetCell((double *) SXGetCell()); SimIdxSetCell((double *) SXGetCell());
@ -78,29 +129,37 @@ static int RunIndexCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode,
diffi->calcZ1(diffi, GetRefName(reflist, i), z1); diffi->calcZ1(diffi, GetRefName(reflist, i), z1);
SimIdxAddReflection(z1); SimIdxAddReflection(z1);
} }
status = SimIdxRun(); status = SimIdxRun();
filterSolutions();
if (status == 1) { if (status == 1) {
if (SimIdxGetNSolutions() < 1) { if (SimIdxGetNSolutions() < 1) {
SCWrite(pCon, "No solutions were found", eWarning); SCWrite(pCon, "No solutions were found", eLog);
return 0; return 0;
} }
SCWrite(pCon, "Indexing Suggestions:", eWarning); SCWrite(pCon, "Indexing Suggestions:", eLog);
for (i = 0; i < SimIdxGetNSolutions(); i++) { for (i = 0; i < SimIdxGetNSolutions(); i++) {
is = SimIdxGetSolution(i); is = SimIdxGetSolution(i);
SCPrintf(pCon, eWarning, "Solution No : %d, GOF = %6.3f", i, SCPrintf(pCon, eLog, "Solution No : %d, GOF = %6.3f", i,
is.diff * 100); is.diff * 100);
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {
if (is.originalID[j] != 999) { if (is.originalID[j] != 999) {
SCPrintf(pCon, eWarning, " Ref = %2d, HKL = %4d %4d %4d ", SCPrintf(pCon, eLog, " Ref = %2d, HKL = %4d %4d %4d ",
is.originalID[j], is.h[j], is.k[j], is.l[j]); is.originalID[j], is.h[j], is.k[j], is.l[j]);
} }
} }
SCPrintf(pCon,eLog," UB:");
ub = calcUBForSolution(is,&err);
if(ub != NULL) { /* should never happen, as filtered */
for(j = 0; j < 3; j++){
SCPrintf(pCon, eLog," %8.5f %8.5f %8.5f",
ub[j][0], ub[j][1], ub[j][2]);
}
}
} }
} }
return status; return status;
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static int ChooseCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode, static int ChooseCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode,
pHdb par[], int nPar) pHdb par[], int nPar)
@ -108,9 +167,7 @@ static int ChooseCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode,
MATRIX UB; MATRIX UB;
int err, solution, i; int err, solution, i;
IndexSolution is; IndexSolution is;
double hkl[3], ub[9]; double ub[9];
pSICSOBJ reflist;
pSingleDiff diffi;
if (nPar < 1) { if (nPar < 1) {
SCWrite(pCon, "ERROR: need the solution number as argument", eError); SCWrite(pCon, "ERROR: need the solution number as argument", eError);
@ -123,30 +180,9 @@ static int ChooseCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode,
return 0; return 0;
} }
is = SimIdxGetSolution(i); is = SimIdxGetSolution(solution);
reflist = SXGetReflectionList(); UB = calcUBForSolution(is,&err);
diffi = SXGetDiffractometer();
assert(reflist != NULL);
assert(diffi != NULL);
for (i = 0; i < 3; i++) {
if (is.originalID[i] != 999) {
hkl[0] = (double) is.h[i];
hkl[1] = (double) is.k[i];
hkl[2] = (double) is.l[i];
SetRefIndex(reflist, is.originalID[i], hkl);
}
}
if (is.originalID[2] == 999) {
UB = diffi->calcUBFromTwo(diffi, GetRefName(reflist, is.originalID[0]),
GetRefName(reflist, is.originalID[1]), &err);
} else {
UB = diffi->calcUBFromThree(diffi,
GetRefName(reflist, is.originalID[0]),
GetRefName(reflist, is.originalID[1]),
GetRefName(reflist, is.originalID[2]),
&err);
}
if (UB == NULL) { if (UB == NULL) {
switch (err) { switch (err) {
case REFERR: case REFERR:
@ -181,7 +217,6 @@ static int ChooseCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode,
SCSendOK(pCon); SCSendOK(pCon);
return 1; return 1;
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static int DiraxCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode, static int DiraxCmd(pSICSOBJ self, SConnection * pCon, pHdb commandNode,
pHdb par[], int nPar) pHdb par[], int nPar)

View File

@ -85,14 +85,15 @@ static int calculateNBSettings(pSingleDiff self,
if (status != 1) { if (status != 1) {
return 0; return 0;
} }
if(om > 180.){
om -= 360;
} else if (om < -180.){
om += 360.;
}
if (checkNormalBeam(om, &gamma, nu, settings, self)) { if (checkNormalBeam(om, &gamma, nu, settings, self)) {
return 1; return 1;
} else { } else {
if (checkNormalBeam(om + 360., &gamma, nu, settings, self)) {
return 1;
} else {
return 0; return 0;
}
} }
return 0; return 0;
} }

View File

@ -710,8 +710,11 @@ const double *SXGetUB()
void SXSetUB(double ub[9]) void SXSetUB(double ub[9])
{ {
pHdb node = NULL; pHdb node = NULL;
pSingleX priv = (pSingleX) singlex->pPrivate;
if(singlex == NULL){
return;
}
pSingleX priv = (pSingleX) singlex->pPrivate;
node = GetHipadabaNode(singlex->objectNode, "ub"); node = GetHipadabaNode(singlex->objectNode, "ub");
assert(node != NULL); assert(node != NULL);
SetHipadabaPar(node, MakeHdbFloatArray(9, ub), NULL); SetHipadabaPar(node, MakeHdbFloatArray(9, ub), NULL);
@ -777,12 +780,15 @@ void SXSetCell(double cell[6])
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
double SXGetLambda() double SXGetLambda()
{ {
pSingleX priv = (pSingleX) singlex->pPrivate;
pSicsVariable lam = NULL; pSicsVariable lam = NULL;
float val; float val;
hdbValue v; hdbValue v;
pHdb node = NULL; pHdb node = NULL;
if(singlex == NULL){
return -99.9;
}
pSingleX priv = (pSingleX) singlex->pPrivate;
if (priv->lambdaDriv != NULL) { if (priv->lambdaDriv != NULL) {
return priv->lambdaDriv->GetValue(priv->lambdaVar, pServ->dummyCon); return priv->lambdaDriv->GetValue(priv->lambdaVar, pServ->dummyCon);
} else if (priv->lambdaVar != NULL) { } else if (priv->lambdaVar != NULL) {
@ -792,7 +798,7 @@ double SXGetLambda()
} }
node = GetHipadabaNode(singlex->objectNode, "lambda"); node = GetHipadabaNode(singlex->objectNode, "lambda");
assert(node != NULL); assert(node != NULL);
GetHipadabaPar(node, &v, NULL); GetHipadabaPar(node, &v, pServ->dummyCon);
return v.v.doubleValue; return v.v.doubleValue;
} }
@ -820,16 +826,20 @@ T_SgInfo *SXGetSpaceGroup()
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
pSingleDiff SXGetDiffractometer() pSingleDiff SXGetDiffractometer()
{ {
pSingleX priv = (pSingleX) singlex->pPrivate;
const double *cell, *ub; const double *cell, *ub;
double lambda; double lambda;
int i; int i;
/* Not initialized. /* Not initialized.
* Trouble is motors need to be configured first, the we can set a diffractometer. * Trouble is motors need to be configured first, the we can set a diffractometer.
* If this is ever triggered, the most likely cause is that no mode was selected in the * If this is ever triggered, the most likely cause is that no mode was selected in the
* initialisation file. * initialisation file.
*/ */
if(singlex == NULL){
return NULL;
}
pSingleX priv = (pSingleX) singlex->pPrivate;
if (priv->diffractometer->calculateSettings == NULL) { if (priv->diffractometer->calculateSettings == NULL) {
return NULL; return NULL;
} }
@ -851,6 +861,9 @@ void SXSetMode(SingleXModes m)
{ {
pHdb node = NULL; pHdb node = NULL;
if(singlex == NULL){
return;
}
node = GetHipadabaNode(singlex->objectNode, "mode"); node = GetHipadabaNode(singlex->objectNode, "mode");
assert(node != NULL); assert(node != NULL);

View File

@ -1083,6 +1083,8 @@ int StandardScanWrapper(SConnection * pCon, SicsInterp * pSics,
return WriteHeader(self); return WriteHeader(self);
} else if (strcmp(argv[1], "prepare") == 0) { } else if (strcmp(argv[1], "prepare") == 0) {
return PrepareScan(self); return PrepareScan(self);
} else if (strcmp(argv[1], "noncheckprepare") == 0) {
return NonCheckPrepare(self);
} else if (strcmp(argv[1], "finish") == 0) { } else if (strcmp(argv[1], "finish") == 0) {
return 1; return 1;
} }

View File

@ -114,7 +114,7 @@ static int GetSimPos(pVelSelDriv self, float *fPos)
assert(self); assert(self);
if (SimRandom() < FAILURE) { if (SimRandom() < FAILURE) {
*fPos = SimRandom(); *fPos = SimRandom();
return HWFault; return VELOFAIL;
} }
pDriv = (pSimi) self->pPrivate; pDriv = (pSimi) self->pPrivate;
@ -127,9 +127,9 @@ static int GetSimPos(pVelSelDriv self, float *fPos)
} else { } else {
*fPos = pDriv->fPos; *fPos = pDriv->fPos;
} }
return OKOK; return VELOOK;
} }
return OKOK; return VELOOK;
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/