formatted slsDetectorCalibration

This commit is contained in:
Erik Frojdh
2022-01-24 11:26:56 +01:00
parent 623b1de8a0
commit c554bbb2d3
77 changed files with 15998 additions and 15890 deletions

View File

@ -3,7 +3,6 @@
//#include "sls/ansi.h"
#include <iostream>
//#include "moench03T1ZmqData.h"
#ifdef NEWRECEIVER
#ifndef RECT
@ -16,13 +15,12 @@
#endif
#ifdef CSAXS_FP
#include "moench03T1ReceiverData.h"
#endif
#endif
#ifdef OLDDATA
#include "moench03Ctb10GbT1Data.h"
#endif
#endif
#ifdef REORDERED
#include "moench03T1ReorderedData.h"
@ -36,204 +34,186 @@
#include "singlePhotonDetector.h"
//#include "interpolatingDetector.h"
#include <stdio.h>
#include <map>
#include <fstream>
#include <map>
#include <stdio.h>
#include <sys/stat.h>
#include <ctime>
using namespace std;
int main(int argc, char *argv[]) {
if (argc<6) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl;
return 1;
}
int p=10000;
int fifosize=1000;
int nthreads=1;
int nsubpix=25;
int etabins=nsubpix*10;
double etamin=-1, etamax=2;
int csize=3;
int nx=400, ny=400;
int save=1;
int nsigma=5;
int nped=1000;
int ndark=100;
int ok;
int iprog=0;
if (argc < 6) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax "
<< endl;
return 1;
}
int p = 10000;
int fifosize = 1000;
int nthreads = 1;
int nsubpix = 25;
int etabins = nsubpix * 10;
double etamin = -1, etamax = 2;
int csize = 3;
int nx = 400, ny = 400;
int save = 1;
int nsigma = 5;
int nped = 1000;
int ndark = 100;
int ok;
int iprog = 0;
#ifdef NEWRECEIVER
#ifdef RECT
cout << "Should be rectangular!" <<endl;
cout << "Should be rectangular!" << endl;
#endif
moench03T1ReceiverDataNew *decoder=new moench03T1ReceiverDataNew();
cout << "RECEIVER DATA WITH ONE HEADER!"<<endl;
moench03T1ReceiverDataNew *decoder = new moench03T1ReceiverDataNew();
cout << "RECEIVER DATA WITH ONE HEADER!" << endl;
#endif
#ifdef CSAXS_FP
moench03T1ReceiverData *decoder=new moench03T1ReceiverData();
cout << "RECEIVER DATA WITH ALL HEADERS!"<<endl;
moench03T1ReceiverData *decoder = new moench03T1ReceiverData();
cout << "RECEIVER DATA WITH ALL HEADERS!" << endl;
#endif
#ifdef OLDDATA
moench03Ctb10GbT1Data *decoder=new moench03Ctb10GbT1Data();
cout << "OLD RECEIVER DATA!"<<endl;
moench03Ctb10GbT1Data *decoder = new moench03Ctb10GbT1Data();
cout << "OLD RECEIVER DATA!" << endl;
#endif
#ifdef REORDERED
moench03T1ReorderedData *decoder=new moench03T1ReorderedData();
cout << "REORDERED DATA!"<<endl;
moench03T1ReorderedData *decoder = new moench03T1ReorderedData();
cout << "REORDERED DATA!" << endl;
#endif
decoder->getDetectorSize(nx, ny);
cout << "nx " << nx << " ny " << ny << endl;
decoder->getDetectorSize(nx,ny);
cout << "nx " << nx << " ny " << ny << endl;
// moench03T1ZmqData *decoder=new moench03T1ZmqData();
singlePhotonDetector *filter =
new singlePhotonDetector(decoder, csize, nsigma, 1, 0, nped, 200);
// char tit[10000];
cout << "filter " << endl;
//moench03T1ZmqData *decoder=new moench03T1ZmqData();
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 200);
// char tit[10000];
cout << "filter " << endl;
// filter->readPedestals("/scratch/ped_100.tiff");
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
// cout << "filter "<< endl;
int size = 327680; ////atoi(argv[3]);
int *image;
// int* image =new int[327680/sizeof(int)];
filter->newDataSet();
// filter->readPedestals("/scratch/ped_100.tiff");
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
// cout << "filter "<< endl;
int ff, np;
int dsize = decoder->getDataSize();
cout << " data size is " << dsize;
int size = 327680;////atoi(argv[3]);
int* image;
//int* image =new int[327680/sizeof(int)];
filter->newDataSet();
char data[dsize];
ifstream filebin;
char *indir = argv[1];
char *outdir = argv[2];
char *fformat = argv[3];
int runmin = atoi(argv[4]);
int runmax = atoi(argv[5]);
int ff, np;
int dsize=decoder->getDataSize();
cout << " data size is " << dsize;
char fname[10000];
char outfname[10000];
char imgfname[10000];
char pedfname[10000];
// strcpy(pedfname,argv[6]);
char fn[10000];
char data[dsize];
std::time_t end_time;
ifstream filebin;
char *indir=argv[1];
char *outdir=argv[2];
char *fformat=argv[3];
int runmin=atoi(argv[4]);
int runmax=atoi(argv[5]);
char fname[10000];
char outfname[10000];
char imgfname[10000];
char pedfname[10000];
// strcpy(pedfname,argv[6]);
char fn[10000];
std::time_t end_time;
FILE *of = NULL;
cout << "input directory is " << indir << endl;
cout << "output directory is " << outdir << endl;
cout << "fileformat is " << fformat << endl;
FILE *of=NULL;
cout << "input directory is " << indir << endl;
cout << "output directory is " << outdir << endl;
cout << "fileformat is " << fformat << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
mt->setDetectorMode(ePhotonCounting);
mt->setFrameMode(eFrame);
mt->StartThreads();
mt->popFree(buff);
cout << "mt " << endl;
int ifr=0;
for (int irun=runmin; irun<runmax; irun++) {
sprintf(fn,fformat,irun);
sprintf(fname,"%s/%s.raw",indir,fn);
sprintf(outfname,"%s/%s.clust",outdir,fn);
sprintf(imgfname,"%s/%s.tiff",outdir,fn);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
if (filebin.is_open()){
of=fopen(outfname,"w");
if (of) {
mt->setFilePointer(of);
// cout << "file pointer set " << endl;
} else {
cout << "Could not open "<< outfname << " for writing " << endl;
mt->setFilePointer(NULL);
return 1;
}
// //while read frame
ff=-1;
while (decoder->readNextFrame(filebin, ff, np,buff)) {
// cout << "*"<<ifr++<<"*"<<ff<< endl;
// cout << ff << " " << np << endl;
// //push
// for (int ix=0; ix<400; ix++)
// for (int iy=0; iy<400; iy++) {
// if (decoder->getChannel(buff, ix, iy)<3000 || decoder->getChannel(buff, ix, iy)>8000) {
// cout << ifr << " " << ff << " " << ix << " " << iy << " " << decoder->getChannel(buff, ix, iy) << endl ;
// }
// }
cout << std::ctime(&end_time) << endl;
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ifr++;
if (ifr%10000==0) cout << ifr << " " << ff << endl;
ff=-1;
}
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
while (mt->isBusy()) {;}//wait until all data are processed from the queues
if (of)
fclose(of);
mt->writeImage(imgfname);
mt->clearImage();
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char *buff;
multiThreadedAnalogDetector *mt =
new multiThreadedAnalogDetector(filter, nthreads, fifosize);
} else
cout << "Could not open "<< fname << " for reading " << endl;
}
mt->setDetectorMode(ePhotonCounting);
mt->setFrameMode(eFrame);
mt->StartThreads();
mt->popFree(buff);
return 0;
cout << "mt " << endl;
int ifr = 0;
for (int irun = runmin; irun < runmax; irun++) {
sprintf(fn, fformat, irun);
sprintf(fname, "%s/%s.raw", indir, fn);
sprintf(outfname, "%s/%s.clust", outdir, fn);
sprintf(imgfname, "%s/%s.tiff", outdir, fn);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
if (filebin.is_open()) {
of = fopen(outfname, "w");
if (of) {
mt->setFilePointer(of);
// cout << "file pointer set " << endl;
} else {
cout << "Could not open " << outfname << " for writing "
<< endl;
mt->setFilePointer(NULL);
return 1;
}
// //while read frame
ff = -1;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
// cout << "*"<<ifr++<<"*"<<ff<< endl;
// cout << ff << " " << np << endl;
// //push
// for (int ix=0; ix<400; ix++)
// for (int iy=0; iy<400; iy++) {
// if (decoder->getChannel(buff, ix, iy)<3000 ||
// decoder->getChannel(buff, ix, iy)>8000) {
// cout << ifr << " " << ff << " " << ix << " " << iy <<
// " " << decoder->getChannel(buff, ix, iy) << endl ;
// }
// }
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ifr++;
if (ifr % 10000 == 0)
cout << ifr << " " << ff << endl;
ff = -1;
}
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
while (mt->isBusy()) {
;
} // wait until all data are processed from the queues
if (of)
fclose(of);
mt->writeImage(imgfname);
mt->clearImage();
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
} else
cout << "Could not open " << fname << " for reading " << endl;
}
return 0;
}

