mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-22 09:37:59 +02:00
Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer
This commit is contained in:
@ -39,7 +39,7 @@ This document describes the differences between v7.x.x and v7.0.0
|
|||||||
|
|
||||||
|
|
||||||
Eiger 7.0.0
|
Eiger 7.0.0
|
||||||
Jungfrau 7.0.0
|
Jungfrau 7.0.2
|
||||||
Mythen3 7.0.0
|
Mythen3 7.0.0
|
||||||
Gotthard2 7.0.0
|
Gotthard2 7.0.0
|
||||||
Gotthard 7.0.0
|
Gotthard 7.0.0
|
||||||
|
@ -1441,6 +1441,10 @@ class Detector(CppDetectorApi):
|
|||||||
|
|
||||||
@udp_srcip.setter
|
@udp_srcip.setter
|
||||||
def udp_srcip(self, ip):
|
def udp_srcip(self, ip):
|
||||||
|
if ip == "auto":
|
||||||
|
if self.type == detectorType.GOTTHARD:
|
||||||
|
raise NotImplementedError('Auto for udp_srcip cannot be used for GotthardI')
|
||||||
|
ip = socket.gethostbyname(self.hostname[0])
|
||||||
ip = ut.make_ip(ip)
|
ip = ut.make_ip(ip)
|
||||||
ut.set_using_dict(self.setSourceUDPIP, ip)
|
ut.set_using_dict(self.setSourceUDPIP, ip)
|
||||||
|
|
||||||
@ -1467,6 +1471,8 @@ class Detector(CppDetectorApi):
|
|||||||
|
|
||||||
@udp_srcip2.setter
|
@udp_srcip2.setter
|
||||||
def udp_srcip2(self, ip):
|
def udp_srcip2(self, ip):
|
||||||
|
if ip == "auto":
|
||||||
|
ip = socket.gethostbyname(self.hostname)
|
||||||
ip = ut.make_ip(ip)
|
ip = ut.make_ip(ip)
|
||||||
ut.set_using_dict(self.setSourceUDPIP2, ip)
|
ut.set_using_dict(self.setSourceUDPIP2, ip)
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
../slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServerv7.0.0
|
|
@ -1 +0,0 @@
|
|||||||
../slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv7.0.0
|
|
@ -1 +0,0 @@
|
|||||||
../slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServerv7.0.0
|
|
@ -1 +0,0 @@
|
|||||||
../slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServerv7.0.0
|
|
@ -1 +0,0 @@
|
|||||||
../slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServerv7.0.0
|
|
@ -1 +0,0 @@
|
|||||||
../slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServerv7.0.0
|
|
@ -1 +0,0 @@
|
|||||||
../slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServerv7.0.0
|
|
@ -78,7 +78,7 @@ template <class dataType> class analogDetector {
|
|||||||
stat[i] = new pedestalSubtraction[nx];
|
stat[i] = new pedestalSubtraction[nx];
|
||||||
/* pedMean[i]=new double[nx]; */
|
/* pedMean[i]=new double[nx]; */
|
||||||
/* pedVariance[i]=new double[nx]; */
|
/* pedVariance[i]=new double[nx]; */
|
||||||
for (ix = 0; ix < nx; ++ix) {
|
for (int ix = 0; ix < nx; ++ix) {
|
||||||
stat[i][ix].SetNPedestals(nped);
|
stat[i][ix].SetNPedestals(nped);
|
||||||
/* stat[i][ix].setPointers(&(pedMean[iy][ix]),&(pedVariance[iy][ix]));
|
/* stat[i][ix].setPointers(&(pedMean[iy][ix]),&(pedVariance[iy][ix]));
|
||||||
*/
|
*/
|
||||||
@ -166,8 +166,8 @@ template <class dataType> class analogDetector {
|
|||||||
int nped = orig->SetNPedestals();
|
int nped = orig->SetNPedestals();
|
||||||
// cout << nped << " " << orig->getPedestal(ix,iy) <<
|
// cout << nped << " " << orig->getPedestal(ix,iy) <<
|
||||||
// orig->getPedestalRMS(ix,iy) << endl;
|
// orig->getPedestalRMS(ix,iy) << endl;
|
||||||
for (iy = 0; iy < ny; ++iy) {
|
for (int iy = 0; iy < ny; ++iy) {
|
||||||
for (ix = 0; ix < nx; ++ix) {
|
for (int ix = 0; ix < nx; ++ix) {
|
||||||
// stat[iy][ix].setPointers(&(pedMean[iy][ix]),&(pedVariance[iy][ix]));
|
// stat[iy][ix].setPointers(&(pedMean[iy][ix]),&(pedVariance[iy][ix]));
|
||||||
stat[iy][ix].SetNPedestals(nped);
|
stat[iy][ix].SetNPedestals(nped);
|
||||||
setPedestal(ix, iy, orig->getPedestal(ix, iy),
|
setPedestal(ix, iy, orig->getPedestal(ix, iy),
|
||||||
@ -298,8 +298,8 @@ template <class dataType> class analogDetector {
|
|||||||
if (gmap)
|
if (gmap)
|
||||||
delete[] gmap;
|
delete[] gmap;
|
||||||
gmap = new double[nnx * nny];
|
gmap = new double[nnx * nny];
|
||||||
for (iy = 0; iy < static_cast<int>(nny); ++iy) {
|
for (int iy = 0; iy < static_cast<int>(nny); ++iy) {
|
||||||
for (ix = 0; ix < static_cast<int>(nnx); ++ix) {
|
for (int ix = 0; ix < static_cast<int>(nnx); ++ix) {
|
||||||
gmap[iy * nnx + ix] = gm[iy * nnx + ix];
|
gmap[iy * nnx + ix] = gm[iy * nnx + ix];
|
||||||
// cout << gmap[iy*nnx+ix] << " " ;
|
// cout << gmap[iy*nnx+ix] << " " ;
|
||||||
}
|
}
|
||||||
@ -319,8 +319,8 @@ template <class dataType> class analogDetector {
|
|||||||
void *ret;
|
void *ret;
|
||||||
if (gmap) {
|
if (gmap) {
|
||||||
gm = new float[nx * ny];
|
gm = new float[nx * ny];
|
||||||
for (iy = 0; iy < ny; ++iy) {
|
for (int iy = 0; iy < ny; ++iy) {
|
||||||
for (ix = 0; ix < nx; ++ix) {
|
for (int ix = 0; ix < nx; ++ix) {
|
||||||
gm[iy * nx + ix] = gmap[iy * nx + ix];
|
gm[iy * nx + ix] = gmap[iy * nx + ix];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,8 +335,8 @@ template <class dataType> class analogDetector {
|
|||||||
|
|
||||||
virtual void newDataSet() {
|
virtual void newDataSet() {
|
||||||
iframe = -1;
|
iframe = -1;
|
||||||
for (iy = 0; iy < ny; ++iy)
|
for (int iy = 0; iy < ny; ++iy)
|
||||||
for (ix = 0; ix < nx; ++ix) {
|
for (int ix = 0; ix < nx; ++ix) {
|
||||||
stat[iy][ix].Clear();
|
stat[iy][ix].Clear();
|
||||||
image[iy * nx + ix] = 0;
|
image[iy * nx + ix] = 0;
|
||||||
}
|
}
|
||||||
@ -445,8 +445,8 @@ template <class dataType> class analogDetector {
|
|||||||
// cout << "+"<< getId() << endl;
|
// cout << "+"<< getId() << endl;
|
||||||
if (cmSub) {
|
if (cmSub) {
|
||||||
// cout << "*" << endl;
|
// cout << "*" << endl;
|
||||||
for (iy = ymin; iy < ymax; ++iy) {
|
for (int iy = ymin; iy < ymax; ++iy) {
|
||||||
for (ix = xmin; ix < xmax; ++ix) {
|
for (int ix = xmin; ix < xmax; ++ix) {
|
||||||
// if (getNumpedestals(ix,iy)>0)
|
// if (getNumpedestals(ix,iy)>0)
|
||||||
// if (det->isGood(ix,iy)) {
|
// if (det->isGood(ix,iy)) {
|
||||||
addToCommonMode(data, ix, iy);
|
addToCommonMode(data, ix, iy);
|
||||||
@ -539,8 +539,8 @@ template <class dataType> class analogDetector {
|
|||||||
if (ped == NULL) {
|
if (ped == NULL) {
|
||||||
ped = new double[nx * ny];
|
ped = new double[nx * ny];
|
||||||
}
|
}
|
||||||
for (iy = 0; iy < ny; ++iy) {
|
for (int iy = 0; iy < ny; ++iy) {
|
||||||
for (ix = 0; ix < nx; ++ix) {
|
for (int ix = 0; ix < nx; ++ix) {
|
||||||
ped[iy * nx + ix] = stat[iy][ix].getPedestal();
|
ped[iy * nx + ix] = stat[iy][ix].getPedestal();
|
||||||
// cout << ped[iy*nx+ix] << " " ;
|
// cout << ped[iy*nx+ix] << " " ;
|
||||||
}
|
}
|
||||||
@ -558,8 +558,8 @@ template <class dataType> class analogDetector {
|
|||||||
if (ped == NULL) {
|
if (ped == NULL) {
|
||||||
ped = new double[nx * ny];
|
ped = new double[nx * ny];
|
||||||
}
|
}
|
||||||
for (iy = 0; iy < ny; ++iy) {
|
for (int iy = 0; iy < ny; ++iy) {
|
||||||
for (ix = 0; ix < nx; ++ix) {
|
for (int ix = 0; ix < nx; ++ix) {
|
||||||
ped[iy * nx + ix] = stat[iy][ix].getPedestalRMS();
|
ped[iy * nx + ix] = stat[iy][ix].getPedestalRMS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,8 +592,8 @@ template <class dataType> class analogDetector {
|
|||||||
*/
|
*/
|
||||||
virtual void setPedestal(double *ped, double *rms = NULL, int m = -1) {
|
virtual void setPedestal(double *ped, double *rms = NULL, int m = -1) {
|
||||||
double rr = 0;
|
double rr = 0;
|
||||||
for (iy = ymin; iy < ymax; ++iy) {
|
for (int iy = ymin; iy < ymax; ++iy) {
|
||||||
for (ix = xmin; ix < xmax; ++ix) {
|
for (int ix = xmin; ix < xmax; ++ix) {
|
||||||
if (rms)
|
if (rms)
|
||||||
rr = rms[iy * nx + ix];
|
rr = rms[iy * nx + ix];
|
||||||
stat[iy][ix].setPedestal(ped[iy * nx + ix], rr, m);
|
stat[iy][ix].setPedestal(ped[iy * nx + ix], rr, m);
|
||||||
@ -619,8 +619,8 @@ template <class dataType> class analogDetector {
|
|||||||
\param rms pointer to array of pedestal rms
|
\param rms pointer to array of pedestal rms
|
||||||
*/
|
*/
|
||||||
virtual void setPedestalRMS(double *rms) {
|
virtual void setPedestalRMS(double *rms) {
|
||||||
for (iy = ymin; iy < ymax; ++iy) {
|
for (int iy = ymin; iy < ymax; ++iy) {
|
||||||
for (ix = xmin; ix < xmax; ++ix) {
|
for (int ix = xmin; ix < xmax; ++ix) {
|
||||||
stat[iy][ix].setPedestalRMS(rms[iy * nx + ix]);
|
stat[iy][ix].setPedestalRMS(rms[iy * nx + ix]);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -662,8 +662,8 @@ template <class dataType> class analogDetector {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
gm = new float[nx * ny];
|
gm = new float[nx * ny];
|
||||||
for (iy = 0; iy < ny; ++iy) {
|
for (int iy = 0; iy < ny; ++iy) {
|
||||||
for (ix = 0; ix < nx; ++ix) {
|
for (int ix = 0; ix < nx; ++ix) {
|
||||||
gm[iy * nx + ix] = image[iy * nx + ix];
|
gm[iy * nx + ix] = image[iy * nx + ix];
|
||||||
#ifdef ROOTSPECTRUM
|
#ifdef ROOTSPECTRUM
|
||||||
hmap->SetBinContent(ix + 1, iy + 1, image[iy * nx + ix]);
|
hmap->SetBinContent(ix + 1, iy + 1, image[iy * nx + ix]);
|
||||||
@ -710,8 +710,8 @@ template <class dataType> class analogDetector {
|
|||||||
new TH2F("hmap", "hmap", nx, -0.5, nx - 0.5, ny, -0.5, ny - 0.5);
|
new TH2F("hmap", "hmap", nx, -0.5, nx - 0.5, ny, -0.5, ny - 0.5);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
for (iy = 0; iy < ny; ++iy) {
|
for (int iy = 0; iy < ny; ++iy) {
|
||||||
for (ix = 0; ix < nx; ++ix) {
|
for (int ix = 0; ix < nx; ++ix) {
|
||||||
/* if (cmSub) */
|
/* if (cmSub) */
|
||||||
/* gm[iy*nx+ix]=stat[iy][ix].getPedestal()-cmSub->getCommonMode();
|
/* gm[iy*nx+ix]=stat[iy][ix].getPedestal()-cmSub->getCommonMode();
|
||||||
*/
|
*/
|
||||||
@ -758,8 +758,8 @@ template <class dataType> class analogDetector {
|
|||||||
nny = ny;
|
nny = ny;
|
||||||
|
|
||||||
if (gm) {
|
if (gm) {
|
||||||
for (iy = 0; iy < nny; ++iy) {
|
for (int iy = 0; iy < nny; ++iy) {
|
||||||
for (ix = 0; ix < nnx; ++ix) {
|
for (int ix = 0; ix < nnx; ++ix) {
|
||||||
stat[iy][ix].setPedestal(gm[iy * nx + ix], -1, -1);
|
stat[iy][ix].setPedestal(gm[iy * nx + ix], -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -783,8 +783,8 @@ template <class dataType> class analogDetector {
|
|||||||
nny = ny;
|
nny = ny;
|
||||||
|
|
||||||
if (gm) {
|
if (gm) {
|
||||||
for (iy = 0; iy < nny; ++iy) {
|
for (int iy = 0; iy < nny; ++iy) {
|
||||||
for (ix = 0; ix < nnx; ++ix) {
|
for (int ix = 0; ix < nnx; ++ix) {
|
||||||
image[iy * nx + ix] = gm[iy * nx + ix];
|
image[iy * nx + ix] = gm[iy * nx + ix];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -808,8 +808,8 @@ template <class dataType> class analogDetector {
|
|||||||
float *gm = NULL;
|
float *gm = NULL;
|
||||||
void *ret;
|
void *ret;
|
||||||
gm = new float[nx * ny];
|
gm = new float[nx * ny];
|
||||||
for (iy = 0; iy < ny; ++iy) {
|
for (int iy = 0; iy < ny; ++iy) {
|
||||||
for (ix = 0; ix < nx; ++ix) {
|
for (int ix = 0; ix < nx; ++ix) {
|
||||||
gm[iy * nx + ix] = stat[iy][ix].getPedestalRMS();
|
gm[iy * nx + ix] = stat[iy][ix].getPedestalRMS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -832,8 +832,8 @@ template <class dataType> class analogDetector {
|
|||||||
if (nny > ny)
|
if (nny > ny)
|
||||||
nny = ny;
|
nny = ny;
|
||||||
if (gm) {
|
if (gm) {
|
||||||
for (iy = 0; iy < nny; ++iy) {
|
for (uint32_t iy = 0; iy < nny; ++iy) {
|
||||||
for (ix = 0; ix < nnx; ++ix) {
|
for (uint32_t ix = 0; ix < nnx; ++ix) {
|
||||||
stat[iy][ix].setPedestalRMS(gm[iy * nx + ix]);
|
stat[iy][ix].setPedestalRMS(gm[iy * nx + ix]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -862,8 +862,8 @@ template <class dataType> class analogDetector {
|
|||||||
|
|
||||||
// cout << xmin << " " << xmax << endl;
|
// cout << xmin << " " << xmax << endl;
|
||||||
// cout << ymin << " " << ymax << endl;
|
// cout << ymin << " " << ymax << endl;
|
||||||
for (iy = ymin; iy < ymax; ++iy) {
|
for (int iy = ymin; iy < ymax; ++iy) {
|
||||||
for (ix = xmin; ix < xmax; ++ix) {
|
for (int ix = xmin; ix < xmax; ++ix) {
|
||||||
if (det->isGood(ix, iy)) {
|
if (det->isGood(ix, iy)) {
|
||||||
// addToPedestal(data,ix,iy,1);
|
// addToPedestal(data,ix,iy,1);
|
||||||
addToPedestal(data, ix, iy, cm);
|
addToPedestal(data, ix, iy, cm);
|
||||||
@ -997,14 +997,13 @@ template <class dataType> class analogDetector {
|
|||||||
virtual int *subtractPedestal(char *data, int *val = NULL, int cm = 0) {
|
virtual int *subtractPedestal(char *data, int *val = NULL, int cm = 0) {
|
||||||
|
|
||||||
newFrame(data);
|
newFrame(data);
|
||||||
|
|
||||||
if (val == NULL)
|
if (val == NULL)
|
||||||
val = image; // new double[nx*ny];
|
val = image; // new double[nx*ny];
|
||||||
|
|
||||||
// calcGhost(data);
|
// calcGhost(data);
|
||||||
|
|
||||||
for (iy = ymin; iy < ymax; ++iy) {
|
for (int iy = ymin; iy < ymax; ++iy) {
|
||||||
for (ix = xmin; ix < xmax; ++ix) {
|
for (int ix = xmin; ix < xmax; ++ix) {
|
||||||
if (det->isGood(ix, iy))
|
if (det->isGood(ix, iy))
|
||||||
val[iy * nx + ix] += subtractPedestal(data, ix, iy, cm);
|
val[iy * nx + ix] += subtractPedestal(data, ix, iy, cm);
|
||||||
}
|
}
|
||||||
@ -1152,8 +1151,6 @@ template <class dataType> class analogDetector {
|
|||||||
image is used \returns pointer to array containing the number of photons
|
image is used \returns pointer to array containing the number of photons
|
||||||
*/
|
*/
|
||||||
virtual int *getNPhotons(char *data, int *nph = NULL) {
|
virtual int *getNPhotons(char *data, int *nph = NULL) {
|
||||||
|
|
||||||
// double val;
|
|
||||||
if (nph == NULL)
|
if (nph == NULL)
|
||||||
nph = image;
|
nph = image;
|
||||||
|
|
||||||
@ -1169,8 +1166,8 @@ template <class dataType> class analogDetector {
|
|||||||
/* } */
|
/* } */
|
||||||
// calcGhost(data);
|
// calcGhost(data);
|
||||||
addToCommonMode(data);
|
addToCommonMode(data);
|
||||||
for (iy = ymin; iy < ymax; ++iy) {
|
for (int iy = ymin; iy < ymax; ++iy) {
|
||||||
for (ix = xmin; ix < xmax; ++ix) {
|
for (int ix = xmin; ix < xmax; ++ix) {
|
||||||
switch (fMode) {
|
switch (fMode) {
|
||||||
case eRaw:
|
case eRaw:
|
||||||
// cout << "raw" << endl;
|
// cout << "raw" << endl;
|
||||||
@ -1190,8 +1187,8 @@ template <class dataType> class analogDetector {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
virtual void clearImage() {
|
virtual void clearImage() {
|
||||||
for (iy = 0; iy < ny; ++iy) {
|
for (int iy = 0; iy < ny; ++iy) {
|
||||||
for (ix = 0; ix < nx; ++ix) {
|
for (int ix = 0; ix < nx; ++ix) {
|
||||||
image[iy * nx + ix] = 0;
|
image[iy * nx + ix] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1219,10 +1216,9 @@ template <class dataType> class analogDetector {
|
|||||||
\returns actual number of samples
|
\returns actual number of samples
|
||||||
*/
|
*/
|
||||||
int SetNPedestals(int i = -1) {
|
int SetNPedestals(int i = -1) {
|
||||||
int ix = 0, iy = 0;
|
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
for (iy = 0; iy < ny; ++iy)
|
for (int iy = 0; iy < ny; ++iy)
|
||||||
for (ix = 0; ix < nx; ++ix)
|
for (int ix = 0; ix < nx; ++ix)
|
||||||
stat[iy][ix].SetNPedestals(i);
|
stat[iy][ix].SetNPedestals(i);
|
||||||
return stat[0][0].SetNPedestals();
|
return stat[0][0].SetNPedestals();
|
||||||
};
|
};
|
||||||
@ -1264,8 +1260,8 @@ template <class dataType> class analogDetector {
|
|||||||
newFrame(data);
|
newFrame(data);
|
||||||
// calcGhost(data);
|
// calcGhost(data);
|
||||||
addToCommonMode(data);
|
addToCommonMode(data);
|
||||||
for (iy = ymi; iy < yma; ++iy)
|
for (int iy = ymi; iy < yma; ++iy)
|
||||||
for (ix = xmi; ix < xma; ++ix)
|
for (int ix = xmi; ix < xma; ++ix)
|
||||||
if (det->isGood(ix, iy)) {
|
if (det->isGood(ix, iy)) {
|
||||||
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny)
|
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny)
|
||||||
val += convertToPhotons(data, ix, iy);
|
val += convertToPhotons(data, ix, iy);
|
||||||
@ -1379,7 +1375,6 @@ template <class dataType> class analogDetector {
|
|||||||
frameMode fMode; /**< current detector frame mode */
|
frameMode fMode; /**< current detector frame mode */
|
||||||
detectorMode dMode; /**< current detector frame mode */
|
detectorMode dMode; /**< current detector frame mode */
|
||||||
FILE *myFile; /**< file pointer to write to */
|
FILE *myFile; /**< file pointer to write to */
|
||||||
int ix, iy;
|
|
||||||
#ifdef ROOTSPECTRUM
|
#ifdef ROOTSPECTRUM
|
||||||
TH2F *hs;
|
TH2F *hs;
|
||||||
#ifdef ROOTCLUST
|
#ifdef ROOTCLUST
|
||||||
|
@ -407,8 +407,8 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
|
|||||||
//int pn;
|
//int pn;
|
||||||
|
|
||||||
//std::cout << dataSize << std::endl;
|
//std::cout << dataSize << std::endl;
|
||||||
if (ff >= 0)
|
//if (ff >= 0) {
|
||||||
// fnum = ff;
|
// fnum = ff; }
|
||||||
|
|
||||||
if (filebin.is_open()) {
|
if (filebin.is_open()) {
|
||||||
if (filebin.read(data, dataSize)) {
|
if (filebin.read(data, dataSize)) {
|
||||||
@ -417,6 +417,9 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
|
|||||||
np = getPacketNumber(data);
|
np = getPacketNumber(data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
std::cout << "#";
|
||||||
|
} else {
|
||||||
|
std::cout << "File not open" << std::endl;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
#ifndef JUNGFRAUMODULEDATA_H
|
#ifndef JUNGFRAUMODULEDATA_H
|
||||||
#define JUNGFRAUMODULEDATA_H
|
#define JUNGFRAUMODULEDATA_H
|
||||||
|
#include <cstdint>
|
||||||
#include "slsDetectorData.h"
|
#include "slsDetectorData.h"
|
||||||
|
|
||||||
//#define VERSION_V2
|
//#define VERSION_V2
|
||||||
|
@ -51,6 +51,7 @@ class interpolatingDetector : public singlePhotonDetector {
|
|||||||
// cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax <<
|
// cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax <<
|
||||||
// endl;
|
// endl;
|
||||||
fi = new pthread_mutex_t;
|
fi = new pthread_mutex_t;
|
||||||
|
pthread_mutex_init(fi, NULL);
|
||||||
};
|
};
|
||||||
|
|
||||||
interpolatingDetector(interpolatingDetector *orig)
|
interpolatingDetector(interpolatingDetector *orig)
|
||||||
|
@ -14,7 +14,7 @@ target_compile_definitions(jungfrauRawDataProcess PRIVATE MODULE)
|
|||||||
list(APPEND JUNGFRAU_EXECUTABLES jungfrauRawDataProcess)
|
list(APPEND JUNGFRAU_EXECUTABLES jungfrauRawDataProcess)
|
||||||
|
|
||||||
# jungfrauRawDataProcessStrx
|
# jungfrauRawDataProcessStrx
|
||||||
add_executable(jungfrauRawDataProcessStrx jungfrauRawDataProcess.cpp)
|
add_executable(jungfrauRawDataProcessStrx jungfrauRawDataProcess_filetxt.cpp)
|
||||||
target_compile_definitions(jungfrauRawDataProcessStrx PRIVATE JFSTRX)
|
target_compile_definitions(jungfrauRawDataProcessStrx PRIVATE JFSTRX)
|
||||||
list(APPEND JUNGFRAU_EXECUTABLES jungfrauRawDataProcessStrx)
|
list(APPEND JUNGFRAU_EXECUTABLES jungfrauRawDataProcessStrx)
|
||||||
|
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
#module add CBFlib/0.9.5
|
#module add CBFlib/0.9.5
|
||||||
|
|
||||||
|
|
||||||
INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ -I../tiffio/include
|
INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ -I../tiffio/include -I/afs/psi/project/sls_det_software/conda/envs/pyclang_fmt/include/
|
||||||
|
|
||||||
LDFLAG= ../tiffio/src/tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -pthread -lrt -ltiff -O3 -std=c++11
|
LDFLAG= ../tiffio/src/tiffIO.cpp -L/afs/psi/project/sls_det_software/conda/envs/pyclang_fmt/lib/ -L/usr/lib64/ -lpthread -lm -lstdc++ -pthread -lrt -ltiff -O3 -std=c++11 -lfmt
|
||||||
|
#-L/afs/psi/project/sls_det_software/conda/envs/pyclang_fmt/lib/
|
||||||
|
#THE ORDER OF LIBRARIES MATTERS!
|
||||||
|
|
||||||
MAIN=jungfrauClusterFinder.cpp
|
MAIN=jungfrauClusterFinder.cpp
|
||||||
|
|
||||||
|
@ -41,12 +41,38 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
|
|
||||||
|
std::string getRootString( const std::string& filepath ) {
|
||||||
|
size_t pos1 = filepath.find_last_of("/");
|
||||||
|
size_t pos2 = filepath.find_last_of(".");
|
||||||
|
std::cout << "pos1 " << pos1 << " pos2 " << pos2 << " size " << filepath.length() << std::endl;
|
||||||
|
return filepath.substr( pos1+1, pos2-pos1-1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create file name string according to slsDetectorPackage format
|
||||||
|
// dir: directory
|
||||||
|
// fprefix: fileprefix (without extension)
|
||||||
|
// fsuffix: filesuffix (for output files, e.g. "ped")
|
||||||
|
// fext: file extension (e.g. "raw")
|
||||||
|
// mindex: module index ("d0" in standard)
|
||||||
|
// findex: file index for one acquisition ("f0")
|
||||||
|
// aindex: acquisition index (i.e. "run number")
|
||||||
|
|
||||||
|
std::string createFileName( const std::string& dir, const std::string& fprefix="run", const std::string& fsuffix="", const std::string& fext="raw", int aindex=0, int mindex=0, int findex=0, int outfilecounter=-1 ) {
|
||||||
|
if (outfilecounter >= 0)
|
||||||
|
return fmt::format("{:s}/{:s}_d{:d}_f{:d}_{:d}_f{:05d}.{:s}", dir, fprefix, mindex, findex, aindex, outfilecounter, fext);
|
||||||
|
else if (fsuffix.length()!=0)
|
||||||
|
return fmt::format("{:s}/{:s}_{:s}.{:s}", dir, fprefix, fsuffix, fext);
|
||||||
|
else
|
||||||
|
return fmt::format("{:s}/{:s}_d{:d}_f{:d}_{:d}.{:s}", dir, fprefix, mindex, findex, aindex, fext);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
if (argc < 5) {
|
if (argc < 5) {
|
||||||
std::cout
|
std::cout
|
||||||
<< "Usage is " << argv[0]
|
<< "Usage is " << argv[0]
|
||||||
<< "indir outdir fname(with formatting, no extension) fextension "
|
<< "indir outdir fprefix(excluding slsDetector standard suffixes and extension) fextension "
|
||||||
"[runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
|
"[runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
|
||||||
"[nframes] [xmin xmax ymin ymax] [gainmap]"
|
"[nframes] [xmin xmax ymin ymax] [gainmap]"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@ -75,11 +101,11 @@ int main(int argc, char *argv[]) {
|
|||||||
int ff, np;
|
int ff, np;
|
||||||
// cout << " data size is " << dsize;
|
// cout << " data size is " << dsize;
|
||||||
|
|
||||||
ifstream filebin;
|
//ifstream filebin;
|
||||||
char *indir = argv[1];
|
std::string indir(argv[1]);
|
||||||
char *outdir = argv[2];
|
std::string outdir(argv[2]);
|
||||||
char *fformat = argv[3];
|
std::string fprefix(argv[3]);
|
||||||
char *fext = argv[4];
|
std::string fext(argv[4]);
|
||||||
int runmin = 0;
|
int runmin = 0;
|
||||||
|
|
||||||
// cout << "argc is " << argc << endl;
|
// cout << "argc is " << argc << endl;
|
||||||
@ -93,9 +119,9 @@ int main(int argc, char *argv[]) {
|
|||||||
runmax = atoi(argv[6]);
|
runmax = atoi(argv[6]);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pedfile = NULL;
|
std::string pedfilename{};
|
||||||
if (argc >= 8) {
|
if (argc >= 8) {
|
||||||
pedfile = argv[7];
|
pedfilename = argv[7];
|
||||||
}
|
}
|
||||||
double thr = 0;
|
double thr = 0;
|
||||||
double thr1 = 1;
|
double thr1 = 1;
|
||||||
@ -110,11 +136,6 @@ int main(int argc, char *argv[]) {
|
|||||||
nframes = atoi(argv[9]);
|
nframes = atoi(argv[9]);
|
||||||
}
|
}
|
||||||
|
|
||||||
char ffname[10000];
|
|
||||||
char fname[10000];
|
|
||||||
char imgfname[10000];
|
|
||||||
char cfname[10000];
|
|
||||||
|
|
||||||
// Define decoders...
|
// Define decoders...
|
||||||
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
|
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
|
||||||
!defined JFSTRXCHIP6
|
!defined JFSTRXCHIP6
|
||||||
@ -137,6 +158,7 @@ int main(int argc, char *argv[]) {
|
|||||||
uint16_t yymax = 0;
|
uint16_t yymax = 0;
|
||||||
|
|
||||||
#ifndef ALDO
|
#ifndef ALDO
|
||||||
|
{ //THIS SCOPE IS IMPORTANT! (To ensure proper destruction of ifstream)
|
||||||
using header = sls::defs::sls_receiver_header;
|
using header = sls::defs::sls_receiver_header;
|
||||||
// check if there is a roi in the header
|
// check if there is a roi in the header
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -146,15 +168,15 @@ int main(int argc, char *argv[]) {
|
|||||||
uint16_t ymax;
|
uint16_t ymax;
|
||||||
} receiverRoi_compact;
|
} receiverRoi_compact;
|
||||||
receiverRoi_compact croi;
|
receiverRoi_compact croi;
|
||||||
sprintf(ffname, "%s/%s.%s", indir, fformat, fext);
|
std::string fsuffix{};
|
||||||
sprintf(fname, (const char *)ffname, runmin);
|
auto filename = createFileName( indir, fprefix, fsuffix, fext, runmin );
|
||||||
std::cout << "Reading header of file " << fname << " to check for ROI "
|
std::cout << "Reading header of file " << filename << " to check for ROI "
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
ifstream firstfile(filename, ios::in | ios::binary);
|
||||||
if (filebin.is_open()) {
|
if (firstfile.is_open()) {
|
||||||
header hbuffer;
|
header hbuffer;
|
||||||
std::cout << "sizeof(header) = " << sizeof(header) << std::endl;
|
std::cout << "sizeof(header) = " << sizeof(header) << std::endl;
|
||||||
if (filebin.read((char *)&hbuffer, sizeof(header))) {
|
if (firstfile.read((char *)&hbuffer, sizeof(header))) {
|
||||||
memcpy(&croi, &hbuffer.detHeader.detSpec1, 8);
|
memcpy(&croi, &hbuffer.detHeader.detSpec1, 8);
|
||||||
std::cout << "Read ROI [" << croi.xmin << ", " << croi.xmax << ", "
|
std::cout << "Read ROI [" << croi.xmin << ", " << croi.xmax << ", "
|
||||||
<< croi.ymin << ", " << croi.ymax << "]" << std::endl;
|
<< croi.ymin << ", " << croi.ymax << "]" << std::endl;
|
||||||
@ -164,9 +186,10 @@ int main(int argc, char *argv[]) {
|
|||||||
yymax = croi.ymax;
|
yymax = croi.ymax;
|
||||||
} else
|
} else
|
||||||
std::cout << "reading error" << std::endl;
|
std::cout << "reading error" << std::endl;
|
||||||
filebin.close();
|
firstfile.close();
|
||||||
} else
|
} else
|
||||||
std::cout << "Could not open " << fname << " for reading " << std::endl;
|
std::cout << "Could not open " << filename << " for reading " << std::endl;
|
||||||
|
} //end of protective scope
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
jungfrauLGADStrixelsData *decoder =
|
jungfrauLGADStrixelsData *decoder =
|
||||||
@ -213,14 +236,13 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
std::time_t end_time;
|
std::time_t end_time;
|
||||||
|
|
||||||
FILE *of = NULL;
|
|
||||||
std::cout << "input directory is " << indir << std::endl;
|
std::cout << "input directory is " << indir << std::endl;
|
||||||
std::cout << "output directory is " << outdir << std::endl;
|
std::cout << "output directory is " << outdir << std::endl;
|
||||||
std::cout << "input file is " << fformat << std::endl;
|
std::cout << "input file prefix is " << fprefix << std::endl;
|
||||||
std::cout << "runmin is " << runmin << std::endl;
|
std::cout << "runmin is " << runmin << std::endl;
|
||||||
std::cout << "runmax is " << runmax << std::endl;
|
std::cout << "runmax is " << runmax << std::endl;
|
||||||
if (pedfile)
|
if (pedfilename.length()!=0)
|
||||||
std::cout << "pedestal file is " << pedfile << std::endl;
|
std::cout << "pedestal file is " << pedfilename << std::endl;
|
||||||
if (thr > 0)
|
if (thr > 0)
|
||||||
std::cout << "threshold is " << thr << std::endl;
|
std::cout << "threshold is " << thr << std::endl;
|
||||||
std::cout << "Nframes is " << nframes << std::endl;
|
std::cout << "Nframes is " << nframes << std::endl;
|
||||||
@ -256,8 +278,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
char *buff;
|
char *buff;
|
||||||
|
|
||||||
// multiThreadedAnalogDetector *mt=new
|
|
||||||
// multiThreadedAnalogDetector(filter,nthreads,fifosize);
|
|
||||||
multiThreadedCountingDetector *mt =
|
multiThreadedCountingDetector *mt =
|
||||||
new multiThreadedCountingDetector(filter, nthreads, fifosize);
|
new multiThreadedCountingDetector(filter, nthreads, fifosize);
|
||||||
mt->setClusterSize(csize, csize);
|
mt->setClusterSize(csize, csize);
|
||||||
@ -285,43 +305,32 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
int ifr = 0;
|
int ifr = 0;
|
||||||
|
|
||||||
char froot[1000];
|
if (pedfilename.length()!=0) {
|
||||||
double *ped = new double[nx * ny]; //, *ped1;
|
|
||||||
|
|
||||||
int pos, pos1;
|
std::string froot = getRootString(pedfilename);
|
||||||
|
|
||||||
if (pedfile) {
|
|
||||||
|
|
||||||
if (string(pedfile).find(".dat") != std::string::npos) {
|
|
||||||
pos1 = string(pedfile).rfind("/");
|
|
||||||
strcpy(froot, pedfile + pos1);
|
|
||||||
pos = string(froot).find(".dat");
|
|
||||||
froot[pos] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "PEDESTAL " << std::endl;
|
std::cout << "PEDESTAL " << std::endl;
|
||||||
// sprintf(imgfname, "%s/pedestals.tiff", outdir);
|
|
||||||
|
|
||||||
if (string(pedfile).find(".tif") == std::string::npos) {
|
if (pedfilename.find(".tif") == std::string::npos) {
|
||||||
sprintf(fname, "%s", pedfile);
|
std::string fname = pedfilename;
|
||||||
std::cout << fname << std::endl;
|
std::cout << fname << std::endl;
|
||||||
std::time(&end_time);
|
std::time(&end_time);
|
||||||
std::cout << "aaa " << std::ctime(&end_time) << std::endl;
|
std::cout << "aaa " << std::ctime(&end_time) << std::endl;
|
||||||
|
|
||||||
mt->setFrameMode(ePedestal);
|
mt->setFrameMode(ePedestal);
|
||||||
// sprintf(fn,fformat,irun);
|
|
||||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
ifstream pedefile(fname, ios::in | ios::binary);
|
||||||
// //open file
|
// //open file
|
||||||
if (filebin.is_open()) {
|
if (pedefile.is_open()) {
|
||||||
std::cout << "bbbb " << std::ctime(&end_time) << std::endl;
|
std::cout << "bbbb " << std::ctime(&end_time) << std::endl;
|
||||||
|
|
||||||
ff = -1;
|
ff = -1;
|
||||||
while (decoder->readNextFrame(filebin, ff, np, buff)) {
|
while (decoder->readNextFrame(pedefile, ff, np, buff)) {
|
||||||
// if (np == 40) {
|
// if (np == 40) {
|
||||||
if ((ifr + 1) % 100 == 0) {
|
if ((ifr + 1) % 100 == 0) {
|
||||||
std::cout
|
std::cout
|
||||||
<< " ****"
|
<< " ****"
|
||||||
<< decoder->getValue(buff, 20, 20); // << endl;
|
<< decoder->getValue(buff, 20, 20); // << std::endl;
|
||||||
}
|
}
|
||||||
mt->pushData(buff);
|
mt->pushData(buff);
|
||||||
mt->nextThread();
|
mt->nextThread();
|
||||||
@ -331,36 +340,38 @@ int main(int argc, char *argv[]) {
|
|||||||
std::cout << " ****" << ifr << " " << ff << " " << np
|
std::cout << " ****" << ifr << " " << ff << " " << np
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
} // else
|
} // else
|
||||||
// cout << ifr << " " << ff << " " << np << endl;
|
//std::cout << ifr << " " << ff << " " << np << std::endl;
|
||||||
if (ifr >= 1000)
|
if (ifr >= 1000)
|
||||||
break;
|
break;
|
||||||
ff = -1;
|
ff = -1;
|
||||||
}
|
}
|
||||||
filebin.close();
|
pedefile.close();
|
||||||
while (mt->isBusy()) {
|
while (mt->isBusy()) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(imgfname, "%s/%s_ped.tiff", outdir, froot);
|
std::cout << "froot " << froot << std::endl;
|
||||||
mt->writePedestal(imgfname);
|
auto imgfname = createFileName( outdir, froot, "ped", "tiff");
|
||||||
sprintf(imgfname, "%s/%s_rms.tiff", outdir, froot);
|
mt->writePedestal(imgfname.c_str());
|
||||||
mt->writePedestalRMS(imgfname);
|
imgfname = createFileName( outdir, froot, "rms", "tiff");
|
||||||
|
mt->writePedestalRMS(imgfname.c_str());
|
||||||
|
|
||||||
} else
|
} else
|
||||||
std::cout << "Could not open pedestal file " << fname
|
std::cout << "Could not open pedestal file " << fname
|
||||||
<< " for reading " << std::endl;
|
<< " for reading " << std::endl;
|
||||||
} else {
|
} else {
|
||||||
float *pp = ReadFromTiff(pedfile, nny, nnx);
|
std::vector<double> ped(nx * ny);
|
||||||
|
float *pp = ReadFromTiff(pedfilename.c_str(), nny, nnx);
|
||||||
if (pp && (int)nnx == nx && (int)nny == ny) {
|
if (pp && (int)nnx == nx && (int)nny == ny) {
|
||||||
for (int i = 0; i < nx * ny; i++) {
|
for (int i = 0; i < nx * ny; i++) {
|
||||||
ped[i] = pp[i];
|
ped[i] = pp[i];
|
||||||
}
|
}
|
||||||
delete[] pp;
|
delete[] pp;
|
||||||
mt->setPedestal(ped);
|
mt->setPedestal(ped.data());
|
||||||
std::cout << "Pedestal set from tiff file " << pedfile
|
std::cout << "Pedestal set from tiff file " << pedfilename
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Could not open pedestal tiff file " << pedfile
|
std::cout << "Could not open pedestal tiff file " << pedfilename
|
||||||
<< " for reading " << std::endl;
|
<< " for reading " << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -373,27 +384,26 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
mt->setFrameMode(eFrame);
|
mt->setFrameMode(eFrame);
|
||||||
|
|
||||||
|
FILE *of = NULL;
|
||||||
|
|
||||||
for (int irun = runmin; irun <= runmax; irun++) {
|
for (int irun = runmin; irun <= runmax; irun++) {
|
||||||
std::cout << "DATA ";
|
std::cout << "DATA ";
|
||||||
// sprintf(fn,fformat,irun);
|
std::string fsuffix{};
|
||||||
sprintf(ffname, "%s/%s.%s", indir, fformat, fext);
|
auto fname = createFileName( indir, fprefix, fsuffix, fext, irun );
|
||||||
sprintf(fname, (const char *)ffname, irun);
|
auto imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun );
|
||||||
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
|
auto cfname = createFileName( outdir, fprefix, fsuffix, "clust", irun );
|
||||||
sprintf(imgfname, (const char *)ffname, irun);
|
|
||||||
sprintf(ffname, "%s/%s.clust", outdir, fformat);
|
|
||||||
sprintf(cfname, (const char *)ffname, irun);
|
|
||||||
std::cout << fname << " ";
|
std::cout << fname << " ";
|
||||||
std::cout << imgfname << std::endl;
|
std::cout << imgfname << std::endl;
|
||||||
std::time(&end_time);
|
std::time(&end_time);
|
||||||
std::cout << std::ctime(&end_time) << std::endl;
|
std::cout << std::ctime(&end_time) << std::endl;
|
||||||
// cout << fname << " " << outfname << " " << imgfname << endl;
|
// std::cout << fname << " " << outfname << " " << imgfname << std::endl;
|
||||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
ifstream filebin(fname, ios::in | ios::binary);
|
||||||
// //open file
|
// //open file
|
||||||
ifile = 0;
|
ifile = 0;
|
||||||
if (filebin.is_open()) {
|
if (filebin.is_open()) {
|
||||||
if (thr <= 0 && cf != 0) { // cluster finder
|
if (thr <= 0 && cf != 0) { // cluster finder
|
||||||
if (of == NULL) {
|
if (of == NULL) {
|
||||||
of = fopen(cfname, "w");
|
of = fopen(cfname.c_str(), "w");
|
||||||
if (of) {
|
if (of) {
|
||||||
mt->setFilePointer(of);
|
mt->setFilePointer(of);
|
||||||
std::cout << "file pointer set " << std::endl;
|
std::cout << "file pointer set " << std::endl;
|
||||||
@ -414,7 +424,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
if ((ifr + 1) % 100 == 0) {
|
if ((ifr + 1) % 100 == 0) {
|
||||||
std::cout << " ****"
|
std::cout << " ****"
|
||||||
<< decoder->getValue(buff, 20, 20); // << endl;
|
<< decoder->getValue(buff, 20, 20); // << std::endl;
|
||||||
}
|
}
|
||||||
mt->pushData(buff);
|
mt->pushData(buff);
|
||||||
// // //pop
|
// // //pop
|
||||||
@ -426,16 +436,14 @@ int main(int argc, char *argv[]) {
|
|||||||
std::cout << " " << ifr << " " << ff << std::endl;
|
std::cout << " " << ifr << " " << ff << std::endl;
|
||||||
if (nframes > 0) {
|
if (nframes > 0) {
|
||||||
if (ifr % nframes == 0) {
|
if (ifr % nframes == 0) {
|
||||||
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat,
|
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, 0, ifile );
|
||||||
ifile);
|
mt->writeImage(imgfname.c_str(), thr1);
|
||||||
sprintf(imgfname, (const char *)ffname, irun);
|
|
||||||
mt->writeImage(imgfname, thr1);
|
|
||||||
mt->clearImage();
|
mt->clearImage();
|
||||||
ifile++;
|
ifile++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// } else
|
// } else
|
||||||
// cout << ifr << " " << ff << " " << np << endl;
|
//std::cout << ifr << " " << ff << " " << np << std::endl;
|
||||||
ff = -1;
|
ff = -1;
|
||||||
}
|
}
|
||||||
std::cout << "--" << std::endl;
|
std::cout << "--" << std::endl;
|
||||||
@ -444,16 +452,11 @@ int main(int argc, char *argv[]) {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (nframes >= 0) {
|
if (nframes >= 0) {
|
||||||
if (nframes > 0) {
|
if (nframes > 0)
|
||||||
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat, ifile);
|
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, 0, ifile );
|
||||||
sprintf(imgfname, (const char *)ffname, irun);
|
|
||||||
} else {
|
|
||||||
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
|
|
||||||
sprintf(imgfname, (const char *)ffname, irun);
|
|
||||||
}
|
|
||||||
std::cout << "Writing tiff to " << imgfname << " " << thr1
|
std::cout << "Writing tiff to " << imgfname << " " << thr1
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
mt->writeImage(imgfname, thr1);
|
mt->writeImage(imgfname.c_str(), thr1);
|
||||||
mt->clearImage();
|
mt->clearImage();
|
||||||
if (of) {
|
if (of) {
|
||||||
fclose(of);
|
fclose(of);
|
||||||
@ -468,10 +471,9 @@ int main(int argc, char *argv[]) {
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
if (nframes < 0) {
|
if (nframes < 0) {
|
||||||
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
|
auto imgfname = createFileName( outdir, fprefix, "sum", "tiff", -1, 0, 0, -1 );
|
||||||
strcpy(imgfname, ffname);
|
|
||||||
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
|
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
|
||||||
mt->writeImage(imgfname, thr1);
|
mt->writeImage(imgfname.c_str(), thr1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -0,0 +1,467 @@
|
|||||||
|
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||||
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
|
// #include "sls/ansi.h"
|
||||||
|
#include <iostream>
|
||||||
|
#undef CORR
|
||||||
|
|
||||||
|
#define C_GHOST 0.0004
|
||||||
|
|
||||||
|
#define CM_ROWS 50
|
||||||
|
|
||||||
|
#define RAWDATA
|
||||||
|
|
||||||
|
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
|
||||||
|
!defined JFSTRXCHIP6
|
||||||
|
#ifndef MODULE
|
||||||
|
#include "jungfrauHighZSingleChipData.h"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULE
|
||||||
|
#include "jungfrauModuleData.h"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef JFSTRX
|
||||||
|
#include "jungfrauLGADStrixelsData_new.h"
|
||||||
|
#endif
|
||||||
|
#if defined JFSTRXCHIP1 || defined JFSTRXCHIP6
|
||||||
|
#include "jungfrauLGADStrixelsDataSingleChip.h"
|
||||||
|
#endif
|
||||||
|
#ifdef JFSTRXOLD
|
||||||
|
#include "jungfrauStrixelsHalfModuleOldDesign.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "multiThreadedCountingDetector.h"
|
||||||
|
#include "singlePhotonDetector.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <map>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <fmt/core.h>
|
||||||
|
|
||||||
|
std::string getRootString( const std::string filepath ) {
|
||||||
|
size_t pos1;
|
||||||
|
if (filepath.find("/") == std::string::npos )
|
||||||
|
pos1 = 0;
|
||||||
|
else
|
||||||
|
pos1 = filepath.find_last_of("/")+1;
|
||||||
|
size_t pos2 = filepath.find_last_of(".");
|
||||||
|
//std::cout << "pos1 " << pos1 << " pos2 " << pos2 << " size " << filepath.length() << std::endl;
|
||||||
|
return filepath.substr( pos1, pos2-pos1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create file name string
|
||||||
|
// dir: directory
|
||||||
|
// fprefix: fileprefix (without extension)
|
||||||
|
// fsuffix: filesuffix (for output files, e.g. "ped")
|
||||||
|
// fext: file extension (e.g. "raw")
|
||||||
|
std::string createFileName( const std::string dir, std::string fprefix="run", std::string fsuffix="", std::string fext="raw", int outfilecounter=-1 ) {
|
||||||
|
std::string filename{};
|
||||||
|
if (outfilecounter >= 0)
|
||||||
|
filename = fmt::format("{:s}/{:s}_{:s}_f{:05d}.{:s}", dir, fprefix, fsuffix, outfilecounter, fext);
|
||||||
|
else if (fsuffix.length()!=0)
|
||||||
|
filename = fmt::format("{:s}/{:s}_{:s}.{:s}", dir, fprefix, fsuffix, fext);
|
||||||
|
else
|
||||||
|
filename = fmt::format("{:s}/{:s}.{:s}", dir, fprefix, fext);
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS!
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
if (argc < 10) {
|
||||||
|
std::cout
|
||||||
|
<< "Usage is " << argv[0]
|
||||||
|
<< "outdir [pedfile (raw or tiff)] [xmin xmax ymin ymax] "
|
||||||
|
"[threshold] [nframes] [full file path and names (with bash wildcards)] "
|
||||||
|
" NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS! "
|
||||||
|
<< std::endl;
|
||||||
|
std::cout
|
||||||
|
<< "threshold <0 means analog; threshold=0 means cluster finder; "
|
||||||
|
"threshold>0 means photon counting"
|
||||||
|
<< std::endl;
|
||||||
|
std::cout
|
||||||
|
<< "nframes <0 means sum everything; nframes=0 means one file per "
|
||||||
|
"run; nframes>0 means one file every nframes"
|
||||||
|
<< std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fifosize = 1000;
|
||||||
|
int nthreads = 10;
|
||||||
|
int csize = 3; // 3
|
||||||
|
int nsigma = 5;
|
||||||
|
int nped = 10000;
|
||||||
|
|
||||||
|
int cf = 0;
|
||||||
|
|
||||||
|
double *gainmap = NULL;
|
||||||
|
// float *gm;
|
||||||
|
|
||||||
|
int ff, np;
|
||||||
|
// cout << " data size is " << dsize;
|
||||||
|
|
||||||
|
std::string outdir(argv[1]);
|
||||||
|
std::string pedfilename(argv[2]);
|
||||||
|
|
||||||
|
int xmin = atoi(argv[3]);
|
||||||
|
int xmax = atoi(argv[4]);
|
||||||
|
int ymin = atoi(argv[5]);
|
||||||
|
int ymax = atoi(argv[6]);
|
||||||
|
|
||||||
|
double thr = 0;
|
||||||
|
double thr1 = 1;
|
||||||
|
thr = atof(argv[7]);
|
||||||
|
|
||||||
|
int nframes = 0;
|
||||||
|
nframes = atoi(argv[8]);
|
||||||
|
|
||||||
|
// Define decoders...
|
||||||
|
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
|
||||||
|
!defined JFSTRXCHIP6
|
||||||
|
#ifndef MODULE
|
||||||
|
jungfrauHighZSingleChipData *decoder = new jungfrauHighZSingleChipData();
|
||||||
|
int nx = 256, ny = 256;
|
||||||
|
#endif
|
||||||
|
#ifdef MODULE
|
||||||
|
jungfrauModuleData *decoder = new jungfrauModuleData();
|
||||||
|
int nx = 1024, ny = 512;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef JFSTRX
|
||||||
|
cout << "Jungfrau strixel full module readout" << endl;
|
||||||
|
// ROI
|
||||||
|
uint16_t xxmin = 0;
|
||||||
|
uint16_t xxmax = 0;
|
||||||
|
uint16_t yymin = 0;
|
||||||
|
uint16_t yymax = 0;
|
||||||
|
|
||||||
|
#ifndef ALDO
|
||||||
|
{ //THIS SCOPE IS IMPORTANT! (To ensure proper destruction of ifstream)
|
||||||
|
using header = sls::defs::sls_receiver_header;
|
||||||
|
// check if there is a roi in the header
|
||||||
|
typedef struct {
|
||||||
|
uint16_t xmin;
|
||||||
|
uint16_t xmax;
|
||||||
|
uint16_t ymin;
|
||||||
|
uint16_t ymax;
|
||||||
|
} receiverRoi_compact;
|
||||||
|
receiverRoi_compact croi;
|
||||||
|
std::string filepath(argv[9]); //This is a problem if the input files have different ROIs!
|
||||||
|
std::cout << "Reading header of file " << filepath << " to check for ROI "
|
||||||
|
<< std::endl;
|
||||||
|
ifstream firstfile(filepath, ios::in | ios::binary);
|
||||||
|
if (firstfile.is_open()) {
|
||||||
|
header hbuffer;
|
||||||
|
std::cout << "sizeof(header) = " << sizeof(header) << std::endl;
|
||||||
|
if (firstfile.read((char *)&hbuffer, sizeof(header))) {
|
||||||
|
memcpy(&croi, &hbuffer.detHeader.detSpec1, 8);
|
||||||
|
std::cout << "Read ROI [" << croi.xmin << ", " << croi.xmax << ", "
|
||||||
|
<< croi.ymin << ", " << croi.ymax << "]" << std::endl;
|
||||||
|
xxmin = croi.xmin;
|
||||||
|
xxmax = croi.xmax;
|
||||||
|
yymin = croi.ymin;
|
||||||
|
yymax = croi.ymax;
|
||||||
|
} else
|
||||||
|
std::cout << "reading error" << std::endl;
|
||||||
|
firstfile.close();
|
||||||
|
} else
|
||||||
|
std::cout << "Could not open " << filepath << " for reading " << std::endl;
|
||||||
|
} //end of protective scope
|
||||||
|
#endif
|
||||||
|
|
||||||
|
jungfrauLGADStrixelsData *decoder =
|
||||||
|
new jungfrauLGADStrixelsData(xxmin, xxmax, yymin, yymax);
|
||||||
|
int nx = 1024 / 3, ny = 512 * 5;
|
||||||
|
#endif
|
||||||
|
#ifdef JFSTRXCHIP1
|
||||||
|
std::cout << "Jungfrau strixel LGAD single chip 1" << std::endl;
|
||||||
|
jungfrauLGADStrixelsDataSingleChip *decoder =
|
||||||
|
new jungfrauLGADStrixelsDataSingleChip(1);
|
||||||
|
int nx = 256 / 3, ny = 256 * 5;
|
||||||
|
#endif
|
||||||
|
#ifdef JFSTRXCHIP6
|
||||||
|
std::cout << "Jungfrau strixel LGAD single chip 6" << std::endl;
|
||||||
|
jungfrauLGADStrixelsDataSingleChip *decoder =
|
||||||
|
new jungfrauLGADStrixelsDataSingleChip(6);
|
||||||
|
int nx = 256 / 3, ny = 256 * 5;
|
||||||
|
#endif
|
||||||
|
#ifdef JFSTRXOLD
|
||||||
|
std::cout << "Jungfrau strixels old design" << std::endl;
|
||||||
|
jungfrauStrixelsHalfModuleOldDesign *decoder =
|
||||||
|
new jungfrauStrixelsHalfModuleOldDesign();
|
||||||
|
int nx = 1024 * 3, ny = 512 / 3;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
decoder->getDetectorSize(nx, ny);
|
||||||
|
std::cout << "Detector size is " << nx << " " << ny << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
if ( xmin == xmax ) {
|
||||||
|
xmin = 0;
|
||||||
|
xmax = nx;
|
||||||
|
}
|
||||||
|
if ( ymin == ymax ) {
|
||||||
|
ymin = 0;
|
||||||
|
ymax = ny;
|
||||||
|
}
|
||||||
|
std::cout << xmin << " " << xmax << " " << ymin << " " << ymax << " "
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
/*
|
||||||
|
char *gainfname = NULL;
|
||||||
|
if (argc > 14) {
|
||||||
|
gainfname = argv[14];
|
||||||
|
std::cout << "Gain map file name is: " << gainfname << std::endl;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::time_t end_time;
|
||||||
|
|
||||||
|
std::cout << "output directory is " << outdir << std::endl;
|
||||||
|
if (pedfilename.length()!=0)
|
||||||
|
std::cout << "pedestal file is " << pedfilename << std::endl;
|
||||||
|
if (thr > 0)
|
||||||
|
std::cout << "threshold is " << thr << std::endl;
|
||||||
|
std::cout << "Nframes is " << nframes << std::endl;
|
||||||
|
|
||||||
|
uint32_t nnx, nny;
|
||||||
|
|
||||||
|
singlePhotonDetector *filter = new singlePhotonDetector(
|
||||||
|
decoder, 3, nsigma, 1, NULL, nped, 200, -1, -1, gainmap, NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (gainfname) {
|
||||||
|
|
||||||
|
if (filter->readGainMap(gainfname))
|
||||||
|
std::cout << "using gain map " << gainfname << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "Could not open gain map " << gainfname << std::endl;
|
||||||
|
} else
|
||||||
|
*/
|
||||||
|
thr = 0.15 * thr;
|
||||||
|
filter->newDataSet();
|
||||||
|
// int dsize = decoder->getDataSize();
|
||||||
|
|
||||||
|
if (thr > 0) {
|
||||||
|
std::cout << "threshold is " << thr << std::endl;
|
||||||
|
filter->setThreshold(thr);
|
||||||
|
cf = 0;
|
||||||
|
|
||||||
|
} else
|
||||||
|
cf = 1;
|
||||||
|
|
||||||
|
filter->setROI(xmin, xmax, ymin, ymax);
|
||||||
|
std::time(&end_time);
|
||||||
|
std::cout << std::ctime(&end_time) << std::endl;
|
||||||
|
|
||||||
|
char *buff;
|
||||||
|
|
||||||
|
multiThreadedCountingDetector *mt =
|
||||||
|
new multiThreadedCountingDetector(filter, nthreads, fifosize);
|
||||||
|
mt->setClusterSize(csize, csize);
|
||||||
|
|
||||||
|
#ifndef ANALOG
|
||||||
|
mt->setDetectorMode(ePhotonCounting);
|
||||||
|
std::cout << "Counting!" << std::endl;
|
||||||
|
if (thr > 0) {
|
||||||
|
cf = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
//{
|
||||||
|
#ifdef ANALOG
|
||||||
|
mt->setDetectorMode(eAnalog);
|
||||||
|
std::cout << "Analog!" << std::endl;
|
||||||
|
cf = 0;
|
||||||
|
// thr1=thr;
|
||||||
|
#endif
|
||||||
|
// }
|
||||||
|
|
||||||
|
mt->StartThreads();
|
||||||
|
mt->popFree(buff);
|
||||||
|
|
||||||
|
// cout << "mt " << endl;
|
||||||
|
|
||||||
|
int ifr = 0;
|
||||||
|
|
||||||
|
if (pedfilename.length()>1) {
|
||||||
|
|
||||||
|
std::string froot = getRootString(pedfilename);
|
||||||
|
|
||||||
|
std::cout << "PEDESTAL " << std::endl;
|
||||||
|
|
||||||
|
if (pedfilename.find(".tif") == std::string::npos) {
|
||||||
|
std::string fname = pedfilename;
|
||||||
|
std::cout << fname << std::endl;
|
||||||
|
std::time(&end_time);
|
||||||
|
std::cout << "aaa " << std::ctime(&end_time) << std::endl;
|
||||||
|
|
||||||
|
mt->setFrameMode(ePedestal);
|
||||||
|
|
||||||
|
ifstream pedefile(fname, ios::in | ios::binary);
|
||||||
|
// //open file
|
||||||
|
if (pedefile.is_open()) {
|
||||||
|
std::cout << "bbbb " << std::ctime(&end_time) << std::endl;
|
||||||
|
|
||||||
|
ff = -1;
|
||||||
|
while (decoder->readNextFrame(pedefile, ff, np, buff)) {
|
||||||
|
// if (np == 40) {
|
||||||
|
if ((ifr + 1) % 100 == 0) {
|
||||||
|
std::cout
|
||||||
|
<< " ****"
|
||||||
|
<< decoder->getValue(buff, 20, 20); // << std::endl;
|
||||||
|
}
|
||||||
|
mt->pushData(buff);
|
||||||
|
mt->nextThread();
|
||||||
|
mt->popFree(buff);
|
||||||
|
ifr++;
|
||||||
|
if (ifr % 100 == 0) {
|
||||||
|
std::cout << " ****" << ifr << " " << ff << " " << np
|
||||||
|
<< std::endl;
|
||||||
|
} // else
|
||||||
|
//std::cout << ifr << " " << ff << " " << np << std::endl;
|
||||||
|
if (ifr >= 1000)
|
||||||
|
break;
|
||||||
|
ff = -1;
|
||||||
|
}
|
||||||
|
pedefile.close();
|
||||||
|
while (mt->isBusy()) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "froot " << froot << std::endl;
|
||||||
|
auto imgfname = createFileName( outdir, froot, "ped", "tiff");
|
||||||
|
mt->writePedestal(imgfname.c_str());
|
||||||
|
imgfname = createFileName( outdir, froot, "rms", "tiff");
|
||||||
|
mt->writePedestalRMS(imgfname.c_str());
|
||||||
|
|
||||||
|
} else
|
||||||
|
std::cout << "Could not open pedestal file " << fname
|
||||||
|
<< " for reading " << std::endl;
|
||||||
|
} else {
|
||||||
|
std::vector<double> ped(nx * ny);
|
||||||
|
float *pp = ReadFromTiff(pedfilename.c_str(), nny, nnx);
|
||||||
|
if (pp && (int)nnx == nx && (int)nny == ny) {
|
||||||
|
for (int i = 0; i < nx * ny; i++) {
|
||||||
|
ped[i] = pp[i];
|
||||||
|
}
|
||||||
|
delete[] pp;
|
||||||
|
mt->setPedestal(ped.data());
|
||||||
|
std::cout << "Pedestal set from tiff file " << pedfilename
|
||||||
|
<< std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Could not open pedestal tiff file " << pedfilename
|
||||||
|
<< " for reading " << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::time(&end_time);
|
||||||
|
std::cout << std::ctime(&end_time) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
ifr = 0;
|
||||||
|
int ifile = 0;
|
||||||
|
|
||||||
|
mt->setFrameMode(eFrame);
|
||||||
|
|
||||||
|
FILE *of = NULL;
|
||||||
|
|
||||||
|
//NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS!
|
||||||
|
for (int iargc = 9; iargc != argc; ++iargc) {
|
||||||
|
std::cout << "DATA ";
|
||||||
|
std::string fname(argv[iargc]);
|
||||||
|
std::string fsuffix{};
|
||||||
|
std::string fprefix = getRootString(fname);
|
||||||
|
std::string imgfname = createFileName( outdir, fprefix, fsuffix, "tiff" );
|
||||||
|
std::string cfname = createFileName( outdir, fprefix, fsuffix, "clust" );
|
||||||
|
std::cout << fname << " ";
|
||||||
|
std::cout << imgfname << std::endl;
|
||||||
|
std::time(&end_time);
|
||||||
|
std::cout << std::ctime(&end_time) << std::endl;
|
||||||
|
|
||||||
|
ifstream filebin(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.c_str(), "w");
|
||||||
|
if (of) {
|
||||||
|
mt->setFilePointer(of);
|
||||||
|
std::cout << "file pointer set " << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Could not open " << cfname
|
||||||
|
<< " for writing " << std::endl;
|
||||||
|
mt->setFilePointer(NULL);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// //while read frame
|
||||||
|
ff = -1;
|
||||||
|
ifr = 0;
|
||||||
|
while (decoder->readNextFrame(filebin, ff, np, buff)) {
|
||||||
|
// if (np == 40) {
|
||||||
|
// //push
|
||||||
|
|
||||||
|
if ((ifr + 1) % 100 == 0) {
|
||||||
|
std::cout << " ****"
|
||||||
|
<< decoder->getValue(buff, 20, 20); // << std::endl;
|
||||||
|
}
|
||||||
|
mt->pushData(buff);
|
||||||
|
// // //pop
|
||||||
|
mt->nextThread();
|
||||||
|
mt->popFree(buff);
|
||||||
|
|
||||||
|
ifr++;
|
||||||
|
if (ifr % 100 == 0)
|
||||||
|
std::cout << " " << ifr << " " << ff << std::endl;
|
||||||
|
if (nframes > 0) {
|
||||||
|
if (ifr % nframes == 0) {
|
||||||
|
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", ifile );
|
||||||
|
mt->writeImage(imgfname.c_str(), thr1);
|
||||||
|
mt->clearImage();
|
||||||
|
ifile++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// } else
|
||||||
|
//std::cout << ifr << " " << ff << " " << np << std::endl;
|
||||||
|
ff = -1;
|
||||||
|
}
|
||||||
|
std::cout << "--" << std::endl;
|
||||||
|
filebin.close();
|
||||||
|
while (mt->isBusy()) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
if (nframes >= 0) {
|
||||||
|
if (nframes > 0)
|
||||||
|
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", ifile );
|
||||||
|
std::cout << "Writing tiff to " << imgfname << " " << thr1
|
||||||
|
<< std::endl;
|
||||||
|
mt->writeImage(imgfname.c_str(), thr1);
|
||||||
|
mt->clearImage();
|
||||||
|
if (of) {
|
||||||
|
fclose(of);
|
||||||
|
of = NULL;
|
||||||
|
mt->setFilePointer(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::time(&end_time);
|
||||||
|
std::cout << std::ctime(&end_time) << std::endl;
|
||||||
|
} else
|
||||||
|
std::cout << "Could not open " << fname << " for reading "
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
if (nframes < 0) {
|
||||||
|
std::string fname(argv[10]);
|
||||||
|
auto fprefix = getRootString(fname); //This might by a non-ideal name choice for that file
|
||||||
|
auto imgfname = createFileName( outdir, fprefix, "sum", "tiff" );
|
||||||
|
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
|
||||||
|
mt->writeImage(imgfname.c_str(), thr1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,497 @@
|
|||||||
|
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||||
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
|
// #include "sls/ansi.h"
|
||||||
|
#include <iostream>
|
||||||
|
#undef CORR
|
||||||
|
|
||||||
|
#define C_GHOST 0.0004
|
||||||
|
|
||||||
|
#define CM_ROWS 50
|
||||||
|
|
||||||
|
#define RAWDATA
|
||||||
|
|
||||||
|
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
|
||||||
|
!defined JFSTRXCHIP6
|
||||||
|
#ifndef MODULE
|
||||||
|
#include "jungfrauHighZSingleChipData.h"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULE
|
||||||
|
#include "jungfrauModuleData.h"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef JFSTRX
|
||||||
|
#include "jungfrauLGADStrixelsData_new.h"
|
||||||
|
#endif
|
||||||
|
#if defined JFSTRXCHIP1 || defined JFSTRXCHIP6
|
||||||
|
#include "jungfrauLGADStrixelsDataSingleChip.h"
|
||||||
|
#endif
|
||||||
|
#ifdef JFSTRXOLD
|
||||||
|
#include "jungfrauStrixelsHalfModuleOldDesign.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "multiThreadedCountingDetector.h"
|
||||||
|
#include "singlePhotonDetector.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <map>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <fmt/core.h>
|
||||||
|
|
||||||
|
|
||||||
|
std::string getRootString( const std::string& filepath ) {
|
||||||
|
size_t pos1;
|
||||||
|
if (filepath.find("/") == std::string::npos )
|
||||||
|
pos1 = 0;
|
||||||
|
else
|
||||||
|
pos1 = filepath.find_last_of("/")+1;
|
||||||
|
size_t pos2 = filepath.find_last_of(".");
|
||||||
|
//std::cout << "pos1 " << pos1 << " pos2 " << pos2 << " size " << filepath.length() << std::endl;
|
||||||
|
return filepath.substr( pos1, pos2-pos1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create file name string
|
||||||
|
// dir: directory
|
||||||
|
// fprefix: fileprefix (without extension)
|
||||||
|
// fsuffix: filesuffix (for output files, e.g. "ped")
|
||||||
|
// fext: file extension (e.g. "raw")
|
||||||
|
std::string createFileName( const std::string& dir, const std::string& fprefix="run", const std::string& fsuffix="", const std::string& fext="raw", int outfilecounter=-1 ) {
|
||||||
|
if (outfilecounter >= 0)
|
||||||
|
return fmt::format("{:s}/{:s}_{:s}_f{:05d}.{:s}", dir, fprefix, fsuffix, outfilecounter, fext);
|
||||||
|
else if (fsuffix.length()!=0)
|
||||||
|
return fmt::format("{:s}/{:s}_{:s}.{:s}", dir, fprefix, fsuffix, fext);
|
||||||
|
else
|
||||||
|
return fmt::format("{:s}/{:s}.{:s}", dir, fprefix, fext);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS!
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
if (argc < 10) {
|
||||||
|
std::cout
|
||||||
|
<< "Usage is " << argv[0]
|
||||||
|
<< "filestxt outdir [pedfile (raw or tiff)] [xmin xmax ymin ymax] "
|
||||||
|
"[threshold] [nframes] "
|
||||||
|
"NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS! "
|
||||||
|
<< std::endl;
|
||||||
|
std::cout
|
||||||
|
<< "threshold <0 means analog; threshold=0 means cluster finder; "
|
||||||
|
"threshold>0 means photon counting"
|
||||||
|
<< std::endl;
|
||||||
|
std::cout
|
||||||
|
<< "nframes <0 means sum everything; nframes=0 means one file per "
|
||||||
|
"run; nframes>0 means one file every nframes"
|
||||||
|
<< std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fifosize = 1000;
|
||||||
|
int nthreads = 10;
|
||||||
|
int csize = 3; // 3
|
||||||
|
int nsigma = 5;
|
||||||
|
int nped = 10000;
|
||||||
|
|
||||||
|
int cf = 0;
|
||||||
|
|
||||||
|
double *gainmap = NULL;
|
||||||
|
// float *gm;
|
||||||
|
|
||||||
|
int ff, np;
|
||||||
|
// cout << " data size is " << dsize;
|
||||||
|
|
||||||
|
const std::string txtfilename(argv[1]);
|
||||||
|
const std::string outdir(argv[2]);
|
||||||
|
const std::string pedfilename(argv[3]);
|
||||||
|
|
||||||
|
int xmin = atoi(argv[4]);
|
||||||
|
int xmax = atoi(argv[5]);
|
||||||
|
int ymin = atoi(argv[6]);
|
||||||
|
int ymax = atoi(argv[7]);
|
||||||
|
|
||||||
|
double thr = 0;
|
||||||
|
double thr1 = 1;
|
||||||
|
thr = atof(argv[8]);
|
||||||
|
|
||||||
|
int nframes = 0;
|
||||||
|
nframes = atoi(argv[9]);
|
||||||
|
|
||||||
|
//Get vector of filenames from input txt-file
|
||||||
|
std::vector<std::string> filenames{};
|
||||||
|
//filenames.reserve(512);
|
||||||
|
{ //Safety scope for ifstream
|
||||||
|
ifstream inputs( txtfilename, std::ios::in );
|
||||||
|
if (inputs.is_open()) {
|
||||||
|
std::cout << "Reading imput filenames from txt-file ..." << std::endl;
|
||||||
|
std::string line{};
|
||||||
|
while (!inputs.eof()) {
|
||||||
|
std::getline(inputs, line);
|
||||||
|
filenames.emplace_back(line);
|
||||||
|
std::cout << line << " line.max_size() " << line.max_size() << " filenames.capacity() " << filenames.capacity() << '\n';
|
||||||
|
}
|
||||||
|
inputs.close();
|
||||||
|
std::cout << "---- Reached end of txt-file. ----" << std::endl;
|
||||||
|
} else
|
||||||
|
std::cout << "Could not open " << txtfilename << std::endl;
|
||||||
|
if (filenames.size()>0) {
|
||||||
|
std::cout << filenames.size() << " filenames found in " << txtfilename << std::endl;
|
||||||
|
std::cout << "The files will be processed in the same order as found in the txt-file." << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "No files found in txt-file!" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "###############" << std::endl;
|
||||||
|
|
||||||
|
// Define decoders...
|
||||||
|
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
|
||||||
|
!defined JFSTRXCHIP6
|
||||||
|
#ifndef MODULE
|
||||||
|
jungfrauHighZSingleChipData *decoder = new jungfrauHighZSingleChipData();
|
||||||
|
int nx = 256, ny = 256;
|
||||||
|
#endif
|
||||||
|
#ifdef MODULE
|
||||||
|
jungfrauModuleData *decoder = new jungfrauModuleData();
|
||||||
|
int nx = 1024, ny = 512;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef JFSTRX
|
||||||
|
cout << "Jungfrau strixel full module readout" << endl;
|
||||||
|
// ROI
|
||||||
|
uint16_t xxmin = 0;
|
||||||
|
uint16_t xxmax = 0;
|
||||||
|
uint16_t yymin = 0;
|
||||||
|
uint16_t yymax = 0;
|
||||||
|
|
||||||
|
#ifndef ALDO
|
||||||
|
{ //THIS SCOPE IS IMPORTANT! (To ensure proper destruction of ifstream)
|
||||||
|
using header = sls::defs::sls_receiver_header;
|
||||||
|
// check if there is a roi in the header
|
||||||
|
typedef struct {
|
||||||
|
uint16_t xmin;
|
||||||
|
uint16_t xmax;
|
||||||
|
uint16_t ymin;
|
||||||
|
uint16_t ymax;
|
||||||
|
} receiverRoi_compact;
|
||||||
|
receiverRoi_compact croi;
|
||||||
|
//std::string filepath(argv[9]); //This is a problem if the input files have different ROIs!
|
||||||
|
std::cout << "Reading header of file " << filenames[0] << " to check for ROI "
|
||||||
|
<< std::endl;
|
||||||
|
ifstream firstfile(filenames[0], ios::in | ios::binary);
|
||||||
|
if (firstfile.is_open()) {
|
||||||
|
header hbuffer;
|
||||||
|
std::cout << "sizeof(header) = " << sizeof(header) << std::endl;
|
||||||
|
if (firstfile.read((char *)&hbuffer, sizeof(header))) {
|
||||||
|
memcpy(&croi, &hbuffer.detHeader.detSpec1, 8);
|
||||||
|
std::cout << "Read ROI [" << croi.xmin << ", " << croi.xmax << ", "
|
||||||
|
<< croi.ymin << ", " << croi.ymax << "]" << std::endl;
|
||||||
|
xxmin = croi.xmin;
|
||||||
|
xxmax = croi.xmax;
|
||||||
|
yymin = croi.ymin;
|
||||||
|
yymax = croi.ymax;
|
||||||
|
} else
|
||||||
|
std::cout << "reading error" << std::endl;
|
||||||
|
firstfile.close();
|
||||||
|
} else
|
||||||
|
std::cout << "Could not open " << filenames[0] << " for reading " << std::endl;
|
||||||
|
} //end of protective scope
|
||||||
|
#endif
|
||||||
|
|
||||||
|
jungfrauLGADStrixelsData *decoder =
|
||||||
|
new jungfrauLGADStrixelsData(xxmin, xxmax, yymin, yymax);
|
||||||
|
int nx = 1024 / 3, ny = 512 * 5;
|
||||||
|
#endif
|
||||||
|
#ifdef JFSTRXCHIP1
|
||||||
|
std::cout << "Jungfrau strixel LGAD single chip 1" << std::endl;
|
||||||
|
jungfrauLGADStrixelsDataSingleChip *decoder =
|
||||||
|
new jungfrauLGADStrixelsDataSingleChip(1);
|
||||||
|
int nx = 256 / 3, ny = 256 * 5;
|
||||||
|
#endif
|
||||||
|
#ifdef JFSTRXCHIP6
|
||||||
|
std::cout << "Jungfrau strixel LGAD single chip 6" << std::endl;
|
||||||
|
jungfrauLGADStrixelsDataSingleChip *decoder =
|
||||||
|
new jungfrauLGADStrixelsDataSingleChip(6);
|
||||||
|
int nx = 256 / 3, ny = 256 * 5;
|
||||||
|
#endif
|
||||||
|
#ifdef JFSTRXOLD
|
||||||
|
std::cout << "Jungfrau strixels old design" << std::endl;
|
||||||
|
jungfrauStrixelsHalfModuleOldDesign *decoder =
|
||||||
|
new jungfrauStrixelsHalfModuleOldDesign();
|
||||||
|
int nx = 1024 * 3, ny = 512 / 3;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
decoder->getDetectorSize(nx, ny);
|
||||||
|
std::cout << "Detector size is " << nx << " " << ny << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
if ( xmin == xmax ) {
|
||||||
|
xmin = 0;
|
||||||
|
xmax = nx;
|
||||||
|
}
|
||||||
|
if ( ymin == ymax ) {
|
||||||
|
ymin = 0;
|
||||||
|
ymax = ny;
|
||||||
|
}
|
||||||
|
std::cout << xmin << " " << xmax << " " << ymin << " " << ymax << " "
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
/*
|
||||||
|
char *gainfname = NULL;
|
||||||
|
if (argc > 14) {
|
||||||
|
gainfname = argv[14];
|
||||||
|
std::cout << "Gain map file name is: " << gainfname << std::endl;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::time_t end_time;
|
||||||
|
|
||||||
|
std::cout << "output directory is " << outdir << std::endl;
|
||||||
|
if (pedfilename.length()!=0)
|
||||||
|
std::cout << "pedestal file is " << pedfilename << std::endl;
|
||||||
|
if (thr > 0)
|
||||||
|
std::cout << "threshold is " << thr << std::endl;
|
||||||
|
std::cout << "Nframes is " << nframes << std::endl;
|
||||||
|
|
||||||
|
uint32_t nnx, nny;
|
||||||
|
|
||||||
|
singlePhotonDetector *filter = new singlePhotonDetector(
|
||||||
|
decoder, 3, nsigma, 1, NULL, nped, 200, -1, -1, gainmap, NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (gainfname) {
|
||||||
|
|
||||||
|
if (filter->readGainMap(gainfname))
|
||||||
|
std::cout << "using gain map " << gainfname << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "Could not open gain map " << gainfname << std::endl;
|
||||||
|
} else
|
||||||
|
*/
|
||||||
|
thr = 0.15 * thr;
|
||||||
|
filter->newDataSet();
|
||||||
|
// int dsize = decoder->getDataSize();
|
||||||
|
|
||||||
|
if (thr > 0) {
|
||||||
|
std::cout << "threshold is " << thr << std::endl;
|
||||||
|
filter->setThreshold(thr);
|
||||||
|
cf = 0;
|
||||||
|
|
||||||
|
} else
|
||||||
|
cf = 1;
|
||||||
|
|
||||||
|
filter->setROI(xmin, xmax, ymin, ymax);
|
||||||
|
std::time(&end_time);
|
||||||
|
std::cout << std::ctime(&end_time) << std::endl;
|
||||||
|
|
||||||
|
char *buff;
|
||||||
|
|
||||||
|
multiThreadedCountingDetector *mt =
|
||||||
|
new multiThreadedCountingDetector(filter, nthreads, fifosize);
|
||||||
|
mt->setClusterSize(csize, csize);
|
||||||
|
|
||||||
|
#ifndef ANALOG
|
||||||
|
mt->setDetectorMode(ePhotonCounting);
|
||||||
|
std::cout << "Counting!" << std::endl;
|
||||||
|
if (thr > 0) {
|
||||||
|
cf = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
//{
|
||||||
|
#ifdef ANALOG
|
||||||
|
mt->setDetectorMode(eAnalog);
|
||||||
|
std::cout << "Analog!" << std::endl;
|
||||||
|
cf = 0;
|
||||||
|
// thr1=thr;
|
||||||
|
#endif
|
||||||
|
// }
|
||||||
|
|
||||||
|
mt->StartThreads();
|
||||||
|
mt->popFree(buff);
|
||||||
|
|
||||||
|
// cout << "mt " << endl;
|
||||||
|
|
||||||
|
int ifr = 0;
|
||||||
|
|
||||||
|
if (pedfilename.length()>1) {
|
||||||
|
|
||||||
|
std::string froot = getRootString(pedfilename);
|
||||||
|
|
||||||
|
std::cout << "PEDESTAL " << std::endl;
|
||||||
|
|
||||||
|
if (pedfilename.find(".tif") == std::string::npos) {
|
||||||
|
const std::string fname(pedfilename);
|
||||||
|
std::cout << fname << std::endl;
|
||||||
|
std::time(&end_time);
|
||||||
|
std::cout << "aaa " << std::ctime(&end_time) << std::endl;
|
||||||
|
|
||||||
|
mt->setFrameMode(ePedestal);
|
||||||
|
|
||||||
|
std::ifstream pedefile(fname, ios::in | ios::binary);
|
||||||
|
// //open file
|
||||||
|
if (pedefile.is_open()) {
|
||||||
|
std::cout << "bbbb " << std::ctime(&end_time) << std::endl;
|
||||||
|
|
||||||
|
ff = -1;
|
||||||
|
while (decoder->readNextFrame(pedefile, ff, np, buff)) {
|
||||||
|
// if (np == 40) {
|
||||||
|
if ((ifr + 1) % 100 == 0) {
|
||||||
|
std::cout
|
||||||
|
<< " ****"
|
||||||
|
<< decoder->getValue(buff, 20, 20); // << std::endl;
|
||||||
|
}
|
||||||
|
mt->pushData(buff);
|
||||||
|
mt->nextThread();
|
||||||
|
mt->popFree(buff);
|
||||||
|
ifr++;
|
||||||
|
if (ifr % 100 == 0) {
|
||||||
|
std::cout << " ****" << ifr << " " << ff << " " << np
|
||||||
|
<< std::endl;
|
||||||
|
} // else
|
||||||
|
//std::cout << ifr << " " << ff << " " << np << std::endl;
|
||||||
|
if (ifr >= 1000)
|
||||||
|
break;
|
||||||
|
ff = -1;
|
||||||
|
}
|
||||||
|
pedefile.close();
|
||||||
|
while (mt->isBusy()) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "froot " << froot << std::endl;
|
||||||
|
auto imgfname = createFileName( outdir, froot, "ped", "tiff");
|
||||||
|
mt->writePedestal(imgfname.c_str());
|
||||||
|
imgfname = createFileName( outdir, froot, "rms", "tiff");
|
||||||
|
mt->writePedestalRMS(imgfname.c_str());
|
||||||
|
|
||||||
|
} else
|
||||||
|
std::cout << "Could not open pedestal file " << fname
|
||||||
|
<< " for reading " << std::endl;
|
||||||
|
} else {
|
||||||
|
std::vector<double> ped(nx * ny);
|
||||||
|
float *pp = ReadFromTiff(pedfilename.c_str(), nny, nnx);
|
||||||
|
if (pp && (int)nnx == nx && (int)nny == ny) {
|
||||||
|
for (int i = 0; i < nx * ny; i++) {
|
||||||
|
ped[i] = pp[i];
|
||||||
|
}
|
||||||
|
delete[] pp;
|
||||||
|
mt->setPedestal(ped.data());
|
||||||
|
std::cout << "Pedestal set from tiff file " << pedfilename
|
||||||
|
<< std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Could not open pedestal tiff file " << pedfilename
|
||||||
|
<< " for reading " << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::time(&end_time);
|
||||||
|
std::cout << std::ctime(&end_time) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
ifr = 0;
|
||||||
|
int ioutfile = 0;
|
||||||
|
|
||||||
|
mt->setFrameMode(eFrame);
|
||||||
|
|
||||||
|
FILE *of = NULL;
|
||||||
|
std::ifstream filebin{};
|
||||||
|
|
||||||
|
//NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS!
|
||||||
|
for (unsigned int ifile = 0; ifile != filenames.size(); ++ifile) {
|
||||||
|
std::cout << "DATA ";
|
||||||
|
std::string fsuffix{};
|
||||||
|
const std::string fprefix( getRootString(filenames[ifile]) );
|
||||||
|
std::string imgfname( createFileName( outdir, fprefix, fsuffix, "tiff" ) );
|
||||||
|
const std::string cfname( createFileName( outdir, fprefix, fsuffix, "clust" ) );
|
||||||
|
std::cout << filenames[ifile] << " ";
|
||||||
|
std::cout << imgfname << std::endl;
|
||||||
|
std::time(&end_time);
|
||||||
|
std::cout << std::ctime(&end_time) << std::endl;
|
||||||
|
|
||||||
|
ifstream filebin(filenames[ifile], ios::in | ios::binary);
|
||||||
|
// //open file
|
||||||
|
ioutfile = 0;
|
||||||
|
if (filebin.is_open()) {
|
||||||
|
if (thr <= 0 && cf != 0) { // cluster finder
|
||||||
|
if (of == NULL) {
|
||||||
|
of = fopen(cfname.c_str(), "w");
|
||||||
|
if (of) {
|
||||||
|
mt->setFilePointer(of);
|
||||||
|
std::cout << "file pointer set " << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Could not open " << cfname
|
||||||
|
<< " for writing " << std::endl;
|
||||||
|
mt->setFilePointer(NULL);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// //while read frame
|
||||||
|
ff = -1;
|
||||||
|
ifr = 0;
|
||||||
|
while (decoder->readNextFrame(filebin, ff, np, buff)) {
|
||||||
|
// if (np == 40) {
|
||||||
|
// //push
|
||||||
|
|
||||||
|
if ((ifr + 1) % 100 == 0) {
|
||||||
|
std::cout << " ****"
|
||||||
|
<< decoder->getValue(buff, 20, 20); // << std::endl;
|
||||||
|
}
|
||||||
|
mt->pushData(buff);
|
||||||
|
// // //pop
|
||||||
|
mt->nextThread();
|
||||||
|
mt->popFree(buff);
|
||||||
|
|
||||||
|
ifr++;
|
||||||
|
if (ifr % 100 == 0)
|
||||||
|
std::cout << " " << ifr << " " << ff << std::endl;
|
||||||
|
if (nframes > 0) {
|
||||||
|
if (ifr % nframes == 0) {
|
||||||
|
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", ioutfile );
|
||||||
|
mt->writeImage(imgfname.c_str(), thr1);
|
||||||
|
mt->clearImage();
|
||||||
|
++ioutfile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// } else
|
||||||
|
//std::cout << ifr << " " << ff << " " << np << std::endl;
|
||||||
|
ff = -1;
|
||||||
|
}
|
||||||
|
std::cout << "aa --" << std::endl;
|
||||||
|
filebin.close();
|
||||||
|
std::cout << "bb --" << std::endl;
|
||||||
|
while (mt->isBusy()) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
std::cout << "cc --" << std::endl;
|
||||||
|
if (nframes >= 0) {
|
||||||
|
if (nframes > 0)
|
||||||
|
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", ioutfile );
|
||||||
|
std::cout << "Writing tiff to " << imgfname << " " << thr1
|
||||||
|
<< std::endl;
|
||||||
|
mt->writeImage(imgfname.c_str(), thr1);
|
||||||
|
mt->clearImage();
|
||||||
|
if (of) {
|
||||||
|
fclose(of);
|
||||||
|
of = NULL;
|
||||||
|
mt->setFilePointer(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::time(&end_time);
|
||||||
|
std::cout << std::ctime(&end_time) << std::endl;
|
||||||
|
} else
|
||||||
|
std::cout << "Could not open " << filenames[ifile] << " for reading "
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
if (nframes < 0) {
|
||||||
|
//std::string fname(argv[10]);
|
||||||
|
std::string fprefix( getRootString(filenames[0]) ); //This might by a non-ideal name choice for that file
|
||||||
|
std::string imgfname( createFileName( outdir, fprefix, "sum", "tiff" ) );
|
||||||
|
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
|
||||||
|
mt->writeImage(imgfname.c_str(), thr1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -130,6 +130,7 @@ class threadedAnalogDetector {
|
|||||||
// return 1;}
|
// return 1;}
|
||||||
|
|
||||||
virtual int isBusy() {
|
virtual int isBusy() {
|
||||||
|
//std::cout << busy << " " << fifoData->isEmpty() << " " << fifoData->getDataValue() << " " << fifoData->getFreeValue() << std::endl;
|
||||||
if (busy == 0) {
|
if (busy == 0) {
|
||||||
usleep(100);
|
usleep(100);
|
||||||
if (busy == 0) {
|
if (busy == 0) {
|
||||||
|
@ -63,6 +63,7 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
|
|||||||
quad(UNDEFINED_QUADRANT), tot(0), quadTot(0) {
|
quad(UNDEFINED_QUADRANT), tot(0), quadTot(0) {
|
||||||
|
|
||||||
fm = new pthread_mutex_t;
|
fm = new pthread_mutex_t;
|
||||||
|
pthread_mutex_init(fm, NULL);
|
||||||
|
|
||||||
eventMask = new eventType *[ny];
|
eventMask = new eventType *[ny];
|
||||||
// val=new double*[ny];
|
// val=new double*[ny];
|
||||||
@ -233,8 +234,8 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
|
|||||||
//cout << "add to common mode?" << endl;
|
//cout << "add to common mode?" << endl;
|
||||||
addToCommonMode(data);
|
addToCommonMode(data);
|
||||||
}
|
}
|
||||||
for (iy = ymin; iy < ymax; ++iy) {
|
for (int iy = ymin; iy < ymax; ++iy) {
|
||||||
for (ix = xmin; ix < xmax; ++ix) {
|
for (int ix = xmin; ix < xmax; ++ix) {
|
||||||
if (det->isGood(ix, iy)) {
|
if (det->isGood(ix, iy)) {
|
||||||
val = subtractPedestal(data, ix, iy, cm);
|
val = subtractPedestal(data, ix, iy, cm);
|
||||||
|
|
||||||
@ -252,8 +253,8 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (iy = ymin; iy < ymax; ++iy) {
|
for (int iy = ymin; iy < ymax; ++iy) {
|
||||||
for (ix = xmin; ix < xmax; ++ix) {
|
for (int ix = xmin; ix < xmax; ++ix) {
|
||||||
|
|
||||||
if (det->isGood(ix, iy)) {
|
if (det->isGood(ix, iy)) {
|
||||||
eventMask[iy][ix] = PEDESTAL;
|
eventMask[iy][ix] = PEDESTAL;
|
||||||
@ -404,8 +405,8 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
|
|||||||
|
|
||||||
double *val = new double[ny * nx];
|
double *val = new double[ny * nx];
|
||||||
|
|
||||||
for (iy = ymin; iy < ymax; ++iy) {
|
for (int iy = ymin; iy < ymax; ++iy) {
|
||||||
for (ix = xmin; ix < xmax; ++ix) {
|
for (int ix = xmin; ix < xmax; ++ix) {
|
||||||
if (det->isGood(ix, iy) == 0)
|
if (det->isGood(ix, iy) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ void qTabSettings::SetupWidgetWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void qTabSettings::SetExportMode(bool exportMode) {
|
void qTabSettings::SetExportMode(bool exportMode) {
|
||||||
if (comboGainMode->isVisible()) {
|
if (comboGainMode->isEnabled()) {
|
||||||
ShowFixG0(exportMode);
|
ShowFixG0(exportMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -1449,7 +1449,7 @@ void setTiming(enum timingMode arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum timingMode getTiming() {
|
enum timingMode getTiming() {
|
||||||
if (bus_r(EXT_SIGNAL_REG) == EXT_SIGNAL_MSK)
|
if ((bus_r(EXT_SIGNAL_REG) & EXT_SIGNAL_MSK) >> EXT_SIGNAL_OFST)
|
||||||
return TRIGGER_EXPOSURE;
|
return TRIGGER_EXPOSURE;
|
||||||
return AUTO_TIMING;
|
return AUTO_TIMING;
|
||||||
}
|
}
|
||||||
@ -1736,40 +1736,40 @@ int setDetectorPosition(int pos[]) {
|
|||||||
detPos[2] = outerPos[X];
|
detPos[2] = outerPos[X];
|
||||||
detPos[3] = outerPos[Y];
|
detPos[3] = outerPos[Y];
|
||||||
|
|
||||||
// row
|
// row [Y]
|
||||||
// outer
|
// outer
|
||||||
uint32_t addr = COORD_ROW_REG;
|
uint32_t addr = COORD_ROW_REG;
|
||||||
bus_w(addr,
|
bus_w(addr,
|
||||||
(bus_r(addr) & ~COORD_ROW_OUTER_MSK) |
|
(bus_r(addr) & ~COORD_ROW_OUTER_MSK) |
|
||||||
((outerPos[X] << COORD_ROW_OUTER_OFST) & COORD_ROW_OUTER_MSK));
|
((outerPos[Y] << COORD_ROW_OUTER_OFST) & COORD_ROW_OUTER_MSK));
|
||||||
if (((bus_r(addr) & COORD_ROW_OUTER_MSK) >> COORD_ROW_OUTER_OFST) !=
|
if (((bus_r(addr) & COORD_ROW_OUTER_MSK) >> COORD_ROW_OUTER_OFST) !=
|
||||||
outerPos[X])
|
|
||||||
ret = FAIL;
|
|
||||||
// inner
|
|
||||||
bus_w(addr,
|
|
||||||
(bus_r(addr) & ~COORD_ROW_INNER_MSK) |
|
|
||||||
((innerPos[X] << COORD_ROW_INNER_OFST) & COORD_ROW_INNER_MSK));
|
|
||||||
if (((bus_r(addr) & COORD_ROW_INNER_MSK) >> COORD_ROW_INNER_OFST) !=
|
|
||||||
innerPos[X])
|
|
||||||
ret = FAIL;
|
|
||||||
|
|
||||||
// col
|
|
||||||
// outer
|
|
||||||
addr = COORD_COL_REG;
|
|
||||||
bus_w(addr,
|
|
||||||
(bus_r(addr) & ~COORD_COL_OUTER_MSK) |
|
|
||||||
((outerPos[Y] << COORD_COL_OUTER_OFST) & COORD_COL_OUTER_MSK));
|
|
||||||
if (((bus_r(addr) & COORD_COL_OUTER_MSK) >> COORD_COL_OUTER_OFST) !=
|
|
||||||
outerPos[Y])
|
outerPos[Y])
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
// inner
|
// inner
|
||||||
bus_w(addr,
|
bus_w(addr,
|
||||||
(bus_r(addr) & ~COORD_COL_INNER_MSK) |
|
(bus_r(addr) & ~COORD_ROW_INNER_MSK) |
|
||||||
((innerPos[Y] << COORD_COL_INNER_OFST) & COORD_COL_INNER_MSK));
|
((innerPos[Y] << COORD_ROW_INNER_OFST) & COORD_ROW_INNER_MSK));
|
||||||
if (((bus_r(addr) & COORD_COL_INNER_MSK) >> COORD_COL_INNER_OFST) !=
|
if (((bus_r(addr) & COORD_ROW_INNER_MSK) >> COORD_ROW_INNER_OFST) !=
|
||||||
innerPos[Y])
|
innerPos[Y])
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
|
|
||||||
|
// col [X]
|
||||||
|
// outer
|
||||||
|
addr = COORD_COL_REG;
|
||||||
|
bus_w(addr,
|
||||||
|
(bus_r(addr) & ~COORD_COL_OUTER_MSK) |
|
||||||
|
((outerPos[X] << COORD_COL_OUTER_OFST) & COORD_COL_OUTER_MSK));
|
||||||
|
if (((bus_r(addr) & COORD_COL_OUTER_MSK) >> COORD_COL_OUTER_OFST) !=
|
||||||
|
outerPos[X])
|
||||||
|
ret = FAIL;
|
||||||
|
// inner
|
||||||
|
bus_w(addr,
|
||||||
|
(bus_r(addr) & ~COORD_COL_INNER_MSK) |
|
||||||
|
((innerPos[X] << COORD_COL_INNER_OFST) & COORD_COL_INNER_MSK));
|
||||||
|
if (((bus_r(addr) & COORD_COL_INNER_MSK) >> COORD_COL_INNER_OFST) !=
|
||||||
|
innerPos[X])
|
||||||
|
ret = FAIL;
|
||||||
|
|
||||||
if (ret == OK) {
|
if (ret == OK) {
|
||||||
if (getNumberofUDPInterfaces() == 1) {
|
if (getNumberofUDPInterfaces() == 1) {
|
||||||
LOG(logINFOBLUE, ("Position set to [%d, %d] #(col, row)\n",
|
LOG(logINFOBLUE, ("Position set to [%d, %d] #(col, row)\n",
|
||||||
|
Binary file not shown.
@ -1345,7 +1345,7 @@ void setTiming(enum timingMode arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum timingMode getTiming() {
|
enum timingMode getTiming() {
|
||||||
if (bus_r(EXT_SIGNAL_REG) == EXT_SIGNAL_MSK)
|
if ((bus_r(EXT_SIGNAL_REG) & EXT_SIGNAL_MSK) >> EXT_SIGNAL_OFST)
|
||||||
return TRIGGER_EXPOSURE;
|
return TRIGGER_EXPOSURE;
|
||||||
return AUTO_TIMING;
|
return AUTO_TIMING;
|
||||||
}
|
}
|
||||||
@ -1632,40 +1632,40 @@ int setDetectorPosition(int pos[]) {
|
|||||||
detPos[2] = outerPos[X];
|
detPos[2] = outerPos[X];
|
||||||
detPos[3] = outerPos[Y];
|
detPos[3] = outerPos[Y];
|
||||||
|
|
||||||
// row
|
// row [Y]
|
||||||
// outer
|
// outer
|
||||||
uint32_t addr = COORD_ROW_REG;
|
uint32_t addr = COORD_ROW_REG;
|
||||||
bus_w(addr,
|
bus_w(addr,
|
||||||
(bus_r(addr) & ~COORD_ROW_OUTER_MSK) |
|
(bus_r(addr) & ~COORD_ROW_OUTER_MSK) |
|
||||||
((outerPos[X] << COORD_ROW_OUTER_OFST) & COORD_ROW_OUTER_MSK));
|
((outerPos[Y] << COORD_ROW_OUTER_OFST) & COORD_ROW_OUTER_MSK));
|
||||||
if (((bus_r(addr) & COORD_ROW_OUTER_MSK) >> COORD_ROW_OUTER_OFST) !=
|
if (((bus_r(addr) & COORD_ROW_OUTER_MSK) >> COORD_ROW_OUTER_OFST) !=
|
||||||
outerPos[X])
|
|
||||||
ret = FAIL;
|
|
||||||
// inner
|
|
||||||
bus_w(addr,
|
|
||||||
(bus_r(addr) & ~COORD_ROW_INNER_MSK) |
|
|
||||||
((innerPos[X] << COORD_ROW_INNER_OFST) & COORD_ROW_INNER_MSK));
|
|
||||||
if (((bus_r(addr) & COORD_ROW_INNER_MSK) >> COORD_ROW_INNER_OFST) !=
|
|
||||||
innerPos[X])
|
|
||||||
ret = FAIL;
|
|
||||||
|
|
||||||
// col
|
|
||||||
// outer
|
|
||||||
addr = COORD_COL_REG;
|
|
||||||
bus_w(addr,
|
|
||||||
(bus_r(addr) & ~COORD_COL_OUTER_MSK) |
|
|
||||||
((outerPos[Y] << COORD_COL_OUTER_OFST) & COORD_COL_OUTER_MSK));
|
|
||||||
if (((bus_r(addr) & COORD_COL_OUTER_MSK) >> COORD_COL_OUTER_OFST) !=
|
|
||||||
outerPos[Y])
|
outerPos[Y])
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
// inner
|
// inner
|
||||||
bus_w(addr,
|
bus_w(addr,
|
||||||
(bus_r(addr) & ~COORD_COL_INNER_MSK) |
|
(bus_r(addr) & ~COORD_ROW_INNER_MSK) |
|
||||||
((innerPos[Y] << COORD_COL_INNER_OFST) & COORD_COL_INNER_MSK));
|
((innerPos[Y] << COORD_ROW_INNER_OFST) & COORD_ROW_INNER_MSK));
|
||||||
if (((bus_r(addr) & COORD_COL_INNER_MSK) >> COORD_COL_INNER_OFST) !=
|
if (((bus_r(addr) & COORD_ROW_INNER_MSK) >> COORD_ROW_INNER_OFST) !=
|
||||||
innerPos[Y])
|
innerPos[Y])
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
|
|
||||||
|
// col [X]
|
||||||
|
// outer
|
||||||
|
addr = COORD_COL_REG;
|
||||||
|
bus_w(addr,
|
||||||
|
(bus_r(addr) & ~COORD_COL_OUTER_MSK) |
|
||||||
|
((outerPos[X] << COORD_COL_OUTER_OFST) & COORD_COL_OUTER_MSK));
|
||||||
|
if (((bus_r(addr) & COORD_COL_OUTER_MSK) >> COORD_COL_OUTER_OFST) !=
|
||||||
|
outerPos[X])
|
||||||
|
ret = FAIL;
|
||||||
|
// inner
|
||||||
|
bus_w(addr,
|
||||||
|
(bus_r(addr) & ~COORD_COL_INNER_MSK) |
|
||||||
|
((innerPos[X] << COORD_COL_INNER_OFST) & COORD_COL_INNER_MSK));
|
||||||
|
if (((bus_r(addr) & COORD_COL_INNER_MSK) >> COORD_COL_INNER_OFST) !=
|
||||||
|
innerPos[X])
|
||||||
|
ret = FAIL;
|
||||||
|
|
||||||
if (ret == OK) {
|
if (ret == OK) {
|
||||||
if (getNumberofUDPInterfaces() == 1) {
|
if (getNumberofUDPInterfaces() == 1) {
|
||||||
LOG(logINFOBLUE, ("Position set to [%d, %d] #(col, row)\n",
|
LOG(logINFOBLUE, ("Position set to [%d, %d] #(col, row)\n",
|
||||||
|
@ -4203,15 +4203,23 @@ int set_adc_enable_mask(int file_des) {
|
|||||||
#else
|
#else
|
||||||
// only set
|
// only set
|
||||||
if (Server_VerifyLock() == OK) {
|
if (Server_VerifyLock() == OK) {
|
||||||
|
if (arg == 0u) {
|
||||||
|
ret = FAIL;
|
||||||
|
sprintf(mess,
|
||||||
|
"Not allowed to set adc mask of 0 due to data readout. \n");
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
} else {
|
||||||
ret = setADCEnableMask(arg);
|
ret = setADCEnableMask(arg);
|
||||||
if (ret == FAIL) {
|
if (ret == FAIL) {
|
||||||
sprintf(mess, "Could not set 1Gb ADC Enable mask to 0x%x.\n", arg);
|
sprintf(mess, "Could not set 1Gb ADC Enable mask to 0x%x.\n",
|
||||||
|
arg);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
} else {
|
} else {
|
||||||
uint32_t retval = getADCEnableMask();
|
uint32_t retval = getADCEnableMask();
|
||||||
if (arg != retval) {
|
if (arg != retval) {
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
sprintf(mess,
|
sprintf(
|
||||||
|
mess,
|
||||||
"Could not set 1Gb ADC Enable mask. Set 0x%x, but read "
|
"Could not set 1Gb ADC Enable mask. Set 0x%x, but read "
|
||||||
"0x%x\n",
|
"0x%x\n",
|
||||||
arg, retval);
|
arg, retval);
|
||||||
@ -4219,6 +4227,7 @@ int set_adc_enable_mask(int file_des) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return Server_SendResult(file_des, INT32, NULL, 0);
|
return Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
}
|
}
|
||||||
@ -4254,6 +4263,12 @@ int set_adc_enable_mask_10g(int file_des) {
|
|||||||
#else
|
#else
|
||||||
// only set
|
// only set
|
||||||
if (Server_VerifyLock() == OK) {
|
if (Server_VerifyLock() == OK) {
|
||||||
|
if (arg == 0u) {
|
||||||
|
ret = FAIL;
|
||||||
|
sprintf(mess,
|
||||||
|
"Not allowed to set adc mask of 0 due to data readout \n");
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
} else {
|
||||||
setADCEnableMask_10G(arg);
|
setADCEnableMask_10G(arg);
|
||||||
uint32_t retval = getADCEnableMask_10G();
|
uint32_t retval = getADCEnableMask_10G();
|
||||||
if (arg != retval) {
|
if (arg != retval) {
|
||||||
@ -4265,6 +4280,7 @@ int set_adc_enable_mask_10g(int file_des) {
|
|||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return Server_SendResult(file_des, INT32, NULL, 0);
|
return Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
}
|
}
|
||||||
|
@ -857,7 +857,7 @@ void Detector::stopDetector(Positions pos) {
|
|||||||
throw RuntimeError(
|
throw RuntimeError(
|
||||||
"Could not stop detector. Returned error status.");
|
"Could not stop detector. Returned error status.");
|
||||||
}
|
}
|
||||||
pimpl->Parallel(&Module::stopAcquisition, pos);
|
pimpl->stopDetector(pos);
|
||||||
status = getDetectorStatus().squash(defs::runStatus::RUNNING);
|
status = getDetectorStatus().squash(defs::runStatus::RUNNING);
|
||||||
++retries;
|
++retries;
|
||||||
|
|
||||||
@ -916,7 +916,7 @@ void Detector::setNextFrameNumber(uint64_t value, Positions pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Detector::sendSoftwareTrigger(const bool block, Positions pos) {
|
void Detector::sendSoftwareTrigger(const bool block, Positions pos) {
|
||||||
pimpl->Parallel(&Module::sendSoftwareTrigger, pos, block);
|
pimpl->sendSoftwareTrigger(block, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<defs::scanParameters> Detector::getScan(Positions pos) const {
|
Result<defs::scanParameters> Detector::getScan(Positions pos) const {
|
||||||
@ -954,18 +954,23 @@ void Detector::setNumberofUDPInterfaces(int n, Positions pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Detector::setNumberofUDPInterfaces_(int n, Positions pos) {
|
void Detector::setNumberofUDPInterfaces_(int n, Positions pos) {
|
||||||
|
if (!size()) {
|
||||||
|
throw RuntimeError("No modules added.");
|
||||||
|
}
|
||||||
bool previouslyClientStreaming = pimpl->getDataStreamingToClient();
|
bool previouslyClientStreaming = pimpl->getDataStreamingToClient();
|
||||||
|
int clientStartingPort = getClientZmqPort({0}).squash(0);
|
||||||
bool useReceiver = getUseReceiverFlag().squash(false);
|
bool useReceiver = getUseReceiverFlag().squash(false);
|
||||||
bool previouslyReceiverStreaming = false;
|
bool previouslyReceiverStreaming = false;
|
||||||
int startingPort = 0;
|
int rxStartingPort = 0;
|
||||||
if (useReceiver) {
|
if (useReceiver) {
|
||||||
previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(true);
|
previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(true);
|
||||||
startingPort = getRxZmqPort({0}).squash(0);
|
rxStartingPort = getRxZmqPort({0}).squash(0);
|
||||||
}
|
}
|
||||||
pimpl->Parallel(&Module::setNumberofUDPInterfaces, pos, n);
|
pimpl->Parallel(&Module::setNumberofUDPInterfaces, pos, n);
|
||||||
// ensure receiver zmq socket ports are multiplied by 2 (2 interfaces)
|
// ensure receiver zmq socket ports are multiplied by 2 (2 interfaces)
|
||||||
if (getUseReceiverFlag().squash(false) && size()) {
|
setClientZmqPort(clientStartingPort, -1);
|
||||||
setRxZmqPort(startingPort, -1);
|
if (getUseReceiverFlag().squash(false)) {
|
||||||
|
setRxZmqPort(rxStartingPort, -1);
|
||||||
}
|
}
|
||||||
// redo the zmq sockets if enabled
|
// redo the zmq sockets if enabled
|
||||||
if (previouslyClientStreaming) {
|
if (previouslyClientStreaming) {
|
||||||
|
@ -755,7 +755,7 @@ void DetectorImpl::readFrameFromReceiver() {
|
|||||||
int nDetActualPixelsY = nDetPixelsY;
|
int nDetActualPixelsY = nDetPixelsY;
|
||||||
|
|
||||||
if (gapPixels) {
|
if (gapPixels) {
|
||||||
int n = InsertGapPixels(multiframe.get(), multigappixels,
|
int n = insertGapPixels(multiframe.get(), multigappixels,
|
||||||
quadEnable, dynamicRange,
|
quadEnable, dynamicRange,
|
||||||
nDetActualPixelsX, nDetActualPixelsY);
|
nDetActualPixelsX, nDetActualPixelsY);
|
||||||
callbackImage = multigappixels;
|
callbackImage = multigappixels;
|
||||||
@ -794,7 +794,7 @@ void DetectorImpl::readFrameFromReceiver() {
|
|||||||
delete[] multigappixels;
|
delete[] multigappixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DetectorImpl::InsertGapPixels(char *image, char *&gpImage, bool quadEnable,
|
int DetectorImpl::insertGapPixels(char *image, char *&gpImage, bool quadEnable,
|
||||||
int dr, int &nPixelsx, int &nPixelsy) {
|
int dr, int &nPixelsx, int &nPixelsy) {
|
||||||
|
|
||||||
LOG(logDEBUG) << "Insert Gap pixels:"
|
LOG(logDEBUG) << "Insert Gap pixels:"
|
||||||
@ -1242,13 +1242,35 @@ int DetectorImpl::acquire() {
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DetectorImpl::startAcquisition(bool blocking, std::vector<int> positions) {
|
bool DetectorImpl::handleSynchronization(Positions pos) {
|
||||||
// handle Mythen3 synchronization
|
bool handleSync = false;
|
||||||
if (shm()->detType == defs::MYTHEN3 && size() > 1) {
|
// multi module m3 or multi module sync enabled jungfrau
|
||||||
std::vector<int> master;
|
if (size() > 1) {
|
||||||
std::vector<int> slaves;
|
switch (shm()->detType) {
|
||||||
if (positions.empty() ||
|
case defs::MYTHEN3:
|
||||||
(positions.size() == 1 && positions[0] == -1)) {
|
case defs::GOTTHARD2:
|
||||||
|
case defs::GOTTHARD:
|
||||||
|
handleSync = true;
|
||||||
|
break;
|
||||||
|
case defs::JUNGFRAU:
|
||||||
|
case defs::MOENCH:
|
||||||
|
if (Parallel(&Module::getSynchronizationFromStopServer, pos)
|
||||||
|
.tsquash("Inconsistent synchronization among modules")) {
|
||||||
|
handleSync = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return handleSync;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DetectorImpl::getMasterSlaveList(std::vector<int> positions,
|
||||||
|
std::vector<int> &masters,
|
||||||
|
std::vector<int> &slaves) {
|
||||||
|
// expand positions list
|
||||||
|
if (positions.empty() || (positions.size() == 1 && positions[0] == -1)) {
|
||||||
positions.resize(modules.size());
|
positions.resize(modules.size());
|
||||||
std::iota(begin(positions), end(positions), 0);
|
std::iota(begin(positions), end(positions), 0);
|
||||||
}
|
}
|
||||||
@ -1257,28 +1279,68 @@ void DetectorImpl::startAcquisition(bool blocking, std::vector<int> positions) {
|
|||||||
auto is_master = Parallel(&Module::isMaster, positions);
|
auto is_master = Parallel(&Module::isMaster, positions);
|
||||||
for (size_t i : positions) {
|
for (size_t i : positions) {
|
||||||
if (is_master[i])
|
if (is_master[i])
|
||||||
master.push_back(i);
|
masters.push_back(i);
|
||||||
else
|
else
|
||||||
slaves.push_back(i);
|
slaves.push_back(i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DetectorImpl::startAcquisition(const bool blocking, Positions pos) {
|
||||||
|
|
||||||
|
// slaves first
|
||||||
|
if (handleSynchronization(pos)) {
|
||||||
|
std::vector<int> masters;
|
||||||
|
std::vector<int> slaves;
|
||||||
|
getMasterSlaveList(pos, masters, slaves);
|
||||||
if (!slaves.empty()) {
|
if (!slaves.empty()) {
|
||||||
Parallel(&Module::startAcquisition, slaves);
|
Parallel(&Module::startAcquisition, slaves);
|
||||||
}
|
}
|
||||||
if (!master.empty()) {
|
if (!masters.empty()) {
|
||||||
if (blocking) {
|
Parallel((blocking ? &Module::startAndReadAll
|
||||||
Parallel(&Module::startAndReadAll, master);
|
: &Module::startAcquisition),
|
||||||
} else {
|
pos);
|
||||||
Parallel(&Module::startAcquisition, master);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
// all in parallel
|
||||||
if (blocking) {
|
else {
|
||||||
Parallel(&Module::startAndReadAll, positions);
|
Parallel(
|
||||||
} else {
|
(blocking ? &Module::startAndReadAll : &Module::startAcquisition),
|
||||||
Parallel(&Module::startAcquisition, positions);
|
pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DetectorImpl::sendSoftwareTrigger(const bool block, Positions pos) {
|
||||||
|
// slaves first
|
||||||
|
if (handleSynchronization(pos)) {
|
||||||
|
std::vector<int> masters;
|
||||||
|
std::vector<int> slaves;
|
||||||
|
getMasterSlaveList(pos, masters, slaves);
|
||||||
|
if (!slaves.empty())
|
||||||
|
Parallel(&Module::sendSoftwareTrigger, slaves, false);
|
||||||
|
if (!masters.empty())
|
||||||
|
Parallel(&Module::sendSoftwareTrigger, masters, block);
|
||||||
|
}
|
||||||
|
// all in parallel
|
||||||
|
else {
|
||||||
|
Parallel(&Module::sendSoftwareTrigger, pos, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DetectorImpl::stopDetector(Positions pos) {
|
||||||
|
// masters first
|
||||||
|
if (handleSynchronization(pos)) {
|
||||||
|
std::vector<int> masters;
|
||||||
|
std::vector<int> slaves;
|
||||||
|
getMasterSlaveList(pos, masters, slaves);
|
||||||
|
if (!masters.empty())
|
||||||
|
Parallel(&Module::stopAcquisition, masters);
|
||||||
|
if (!slaves.empty())
|
||||||
|
Parallel(&Module::stopAcquisition, slaves);
|
||||||
|
}
|
||||||
|
// all in parallel
|
||||||
|
else {
|
||||||
|
Parallel(&Module::stopAcquisition, pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DetectorImpl::printProgress(double progress) {
|
void DetectorImpl::printProgress(double progress) {
|
||||||
@ -1383,7 +1445,8 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
|||||||
default:
|
default:
|
||||||
throw RuntimeError(
|
throw RuntimeError(
|
||||||
"Unknown detector type. Did the 'hostname' command execute "
|
"Unknown detector type. Did the 'hostname' command execute "
|
||||||
"successfully? Or use update mode in the detector server side.");
|
"successfully? Or use update mode in the detector server "
|
||||||
|
"side.");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(logINFO) << "This can take awhile. Please be patient.";
|
LOG(logINFO) << "This can take awhile. Please be patient.";
|
||||||
@ -1411,9 +1474,8 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
|||||||
int dst = mkstemp(destfname); // create temporary file and open it in r/w
|
int dst = mkstemp(destfname); // create temporary file and open it in r/w
|
||||||
if (dst == -1) {
|
if (dst == -1) {
|
||||||
fclose(src);
|
fclose(src);
|
||||||
throw RuntimeError(
|
throw RuntimeError(std::string("Could not create destination file "
|
||||||
std::string(
|
"in /tmp for programming: ") +
|
||||||
"Could not create destination file in /tmp for programming: ") +
|
|
||||||
destfname);
|
destfname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1466,8 +1528,8 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
|||||||
}
|
}
|
||||||
// validate pof: read less than footer offset
|
// validate pof: read less than footer offset
|
||||||
if (isPof && dstFilePos < pofFooterOfst) {
|
if (isPof && dstFilePos < pofFooterOfst) {
|
||||||
throw RuntimeError(
|
throw RuntimeError("Could not convert programming file. EOF "
|
||||||
"Could not convert programming file. EOF before end of flash");
|
"before end of flash");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fclose(src) != 0) {
|
if (fclose(src) != 0) {
|
||||||
|
@ -278,7 +278,13 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
|||||||
int acquire();
|
int acquire();
|
||||||
|
|
||||||
/** also takes care of master and slave for multi module mythen */
|
/** also takes care of master and slave for multi module mythen */
|
||||||
void startAcquisition(bool blocking, std::vector<int> positions);
|
void startAcquisition(const bool blocking, Positions pos);
|
||||||
|
|
||||||
|
/** also takes care of master and slave for multi module mythen */
|
||||||
|
void sendSoftwareTrigger(const bool block, Positions pos);
|
||||||
|
|
||||||
|
/** also takes care of master and slave for multi module mythen */
|
||||||
|
void stopDetector(Positions pos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines data from all readouts and gives it to the gui
|
* Combines data from all readouts and gives it to the gui
|
||||||
@ -379,9 +385,14 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
|||||||
* @param nPixelsy number of pixels in Y axis (updated)
|
* @param nPixelsy number of pixels in Y axis (updated)
|
||||||
* @returns total data bytes for updated image
|
* @returns total data bytes for updated image
|
||||||
*/
|
*/
|
||||||
int InsertGapPixels(char *image, char *&gpImage, bool quadEnable, int dr,
|
int insertGapPixels(char *image, char *&gpImage, bool quadEnable, int dr,
|
||||||
int &nPixelsx, int &nPixelsy);
|
int &nPixelsx, int &nPixelsy);
|
||||||
|
|
||||||
|
bool handleSynchronization(Positions pos);
|
||||||
|
void getMasterSlaveList(std::vector<int> positions,
|
||||||
|
std::vector<int> &masters,
|
||||||
|
std::vector<int> &slaves);
|
||||||
|
|
||||||
void printProgress(double progress);
|
void printProgress(double progress);
|
||||||
|
|
||||||
void startProcessingThread(bool receiver);
|
void startProcessingThread(bool receiver);
|
||||||
|
@ -544,8 +544,15 @@ bool Module::getSynchronization() const {
|
|||||||
return sendToDetector<int>(F_GET_SYNCHRONIZATION);
|
return sendToDetector<int>(F_GET_SYNCHRONIZATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Module::getSynchronizationFromStopServer() const {
|
||||||
|
return sendToDetectorStop<int>(F_GET_SYNCHRONIZATION);
|
||||||
|
}
|
||||||
|
|
||||||
void Module::setSynchronization(const bool value) {
|
void Module::setSynchronization(const bool value) {
|
||||||
sendToDetector(F_SET_SYNCHRONIZATION, static_cast<int>(value), nullptr);
|
sendToDetector(F_SET_SYNCHRONIZATION, static_cast<int>(value), nullptr);
|
||||||
|
// to deal with virtual servers as well
|
||||||
|
// (get sync from stop server during blocking acquisition)
|
||||||
|
sendToDetectorStop(F_SET_SYNCHRONIZATION, static_cast<int>(value), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> Module::getBadChannels() const {
|
std::vector<int> Module::getBadChannels() const {
|
||||||
|
@ -130,6 +130,7 @@ class Module : public virtual slsDetectorDefs {
|
|||||||
bool isMaster() const;
|
bool isMaster() const;
|
||||||
void setMaster(const bool master);
|
void setMaster(const bool master);
|
||||||
bool getSynchronization() const;
|
bool getSynchronization() const;
|
||||||
|
bool getSynchronizationFromStopServer() const;
|
||||||
void setSynchronization(const bool value);
|
void setSynchronization(const bool value);
|
||||||
std::vector<int> getBadChannels() const;
|
std::vector<int> getBadChannels() const;
|
||||||
void setBadChannels(std::vector<int> list);
|
void setBadChannels(std::vector<int> list);
|
||||||
|
@ -1207,10 +1207,10 @@ TEST_CASE("dbitphase", "[.cmd]") {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::ostringstream oss1, oss2;
|
std::ostringstream oss1, oss2;
|
||||||
proxy.Call("dbitphase", {"20", "deg"}, -1, PUT, oss1);
|
proxy.Call("dbitphase", {"23", "deg"}, -1, PUT, oss1);
|
||||||
REQUIRE(oss1.str() == "dbitphase 20 deg\n");
|
REQUIRE(oss1.str() == "dbitphase 23 deg\n");
|
||||||
proxy.Call("dbitphase", {"deg"}, -1, GET, oss2);
|
proxy.Call("dbitphase", {"deg"}, -1, GET, oss2);
|
||||||
REQUIRE(oss2.str() == "dbitphase 20 deg\n");
|
REQUIRE(oss2.str() == "dbitphase 23 deg\n");
|
||||||
}
|
}
|
||||||
for (int i = 0; i != det.size(); ++i) {
|
for (int i = 0; i != det.size(); ++i) {
|
||||||
det.setDBITPhase(prev_val[i], {i});
|
det.setDBITPhase(prev_val[i], {i});
|
||||||
|
@ -56,6 +56,8 @@ void DataStreamer::SetAdditionalJsonHeader(
|
|||||||
isAdditionalJsonUpdated = true;
|
isAdditionalJsonUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataStreamer::SetReceiverROI(ROI roi) { receiverRoi = roi; }
|
||||||
|
|
||||||
void DataStreamer::ResetParametersforNewAcquisition(const std::string &fname) {
|
void DataStreamer::ResetParametersforNewAcquisition(const std::string &fname) {
|
||||||
StopRunning();
|
StopRunning();
|
||||||
startedFlag = false;
|
startedFlag = false;
|
||||||
@ -249,6 +251,7 @@ int DataStreamer::SendDataHeader(sls_detector_header header, uint32_t size,
|
|||||||
isAdditionalJsonUpdated = false;
|
isAdditionalJsonUpdated = false;
|
||||||
}
|
}
|
||||||
zHeader.addJsonHeader = localAdditionalJsonHeader;
|
zHeader.addJsonHeader = localAdditionalJsonHeader;
|
||||||
|
zHeader.rx_roi = receiverRoi.getIntArray();
|
||||||
|
|
||||||
return zmqSocket->SendHeader(index, zHeader);
|
return zmqSocket->SendHeader(index, zHeader);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
|
|||||||
void SetNumberofTotalFrames(uint64_t value);
|
void SetNumberofTotalFrames(uint64_t value);
|
||||||
void
|
void
|
||||||
SetAdditionalJsonHeader(const std::map<std::string, std::string> &json);
|
SetAdditionalJsonHeader(const std::map<std::string, std::string> &json);
|
||||||
|
void SetReceiverROI(ROI roi);
|
||||||
|
|
||||||
void ResetParametersforNewAcquisition(const std::string &fname);
|
void ResetParametersforNewAcquisition(const std::string &fname);
|
||||||
/**
|
/**
|
||||||
@ -92,6 +93,7 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
|
|||||||
uint64_t fileIndex{0};
|
uint64_t fileIndex{0};
|
||||||
bool flipRows{false};
|
bool flipRows{false};
|
||||||
std::map<std::string, std::string> additionalJsonHeader;
|
std::map<std::string, std::string> additionalJsonHeader;
|
||||||
|
ROI receiverRoi{};
|
||||||
|
|
||||||
/** Used by streamer thread to update local copy (reduce number of locks
|
/** Used by streamer thread to update local copy (reduce number of locks
|
||||||
* during streaming) */
|
* during streaming) */
|
||||||
|
@ -216,6 +216,8 @@ void Implementation::SetupDataStreamer(int i) {
|
|||||||
dataStreamer[i]->SetNumberofPorts(numPorts);
|
dataStreamer[i]->SetNumberofPorts(numPorts);
|
||||||
dataStreamer[i]->SetQuadEnable(quadEnable);
|
dataStreamer[i]->SetQuadEnable(quadEnable);
|
||||||
dataStreamer[i]->SetNumberofTotalFrames(numberOfTotalFrames);
|
dataStreamer[i]->SetNumberofTotalFrames(numberOfTotalFrames);
|
||||||
|
dataStreamer[i]->SetReceiverROI(
|
||||||
|
portRois[i].completeRoi() ? GetMaxROIPerPort() : portRois[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
slsDetectorDefs::xy Implementation::getDetectorSize() const {
|
slsDetectorDefs::xy Implementation::getDetectorSize() const {
|
||||||
@ -231,6 +233,11 @@ const slsDetectorDefs::xy Implementation::GetPortGeometry() const {
|
|||||||
return portGeometry;
|
return portGeometry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const slsDetectorDefs::ROI Implementation::GetMaxROIPerPort() const {
|
||||||
|
return slsDetectorDefs::ROI{0, (int)generalData->nPixelsX - 1, 0,
|
||||||
|
(int)generalData->nPixelsY - 1};
|
||||||
|
}
|
||||||
|
|
||||||
void Implementation::setDetectorSize(const slsDetectorDefs::xy size) {
|
void Implementation::setDetectorSize(const slsDetectorDefs::xy size) {
|
||||||
xy portGeometry = GetPortGeometry();
|
xy portGeometry = GetPortGeometry();
|
||||||
|
|
||||||
@ -458,6 +465,10 @@ void Implementation::setReceiverROI(const slsDetectorDefs::ROI arg) {
|
|||||||
listener[i]->SetNoRoi(portRois[i].noRoi());
|
listener[i]->SetNoRoi(portRois[i].noRoi());
|
||||||
for (size_t i = 0; i != dataProcessor.size(); ++i)
|
for (size_t i = 0; i != dataProcessor.size(); ++i)
|
||||||
dataProcessor[i]->SetReceiverROI(portRois[i]);
|
dataProcessor[i]->SetReceiverROI(portRois[i]);
|
||||||
|
for (size_t i = 0; i != dataStreamer.size(); ++i) {
|
||||||
|
dataStreamer[i]->SetReceiverROI(
|
||||||
|
portRois[i].completeRoi() ? GetMaxROIPerPort() : portRois[i]);
|
||||||
|
}
|
||||||
LOG(logINFO) << "receiver roi: " << ToString(receiverRoi);
|
LOG(logINFO) << "receiver roi: " << ToString(receiverRoi);
|
||||||
if (generalData->numUDPInterfaces == 2 &&
|
if (generalData->numUDPInterfaces == 2 &&
|
||||||
generalData->detType != slsDetectorDefs::GOTTHARD2) {
|
generalData->detType != slsDetectorDefs::GOTTHARD2) {
|
||||||
|
@ -282,6 +282,7 @@ class Implementation : private virtual slsDetectorDefs {
|
|||||||
void SetupFifoStructure();
|
void SetupFifoStructure();
|
||||||
|
|
||||||
const xy GetPortGeometry() const;
|
const xy GetPortGeometry() const;
|
||||||
|
const ROI GetMaxROIPerPort() const;
|
||||||
void ResetParametersforNewAcquisition();
|
void ResetParametersforNewAcquisition();
|
||||||
void CreateUDPSockets();
|
void CreateUDPSockets();
|
||||||
void SetupWriter();
|
void SetupWriter();
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "sls/container_utils.h"
|
#include "sls/container_utils.h"
|
||||||
#include "sls/sls_detector_exceptions.h"
|
#include "sls/sls_detector_exceptions.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -83,6 +84,8 @@ struct zmqHeader {
|
|||||||
bool completeImage{false};
|
bool completeImage{false};
|
||||||
/** additional json header */
|
/** additional json header */
|
||||||
std::map<std::string, std::string> addJsonHeader;
|
std::map<std::string, std::string> addJsonHeader;
|
||||||
|
/** (xmin, xmax, ymin, ymax) roi only in files written */
|
||||||
|
std::array<int, 4> rx_roi{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class ZmqSocket {
|
class ZmqSocket {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
/** API versions */
|
/** API versions */
|
||||||
#define RELEASE "developer"
|
#define RELEASE "developer"
|
||||||
#define APICTB "developer 0x230224"
|
|
||||||
#define APIGOTTHARD "developer 0x230224"
|
#define APIGOTTHARD "developer 0x230224"
|
||||||
#define APIGOTTHARD2 "developer 0x230224"
|
#define APIGOTTHARD2 "developer 0x230224"
|
||||||
#define APIJUNGFRAU "developer 0x230224"
|
|
||||||
#define APIMYTHEN3 "developer 0x230224"
|
#define APIMYTHEN3 "developer 0x230224"
|
||||||
#define APIMOENCH "developer 0x230224"
|
|
||||||
#define APILIB "developer 0x230224"
|
#define APILIB "developer 0x230224"
|
||||||
#define APIRECEIVER "developer 0x230224"
|
#define APIRECEIVER "developer 0x230224"
|
||||||
#define APIEIGER "developer 0x230224"
|
#define APIEIGER "developer 0x230224"
|
||||||
|
#define APIJUNGFRAU "developer 0x230508"
|
||||||
|
#define APIMOENCH "developer 0x230508"
|
||||||
|
#define APICTB "developer 0x230522"
|
||||||
|
@ -254,6 +254,8 @@ int ZmqSocket::SendHeader(int index, zmqHeader header) {
|
|||||||
}
|
}
|
||||||
oss << " } ";
|
oss << " } ";
|
||||||
}
|
}
|
||||||
|
oss << ", \"rx_roi\":[" << header.rx_roi[0] << ", " << header.rx_roi[1]
|
||||||
|
<< ", " << header.rx_roi[2] << ", " << header.rx_roi[3] << "]";
|
||||||
oss << "}\n";
|
oss << "}\n";
|
||||||
std::string message = oss.str();
|
std::string message = oss.str();
|
||||||
int length = message.length();
|
int length = message.length();
|
||||||
@ -375,6 +377,11 @@ int ZmqSocket::ParseHeader(const int index, int length, char *buff,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Value &a = document["rx_roi"].GetArray();
|
||||||
|
for (SizeType i = 0; i != a.Size(); ++i) {
|
||||||
|
zHeader.rx_roi[i] = a[i].GetInt();
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,3 +58,5 @@ set_target_properties(tests PROPERTIES
|
|||||||
include(CTest)
|
include(CTest)
|
||||||
include(Catch)
|
include(Catch)
|
||||||
catch_discover_tests(tests)
|
catch_discover_tests(tests)
|
||||||
|
|
||||||
|
configure_file(scripts/test_simulators.py ${CMAKE_BINARY_DIR}/bin/test_simulators.py COPYONLY)
|
||||||
|
200
tests/scripts/test_simulators.py
Normal file
200
tests/scripts/test_simulators.py
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
# SPDX-License-Identifier: LGPL-3.0-or-other
|
||||||
|
# Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
|
'''
|
||||||
|
This file is used to start up simulators, receivers and run all the tests on them and finally kill the simulators and receivers.
|
||||||
|
'''
|
||||||
|
import argparse
|
||||||
|
import os, sys, subprocess, time, colorama, signal, psutil
|
||||||
|
|
||||||
|
from colorama import Fore
|
||||||
|
from slsdet import Detector, detectorType, detectorSettings
|
||||||
|
from slsdet.defines import DEFAULT_TCP_CNTRL_PORTNO, DEFAULT_TCP_RX_PORTNO, DEFAULT_UDP_DST_PORTNO
|
||||||
|
HALFMOD2_TCP_CNTRL_PORTNO=1955
|
||||||
|
HALFMOD2_TCP_RX_PORTNO=1957
|
||||||
|
|
||||||
|
colorama.init(autoreset=True)
|
||||||
|
|
||||||
|
class RuntimeException (Exception):
|
||||||
|
def __init__ (self, message):
|
||||||
|
super().__init__(Fore.RED + message)
|
||||||
|
|
||||||
|
def Log(color, message):
|
||||||
|
print('\n' + color + message, flush=True)
|
||||||
|
|
||||||
|
def checkIfProcessRunning(processName):
|
||||||
|
'''
|
||||||
|
Check if there is any running process that contains the given name processName.
|
||||||
|
https://gist.github.com/Sanix-Darker/8cbed2ff6f8eb108ce2c8c51acd2aa5a
|
||||||
|
'''
|
||||||
|
# Iterate over the all the running process
|
||||||
|
for proc in psutil.process_iter():
|
||||||
|
try:
|
||||||
|
# Check if process name contains the given name string.
|
||||||
|
if processName.lower() in proc.name().lower():
|
||||||
|
return True
|
||||||
|
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
|
||||||
|
pass
|
||||||
|
return False;
|
||||||
|
|
||||||
|
def killProcess(name):
|
||||||
|
if checkIfProcessRunning(name):
|
||||||
|
Log(Fore.GREEN, 'killing ' + name)
|
||||||
|
p = subprocess.run(['killall', name])
|
||||||
|
if p.returncode != 0:
|
||||||
|
raise RuntimeException('error in killall ' + name)
|
||||||
|
|
||||||
|
def cleanup(name, d):
|
||||||
|
'''
|
||||||
|
kill both servers, receivers and clean shared memory
|
||||||
|
'''
|
||||||
|
Log(Fore.GREEN, 'Cleaning up...')
|
||||||
|
killProcess(name + 'DetectorServer_virtual')
|
||||||
|
killProcess('slsReceiver')
|
||||||
|
killProcess('slsMultiReceiver')
|
||||||
|
d.freeSharedMemory()
|
||||||
|
|
||||||
|
def startProcessInBackground(name):
|
||||||
|
try:
|
||||||
|
# in background and dont print output
|
||||||
|
p = subprocess.Popen(name.split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
Log(Fore.GREEN, 'Starting up ' + name + ' ...')
|
||||||
|
except:
|
||||||
|
Log(Fore.RED, 'Could not start ' + name)
|
||||||
|
raise
|
||||||
|
|
||||||
|
def startServer(name):
|
||||||
|
startProcessInBackground(name + 'DetectorServer_virtual')
|
||||||
|
# second half
|
||||||
|
if name == 'eiger':
|
||||||
|
startProcessInBackground(name + 'DetectorServer_virtual -p' + str(HALFMOD2_TCP_CNTRL_PORTNO))
|
||||||
|
tStartup = 6
|
||||||
|
Log(Fore.WHITE, 'Takes ' + str(tStartup) + ' seconds... Please be patient')
|
||||||
|
time.sleep(tStartup)
|
||||||
|
|
||||||
|
def startReceiver(name):
|
||||||
|
startProcessInBackground('slsReceiver')
|
||||||
|
# second half
|
||||||
|
if name == 'eiger':
|
||||||
|
startProcessInBackground('slsReceiver -t' + str(HALFMOD2_TCP_RX_PORTNO))
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
def loadConfig(name, rx_hostname, settingsdir):
|
||||||
|
try:
|
||||||
|
d = Detector()
|
||||||
|
if name == 'eiger':
|
||||||
|
d.hostname = 'localhost:' + str(DEFAULT_TCP_CNTRL_PORTNO) + '+localhost:' + str(HALFMOD2_TCP_CNTRL_PORTNO)
|
||||||
|
#d.udp_dstport = {2: 50003}
|
||||||
|
# will set up for every module
|
||||||
|
d.udp_dstport = DEFAULT_UDP_DST_PORTNO
|
||||||
|
d.udp_dstport2 = DEFAULT_UDP_DST_PORTNO + 1
|
||||||
|
d.rx_hostname = rx_hostname + ':' + str(DEFAULT_TCP_RX_PORTNO) + '+' + rx_hostname + ':' + str(HALFMOD2_TCP_RX_PORTNO)
|
||||||
|
d.udp_dstip = 'auto'
|
||||||
|
d.trimen = [4500, 5400, 6400]
|
||||||
|
d.settingspath = settingsdir + '/eiger/'
|
||||||
|
d.setThresholdEnergy(4500, detectorSettings.STANDARD)
|
||||||
|
else:
|
||||||
|
d.hostname = 'localhost'
|
||||||
|
d.rx_hostname = rx_hostname
|
||||||
|
d.udp_dstip = 'auto'
|
||||||
|
if d.type == detectorType.GOTTHARD:
|
||||||
|
d.udp_srcip = d.udp_dstip
|
||||||
|
else:
|
||||||
|
d.udp_srcip = 'auto'
|
||||||
|
if d.type == detectorType.JUNGFRAU or d.type == detectorType.MOENCH:
|
||||||
|
d.powerchip = 1
|
||||||
|
except:
|
||||||
|
Log(Fore.RED, 'Could not load config for ' + name)
|
||||||
|
raise
|
||||||
|
|
||||||
|
def startCmdTests(name, fp):
|
||||||
|
try:
|
||||||
|
p = subprocess.run(['tests', '--abort', '[.cmd]'], stdout=fp, stderr=fp)
|
||||||
|
if p.returncode != 0:
|
||||||
|
raise Exception
|
||||||
|
except:
|
||||||
|
Log(Fore.RED, 'Cmd tests failed for ' + name)
|
||||||
|
raise
|
||||||
|
|
||||||
|
def startNormalTests(d, fp):
|
||||||
|
try:
|
||||||
|
Log(Fore.BLUE, '\nNormal tests')
|
||||||
|
p = subprocess.run(['tests', '--abort' ], stdout=fp, stderr=fp)
|
||||||
|
if p.returncode != 0:
|
||||||
|
raise Exception
|
||||||
|
d.freeSharedMemory()
|
||||||
|
except:
|
||||||
|
Log(Fore.RED, 'Normal tests failed')
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
# parse cmd line for rx_hostname and settingspath using the argparse library
|
||||||
|
parser = argparse.ArgumentParser(description = 'automated tests with the virtual detector servers')
|
||||||
|
parser.add_argument('rx_hostname', help = 'hostname/ip of the current machine')
|
||||||
|
parser.add_argument('settingspath', help = 'Relative or absolut path to the settingspath')
|
||||||
|
parser.add_argument('-s', '--servers', help='Detector servers to run', nargs='*')
|
||||||
|
args = parser.parse_args()
|
||||||
|
if args.rx_hostname == 'localhost':
|
||||||
|
raise RuntimeException('Cannot use localhost for rx_hostname for the tests (fails for rx_arping for eg.)')
|
||||||
|
|
||||||
|
if args.servers is None:
|
||||||
|
servers = [
|
||||||
|
'eiger',
|
||||||
|
'jungfrau',
|
||||||
|
'mythen3',
|
||||||
|
'gotthard2',
|
||||||
|
'gotthard',
|
||||||
|
'ctb',
|
||||||
|
'moench',
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
servers = args.servers
|
||||||
|
|
||||||
|
Log(Fore.WHITE, 'rx_hostname: ' + args.rx_hostname + '\settingspath: \'' + args.settingspath + '\'')
|
||||||
|
|
||||||
|
|
||||||
|
# handle zombies (else killing slsReceivers will fail)
|
||||||
|
# dont care about child process success
|
||||||
|
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
|
||||||
|
|
||||||
|
|
||||||
|
# redirect to file
|
||||||
|
original_stdout = sys.stdout
|
||||||
|
original_stderr = sys.stderr
|
||||||
|
fname = '/tmp/slsDetectorPackage_virtual_test.txt'
|
||||||
|
Log(Fore.BLUE, 'Tests -> ' + fname)
|
||||||
|
with open(fname, 'w') as fp:
|
||||||
|
sys.stdout = fp
|
||||||
|
sys.stderr = fp
|
||||||
|
|
||||||
|
d = Detector()
|
||||||
|
# TODO: redirect Detector object print out also to file
|
||||||
|
startNormalTests(d, fp)
|
||||||
|
|
||||||
|
for server in servers:
|
||||||
|
try:
|
||||||
|
# print to terminal for progress
|
||||||
|
sys.stdout = original_stdout
|
||||||
|
sys.stderr = original_stderr
|
||||||
|
Log(Fore.BLUE, server + ' tests')
|
||||||
|
sys.stdout = fp
|
||||||
|
sys.stderr = fp
|
||||||
|
|
||||||
|
# cmd tests for det
|
||||||
|
Log(Fore.BLUE, 'Cmd Tests for ' + server)
|
||||||
|
cleanup(server, d)
|
||||||
|
startServer(server)
|
||||||
|
startReceiver(server)
|
||||||
|
loadConfig(server, args.rx_hostname, args.settingspath)
|
||||||
|
startCmdTests(server, fp)
|
||||||
|
cleanup(server, d)
|
||||||
|
except:
|
||||||
|
cleanup(server, d)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
Log(Fore.GREEN, 'Passed all tests for virtual detectors \n' + str(servers))
|
||||||
|
|
||||||
|
# redirect to terminal
|
||||||
|
sys.stdout = original_stdout
|
||||||
|
sys.stderr = original_stderr
|
||||||
|
Log(Fore.GREEN, 'Passed all tests for virtual detectors \n' + str(servers) + '\nYayyyy! :) ')
|
Reference in New Issue
Block a user