From fbf853ea2056eafc1a9b958e6cec43b3247bdaa2 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Wed, 2 Oct 2013 14:19:26 +0000 Subject: [PATCH] some more untested methods for single photon filter git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@674 951219d9-93cf-4727-9268-0efd64621fa3 --- .../singlePhotonFilter.cpp | 220 +++++++++--------- .../slsDetectorAnalysis/singlePhotonFilter.h | 80 +++++-- 2 files changed, 172 insertions(+), 128 deletions(-) diff --git a/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp b/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp index 1b922980f..9869838d1 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/singlePhotonFilter.cpp @@ -5,20 +5,18 @@ #include "singlePhotonFilter.h" -/*#define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00 -#define MOENCH_PACKET_INDEX_MASK 0xFF -#define MOENCH_FRAME_INDEX_OFFSET 8 -*/ -singlePhotonFilter::singlePhotonFilter(int x, int y, vector >m, vector >s, int d): +singlePhotonFilter::singlePhotonFilter(int nx, int ny, + int fmask, int pmask, int foffset, int poffset, int pperf, int iValue, + vector > m, vector > s, int d): #ifdef MYROOT myTree(NULL), myFile(NULL), #else myFile(NULL), #endif - nChannelsX(x), - nChannelsY(y), + nChannelsX(nx), + nChannelsY(ny), nClusterX(CLUSTER_SIZE), nClusterY(CLUSTER_SIZE), map(m), @@ -32,19 +30,25 @@ singlePhotonFilter::singlePhotonFilter(int x, int y, vector >m, pnum(0), ptot(0), f0(0), - frame_index_mask(0x00000000), - packet_index_mask(0x00000000), - frame_index_offset(0), - packet_index_offset(0), - packets_per_frame(0){ + frame_index_mask(fmask), + packet_index_mask(pmask), + frame_index_offset(foffset), + packet_index_offset(poffset), + packets_per_frame(pperf), + incrementValue(iValue), + enable(false), + firstTime(true), + ret(0), + pIndex(0), + fIndex(0){ - if (x == 1) + if (nChannelsX) nClusterX = 1; - stat.resize(x); - for(int i=0; i >m, -void singlePhotonFilter::initTree(char *outdir, char *fname){ - //path - char outfname[MAX_STR_LENGTH]; - sprintf(outfname, "%s/%s.root", outdir, fname); +void singlePhotonFilter::initTree(char *outfname){ #ifdef MYROOT + outfname = string(outfname).replace(".raw",".root"); + //fName.replace(".raw",".png"); + //sprintf(outfname, "%s/%s.root", outdir, fname); + char c1[10],c2[10],cdata[100]; sprintf(c1,"%d",nClusterX); sprintf(c2,"%d",nClusterY); @@ -82,7 +87,7 @@ void singlePhotonFilter::initTree(char *outdir, char *fname){ myTree->Branch("pedestal",&myPhotonHit.ped,"pedestal/D"); myTree->Branch("rms",&myPhotonHit.rms,"rms/D"); #else - myFile = fopen(outfname, "w"); + ;/*myFile = fopen(outfname, "w");*/ #endif //initialize for (int ir=0; ir> frame_index_offset; + pIndex = (((uint32_t)(*((uint32_t*)inData)))& packet_index_mask) >> packet_index_offset; + + //check validity of packet index + if ((pIndex < 0) && (pIndex >= packets_per_frame)){ + cout << "cannot decode packet index:" << pIndex << endl; + //its already dealt with cuz this frame will be discarded in the end + } + pIndex += incrementValue; + + //for moench, put first packet last + if (pIndex == 0) + pIndex = packets_per_frame; +#ifdef VERYVERBOSE + cout<<"fi:"<> frame_index_offset); - pIndex = ((((int)(*((int*)inData))) & (packet_index_mask)) >> packet_index_offset); - - offset += 4; - - //check validity of packet index - if ((pIndex < 0) && (pIndex >= packets_per_frame)){ - cout << "cannot decode packet index:" << pIndex << endl; - //its already dealt with cuz this frame will be discarded in the end - } - - //put first packet last - if (pIndex == 0) - pIndex = packets_per_frame; + //copy packet to correct spot in outData + /*myData[pIndex-1] = inData; + cout<<"mydata["< >m, vector >s, int d = -1); - /*map[56][63]=656; data[map[56][63]] ^ 0x7fff*/ + singlePhotonFilter( + int nx, + int ny, + int fmask, + int pmask, + int foffset, + int poffset, + int pperf, + int iValue, + vector > m, + vector > s, + int d = -1); /** virtual destructor */ virtual ~singlePhotonFilter(){}; /** - * Construct a tree, populate struct for the single photon hit - * @param outdir Output file directory - * @param fname Output file name + * Construct a tree, populate struct for the single photon hit and provide all the masks and offsets + * @param outdir Output file directory/Output file name + */ - void initTree(char *outdir, char *fname); + void initTree(char *outfname); /** - * Reset Indices before starting acquisition and provide all the masks and offsets - * @param fmask frame index mask - * @param pmask packet index mask - * @param foffset frame index offset - * @param poffset packet index offset - * @param pperf packets per frame + * Reset Indices before starting acquisition */ - void initialize(int fmask, int pmask, int foffset, int poffset, int pperf); + void setupAcquisitionParameters(); - /** Verify if all packets exist for the frame + /** reconstruct the frame with all the right packets * @param inData the data from socket to be verified - * @param inDataSize datasize of packet - * @param myData frame with all the packets - * @param firstTime the first frame received from socket * */ - int verifyFrame(char *inData, int inDataSize, int16_t* myData, int firstTime); + int verifyFrame(char *inData); /** * Writes tree/struct to file @@ -121,6 +129,16 @@ public: */ int findHits(int16_t *myData, int myDataSize); + /** + * Enable Filter, This makes sure findHits() is called + */ + void enableFilter(bool r){enable = r;}; + + /** + * Returns packets per frame + */ + int getPacketsPerFrame(){ return packets_per_frame;}; + #ifdef MYROOT @@ -187,13 +205,13 @@ private: int nClusterY; /** map to the data without headers */ - vector >map; + vector > map; /** Size of data with headers */ int dataSize; /** mask as to which adcs are inverted */ - vector >mask; + vector > mask; /** movingStat object */ vector > stat; @@ -255,6 +273,24 @@ private: /** number of packets per frame */ int packets_per_frame; + /** increment value for index for gotthard */ + int incrementValue; + + /** filter enable */ + bool enable; + + /** first packet */ + bool firstTime; + + /** return status */ + int ret; + + /** current packet index */ + int pIndex; + + /** current frame index */ + int fIndex; + }; #endif