View File

@ -17,100 +17,103 @@
#endif
//#include "etaInterpolationPosXY.h"
#include "noInterpolation.h"
#include "etaInterpolationPosXY.h"
#include "noInterpolation.h"
//#include "etaInterpolationCleverAdaptiveBins.h"
//#include "etaInterpolationRandomBins.h"
using namespace std;
#define NC 400
#define NR 400
#define MAX_ITERATIONS (nSubPixels*100)
#define NC 400
#define NR 400
#define MAX_ITERATIONS (nSubPixels * 100)
#define XTALK
int main(int argc, char *argv[]) {
#ifndef FF
if (argc<9) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile outfile runmin runmax ns cmin cmax" << endl;
return 1;
}
#endif
#ifdef FF
if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile runmin runmax cmin cmax" << endl;
return 1;
}
#endif
int iarg=4;
char infname[10000];
char fname[10000];
char outfname[10000];
#ifndef FF
iarg=4;
if (argc < 9) {
cout << "Wrong usage! Should be: " << argv[0]
<< " infile etafile outfile runmin runmax ns cmin cmax" << endl;
return 1;
}
#endif
#ifdef FF
iarg=3;
if (argc < 7) {
cout << "Wrong usage! Should be: " << argv[0]
<< " infile etafile runmin runmax cmin cmax" << endl;
return 1;
}
#endif
int runmin=atoi(argv[iarg++]);
int runmax=atoi(argv[iarg++]);
cout << "Run min: " << runmin << endl;
cout << "Run max: " << runmax << endl;
int nsubpix=4;
int iarg = 4;
char infname[10000];
char fname[10000];
char outfname[10000];
#ifndef FF
nsubpix=atoi(argv[iarg++]);
cout << "Subpix: " << nsubpix << endl;
iarg = 4;
#endif
float cmin=atof(argv[iarg++]);
float cmax=atof(argv[iarg++]);
cout << "Energy min: " << cmin << endl;
cout << "Energy max: " << cmax << endl;
//int etabins=500;
int etabins=1000;//nsubpix*2*100;
double etamin=-1, etamax=2;
//double etamin=-0.1, etamax=1.1;
double eta3min=-2, eta3max=2;
int quad;
double sum, totquad;
double sDum[2][2];
double etax, etay, int_x, int_y;
double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y;
int ok;
int f0=-1;
int ix, iy, isx, isy;
int nframes=0, lastframe=-1;
double d_x, d_y, res=5, xx, yy;
int nph=0, badph=0, totph=0;
FILE *f=NULL;
#ifdef FF
iarg = 3;
#endif
int runmin = atoi(argv[iarg++]);
int runmax = atoi(argv[iarg++]);
cout << "Run min: " << runmin << endl;
cout << "Run max: " << runmax << endl;
int nsubpix = 4;
#ifndef FF
nsubpix = atoi(argv[iarg++]);
cout << "Subpix: " << nsubpix << endl;
#endif
float cmin = atof(argv[iarg++]);
float cmax = atof(argv[iarg++]);
cout << "Energy min: " << cmin << endl;
cout << "Energy max: " << cmax << endl;
// int etabins=500;
int etabins = 1000; // nsubpix*2*100;
double etamin = -1, etamax = 2;
// double etamin=-0.1, etamax=1.1;
double eta3min = -2, eta3max = 2;
int quad;
double sum, totquad;
double sDum[2][2];
double etax, etay, int_x, int_y;
double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y;
int ok;
int f0 = -1;
int ix, iy, isx, isy;
int nframes = 0, lastframe = -1;
double d_x, d_y, res = 5, xx, yy;
int nph = 0, badph = 0, totph = 0;
FILE *f = NULL;
#ifdef DOUBLE_SPH
single_photon_hit_double cl(3,3);
single_photon_hit_double cl(3, 3);
#endif
#ifndef DOUBLE_SPH
single_photon_hit cl(3,3);
single_photon_hit cl(3, 3);
#endif
int nSubPixels=nsubpix;
int nSubPixels = nsubpix;
#ifndef NOINTERPOLATION
eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
//eta2InterpolationCleverAdaptiveBins *interp=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax);
eta2InterpolationPosXY *interp =
new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
// eta2InterpolationCleverAdaptiveBins *interp=new
// eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin,
// etamax);
#endif
#ifdef NOINTERPOLATION
noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
noInterpolation *interp = new noInterpolation(NC, NR, nsubpix);
#endif
#ifndef FF
#ifndef NOINTERPOLATION
cout << "read ff " << argv[2] << endl;
sprintf(fname,"%s",argv[2]);
sprintf(fname, "%s", argv[2]);
interp->readFlatField(fname);
interp->prepareInterpolation(ok);//, MAX_ITERATIONS);
interp->prepareInterpolation(ok); //, MAX_ITERATIONS);
#endif
// return 0;
#endif
@ -119,134 +122,144 @@ int main(int argc, char *argv[]) {
#endif
int *img;
float *totimg=new float[NC*NR*nsubpix*nsubpix];
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]=0;
}
}
}
float *totimg = new float[NC * NR * nsubpix * nsubpix];
for (ix = 0; ix < NC; ix++) {
for (iy = 0; iy < NR; iy++) {
for (isx = 0; isx < nsubpix; isx++) {
for (isy = 0; isy < nsubpix; isy++) {
totimg[ix * nsubpix + isx +
(iy * nsubpix + isy) * (NC * nsubpix)] = 0;
}
}
}
}
#ifdef FF
sprintf(outfname,argv[2]);
#endif
sprintf(outfname, argv[2]);
#endif
int irun;
for (irun=runmin; irun<runmax; irun++) {
sprintf(infname,argv[1],irun);
for (irun = runmin; irun < runmax; irun++) {
sprintf(infname, argv[1], irun);
#ifndef FF
sprintf(outfname,argv[3],irun);
sprintf(outfname, argv[3], irun);
#endif
f=fopen(infname,"r");
if (f) {
cout << infname << endl;
nframes=0;
f0=-1;
while (cl.read(f)) {
totph++;
if (lastframe!=cl.iframe) {
lastframe=cl.iframe;
// cout << cl.iframe << endl;
// f0=cl.iframe;
if (nframes==0) f0=lastframe;
nframes++;
}
//quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
quad=interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum<cmax ) {
nph++;
// if (sum>200 && sum<580) {
// interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y);
f = fopen(infname, "r");
if (f) {
cout << infname << endl;
nframes = 0;
f0 = -1;
while (cl.read(f)) {
totph++;
if (lastframe != cl.iframe) {
lastframe = cl.iframe;
// cout << cl.iframe << endl;
// f0=cl.iframe;
if (nframes == 0)
f0 = lastframe;
nframes++;
}
// quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
quad = interp->calcEta(cl.get_cluster(), etax, etay, sum,
totquad, sDum);
if (sum > cmin && totquad / sum > 0.8 && totquad / sum < 1.2 &&
sum < cmax) {
nph++;
// if (sum>200 && sum<580) {
// interp->getInterpolatedPosition(cl.x,cl.y,
// totquad,quad,cl.get_cluster(),int_x, int_y);
// #ifdef SOLEIL
// if (cl.x>210 && cl.x<240 && cl.y>210 && cl.y<240) {
// #endif
#ifndef FF
// interp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y);
interp->getInterpolatedPosition(cl.x,cl.y, etax, etay, quad,int_x, int_y);
// cout <<"**************"<< endl;
// cout << cl.x << " " << cl.y << " " << sum << endl;
// cl.print();
// cout << int_x << " " << int_y << endl;
// cout <<"**************"<< endl;
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
interp->addToImage(int_x, int_y);
if (int_x<0 || int_y<0 || int_x>400 || int_y>400) {
cout <<"**************"<< endl;
cout << cl.x << " " << cl.y << " " << sum << endl;
cl.print();
cout << int_x << " " << int_y << endl;
cout <<"**************"<< endl;
}
// interp->getInterpolatedPosition(cl.x,cl.y,
// cl.get_cluster(),int_x, int_y);
interp->getInterpolatedPosition(cl.x, cl.y, etax, etay,
quad, int_x, int_y);
// cout <<"**************"<< endl;
// cout << cl.x << " " << cl.y << " " << sum << endl;
// cl.print();
// cout << int_x << " " << int_y << endl;
// cout <<"**************"<< endl;
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
interp->addToImage(int_x, int_y);
if (int_x < 0 || int_y < 0 || int_x > 400 || int_y > 400) {
cout << "**************" << endl;
cout << cl.x << " " << cl.y << " " << sum << endl;
cl.print();
cout << int_x << " " << int_y << endl;
cout << "**************" << endl;
}
#endif
#ifdef FF
// interp->addToFlatField(cl.get_cluster(), etax, etay);
// #ifdef UCL
// if (cl.x>50)
// #endif
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
interp->addToFlatField(etax, etay);
// if (etax==0 || etay==0) cout << cl.x << " " << cl.y << endl;
#endif
// #ifdef SOLEIL
// }
// #endif
if (nph%1000000==0) cout << nph << endl;
if (nph%10000000==0) {
#ifndef FF
interp->writeInterpolatedImage(outfname);
#endif
#ifdef FF
interp->writeFlatField(outfname);
#endif
}
}
}
fclose(f);
#ifdef FF
interp->writeFlatField(outfname);
#endif
#ifndef FF
interp->writeInterpolatedImage(outfname);
// interp->addToFlatField(cl.get_cluster(), etax, etay);
// #ifdef UCL
// if (cl.x>50)
// #endif
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
interp->addToFlatField(etax, etay);
// if (etax==0 || etay==0) cout << cl.x << " " << cl.y <<
// endl;
img=interp->getInterpolatedImage();
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]+=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
}
}
}
}
cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ") nph="<< nph <<endl;
interp->clearInterpolatedImage();
#endif
} else
cout << "could not open file " << infname << endl;
// #ifdef SOLEIL
// }
// #endif
if (nph % 1000000 == 0)
cout << nph << endl;
if (nph % 10000000 == 0) {
#ifndef FF
interp->writeInterpolatedImage(outfname);
#endif
#ifdef FF
interp->writeFlatField(outfname);
#endif
}
}
}
fclose(f);
#ifdef FF
interp->writeFlatField(outfname);
#endif
#ifndef FF
interp->writeInterpolatedImage(outfname);
img = interp->getInterpolatedImage();
for (ix = 0; ix < NC; ix++) {
for (iy = 0; iy < NR; iy++) {
for (isx = 0; isx < nsubpix; isx++) {
for (isy = 0; isy < nsubpix; isy++) {
totimg[ix * nsubpix + isx +
(iy * nsubpix + isy) * (NC * nsubpix)] +=
img[ix * nsubpix + isx +
(iy * nsubpix + isy) * (NC * nsubpix)];
}
}
}
}
cout << "Read " << nframes << " frames (first frame: " << f0
<< " last frame: " << lastframe << " delta:" << lastframe - f0
<< ") nph=" << nph << endl;
interp->clearInterpolatedImage();
#endif
} else
cout << "could not open file " << infname << endl;
}
#ifndef FF
sprintf(outfname,argv[3],11111);
WriteToTiff(totimg, outfname,NC*nsubpix,NR*nsubpix);
#endif
#ifdef FF
interp->writeFlatField(outfname);
sprintf(outfname, argv[3], 11111);
WriteToTiff(totimg, outfname, NC * nsubpix, NR * nsubpix);
#endif
cout << "Filled " << nph << " (/"<< totph <<") " << endl;
#ifdef FF
interp->writeFlatField(outfname);
#endif
cout << "Filled " << nph << " (/" << totph << ") " << endl;
return 0;
}

