Jf rawdataprocess txtfile (#732)

* Fix ROI mapping

* Formatting

* Minor edit

* intial draft of cmake for jungfrau executables Makefile.rawdataprocess

* added the cmake file

* missed Makefile

* added libfmt

* Fix some compiler warnings

* Fix some compiler warnings

* Create filename usining fmt::format

* Rewrite command line parsing with std::string and fmt::format

* Fix file reading

* Fix root string extraction

* Fix ifstream file reading

* Clean up comments

* Add version of rawdataprocess with bash wildcards

* Add version of rawdataprocess that reads inputs from txt-file, still buggy

* intermediate

* fix file loop

* fix const

* Circumevent bug with stuck threads

* Fix mutex bug

* cleanup

---------

Co-authored-by: vhinger182 <hinger_v@hv_home_lt1.localdomain>
Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>
This commit is contained in:
hinger_v 2023-05-08 16:30:37 +02:00 committed by GitHub
parent 74acbb15f5
commit 4c6be26846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 39 deletions

View File

@ -14,7 +14,7 @@ target_compile_definitions(jungfrauRawDataProcess PRIVATE MODULE)
list(APPEND JUNGFRAU_EXECUTABLES jungfrauRawDataProcess)
# jungfrauRawDataProcessStrx
add_executable(jungfrauRawDataProcessStrx jungfrauRawDataProcess.cpp)
add_executable(jungfrauRawDataProcessStrx jungfrauRawDataProcess_filetxt.cpp)
target_compile_definitions(jungfrauRawDataProcessStrx PRIVATE JFSTRX)
list(APPEND JUNGFRAU_EXECUTABLES jungfrauRawDataProcessStrx)

View File

@ -59,14 +59,12 @@ std::string getRootString( const std::string& filepath ) {
// 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 ) {
std::string filename{};
if (outfilecounter >= 0)
filename = 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)
filename = fmt::format("{:s}/{:s}_{:s}.{:s}", dir, fprefix, fsuffix, fext);
return fmt::format("{:s}/{:s}_{:s}.{:s}", dir, fprefix, fsuffix, fext);
else
filename = fmt::format("{:s}/{:s}_d{:d}_f{:d}_{:d}.{:s}", dir, fprefix, mindex, findex, aindex, fext);
return filename;
return fmt::format("{:s}/{:s}_d{:d}_f{:d}_{:d}.{:s}", dir, fprefix, mindex, findex, aindex, fext);
}
int main(int argc, char *argv[]) {

View File

@ -41,7 +41,8 @@
#include <ctime>
#include <fmt/core.h>
std::string getRootString( const std::string filepath ) {
std::string getRootString( const std::string& filepath ) {
size_t pos1;
if (filepath.find("/") == std::string::npos )
pos1 = 0;
@ -57,15 +58,13 @@ std::string getRootString( const std::string filepath ) {
// 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{};
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)
filename = fmt::format("{:s}/{:s}_{:s}_f{:05d}.{:s}", dir, fprefix, fsuffix, outfilecounter, fext);
return 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);
return fmt::format("{:s}/{:s}_{:s}.{:s}", dir, fprefix, fsuffix, fext);
else
filename = fmt::format("{:s}/{:s}.{:s}", dir, fprefix, fext);
return filename;
return fmt::format("{:s}/{:s}.{:s}", dir, fprefix, fext);
}
@ -104,9 +103,9 @@ int main(int argc, char *argv[]) {
int ff, np;
// cout << " data size is " << dsize;
std::string txtfilename(argv[1]);
std::string outdir(argv[2]);
std::string pedfilename(argv[3]);
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]);
@ -122,26 +121,31 @@ int main(int argc, char *argv[]) {
//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::string line{};
std::getline(inputs, line);
filenames.push_back(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;
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;
}
} 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 && \
@ -319,14 +323,14 @@ int main(int argc, char *argv[]) {
std::cout << "PEDESTAL " << std::endl;
if (pedfilename.find(".tif") == std::string::npos) {
std::string fname = pedfilename;
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);
ifstream pedefile(fname, ios::in | ios::binary);
std::ifstream pedefile(fname, ios::in | ios::binary);
// //open file
if (pedefile.is_open()) {
std::cout << "bbbb " << std::ctime(&end_time) << std::endl;
@ -392,15 +396,15 @@ int main(int argc, char *argv[]) {
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 fname(argv[iargc]);
std::string fsuffix{};
std::string fprefix = getRootString(filenames[ifile]);
std::string imgfname = createFileName( outdir, fprefix, fsuffix, "tiff" );
std::string cfname = createFileName( outdir, fprefix, fsuffix, "clust" );
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);
@ -408,7 +412,7 @@ int main(int argc, char *argv[]) {
ifstream filebin(filenames[ifile], ios::in | ios::binary);
// //open file
ifile = 0;
ioutfile = 0;
if (filebin.is_open()) {
if (thr <= 0 && cf != 0) { // cluster finder
if (of == NULL) {
@ -448,21 +452,23 @@ int main(int argc, char *argv[]) {
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", ioutfile );
mt->writeImage(imgfname.c_str(), thr1);
mt->clearImage();
ioutfile++;
++ioutfile;
}
}
// } else
//std::cout << ifr << " " << ff << " " << np << std::endl;
ff = -1;
}
std::cout << "--" << std::endl;
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", ifile );
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", ioutfile );
std::cout << "Writing tiff to " << imgfname << " " << thr1
<< std::endl;
mt->writeImage(imgfname.c_str(), thr1);
@ -481,8 +487,8 @@ int main(int argc, char *argv[]) {
}
if (nframes < 0) {
//std::string fname(argv[10]);
auto fprefix = getRootString(filenames[0]); //This might by a non-ideal name choice for that file
auto imgfname = createFileName( outdir, fprefix, "sum", "tiff" );
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);
}

View File

@ -130,6 +130,7 @@ class threadedAnalogDetector {
// return 1;}
virtual int isBusy() {
//std::cout << busy << " " << fifoData->isEmpty() << " " << fifoData->getDataValue() << " " << fifoData->getFreeValue() << std::endl;
if (busy == 0) {
usleep(100);
if (busy == 0) {
@ -447,7 +448,7 @@ class multiThreadedAnalogDetector {
for (int i = 0; i < nThreads; i++) {
ret1 = dets[i]->isBusy();
ret |= ret1;
// if (ret1) cout << "thread " << i <<" still busy " << endl;
//if (ret1) cout << "thread " << i <<" still busy " << endl;
}
return ret;
}

View File

@ -63,7 +63,7 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
quad(UNDEFINED_QUADRANT), tot(0), quadTot(0) {
fm = new pthread_mutex_t;
pthread_mutex_init(fm, NULL);
pthread_mutex_init(fm, NULL);
eventMask = new eventType *[ny];
// val=new double*[ny];