Read rx_ROI from json master

This commit is contained in:
hinger_v 2023-08-03 18:25:43 +02:00
parent 558c2de85c
commit f90a9b7520
5 changed files with 367 additions and 143 deletions

View File

@ -28,6 +28,10 @@
@li version is the version number of this structure format @li version is the version number of this structure format
*/ */
#include <algorithm>
#include <numeric>
#include <tuple>
namespace strixelSingleChip { namespace strixelSingleChip {
constexpr int nc_rawimg = 1024; // for full images //256; constexpr int nc_rawimg = 1024; // for full images //256;
constexpr int nr_rawimg = 512; constexpr int nr_rawimg = 512;
@ -97,6 +101,13 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
int chip_x0; int chip_x0;
int chip_y0; int chip_y0;
int x0, y0, x1, y1, shifty; int x0, y0, x1, y1, shifty;
struct {
uint16_t xmin;
uint16_t xmax;
uint16_t ymin;
uint16_t ymax;
int nc;
} globalROI;
int getMultiplicator(const int group) { int getMultiplicator(const int group) {
int multiplicator; int multiplicator;
@ -215,9 +226,113 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
} }
} }
void remapROI(uint16_t xmin, uint16_t xmax, uint16_t ymin, uint16_t ymax) {
std::tuple< uint16_t, uint16_t, uint16_t, uint16_t > adjustROItoLimits(uint16_t xmin,
uint16_t xmax,
uint16_t ymin,
uint16_t ymax,
uint16_t lim_roi_xmin,
uint16_t lim_roi_xmax,
uint16_t lim_roi_ymin,
uint16_t lim_roi_ymax) {
uint16_t xmin_roi, xmax_roi, ymin_roi, ymax_roi;
if ( xmin < lim_roi_xmin)
xmin_roi = lim_roi_xmin;
else
xmin_roi = xmin;
if ( xmax > lim_roi_xmax )
xmax_roi = lim_roi_xmax;
else
xmax_roi = xmax;
if ( ymin < lim_roi_ymin )
ymin_roi = lim_roi_ymin;
else
ymin_roi = ymin;
if ( ymax > lim_roi_ymax )
ymax_roi = lim_roi_ymax;
else
ymax_roi = ymax;
return std::make_tuple(xmin_roi, xmax_roi, ymin_roi, ymax_roi);
}
std::vector < std::tuple< int, int, uint16_t, uint16_t, uint16_t, uint16_t > > mapSubROIs(uint16_t xmin,
uint16_t xmax,
uint16_t ymin,
uint16_t ymax) {
bool chip_1_1 = false;
bool chip_1_2 = false;
bool chip_1_3 = false;
bool chip_6_1 = false;
bool chip_6_2 = false;
bool chip_6_3 = false;
for ( int x=xmin; x!=xmax+1; ++x ) {
for ( int y=ymin; y!=ymax; ++y ) {
if ( c1g1_xstart<=x && x<=c1_xend && (c1g1_ystart+bond_shift_y)<=y && y<=(c1g1_yend+bond_shift_y) )
chip_1_1 = true;
if ( c1g2_xstart<=x && x<=c1_xend && (c1g2_ystart+bond_shift_y)<=y && y<=(c1g2_yend+bond_shift_y) )
chip_1_2 = true;
if ( c1g3_xstart<=x && x<=c1_xend && (c1g3_ystart+bond_shift_y)<=y && y<=(c1g3_yend+bond_shift_y) )
chip_1_3 = true;
if ( c6_xstart<=x && x<=c6g1_xend && (c6g1_ystart-bond_shift_y)<=y && y<=(c6g1_yend-bond_shift_y) )
chip_6_1 = true;
if ( c6_xstart<=x && x<=c6g2_xend && (c6g2_ystart-bond_shift_y)<=y && y<=(c6g2_yend-bond_shift_y) )
chip_6_2 = true;
if ( c6_xstart<=x && x<=c6g3_xend && (c6g3_ystart-bond_shift_y)<=y && y<=(c6g3_yend-bond_shift_y) )
chip_6_3 = true;
}
}
uint16_t xmin_roi{}, xmax_roi{}, ymin_roi{}, ymax_roi{};
//[ chip, group, xmin, xmax, ymin, ymax ]
std::vector < std::tuple< int, int, uint16_t, uint16_t, uint16_t, uint16_t > > rois{};
if (chip_1_1) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c1g1_xstart, c1_xend, 0, c1g1_yend+bond_shift_y );
rois.push_back( std::make_tuple( 1, 1, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
if (chip_1_2) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c1g2_xstart, c1_xend, c1g2_ystart+bond_shift_y, c1g2_yend+bond_shift_y );
rois.push_back( std::make_tuple( 1, 2, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
if (chip_1_3) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c1g3_xstart, c1_xend, c1g3_ystart+bond_shift_y, c1g3_yend+bond_shift_y );
rois.push_back( std::make_tuple( 1, 3, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
if (chip_6_3) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c6_xstart, c6g3_xend, c6g3_ystart-bond_shift_y, c6g3_yend-bond_shift_y );
rois.push_back( std::make_tuple( 6, 3, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
if (chip_6_2) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c6_xstart, c6g2_xend, c6g2_ystart-bond_shift_y, c6g2_yend-bond_shift_y );
rois.push_back( std::make_tuple( 6, 2, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
if (chip_6_1) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c6_xstart, c6g1_xend, c6g1_ystart-bond_shift_y, 511 );
rois.push_back( std::make_tuple( 6, 1, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
return rois;
}
void remapROI(std::tuple< int, int, uint16_t, uint16_t, uint16_t, uint16_t > roi) {
// determine group and chip selected by ROI // determine group and chip selected by ROI
int group; int group, xmin, xmax, ymin, ymax;
std::tie( mchip, group, xmin, xmax, ymin, ymax ) = roi;
/*
if (ymax <= c1g1_yend + bond_shift_y) { if (ymax <= c1g1_yend + bond_shift_y) {
group = 1; group = 1;
mchip = 1; mchip = 1;
@ -243,18 +358,17 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
group = -1; group = -1;
mchip = -1; mchip = -1;
} }
*/
int multiplicator = getMultiplicator(group); int multiplicator = getMultiplicator(group);
setMappingShifts(group); setMappingShifts(group);
std::cout << "chip: " << mchip << ", group: " << group << ", m: " << multiplicator std::cout << "remapping chip: " << mchip << ", group: " << group << ", m: " << multiplicator
<< ", x0: " << x0 << ", x1: " << x1 << ", y0: " << y0 << ", x0: " << x0 << ", x1: " << x1 << ", y0: " << y0
<< ", y1: " << y1 << std::endl; << ", y1: " << y1 << std::endl;
std::cout << "Adjusted roi: [" << xmin << ", " << xmax << ", " << ymin << ", " << ymax << "]" << std::endl;
// get ROI raw image number of columns
int nc_roi = xmax - xmin + 1;
std::cout << "nc_roi = " << nc_roi << std::endl;
// make sure loop bounds are correct // make sure loop bounds are correct
/*
if (y0 < ymin) if (y0 < ymin)
std::cout << "Error ymin" << std::endl; std::cout << "Error ymin" << std::endl;
if (y1 > ymax) if (y1 > ymax)
@ -264,6 +378,7 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
std::cout << "Error xmin" << std::endl; std::cout << "Error xmin" << std::endl;
if (x1 > xmax) if (x1 > xmax)
std::cout << "Error xmax" << std::endl; std::cout << "Error xmax" << std::endl;
*/
// remapping loop // remapping loop
int ix, iy = 0; int ix, iy = 0;
@ -277,8 +392,10 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
} }
// if (iy< 40) cout << iy << " " << ix <<endl; // if (iy< 40) cout << iy << " " << ix <<endl;
dataMap[iy][ix] = if ( ipx>=xmin && ipx<=xmax && ipy>=ymin && ipy <=ymax )
sizeof(header) + (nc_roi * (ipy - ymin) + (ipx - xmin)) * 2; dataMap[iy][ix] =
sizeof(header) + (globalROI.nc * (ipy - globalROI.ymin) + (ipx - globalROI.xmin)) * 2;
else dataMap[iy][ix] = sizeof(header);
groupmap[iy][ix] = group - 1; groupmap[iy][ix] = group - 1;
} }
} }
@ -307,16 +424,31 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
} }
} }
globalROI.xmin = xmin;
globalROI.xmax = xmax;
globalROI.ymin = ymin;
globalROI.ymax = ymax;
std::cout << "sizeofheader = " << sizeof(header) << std::endl; std::cout << "sizeofheader = " << sizeof(header) << std::endl;
std::cout << "Jungfrau strixels 2X single chip with full module data " std::cout << "Jungfrau strixels 2X single chip with full module data "
<< std::endl; << std::endl;
if (xmin < xmax && ymin < ymax) { if (xmin < xmax && ymin < ymax) {
dataSize = // get ROI raw image number of columns
(xmax - xmin + 1) * (ymax - ymin + 1) * 2 + sizeof(header); globalROI.nc = xmax - xmin + 1;
std::cout << "datasize " << dataSize << std::endl; std::cout << "nc_roi = " << globalROI.nc << std::endl;
remapROI(xmin, xmax, ymin, ymax);
dataSize =
(xmax - xmin + 1) * (ymax - ymin + 1) * 2 + sizeof(header);
std::cout << "datasize " << dataSize << std::endl;
//[ chip, group, xmin, xmax, ymin, ymax ]
auto rois = mapSubROIs(xmin, xmax, ymin, ymax);
//function to fill vector of rois from globalROI
for ( auto roi : rois )
remapROI(roi);
} else { } else {

View File

@ -50,12 +50,33 @@ class jungfrauModuleData : public slsDetectorData<uint16_t> {
#endif #endif
jungfrauModuleData() jungfrauModuleData(uint16_t xmin=0, uint16_t xmax=0,
uint16_t ymin=0, uint16_t ymax=0)
: slsDetectorData<uint16_t>(1024, 512, : slsDetectorData<uint16_t>(1024, 512,
1024* 512 * 2 + off) { 1024* 512 * 2 + off) {
for (int ix = 0; ix < 1024; ix++) { if (xmin < xmax && ymin < ymax) {
for (int iy = 0; iy < 512; iy++) {
int nc_roi = xmax - xmin + 1;
std::cout << "nc_roi = " << nc_roi << std::endl;
dataSize =
(xmax - xmin + 1) * (ymax - ymin + 1) * 2 + off;
std::cout << "datasize " << dataSize << std::endl;
for (int ix = xmin; ix < xmax+1; ++ix) {
for (int iy = ymin; iy < ymax+1; ++iy) {
dataMap[iy][ix] = off + (nc_roi * iy + ix) * 2;
#ifdef HIGHZ
dataMask[iy][ix] = 0x3fff;
#endif
}
}
} else {
for (int ix = 0; ix < 1024; ++ix) {
for (int iy = 0; iy < 512; ++iy) {
dataMap[iy][ix] = off + (1024 * iy + ix) * 2; dataMap[iy][ix] = off + (1024 * iy + ix) * 2;
#ifdef HIGHZ #ifdef HIGHZ
dataMask[iy][ix] = 0x3fff; dataMask[iy][ix] = 0x3fff;
@ -63,7 +84,7 @@ class jungfrauModuleData : public slsDetectorData<uint16_t> {
} }
} }
}
iframe = 0; iframe = 0;

View File

@ -7,6 +7,7 @@
set(JUNGFRAU_EXECUTABLES) set(JUNGFRAU_EXECUTABLES)
find_package(fmt REQUIRED) find_package(fmt REQUIRED)
find_package(nlohmann_json 3.11.2 REQUIRED)
# jungfrauRawDataProcess # jungfrauRawDataProcess
add_executable(jungfrauRawDataProcess jungfrauRawDataProcess.cpp) add_executable(jungfrauRawDataProcess jungfrauRawDataProcess.cpp)
@ -14,7 +15,7 @@ target_compile_definitions(jungfrauRawDataProcess PRIVATE MODULE)
list(APPEND JUNGFRAU_EXECUTABLES jungfrauRawDataProcess) list(APPEND JUNGFRAU_EXECUTABLES jungfrauRawDataProcess)
# jungfrauRawDataProcessStrx # jungfrauRawDataProcessStrx
add_executable(jungfrauRawDataProcessStrx jungfrauRawDataProcess_filetxt.cpp) add_executable(jungfrauRawDataProcessStrx jungfrauRawDataProcess.cpp)
target_compile_definitions(jungfrauRawDataProcessStrx PRIVATE JFSTRX) target_compile_definitions(jungfrauRawDataProcessStrx PRIVATE JFSTRX)
list(APPEND JUNGFRAU_EXECUTABLES jungfrauRawDataProcessStrx) list(APPEND JUNGFRAU_EXECUTABLES jungfrauRawDataProcessStrx)
@ -79,6 +80,7 @@ foreach(exe ${JUNGFRAU_EXECUTABLES})
pthread pthread
tiffio tiffio
fmt::fmt fmt::fmt
nlohmann_json::nlohmann_json
#-L/usr/lib64/ #-L/usr/lib64/
#-lm -lstdc++ -lrt #-lm -lstdc++ -lrt

View File

@ -41,6 +41,9 @@
#include <ctime> #include <ctime>
#include <fmt/core.h> #include <fmt/core.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
std::string getRootString( const std::string& filepath ) { std::string getRootString( const std::string& filepath ) {
size_t pos1 = filepath.find_last_of("/"); size_t pos1 = filepath.find_last_of("/");
@ -61,20 +64,24 @@ std::string getRootString( const std::string& filepath ) {
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 ) { 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) if (outfilecounter >= 0)
return fmt::format("{:s}/{:s}_d{:d}_f{:d}_{:d}_f{:05d}.{:s}", dir, fprefix, mindex, findex, aindex, outfilecounter, fext); 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) else if (fsuffix.length()!=0) {
return fmt::format("{:s}/{:s}_{:s}.{:s}", dir, fprefix, fsuffix, fext); if (fsuffix == "master")
return fmt::format("{:s}/{:s}_master_{:d}.{:s}", dir, fprefix, aindex, fext);
else
return fmt::format("{:s}/{:s}_{:s}.{:s}", dir, fprefix, fsuffix, fext);
}
else else
return fmt::format("{:s}/{:s}_d{:d}_f{:d}_{:d}.{:s}", dir, fprefix, mindex, findex, aindex, fext); 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 < 6) {
std::cout std::cout
<< "Usage is " << argv[0] << "Usage is " << argv[0]
<< "indir outdir fprefix(excluding slsDetector standard suffixes and extension) fextension " << "indir outdir [fprefix(excluding slsDetector standard suffixes and extension)] [fextension] "
"[runmin] [runmax] [pedfile (raw or tiff)] [threshold] " "[fmin] [fmax] [runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
"[nframes] [xmin xmax ymin ymax] [gainmap]" "[nframes] [xmin xmax ymin ymax] [optional: bool read rxroi from data file header] [gainmap]"
<< std::endl; << std::endl;
std::cout std::cout
<< "threshold <0 means analog; threshold=0 means cluster finder; " << "threshold <0 means analog; threshold=0 means cluster finder; "
@ -106,36 +113,71 @@ int main(int argc, char *argv[]) {
std::string outdir(argv[2]); std::string outdir(argv[2]);
std::string fprefix(argv[3]); std::string fprefix(argv[3]);
std::string fext(argv[4]); std::string fext(argv[4]);
int fmin = 0;
if (argc >= 6)
fmin = atoi(argv[5]);
int fmax = fmin;
if (argc >= 7)
fmax = atoi(argv[6]);
int runmin = 0; int runmin = 0;
// cout << "argc is " << argc << endl; // cout << "argc is " << argc << endl;
if (argc >= 6) { if (argc >= 8) {
runmin = atoi(argv[5]); runmin = atoi(argv[7]);
} }
int runmax = runmin; int runmax = runmin;
if (argc >= 9) {
if (argc >= 7) { runmax = atoi(argv[8]);
runmax = atoi(argv[6]);
} }
std::string pedfilename{}; std::string pedfilename{};
if (argc >= 8) { if (argc >= 10) {
pedfilename = argv[7]; pedfilename = argv[9];
} }
double thr = 0; double thr = 0;
double thr1 = 1; double thr1 = 1;
if (argc >= 9) { if (argc >= 11) {
thr = atof(argv[8]); thr = atof(argv[10]);
} }
int nframes = 0; int nframes = 0;
if (argc >= 10) { if (argc >= 12) {
nframes = atoi(argv[9]); nframes = atoi(argv[11]);
} }
bool readrxroifromdatafile = false;
if (argc >= 17)
readrxroifromdatafile = atoi(argv[16]);
// Receiver ROI
uint16_t rxroi_xmin = 0;
uint16_t rxroi_xmax = 0;
uint16_t rxroi_ymin = 0;
uint16_t rxroi_ymax = 0;
{ //protective scope so ifstream gets destroyed properly
auto jsonmastername = createFileName( indir, fprefix, "master", "json", runmin );
std::cout << "json master file " << jsonmastername << std::endl;
std::ifstream masterfile(jsonmastername); //, ios::in | ios::binary);
if (masterfile.is_open()) {
json j;
masterfile >> j;
rxroi_xmin = j["Receiver Roi"]["xmin"];
rxroi_xmax = j["Receiver Roi"]["xmax"];
rxroi_ymin = j["Receiver Roi"]["ymin"];
rxroi_ymax = j["Receiver Roi"]["ymax"];
masterfile.close();
std::cout << "Read Receiver ROI [" << rxroi_xmin << ", " << rxroi_xmax << ", "
<< rxroi_ymin << ", " << rxroi_ymax << "] from json master file" << std::endl;
} else
std::cout << "Could not open master file " << jsonmastername << std::endl;
}
// Define decoders... // Define decoders...
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \ #if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
!defined JFSTRXCHIP6 !defined JFSTRXCHIP6
@ -151,49 +193,45 @@ int main(int argc, char *argv[]) {
#ifdef JFSTRX #ifdef JFSTRX
cout << "Jungfrau strixel full module readout" << endl; 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 #ifndef ALDO
{ //THIS SCOPE IS IMPORTANT! (To ensure proper destruction of ifstream) if (readrxroifromdatafile)
using header = sls::defs::sls_receiver_header; { //THIS SCOPE IS IMPORTANT! (To ensure proper destruction of ifstream)
// check if there is a roi in the header using header = sls::defs::sls_receiver_header;
typedef struct { // check if there is a roi in the header
uint16_t xmin; typedef struct {
uint16_t xmax; uint16_t xmin;
uint16_t ymin; uint16_t xmax;
uint16_t ymax; uint16_t ymin;
} receiverRoi_compact; uint16_t ymax;
receiverRoi_compact croi; } receiverRoi_compact;
std::string fsuffix{}; receiverRoi_compact croi;
auto filename = createFileName( indir, fprefix, fsuffix, fext, runmin ); std::string fsuffix{};
std::cout << "Reading header of file " << filename << " to check for ROI " auto filename = createFileName( indir, fprefix, fsuffix, fext, runmin );
<< std::endl; std::cout << "Reading header of file " << filename << " to check for ROI "
ifstream firstfile(filename, ios::in | ios::binary); << std::endl;
if (firstfile.is_open()) { ifstream firstfile(filename, ios::in | ios::binary);
header hbuffer; if (firstfile.is_open()) {
std::cout << "sizeof(header) = " << sizeof(header) << std::endl; header hbuffer;
if (firstfile.read((char *)&hbuffer, sizeof(header))) { std::cout << "sizeof(header) = " << sizeof(header) << std::endl;
memcpy(&croi, &hbuffer.detHeader.detSpec1, 8); if (firstfile.read((char *)&hbuffer, sizeof(header))) {
std::cout << "Read ROI [" << croi.xmin << ", " << croi.xmax << ", " memcpy(&croi, &hbuffer.detHeader.detSpec1, 8);
<< croi.ymin << ", " << croi.ymax << "]" << std::endl; std::cout << "Read ROI [" << croi.xmin << ", " << croi.xmax << ", "
xxmin = croi.xmin; << croi.ymin << ", " << croi.ymax << "]" << std::endl;
xxmax = croi.xmax; rxroi_xmin = croi.xmin;
yymin = croi.ymin; rxroi_xmax = croi.xmax;
yymax = croi.ymax; rxroi_ymin = croi.ymin;
} else rxroi_ymax = croi.ymax;
std::cout << "reading error" << std::endl; } else
firstfile.close(); std::cout << "reading error" << std::endl;
} else firstfile.close();
std::cout << "Could not open " << filename << " for reading " << std::endl; } else
} //end of protective scope std::cout << "Could not open " << filename << " for reading " << std::endl;
} //end of protective scope
#endif #endif
jungfrauLGADStrixelsData *decoder = jungfrauLGADStrixelsData *decoder =
new jungfrauLGADStrixelsData(xxmin, xxmax, yymin, yymax); new jungfrauLGADStrixelsData(rxroi_xmin, rxroi_xmax, rxroi_ymin, rxroi_ymax);
int nx = 1024 / 3, ny = 512 * 5; int nx = 1024 / 3, ny = 512 * 5;
#endif #endif
#ifdef JFSTRXCHIP1 #ifdef JFSTRXCHIP1
@ -218,19 +256,20 @@ int main(int argc, char *argv[]) {
decoder->getDetectorSize(nx, ny); decoder->getDetectorSize(nx, ny);
std::cout << "Detector size is " << nx << " " << ny << std::endl; std::cout << "Detector size is " << nx << " " << ny << std::endl;
//Cluster finder ROI
int xmin = 0, xmax = nx, ymin = 0, ymax = ny; int xmin = 0, xmax = nx, ymin = 0, ymax = ny;
if (argc >= 14) { if (argc >= 16) {
xmin = atoi(argv[10]); xmin = atoi(argv[12]);
xmax = atoi(argv[11]); xmax = atoi(argv[13]);
ymin = atoi(argv[12]); ymin = atoi(argv[14]);
ymax = atoi(argv[13]); ymax = atoi(argv[15]);
} }
std::cout << xmin << " " << xmax << " " << ymin << " " << ymax << " " std::cout << "Cluster finder ROI: [" << xmin << ", " << xmax << ", " << ymin << ", " << ymax << "]"
<< std::endl; << std::endl;
char *gainfname = NULL; char *gainfname = NULL;
if (argc > 14) { if (argc > 17) {
gainfname = argv[14]; gainfname = argv[17];
std::cout << "Gain map file name is: " << gainfname << std::endl; std::cout << "Gain map file name is: " << gainfname << std::endl;
} }
@ -239,6 +278,8 @@ int main(int argc, char *argv[]) {
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 prefix is " << fprefix << std::endl; std::cout << "input file prefix is " << fprefix << std::endl;
std::cout << "fmin is " << fmin << std::endl;
std::cout << "fmax is " << fmax << 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 (pedfilename.length()!=0) if (pedfilename.length()!=0)
@ -380,26 +421,27 @@ int main(int argc, char *argv[]) {
} }
ifr = 0; ifr = 0;
int ifile = 0; int ioutfile = 0;
mt->setFrameMode(eFrame); mt->setFrameMode(eFrame);
FILE *of = NULL; FILE *of = NULL;
for (int irun = runmin; irun <= runmax; irun++) { for (int irun = runmin; irun <= runmax; ++irun) {
for (int ifile = fmin; ifile <= fmax; ++ifile) {
std::cout << "DATA "; std::cout << "DATA ";
std::string fsuffix{}; std::string fsuffix{};
auto fname = createFileName( indir, fprefix, fsuffix, fext, irun ); auto fname = createFileName( indir, fprefix, fsuffix, fext, irun, 0, ifile );
auto imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun ); auto imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, ifile );
auto cfname = createFileName( outdir, fprefix, fsuffix, "clust", irun ); auto cfname = createFileName( outdir, fprefix, fsuffix, "clust", irun, 0, ifile );
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;
// std::cout << fname << " " << outfname << " " << imgfname << std::endl; // std::cout << fname << " " << outfname << " " << imgfname << std::endl;
ifstream filebin(fname, ios::in | ios::binary); std::ifstream filebin(fname, ios::in | ios::binary);
// //open file // //open file
ifile = 0; ioutfile = 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) {
@ -436,10 +478,10 @@ 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) {
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, 0, ifile ); imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, 0, ioutfile );
mt->writeImage(imgfname.c_str(), thr1); mt->writeImage(imgfname.c_str(), thr1);
mt->clearImage(); mt->clearImage();
ifile++; ioutfile++;
} }
} }
// } else // } else
@ -453,7 +495,7 @@ int main(int argc, char *argv[]) {
} }
if (nframes >= 0) { if (nframes >= 0) {
if (nframes > 0) if (nframes > 0)
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, 0, ifile ); imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, 0, ioutfile );
std::cout << "Writing tiff to " << imgfname << " " << thr1 std::cout << "Writing tiff to " << imgfname << " " << thr1
<< std::endl; << std::endl;
mt->writeImage(imgfname.c_str(), thr1); mt->writeImage(imgfname.c_str(), thr1);
@ -469,9 +511,10 @@ int main(int argc, char *argv[]) {
} else } else
std::cout << "Could not open " << fname << " for reading " std::cout << "Could not open " << fname << " for reading "
<< std::endl; << std::endl;
}
} }
if (nframes < 0) { if (nframes < 0) {
auto imgfname = createFileName( outdir, fprefix, "sum", "tiff", -1, 0, 0, -1 ); auto imgfname = createFileName( outdir, fprefix, "sum", "tiff", runmin, 0, fmin, -1 );
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl; std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
mt->writeImage(imgfname.c_str(), thr1); mt->writeImage(imgfname.c_str(), thr1);
} }

