From 877b46164b4c7e8aaf6e52ddf30153536b62daca Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Fri, 16 Feb 2007 09:46:51 +1100 Subject: [PATCH] Added option to get histograms from filesystem as well as from socket. Added: direct, hmdatapath, and scanpoint config parameters. r1492 | ffr | 2007-02-16 09:46:51 +1100 (Fri, 16 Feb 2007) | 3 lines --- site_ansto/anstohttp.c | 89 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 8 deletions(-) diff --git a/site_ansto/anstohttp.c b/site_ansto/anstohttp.c index f7765d65..202cc17d 100644 --- a/site_ansto/anstohttp.c +++ b/site_ansto/anstohttp.c @@ -21,6 +21,7 @@ #include #include #include +#include extern char *trim(char *); /*=================================================================== @@ -37,17 +38,19 @@ static char preset[] = {"/admin/presethm.egi"}; /*==================================================================== error codes ======================================================================*/ -#define BADURL -701 -#define HTTPERROR -702 -#define NOBODY -703 -#define BODYSHORT -704 +#define BADURL -701 +#define HTTPERROR -702 +#define NOBODY -703 +#define BODYSHORT -704 #define NOTIMPLEMENTED -705 -#define SERVERERROR -706 -#define BADSTATUS -707 -#define BADAUTH -708 +#define SERVERERROR -706 +#define BADSTATUS -707 +#define BADAUTH -708 +#define IMMEDFAIL -709 /*===================================================================== our driver private data structure ======================================================================*/ +#define MAXSTRLEN 512 typedef struct { ghttp_request *syncRequest; char hmAddress[512]; @@ -547,7 +550,60 @@ static int AnstoHttpGetData(pHistDriver self,SConnection *pCon){ return OKOK; } /*-------------------------------------------------------------------*/ -static int AnstoHttpGetHistogram(pHistDriver self, SConnection *pCon, +/** \brief Reads histogram data from a zipped file produced by the + * histogram memory server + * + * \param self (r) provides access to the histogram data structure + * \param bank number n maps to a HDS_Pn file. + */ +static int GetHMfromFile(pHistDriver self, SConnection *pCon, + int bank, int start, int end, HistInt *data){ + HistInt *hmdata; + pAnstoHttp pPriv = NULL; + int status, len, i, size; + int errMsgLen; + FILE *fp; + + char command[256]; + char hmDataPath[MAXSTRLEN]; + char DAQdir[MAXSTRLEN]; + char DSfilepath[MAXSTRLEN]; + char scanpoint[32]; + memset(command, 0, sizeof(command)); + memset(hmDataPath, 0, sizeof(hmDataPath)); + memset(DAQdir, 0, sizeof(DAQdir)); + memset(DSfilepath, 0, sizeof(DSfilepath)); + memset(scanpoint, 0, sizeof(scanpoint)); + + pPriv = (pAnstoHttp)self->pPriv; + assert(pPriv != NULL); + errMsgLen = sizeof(pPriv->hmError); + if (bank < 0) { + snprintf(pPriv->hmError,errMsgLen,"Negative bank numbers are not supported when reading from the filesystem"); + pPriv->errorCode = IMMEDFAIL; + return HWFault; + } + StringDictGet(self->pOption, "daq_dirname",DAQdir, sizeof(DAQdir)-1); + StringDictGet(self->pOption, "hmdatapath",hmDataPath, sizeof(hmDataPath)-1); + StringDictGet(self->pOption, "scanpoint",scanpoint, sizeof(scanpoint)-1); + snprintf(DSfilepath,sizeof(DSfilepath),"%s/%s/DATASET_%s/HDS_P%d",hmDataPath,DAQdir,scanpoint,bank); + + if ((fp=gzopen(DSfilepath, "rb")) == NULL) { + snprintf(pPriv->hmError,errMsgLen,"Failed to open hm data file for reading"); + pPriv->errorCode = IMMEDFAIL; + return HWFault; + } + size = end - start; + gzread(fp, data, size*sizeof(HistInt)); + data+=size; + start+=size; + gzclose(fp); + return OKOK; +} + +/**\brief Gets histogram data directly from the histogram memory http server. + */ +static int GetHMfromSocket(pHistDriver self, SConnection *pCon, int bank, int start, int end, HistInt *data){ char command[256]; HistInt *hmdata; @@ -627,6 +683,17 @@ static int AnstoHttpGetHistogram(pHistDriver self, SConnection *pCon, } return OKOK; } + +static int AnstoHttpGetHistogram(pHistDriver self, SConnection *pCon, + int bank, int start, int end, HistInt *data){ + char direct[2]; + + StringDictGet(self->pOption, "direct",direct, 2); + if (strcmp(direct,"1") == 0) + return GetHMfromSocket(self, pCon, bank, start, end, data); + else + return GetHMfromFile(self, pCon, bank, start, end, data); +} /*--------------------------------------------------------------------*/ static int AnstoHttpSetHistogram(pHistDriver self, SConnection *pCon, int bank, int start, int end, HistInt *data){ @@ -703,11 +770,17 @@ pHistDriver CreateAnstoHttpDriver(pStringDict pOption){ memset(pInternal,0,sizeof(anstoHttp)); pNew->pPriv = pInternal; pInternal->syncRequest = ghttp_request_new(); + memset(pInternal->hmError,0,sizeof(pInternal->hmError)); if(pInternal->syncRequest == NULL){ free(pNew); free(pInternal); return NULL; } + /* direct = 0 Get HM from data files + * direct = 1 Get HM from http server */ + StringDictAddPair(pOption, "direct", "1"); + StringDictAddPair(pOption, "hmdatapath", "../HMData"); + StringDictAddPair(pOption, "scanpoint", "0"); /* configure all those functions */