mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 18:10:40 +02:00
Jf zeromq display (#644)
* modified ZmqSocket to expose the SO_RCVBUF and SO_SENDBUF parameters. Modified DataStreamer.cpp to change the SENDBUF to 1MB when HWL is <10. Modified Datastreamer.cpp so that when HWL is changed, socket is unbind/rebind. Added rebind to ZmqSocket.cpp. Changed slot UpdatePlot() in qdrawplot.h from privat tto public, added plot->UpdatePlot() after every axis range change, so the plots are updated immediatly and not at the next image. Added onlinedisp_zmq program which connects to the receiver ZMQ port and show images and histos. Compiled against ROOT 6.22/02. Added examples files. * added setbuffer size also for gui, moved hardcoded values to a macro, removed unnecessary return of ok or success, added actual zmq exception message to could not create sockets error * zmq: changing buffer size done within hwm --------- Co-authored-by: mozzanica <l_mozzanica@mpc2012.psi.ch> Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
This commit is contained in:
parent
e14f6981a0
commit
4ee4d66977
@ -40,20 +40,31 @@ class jungfrauModuleData : public slsDetectorData<uint16_t> {
|
||||
out by a module i.e. using the slsReceiver (160x160 pixels, 40 packets
|
||||
1286 large etc.) \param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
*/
|
||||
#ifndef ZMQ
|
||||
#define off sizeof(jf_header)
|
||||
#endif
|
||||
#ifdef ZMQ
|
||||
#define off 0
|
||||
#endif
|
||||
|
||||
|
||||
jungfrauModuleData()
|
||||
: slsDetectorData<uint16_t>(1024, 512,
|
||||
1024* 512 * 2 + sizeof(jf_header)) {
|
||||
|
||||
1024* 512 * 2 + off) {
|
||||
|
||||
for (int ix = 0; ix < 1024; ix++) {
|
||||
for (int iy = 0; iy < 512; iy++) {
|
||||
dataMap[iy][ix] = sizeof(jf_header) + (1024 * iy + ix) * 2;
|
||||
dataMap[iy][ix] = off + (1024 * iy + ix) * 2;
|
||||
#ifdef HIGHZ
|
||||
dataMask[iy][ix] = 0x3fff;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
iframe = 0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
@ -0,0 +1,64 @@
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
# Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
#module add CBFlib/0.9.5
|
||||
INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ -I../tiffio/include
|
||||
|
||||
LDFLAG= ../tiffio/src/tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -pthread -lrt -ltiff -O3 -std=c++11
|
||||
|
||||
MAIN=jungfrauClusterFinder.cpp
|
||||
|
||||
|
||||
all: jungfrauRawDataProcess
|
||||
|
||||
jungfrauRawDataProcess: jungfrauRawDataProcess.cpp $(INCS) clean
|
||||
g++ -o jungfrauRawDataProcess jungfrauRawDataProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DMODULE
|
||||
|
||||
jungfrauRawDataProcessStrx: jungfrauRawDataProcess.cpp $(INCS) clean
|
||||
g++ -o jungfrauRawDataProcessStrx jungfrauRawDataProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DJFSTRX
|
||||
|
||||
jungfrauRawDataProcessStrxAldo: jungfrauRawDataProcess.cpp $(INCS) clean
|
||||
g++ -o jungfrauRawDataProcessStrxAldo jungfrauRawDataProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DJFSTRX -DALDO
|
||||
|
||||
jungfrauRawDataProcessStrxOld: jungfrauRawDataProcess.cpp $(INCS) clean
|
||||
g++ -o jungfrauRawDataProcessStrxOld jungfrauRawDataProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DJFSTRXOLD
|
||||
|
||||
jungfrauRawDataProcessStrxOldAldo: jungfrauRawDataProcess.cpp $(INCS) clean
|
||||
g++ -o jungfrauRawDataProcessStrxOldAldo jungfrauRawDataProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DJFSTRXOLD -DALDO
|
||||
|
||||
|
||||
|
||||
jungfrauClusterFinder: jungfrauClusterFinder.cpp $(INCS) clean
|
||||
g++ -o jungfrauClusterFinder jungfrauClusterFinder.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL
|
||||
|
||||
|
||||
jungfrauClusterFinderHighZ: jungfrauClusterFinder.cpp $(INCS) clean
|
||||
g++ -o jungfrauClusterFinderHighZ jungfrauClusterFinder.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DHIGHZ
|
||||
|
||||
|
||||
|
||||
|
||||
jungfrauMakeEta: jungfrauInterpolation.cpp $(INCS) clean
|
||||
g++ -o jungfrauMakeEta jungfrauInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF
|
||||
|
||||
jungfrauInterpolation: jungfrauInterpolation.cpp $(INCS) clean
|
||||
g++ -o jungfrauInterpolation jungfrauInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF)
|
||||
|
||||
jungfrauNoInterpolation: jungfrauNoInterpolation.cpp $(INCS) clean
|
||||
g++ -o jungfrauNoInterpolation jungfrauNoInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF)
|
||||
|
||||
jungfrauPhotonCounter: jungfrauPhotonCounter.cpp $(INCS) clean
|
||||
g++ -o jungfrauPhotonCounter jungfrauPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER
|
||||
|
||||
jungfrauAnalog: jungfrauPhotonCounter.cpp $(INCS) clean
|
||||
g++ -o jungfrauAnalog jungfrauPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DANALOG
|
||||
|
||||
jungfrauPhotonCounterHighZ: jungfrauPhotonCounter.cpp $(INCS) clean
|
||||
g++ -o jungfrauPhotonCounterHighZ jungfrauPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DHIGHZ
|
||||
|
||||
jungfrauAnalogHighZ: jungfrauPhotonCounter.cpp $(INCS) clean
|
||||
g++ -o jungfrauAnalogHighZ jungfrauPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DANALOG -DHIGHZ
|
||||
|
||||
clean:
|
||||
rm -f jungfrauClusterFinder jungfrauMakeEta jungfrauInterpolation jungfrauNoInterpolation jungfrauPhotonCounter jungfrauAnalog
|
||||
|
||||
|
@ -1,25 +1,19 @@
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
# Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
|
||||
INCDIR= -I. -I../dataStructures ../tiffIO.cpp -I../ -I../interpolations/ -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ -I../../libs/rapidjson/
|
||||
INCDIR= -I. -I../dataStructures ../tiffio/src/tiffIO.cpp -I../ -I../interpolations/ -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ -I../../libs/rapidjson/ -I../tiffio/include
|
||||
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -O3 -std=c++11 -Wall -L../../build/bin/ -lSlsSupport
|
||||
#-L../../bin -lhdf5 -L.
|
||||
|
||||
#DESTDIR?=../bin
|
||||
|
||||
all: moenchZmqProcess moenchZmq04Process
|
||||
#moenchZmqProcessCtbGui
|
||||
all: jungfrauZmqProcess
|
||||
#jungfrauZmqProcessCtbGui
|
||||
|
||||
moenchZmqProcess: moenchZmqProcess.cpp clean
|
||||
g++ -o moenchZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP
|
||||
|
||||
moenchZmq04Process: moenchZmqProcess.cpp clean
|
||||
g++ -o moench04ZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DMOENCH04
|
||||
|
||||
#moenchZmqProcessCtbGui: moenchZmqProcess.cpp clean
|
||||
# g++ -o moenchZmqProcessCtbGui moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DCTBGUI
|
||||
jungfrauZmqProcess: jungfrauZmqProcess.cpp clean
|
||||
g++ -o jungfrauZmqProcess jungfrauZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP
|
||||
|
||||
clean:
|
||||
rm -f moenchZmqProcess
|
||||
rm -f jungfrauZmqProcess
|
||||
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
ROOTSYS=/opt/cern/v6/root
|
||||
#/afs/psi.ch/project/sls_det_sof/roottware/root_v5.34.23_sl6_64bit
|
||||
|
||||
|
||||
|
||||
LIBZMQDIR = $(PWD)
|
||||
LIBZMQ = -L$(LIBZMQDIR) -lzmq
|
||||
SHLIB_PATH=/opt/cern/v6/root/lib
|
||||
CMAKE_PREFIX_PATH=/opt/cern/v6/root
|
||||
DYLD_LIBRARY_PATH=/opt/cern/v6/root/lib
|
||||
|
||||
|
||||
INCDIR= -I. -I../dataStructures ../tiffio/src/tiffIO.cpp -I../ -I../interpolations/ -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ -I../../libs/rapidjson/ -I../tiffio/include
|
||||
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -O3 -std=c++11 -Wall -L../../build/bin/ -lSlsSupport
|
||||
#-L../../bin -lhdf5 -L.
|
||||
|
||||
|
||||
|
||||
default: onlinedisp_zmq
|
||||
|
||||
onlinedisp_zmq: onlinedisp_zmq.cpp onlinedisp_zmq.h
|
||||
# flags from root-config --cflags --glibs
|
||||
g++ -o onlinedisp_zmq onlinedisp_zmq.cpp -I. -I$(ROOTSYS)/include -Wall -g -lm -L. -lzmq -pthread -lrt -L$(ROOTSYS)/lib -lGui -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -m64 $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF)
|
||||
|
||||
#-lCint
|
||||
|
10
slsDetectorCalibration/jungfrauExecutables/examples.txt
Normal file
10
slsDetectorCalibration/jungfrauExecutables/examples.txt
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
sls_detector_put rx_jsonpara detectorMode counting
|
||||
sls_detector_put rx_jsonpara frameMode newPedestal
|
||||
sls_detector_put rx_jsonpara frameMode frame
|
||||
sls_detector_put rx_jsonpara detectorMode analog
|
||||
sls_detector_put rx_jsonpara threshold 150
|
||||
sls_detector_put rx_jsonpara threshold 0
|
||||
sls_detector_put rx_jsonpara threshold 300
|
||||
sls_detector_put rx_zmqhwm 50
|
@ -0,0 +1,418 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
//#include "sls/ansi.h"
|
||||
#include <iostream>
|
||||
#undef CORR
|
||||
|
||||
#define C_GHOST 0.0004
|
||||
|
||||
#define CM_ROWS 50
|
||||
|
||||
#define RAWDATA
|
||||
|
||||
#ifndef JFSTRX
|
||||
#ifndef JFSTRXOLD
|
||||
#ifndef MODULE
|
||||
#include "jungfrauHighZSingleChipData.h"
|
||||
#endif
|
||||
#ifdef MODULE
|
||||
#include "jungfrauModuleData.h"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifdef JFSTRX
|
||||
#include "jungfrauLGADStrixelsData.h"
|
||||
#endif
|
||||
#ifdef JFSTRXOLD
|
||||
#include "jungfrauStrixelsHalfModuleOldDesign.h"
|
||||
#endif
|
||||
|
||||
#include "multiThreadedCountingDetector.h"
|
||||
#include "singlePhotonDetector.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if (argc < 5) {
|
||||
cout << "Usage is " << argv[0]
|
||||
<< "indir outdir fname(no extension) fextension [runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
|
||||
"[nframes] [xmin xmax ymin ymax] [gainmap]"
|
||||
<< endl;
|
||||
cout << "threshold <0 means analog; threshold=0 means cluster finder; "
|
||||
"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"
|
||||
<< endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fifosize = 1000;
|
||||
int nthreads = 10;
|
||||
int csize = 3;
|
||||
int nsigma = 5;
|
||||
int nped = 10000;
|
||||
|
||||
int cf = 0;
|
||||
|
||||
|
||||
#ifndef JFSTRX
|
||||
#ifndef JFSTRXOLD
|
||||
#ifndef MODULE
|
||||
jungfrauHighZSingleChipData *decoder = new jungfrauHighZSingleChipData();
|
||||
int nx = 256, ny = 256;
|
||||
#endif
|
||||
#ifdef MODULE
|
||||
jungfrauModuleData *decoder = new jungfrauModuleData();
|
||||
int nx = 1024, ny = 512;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifdef JFSTRX
|
||||
cout << "bbb" << endl;
|
||||
jungfrauLGADStrixelsData *decoder = new jungfrauLGADStrixelsData();
|
||||
int nx = 1024/5, ny = 512*5;
|
||||
#endif
|
||||
#ifdef JFSTRXOLD
|
||||
cout << "ccc" << endl;
|
||||
jungfrauStrixelsHalfModuleOldDesign *decoder = new jungfrauStrixelsHalfModuleOldDesign();
|
||||
int nx = 1024*3, ny = 512/3;
|
||||
#endif
|
||||
|
||||
|
||||
decoder->getDetectorSize(nx, ny);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cout << "Detector size is " << nx << " " << ny << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
double *gainmap = NULL;
|
||||
//float *gm;
|
||||
|
||||
int ff, np;
|
||||
// cout << " data size is " << dsize;
|
||||
|
||||
ifstream filebin;
|
||||
char *indir = argv[1];
|
||||
char *outdir = argv[2];
|
||||
char *fformat = argv[3];
|
||||
char *fext = argv[4];
|
||||
int runmin = 0;
|
||||
|
||||
// cout << "argc is " << argc << endl;
|
||||
if (argc >= 6) {
|
||||
runmin = atoi(argv[5]);
|
||||
}
|
||||
|
||||
int runmax = runmin;
|
||||
|
||||
if (argc >= 7) {
|
||||
runmax = atoi(argv[6]);
|
||||
}
|
||||
|
||||
char *pedfile = NULL;
|
||||
if (argc >= 8) {
|
||||
pedfile = argv[7];
|
||||
}
|
||||
double thr = 0;
|
||||
double thr1 = 1;
|
||||
|
||||
if (argc >= 9) {
|
||||
thr = atof(argv[8]);
|
||||
}
|
||||
|
||||
int nframes = 0;
|
||||
|
||||
if (argc >= 10) {
|
||||
nframes = atoi(argv[9]);
|
||||
}
|
||||
|
||||
int xmin = 0, xmax = nx, ymin = 0, ymax = ny;
|
||||
if (argc >= 14) {
|
||||
xmin = atoi(argv[10]);
|
||||
xmax = atoi(argv[11]);
|
||||
ymin = atoi(argv[12]);
|
||||
ymax = atoi(argv[13]);
|
||||
}
|
||||
|
||||
char *gainfname = NULL;
|
||||
if (argc > 14) {
|
||||
gainfname = argv[14];
|
||||
cout << "Gain map file name is: " << gainfname << endl;
|
||||
}
|
||||
|
||||
char ffname[10000];
|
||||
char fname[10000];
|
||||
char imgfname[10000];
|
||||
char cfname[10000];
|
||||
|
||||
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;
|
||||
|
||||
singlePhotonDetector *filter = new singlePhotonDetector(
|
||||
decoder, csize, nsigma, 1, NULL, nped, 200, -1, -1, gainmap, NULL);
|
||||
|
||||
if (gainfname) {
|
||||
|
||||
if (filter->readGainMap(gainfname))
|
||||
cout << "using gain map " << gainfname << endl;
|
||||
else
|
||||
cout << "Could not open gain map " << gainfname << endl;
|
||||
} else
|
||||
thr = 0.15 * thr;
|
||||
filter->newDataSet();
|
||||
//int dsize = decoder->getDataSize();
|
||||
|
||||
if (thr > 0) {
|
||||
cout << "threshold is " << thr << endl;
|
||||
filter->setThreshold(thr);
|
||||
cf = 0;
|
||||
|
||||
} else
|
||||
cf = 1;
|
||||
|
||||
filter->setROI(xmin, xmax, ymin, ymax);
|
||||
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) {
|
||||
cf = 0;
|
||||
}
|
||||
#endif
|
||||
//{
|
||||
#ifdef ANALOG
|
||||
mt->setDetectorMode(eAnalog);
|
||||
cout << "Analog!" << endl;
|
||||
cf = 0;
|
||||
// thr1=thr;
|
||||
#endif
|
||||
// }
|
||||
|
||||
mt->StartThreads();
|
||||
mt->popFree(buff);
|
||||
|
||||
// cout << "mt " << endl;
|
||||
|
||||
int ifr = 0;
|
||||
|
||||
char froot[1000];
|
||||
double *ped=new double[nx * ny];//, *ped1;
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
cout << "PEDESTAL " << endl;
|
||||
// sprintf(imgfname, "%s/pedestals.tiff", outdir);
|
||||
|
||||
if (string(pedfile).find(".tif") == std::string::npos) {
|
||||
sprintf(fname, "%s", pedfile);
|
||||
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;
|
||||
while (decoder->readNextFrame(filebin, ff, np, buff)) {
|
||||
// if (np == 40) {
|
||||
if ((ifr+1) % 100 == 0) {
|
||||
cout << " ****" << decoder->getValue(buff,20,20);// << endl;
|
||||
}
|
||||
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>=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
|
||||
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++) {
|
||||
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
|
||||
<< " for reading " << endl;
|
||||
}
|
||||
}
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << endl;
|
||||
}
|
||||
|
||||
ifr = 0;
|
||||
int ifile = 0;
|
||||
|
||||
mt->setFrameMode(eFrame);
|
||||
|
||||
for (int irun = runmin; irun <= runmax; irun++) {
|
||||
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);
|
||||
cout << fname << " ";
|
||||
cout << imgfname << endl;
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << 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);
|
||||
cout << "file pointer set " << endl;
|
||||
} else {
|
||||
cout << "Could not open " << cfname << " for writing "
|
||||
<< 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) {
|
||||
cout << " ****" << decoder->getValue(buff,20,20);// << endl;
|
||||
}
|
||||
mt->pushData(buff);
|
||||
// // //pop
|
||||
mt->nextThread();
|
||||
mt->popFree(buff);
|
||||
|
||||
ifr++;
|
||||
if (ifr % 100 == 0)
|
||||
cout << " " << ifr << " " << ff << 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;
|
||||
}
|
||||
cout << "--" << 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);
|
||||
}
|
||||
cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
|
||||
mt->writeImage(imgfname, thr1);
|
||||
mt->clearImage();
|
||||
if (of) {
|
||||
fclose(of);
|
||||
of = NULL;
|
||||
mt->setFilePointer(NULL);
|
||||
}
|
||||
}
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << endl;
|
||||
} else
|
||||
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);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
679
slsDetectorCalibration/jungfrauExecutables/onlinedisp_zmq.cpp
Normal file
679
slsDetectorCalibration/jungfrauExecutables/onlinedisp_zmq.cpp
Normal file
@ -0,0 +1,679 @@
|
||||
#include "onlinedisp_zmq.h"
|
||||
bool hasallpede;
|
||||
TH1F * his102;TH1F * his101;
|
||||
int processedf;
|
||||
sls::zmqHeader zHeader;
|
||||
#define PEDEFNAME "current_pede.dat"
|
||||
#define NPRO 50
|
||||
#define NPRI 50
|
||||
|
||||
//#define JFSTRX
|
||||
#ifdef JFSTRX
|
||||
#include "jungfrauLGADStrixelsData.h"
|
||||
#else
|
||||
#include "jungfrauModuleData.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
goout=1;
|
||||
hasallpede=false;
|
||||
dophotonmap=true; if ((argc<3)) {printf("USAGE: command photon_energy_(peakinADC) [rx_ip] [port] \n"); return -1 ;}
|
||||
else {
|
||||
phene=atoi(argv[1]);
|
||||
if (phene<0) dophotonmap=false;
|
||||
threshold=float (phene/2);
|
||||
printf( " \n");
|
||||
printf( "phene %d \n",phene);
|
||||
}
|
||||
|
||||
if (argc>=3) {
|
||||
strcpy(serverip,argv[2]);
|
||||
printf("ip is %s ",serverip);
|
||||
}
|
||||
|
||||
portnum=30001;
|
||||
if (argc>=4 ){ portnum= atoi(argv[3]);
|
||||
}
|
||||
printf(", port number is %d ",portnum); printf(". \n");
|
||||
|
||||
|
||||
#ifdef JFSTRX
|
||||
cout << "JFSTRX" << endl;
|
||||
jungfrauLGADStrixelsData *decoder = new jungfrauLGADStrixelsData();
|
||||
nx = 1024/5; ny= 512*5;
|
||||
#else
|
||||
nx = 1024; ny= 512;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
gain_flag=false;
|
||||
pede_flag=false;
|
||||
bw_flag=false;
|
||||
|
||||
HDraw_every=20;
|
||||
fixranges=false;
|
||||
|
||||
|
||||
hchptr = (short*) malloc(NCH*sizeof(short));
|
||||
|
||||
startsocket(); //create and connect ZMQ
|
||||
|
||||
for (ipx=0;ipx<NCH;ipx++) hchptr[(ipx)]=0;
|
||||
|
||||
|
||||
// cout<< decoder->getValue((char*)(hchptr),279,130)<<endl;
|
||||
|
||||
|
||||
nonblock(NB_ENABLE);
|
||||
|
||||
cout <<"opening the rootapp" <<endl;
|
||||
|
||||
rootapp = new TApplication("Online JF display",&argc, argv);
|
||||
|
||||
LoadPaletteFalse();
|
||||
|
||||
char hname[100];
|
||||
|
||||
|
||||
|
||||
his1000= new TH2F("his1000","2d , ev. pede corrected",nx,-0.5,nx-0.5,ny,-0.5,ny-0.5);
|
||||
his1000->SetOption("colz");
|
||||
his2000= new TH2F("his2000","2d gain ",nx,-0.5,nx-0.5,ny,-0.5,ny-0.5);
|
||||
his2000->GetZaxis()->SetRangeUser(0,4);
|
||||
|
||||
if (dophotonmap) {
|
||||
his3000= new TH2F("his3000"," photon map ",nx,-0.5,nx-0.5,ny,-0.5,ny-0.5);
|
||||
}
|
||||
else {
|
||||
his3000= new TH2F("his3000"," raw adc ",nx,-0.5,nx-0.5,ny,-0.5,ny-0.5);
|
||||
}
|
||||
|
||||
his4500= new TH2F("his45000","L vs R",101,-50,500,101,-50,500);
|
||||
hchip=new TH1I*[8];
|
||||
for (i=0;i<8;i++) {
|
||||
sprintf(hname,"hchip%d",i);
|
||||
hchip[i] = new TH1I(hname,hname,NBIN,MIN_POS,MAX_POS);
|
||||
}
|
||||
|
||||
cout <<"end of histo booking" <<endl;
|
||||
if (A2==NULL) A2 = new TCanvas("A2","Plotting Canvas gain",150,10,500,250);
|
||||
if (A3==NULL) A3 = new TCanvas("A3","Plotting Canvas ADC",150,360,1200,550);
|
||||
if (A4==NULL) A4 = new TCanvas("A4","Plotting Canvas PHs",750,300,1000,800);
|
||||
A4->Clear();
|
||||
A4->Divide(4,2,0.005,0.005);
|
||||
if (A5==NULL) A5 = new TCanvas("A5","Plotting Canvas Photon Map",750,300,1000,600);
|
||||
if (A6==NULL) A6 = new TCanvas("A6","Plotting Canvas LvsR",650,250,650,660);
|
||||
|
||||
gSystem->ProcessEvents();
|
||||
int running=0;
|
||||
char runc[15]="*\\-/|";
|
||||
printhelp();
|
||||
|
||||
|
||||
|
||||
while (1==1) { // loop on streamed frames
|
||||
|
||||
if(!zmqSocket->ReceiveHeader(0,zHeader, SLS_DETECTOR_JSON_HEADER_VERSION)){
|
||||
cout<< "Receiver stopped, waiting for new stream" << endl;
|
||||
zmqSocket->Disconnect();
|
||||
zmqSocket->Connect();
|
||||
}
|
||||
else {
|
||||
|
||||
// if (((icount++)%10)==0) cout <<"recived frameindex "<<zHeader.frameIndex <<endl;
|
||||
//cout <<"there" <<endl;
|
||||
zmqSocket->ReceiveData(0, (char *)(&image_data), NCH*2);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
framesinstream++;
|
||||
running++;
|
||||
|
||||
fill1Ds=true; //alway fill 1d and LR plots
|
||||
//if (((framesinstream%(int(HDraw_every)))==(int (HDraw_every)-1))) {fill1Ds=true;}else{fill1Ds=false;}
|
||||
if (((framesinstream%(HDraw_every))==(HDraw_every)-1)) {show2Ds=true;}else{show2Ds=false;}
|
||||
if (((framesinstream%NPRI)==NPRI-1)) { cout<<"\r "<<"frame (from start): "<<framesinstream<<" " << runc[((running/NPRI)%5)]<< " discarded frames %=" << (1-float(processedf)/float(zHeader.frameIndex-frameIndex_old))*100 << " current framenumber= " <<zHeader.frameIndex << " "<<std::flush; processedf=0;frameIndex_old=zHeader.frameIndex;}
|
||||
|
||||
|
||||
npacket=0;
|
||||
if (show2Ds) {
|
||||
his1000->Reset();
|
||||
his2000->Reset();
|
||||
if (!dophotonmap) his3000->Reset(); //FOR RAW ADC DISPLAY
|
||||
}
|
||||
|
||||
|
||||
if ((fill1Ds)or(show2Ds)or(dophotonmap)) { // do something, otherwise skip to the next
|
||||
processedf++;
|
||||
|
||||
for (i=0 ;i<NCH;i++) {
|
||||
|
||||
adcvalue= (image_data[i]) & 0x3fff;
|
||||
|
||||
if ((image_data[i] & 0xc000)!=0){ gain = (image_data[i]>>14) & 0x3;} else {gain=0;}
|
||||
if (pede_flag){
|
||||
|
||||
if (gain_flag)
|
||||
{
|
||||
if ((gain==0)||(!hasallpede)) adcpedecorr=(adcvalue&0x3fff)*fgaind[i]-fpeded[i]*fgaind[i];
|
||||
|
||||
if ((gain==1)&&hasallpede) adcpedecorr=(fpedeG1d[i]*fgaind[i]+G1Poffset-adcvalue*fgaind[i])*30.0;
|
||||
if ((gain==3)&&hasallpede) adcpedecorr=(fpedeG2d[i]*fgaind[i]+G2Poffset-adcvalue*fgaind[i])*340.0;
|
||||
}
|
||||
else
|
||||
|
||||
{
|
||||
|
||||
if ((gain==0)||(!hasallpede)) adcpedecorr=(adcvalue&0x3fff)-fpeded[i];
|
||||
if ((gain==1)&&hasallpede) adcpedecorr=(fpedeG1d[i]+G1Poffset-adcvalue)*30.0;
|
||||
if ((gain==3)&&hasallpede) adcpedecorr=(fpedeG2d[i]+G2Poffset-adcvalue)*340.0;
|
||||
}
|
||||
|
||||
|
||||
} else {adcpedecorr=float (adcvalue);} //end of if pede
|
||||
|
||||
|
||||
|
||||
|
||||
if ((adcpedecorr>threshold)&&(pede_flag)) hchptr[(i)]= hchptr[(i)]+(int)((adcpedecorr+threshold)/phene);
|
||||
|
||||
|
||||
if (fill1Ds) {
|
||||
if (((i%1024)<1004)&&((i%1024)>20)&&((i/1024)>20)) { //skip the pix near guardring for PH plots
|
||||
ichip= i/(256*256*4)*4+((i/256)%4) ;
|
||||
|
||||
hchip[ichip]->Fill(adcpedecorr,1);
|
||||
|
||||
if (((i%256)<253)&&((i%256)>2)) his4500->Fill(adcpedecorrold,adcpedecorr,1);
|
||||
adcpedecorrold=adcpedecorr;
|
||||
|
||||
|
||||
}
|
||||
}//if (fill1Ds)
|
||||
|
||||
|
||||
|
||||
|
||||
if ((show2Ds)) {
|
||||
factor=2.0;
|
||||
value=adcpedecorr;
|
||||
if ((i%256==0)||(i%256==255)) value=int(value/factor);
|
||||
if ((i/1024==255)||(i/1024==256)||(i/1024==767)||(i/1024==768)) value=int(value/factor);
|
||||
|
||||
his1000->Fill(float(i%1024),float(int (i/1024)),value);
|
||||
|
||||
if (!dophotonmap) his3000->Fill(float(i%1024),float(int (i/1024)) ,adcvalue);
|
||||
|
||||
his2000->Fill(float(i%1024),float(int (i/1024)) ,gain);
|
||||
|
||||
value=(int)(hchptr[i]);
|
||||
|
||||
if ((i%256==0)||(i%256==255)) value=int(value/factor);
|
||||
if ((i/1024==255)||(i/1024==256)||(i/1024==767)||(i/1024==768)) value=int(value/factor);
|
||||
if (dophotonmap) his3000->Fill(float(i%1024),float(int (i/1024)),float(value));
|
||||
|
||||
}
|
||||
}// for (i=0 ;i<NCH-0;i++)
|
||||
}// /end of do something
|
||||
|
||||
|
||||
|
||||
if ((show2Ds)) {
|
||||
|
||||
for (ipx=0;ipx<NCH;ipx++) hchptr[(ipx)]=0;
|
||||
|
||||
|
||||
|
||||
Plot2DHistos(); Plot1DHistos();
|
||||
}
|
||||
|
||||
|
||||
ifp=kbhit();
|
||||
processifp(ifp);
|
||||
|
||||
if (((framesinstream%NPRO))==NPRO-1) gSystem->ProcessEvents();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}// end of infinite loop
|
||||
|
||||
rootapp->Run();
|
||||
nonblock(NB_DISABLE);
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
void processifp(int ifp){
|
||||
|
||||
if (ifp!=0){
|
||||
c=fgetc(stdin);
|
||||
if (c=='s') {if (goout==0){goout=1;}else {myloop();}}
|
||||
if (c=='S') SetRanges();
|
||||
if (c=='+') { HDraw_every=HDraw_every*0.8;cout<< endl <<"Drawing every "<< HDraw_every<<" frames "<<endl; }
|
||||
if (c=='-') { HDraw_every=HDraw_every*1.25;cout<< endl <<"Drawing every "<< HDraw_every<<" frames "<<endl;}
|
||||
if (c=='G') {gain_flag=not gain_flag ;if (gain_flag) {cout<<"gain corr enab."<< endl;}else {cout<<"gain corr disab."<< endl;}}
|
||||
if (c=='[') { G1Poffset=G1Poffset-10;cout<< endl <<"G1Poffset "<<G1Poffset<<endl; }
|
||||
if (c==']') { G1Poffset=G1Poffset+10;cout<< endl <<"G1Poffset "<<G1Poffset<<endl; }
|
||||
if (c=='{') { G2Poffset=G2Poffset-10;cout<< endl <<"G2Poffset "<<G2Poffset<<endl; }
|
||||
if (c=='}') { G2Poffset=G2Poffset+10;cout<< endl <<"G2Poffset "<<G2Poffset<<endl; }
|
||||
if (c=='p') { //stopsocket();
|
||||
loadpede();//startsocket();
|
||||
}
|
||||
if (c=='b') {LoadPaletteBW(1.1111);bw_flag=true; }
|
||||
if (c=='B') {LoadPaletteBW(0.9);bw_flag=true; }
|
||||
if (c=='O') savepede();
|
||||
if (c=='o') readpede();
|
||||
if (c=='P') loadallpede();
|
||||
if (c=='u') his1000->SetOption("surf2z");
|
||||
if (c=='C') his1000->SetOption("colz");
|
||||
|
||||
if (c=='q') exit(0);
|
||||
if (c=='r') historeset();
|
||||
if (c=='R') axisreset();
|
||||
}
|
||||
|
||||
}
|
||||
void loadallpede(){
|
||||
cout <<"not implemented "<< endl;
|
||||
// hasallpede=true;
|
||||
|
||||
// system("./sls_detector_put setbit 0x5d 12 "); //setting to FSG1 ;
|
||||
|
||||
// loadpede();
|
||||
// loadpede();
|
||||
// for (i=0;i<NCH;i++) {fpedeG1d[i]=fpeded[i];}
|
||||
|
||||
// system("./sls_detector_put setbit 0x5d 13 "); //setting to FSG0 ;
|
||||
// sleep(1);
|
||||
// loadpede();
|
||||
// loadpede();
|
||||
// for (i=0;i<NCH;i++) {fpedeG2d[i]=fpeded[i];}
|
||||
// system("./sls_detector_put clearbit 0x5d 12 "); //setting to G0;
|
||||
// system("./sls_detector_put clearbit 0x5d 13 "); //setting to G0;
|
||||
// sleep(2);
|
||||
|
||||
// loadpede();
|
||||
// loadpede();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
void loadpede(void){
|
||||
//startsocket();
|
||||
framesinstream=0;
|
||||
pede_flag=true;
|
||||
nframes=0;
|
||||
|
||||
|
||||
|
||||
for (ipx=0;ipx<NCH;ipx++) fpeded[ipx]=0;
|
||||
|
||||
|
||||
|
||||
while (framesinstream<50) { // loop on files
|
||||
|
||||
|
||||
if (!zmqSocket->ReceiveHeader(0,zHeader, SLS_DETECTOR_JSON_HEADER_VERSION)){
|
||||
return;
|
||||
}
|
||||
|
||||
cout <<"received frameindex "<<zHeader.frameIndex << endl;
|
||||
|
||||
zmqSocket->ReceiveData(0, (char *)(&image_data), NCH*2);
|
||||
framesinstream++;nframes++;
|
||||
for (ipx=0;ipx<NCH;ipx++) fpeded[ipx]=(fpeded[ipx]*(nframes-1)+(float)(image_data[ipx]&0x3fff))/(float)(nframes);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
for (ipx=0;ipx<NCH;ipx++) { ipeded[ipx]=(short)(fpeded[ipx]);
|
||||
if (ipx%60033==0) printf("i=%d pede= %d %f .\n",ipx, ipeded[ipx],fpeded[ipx]);
|
||||
}
|
||||
printf("total frames for pede: %d \n",nframes);
|
||||
//stopsocket();
|
||||
|
||||
printhelp();
|
||||
}
|
||||
|
||||
int kbhit()
|
||||
{
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(STDIN_FILENO, &fds); //STDIN_FILENO is 0
|
||||
select(STDIN_FILENO+1, &fds, NULL, NULL, &tv);
|
||||
return FD_ISSET(STDIN_FILENO, &fds);
|
||||
}
|
||||
void myloop(void){ //wait doing nothing.
|
||||
goout=0;
|
||||
int ifp;
|
||||
|
||||
|
||||
while (goout==0){
|
||||
|
||||
ifp=kbhit();
|
||||
processifp(ifp);
|
||||
|
||||
|
||||
gSystem->ProcessEvents();
|
||||
usleep(5000);
|
||||
|
||||
}
|
||||
}
|
||||
void printhelp(){
|
||||
cout<< endl << "s=start/pause| p/n=getnewpede/raw | o/O=read/save pede | n=nopede(raw) | r/R=rst His/Axis | +/- = faster/slower ref. |q=exit | U/C sUrf2/Colz " <<endl;
|
||||
}
|
||||
|
||||
void historeset(){
|
||||
|
||||
his4500->Reset();
|
||||
his3000->Reset();
|
||||
for (i=0;i<8;i++) {
|
||||
hchip[i]->Reset();
|
||||
|
||||
}
|
||||
Plot2DHistos();
|
||||
Plot1DHistos();
|
||||
|
||||
}
|
||||
|
||||
void SetRanges() {
|
||||
string str;
|
||||
std::cin.clear();
|
||||
//cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
|
||||
cout<< endl;
|
||||
cout<< " adc min " <<endl;
|
||||
//getline(cin, str);
|
||||
// adcmin= stoi(str);
|
||||
std::cin >> adcmin;
|
||||
cout<< " adc max " <<endl;
|
||||
std::cin >> adcmax;
|
||||
cout<< " p.map min " <<endl;
|
||||
std::cin >> pmmin;
|
||||
cout<< " p.map max " <<endl;
|
||||
std::cin >> pmmax;
|
||||
|
||||
fixranges=true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void axisreset(){
|
||||
fixranges=false;
|
||||
his1000->GetXaxis()->UnZoom();
|
||||
|
||||
his1000->GetYaxis()->UnZoom();
|
||||
his1000->GetZaxis()->UnZoom();
|
||||
his2000->GetXaxis()->UnZoom();
|
||||
his2000->GetYaxis()->UnZoom();
|
||||
|
||||
his3000->GetZaxis()->UnZoom();
|
||||
|
||||
for (i=0;i<8;i++) {
|
||||
hchip[i]->GetXaxis()->UnZoom();
|
||||
hchip[i]->GetYaxis()->UnZoom();
|
||||
}
|
||||
|
||||
his4500->GetXaxis()->UnZoom();
|
||||
his4500->GetYaxis()->UnZoom();
|
||||
his4500->GetZaxis()->UnZoom();
|
||||
|
||||
Plot2DHistos();
|
||||
Plot1DHistos();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void nonblock(int state)
|
||||
{
|
||||
struct termios ttystate;
|
||||
//get the terminal state
|
||||
tcgetattr(STDIN_FILENO, &ttystate);
|
||||
if (state==NB_ENABLE)
|
||||
{
|
||||
//turn off canonical mode
|
||||
ttystate.c_lflag &= ~ICANON;
|
||||
//minimum of number input read.
|
||||
ttystate.c_cc[VMIN] = 1;
|
||||
}
|
||||
else if (state==NB_DISABLE)
|
||||
{ //turn on canonical mode
|
||||
ttystate.c_lflag |= ICANON;
|
||||
}
|
||||
//set the terminal attributes.
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
|
||||
}
|
||||
|
||||
|
||||
void LoadPaletteFalse(){
|
||||
const Int_t NRGBs = 5;
|
||||
const Int_t NCont = 90;
|
||||
|
||||
Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
|
||||
Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
|
||||
Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
|
||||
Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
|
||||
TColor::CreateGradientColorTable(NRGBs, stops, red,green, blue, NCont);
|
||||
gStyle->SetNumberContours(NCont);
|
||||
TColor::CreateGradientColorTable(NRGBs, stops, red,green ,blue, NCont);
|
||||
gStyle->SetNumberContours(NCont);
|
||||
|
||||
}
|
||||
void LoadPaletteBW(float gammatune){
|
||||
|
||||
vgamma=vgamma*gammatune;
|
||||
cout<< "gamma is "<<vgamma<<endl;
|
||||
const Int_t NRGBs = 99;
|
||||
const Int_t NCont = 990;
|
||||
Double_t stops[NRGBs] ;
|
||||
Double_t red[NRGBs] ;
|
||||
Double_t green[NRGBs];
|
||||
Double_t blue[NRGBs] ;
|
||||
|
||||
for (int iRGB=0;iRGB<NRGBs;iRGB++){
|
||||
|
||||
|
||||
stops[iRGB] =(1/float(NRGBs)*float(iRGB));
|
||||
red[iRGB] = pow(stops[iRGB],vgamma);
|
||||
green[iRGB] = red[iRGB];
|
||||
blue[iRGB] =red[iRGB];
|
||||
// cout << iRGB<<" "<< stops[iRGB] <<" " << red[iRGB]<<endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
|
||||
gStyle->SetNumberContours(NCont);
|
||||
|
||||
|
||||
|
||||
// TColor::SetPalette(52,0,1);
|
||||
|
||||
}
|
||||
|
||||
void Plot1DHistos(void){
|
||||
|
||||
if (hchip[0]->GetXaxis()->GetLast()!=oldh0xlast){
|
||||
oldh0xlast=hchip[0]->GetXaxis()->GetLast();
|
||||
oldh0xfirst=hchip[0]->GetXaxis()->GetFirst();
|
||||
for (int ipad=1; ipad<8;ipad++) {
|
||||
hchip[ipad]->GetXaxis()->SetRange(oldh0xfirst,oldh0xlast);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int ipad=0; ipad<8;ipad++) {
|
||||
A4->cd(ipad+1);
|
||||
gStyle->SetOptStat(1); gPad->SetLogy();
|
||||
hchip[ipad%4+(1-int(ipad/4))*4]->Draw();
|
||||
|
||||
}
|
||||
A4->cd();
|
||||
A4->Update();
|
||||
}
|
||||
|
||||
|
||||
void Plot2DHistos(void){
|
||||
gStyle->SetOptStat(0);
|
||||
A3->cd();
|
||||
|
||||
// if (bw_flag) LoadPaletteBW(1.0);
|
||||
|
||||
if (fixranges) {
|
||||
|
||||
his1000->GetZaxis()->SetRangeUser(float(adcmin),float(adcmax));
|
||||
his3000->GetZaxis()->SetRangeUser(float(pmmin),float(pmmax));
|
||||
|
||||
|
||||
}
|
||||
|
||||
his1000->SetMinimum(-200);
|
||||
his1000->Draw();
|
||||
|
||||
A3->Update();
|
||||
A2->cd();
|
||||
// if (bw_flag) LoadPaletteFalse();
|
||||
his2000->GetXaxis()->SetRange(his1000->GetXaxis()->GetFirst(),his1000->GetXaxis()->GetLast());
|
||||
his2000->GetYaxis()->SetRange(his1000->GetYaxis()->GetFirst(),his1000->GetYaxis()->GetLast());
|
||||
|
||||
his2000->Draw("colz");
|
||||
A2->Update();
|
||||
A5->cd();
|
||||
|
||||
his3000->GetXaxis()->SetRange(his1000->GetXaxis()->GetFirst(),his1000->GetXaxis()->GetLast());
|
||||
his3000->GetYaxis()->SetRange(his1000->GetYaxis()->GetFirst(),his1000->GetYaxis()->GetLast());
|
||||
his3000->Draw("colz");
|
||||
A5->Update();
|
||||
|
||||
A6->cd();
|
||||
his4500->Draw("colz");
|
||||
A6->Update();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void startsocket(void) {
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
zmqSocket = new sls::ZmqSocket(serverip, portnum);
|
||||
|
||||
} catch (...) {
|
||||
cprintf(RED,
|
||||
"Error: Could not create Zmq socket on port %d with ip %s\n",
|
||||
portnum, serverip);
|
||||
delete zmqSocket;
|
||||
return;
|
||||
}
|
||||
zmqSocket->SetReceiveHighWaterMark(3);
|
||||
zmqSocket->SetReceiveBuffer(1024*1024);
|
||||
zmqSocket->Connect();
|
||||
|
||||
|
||||
cout<<"Zmq Client[] "<< zmqSocket->GetZmqServerAddress()<<endl;
|
||||
|
||||
|
||||
haveconnection=true;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void tryconnect(void)
|
||||
|
||||
{
|
||||
int itry=0;
|
||||
cout<< endl;
|
||||
|
||||
|
||||
|
||||
while (haveconnection==false) {
|
||||
sleep(1);
|
||||
cout<<"\r trying to (re)connect " <<itry++ << " " << endl ;
|
||||
startsocket();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void stopsocket(void) {
|
||||
// cout<<" cfd " << cfd << endl;;
|
||||
|
||||
|
||||
|
||||
delete zmqSocket;
|
||||
zmqSocket=0;
|
||||
//zmqSocket->~ZmqSocket ();
|
||||
|
||||
|
||||
|
||||
haveconnection=false;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
void savepede(void) {
|
||||
|
||||
int pfd;
|
||||
|
||||
pfd=open(PEDEFNAME,O_CREAT|O_WRONLY, 0666);
|
||||
if (pfd==-1) perror("open pede file");
|
||||
|
||||
write(pfd,fpeded,2*NCH*sizeof(float));
|
||||
write(pfd,fpedeG1d,2*NCH*sizeof(float));
|
||||
write(pfd,fpedeG2d,2*NCH*sizeof(float));
|
||||
close(pfd);
|
||||
|
||||
}
|
||||
|
||||
void readpede(void) {
|
||||
|
||||
int pfd;
|
||||
|
||||
pfd=open(PEDEFNAME,O_RDONLY);
|
||||
if (pfd==-1) perror("open pede file");
|
||||
|
||||
read(pfd,fpeded,NCH*2*sizeof(float));
|
||||
read(pfd,fpedeG1d,NCH*2*sizeof(float));
|
||||
read(pfd,fpedeG2d,NCH*2*sizeof(float));
|
||||
|
||||
close(pfd);
|
||||
pede_flag=true;
|
||||
hasallpede=true;
|
||||
|
||||
}
|
||||
|
204
slsDetectorCalibration/jungfrauExecutables/onlinedisp_zmq.h
Normal file
204
slsDetectorCalibration/jungfrauExecutables/onlinedisp_zmq.h
Normal file
@ -0,0 +1,204 @@
|
||||
|
||||
/**************************************************************************/
|
||||
/* Header files section needs cleanup */
|
||||
/**************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include "sls/ZmqSocket.h"
|
||||
|
||||
#include "sls/tiffIO.h"
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdlib.h> /* exit() */
|
||||
#include <string.h> /* memset(), memcpy() */
|
||||
#include <sys/utsname.h> /* uname() */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h> /* socket(), bind(),
|
||||
listen(), accept() */
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h> /* fork(), write(), close() */
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <cmath>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <rapidjson/document.h> //json header in zmq stream
|
||||
#include <omp.h>
|
||||
#define NTHREADS 2
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <ctime> // time_t
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
using namespace sls;
|
||||
|
||||
#include "TCanvas.h"
|
||||
#include "TH1F.h"
|
||||
#include "TF1.h"
|
||||
#include "TH2F.h"
|
||||
#include "TMath.h"
|
||||
#include "TFile.h"
|
||||
#include "TStyle.h"
|
||||
#include "TSystem.h"
|
||||
#include "TTimer.h"
|
||||
#include "TProfile.h"
|
||||
#include "TColor.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <termios.h>
|
||||
#include <TApplication.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "sls/ansi.h"
|
||||
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x4
|
||||
|
||||
#define PI 3.14159265
|
||||
|
||||
#define FALSE 0
|
||||
#define OFFSET 0
|
||||
#define NBIN 500
|
||||
#define MIN_POS -500.5 // 400.5
|
||||
#define MAX_POS 3499.5 //-100.5
|
||||
|
||||
|
||||
#define NCH 524288
|
||||
// #define NCH 262144 in case of half_frames
|
||||
|
||||
char serverip[256];
|
||||
int portnum;
|
||||
FILE * sfilefd;
|
||||
|
||||
short* hchptr; // photon counted map "histogram"
|
||||
int value;
|
||||
float factor=1.84;
|
||||
int npacket=0;
|
||||
int totalnpacket=0;
|
||||
float vgamma;
|
||||
|
||||
struct sockaddr_in serveraddr;
|
||||
struct sockaddr_in clientaddr;
|
||||
struct in_addr inadr;
|
||||
struct hostent *server;
|
||||
|
||||
int i=0;
|
||||
int ipx=0;
|
||||
bool haveconnection;
|
||||
|
||||
|
||||
TStyle *gStyle;
|
||||
TApplication* rootapp;
|
||||
TCanvas *A2;
|
||||
TCanvas *A3;
|
||||
TCanvas *A4;
|
||||
TCanvas *A5;
|
||||
TCanvas *A6;
|
||||
|
||||
TH1I **hchip;
|
||||
TH2F **h4500chip;
|
||||
short image_data[NCH*2];
|
||||
short imaged[NCH*2];
|
||||
float fpeded[NCH*2];
|
||||
float fpedeG2d[NCH*2];
|
||||
float fpedeG1d[NCH*2];
|
||||
short ipeded[NCH*2];
|
||||
short pcimaged[NCH*2];
|
||||
|
||||
float fgaind[NCH*2];
|
||||
|
||||
|
||||
float adcpedecorr,adcpedecorrold;
|
||||
|
||||
bool gain_flag;
|
||||
bool bw_flag;
|
||||
bool fill2Ds;
|
||||
bool show2Ds;
|
||||
bool fill1Ds;
|
||||
bool pede_flag;
|
||||
bool dophotonmap;
|
||||
|
||||
int nx, ny;
|
||||
int nframes;
|
||||
int goout;
|
||||
int framesinstream;
|
||||
int ifp;
|
||||
float threshold;
|
||||
int phene;
|
||||
int adcvalue;
|
||||
int gain;
|
||||
int ichip;
|
||||
int frameIndex_old;
|
||||
|
||||
char pedefilename[128];
|
||||
int framenum,bunchid;
|
||||
|
||||
TH2F* his1000;
|
||||
TH2F* his2000;
|
||||
TH2F* his3000;
|
||||
TH2F* his4500;
|
||||
TH1I* hproj;
|
||||
TH1I* hchcum;
|
||||
|
||||
|
||||
using namespace std;
|
||||
void printhelp(void);
|
||||
void processifp(int ifp);
|
||||
void historeset(void);
|
||||
void SetRanges(void);
|
||||
void startsocket(void);
|
||||
void stopsocket(void);
|
||||
void axisreset(void);
|
||||
int kbhit(void);
|
||||
void myloop(void);
|
||||
void loadpede(void);
|
||||
void loadallpede(void);
|
||||
void loadgain(void);
|
||||
void nonblock(int state);
|
||||
void LoadPaletteFalse(void);
|
||||
void LoadPaletteBW(float);
|
||||
void Plot1DHistos(void);
|
||||
void Plot2DHistos(void);
|
||||
void savepede(void);
|
||||
void readpede(void);
|
||||
int findinterpoindex(int startindex);
|
||||
int findclumax(int startindex);
|
||||
void tryconnect(void) ;
|
||||
|
||||
#define NB_ENABLE 1
|
||||
#define NB_DISABLE 0
|
||||
char c;
|
||||
int HDraw_every;
|
||||
|
||||
|
||||
float oldh0xfirst,oldh0xlast;
|
||||
int idx;
|
||||
int GXPoffset,G1Poffset,G2Poffset;
|
||||
int ix,iy;
|
||||
int adcmin,adcmax;
|
||||
int pmmin,pmmax; //min/mnx for the photon map
|
||||
bool fixranges;
|
||||
|
||||
|
||||
sls::ZmqSocket *zmqSocket= NULL;
|
@ -59,6 +59,7 @@ class qDrawPlot : public QWidget, private Ui::PlotObject {
|
||||
void ClonePlot();
|
||||
void SavePlot();
|
||||
void SetGapPixels(bool enable);
|
||||
void UpdatePlot();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
@ -67,7 +68,7 @@ class qDrawPlot : public QWidget, private Ui::PlotObject {
|
||||
void Zoom1DGainPlot(const QRectF &rect);
|
||||
void Zoom2DGainPlot(const QRectF &rect);
|
||||
void SetSaveFileName(QString val);
|
||||
void UpdatePlot();
|
||||
// void UpdatePlot();
|
||||
|
||||
signals:
|
||||
void AcquireFinishedSignal();
|
||||
|
@ -487,6 +487,7 @@ void qTabPlot::SetXYRange() {
|
||||
}
|
||||
|
||||
plot->SetXYRangeChanged(disablezoom, xyRange, isRange);
|
||||
plot->UpdatePlot();
|
||||
emit DisableZoomSignal(disablezoom);
|
||||
}
|
||||
|
||||
@ -624,6 +625,7 @@ void qTabPlot::SetZRange() {
|
||||
zRange[1] = val;
|
||||
}
|
||||
plot->SetZRange(zRange, isZRange);
|
||||
plot->UpdatePlot();
|
||||
}
|
||||
|
||||
void qTabPlot::GetStreamingFrequency() {
|
||||
|
@ -519,19 +519,18 @@ void DetectorImpl::setTransmissionDelay(int step) {
|
||||
f.get();
|
||||
}
|
||||
|
||||
int DetectorImpl::destroyReceivingDataSockets() {
|
||||
void DetectorImpl::destroyReceivingDataSockets() {
|
||||
LOG(logINFO) << "Going to destroy data sockets";
|
||||
// close socket
|
||||
zmqSocket.clear();
|
||||
|
||||
client_downstream = false;
|
||||
LOG(logINFO) << "Destroyed Receiving Data Socket(s)";
|
||||
return OK;
|
||||
}
|
||||
|
||||
int DetectorImpl::createReceivingDataSockets() {
|
||||
void DetectorImpl::createReceivingDataSockets() {
|
||||
if (client_downstream) {
|
||||
return OK;
|
||||
return;
|
||||
}
|
||||
LOG(logINFO) << "Going to create data sockets";
|
||||
|
||||
@ -558,24 +557,22 @@ int DetectorImpl::createReceivingDataSockets() {
|
||||
int hwm = shm()->zmqHwm;
|
||||
if (hwm >= 0) {
|
||||
zmqSocket[iSocket]->SetReceiveHighWaterMark(hwm);
|
||||
if (zmqSocket[iSocket]->GetReceiveHighWaterMark() != hwm) {
|
||||
throw ZmqSocketError("Could not set zmq rcv hwm to " +
|
||||
std::to_string(hwm));
|
||||
}
|
||||
// need not reconnect. cannot be connected (detector idle)
|
||||
}
|
||||
LOG(logINFO) << "Zmq Client[" << iSocket << "] at "
|
||||
<< zmqSocket.back()->GetZmqServerAddress() << "[hwm: "
|
||||
<< zmqSocket.back()->GetReceiveHighWaterMark() << "]";
|
||||
} catch (...) {
|
||||
LOG(logERROR) << "Could not create Zmq socket on port " << portnum;
|
||||
} catch (std::exception &e) {
|
||||
destroyReceivingDataSockets();
|
||||
return FAIL;
|
||||
std::ostringstream oss;
|
||||
oss << "Could not create zmq sub socket on port " << portnum;
|
||||
oss << " [" << e.what() << ']';
|
||||
throw RuntimeError(oss.str());
|
||||
}
|
||||
}
|
||||
|
||||
client_downstream = true;
|
||||
LOG(logINFO) << "Receiving Data Socket(s) created";
|
||||
return OK;
|
||||
}
|
||||
|
||||
void DetectorImpl::readFrameFromReceiver() {
|
||||
@ -1115,9 +1112,7 @@ void DetectorImpl::setDataStreamingToClient(bool enable) {
|
||||
destroyReceivingDataSockets();
|
||||
// create data threads
|
||||
} else {
|
||||
if (createReceivingDataSockets() == FAIL) {
|
||||
throw RuntimeError("Could not create data threads in client.");
|
||||
}
|
||||
createReceivingDataSockets();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1150,11 +1145,7 @@ void DetectorImpl::setClientStreamingHwm(const int limit) {
|
||||
if (limit >= 0) {
|
||||
for (auto &it : zmqSocket) {
|
||||
it->SetReceiveHighWaterMark(limit);
|
||||
if (it->GetReceiveHighWaterMark() != limit) {
|
||||
shm()->zmqHwm = -1;
|
||||
throw ZmqSocketError("Could not set zmq rcv hwm to " +
|
||||
std::to_string(limit));
|
||||
}
|
||||
// need not reconnect. cannot be connected (detector idle)
|
||||
}
|
||||
LOG(logINFO) << "Setting Client Zmq socket rcv hwm to " << limit;
|
||||
}
|
||||
|
@ -349,8 +349,8 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
||||
|
||||
void updateDetectorSize();
|
||||
|
||||
int destroyReceivingDataSockets();
|
||||
int createReceivingDataSockets();
|
||||
void destroyReceivingDataSockets();
|
||||
void createReceivingDataSockets();
|
||||
|
||||
/**
|
||||
* Reads frames from receiver through a constant socket
|
||||
|
@ -87,19 +87,18 @@ void DataStreamer::CreateZmqSockets(uint32_t port, const IpAddr ip, int hwm) {
|
||||
std::string sip = ip.str();
|
||||
try {
|
||||
zmqSocket = new ZmqSocket(portnum, (ip != 0 ? sip.c_str() : nullptr));
|
||||
|
||||
// set if custom
|
||||
if (hwm >= 0) {
|
||||
zmqSocket->SetSendHighWaterMark(hwm);
|
||||
if (zmqSocket->GetSendHighWaterMark() != hwm) {
|
||||
throw RuntimeError(
|
||||
"Could not set zmq send high water mark to " +
|
||||
std::to_string(hwm));
|
||||
}
|
||||
// needed, or HWL is not taken
|
||||
zmqSocket->Rebind();
|
||||
}
|
||||
} catch (...) {
|
||||
LOG(logERROR) << "Could not create Zmq socket on port " << portnum
|
||||
<< " for Streamer " << index;
|
||||
throw;
|
||||
} catch (std::exception &e) {
|
||||
std::ostringstream oss;
|
||||
oss << "Could not create zmq pub socket on port " << portnum;
|
||||
oss << " [" << e.what() << ']';
|
||||
throw RuntimeError(oss.str());
|
||||
}
|
||||
LOG(logINFO) << index << " Streamer: Zmq Server started at "
|
||||
<< zmqSocket->GetZmqServerAddress()
|
||||
|
@ -31,6 +31,10 @@ namespace sls {
|
||||
// #define ZMQ_DETAIL
|
||||
#define ROIVERBOSITY
|
||||
|
||||
// high water mark for gui
|
||||
#define DEFFAULT_LOW_HWM (25)
|
||||
#define DEFAULT_LOW_HWM_BUFFERSIZE (1024 * 1024) // 1MB
|
||||
|
||||
/** zmq header structure */
|
||||
struct zmqHeader {
|
||||
/** true if incoming data, false if end of acquisition */
|
||||
@ -108,15 +112,29 @@ class ZmqSocket {
|
||||
/** Returns high water mark for outbound messages */
|
||||
int GetSendHighWaterMark();
|
||||
|
||||
/** Sets high water mark for outbound messages. Default 1000 (zmqlib) */
|
||||
/** Sets high water mark for outbound messages. Default 1000 (zmqlib). Also
|
||||
* changes send buffer size depending on low hwm. Must rebind. */
|
||||
void SetSendHighWaterMark(int limit);
|
||||
|
||||
/** Returns high water mark for inbound messages */
|
||||
int GetReceiveHighWaterMark();
|
||||
|
||||
/** Sets high water mark for inbound messages. Default 1000 (zmqlib) */
|
||||
/** Sets high water mark for inbound messages. Default 1000 (zmqlib). Also
|
||||
* changes receiver buffer size depending on low hwm. Must reconnect */
|
||||
void SetReceiveHighWaterMark(int limit);
|
||||
|
||||
/** Gets kernel buffer for outbound messages. Default 0 (os) */
|
||||
int GetSendBuffer();
|
||||
|
||||
/** Sets kernel buffer for outbound messages. Default 0 (os) */
|
||||
void SetSendBuffer(int limit);
|
||||
|
||||
/** Gets kernel buffer for inbound messages. Default 0 (os) */
|
||||
int GetReceiveBuffer();
|
||||
|
||||
/** Sets kernel buffer for inbound messages. Default 0 (os) */
|
||||
void SetReceiveBuffer(int limit);
|
||||
|
||||
/**
|
||||
* Returns Port Number
|
||||
* @returns Port Number
|
||||
@ -129,6 +147,9 @@ class ZmqSocket {
|
||||
*/
|
||||
std::string GetZmqServerAddress() { return sockfd.serverAddress; }
|
||||
|
||||
/** unbinds and rebind, to apply changes of HWM */
|
||||
void Rebind();
|
||||
|
||||
/**
|
||||
* Connect client socket to server socket
|
||||
* @returns 1 for fail, 0 for success
|
||||
|
@ -102,6 +102,13 @@ void ZmqSocket::SetSendHighWaterMark(int limit) {
|
||||
PrintError();
|
||||
throw ZmqSocketError("Could not set ZMQ_SNDHWM");
|
||||
}
|
||||
if (GetSendHighWaterMark() != limit) {
|
||||
throw ZmqSocketError("Could not set ZMQ_SNDHWM to " +
|
||||
std::to_string(limit));
|
||||
}
|
||||
if (limit < DEFFAULT_LOW_HWM) {
|
||||
SetSendBuffer(DEFAULT_LOW_HWM_BUFFERSIZE);
|
||||
}
|
||||
}
|
||||
|
||||
int ZmqSocket::GetReceiveHighWaterMark() {
|
||||
@ -110,7 +117,7 @@ int ZmqSocket::GetReceiveHighWaterMark() {
|
||||
if (zmq_getsockopt(sockfd.socketDescriptor, ZMQ_RCVHWM, &value,
|
||||
&value_size)) {
|
||||
PrintError();
|
||||
throw ZmqSocketError("Could not get ZMQ_SNDHWM");
|
||||
throw ZmqSocketError("Could not get ZMQ_RCVHWM");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@ -119,7 +126,75 @@ void ZmqSocket::SetReceiveHighWaterMark(int limit) {
|
||||
if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_RCVHWM, &limit,
|
||||
sizeof(limit))) {
|
||||
PrintError();
|
||||
throw ZmqSocketError("Could not set ZMQ_SNDHWM");
|
||||
throw ZmqSocketError("Could not set ZMQ_RCVHWM");
|
||||
}
|
||||
if (GetReceiveHighWaterMark() != limit) {
|
||||
throw ZmqSocketError("Could not set ZMQ_RCVHWM to " +
|
||||
std::to_string(limit));
|
||||
}
|
||||
if (limit < DEFFAULT_LOW_HWM) {
|
||||
SetReceiveBuffer(DEFAULT_LOW_HWM_BUFFERSIZE);
|
||||
}
|
||||
}
|
||||
|
||||
int ZmqSocket::GetSendBuffer() {
|
||||
int value = 0;
|
||||
size_t value_size = sizeof(value);
|
||||
if (zmq_getsockopt(sockfd.socketDescriptor, ZMQ_SNDBUF, &value,
|
||||
&value_size)) {
|
||||
PrintError();
|
||||
throw ZmqSocketError("Could not get ZMQ_SNDBUF");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void ZmqSocket::SetSendBuffer(int limit) {
|
||||
if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_SNDBUF, &limit,
|
||||
sizeof(limit))) {
|
||||
PrintError();
|
||||
throw ZmqSocketError("Could not set ZMQ_SNDBUF");
|
||||
}
|
||||
if (GetSendBuffer() != limit) {
|
||||
throw ZmqSocketError("Could not set ZMQ_SNDBUF to " +
|
||||
std::to_string(limit));
|
||||
}
|
||||
}
|
||||
|
||||
int ZmqSocket::GetReceiveBuffer() {
|
||||
int value = 0;
|
||||
size_t value_size = sizeof(value);
|
||||
if (zmq_getsockopt(sockfd.socketDescriptor, ZMQ_RCVBUF, &value,
|
||||
&value_size)) {
|
||||
PrintError();
|
||||
throw ZmqSocketError("Could not get ZMQ_RCVBUF");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void ZmqSocket::SetReceiveBuffer(int limit) {
|
||||
if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_RCVBUF, &limit,
|
||||
sizeof(limit))) {
|
||||
PrintError();
|
||||
throw ZmqSocketError("Could not set ZMQ_RCVBUF");
|
||||
}
|
||||
if (GetReceiveBuffer() != limit) {
|
||||
throw ZmqSocketError("Could not set ZMQ_RCVBUF to " +
|
||||
std::to_string(limit));
|
||||
}
|
||||
}
|
||||
|
||||
void ZmqSocket::Rebind() { // the purpose is to apply HWL changes, which are
|
||||
// frozen at bind, which is in the constructor.
|
||||
|
||||
// unbbind
|
||||
if (zmq_unbind(sockfd.socketDescriptor, sockfd.serverAddress.c_str())) {
|
||||
PrintError();
|
||||
throw ZmqSocketError("Could not unbind socket");
|
||||
}
|
||||
// bind address
|
||||
if (zmq_bind(sockfd.socketDescriptor, sockfd.serverAddress.c_str())) {
|
||||
PrintError();
|
||||
throw ZmqSocketError("Could not bind socket");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user