View File

@ -41,6 +41,9 @@
#include <ctime> #include <ctime>
#include <fmt/core.h> #include <fmt/core.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
std::string getRootString( const std::string& filepath ) { std::string getRootString( const std::string& filepath ) {
size_t pos1; size_t pos1;
@ -71,11 +74,11 @@ std::string createFileName( const std::string& dir, const std::string& fprefix="
//NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS! //NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS!
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (argc < 10) { if (argc < 11) {
std::cout std::cout
<< "Usage is " << argv[0] << "Usage is " << argv[0]
<< " filestxt outdir [pedfile (raw or tiff)] [xmin xmax ymin ymax] " << " filestxt outdir [json master] [pedfile (raw or tiff)] [xmin xmax ymin ymax] "
"[threshold] [nframes] " "[threshold] [nframes] [optional: bool read rxroi from data file header]"
"NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS! " "NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS! "
<< std::endl; << std::endl;
std::cout std::cout
@ -105,19 +108,24 @@ int main(int argc, char *argv[]) {
const std::string txtfilename(argv[1]); const std::string txtfilename(argv[1]);
const std::string outdir(argv[2]); const std::string outdir(argv[2]);
const std::string pedfilename(argv[3]); const std::string jsonmastername(argv[3]);
const std::string pedfilename(argv[4]);
int xmin = atoi(argv[4]); int xmin = atoi(argv[5]);
int xmax = atoi(argv[5]); int xmax = atoi(argv[6]);
int ymin = atoi(argv[6]); int ymin = atoi(argv[7]);
int ymax = atoi(argv[7]); int ymax = atoi(argv[8]);
double thr = 0; double thr = 0;
double thr1 = 1; double thr1 = 1;
thr = atof(argv[8]); thr = atof(argv[9]);
int nframes = 0; int nframes = 0;
nframes = atoi(argv[9]); nframes = atoi(argv[10]);
bool readrxroifromdatafile = false;
if (argc > 11)
readrxroifromdatafile = atoi(argv[11]);
//Get vector of filenames from input txt-file //Get vector of filenames from input txt-file
std::vector<std::string> filenames{}; std::vector<std::string> filenames{};
@ -146,7 +154,29 @@ int main(int argc, char *argv[]) {
} }
std::cout << "###############" << std::endl; std::cout << "###############" << std::endl;
// Receiver ROI
uint16_t rxroi_xmin = 0;
uint16_t rxroi_xmax = 0;
uint16_t rxroi_ymin = 0;
uint16_t rxroi_ymax = 0;
{ //protective scope so ifstream gets destroyed properly
std::ifstream masterfile(jsonmastername); //, ios::in | ios::binary);
if (masterfile.is_open()) {
json j;
masterfile >> j;
rxroi_xmin = j["Receiver Roi"]["xmin"];
rxroi_xmax = j["Receiver Roi"]["xmax"];
rxroi_ymin = j["Receiver Roi"]["ymin"];
rxroi_ymax = j["Receiver Roi"]["ymax"];
masterfile.close();
} else
std::cout << "Could not open master file " << jsonmastername << std::endl;
}
// Define decoders... // Define decoders...
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \ #if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
!defined JFSTRXCHIP6 !defined JFSTRXCHIP6
@ -162,48 +192,44 @@ int main(int argc, char *argv[]) {
#ifdef JFSTRX #ifdef JFSTRX
cout << "Jungfrau strixel full module readout" << endl; 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 #ifndef ALDO
{ //THIS SCOPE IS IMPORTANT! (To ensure proper destruction of ifstream) if (readrxroifromdatafile)
using header = sls::defs::sls_receiver_header; { //THIS SCOPE IS IMPORTANT! (To ensure proper destruction of ifstream)
// check if there is a roi in the header using header = sls::defs::sls_receiver_header;
typedef struct { // check if there is a roi in the header
uint16_t xmin; typedef struct {
uint16_t xmax; uint16_t xmin;
uint16_t ymin; uint16_t xmax;
uint16_t ymax; uint16_t ymin;
} receiverRoi_compact; uint16_t ymax;
receiverRoi_compact croi; } receiverRoi_compact;
//std::string filepath(argv[9]); //This is a problem if the input files have different ROIs! receiverRoi_compact croi;
std::cout << "Reading header of file " << filenames[0] << " to check for ROI " //std::string filepath(argv[9]); //This is a problem if the input files have different ROIs!
<< std::endl; std::cout << "Reading header of file " << filenames[0] << " to check for ROI "
ifstream firstfile(filenames[0], ios::in | ios::binary); << std::endl;
if (firstfile.is_open()) { std::ifstream firstfile( filenames[0], ios::in | ios::binary);
header hbuffer; if (firstfile.is_open()) {
std::cout << "sizeof(header) = " << sizeof(header) << std::endl; header hbuffer;
if (firstfile.read((char *)&hbuffer, sizeof(header))) { std::cout << "sizeof(header) = " << sizeof(header) << std::endl;
memcpy(&croi, &hbuffer.detHeader.detSpec1, 8); if (firstfile.read((char *)&hbuffer, sizeof(header))) {
std::cout << "Read ROI [" << croi.xmin << ", " << croi.xmax << ", " memcpy(&croi, &hbuffer.detHeader.detSpec1, 8);
<< croi.ymin << ", " << croi.ymax << "]" << std::endl; std::cout << "Read ROI [" << croi.xmin << ", " << croi.xmax << ", "
xxmin = croi.xmin; << croi.ymin << ", " << croi.ymax << "]" << std::endl;
xxmax = croi.xmax; rxroi_xmin = croi.xmin;
yymin = croi.ymin; rxroi_xmax = croi.xmax;
yymax = croi.ymax; rxroi_ymin = croi.ymin;
} else rxroi_ymax = croi.ymax;
std::cout << "reading error" << std::endl; } else
firstfile.close(); std::cout << "reading error" << std::endl;
} else firstfile.close();
std::cout << "Could not open " << filenames[0] << " for reading " << std::endl; } else
} //end of protective scope std::cout << "Could not open " << filenames[0] << " for reading " << std::endl;
} //end of protective scope
#endif #endif
jungfrauLGADStrixelsData *decoder = jungfrauLGADStrixelsData *decoder =
new jungfrauLGADStrixelsData(xxmin, xxmax, yymin, yymax); new jungfrauLGADStrixelsData(rxroi_xmin, rxroi_xmax, rxroi_ymin, rxroi_ymax);
int nx = 1024 / 3, ny = 512 * 5; int nx = 1024 / 3, ny = 512 * 5;
#endif #endif
#ifdef JFSTRXCHIP1 #ifdef JFSTRXCHIP1