mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 18:10:40 +02:00
Working for gotthard double modules
This commit is contained in:
parent
b029f1fa26
commit
593f5b6c65
@ -1,215 +0,0 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
//#include <deque>
|
||||
//#include <list>
|
||||
//#include <queue>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
|
||||
#include "gotthardModuleDataNew.h"
|
||||
#include "gotthardDoubleModuleDataNew.h"
|
||||
|
||||
#include "singlePhotonDetector.h"
|
||||
//#include "interpolatingDetector.h"
|
||||
//#include "linearInterpolation.h"
|
||||
#include "multiThreadedAnalogDetector.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#define NC 1280
|
||||
#define NR 1
|
||||
|
||||
#include "tiffIO.h"
|
||||
|
||||
|
||||
void *gotthardProcessFrame() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (argc < 3 ) {
|
||||
cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// receive parameters
|
||||
bool send = false;
|
||||
char* socketip=argv[1];
|
||||
uint32_t portnum = atoi(argv[2]);
|
||||
int size = 32*2*5000;//atoi(argv[3]);
|
||||
|
||||
// send parameters if any
|
||||
char* socketip2 = 0;
|
||||
uint32_t portnum2 = 0;
|
||||
if (argc > 3) {
|
||||
send = true;
|
||||
socketip2 = argv[3];
|
||||
portnum2 = atoi(argv[4]);
|
||||
}
|
||||
cout << "\nrx socket ip : " << socketip <<
|
||||
"\nrx port num : " << portnum ;
|
||||
if (send) {
|
||||
cout << "\nsd socket ip : " << socketip2 <<
|
||||
"\nsd port num : " << portnum2;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
char fname0[10000], fname1[10000];
|
||||
char fformat[10000];
|
||||
int fifosize=1000;
|
||||
strcpy(fformat,"/external_pool/gotthard_data/datadir_gotthardI/bchip074075/20170731/Xray/xray_15kV_200uA_5us_d%d_f000000000000_0.raw");
|
||||
sprintf(fname0,fformat,0,0);
|
||||
sprintf(fname1,fformat,1,1);
|
||||
|
||||
|
||||
int nthreads=3;
|
||||
|
||||
int nph, nph1;
|
||||
// single_photon_hit clusters[NR*NC];
|
||||
// cout << "hits "<< endl;
|
||||
int etabins=550;
|
||||
double etamin=-1, etamax=2;
|
||||
int nsubpix=1;
|
||||
float *etah=new float[etabins*etabins];
|
||||
// cout << "etah "<< endl;
|
||||
cout << "image size "<< nsubpix*nsubpix*NC*NR << endl;
|
||||
|
||||
int *heta, *himage;
|
||||
|
||||
gotthardModuleDataNew *decoder=new gotthardModuleDataNew();
|
||||
gotthardDoubleModuleDataNew *det=new gotthardDoubleModuleDataNew();
|
||||
// cout << "decoder "<< endl;
|
||||
// etaInterpolationPosXY *interp=new etaInterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
|
||||
// cout << "interp "<< endl;
|
||||
// linearInterpolation *interp=new linearInterpolation(NC, NR, nsubpix);
|
||||
//noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
|
||||
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
|
||||
// interpolatingDetector *filter0=new interpolatingDetector(decoder,interp, 5, 1, 0, 1000, 10);
|
||||
// interpolatingDetector *filter1=new interpolatingDetector(decoder,interp, 5, 1, 0, 1000, 10);
|
||||
//filter->readPedestals("/scratch/ped_100.tiff");
|
||||
//cout << "filter "<< endl;
|
||||
|
||||
singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 200);
|
||||
|
||||
filter->setFrameMode(eFrame);
|
||||
|
||||
char *buff;//[2*(48+1280*2)];
|
||||
|
||||
|
||||
char *buff0;
|
||||
char *buff1;
|
||||
|
||||
|
||||
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
|
||||
mt->setFrameMode(eFrame);
|
||||
mt->StartThreads();
|
||||
mt->popFree(buff);
|
||||
buff0=buff;
|
||||
buff1=buff+48+1280*2;
|
||||
|
||||
|
||||
int photons[1280*2];
|
||||
|
||||
int nf=0;
|
||||
int ok=0;
|
||||
ifstream filebin0,filebin1;
|
||||
std::time_t end_time;
|
||||
int16_t dout[1280*2];
|
||||
int iFrame=-1;
|
||||
int np=-1;
|
||||
|
||||
nph=0;
|
||||
nph1=0;
|
||||
//int np;
|
||||
int iph;
|
||||
int data_ready=1;
|
||||
int *image;
|
||||
|
||||
// filter->setROI(0,512,0,1);
|
||||
|
||||
filebin0.open((const char *)(fname0), ios::in | ios::binary);
|
||||
filebin1.open((const char *)(fname1), ios::in | ios::binary);
|
||||
if (filebin0.is_open() && filebin1.is_open()) {
|
||||
cout << "Opened file " << fname0<< endl;
|
||||
cout << "Opened file " << fname1<< endl;
|
||||
// mt->setFrameMode(eFrame);
|
||||
// mt->prepareInterpolation(ok);
|
||||
// mt->StartThreads();
|
||||
// mt->popFree(buff);
|
||||
nf=0;
|
||||
iFrame=-1;
|
||||
while ((decoder->readNextFrame(filebin0, iFrame, np, buff0)) && (decoder->readNextFrame(filebin1, iFrame, np, buff1))) {
|
||||
//filter->processData(buff, photons);
|
||||
// cout << nf << " " << decoder->getFrameNumber(buff0) << " " << decoder->getFrameNumber(buff1) << " " << filter->getPhFrame() << " " << filter->getPhTot() << endl;
|
||||
// for (int i=0; i<1280*2; i++) {
|
||||
// filter->addToPedestal(buff,i,0);
|
||||
// dout[i]=filter->subtractPedestal(buff,i,0);
|
||||
// if (nf>10 && i<512)
|
||||
// if (i%2)
|
||||
// cout << nf << " " << i << " " << filter->getPedestal(i,0) << " " << det->getValue(buff,i,0) << " " << decoder->getValue(buff1,1280-1-i/2,0)<< " " << dout[i] << endl;
|
||||
// else
|
||||
// cout << nf << " " << i << " " << filter->getPedestal(i,0) << " " << det->getValue(buff,i,0) << " " << decoder->getValue(buff0,i/2,0)<< " " << dout[i] << endl;
|
||||
|
||||
// }
|
||||
mt->pushData(buff);
|
||||
mt->nextThread();
|
||||
mt->popFree(buff);
|
||||
buff0=buff;
|
||||
buff1=buff+48+1280*2;
|
||||
|
||||
nf++;
|
||||
|
||||
// cout << id << " " << nf << endl;
|
||||
if (nf%10000==0) {
|
||||
while (mt->isBusy()) {;}
|
||||
image=filter->getImage();
|
||||
if (image) {
|
||||
cout << nf << "*****************" << endl;
|
||||
for (int i=0; i<512; i++) {
|
||||
cout << image[i] << "\t";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
filter->clearImage();
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << " " << nf << endl;
|
||||
}
|
||||
iFrame=-1;
|
||||
}
|
||||
|
||||
filebin0.close();
|
||||
filebin1.close();
|
||||
}
|
||||
else
|
||||
cout << "Could not open file " << fname0<< " or " << fname1 << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
gotthardProcessFrame();
|
||||
|
||||
}
|
@ -205,7 +205,8 @@ int main(int argc, char *argv[]){
|
||||
string filename0 = "";
|
||||
|
||||
|
||||
|
||||
int eoa0=0;
|
||||
int eoa1=0;
|
||||
|
||||
|
||||
|
||||
@ -227,6 +228,7 @@ int main(int argc, char *argv[]){
|
||||
char ofname[10000];
|
||||
char fn0[10000], fn1[10000];
|
||||
FILE *fout=NULL;
|
||||
FILE *fclust=NULL;
|
||||
for (int i=0; i<nnx; i++)
|
||||
dout[i]=0;
|
||||
char fname0[10000], fname1[10000];
|
||||
@ -275,21 +277,29 @@ int main(int argc, char *argv[]){
|
||||
int end_of_acquisition;
|
||||
while(1) {
|
||||
end_of_acquisition=0;
|
||||
eoa0=0;
|
||||
eoa1=0;
|
||||
|
||||
// cout << "Receive header " << nf << endl;
|
||||
if (!zmqsocket0->ReceiveHeader(0, acqIndex0, frameIndex0, subframeIndex0, filename0, fileindex0)) {
|
||||
|
||||
// cout << "************************************************************************** packet0!*****************************"<< endl;
|
||||
|
||||
eoa0=1;
|
||||
end_of_acquisition++;
|
||||
}
|
||||
if (!zmqsocket1->ReceiveHeader(0, acqIndex1, frameIndex1, subframeIndex1, filename1, fileindex1)) {
|
||||
//cout << "************************************************************************** packet1!*****************************"<< endl;
|
||||
|
||||
eoa1=1;
|
||||
end_of_acquisition++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// if ((!zmqsocket0->ReceiveHeader(0, acqIndex0, frameIndex0, subframeIndex0, filename0, fileindex0)) && (!zmqsocket1->ReceiveHeader(0, acqIndex1, frameIndex1, subframeIndex1, filename1, fileindex1))){
|
||||
if (end_of_acquisition==0) {
|
||||
|
||||
if (acqIndex0!=acqIndex1)
|
||||
cout << "different acquisition indexes " << acqIndex0 << " and " << acqIndex1 << endl;
|
||||
if (frameIndex0!=frameIndex1)
|
||||
@ -301,6 +311,8 @@ int main(int argc, char *argv[]){
|
||||
length = zmqsocket0->ReceiveData(0, buff0, size/2);
|
||||
if (!zmqsocket0->ReceiveHeader(0, acqIndex0, frameIndex0, subframeIndex0, filename0, fileindex0)) {
|
||||
end_of_acquisition++;
|
||||
eoa0=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,29 +321,56 @@ int main(int argc, char *argv[]){
|
||||
length = zmqsocket1->ReceiveData(0, buff1, size/2);
|
||||
if (!zmqsocket1->ReceiveHeader(0, acqIndex1, frameIndex1, subframeIndex1, filename1, fileindex1)) {
|
||||
end_of_acquisition++;
|
||||
eoa1=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (eoa0!=eoa1) {
|
||||
|
||||
while (eoa0<1) {
|
||||
length = zmqsocket0->ReceiveData(0, buff0, size/2);
|
||||
if (!zmqsocket0->ReceiveHeader(0, acqIndex0, frameIndex0, subframeIndex0, filename0, fileindex0)) {
|
||||
end_of_acquisition++;
|
||||
eoa0=1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
while (eoa1<1) {
|
||||
length = zmqsocket1->ReceiveData(0, buff1, size/2);
|
||||
if (!zmqsocket1->ReceiveHeader(0, acqIndex1, frameIndex1, subframeIndex1, filename1, fileindex1)) {
|
||||
end_of_acquisition++;
|
||||
eoa1=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (end_of_acquisition) {
|
||||
cout << "************************************************************************** END OF FRAME" << end_of_acquisition << " !*****************************"<< endl;
|
||||
// cout << "************************************************************************** END OF FRAME" << end_of_acquisition << " !*****************************"<< endl;
|
||||
// return 0;
|
||||
|
||||
sprintf(ofname,"%s_%d.ph",fn0,irun);
|
||||
while (mt->isBusy()) {;}
|
||||
image=filter->getImage();
|
||||
if (image) {
|
||||
// fout=fopen(ofname,"w");
|
||||
fout=fopen(ofname,"w");
|
||||
cout << nf << "*****************" << endl;
|
||||
for (int i=0; i<2560/2; i++) {
|
||||
// fprintf(fout,"%d %d\n",i,image[i]);
|
||||
dout[i]=image[i/2];
|
||||
dout[i+1280]=image[i/2+1];
|
||||
|
||||
for (int i=0; i<2560; i++) {
|
||||
fprintf(fout,"%d %d\n",i,image[i]);
|
||||
dout[i]=image[i];
|
||||
if (dout[i]<0)
|
||||
dout[i]=0;
|
||||
}
|
||||
// fclose(fout);
|
||||
fclose(fout);
|
||||
}
|
||||
|
||||
|
||||
@ -354,13 +393,23 @@ int main(int argc, char *argv[]){
|
||||
filter->clearImage();
|
||||
// std::time(&end_time);
|
||||
// cout << std::ctime(&end_time) << " " << nf << endl;
|
||||
|
||||
fclose(fclust);
|
||||
fclust=NULL;
|
||||
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fclust==NULL) {
|
||||
|
||||
strcpy(fn0,filename0.c_str());
|
||||
strcpy(fn1,filename1.c_str());
|
||||
sprintf(ofname,"%s_%d.clust",fn0,irun);
|
||||
fclust=fopen(ofname,"w");
|
||||
|
||||
}
|
||||
|
||||
strcpy(fn0,filename0.c_str());
|
||||
strcpy(fn1,filename1.c_str());
|
||||
|
||||
@ -372,8 +421,6 @@ int main(int argc, char *argv[]){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// // if (nf>100)
|
||||
// // mt->setFrameMode(eFrame);
|
||||
// //filter->clearImage();
|
||||
@ -384,7 +431,7 @@ int main(int argc, char *argv[]){
|
||||
|
||||
mt->pushData(buff);
|
||||
mt->nextThread();
|
||||
cout << "==" << nf << endl;
|
||||
// cout << "==" << nf << endl;
|
||||
|
||||
// while (mt->isBusy()) {;}
|
||||
// image=filter->getImage();
|
||||
|
Loading…
x
Reference in New Issue
Block a user