From d2958eb0a442fc25bdcf7a3e4b1fe1f639dfaedd Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Thu, 5 Dec 2013 14:51:29 +0000 Subject: [PATCH] single photon writer updated git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@706 951219d9-93cf-4727-9268-0efd64621fa3 --- .../singlePhotonFilter.cpp | 57 ++++++++++++------- .../slsDetectorAnalysis/singlePhotonFilter.h | 15 +---- .../slsDetectorAnalysis/single_photon_hit.h | 43 ++++++++++++++ 3 files changed, 84 insertions(+), 31 deletions(-) create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/single_photon_hit.h diff --git a/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp b/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp index 7c9cddab4..47eb1b389 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp @@ -58,14 +58,17 @@ singlePhotonFilter::singlePhotonFilter(int nx, int ny, totalFramesCaught(tfcaught), framesCaught(fcaught), currentframenum(cframenum), - freeFifoCallBack(NULL), + freeFifoCallBack(NULL), pFreeFifo(NULL){ -#ifndef MYROOT1 - photonHitList = new single_photon_hit[nChannelsX*nChannelsY]; -#endif //cluster - if (nChannelsX) - nClusterX = 1; + if (nChannelsX) + nClusterX = 1; + +#ifndef MYROOT1 + //photonHitList=(single_photon_hit**) (new int*[nChannelsX*nChannelsY/(nClusterX*nClusterY)*1000]); + photonHitList=new single_photon_hit*[nChannelsX*nChannelsY/(nClusterX*nClusterY)*1000]; +#endif + sqrtCluster = sqrt(nClusterX*nClusterY); deltaX = nClusterX/2;// 0 or 1 clusterCenterPixel = (deltaX * nClusterY) + 1; @@ -74,8 +77,8 @@ singlePhotonFilter::singlePhotonFilter(int nx, int ny, stat = new movingStat[nChannelsX*nChannelsY]; nHitStat = new movingStat(); - myPhotonHit = new single_photon_hit; - myPhotonHit->data = new double[nClusterX*nClusterY]; + myPhotonHit = new single_photon_hit(nClusterX,nClusterY); + // myPhotonHit->data = new double[nClusterX*nClusterY]; myPhotonHit->x = 0; myPhotonHit->y = 0; myPhotonHit->rms = 0; @@ -221,8 +224,16 @@ int singlePhotonFilter::writeToFile(){ cout << "ERROR: Could not write to " << nHitsPerFrame << " hits to file as file or tree doesnt exist" << endl; #else if(myFile){ + int ii; /*cout<<"writing "<< nHitsPerFrame << " hits to file" << endl;*/ - fwrite((void*)(photonHitList), 1, sizeof(single_photon_hit)*nHitsPerFrame, myFile); + for (ii=0; iiwrite(myFile); + delete photonHitList[ii]; + } + delete photonHitList[ii]; + + + // fwrite((void*)(photonHitList), 1, sizeof(single_photon_hit)*nHitsPerFrame, myFile); /*framesInFile += nHitsPerFrame;*/ nHitsPerFrame = 0; //cout<<"Exiting writeToFile"<data; //for each pixel for (ir=0; irFill(); #else - photonHitList[nHitsPerFrame].data = clusterData; - photonHitList[nHitsPerFrame].x = ic; - photonHitList[nHitsPerFrame].y = ir; - photonHitList[nHitsPerFrame].rms = clusterrms; - photonHitList[nHitsPerFrame].ped = clusterped; - photonHitList[nHitsPerFrame].iframe = clusteriframe; - + // photonHitList[nHitsPerFrame].data = clusterData; + photonHitList[nHitsPerFrame]->x = ic; + photonHitList[nHitsPerFrame]->y = ir; + photonHitList[nHitsPerFrame]->rms = clusterrms; + photonHitList[nHitsPerFrame]->ped = clusterped; + photonHitList[nHitsPerFrame]->iframe = clusteriframe; + //hit.write(myFile); + + nHitsPerFrame++; + photonHitList[nHitsPerFrame]=new single_photon_hit(nClusterX,nClusterY); nHitsPerFile++; nTotalHits++; if(nHitsPerFile >= MAX_HITS_PER_FILE-1) @@ -575,9 +594,9 @@ void singlePhotonFilter::findHits(){ //calulate the average hits per frame nHitStat->Calc((double)nHitsPerFrame); //write for each frame, not packet + pthread_mutex_lock(&write_mutex); writeToFile(); - //fifo->push(isData); pthread_mutex_unlock(&write_mutex); //increment offset diff --git a/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.h b/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.h index bab1bdfac..3a9a398f5 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.h @@ -33,6 +33,7 @@ #include "circularFifo.h" #include "runningStat.h" #include "movingStat.h" +#include "single_photon_hit.h" using namespace std; @@ -48,17 +49,6 @@ enum { OK, /**< function succeeded */ FAIL /**< function failed */ }; -/** - @short structure for a single photon hit -*/ -typedef struct{ - double* data; /**< data size */ - int x; /**< x-coordinate of the center of hit */ - int y; /**< x-coordinate of the center of hit */ - double rms; /**< noise of central pixel */ - double ped; /**< pedestal of the central pixel */ - int iframe; /**< frame number */ -}single_photon_hit; /** @@ -241,7 +231,8 @@ private: FILE *myFile; /** pointer to array of structs when only using files */ - single_photon_hit* photonHitList; + //single_photon_hit* photonHitList; + single_photon_hit ** photonHitList; /** Number of Hits per file */ int nHitsPerFile; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/single_photon_hit.h b/slsDetectorSoftware/slsDetectorAnalysis/single_photon_hit.h new file mode 100644 index 000000000..b8101240c --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/single_photon_hit.h @@ -0,0 +1,43 @@ +#ifndef SINGLE_PHOTON_HIT_H +#define SINGLE_PHOTON_HIT_h + +typedef double double32_t; +typedef float float32_t; +typedef int int32_t; + +/* /\** */ +/* @short structure for a single photon hit */ +/* *\/ */ +/* typedef struct{ */ +/* double* data; /\**< data size *\/ */ +/* int x; /\**< x-coordinate of the center of hit *\/ */ +/* int y; /\**< x-coordinate of the center of hit *\/ */ +/* double rms; /\**< noise of central pixel *\/ */ +/* double ped; /\**< pedestal of the central pixel *\/ */ +/* int iframe; /\**< frame number *\/ */ +/* }single_photon_hit; */ + + +class single_photon_hit { + + public: + single_photon_hit(int nx, int ny): dx(nx), dy(ny) {data=new double[dx*dy];}; + ~single_photon_hit(){delete [] data;}; + void write(FILE *myFile) {fwrite((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fwrite((void*)data, 1, dx*dy*sizeof(double), myFile);}; + void read(FILE *myFile) {fread((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fread((void*)data, 1, dx*dy*sizeof(double), myFile);}; + + + + int x; /**< x-coordinate of the center of hit */ + int y; /**< x-coordinate of the center of hit */ + double rms; /**< noise of central pixel */ + double ped; /**< pedestal of the central pixel */ + int iframe; /**< frame number */ + double *data; /**< data size */ + const int dx; + const int dy; +}; + + + +#endif