Moench v8 (#892)

* new rct structure for moench03

* new moench data structure for offline processing

* meonch raw data and zmq process files updated to 7.0.3 version

* implemented config file for Zmq file

* raw data and zmq work with config file, but only with one file/interface

* zmq config change

* added config examples for zmq and rawdata
This commit is contained in:
anberga
2024-01-12 14:01:06 +01:00
committed by GitHub
parent a03780718e
commit aa40128965
7 changed files with 985 additions and 251 deletions

View File

@ -13,7 +13,7 @@
#ifndef MOENCH04
#ifndef RECT
#include "moench03T1ReceiverDataNew.h"
#include "moench03v2Data.h"
#endif
#endif
@ -41,34 +41,147 @@ using namespace std;
int main(int argc, char *argv[]) {
if (argc < 4) {
std::map<std::string, std::string> args = {
{"numfiles","1"},
{"nthreads","5"},
{"fifosize","5000"},
{"nsigma","5"},
{"gainfile","none"},
{"detectorMode","counting"},
{"threshold","0"},
{"pedestalfile","none"},
{"nframes","0"},
{"xMin","0"},
{"xMax","400"},
{"yMin","0"},
{"yMax","400"},
{"eMin","0"},
{"eMax","16000"},
{"outdir","./"},
{"indir","./"},
{"flist","none"},
{"fformat","none"},
{"runmin","0"},
{"runmax","-1"},
{"readnrows","400"}
};
//float *gm;
int ff, np;
// cout << " data size is " << dsize;
ifstream filebin;
if (argc < 4) {
std::string name, value,sline;
int ic=0;
ifstream flist;
flist.open (argv[1], std::ifstream::in);
if (flist.is_open()) {
cout << "Using config file " <<argv[1] << endl;
while (std::getline(flist,sline)){
if (sline.at(0)!='#') {
ic=sline.find(' ');
name = sline.substr(0,ic);
value = sline.substr(ic+1,sline.size()-ic);
args[name]=value;
}
}
flist.close();
} else {
cout << "Usage is " << argv[0]
<< "indir outdir fname(no extension) [runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
"[nframes] [xmin xmax ymin ymax] [gainmap]"
"[nframes] [xmin xmax ymin ymax] [gainmap]"
<< endl;
cout << "threshold <0 means analog; threshold=0 means cluster finder; "
"threshold>0 means photon counting"
"threshold>0 means photon counting"
<< endl;
cout << "nframes <0 means sum everything; nframes=0 means one file per "
"run; nframes>0 means one file every nframes"
"run; nframes>0 means one file every nframes"
<< endl;
return 1;
return EXIT_FAILURE;
}
} else {
args["indir"]=argv[1];
args["outdir"]=argv[1];
args["fformat"]=argv[3];
if (argc >= 5) {
args["runmin"] = argv[4];
}
args["runmax"] = args["runmin"];
if (argc >= 6) {
args["runmax"] = argv[5];
}
if (argc >= 7) {
args["pedestalfile"] = argv[6];
}
if (argc >= 8) {
args["threshold"] = argv[7];
}
if (argc >= 9) {
args["nframes"] = argv[8];
}
if (argc >= 13) {
args["xMin"] = argv[9];
args["xMax"] = argv[10];
args["yMin"] = argv[11];
args["yMax"] = argv[12];
}
if (argc > 13) {
args["gainfile"] = argv[13];
}
if (atof(args["threshold"].c_str())<0) {
args["detectorMode"]="analog";
}
}
int fifosize = 1000;
int nthreads = 10;
int csize = 3;
int nsigma = 5;
int nped = 10000;
for (auto const& x : args)
{
std::cout << x.first // string (key)
<< ':'
<< x.second // string's value
<< std::endl;
}
string indir=args["indir"];
string outdir = args["outdir"];
string fformat= args["fformat"];
int runmin = atoi(args["runmin"].c_str());
int runmax = atoi(args["runmin"].c_str());
string pedfile =args["pedestalfile"];
double thr = atof(args["threshold"].c_str());
double thr1 = 1;
int nframes = atoi(args["nframes"].c_str());
int xmin = atoi(args["xMin"].c_str()), xmax = atoi(args["xMax"].c_str()), ymin = atoi(args["yMin"].c_str()), ymax = atoi(args["yMax"].c_str());
string gainfname=args["gainfile"];
int fifosize = atoi(args["fifosize"].c_str());
int nthreads = atoi(args["nthreads"].c_str());
int nsigma = atoi(args["nsigma"].c_str());
int nrows = atoi(args["readnrows"].c_str());
float eMin = atof(args["eMin"].c_str());
float eMax = atof(args["eMax"].c_str());
int csize = 3;
int nped = 1000;
int cf = 0;
int numberOfPackets=40;
int numberOfPackets=nrows/8;
#ifdef RECT
cout << "Should be rectangular but now it will crash! No data structure defined!" << endl;
#endif
#ifndef MOENCH04
moench03T1ReceiverDataNew *decoder = new moench03T1ReceiverDataNew();
moench03v2Data *decoder = new moench03v2Data(100);
cout << "MOENCH03!" << endl;
#endif
@ -77,7 +190,7 @@ int main(int argc, char *argv[]) {
moench04CtbZmq10GbData *decoder = new moench04CtbZmq10GbData(5000,0);
cout << "MOENCH04!" << endl;
#endif
#ifdef MOENCH04_DGS
moench04CtbZmq10GbData *decoder = new moench04CtbZmq10GbData(5000,5000);
cout << "MOENCH04 DGS!" << endl;
@ -86,63 +199,11 @@ int main(int argc, char *argv[]) {
#endif
//Read detector size from decoder
int nx , ny;
decoder->getDetectorSize(nx, ny);
//float *gm;
int ff, np;
// cout << " data size is " << dsize;
ifstream filebin;
char *indir = argv[1];
char *outdir = argv[2];
char *fformat = argv[3];
int runmin = 0;
// cout << "argc is " << argc << endl;
if (argc >= 5) {
runmin = atoi(argv[4]);
}
int runmax = runmin;
if (argc >= 6) {
runmax = atoi(argv[5]);
}
char *pedfile = NULL;
if (argc >= 7) {
pedfile = argv[6];
}
double thr = 0;
double thr1 = 1;
if (argc >= 8) {
thr = atof(argv[7]);
}
int nframes = 0;
if (argc >= 9) {
nframes = atoi(argv[8]);
}
int xmin = 0, xmax = nx, ymin = 0, ymax = ny;
if (argc >= 13) {
xmin = atoi(argv[9]);
xmax = atoi(argv[10]);
ymin = atoi(argv[11]);
ymax = atoi(argv[12]);
}
char *gainfname = NULL;
if (argc > 13) {
gainfname = argv[13];
cout << "Gain map file name is: " << gainfname << endl;
}
//Read detector size from decoder
char ffname[10000];
char fname[10000];
char imgfname[10000];
@ -151,17 +212,6 @@ int main(int argc, char *argv[]) {
std::time_t end_time;
FILE *of = NULL;
cout << "input directory is " << indir << endl;
cout << "output directory is " << outdir << endl;
cout << "input file is " << fformat << endl;
cout << "runmin is " << runmin << endl;
cout << "runmax is " << runmax << endl;
if (pedfile)
cout << "pedestal file is " << pedfile << endl;
if (thr > 0)
cout << "threshold is " << thr << endl;
cout << "Nframes is " << nframes << endl;
uint32_t nnx, nny;
@ -182,50 +232,62 @@ int main(int argc, char *argv[]) {
singlePhotonDetector *filter = new singlePhotonDetector(
decoder, csize, nsigma, 1, cm, nped, 200, -1, -1, gainmap, gs);
if (gainfname) {
//if (gainfname) {
if (filter->readGainMap(gainfname))
if (filter->readGainMap(gainfname.c_str()))
cout << "using gain map " << gainfname << endl;
else
cout << "Could not open gain map " << gainfname << endl;
} else
thr = 0.15 * thr;
// } else
thr = 0.15 * thr;
filter->newDataSet();
//int dsize = decoder->getDataSize();
if (thr > 0) {
cout << "threshold is " << thr << endl;
filter->setThreshold(thr);
cf = 0;
cout << "threshold is " << thr << endl;
filter->setThreshold(thr);
cf = 0;
} else
cf = 1;
cf = 1;
filter->setROI(xmin, xmax, ymin, ymax);
filter->setEnergyRange(eMin, eMax);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char *buff;
// multiThreadedAnalogDetector *mt=new
// multiThreadedAnalogDetector(filter,nthreads,fifosize);
multiThreadedCountingDetector *mt =
new multiThreadedCountingDetector(filter, nthreads, fifosize);
#ifndef ANALOG
mt->setDetectorMode(ePhotonCounting);
cout << "Counting!" << endl;
if (thr > 0) {
if (args["detectorMode"]=="counting") {
mt->setDetectorMode(ePhotonCounting);
if (thr > 0) {
cf = 0;
}
} else {
mt->setDetectorMode(eAnalog);
cf = 0;
}
#endif
//{
#ifdef ANALOG
mt->setDetectorMode(eAnalog);
cout << "Analog!" << endl;
cf = 0;
// thr1=thr;
#endif
// }
// #ifndef ANALOG
// mt->setDetectorMode(ePhotonCounting);
// cout << "Counting!" << endl;
// if (thr > 0) {
// cf = 0;
// }
// #endif
// //{
// #ifdef ANALOG
// mt->setDetectorMode(eAnalog);
// cout << "Analog!" << endl;
// cf = 0;
// // thr1=thr;
// #endif
// // }
mt->StartThreads();
mt->popFree(buff);
@ -236,84 +298,117 @@ int main(int argc, char *argv[]) {
char froot[1000];
double *ped=new double[nx * ny];//, *ped1;
int pos,pos1;
//return 0;
if (pedfile.find(".raw") != std::string::npos) {
pos1=pedfile.rfind("/");
strcpy(froot,pedfile.substr(pos1).c_str());
pos=string(froot).find(".raw");
froot[pos]='\0';
}
if (pedfile) {
if (string(pedfile).find(".raw") != std::string::npos) {
pos1=string(pedfile).rfind("/");
strcpy(froot,pedfile+pos1);
pos=string(froot).find(".raw");
froot[pos]='\0';
}
cout << "PEDESTAL " << endl;
if (string(pedfile).find(".tif") == std::string::npos) {
sprintf(fname, "%s", pedfile);
cout << "PEDESTAL " << endl;
if (pedfile.find(".tif") == std::string::npos) {
sprintf(fname, "%s", pedfile.c_str());
cout << fname << endl;
std::time(&end_time);
//cout << "aaa" << std::ctime(&end_time) << endl;
mt->setFrameMode(ePedestal);
// sprintf(fn,fformat,irun);
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
if (filebin.is_open()) {
ff = -1;
ff = -1;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
if (np == numberOfPackets) {
mt->pushData(buff);
if (np == numberOfPackets) {
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
ifr++;
if (ifr % 100 == 0)
cout << ifr << " " << ff << " " << np << endl;
} else
cout << ifr << " " << ff << " " << np << endl;
if (ifr % 100 == 0)
cout << ifr << " " << ff << " " << np << endl;
// break;
} else {
cout << ifr << " " << ff << " " << np << endl;
break;
}
ff = -1;
}
filebin.close();
while (mt->isBusy()) {
;
}
;
sprintf(imgfname, "%s/%s_ped.tiff", outdir,froot);
}
sprintf(imgfname, "%s/%s_ped.tiff", outdir.c_str(),froot);
mt->writePedestal(imgfname);
sprintf(imgfname, "%s/%s_var.tiff", outdir,froot);
sprintf(imgfname, "%s/%s_var.tiff", outdir.c_str(),froot);
mt->writePedestalRMS(imgfname);
} else
cout << "Could not open pedestal file " << fname
<< " for reading " << endl;
} else {
float *pp = ReadFromTiff(pedfile, nny, nnx);
if (pp && (int)nnx == nx && (int)nny == ny) {
for (int i = 0; i < nx * ny; i++) {
cout << "Could not open pedestal file " << fname
<< " for reading " << endl;
} else {
float *pp = ReadFromTiff(pedfile.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);
cout << "Pedestal set from tiff file " << pedfile << endl;
} else {
cout << "Could not open pedestal tiff file " << pedfile
}
delete[] pp;
mt->setPedestal(ped);
cout << "Pedestal set from tiff file " << pedfile << endl;
} else {
cout << "Could not open pedestal tiff file " << pedfile
<< " for reading " << endl;
}
}
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
}
}
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
ifr = 0;
int ifile = 0;
mt->setFrameMode(eFrame);
//t filelist=0;
ifstream flist;
flist.open (args["flist"].c_str(), std::ifstream::in);
if (flist.is_open()) {
cout << "Using file list" << endl;
runmin=0;
runmax=0;
while (flist.getline(ffname,10000)){
cout << ffname << endl;
runmax++;
}
runmax--;
flist.close();
cout << "Found " << runmax << " files " << endl;
flist.open (fformat, std::ifstream::in);
}
for (int irun = runmin; irun <= runmax; irun++) {
cout << "DATA ";
// sprintf(fn,fformat,irun);
sprintf(ffname, "%s/%s.raw", indir, fformat);
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);
// sprintf(ffname, "%s/%s.raw", indir, fformat);
// 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);
if (flist.is_open()) {
flist.getline(ffname,10000);
cout << "file list " << ffname << endl;
} else {
//sprintf(ffname,(const char*)fformat,irun);
sprintf(ffname,args["fformat"].c_str(),irun);
cout << "loop " << ffname << endl;
}
cout << "ffname "<< ffname << endl;
sprintf(fname, "%s/%s.raw",indir.c_str(),ffname);
sprintf(imgfname, "%s/%s.tiff",outdir.c_str(),ffname);
sprintf(cfname, "%s/%s.clust",outdir.c_str(),ffname);
cout << fname << " ";
cout << imgfname << endl;
std::time(&end_time);
@ -323,7 +418,7 @@ int main(int argc, char *argv[]) {
// //open file
ifile = 0;
if (filebin.is_open()) {
if (thr <= 0 && cf != 0) { // cluster finder
if (cf != 0) { // cluster finder
if (of == NULL) {
of = fopen(cfname, "w");
if (of) {
@ -341,7 +436,7 @@ int main(int argc, char *argv[]) {
ff = -1;
ifr = 0;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
if (np == numberOfPackets) {
if (np == numberOfPackets) {
// //push
mt->pushData(buff);
// // //pop
@ -350,21 +445,26 @@ int main(int argc, char *argv[]) {
ifr++;
if (ifr % 100 == 0)
cout << ifr << " " << ff << endl;
cout << ifr << " " << ff << " " << np << endl;
//break;
if (nframes > 0) {
if (ifr % nframes == 0) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat,
ifile);
sprintf(imgfname, (const char*)ffname, irun);
// sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat,
// ifile);
// sprintf(imgfname, (const char*)ffname, irun);
sprintf(imgfname, "%s/%s_f%05d.tiff",outdir.c_str(),ffname,ifile);
while (mt->isBusy())
;
mt->writeImage(imgfname, thr1);
mt->clearImage();
ifile++;
}
}
} else {
cout << "bp " << ifr << " " << ff << " " << np << endl;
//break;
}
} else {
cout << "bp " << ifr << " " << ff << " " << np << endl;
//break;
}
ff = -1;
}
cout << "--" << endl;
@ -374,13 +474,17 @@ int main(int argc, char *argv[]) {
}
if (nframes >= 0) {
if (nframes > 0) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat, ifile);
sprintf(imgfname, (const char*)ffname, irun);
sprintf(imgfname, "%s/%s_f%05d.tiff",outdir.c_str(),ffname,ifile);
// 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);
sprintf(imgfname, "%s/%s.tiff",outdir.c_str(),ffname);
// sprintf(ffname, "%s/%s.tiff", outdir, fformat);
// sprintf(imgfname, (const char*)ffname, irun);
}
cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
while (mt->isBusy())
;
mt->writeImage(imgfname, thr1);
mt->clearImage();
if (of) {
@ -395,11 +499,16 @@ int main(int argc, char *argv[]) {
cout << "Could not open " << fname << " for reading " << endl;
}
if (nframes < 0) {
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
strcpy(imgfname, ffname);
cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
mt->writeImage(imgfname, thr1);
//sprintf(ffname, "%s/%s.tiff", outdir, fformat);
// strcpy(imgfname, ffname);
sprintf(imgfname, "%s/%s_tot.tiff",outdir.c_str(),ffname);
cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
while (mt->isBusy())
;
mt->writeImage(imgfname, thr1);
}
if (flist.is_open()) {
flist.close();
}
return 0;
}