program runs (fixed detector size in jungfrauLGADStrixelsDataQuadH5.h)

This commit is contained in:
hinger_v 2024-09-05 17:03:31 +02:00
parent 16bfcc17ce
commit 7b4740ced2
2 changed files with 196 additions and 186 deletions

View File

@ -105,7 +105,7 @@ class jungfrauLGADStrixelsDataQuadH5 : public slsDetectorData<uint16_t> {
std::reverse( v.begin(), v.end() ); std::reverse( v.begin(), v.end() );
std::cout << "mods reversed "; std::cout << "mods reversed ";
for ( auto i : v ) for ( auto i : v )
std::cout << i << " "; std::cout << i << " ";
std::cout << '\n'; std::cout << '\n';
} }
@ -115,21 +115,21 @@ class jungfrauLGADStrixelsDataQuadH5 : public slsDetectorData<uint16_t> {
x1 = xend; x1 = xend;
if (rot==NORMAL) { if (rot==NORMAL) {
x0 += shift; x0 += shift;
} else { } else {
x1-=shift; x1-=shift;
reverseVector(mods); reverseVector(mods);
} }
if (half==BOTTOM) { if (half==BOTTOM) {
y0 = bottom_ystart; y0 = bottom_ystart;
y1 = bottom_yend; y1 = bottom_yend;
shifty = 0; shifty = 0;
} else { } else {
y0 = top_ystart; y0 = top_ystart;
y1 = top_yend; y1 = top_yend;
reverseVector(mods); reverseVector(mods);
shifty = nr_strixel + nr_center; //double-sided pixels in the center have to be jumped shifty = nr_strixel + nr_center; //double-sided pixels in the center have to be jumped
} }
} }
@ -138,23 +138,23 @@ class jungfrauLGADStrixelsDataQuadH5 : public slsDetectorData<uint16_t> {
int ix, iy = 0; int ix, iy = 0;
// remapping loop // remapping loop
for (int ipy = y0; ipy <= y1; ipy++) { for (int ipy = y0; ipy <= y1; ++ipy) {
for (int ipx = x0; ipx <= x1; ipx++) { for (int ipx = x0; ipx <= x1; ++ipx) {
ix = int((ipx - x0) / multiplicator); ix = int((ipx - x0) / multiplicator);
for (int m = 0; m < multiplicator; ++m) { for (int m = 0; m < multiplicator; ++m) {
if ((ipx - x0) % multiplicator == m) if ((ipx - x0) % multiplicator == m)
iy = (ipy - y0) * multiplicator + mods[m] + shifty; iy = (ipy - y0) * multiplicator + mods[m] + shifty;
} }
// if (iy< 40) cout << iy << " " << ix <<endl; // if (iy< 40) cout << iy << " " << ix <<endl;
if (xmin < xmax && ymin < ymax) { if (xmin < xmax && ymin < ymax) {
if ( ipx>=xmin && ipx<=xmax && ipy>=ymin && ipy <=ymax ) if ( ipx>=xmin && ipx<=xmax && ipy>=ymin && ipy <=ymax )
dataMap[iy][ix] = dataMap[iy][ix] =
(globalROI.nc * (ipy - globalROI.ymin) + (ipx - globalROI.xmin)) * 2; (globalROI.nc * (ipy - globalROI.ymin) + (ipx - globalROI.xmin)) * 2;
} else { } else {
dataMap[iy][ix] = (nc_rawimg * ipy + ipx) * 2; dataMap[iy][ix] = (nc_rawimg * ipy + ipx) * 2;
} }
} }
} }
@ -162,10 +162,10 @@ class jungfrauLGADStrixelsDataQuadH5 : public slsDetectorData<uint16_t> {
void remapQuad(const int rot) { void remapQuad(const int rot) {
setMappingShifts( rot, BOTTOM ); setMappingShifts( rot, BOTTOM );
remap(); remap();
setMappingShifts( rot, TOP ); setMappingShifts( rot, TOP );
remap(); remap();
} }
@ -264,16 +264,21 @@ class jungfrauLGADStrixelsDataQuadH5 : public slsDetectorData<uint16_t> {
jungfrauLGADStrixelsDataQuadH5(uint16_t xmin = 0, uint16_t xmax = 0, jungfrauLGADStrixelsDataQuadH5(uint16_t xmin = 0, uint16_t xmax = 0,
uint16_t ymin = 0, uint16_t ymax = 0) uint16_t ymin = 0, uint16_t ymax = 0)
: slsDetectorData<uint16_t>( : slsDetectorData<uint16_t>(
nc_strixel, //nc_strixel,
nr_strixel * 2 + nr_center, //nr_strixel * 2 + nr_center,
nc_strixel * ( nr_strixel * 2 + nr_center ) * 2 ) { //nc_strixel * ( nr_strixel * 2 + nr_center ) * 2
512/2,
1024*2,
512 * 1024 * 2 ) {
std::cout << "Jungfrau strixels quad with full module data " std::cout << "Jungfrau strixels quad with full module data "
<< std::endl; << std::endl;
// Fill all strixels with dummy values // Fill all strixels with dummy values
for (int ix = 0; ix != nc_strixel; ++ix) { //for (int ix = 0; ix != nc_strixel; ++ix) {
for (int iy = 0; iy != nr_strixel * 2 + nr_center; ++iy) { // for (int iy = 0; iy != nr_strixel * 2 + nr_center; ++iy) {
dataMap[iy][ix] = sizeof(header); //mayb another value is safer for (int ix = 0; ix != 512/2; ++ix) {
for (int iy = 0; iy != 1024*2; ++iy) {
dataMap[iy][ix] = sizeof(header); //maybe another value is safer
} }
} }

View File

@ -109,23 +109,25 @@ int main(int argc, char *argv[]) {
{ //Safety scope for ifstream { //Safety scope for ifstream
ifstream inputs( txtfilename, std::ios::in ); ifstream inputs( txtfilename, std::ios::in );
if (inputs.is_open()) { if (inputs.is_open()) {
std::cout << "Reading imput filenames from txt-file ..." << std::endl; std::cout << "Reading imput filenames from txt-file ..." << std::endl;
std::string line{}; std::string line{};
while (!inputs.eof()) { while (!inputs.eof()) {
std::getline(inputs, line); std::getline(inputs, line);
filenames.emplace_back(line); if(line.find(".h5") != std::string::npos) {
std::cout << line << " line.max_size() " << line.max_size() << " filenames.capacity() " << filenames.capacity() << '\n'; filenames.emplace_back(line);
} std::cout << line << std::endl; //" line.max_size() " << line.max_size() << " filenames.capacity() " << filenames.capacity() << '\n';
inputs.close(); }
std::cout << "---- Reached end of txt-file. ----" << std::endl; }
inputs.close();
std::cout << "---- Reached end of txt-file. ----" << std::endl;
} else } else
std::cout << "Could not open " << txtfilename << std::endl; std::cout << "Could not open " << txtfilename << std::endl;
if (filenames.size()>0) { if (filenames.size()>0) {
std::cout << filenames.size() << " filenames found in " << txtfilename << std::endl; 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; std::cout << "The files will be processed in the same order as found in the txt-file." << std::endl;
} else { } else {
std::cout << "No files found in txt-file!" << std::endl; std::cout << "No files found in txt-file!" << std::endl;
return 1; return 1;
} }
} }
@ -133,8 +135,8 @@ int main(int argc, char *argv[]) {
// Define decoder // Define decoder
std::cout << "Jungfrau strixel quad h5" << std::endl; std::cout << "Jungfrau strixel quad h5" << std::endl;
//jungfrauLGADStrixelsDataQuadH5* decoder = new jungfrauLGADStrixelsDataQuadH5(); jungfrauLGADStrixelsDataQuadH5* decoder = new jungfrauLGADStrixelsDataQuadH5();
auto decoder = std::make_unique<jungfrauLGADStrixelsDataQuadH5>(); //auto decoder = std::make_unique<jungfrauLGADStrixelsDataQuadH5>();
int nx = 1024 / 3, ny = 512 * 3; int nx = 1024 / 3, ny = 512 * 3;
//Cluster finder ROI //Cluster finder ROI
@ -162,9 +164,9 @@ int main(int argc, char *argv[]) {
uint32_t nnx, nny; uint32_t nnx, nny;
//singlePhotonDetector* filter = singlePhotonDetector* filter =
// new singlePhotonDetector(decoder.get(), 3, nsigma, 1, NULL, nped, 200, -1, -1, NULL, NULL); new singlePhotonDetector(decoder, 3, nsigma, 1, NULL, nped, 200, -1, -1, NULL, NULL);
auto filter = std::make_unique<singlePhotonDetector>(decoder.get(), 3, nsigma, 1, nullptr, nped, 200, -1, -1, nullptr, nullptr); //auto filter = std::make_unique<singlePhotonDetector>(decoder.get(), 3, nsigma, 1, nullptr, nped, 200, -1, -1, nullptr, nullptr);
thr = 0.15 * thr; thr = 0.15 * thr;
filter->newDataSet(); filter->newDataSet();
@ -184,9 +186,9 @@ int main(int argc, char *argv[]) {
char* buff; char* buff;
//multiThreadedCountingDetector* mt = multiThreadedCountingDetector* mt =
// new multiThreadedCountingDetector(filter, nthreads, fifosize); new multiThreadedCountingDetector(filter, nthreads, fifosize);
auto mt = std::make_unique<multiThreadedCountingDetector>(filter.get(), nthreads, fifosize); //auto mt = std::make_unique<multiThreadedCountingDetector>(filter.get(), nthreads, fifosize);
mt->setClusterSize(csize, csize); mt->setClusterSize(csize, csize);
#ifndef ANALOG #ifndef ANALOG
@ -219,73 +221,73 @@ int main(int argc, char *argv[]) {
std::cout << "PEDESTAL " << std::endl; std::cout << "PEDESTAL " << std::endl;
if (pedfilename.find(".tif") == std::string::npos) { //not a tiff file if (pedfilename.find(".tif") == std::string::npos) { //not a tiff file
std::string const fname(pedfilename); std::string const 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);
//HDF5File pedefile; //HDF5File pedefile;
auto pedefile = std::make_unique<HDF5File>(); auto pedefile = std::make_unique<HDF5File>();
// //open file // //open file
if ( pedefile->OpenResources(fname.c_str(),validate_rank) ) { if ( pedefile->OpenResources(fname.c_str(),validate_rank) ) {
std::cout << "bbbb " << std::ctime(&end_time) << std::endl; std::cout << "bbbb " << std::ctime(&end_time) << std::endl;
framenumber = -1; framenumber = -1;
while ( decoder->readNextFrame(*pedefile, framenumber, iframe, buff) ) { while ( decoder->readNextFrame(*pedefile, framenumber, iframe, buff) ) {
if ((ifr + 1) % 100 == 0) { if ((ifr + 1) % 100 == 0) {
std::cout std::cout
<< " ****" << " ****"
<< decoder->getValue(buff, 20, 20); // << std::endl; << decoder->getValue(buff, 20, 20); // << std::endl;
} }
mt->pushData(buff); mt->pushData(buff);
mt->nextThread(); mt->nextThread();
mt->popFree(buff); mt->popFree(buff);
++ifr; ++ifr;
if (ifr % 100 == 0) { if (ifr % 100 == 0) {
std::cout << " ****" << ifr << " " << framenumber << " " << iframe std::cout << " ****" << ifr << " " << framenumber << " " << iframe
<< std::endl; << std::endl;
} // else } // else
if (ifr >= 1000) if (ifr >= 1000)
break; break;
framenumber = -1; framenumber = -1;
} }
pedefile->CloseResources(); pedefile->CloseResources();
while (mt->isBusy()) { while (mt->isBusy()) {
; ;
} }
std::cout << "froot " << froot << std::endl; std::cout << "froot " << froot << std::endl;
auto imgfname = createFileName( outdir, froot, "ped", "tiff"); auto imgfname = createFileName( outdir, froot, "ped", "tiff");
mt->writePedestal(imgfname.c_str()); mt->writePedestal(imgfname.c_str());
imgfname = createFileName( outdir, froot, "rms", "tiff"); imgfname = createFileName( outdir, froot, "rms", "tiff");
mt->writePedestalRMS(imgfname.c_str()); 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 { //is a tiff file } else { //is a tiff file
std::vector<double> ped(nx * ny); std::vector<double> ped(nx * ny);
float* pp = ReadFromTiff(pedfilename.c_str(), nny, nnx); 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.data()); mt->setPedestal(ped.data());
std::cout << "Pedestal set from tiff file " << pedfilename std::cout << "Pedestal set from tiff file " << pedfilename
<< std::endl; << std::endl;
} else { } else {
std::cout << "Could not open pedestal tiff file " << pedfilename std::cout << "Could not open pedestal tiff file " << pedfilename
<< " for reading " << std::endl; << " for reading " << 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;
@ -315,88 +317,88 @@ int main(int argc, char *argv[]) {
// //open file // //open file
ioutfile = 0; ioutfile = 0;
if ( fileh5->OpenResources(filenames[ifile].c_str(), validate_rank) ) { if ( fileh5->OpenResources(filenames[ifile].c_str(), validate_rank) ) {
if (thr <= 0 && cf != 0) { // cluster finder if (thr <= 0 && cf != 0) { // cluster finder
if (of == nullptr) { if (of == nullptr) {
of = fopen(cfname.c_str(), "w"); of = fopen(cfname.c_str(), "w");
if (of) { if (of) {
if (mt) { if (mt) {
mt->setFilePointer(of); mt->setFilePointer(of);
std::cout << "file pointer set " << std::endl; std::cout << "file pointer set " << std::endl;
} else { } else {
std::cerr << "Error: mt is null." << std::endl; std::cerr << "Error: mt is null." << std::endl;
return 1; return 1;
}
//mt->setFilePointer(of);
//std::cout << "file pointer set " << std::endl;
std::cout << "Here! " << framenumber << " ";
} else {
std::cout << "Could not open " << cfname
<< " for writing " << std::endl;
mt->setFilePointer(nullptr);
return 1;
}
}
} }
//mt->setFilePointer(of);
//std::cout << "file pointer set " << std::endl;
std::cout << "Here! " << framenumber << " ";
} else {
std::cout << "Could not open " << cfname
<< " for writing " << std::endl;
mt->setFilePointer(nullptr);
return 1;
}
}
}
// //while read frame // //while read frame
framenumber = -1; framenumber = -1;
iframe = 0; iframe = 0;
ifr = 0; ifr = 0;
//std::cout << "Here! " << framenumber << " "; //std::cout << "Here! " << framenumber << " ";
while ( decoder->readNextFrame(*fileh5, framenumber, iframe, buff) ) { while ( decoder->readNextFrame(*fileh5, framenumber, iframe, buff) ) {
//std::cout << "Here! " << framenumber << " "; //std::cout << "Here! " << framenumber << " ";
// //push // //push
if ((ifr + 1) % 100 == 0) { if ((ifr + 1) % 1000 == 0) {
std::cout << " ****" std::cout << " ****"
<< decoder->getValue(buff, 20, 20); // << std::endl; << decoder->getValue(buff, 20, 20); // << std::endl;
} }
mt->pushData(buff); mt->pushData(buff);
// // //pop // // //pop
mt->nextThread(); mt->nextThread();
mt->popFree(buff); mt->popFree(buff);
++ifr; ++ifr;
if (ifr % 100 == 0) if (ifr % 1000 == 0)
std::cout << " " << ifr << " " << framenumber << std::endl; std::cout << " " << ifr << " " << framenumber << std::endl;
if (nframes > 0) { if (nframes > 0) {
if (ifr % nframes == 0) { if (ifr % nframes == 0) {
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", ioutfile ); imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", ioutfile );
mt->writeImage(imgfname.c_str(), thr1); mt->writeImage(imgfname.c_str(), thr1);
mt->clearImage(); mt->clearImage();
++ioutfile; ++ioutfile;
} }
} }
framenumber = -1; framenumber = -1;
} }
std::cout << "aa --" << std::endl; std::cout << "aa --" << std::endl;
fileh5->CloseResources(); fileh5->CloseResources();
std::cout << "bb --" << std::endl; std::cout << "bb --" << std::endl;
while (mt->isBusy()) { while (mt->isBusy()) {
; ;
} }
std::cout << "cc --" << std::endl; std::cout << "cc --" << std::endl;
if (nframes >= 0) { if (nframes >= 0) {
if (nframes > 0) if (nframes > 0)
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", ioutfile ); imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", 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);
mt->clearImage(); mt->clearImage();
if (of) { if (of) {
fclose(of); fclose(of);
of = nullptr; of = nullptr;
mt->setFilePointer(nullptr); mt->setFilePointer(nullptr);
} }
} }
std::time(&end_time); std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl; std::cout << std::ctime(&end_time) << std::endl;
} else } else
std::cout << "Could not open " << filenames[ifile] << " for reading " std::cout << "Could not open " << filenames[ifile] << " for reading "
<< std::endl; << std::endl;
} }
if (nframes < 0) { if (nframes < 0) {
std::string fprefix( getRootString(filenames[0]) ); //This might by a non-ideal name choice for that file std::string fprefix( getRootString(filenames[0]) ); //This might by a non-ideal name choice for that file
@ -405,8 +407,11 @@ int main(int argc, char *argv[]) {
mt->writeImage(imgfname.c_str(), thr1); mt->writeImage(imgfname.c_str(), thr1);
} }
//delete decoder
//delete filter; //delete filter;
//delete mt; delete mt;
delete filter;
delete decoder;
delete buff; delete buff;
return 0; return 0;