formatting (#716)

* formatting
This commit is contained in:
Dhanya Thattil
2023-04-12 15:30:34 +02:00
committed by GitHub
parent a5022ff0ee
commit cb4f733350
4 changed files with 588 additions and 535 deletions

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
//#include "sls/ansi.h"
// #include "sls/ansi.h"
#include <iostream>
#undef CORR
@ -10,7 +10,8 @@
#define RAWDATA
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && !defined JFSTRXCHIP6
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
!defined JFSTRXCHIP6
#ifndef MODULE
#include "jungfrauHighZSingleChipData.h"
#endif
@ -38,34 +39,38 @@
#include <sys/stat.h>
#include <ctime>
//using namespace std;
// using namespace std;
int main(int argc, char *argv[]) {
if (argc < 5) {
std::cout << "Usage is " << argv[0]
<< "indir outdir fname(with formatting, no extension) fextension [runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
"[nframes] [xmin xmax ymin ymax] [gainmap]"
<< 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;
std::cout
<< "Usage is " << argv[0]
<< "indir outdir fname(with formatting, no extension) fextension "
"[runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
"[nframes] [xmin xmax ymin ymax] [gainmap]"
<< 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 csize = 3; // 3
int nsigma = 5;
int nped = 10000;
int cf = 0;
double *gainmap = NULL;
//float *gm;
// float *gm;
int ff, np;
// cout << " data size is " << dsize;
@ -110,9 +115,9 @@ int main(int argc, char *argv[]) {
char imgfname[10000];
char cfname[10000];
//Define decoders...
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && !defined JFSTRXCHIP6
// Define decoders...
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
!defined JFSTRXCHIP6
#ifndef MODULE
jungfrauHighZSingleChipData *decoder = new jungfrauHighZSingleChipData();
int nx = 256, ny = 256;
@ -125,67 +130,71 @@ int main(int argc, char *argv[]) {
#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;
// ROI
uint16_t xxmin = 0;
uint16_t xxmax = 0;
uint16_t yymin = 0;
uint16_t yymax = 0;
#ifndef ALDO
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 {
uint16_t xmin;
uint16_t xmax;
uint16_t ymin;
uint16_t ymax;
uint16_t xmin;
uint16_t xmax;
uint16_t ymin;
uint16_t ymax;
} receiverRoi_compact;
receiverRoi_compact croi;
sprintf(ffname, "%s/%s.%s", indir, fformat, fext);
sprintf(fname, (const char*)ffname, runmin);
std::cout << "Reading header of file " << fname << " to check for ROI " << std::endl;
sprintf(fname, (const char *)ffname, runmin);
std::cout << "Reading header of file " << fname << " to check for ROI "
<< std::endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
if (filebin.is_open()) {
header hbuffer;
std::cout << "sizeof(header) = " << sizeof(header) << std::endl;
if ( filebin.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;
filebin.close();
header hbuffer;
std::cout << "sizeof(header) = " << sizeof(header) << std::endl;
if (filebin.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;
filebin.close();
} else
std::cout << "Could not open " << fname << " for reading " << std::endl;
std::cout << "Could not open " << fname << " for reading " << std::endl;
#endif
jungfrauLGADStrixelsData *decoder = new jungfrauLGADStrixelsData( xxmin, xxmax, yymin, yymax );
int nx = 1024/3, ny = 512*5;
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;
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;
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;
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;
int xmin = 0, xmax = nx, ymin = 0, ymax = ny;
if (argc >= 14) {
xmin = atoi(argv[10]);
@ -193,12 +202,13 @@ int main(int argc, char *argv[]) {
ymin = atoi(argv[12]);
ymax = atoi(argv[13]);
}
std::cout << xmin << " " << xmax << " " << ymin << " " << ymax << " " << std::endl;
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::cout << "Gain map file name is: " << gainfname << std::endl;
}
std::time_t end_time;
@ -210,34 +220,32 @@ int main(int argc, char *argv[]) {
std::cout << "runmin is " << runmin << std::endl;
std::cout << "runmax is " << runmax << std::endl;
if (pedfile)
std::cout << "pedestal file is " << pedfile << std::endl;
std::cout << "pedestal file is " << pedfile << std::endl;
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 << "HHHEEEEEEEEEEEEEEEEEEEEEEERE!!!!!" << std::endl;
// std::cout << "HHHEEEEEEEEEEEEEEEEEEEEEEERE!!!!!" << 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;
std::cout << "using gain map " << gainfname << std::endl;
else
std::cout << "Could not open gain map " << gainfname << std::endl;
std::cout << "Could not open gain map " << gainfname << std::endl;
} else
thr = 0.15 * thr;
filter->newDataSet();
//int dsize = decoder->getDataSize();
// int dsize = decoder->getDataSize();
if (thr > 0) {
std::cout << "threshold is " << thr << std::endl;
filter->setThreshold(thr);
cf = 0;
std::cout << "threshold is " << thr << std::endl;
filter->setThreshold(thr);
cf = 0;
} else
cf = 1;
@ -252,7 +260,7 @@ int main(int argc, char *argv[]) {
// multiThreadedAnalogDetector(filter,nthreads,fifosize);
multiThreadedCountingDetector *mt =
new multiThreadedCountingDetector(filter, nthreads, fifosize);
mt->setClusterSize(csize,csize);
mt->setClusterSize(csize, csize);
#ifndef ANALOG
mt->setDetectorMode(ePhotonCounting);
@ -278,186 +286,193 @@ int main(int argc, char *argv[]) {
int ifr = 0;
char froot[1000];
double *ped=new double[nx * ny];//, *ped1;
double *ped = new double[nx * ny]; //, *ped1;
int pos,pos1;
int pos, pos1;
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';
}
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;
// sprintf(imgfname, "%s/pedestals.tiff", outdir);
std::cout << "PEDESTAL " << std::endl;
// sprintf(imgfname, "%s/pedestals.tiff", outdir);
if (string(pedfile).find(".tif") == std::string::npos) {
sprintf(fname, "%s", pedfile);
std::cout << fname << std::endl;
std::time(&end_time);
std::cout << "aaa" << std::ctime(&end_time) << std::endl;
mt->setFrameMode(ePedestal);
// sprintf(fn,fformat,irun);
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
if (filebin.is_open()) {
std::cout << "bbbb" << std::ctime(&end_time) << std::endl;
ff = -1;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
// if (np == 40) {
if ((ifr+1) % 100 == 0) {
std::cout << " ****" << decoder->getValue(buff,20,20);// << endl;
}
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
ifr++;
if (ifr % 100 == 0) {
std::cout << " ****" << ifr << " " << ff << " " << np << std::endl;
} //else
//cout << ifr << " " << ff << " " << np << endl;
if (ifr>=1000)
break;
ff = -1;
}
filebin.close();
while (mt->isBusy()) {
;
}
sprintf(imgfname, "%s/%s_ped.tiff", outdir, froot);
mt->writePedestal(imgfname);
sprintf(imgfname, "%s/%s_rms.tiff", outdir, froot);
mt->writePedestalRMS(imgfname);
} else
std::cout << "Could not open pedestal file " << fname
<< " for reading " << std::endl;
} else {
float *pp = ReadFromTiff(pedfile, 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);
std::cout << "Pedestal set from tiff file " << pedfile << std::endl;
} else {
std::cout << "Could not open pedestal tiff file " << pedfile
<< " for reading " << std::endl;
}
}
std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl;
if (string(pedfile).find(".tif") == std::string::npos) {
sprintf(fname, "%s", pedfile);
std::cout << fname << std::endl;
std::time(&end_time);
std::cout << "aaa" << std::ctime(&end_time) << std::endl;
mt->setFrameMode(ePedestal);
// sprintf(fn,fformat,irun);
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
if (filebin.is_open()) {
std::cout << "bbbb" << std::ctime(&end_time) << std::endl;
ff = -1;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
// if (np == 40) {
if ((ifr + 1) % 100 == 0) {
std::cout
<< " ****"
<< decoder->getValue(buff, 20, 20); // << endl;
}
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
ifr++;
if (ifr % 100 == 0) {
std::cout << " ****" << ifr << " " << ff << " " << np
<< std::endl;
} // else
// cout << ifr << " " << ff << " " << np << endl;
if (ifr >= 1000)
break;
ff = -1;
}
filebin.close();
while (mt->isBusy()) {
;
}
sprintf(imgfname, "%s/%s_ped.tiff", outdir, froot);
mt->writePedestal(imgfname);
sprintf(imgfname, "%s/%s_rms.tiff", outdir, froot);
mt->writePedestalRMS(imgfname);
} else
std::cout << "Could not open pedestal file " << fname
<< " for reading " << std::endl;
} else {
float *pp = ReadFromTiff(pedfile, 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);
std::cout << "Pedestal set from tiff file " << pedfile
<< std::endl;
} else {
std::cout << "Could not open pedestal tiff file " << pedfile
<< " for reading " << std::endl;
}
}
std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl;
}
ifr = 0;
int ifile = 0;
mt->setFrameMode(eFrame);
for (int irun = runmin; irun <= runmax; irun++) {
std::cout << "DATA ";
// sprintf(fn,fformat,irun);
sprintf(ffname, "%s/%s.%s", indir, fformat, fext);
sprintf(fname, (const char*)ffname, irun);
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
sprintf(imgfname, (const char*)ffname, irun);
sprintf(ffname, "%s/%s.clust", outdir, fformat);
sprintf(cfname, (const char*)ffname, irun);
std::cout << fname << " ";
std::cout << imgfname << std::endl;
std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl;
// cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
ifile = 0;
if (filebin.is_open()) {
if (thr <= 0 && cf != 0) { // cluster finder
if (of == NULL) {
of = fopen(cfname, "w");
if (of) {
mt->setFilePointer(of);
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);// << 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) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat,
ifile);
sprintf(imgfname, (const char*)ffname, irun);
mt->writeImage(imgfname, thr1);
mt->clearImage();
ifile++;
}
}
// } else
// cout << ifr << " " << ff << " " << np << endl;
ff = -1;
}
std::cout << "--" << std::endl;
filebin.close();
while (mt->isBusy()) {
;
}
if (nframes >= 0) {
if (nframes > 0) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat, 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::endl;
mt->writeImage(imgfname, 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;
std::cout << "DATA ";
// sprintf(fn,fformat,irun);
sprintf(ffname, "%s/%s.%s", indir, fformat, fext);
sprintf(fname, (const char *)ffname, irun);
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
sprintf(imgfname, (const char *)ffname, irun);
sprintf(ffname, "%s/%s.clust", outdir, fformat);
sprintf(cfname, (const char *)ffname, irun);
std::cout << fname << " ";
std::cout << imgfname << std::endl;
std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl;
// cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
ifile = 0;
if (filebin.is_open()) {
if (thr <= 0 && cf != 0) { // cluster finder
if (of == NULL) {
of = fopen(cfname, "w");
if (of) {
mt->setFilePointer(of);
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); // << 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) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat,
ifile);
sprintf(imgfname, (const char *)ffname, irun);
mt->writeImage(imgfname, thr1);
mt->clearImage();
ifile++;
}
}
// } else
// cout << ifr << " " << ff << " " << np << endl;
ff = -1;
}
std::cout << "--" << std::endl;
filebin.close();
while (mt->isBusy()) {
;
}
if (nframes >= 0) {
if (nframes > 0) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat, 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::endl;
mt->writeImage(imgfname, 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) {
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
strcpy(imgfname, ffname);
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
mt->writeImage(imgfname, thr1);
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
strcpy(imgfname, ffname);
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
mt->writeImage(imgfname, thr1);
}
return 0;
}