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
This commit is contained in:
l_maliakal_d 2013-10-02 14:19:26 +00:00
parent 65748059cc
commit fbf853ea20
2 changed files with 172 additions and 128 deletions

View File

@ -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 <vector<int16_t> >m, vector <vector<int16_t> >s, int d):
singlePhotonFilter::singlePhotonFilter(int nx, int ny,
int fmask, int pmask, int foffset, int poffset, int pperf, int iValue,
vector <vector<int16_t> > m, vector <vector<int16_t> > 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 <vector<int16_t> >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<x; i++)
stat[i].resize(y);
stat.resize(nChannelsX);
for(int i=0; i<nChannelsX; i++)
stat[i].resize(nChannelsY);
//struct
myPhotonHit.data.resize(nClusterX);
@ -61,12 +65,13 @@ singlePhotonFilter::singlePhotonFilter(int x, int y, vector <vector<int16_t> >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<nChannelsX; ir++){
@ -105,12 +110,13 @@ int singlePhotonFilter::writeToFile(){
delete myFile;
}
#else
if(myFile){ /*&& (number of structs?)*/
;
/*if(myFile){ //&& (number of structs?)
fwrite((void*)(&myPhotonHit), 1, sizeof(myPhotonHit), myFile);
fclose(myFile);
delete myFile;
return OK;
}
}*/
#endif
return FAIL;
}
@ -241,47 +247,36 @@ if(firstTimeHere){
*/
void singlePhotonFilter::initialize(int fmask, int pmask, int foffset, int poffset, int pperf){
fnum = 0; pnum = 0; ptot = 0; f0 = 0;
frame_index_mask = fmask;
packet_index_mask = pmask;
frame_index_offset = foffset;
packet_index_offset = poffset;
packets_per_frame = pperf;
void singlePhotonFilter::setupAcquisitionParameters(){
fnum = 0; pnum = 0; ptot = 0; f0 = 0; firstTime = true;
}
int singlePhotonFilter::verifyFrame(char *inData, int inDataSize, int16_t* myData, int firstTime){
int offset = 0;
int fIndex = 0;
int pIndex = 0;
while(offset < inDataSize){
fIndex = ((((int)(*((int*)inData))) & (frame_index_mask)) >> frame_index_offset);
pIndex = ((((int)(*((int*)inData))) & (packet_index_mask)) >> packet_index_offset);
offset += 4;
int singlePhotonFilter::verifyFrame(char *inData){
ret = 0;
pIndex = 0;
fIndex = 0;
fIndex = (((uint32_t)(*((uint32_t*)inData)))& frame_index_mask) >> 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;
//put first packet last
//for moench, put first packet last
if (pIndex == 0)
pIndex = packets_per_frame;
//copy packet to correct spot in outData
memcpy(((char*)(myData+(pIndex-1)*640)), (inData + offset), 1280);
offset += 1280 + 2;
#ifdef VERYVERBOSE
cout<<"fi:"<<hex<<fIndex<< " pi:"<< pIndex << endl;
#endif
//firsttime
if (firstTime){
firstTime = 0;
firstTime = false;
f0 = fIndex;
fnum = fIndex;
pnum = pIndex - 1; //should b 0 at first
@ -290,19 +285,22 @@ int singlePhotonFilter::verifyFrame(char *inData, int inDataSize, int16_t* myDat
//if it is not matching withthe frame number
if (fIndex != fnum){
cout << "Missing Packet! " << fnum << " "
"Expected f" << fnum << " p " << pnum + 1 << " received f " << fnum << " p " << pIndex << endl;
/*cout << "**Frame number doesnt match:Missing Packet! " << fnum << " "
"Expected f " << fnum << " p " << pnum + 1 << " received f " << fIndex << " p " << pIndex << endl;*/
fnum = fIndex;
pnum = pIndex - 1;
ptot = 0;
/* pnum = pIndex - 1;
ptot = 0;*/
pnum = pIndex;
ptot = 1;
ret = -2; //dont return here.. if is the end of packets, for gotthard uve toreturn -1
}
//if missing a packet, discard
if (pIndex != pnum + 1){
cout << "Missing Packet! " << fnum << " "
"Expected f" << fnum << " p " << pnum + 1 << " received f " << fnum << " p " << pIndex << endl;
else if (pIndex != pnum + 1){/**else */
/* cout << "**packet number doesnt match:Missing Packet! " << fnum << " "
"Expected f" << fnum << " p " << pnum + 1 << " received f " << fnum << " p " << pIndex << endl;*/
pnum = pIndex;
ptot = 0;/** should it be 0 or just not incrememnted */
ptot++;/*ptot = 0;*/
}
//no missing packet
else{
@ -311,33 +309,43 @@ int singlePhotonFilter::verifyFrame(char *inData, int inDataSize, int16_t* myDat
}
//copy packet to correct spot in outData
/*myData[pIndex-1] = inData;
cout<<"mydata["<<pIndex-1<<"]:"<<hex<<(uint32_t)(*((uint32_t*)inData))<<endl;*/
/*memcpy((myData+(pIndex-1)*inDataSize), inData, inDataSize);*/
//memcpy(((char*)(myData+(pIndex-1)*640)), (inData + offset), 1280);
//if its the last index
if (pIndex == packets_per_frame){
//got all packets
if (ptot == packets_per_frame){
myPhotonHit.iframe = fnum - f0;/** ?? */
findHits(myData,nChannelsX*nChannelsY*2);
return 1;
/*myPhotonHit.iframe = fnum - f0;//??
if (enable)
;*//*findHits(myData,inDataSize * ptot);*/
fnum = fIndex + 1;
ptot = 0;
pnum = 0;
ret = 1;
}else{
cout << "* Some packets have been missed!" << fnum << endl;
/* cout << "* Some packets have been missed!*************************************" << fnum << " " << pnum<<" " << ptot<<endl;*/
ptot = 0;
pnum = 0;
fnum = fIndex + 1;
ret = -1;
}
}
//index not 40, but total is 40.. strange
else if (ptot == packets_per_frame){
cout << "** Some packets have been missed! " << fnum << endl;
cout << "***** Some packets have been missed! " << fnum << " " << pnum<< endl;
ptot = 0;
pnum = pIndex - 1;
fnum = fIndex;
ret = -1;
}
}
delete myData;
return 0;
return ret;
}
/*

View File

@ -68,44 +68,52 @@ class singlePhotonFilter{
public:
/**
* Constructor
* @param nChannelsX Number of Channels in X direction
* @param nChannelsY Number of Channels in Y direction
* @param nx Number of Channels in X direction
* @param ny Number of Channels in Y direction
* @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
* @param iValue increment value (only for gotthard to increment index to have matching frame number)
* @param m Map to data without headers
* @param s mask as to which adcs are inverted
* @param d Size of data with the headers
*/
/** why is the datasize -1, you need to know the datasize with headers so that you dont go over the limits */
singlePhotonFilter(int x, int y, vector <vector<int16_t> >m, vector <vector<int16_t> >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 <vector<int16_t> > m,
vector <vector<int16_t> > 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
@ -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