PSI update

r1464 | ffr | 2007-02-12 12:20:21 +1100 (Mon, 12 Feb 2007) | 2 lines
This commit is contained in:
Ferdi Franceschini
2007-02-12 12:20:21 +11:00
committed by Douglas Clowes
parent 634f2023b1
commit 3168325921
157 changed files with 29053 additions and 910 deletions

130
hmdata.c
View File

@@ -5,11 +5,15 @@
copyright: see file COPYRIGHT
Mark Koennecke, January 2003
Added loading HM data from file, Mark Koennecke, November 2006
-------------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <time.h>
#include "splitter.h"
#include "fortify.h"
#include "hmdata.h"
#include "HistMem.h"
@@ -46,7 +50,7 @@ void clearHMData(pHMdata self){
size *= self->iDim[i];
}
if(self->tofMode){
size *= self->nTimeChan;
size *= getNoOfTimebins(self);
}
memset(self->localBuffer,0,size*sizeof(HistInt));
}
@@ -60,7 +64,7 @@ static int resizeBuffer(pHMdata self){
size *= self->iDim[i];
}
if(self->tofMode){
size *= self->nTimeChan;
size *= getNoOfTimebins(self);
}
if(self->localBuffer != NULL){
free(self->localBuffer);
@@ -80,6 +84,7 @@ int configureHMdata(pHMdata self, pStringDict pOpt,
int status, i;
float fVal;
char pValue[80];
pHistMem master = NULL;
if(self->nTimeChan > 2) {
self->tofMode = 1;
@@ -111,6 +116,18 @@ int configureHMdata(pHMdata self, pStringDict pOpt,
self->updateIntervall = (int)rint(fVal);
}
status = StringDictGet(pOpt,"timeslave",pValue, 79);
if(status == 1) {
master = (pHistMem)FindCommandData(pServ->pSics,pValue,"HistMem");
if(master == NULL){
SCWrite(pCon,"ERROR: timeslave requested, but master HM not found",
eError);
} else {
self->timeslave = master->pDriv->data;
self->tofMode = 1;
}
}
/*
invalidate buffer
*/
@@ -138,7 +155,7 @@ int configureHMdata(pHMdata self, pStringDict pOpt,
int genTimeBinning(pHMdata self, float start, float step, int noSteps){
int i;
if(noSteps >= MAXCHAN){
if(noSteps >= MAXCHAN || self->timeslave != NULL){
return 0;
}
for(i = 0; i < noSteps; i++){
@@ -150,6 +167,10 @@ int genTimeBinning(pHMdata self, float start, float step, int noSteps){
}
/*----------------------------------------------------------------------*/
int setTimeBin(pHMdata self, int index, float value){
if(self->timeslave != NULL){
return 0;
}
if(index >= 0 && index < MAXCHAN){
self->timeBinning[index] = value;
} else {
@@ -157,7 +178,7 @@ int setTimeBin(pHMdata self, int index, float value){
}
self->tofMode = 1;
if(index > self->nTimeChan){
self->nTimeChan = index;
self->nTimeChan = index+1;
return resizeBuffer(self);
}
return 1;
@@ -168,17 +189,27 @@ int isInTOFMode(pHMdata self){
}
/*---------------------------------------------------------------------*/
int getNoOfTimebins(pHMdata self){
return self->nTimeChan;
if(self->timeslave != NULL){
return getNoOfTimebins(self->timeslave);
} else {
return self->nTimeChan;
}
}
/*---------------------------------------------------------------------*/
float *getTimeBinning(pHMdata self){
return self->timeBinning;
if(self->timeslave != NULL){
return getTimeBinning(self->timeslave);
} else {
return self->timeBinning;
}
}
/*-------------------------------------------------------------------*/
void clearTimeBinning(pHMdata self){
self->nTimeChan = 1;
self->tofMode = 0;
resizeBuffer(self);
if(self->timeslave == NULL){
self->nTimeChan = 1;
self->tofMode = 0;
resizeBuffer(self);
}
}
/*--------------------------------------------------------------------*/
void getHMDataDim(pHMdata self, int iDim[MAXDIM], int *rank){
@@ -193,7 +224,7 @@ long getHMDataLength(pHMdata self){
length *= self->iDim[i];
}
if(self->tofMode){
length *= self->nTimeChan;
length *= getNoOfTimebins(self);
}
return length;
}
@@ -227,6 +258,10 @@ static int updateHMbuffer(pHistMem hist, int bank, SConnection *pCon){
assert(self);
if(self->timeslave != NULL){
resizeBuffer(self);
}
for(i = 0; i < 3; i++){
status = hist->pDriv->GetHistogram(hist->pDriv,pCon,
bank,0,getHMDataLength(self),
@@ -292,7 +327,7 @@ HistInt *getHMDataBufferPointer(pHistMem hist,SConnection *pCon){
assert(self);
if(self->localBuffer == NULL){
if(self->localBuffer == NULL || self->timeslave != NULL){
resizeBuffer(self);
}
/*
@@ -327,7 +362,7 @@ long sumHMDataRectangle(pHistMem hist, SConnection *pCon,
int iStart[MAXDIM], int iEnd[MAXDIM]) {
HistInt *iData;
pHMdata self = hist->pDriv->data;
int i, iHistLength, status, iIndex;
int i, iHistLength, status, iIndex, myrank;
char pBueffel[256];
unsigned long lSum, lRowSum;
@@ -336,7 +371,12 @@ long sumHMDataRectangle(pHistMem hist, SConnection *pCon,
/*
error checking
*/
for(i = 0; i < self->rank; i++){
myrank = self->rank;
if(isInTOFMode(self)){
self->iDim[self->rank] = getNoOfTimebins(self);
myrank++;
}
for(i = 0; i < myrank; i++){
if( (iStart[i] < 0) || (iStart[i] > self->iDim[i]) ) {
sprintf(pBueffel,"ERROR: %d is out of data dimension range",
iStart[i]);
@@ -367,25 +407,35 @@ long sumHMDataRectangle(pHistMem hist, SConnection *pCon,
iHistLength = getHMDataLength(self);
/* actually sum */
switch(self->rank)
switch(myrank)
{
case 1:
lSum = SumRow(self->localBuffer, iHistLength,
iStart[0], iEnd[0]);
break;
case 2:
lSum = 0;
for(i = iStart[0]; i < iEnd[0]; i++){
iIndex = i*self->iDim[1];
lRowSum = SumRow(self->localBuffer,iHistLength,
if(isInTOFMode(self)){
lSum = 0;
for(i = iStart[0]; i < iEnd[0]; i++){
iIndex = i*self->iDim[1];
lRowSum = SumRow(self->localBuffer,iHistLength,
iIndex+iStart[1], iIndex+iEnd[1]);
lSum += lRowSum;
lSum += lRowSum;
}
} else {
lSum = 0;
for(i = iStart[1]; i < iEnd[1]; i++){
iIndex = i*self->iDim[0];
lRowSum = SumRow(self->localBuffer,iHistLength,
iIndex+iStart[0], iIndex+iEnd[0]);
lSum += lRowSum;
}
}
break;
default:
sprintf(pBueffel,
"ERROR: summing in %d dimensions not yet implemented",
self->rank);
myrank);
SCWrite(pCon,pBueffel,eError);
return -1;
break;
@@ -395,3 +445,43 @@ long sumHMDataRectangle(pHistMem hist, SConnection *pCon,
}
return lSum;
}
/*--------------------------------------------------------------------------*/
int loadHMData(pHMdata self, SConnection *pCon, char *filename){
FILE *fd = NULL;
char buffer[1024], pNumber[80], *pPtr;
long i = 0, length;
HistInt *data = NULL;
fd = fopen(filename,"r");
if(fd == NULL){
snprintf(buffer,1023,"ERROR: failed to open file %s", filename);
SCWrite(pCon,buffer,eError);
return 0;
}
length = getHMDataLength(self);
if(self->localBuffer == NULL || self->timeslave != NULL){
resizeBuffer(self);
}
data = self->localBuffer;
if(data == NULL){
SCWrite(pCon,"ERROR: failed to allocate HM", eError);
fclose(fd);
return 0;
}
while(i < length && fgets(buffer,1024,fd) != NULL){
pPtr = buffer;
while(pPtr != NULL){
pPtr = sicsNextNumber(pPtr,pNumber);
if(pPtr != NULL){
data[i] = atoi(pNumber);
i++;
}
}
}
if(i < length-1){
SCWrite(pCon,"WARNING: not enough data in file to fill HM",eWarning);
}
fclose(fd);
return 1;
}