View File

@ -12,161 +12,165 @@ using namespace std;
#define NC 400
#define NR 400
int main(int argc, char *argv[]) {
/**
* trial.o [socket ip] [starting port number] [outfname]
*
*/
/**
* trial.o [socket ip] [starting port number] [outfname]
*
*/
if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " etafile outfile runmin runmax ns" << endl;
return 1;
}
if (argc < 7) {
cout << "Wrong usage! Should be: " << argv[0] << " infile "
<< " etafile outfile runmin runmax ns" << endl;
return 1;
}
char infname[10000];
char outfname[10000];
int runmin=atoi(argv[4]);
int runmax=atoi(argv[5]);
int nsubpix=atoi(argv[6]);
int etabins=1000;//nsubpix*2*100;
double etamin=-1, etamax=2;
int quad;
double sum, totquad;
double sDum[2][2];
double etax, etay, int_x, int_y;
int ok;
char infname[10000];
char outfname[10000];
int runmin = atoi(argv[4]);
int runmax = atoi(argv[5]);
int nsubpix = atoi(argv[6]);
int ix, iy, isx, isy;
int etabins = 1000; // nsubpix*2*100;
double etamin = -1, etamax = 2;
int quad;
double sum, totquad;
double sDum[2][2];
double etax, etay, int_x, int_y;
int ok;
int ix, iy, isx, isy;
FILE *f=NULL;
FILE *f = NULL;
single_photon_hit cl(3,3);
// etaInterpolationPosXY *interp=new etaInterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
single_photon_hit cl(3, 3);
// etaInterpolationPosXY *interp=new etaInterpolationPosXY(NC, NR, nsubpix,
// etabins, etamin, etamax);
noInterpolation *interp = new noInterpolation(NC, NR, nsubpix);
// interp->readFlatField(argv[2]);
// interp->prepareInterpolation(ok);
int *img;
float *totimg=new float[NC*NR*nsubpix*nsubpix];
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]=0;
}
}
}
float *totimg = new float[NC * NR * nsubpix * nsubpix];
for (ix = 0; ix < NC; ix++) {
for (iy = 0; iy < NR; iy++) {
for (isx = 0; isx < nsubpix; isx++) {
for (isy = 0; isy < nsubpix; isy++) {
totimg[ix * nsubpix + isx +
(iy * nsubpix + isy) * (NC * nsubpix)] = 0;
}
}
}
}
#ifdef FF
float ff[nsubpix*nsubpix];
float *ffimg=new float[NC*NR*nsubpix*nsubpix];
float totff=0;
float ff[nsubpix * nsubpix];
float *ffimg = new float[NC * NR * nsubpix * nsubpix];
float totff = 0;
#endif
for (int irun=runmin; irun<runmax; irun++) {
sprintf(infname,argv[1],irun);
sprintf(outfname,argv[3],irun);
f=fopen(infname,"r");
if (f) {
while (cl.read(f)) {
quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
if (sum>200 && sum<580) {
interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y);
interp->addToImage(int_x, int_y);
}
}
fclose(f);
for (int irun = runmin; irun < runmax; irun++) {
sprintf(infname, argv[1], irun);
sprintf(outfname, argv[3], irun);
f = fopen(infname, "r");
if (f) {
while (cl.read(f)) {
quad = interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
if (sum > 200 && sum < 580) {
interp->getInterpolatedPosition(cl.x, cl.y, totquad, quad,
cl.get_cluster(), int_x,
int_y);
interp->addToImage(int_x, int_y);
}
}
fclose(f);
#ifdef FF
img=interp->getInterpolatedImage();
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
ff[isy*nsubpix+isx]=0;
}
}
totff=0;
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR-100; iy++) {
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
ff[isy*nsubpix+isx]+=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
}
}
}
}
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
totff+=ff[isy*nsubpix+isx];
}
}
totff/=nsubpix*nsubpix;
img = interp->getInterpolatedImage();
for (isx = 0; isx < nsubpix; isx++) {
for (isy = 0; isy < nsubpix; isy++) {
ff[isy * nsubpix + isx] = 0;
}
}
totff = 0;
for (ix = 0; ix < NC; ix++) {
for (iy = 0; iy < NR - 100; iy++) {
for (isx = 0; isx < nsubpix; isx++) {
for (isy = 0; isy < nsubpix; isy++) {
ff[isy * nsubpix + isx] +=
img[ix * nsubpix + isx +
(iy * nsubpix + isy) * (NC * nsubpix)];
}
}
}
}
for (isx = 0; isx < nsubpix; isx++) {
for (isy = 0; isy < nsubpix; isy++) {
totff += ff[isy * nsubpix + isx];
}
}
totff /= nsubpix * nsubpix;
if (totff) {
if (totff) {
cout << "ff: " << totff << endl;
cout << "ff: " << totff << endl;
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
ff[isy*nsubpix+isx]/=totff;
cout << ff[isy*nsubpix+isx] << "\t";
}
cout << endl;
}
for (isx = 0; isx < nsubpix; isx++) {
for (isy = 0; isy < nsubpix; isy++) {
ff[isy * nsubpix + isx] /= totff;
cout << ff[isy * nsubpix + isx] << "\t";
}
cout << endl;
}
for (ix = 0; ix < NC; ix++) {
for (iy = 0; iy < NR; iy++) {
for (isx = 0; isx < nsubpix; isx++) {
for (isy = 0; isy < nsubpix; isy++) {
ffimg[ix * nsubpix + isx +
(iy * nsubpix + isy) * (NC * nsubpix)] =
img[ix * nsubpix + isx +
(iy * nsubpix + isy) * (NC * nsubpix)] /
ff[isy * nsubpix + isx];
totimg[ix * nsubpix + isx +
(iy * nsubpix + isy) * (NC * nsubpix)] +=
ffimg[ix * nsubpix + isx +
(iy * nsubpix + isy) *
(NC * nsubpix)];
}
}
}
}
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
ffimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]/ff[isy*nsubpix+isx];
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]+=ffimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
}
}
}
}
WriteToTiff(ffimg, outfname,NC*nsubpix,NR*nsubpix);
}
WriteToTiff(ffimg, outfname, NC * nsubpix, NR * nsubpix);
}
#endif
#ifndef FF
interp->writeInterpolatedImage(outfname);
img=interp->getInterpolatedImage();
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]+=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
}
}
}
}
interp->writeInterpolatedImage(outfname);
img = interp->getInterpolatedImage();
for (ix = 0; ix < NC; ix++) {
for (iy = 0; iy < NR; iy++) {
for (isx = 0; isx < nsubpix; isx++) {
for (isy = 0; isy < nsubpix; isy++) {
totimg[ix * nsubpix + isx +
(iy * nsubpix + isy) * (NC * nsubpix)] +=
img[ix * nsubpix + isx +
(iy * nsubpix + isy) * (NC * nsubpix)];
}
}
}
}
#endif
interp->clearInterpolatedImage();
}
interp->clearInterpolatedImage();
}
}
sprintf(outfname,argv[3],11111);
WriteToTiff(totimg, outfname,NC*nsubpix,NR*nsubpix);
sprintf(outfname, argv[3], 11111);
WriteToTiff(totimg, outfname, NC * nsubpix, NR * nsubpix);
return 0;
}

