- Added bridge functions to histmemsec to make it look more like histmem

- Modifed many modules using histmem to work also with histmemsec
- Extended tasker with task names and task groups
- There is a new taskobj which allows to list tasks and to interact with them.
- Task now supports running Tcl functions as tasks
- There is a new experimental sctcomtask module which allows to define communication
  tasks against a scriptcontext. This is a new feature which should facilitate
  writing sequential scripts using asynchronous communication.
- A fix to make spss7 work when there are no switches
- ORION support for single X. TRICS measures crystals hanging down, ORION
  standing up


SKIPPED:
	psi/ease.c
	psi/faverage.c
	psi/jvlprot.c
	psi/make_gen
	psi/pardef.c
	psi/polterwrite.c
	psi/psi.c
	psi/sinq.c
	psi/spss7.c
This commit is contained in:
koennecke
2012-12-20 11:32:33 +00:00
parent 4f560552c4
commit 86e246416b
57 changed files with 2025 additions and 290 deletions

View File

@ -10,10 +10,17 @@
* copyright: see file COPYRIGHT
*
* Mark Koennecke, May 2009
*
* Added bridging routines implementing first gen HM interfaces
*
* Mark Koennecke, December 2012
*/
#include <sics.h>
#include <sicshipadaba.h>
#include <counter.h>
#include "HistMem.h"
#include "HistMem.i"
#include "arrayutil.h"
#define CONFIG 1005
@ -82,6 +89,45 @@ static int ResetCmd(pSICSOBJ ccmd, SConnection * pCon,
return 1;
}
/*--------------------------------------------------------------------------*/
static int NoTimeBinCmd(pSICSOBJ ccmd, SConnection * pCon,
Hdb * cmdNode, Hdb * par[], int nPar)
{
pHdb timeNode = NULL;
timeNode = GetHipadabaNode(ccmd->objectNode,"time_binning");
if(timeNode == NULL){
SCWrite(pCon,"ERROR: HM has no time binning",eError);
return 0;
}
SCPrintf(pCon,eValue,"%s.totimebin = %d", ccmd->objectNode->name,
timeNode->value.arrayLength);
return 1;
}
/*--------------------------------------------------------------------------*/
static int TimebinsCmd(pSICSOBJ ccmd, SConnection * pCon,
Hdb * cmdNode, Hdb * par[], int nPar)
{
pHdb timeNode = NULL;
pDynString data= NULL;
timeNode = GetHipadabaNode(ccmd->objectNode,"time_binning");
if(timeNode == NULL){
SCWrite(pCon,"ERROR: HM has no time binning",eError);
return 0;
}
data = formatValue(timeNode->value,timeNode);
if(data != NULL){
SCPrintf(pCon,eValue,"%s.timebins = %s", ccmd->objectNode->name,
GetCharArray(data));
DeleteDynString(data);
} else {
SCWrite(pCon,"ERROR: out of memory formatting timebins", eError);
return 0;
}
return 1;
}
/*--------------------------------------------------------------------------*/
static int GenbinCmd(pSICSOBJ ccmd, SConnection * pCon,
Hdb * cmdNode, Hdb * par[], int nPar)
{
@ -124,6 +170,96 @@ static int GenbinCmd(pSICSOBJ ccmd, SConnection * pCon,
return 1;
}
/*--------------------------------------------------------------------------*/
static int ConfigureCmd(pSICSOBJ ccmd, SConnection * pCon,
Hdb * cmdNode, Hdb * par[], int nPar)
{
pHdb dimNode = NULL;
if(nPar < 1) {
SCWrite(pCon,"ERROR: need a parameter to read", eError);
return 0;
}
dimNode = GetHipadabaNode(ccmd->objectNode,"dim");
assert(dimNode != NULL);
if(strcmp(par[0]->value.v.text,"dim0") == 0){
SCPrintf(pCon,eValue,"%s.dim0 = %d", ccmd->objectNode->name,
dimNode->value.v.intArray[0]);
} else if(strcmp(par[0]->value.v.text,"dim1") == 0){
SCPrintf(pCon,eValue,"%s.dim1 = %d", ccmd->objectNode->name,
dimNode->value.v.intArray[1]);
} else {
SCPrintf(pCon,eError,"ERROR: subcommand %s to configure not found",
par[0]->value.v.text);
return 0;
}
return 1;
}
/*--------------------------------------------------------------------------*/
static int SumCmd(pSICSOBJ ccmd, SConnection * pCon,
Hdb * cmdNode, Hdb * par[], int nPar)
{
pHdb dimNode = NULL, dataNode = NULL;
int xstart, xend, ystart, yend, i;
long lSum;
dimNode = GetHipadabaNode(ccmd->objectNode,"dim");
dataNode = GetHipadabaNode(ccmd->objectNode,"data");
assert(dimNode != NULL && dataNode != NULL);
switch(dimNode->value.arrayLength){
case 1:
if(nPar < 2) {
SCWrite(pCon,"ERROR: need start and end for summing 1D data",eError);
return 0;
}
xstart = par[0]->value.v.intValue;
xend = par[1]->value.v.intValue;
if(xstart < 0){
xstart = 0;
}
if(xend > dataNode->value.arrayLength){
xend = dataNode->value.arrayLength;
}
for(i = xstart; i < xend; i++){
lSum += dataNode->value.v.intArray[i];
}
SCPrintf(pCon,eValue,"%s.sum = %ld", ccmd->objectNode->name, lSum);
break;
case 2:
if(nPar < 4) {
SCWrite(pCon,"ERROR: need start and end in x and y for summing 2D data",eError);
return 0;
}
xstart = par[0]->value.v.intValue;
xend = par[1]->value.v.intValue;
if(xstart < 0){
xstart = 0;
}
if(xend > dimNode->value.v.intArray[0]){
xend = dimNode->value.v.intArray[0];
}
ystart = par[2]->value.v.intValue;
yend = par[3]->value.v.intValue;
if(ystart < 0){
ystart = 0;
}
if(yend > dimNode->value.v.intArray[1]){
yend = dimNode->value.v.intArray[1];
}
lSum = sumWindow(dataNode->value.v.intArray, xstart,xend,dimNode->value.v.intArray[0],
ystart, yend, dimNode->value.v.intArray[1]);
SCPrintf(pCon,eValue,"%s.sum = %ld", ccmd->objectNode->name, lSum);
default:
SCPrintf(pCon,eError, "ERROR: summing not supported for %s dimensional data",
dimNode->value.arrayLength);
return 0;
}
return 1;
}
/*--------------------------------------------------------------------------*/
static int InitCmd(pSICSOBJ ccmd, SConnection * con,
Hdb * cmdNode, Hdb * par[], int nPar)
{
@ -228,24 +364,34 @@ int MakeSecHM(SConnection * pCon, SicsInterp * pSics, void *pData,
child = AddSICSHdbPar(node,"init", usMugger, MakeSICSFunc(InitCmd));
child = AddSICSHdbPar(node,"sum", usSpy, MakeSICSFunc(SumCmd));
AddSICSHdbPar(child, "xstart", usSpy, MakeHdbInt(0));
AddSICSHdbPar(child, "xend", usSpy, MakeHdbInt(0));
AddSICSHdbPar(child, "ystart", usSpy, MakeHdbInt(0));
AddSICSHdbPar(child, "yend", usSpy, MakeHdbInt(0));
/*
* test TOF option
*/
if(argc > 3){
if(strcmp(argv[3],"tof") == 0){
child = MakeSICSHdbPar("time_binning", usMugger, makeHdbValue(HIPFLOATVARAR,100));
if (child == NULL) {
return 0;
}
AddHipadabaChild(node, child, NULL);
AppendHipadabaCallback(child,
MakeHipadabaCallback(HMTOFCallback, NULL, NULL));
if(strcmp(argv[3],"tof") == 0){
child = MakeSICSHdbPar("time_binning", usMugger, makeHdbValue(HIPFLOATVARAR,100));
if (child == NULL) {
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.));
AddSICSHdbPar(child, "np", usMugger, MakeHdbInt(10));
}
child = AddSICSHdbPar(node,"genbin", usMugger, MakeSICSFunc(GenbinCmd));
AddSICSHdbPar(child, "start", usMugger, MakeHdbFloat(10.));
AddSICSHdbPar(child, "step", usMugger, MakeHdbFloat(10.));
AddSICSHdbPar(child, "np", usMugger, MakeHdbInt(10));
child = AddSICSHdbPar(node,"notimebin", usSpy, MakeSICSFunc(NoTimeBinCmd));
child = AddSICSHdbPar(node,"timebins", usSpy, MakeSICSFunc(TimebinsCmd));
}
}
status =
@ -257,3 +403,99 @@ int MakeSecHM(SConnection * pCon, SicsInterp * pSics, void *pData,
}
return 1;
}
/*===========================================================================
This is a set of adapter functions which make the second gen HM look like
a first generation one. This saves me from rewriting all the calculation codes
based on the first gen HM
!!!! BEWARE: In the functions below pHistMem should never be a pointer to a
HistMem but rather a second generation HM which is a counter object !!!!
===============================================================================*/
const float *GetSecHistTimeBin(pHistMem self, int *iLength)
{
float *tb = NULL;
pHdb tbNode = NULL;
int i;
pCounter pCter;
assert(self->pDes->parNode != NULL);
pCter = (pCounter)self;
tbNode = GetHipadabaNode(self->pDes->parNode,"time_binning");
if(tbNode == NULL){
return NULL;
}
*iLength = tbNode->value.arrayLength;
if(*iLength != pCter->tbLength){
if(pCter->timeBinning){
free(pCter->timeBinning);
}
pCter->timeBinning = malloc(*iLength*sizeof(float));
}
for(i = 0; i < *iLength; i++){
pCter->timeBinning[i] = tbNode->value.v.floatArray[i];
}
return (const float*)pCter->timeBinning;
}
/*---------------------------------------------------------------------------*/
HistInt *GetSecHistogramPointer(pHistMem self,SConnection *pCon)
{
pHdb dataNode = NULL;
assert(self->pDes->parNode != NULL);
dataNode = GetHipadabaNode(self->pDes->parNode,"data");
if(dataNode == NULL){
return NULL;
}
return (HistInt *)dataNode->value.v.intArray;
}
/*--------------------------------------------------------------------------*/
int GetSecHistogram(pHistMem self, SConnection *pCon,
int i,int iStart, int iEnd, HistInt *lData, int iDataLen)
{
pHdb dataNode = NULL;
assert(self->pDes->parNode != NULL);
dataNode = GetHipadabaNode(self->pDes->parNode,"data");
if(dataNode == NULL){
return 0;
}
if(iEnd > dataNode->value.arrayLength){
iEnd = dataNode->value.arrayLength;
}
if ((iEnd - iStart) > iDataLen / sizeof(HistInt)) {
SCWrite(pCon, "WARNING: truncating request to fit data space",
eWarning);
iEnd = (iDataLen / sizeof(HistInt)) - 1;
}
memcpy(lData,dataNode->value.v.intArray+iStart, (iEnd-iStart)*sizeof(int));
return 1;
}
/*-------------------------------------------------------------------------*/
void SecHistDirty(pHistMem self)
{
/* Nothing to do */
}
/*-------------------------------------------------------------------------*/
int GetSecHistLength(pHistMem self)
{
pHdb dataNode = NULL;
int i, length = 1;
assert(self->pDes->parNode != NULL);
dataNode = GetHipadabaNode(self->pDes->parNode,"dim");
if(dataNode == NULL){
return 0;
}
for(i = 0; i < dataNode->value.arrayLength; i++){
length *= dataNode->value.v.intArray[i];
}
return length;
}