- Scriptcontext debugged to be working

- Added a drivable adapter to scriptcontext nodes
- Added subsampling to simulated histograms (and as a general option) in
  order to support Gumtree testing.
This commit is contained in:
koennecke
2008-06-09 08:57:53 +00:00
parent 3cb901b437
commit 0915491925
33 changed files with 1938 additions and 247 deletions

153
hmdata.c
View File

@ -16,10 +16,12 @@
#include "splitter.h"
#include "fortify.h"
#include "hmdata.h"
#include <nxdataset.h>
#include "HistMem.h"
#include "HistMem.i"
#include "HistDriv.i"
#include "countdriv.h"
#include "stptok.h"
/*----------------------------------------------------------------------*/
pHMdata makeHMData(void) {
pHMdata self = NULL;
@ -484,4 +486,155 @@ int loadHMData(pHMdata self, SConnection *pCon, char *filename){
fclose(fd);
return 1;
}
/*==========================================================================
* subsampling was stolen from the SinqHTTP histogram memory code and
* thus contains some additional indirections.
* =========================================================================*/
static pNXDS hmDataToNXDataset(pHMdata self){
pNXDS result = NULL;
int i;
result = malloc(sizeof(NXDS));
if(result == NULL){
return NULL;
}
memset(result,0,sizeof(NXDS));
result->magic = MAGIC;
result->type = NX_INT32;
result->rank = self->rank;
if(isInTOFMode(self)){
result->rank++;
}
result->dim = malloc(self->rank*sizeof(int));
if(result->dim == NULL){
free(result);
return NULL;
}
for(i = 0; i < self->rank; i++){
result->dim[i] = self->iDim[i];
}
if(isInTOFMode(self)){
result->dim[result->rank-1] = getNoOfTimebins(self);
}
if(self->localBuffer == NULL){
resizeBuffer(self);
}
result->u.iPtr = self->localBuffer;
return result;
}
/*---------------------------------------------------------------------------*/
static pNXDS subSampleCommand(pNXDS source, char *command,
char *error, int errLen){
int startDim[NX_MAXRANK], endDim[NX_MAXRANK];
int dim = 0, start = 0, i;
char *pPtr = NULL, token[80];
pPtr = stptok(command,token,79,":\0");
while((pPtr = stptok(pPtr,token,79,":\0")) != NULL){
if(start == 0){
startDim[dim] = atoi(token);
start = 1;
} else {
endDim[dim] = atoi(token);
start = 0;
dim++;
}
}
if(dim < source->rank - 1){
strncpy(error,"ERROR: Not enough border values specified for subsampling",errLen);
return NULL;
}
for(i = 0; i < source->rank; i++){
if(startDim[i] < 0 || startDim[i] >= source->dim[i]){
snprintf(error,errLen,"ERROR: invalid start value %d for dimension %d", startDim[1], i);
return NULL;
}
if(endDim[i] < startDim[i] || endDim[i] >= source->dim[i]){
snprintf(error,errLen,"ERROR: invalid end value %d for dimension %d", endDim[1], i);
return NULL;
}
}
return cutNXDataset(source,startDim,endDim);
}
/*-----------------------------------------------------------------------------*/
static pNXDS sumCommand(pNXDS source, char *command, char *error, int errlen){
int dimNo = -1, start = -1, end = -1;
char *pPtr = NULL;
char token[80];
pPtr = stptok(command,token,79,":\0");
pPtr = stptok(pPtr,token,79,":\0");
if(pPtr != NULL){
dimNo = atoi(token);
}
pPtr = stptok(pPtr,token,79,":\0");
if(pPtr != NULL){
start = atoi(token);
}
pPtr = stptok(pPtr,token,79,":\0");
if(pPtr != NULL){
end = atoi(token);
}
if(dimNo < 0 || dimNo > source->rank - 1){
snprintf(error,errlen,"ERROR: invalid dimension %d requestd to sum", dimNo);
return NULL;
}
if(end < 0 || end > source->dim[dimNo] || start < 0 || start > end){
snprintf(error,errlen,"ERROR: invalid summing limits %d to %d requested", start,end);
return NULL;
}
return sumNXDataset(source,dimNo, start, end);
}
/*--------------------------------------------------------------------------*/
HistInt *subSample(pHMdata self, char *command,
char *error, int errLen){
pNXDS source = NULL, start = NULL;
pNXDS result = NULL;
char *pPtr = NULL;
char subCommand[132];
HistInt *data = NULL;
int length;
start = hmDataToNXDataset(self);
if(start == NULL){
strncpy(error,"Out-Of-Memory or no data while subsampling ",
errLen);
return NULL;
}
source = start;
pPtr = command;
while((pPtr = stptok(pPtr,subCommand,131,";\0\r\n")) != NULL){
if(strstr(subCommand,"sample") != NULL){
result = subSampleCommand(source,subCommand,error, errLen);
} else if(strstr(subCommand,"sum") != NULL){
result = sumCommand(source,subCommand,error, errLen);
} else {
strncpy(error,"ERROR: invalid subcommand to process requested",errLen);
return NULL;
}
if(result == NULL){
return NULL;
}
if(source != start){
dropNXDataset(source);
}
source = result;
}
length = getNXDatasetLength(result);
data = malloc((length+1)*sizeof(int));
if(data == NULL){
strncpy(error,"Out-Of-Mmeory in Subsample", errLen);
dropNXDataset(result);
return NULL;
}
data[0] = length;
memcpy(data+1,result->u.iPtr, length*sizeof(int));
dropNXDataset(result);
return data;
}