View File

@ -22,13 +22,12 @@
#endif
#ifdef CSAXS_FP
#include "moench03T1ReceiverData.h"
#endif
#endif
#ifdef OLDDATA
#include "moench03Ctb10GbT1Data.h"
#endif
#endif
// #include "interpolatingDetector.h"
//#include "etaInterpolationPosXY.h"
@ -36,420 +35,413 @@
// #include "noInterpolation.h"
#include "multiThreadedCountingDetector.h"
//#include "multiThreadedAnalogDetector.h"
#include "singlePhotonDetector.h"
#include "moench03GhostSummation.h"
#include "moench03CommonMode.h"
#include "moench03GhostSummation.h"
#include "singlePhotonDetector.h"
//#include "interpolatingDetector.h"
#include <stdio.h>
#include <map>
#include <fstream>
#include <map>
#include <stdio.h>
#include <sys/stat.h>
#include <ctime>
using namespace std;
int main(int argc, char *argv[]) {
if (argc < 4) {
cout << "Usage is " << argv[0]
<< "indir outdir fname [runmin] [runmax] [pedfile] [threshold] "
"[nframes] [xmin xmax ymin ymax] [gainmap]"
<< endl;
cout << "threshold <0 means analog; threshold=0 means cluster finder; "
"threshold>0 means photon counting"
<< endl;
cout << "nframes <0 means sum everything; nframes=0 means one file per "
"run; nframes>0 means one file every nframes"
<< endl;
return 1;
}
if (argc<4) {
cout << "Usage is " << argv[0] << "indir outdir fname [runmin] [runmax] [pedfile] [threshold] [nframes] [xmin xmax ymin ymax] [gainmap]" << endl;
cout << "threshold <0 means analog; threshold=0 means cluster finder; threshold>0 means photon counting" << endl;
cout << "nframes <0 means sum everything; nframes=0 means one file per run; nframes>0 means one file every nframes" << endl;
return 1;
}
int p = 10000;
int fifosize = 1000;
int nthreads = 10;
int nsubpix = 25;
int etabins = nsubpix * 10;
double etamin = -1, etamax = 2;
int csize = 3;
int save = 1;
int nsigma = 5;
int nped = 10000;
int ndark = 100;
int ok;
int iprog = 0;
int p=10000;
int fifosize=1000;
int nthreads=10;
int nsubpix=25;
int etabins=nsubpix*10;
double etamin=-1, etamax=2;
int csize=3;
int save=1;
int nsigma=5;
int nped=10000;
int ndark=100;
int ok;
int iprog=0;
int cf=0;
int cf = 0;
#ifdef NEWRECEIVER
#ifdef RECT
cout << "Should be rectangular!" <<endl;
cout << "Should be rectangular!" << endl;
#endif
moench03T1ReceiverDataNew *decoder=new moench03T1ReceiverDataNew();
cout << "RECEIVER DATA WITH ONE HEADER!"<<endl;
moench03T1ReceiverDataNew *decoder = new moench03T1ReceiverDataNew();
cout << "RECEIVER DATA WITH ONE HEADER!" << endl;
#endif
#ifdef CSAXS_FP
moench03T1ReceiverData *decoder=new moench03T1ReceiverData();
cout << "RECEIVER DATA WITH ALL HEADERS!"<<endl;
moench03T1ReceiverData *decoder = new moench03T1ReceiverData();
cout << "RECEIVER DATA WITH ALL HEADERS!" << endl;
#endif
#ifdef OLDDATA
moench03Ctb10GbT1Data *decoder=new moench03Ctb10GbT1Data();
cout << "OLD RECEIVER DATA!"<<endl;
moench03Ctb10GbT1Data *decoder = new moench03Ctb10GbT1Data();
cout << "OLD RECEIVER DATA!" << endl;
#endif
int nx=400, ny=400;
int nx = 400, ny = 400;
decoder->getDetectorSize(nx,ny);
decoder->getDetectorSize(nx, ny);
int ncol_cm=CM_ROWS;
double xt_ghost=C_GHOST;
moench03CommonMode *cm=NULL;
moench03GhostSummation *gs;
double *gainmap=NULL;
float *gm;
int ncol_cm = CM_ROWS;
double xt_ghost = C_GHOST;
moench03CommonMode *cm = NULL;
moench03GhostSummation *gs;
double *gainmap = NULL;
float *gm;
int size = 327680; ////atoi(argv[3]);
int *image;
// int* image =new int[327680/sizeof(int)];
int size = 327680;////atoi(argv[3]);
int* image;
//int* image =new int[327680/sizeof(int)];
int ff, np;
// cout << " data size is " << dsize;
int ff, np;
//cout << " data size is " << dsize;
ifstream filebin;
char *indir = argv[1];
char *outdir = argv[2];
char *fformat = argv[3];
int runmin = 0;
// cout << "argc is " << argc << endl;
if (argc >= 5) {
runmin = atoi(argv[4]);
}
ifstream filebin;
char *indir=argv[1];
char *outdir=argv[2];
char *fformat=argv[3];
int runmin=0;
// cout << "argc is " << argc << endl;
if (argc>=5) {
runmin=atoi(argv[4]);
}
int runmax = runmin;
int runmax=runmin;
if (argc >= 6) {
runmax = atoi(argv[5]);
}
if (argc>=6) {
runmax=atoi(argv[5]);
}
char *pedfile = NULL;
if (argc >= 7) {
pedfile = argv[6];
}
double thr = 0;
double thr1 = 1;
char *pedfile=NULL;
if (argc>=7) {
pedfile=argv[6];
}
double thr=0;
double thr1=1;
if (argc >= 8) {
thr = atof(argv[7]);
}
if (argc>=8) {
thr=atof(argv[7]);
}
int nframes = 0;
int nframes=0;
if (argc>=9) {
nframes=atoi(argv[8]);
}
if (argc >= 9) {
nframes = atoi(argv[8]);
}
int xmin=0, xmax=nx, ymin=0, ymax=ny;
if (argc>=13) {
xmin=atoi(argv[9]);
xmax=atoi(argv[10]);
ymin=atoi(argv[11]);
ymax=atoi(argv[12]);
}
int xmin = 0, xmax = nx, ymin = 0, ymax = ny;
if (argc >= 13) {
xmin = atoi(argv[9]);
xmax = atoi(argv[10]);
ymin = atoi(argv[11]);
ymax = atoi(argv[12]);
}
char *gainfname=NULL;
if (argc>13) {
gainfname=argv[13];
cout << "Gain map file name is: " << gainfname << endl;
}
char *gainfname = NULL;
if (argc > 13) {
gainfname = argv[13];
cout << "Gain map file name is: " << gainfname << endl;
}
char ffname[10000];
char fname[10000];
char imgfname[10000];
char cfname[10000];
char fn[10000];
std::time_t end_time;
char ffname[10000];
char fname[10000];
char imgfname[10000];
char cfname[10000];
char fn[10000];
std::time_t end_time;
FILE *of = NULL;
cout << "input directory is " << indir << endl;
cout << "output directory is " << outdir << endl;
cout << "input file is " << fformat << endl;
cout << "runmin is " << runmin << endl;
cout << "runmax is " << runmax << endl;
if (pedfile)
cout << "pedestal file is " << pedfile << endl;
if (thr > 0)
cout << "threshold is " << thr << endl;
cout << "Nframes is " << nframes << endl;
FILE *of=NULL;
cout << "input directory is " << indir << endl;
cout << "output directory is " << outdir << endl;
cout << "input file is " << fformat << endl;
cout << "runmin is " << runmin << endl;
cout << "runmax is " << runmax << endl;
if (pedfile)
cout << "pedestal file is " << pedfile << endl;
if (thr>0)
cout << "threshold is " << thr << endl;
cout << "Nframes is " << nframes << endl;
uint32_t nnx, nny;
double *gmap;
uint32_t nnx, nny;
double *gmap;
// if (gainfname) {
// gm=ReadFromTiff(gainfname, nny, nnx);
// if (gm && nnx==nx && nny==ny) {
// gmap=new double[nx*ny];
// for (int i=0; i<nx*ny; i++) {
// gmap[i]=gm[i];
// }
// delete gm;
// } else
// cout << "Could not open gain map " << gainfname << endl;
// }
// if (gainfname) {
// gm=ReadFromTiff(gainfname, nny, nnx);
// if (gm && nnx==nx && nny==ny) {
// gmap=new double[nx*ny];
// for (int i=0; i<nx*ny; i++) {
// gmap[i]=gm[i];
// }
// delete gm;
// } else
// cout << "Could not open gain map " << gainfname << endl;
// }
#ifdef CORR
cout << "Applying common mode " << ncol_cm << endl;
cm=new moench03CommonMode(ncol_cm);
cout << "Applying common mode " << ncol_cm << endl;
cm = new moench03CommonMode(ncol_cm);
cout << "Applying ghost corrections " << xt_ghost << endl;
gs=new moench03GhostSummation(decoder, xt_ghost);
cout << "Applying ghost corrections " << xt_ghost << endl;
gs = new moench03GhostSummation(decoder, xt_ghost);
#endif
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, cm, nped, 200, -1, -1, gainmap, gs);
singlePhotonDetector *filter = new singlePhotonDetector(
decoder, csize, nsigma, 1, cm, nped, 200, -1, -1, gainmap, gs);
if (gainfname) {
if (gainfname) {
if (filter->readGainMap(gainfname))
cout << "using gain map " << gainfname << endl;
else
cout << "Could not open gain map " << gainfname << endl;
} else
thr=0.15*thr;
filter->newDataSet();
int dsize=decoder->getDataSize();
if (filter->readGainMap(gainfname))
cout << "using gain map " << gainfname << endl;
else
cout << "Could not open gain map " << gainfname << endl;
} else
thr = 0.15 * thr;
filter->newDataSet();
int dsize = decoder->getDataSize();
char data[dsize];
char data[dsize];
//#ifndef ANALOG
if (thr>0) {
cout << "threshold is " << thr << endl;
//#ifndef ANALOG
filter->setThreshold(thr);
if (thr > 0) {
cout << "threshold is " << thr << endl;
//#ifndef ANALOG
filter->setThreshold(thr);
//#endif
cf = 0;
} else
cf = 1;
//#endif
cf=0;
} else
cf=1;
//#endif
filter->setROI(xmin, xmax, ymin, ymax);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char *buff;
filter->setROI(xmin,xmax,ymin,ymax);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char* buff;
// multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
multiThreadedCountingDetector *mt=new multiThreadedCountingDetector(filter,nthreads,fifosize);
// multiThreadedAnalogDetector *mt=new
// multiThreadedAnalogDetector(filter,nthreads,fifosize);
multiThreadedCountingDetector *mt =
new multiThreadedCountingDetector(filter, nthreads, fifosize);
#ifndef ANALOG
mt->setDetectorMode(ePhotonCounting);
cout << "Counting!" << endl;
if (thr>0) {
cf=0;
}
if (thr > 0) {
cf = 0;
}
#endif
//{
#ifdef ANALOG
mt->setDetectorMode(eAnalog);
cout << "Analog!" << endl;
cf=0;
//thr1=thr;
#endif
// }
mt->StartThreads();
mt->popFree(buff);
mt->setDetectorMode(eAnalog);
cout << "Analog!" << endl;
cf = 0;
// thr1=thr;
#endif
// }
mt->StartThreads();
mt->popFree(buff);
// cout << "mt " << endl;
// cout << "mt " << endl;
int ifr=0;
int ifr = 0;
double ped[nx*ny], *ped1;
double ped[nx * ny], *ped1;
if (pedfile) {
if (pedfile) {
cout << "PEDESTAL " << endl;
sprintf(imgfname, "%s/pedestals.tiff", outdir);
cout << "PEDESTAL " << endl;
sprintf(imgfname,"%s/pedestals.tiff",outdir);
if (string(pedfile).find(".tif") == std::string::npos) {
sprintf(fname, "%s.raw", pedfile);
cout << fname << endl;
std::time(&end_time);
cout << "aaa" << std::ctime(&end_time) << endl;
if (string(pedfile).find(".tif")==std::string::npos){
sprintf(fname,"%s.raw",pedfile);
cout << fname << endl ;
std::time(&end_time);
cout << "aaa" << std::ctime(&end_time) << endl;
mt->setFrameMode(ePedestal);
// sprintf(fn,fformat,irun);
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
if (filebin.is_open()){
ff=-1;
while (decoder->readNextFrame(filebin, ff, np,buff)) {
if (np==40) {
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
ifr++;
if (ifr%100==0)
cout << ifr << " " << ff << " " << np << endl;
} else
cout << ifr << " " << ff << " " << np << endl;
ff=-1;
}
filebin.close();
while (mt->isBusy()) {;}
} else
cout << "Could not open pedestal file "<< fname << " for reading " << endl;
} else {
float *pp=ReadFromTiff(pedfile, nny, nnx);
if (pp && nnx==nx && nny==ny) {
for (int i=0; i<nx*ny; i++) {
ped[i]=pp[i];
}
delete [] pp;
mt->setPedestal(ped);
// ped1=mt->getPedestal();
// for (int i=0; i<nx*ny; i++) {
mt->setFrameMode(ePedestal);
// sprintf(fn,fformat,irun);
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
if (filebin.is_open()) {
ff = -1;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
if (np == 40) {
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
ifr++;
if (ifr % 100 == 0)
cout << ifr << " " << ff << " " << np << endl;
} else
cout << ifr << " " << ff << " " << np << endl;
ff = -1;
}
filebin.close();
while (mt->isBusy()) {
;
}
// cout << ped[i]<<"/"<<ped1[i] << " " ;
// }
cout << "Pedestal set from tiff file " << pedfile << endl;
} else {
cout << "Could not open pedestal tiff file "<< pedfile << " for reading " << endl;
}
} else
cout << "Could not open pedestal file " << fname
<< " for reading " << endl;
} else {
float *pp = ReadFromTiff(pedfile, nny, nnx);
if (pp && nnx == nx && nny == ny) {
for (int i = 0; i < nx * ny; i++) {
ped[i] = pp[i];
}
delete[] pp;
mt->setPedestal(ped);
// ped1=mt->getPedestal();
// for (int i=0; i<nx*ny; i++) {
// cout << ped[i]<<"/"<<ped1[i] << " " ;
// }
cout << "Pedestal set from tiff file " << pedfile << endl;
} else {
cout << "Could not open pedestal tiff file " << pedfile
<< " for reading " << endl;
}
}
mt->writePedestal(imgfname);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
}
mt->writePedestal(imgfname);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
}
ifr = 0;
int ifile = 0;
ifr=0;
int ifile=0;
mt->setFrameMode(eFrame);
mt->setFrameMode(eFrame);
for (int irun=runmin; irun<=runmax; irun++) {
cout << "DATA " ;
// sprintf(fn,fformat,irun);
sprintf(ffname,"%s/%s.raw",indir,fformat);
sprintf(fname,ffname,irun);
sprintf(ffname,"%s/%s.tiff",outdir,fformat);
sprintf(imgfname,ffname,irun);
sprintf(ffname,"%s/%s.clust",outdir,fformat);
sprintf(cfname,ffname,irun);
cout << fname << " " ;
cout << imgfname << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
// cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
ifile=0;
if (filebin.is_open()){
if (thr<=0 && cf!=0) { //cluster finder
if (of==NULL) {
of=fopen(cfname,"w");
if (of) {
mt->setFilePointer(of);
cout << "file pointer set " << endl;
} else {
cout << "Could not open "<< cfname << " for writing " << endl;
mt->setFilePointer(NULL);
return 1;
}
}
}
// //while read frame
ff=-1;
ifr=0;
while (decoder->readNextFrame(filebin, ff, np,buff)) {
if (np==40) {
// cout << "*"<<ifr++<<"*"<<ff<< endl;
// cout << ff << " " << np << endl;
// //push
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
for (int irun = runmin; irun <= runmax; irun++) {
cout << "DATA ";
// sprintf(fn,fformat,irun);
sprintf(ffname, "%s/%s.raw", indir, fformat);
sprintf(fname, ffname, irun);
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
sprintf(imgfname, ffname, irun);
sprintf(ffname, "%s/%s.clust", outdir, fformat);
sprintf(cfname, ffname, irun);
cout << fname << " ";
cout << imgfname << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
// cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
ifile = 0;
if (filebin.is_open()) {
if (thr <= 0 && cf != 0) { // cluster finder
if (of == NULL) {
of = fopen(cfname, "w");
if (of) {
mt->setFilePointer(of);
cout << "file pointer set " << endl;
} else {
cout << "Could not open " << cfname << " for writing "
<< endl;
mt->setFilePointer(NULL);
return 1;
}
}
}
// //while read frame
ff = -1;
ifr = 0;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
if (np == 40) {
// cout << "*"<<ifr++<<"*"<<ff<< endl;
// cout << ff << " " << np << endl;
// //push
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ifr++;
if (ifr % 100 == 0)
cout << ifr << " " << ff << endl;
if (nframes > 0) {
if (ifr % nframes == 0) {
// The name has an additional "_fXXXXX" at the end,
// where "XXXXX" is the initial frame number of the
// image (0,1000,2000...)
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat,
ifile);
sprintf(imgfname, ffname, irun);
// cout << "Writing tiff to " << imgfname << " " <<
// thr1 << endl;
mt->writeImage(imgfname, thr1);
mt->clearImage();
ifile++;
}
}
} else
cout << ifr << " " << ff << " " << np << endl;
ff = -1;
}
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
while (mt->isBusy()) {
;
}
if (nframes >= 0) {
if (nframes > 0) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat, ifile);
sprintf(imgfname, ffname, irun);
} else {
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
sprintf(imgfname, ffname, irun);
}
cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
mt->writeImage(imgfname, thr1);
mt->clearImage();
if (of) {
fclose(of);
of = NULL;
mt->setFilePointer(NULL);
}
}
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
} else
cout << "Could not open " << fname << " for reading " << endl;
}
if (nframes < 0) {
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
strcpy(imgfname, ffname);
cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
mt->writeImage(imgfname, thr1);
}
ifr++;
if (ifr%100==0) cout << ifr << " " << ff << endl;
if (nframes>0) {
if (ifr%nframes==0) {
//The name has an additional "_fXXXXX" at the end, where "XXXXX" is the initial frame number of the image (0,1000,2000...)
sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile);
sprintf(imgfname,ffname,irun);
//cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
mt->writeImage(imgfname, thr1);
mt->clearImage();
ifile++;
}
}
} else
cout << ifr << " " << ff << " " << np << endl;
ff=-1;
}
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
while (mt->isBusy()) {;}
if (nframes>=0) {
if (nframes>0) {
sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile);
sprintf(imgfname,ffname,irun);
} else {
sprintf(ffname,"%s/%s.tiff",outdir,fformat);
sprintf(imgfname,ffname,irun);
}
cout << "Writing tiff to " << imgfname << " " << thr1 <<endl;
mt->writeImage(imgfname, thr1);
mt->clearImage();
if (of) {
fclose(of);
of=NULL;
mt->setFilePointer(NULL);
}
}
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
} else
cout << "Could not open "<< fname << " for reading " << endl;
}
if (nframes<0){
sprintf(ffname,"%s/%s.tiff",outdir,fformat);
strcpy(imgfname,ffname);
cout << "Writing tiff to " << imgfname << " " << thr1 <<endl;
mt->writeImage(imgfname, thr1);
}
return 0;
return 0;
}

File diff suppressed because it is too large Load Diff