merge fix

This commit is contained in:
maliakal_d 2022-02-03 13:03:40 +01:00
commit bc4cf95d0e
39 changed files with 395 additions and 360 deletions

View File

@ -31,6 +31,8 @@ This document describes the differences between v6.1.0 and v6.0.0.
- rx_arping
- rx_threadsids max is now 9 (breaking api)
- fixed datastream disabling for eiger. Its only available in 10g mode.
- m3 server crash (vthrehsold)
2. Resolved Issues
==================

View File

@ -13,8 +13,8 @@ import subprocess
from parse import remove_comments
allow_bitwise_op = ["M3_GainCaps"]
allow_bitwise_op = ["streamingInterface"]
allow_bitwise_op = ["streamingInterface", "M3_GainCaps"]
op_key = {"operator|": "|",
"operator&" : "&"}

View File

@ -271,7 +271,7 @@ class Detector(CppDetectorApi):
@property
@element
def rx_arping(self):
"""Starts a thread in slsReceiver to ping the interface it is listening every minute. Useful in 10G mode. """
"""Starts a thread in slsReceiver to arping the interface it is listening every minute. Useful in 10G mode. """
return self.getRxArping()
@rx_arping.setter

View File

@ -273,7 +273,8 @@ void init_enums(py::module &m) {
slsDetectorDefs::timingSourceType::TIMING_EXTERNAL)
.export_values();
py::enum_<slsDetectorDefs::M3_GainCaps>(Defs, "M3_GainCaps")
py::enum_<slsDetectorDefs::M3_GainCaps>(Defs, "M3_GainCaps",
py::arithmetic())
.value("M3_C10pre", slsDetectorDefs::M3_GainCaps::M3_C10pre)
.value("M3_C15sh", slsDetectorDefs::M3_GainCaps::M3_C15sh)
.value("M3_C30sh", slsDetectorDefs::M3_GainCaps::M3_C30sh)

View File

@ -149,7 +149,7 @@ class interpolatingDetector : public singlePhotonDetector {
{
nph = addFrame(data, val, 1);
if (interp)
return interp->getFlatField();
return interp->getFlatFieldDistribution();
else
return NULL;
};

View File

@ -238,96 +238,96 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
// cout <<"******"<< etax << " " << etay << endl;
return addToFlatField(etax, etay);
return addToFlatFieldDistribution(etax, etay);
}
virtual int addToFlatField(double totquad, int quad, double *cl,
double &etax, double &etay) {
double cc[2][2];
int xoff = 0, yoff = 0;
/* virtual int addToFlatField(double totquad, int quad, double *cl, */
/* double &etax, double &etay) { */
/* double cc[2][2]; */
/* int xoff = 0, yoff = 0; */
switch (quad) {
case BOTTOM_LEFT:
xoff = 0;
yoff = 0;
break;
case BOTTOM_RIGHT:
xoff = 1;
yoff = 0;
break;
case TOP_LEFT:
xoff = 0;
yoff = 1;
break;
case TOP_RIGHT:
xoff = 1;
yoff = 1;
break;
default:;
}
cc[0][0] = cl[xoff + 3 * yoff];
cc[1][0] = cl[(yoff + 1) * 3 + xoff];
cc[0][1] = cl[yoff * 3 + xoff + 1];
cc[1][1] = cl[(yoff + 1) * 3 + xoff + 1];
/* switch (quad) { */
/* case BOTTOM_LEFT: */
/* xoff = 0; */
/* yoff = 0; */
/* break; */
/* case BOTTOM_RIGHT: */
/* xoff = 1; */
/* yoff = 0; */
/* break; */
/* case TOP_LEFT: */
/* xoff = 0; */
/* yoff = 1; */
/* break; */
/* case TOP_RIGHT: */
/* xoff = 1; */
/* yoff = 1; */
/* break; */
/* default:; */
/* } */
/* cc[0][0] = cl[xoff + 3 * yoff]; */
/* cc[1][0] = cl[(yoff + 1) * 3 + xoff]; */
/* cc[0][1] = cl[yoff * 3 + xoff + 1]; */
/* cc[1][1] = cl[(yoff + 1) * 3 + xoff + 1]; */
/* cout << cl[0] << " " << cl[1] << " " << cl[2] << endl; */
/* cout << cl[3] << " " << cl[4] << " " << cl[5] << endl; */
/* cout << cl[6] << " " << cl[7] << " " << cl[8] << endl; */
/* cout <<"******"<<totquad << " " << quad << endl; */
/* cout << cc[0][0]<< " " << cc[0][1] << endl; */
/* cout << cc[1][0]<< " " << cc[1][1] << endl; */
// calcMyEta(totquad,quad,cl,etax, etay);
calcEta(totquad, cc, etax, etay);
/* /\* cout << cl[0] << " " << cl[1] << " " << cl[2] << endl; *\/ */
/* /\* cout << cl[3] << " " << cl[4] << " " << cl[5] << endl; *\/ */
/* /\* cout << cl[6] << " " << cl[7] << " " << cl[8] << endl; *\/ */
/* /\* cout <<"******"<<totquad << " " << quad << endl; *\/ */
/* /\* cout << cc[0][0]<< " " << cc[0][1] << endl; *\/ */
/* /\* cout << cc[1][0]<< " " << cc[1][1] << endl; *\/ */
/* // calcMyEta(totquad,quad,cl,etax, etay); */
/* calcEta(totquad, cc, etax, etay); */
// cout <<"******"<< etax << " " << etay << endl;
/* // cout <<"******"<< etax << " " << etay << endl; */
return addToFlatField(etax, etay);
}
/* return addToFlatFieldDistribution(etax, etay); */
/* } */
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay) {
double sDum[2][2];
double tot, totquad;
// int corner;
// corner=
calcQuad(cluster, tot, totquad, sDum);
/* virtual int addToFlatField(double *cluster, double &etax, double &etay) { */
/* double sDum[2][2]; */
/* double tot, totquad; */
/* // int corner; */
/* // corner= */
/* calcQuad(cluster, tot, totquad, sDum); */
// double xpos_eta,ypos_eta;
// double dX,dY;
/* // double xpos_eta,ypos_eta; */
/* // double dX,dY; */
calcEta(totquad, sDum, etax, etay);
/* calcEta(totquad, sDum, etax, etay); */
return addToFlatField(etax, etay);
};
/* return addToFlatField(etax, etay); */
/* }; */
virtual int addToFlatField(int *cluster, double &etax, double &etay) {
double sDum[2][2];
double tot, totquad;
// int corner;
// corner=
calcQuad(cluster, tot, totquad, sDum);
/* virtual int addToFlatField(int *cluster, double &etax, double &etay) { */
/* double sDum[2][2]; */
/* double tot, totquad; */
/* // int corner; */
/* // corner= */
/* calcQuad(cluster, tot, totquad, sDum); */
// double xpos_eta,ypos_eta;
// double dX,dY;
/* // double xpos_eta,ypos_eta; */
/* // double dX,dY; */
calcEta(totquad, sDum, etax, etay);
/* calcEta(totquad, sDum, etax, etay); */
return addToFlatField(etax, etay);
};
/* return addToFlatField(etax, etay); */
/* }; */
virtual int addToFlatField(double etax, double etay) {
#ifdef MYROOT1
heta->Fill(etax, etay);
#endif
#ifndef MYROOT1
int ex, ey;
ex = (etax - etamin) / etastepX;
ey = (etay - etamin) / etastepY;
if (ey < nbetaY && ex < nbetaX && ex >= 0 && ey >= 0)
heta[ey * nbetaX + ex]++;
#endif
return 0;
};
/* virtual int addToFlatFieldDistribution(double etax, double etay) { */
/* #ifdef MYROOT1 */
/* heta->Fill(etax, etay); */
/* #endif */
/* #ifndef MYROOT1 */
/* int ex, ey; */
/* ex = (etax - etamin) / etastepX; */
/* ey = (etay - etamin) / etastepY; */
/* if (ey < nbetaY && ex < nbetaX && ex >= 0 && ey >= 0) */
/* heta[ey * nbetaX + ex]++; */
/* #endif */
/* return 0; */
/* }; */
virtual int *getInterpolatedImage() {
int ipx, ipy;

View File

@ -205,44 +205,44 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
double &etay) {
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax, etay);
return addToFlatFieldDistribution(etax, etay);
}
virtual int addToFlatField(double totquad, int quad, double *cl,
double &etax, double &etay) {
/* virtual int addToFlatField(double totquad, int quad, double *cl, */
/* double &etax, double &etay) { */
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax, etay);
}
/* calcEta3(cl, etax, etay, totquad); */
/* return addToFlatField(etax, etay); */
/* } */
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay) {
double totquad;
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax, etay);
};
/* virtual int addToFlatField(double *cluster, double &etax, double &etay) { */
/* double totquad; */
/* calcEta3(cluster, etax, etay, totquad); */
/* return addToFlatField(etax, etay); */
/* }; */
virtual int addToFlatField(int *cluster, double &etax, double &etay) {
/* virtual int addToFlatField(int *cluster, double &etax, double &etay) { */
double totquad;
/* double totquad; */
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax, etay);
};
/* calcEta3(cluster, etax, etay, totquad); */
/* return addToFlatField(etax, etay); */
/* }; */
virtual int addToFlatField(double etax, double etay) {
#ifdef MYROOT1
heta->Fill(etax, etay);
#endif
#ifndef MYROOT1
int ex, ey;
ex = (etax - etamin) / etastepX;
ey = (etay - etamin) / etastepY;
if (ey < nbetaY && ex < nbetaX && ex >= 0 && ey >= 0)
heta[ey * nbetaX + ex]++;
#endif
return 0;
};
/* virtual int addToFlatField(double etax, double etay) { */
/* #ifdef MYROOT1 */
/* heta->Fill(etax, etay); */
/* #endif */
/* #ifndef MYROOT1 */
/* int ex, ey; */
/* ex = (etax - etamin) / etastepX; */
/* ey = (etay - etamin) / etastepY; */
/* if (ey < nbetaY && ex < nbetaX && ex >= 0 && ey >= 0) */
/* heta[ey * nbetaX + ex]++; */
/* #endif */
/* return 0; */
/* }; */
/* protected: */

View File

@ -128,7 +128,7 @@ class etaInterpolationBase : public slsInterpolation {
return NULL;
};
int readFlatField(const char *imgname, double emin = 1, double emax = 0) {
void *readFlatField(const char *imgname, double emin = 1, double emax = 0) {
if (emax >= 1)
etamax = emax;
if (emin <= 0)
@ -169,9 +169,9 @@ class etaInterpolationBase : public slsInterpolation {
}
}
delete[] gm;
return 1;
return heta;
}
return 0;
return NULL;
};
float *gethhx() {
@ -183,12 +183,17 @@ class etaInterpolationBase : public slsInterpolation {
// hhy->Scale((double)nSubPixels);
return hhy;
};
virtual int addToFlatField(double etax, double etay) {
virtual int addToFlatFieldDistribution(double etax, double etay) {
#ifdef MYROOT1
heta->Fill(etax, etay);
#endif
#ifndef MYROOT1
int ex, ey;
ex = (etax - etamin) / etastepX;
ey = (etay - etamin) / etastepY;
if (ey < nbetaY && ex < nbetaX && ex >= 0 && ey >= 0)
heta[ey * nbetaX + ex]++;
#endif
return 0;
};

View File

@ -78,20 +78,20 @@ class noInterpolation : public slsInterpolation {
};
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay) {
return 0;
};
/* virtual int addToFlatField(double *cluster, double &etax, double &etay) { */
/* return 0; */
/* }; */
virtual int addToFlatField(int *cluster, double &etax, double &etay) {
return 0;
};
/* virtual int addToFlatField(int *cluster, double &etax, double &etay) { */
/* return 0; */
/* }; */
virtual int addToFlatField(double etax, double etay) { return 0; };
virtual int addToFlatFieldDistribution(double etax, double etay) { return 0; };
virtual int addToFlatField(double totquad, int quad, double *cl,
double &etax, double &etay) {
return 0;
};
/* virtual int addToFlatField(double totquad, int quad, double *cl, */
/* double &etax, double &etay) { */
/* return 0; */
/* }; */
virtual int addToFlatField(double totquad, int quad, int *cl, double &etax,
double &etay) {

View File

@ -175,29 +175,31 @@ class slsInterpolation {
return hint;
};
virtual int addToFlatField(double *cluster, double &etax, double &etay) = 0;
virtual int addToFlatField(int *cluster, double &etax, double &etay) = 0;
//virtual int addToFlatField(double *cluster, double &etax, double &etay) = 0;
//virtual int addToFlatField(int *cluster, double &etax, double &etay) = 0;
virtual int addToFlatField(double totquad, int quad, int *cl, double &etax,
double &etay) = 0;
virtual int addToFlatField(double totquad, int quad, double *cluster,
double &etax, double &etay) = 0;
virtual int addToFlatField(double etax, double etay) = 0;
//virtual int addToFlatField(double totquad, int quad, double *cluster,
// double &etax, double &etay) = 0;
virtual int addToFlatFieldDistribution(double etax, double etay) = 0;
virtual int *getFlatField() { return NULL; };
virtual int *setFlatField(int *h, int nb = -1, double emin = -1,
virtual int *getFlatFieldDistribution() { return NULL; };
virtual int *setFlatField(int *h, int nbx = -1, int nby = -1,
double emin = -1,
double emax = -1) {
return NULL;
};
virtual void *writeFlatField(const char *imgname) { return NULL; };
virtual void *readFlatField(const char *imgname, int nb = -1,
double emin = 1, double emax = 0) {
virtual void *readFlatField(const char *imgname,
double emin = 1, double emax = 0) {
return NULL;
};
virtual int *getFlatField(int &nb, double &emin, double &emax) {
nb = 0;
virtual int *getFlatField(int &nbx, int &nby, double &emin, double &emax) {
nbx = 0;
nby=0;
emin = 0;
emax = 0;
return getFlatField();
return getFlatFieldDistribution();
};
virtual void resetFlatField() = 0;

View File

@ -47,7 +47,6 @@ int main(int argc, char *argv[]) {
#endif
int iarg = 4;
char infname[10000];
char fname[10000];
char outfname[10000];
#ifndef FF
iarg = 4;
@ -74,18 +73,17 @@ int main(int argc, char *argv[]) {
int etabins = 1000; // nsubpix*2*100;
double etamin = -1, etamax = 2;
// double etamin=-0.1, etamax=1.1;
double eta3min = -2, eta3max = 2;
int quad;
// double eta3min = -2, eta3max = 2;
double sum, totquad;
double sDum[2][2];
double etax, etay, int_x, int_y;
double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y;
int ok;
int f0 = -1;
double etax, etay;
// double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y;
int ix, iy, isx, isy;
int nframes = 0, lastframe = -1;
double d_x, d_y, res = 5, xx, yy;
int nph = 0, badph = 0, totph = 0;
//double d_x, d_y, res = 5, xx, yy;
int nph = 0, totph = 0;
//badph = 0,
FILE *f = NULL;
#ifdef DOUBLE_SPH
@ -96,7 +94,8 @@ int main(int argc, char *argv[]) {
single_photon_hit cl(3, 3);
#endif
int nSubPixels = nsubpix;
//int f0 = -1;
// int nSubPixels = nsubpix;
#ifndef NOINTERPOLATION
eta2InterpolationPosXY *interp =
new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
@ -109,7 +108,12 @@ int main(int argc, char *argv[]) {
#endif
#ifndef FF
int quad;
#ifndef NOINTERPOLATION
char fname[10000];
int ok;
double int_x, int_y;
int *img;
cout << "read ff " << argv[2] << endl;
sprintf(fname, "%s", argv[2]);
interp->readFlatField(fname);
@ -121,7 +125,6 @@ int main(int argc, char *argv[]) {
cout << "Will write eta file " << argv[2] << endl;
#endif
int *img;
float *totimg = new float[NC * NR * nsubpix * nsubpix];
for (ix = 0; ix < NC; ix++) {
for (iy = 0; iy < NR; iy++) {
@ -149,7 +152,7 @@ int main(int argc, char *argv[]) {
if (f) {
cout << infname << endl;
nframes = 0;
f0 = -1;
//f0 = -1;
while (cl.read(f)) {
totph++;
@ -157,14 +160,21 @@ int main(int argc, char *argv[]) {
lastframe = cl.iframe;
// cout << cl.iframe << endl;
// f0=cl.iframe;
if (nframes == 0)
f0 = lastframe;
// if (nframes == 0)
// f0 = lastframe;
nframes++;
}
// quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
#ifndef FF
quad = interp->calcEta(cl.get_cluster(), etax, etay, sum,
totquad, sDum);
if (sum > cmin && totquad / sum > 0.8 && totquad / sum < 1.2 &&
#endif
#ifdef FF
interp->calcEta(cl.get_cluster(), etax, etay, sum,
totquad, sDum);
#endif
if (sum > cmin && totquad / sum > 0.8 && totquad / sum < 1.2 &&
sum < cmax) {
nph++;
// if (sum>200 && sum<580) {
@ -199,7 +209,7 @@ int main(int argc, char *argv[]) {
// if (cl.x>50)
// #endif
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
interp->addToFlatField(etax, etay);
interp->addToFlatFieldDistribution(etax, etay);
// if (etax==0 || etay==0) cout << cl.x << " " << cl.y <<
// endl;
@ -242,9 +252,9 @@ int main(int argc, char *argv[]) {
}
}
}
cout << "Read " << nframes << " frames (first frame: " << f0
<< " last frame: " << lastframe << " delta:" << lastframe - f0
<< ") nph=" << nph << endl;
// cout << "Read " << nframes << " frames (first frame: " << f0
// << " last frame: " << lastframe << " delta:" << lastframe - f0
// << ") nph=" << nph << endl;
interp->clearInterpolatedImage();
#endif

View File

@ -502,13 +502,13 @@ int main(int argc, char *argv[]) {
}
#ifdef INTERP
else if (fMode == eFlat) {
int nb;
int nbx, nby;
double emi = 0, ema = 1;
int *ff = mt->getFlatField(nb, emi, ema);
nnx = nb;
nny = nb;
dout = new int32_t[nb * nb];
for (int ix = 0; ix < nb * nb; ix++) {
int *ff = mt->getFlatField(nbx, nby, emi, ema);
nnx = nbx;
nny = nby;
dout = new int32_t[nbx * nby];
for (int ix = 0; ix < nbx * nby; ix++) {
dout[ix] = ff[ix];
}
}

View File

@ -182,10 +182,10 @@ class threadedAnalogDetector {
interp->prepareInterpolation(ok);
}
virtual int *getFlatField() {
virtual int *getFlatFieldDistribution() {
slsInterpolation *interp = (det)->getInterpolation();
if (interp)
return interp->getFlatField();
return interp->getFlatFieldDistribution();
else
return NULL;
}
@ -208,19 +208,19 @@ class threadedAnalogDetector {
return NULL;
}
void *readFlatField(const char *imgname, int nb = -1, double emin = 1,
void *readFlatField(const char *imgname, double emin = 1,
double emax = 0) {
slsInterpolation *interp = (det)->getInterpolation();
if (interp)
return interp->readFlatField(imgname, nb, emin, emax);
return interp->readFlatField(imgname, emin, emax);
return NULL;
}
virtual int *getFlatField(int &nb, double emi, double ema) {
virtual int *getFlatField(int &nbx, int &nby, double &emi, double &ema) {
slsInterpolation *interp = (det)->getInterpolation();
int *ff = NULL;
if (interp) {
ff = interp->getFlatField(nb, emi, ema);
ff = interp->getFlatField(nbx, nby, emi, ema);
}
return ff;
}

View File

@ -25,10 +25,10 @@ class multiThreadedInterpolatingDetector
// }
}
virtual int *getFlatField() { return (dets[0])->getFlatField(); }
virtual int *getFlatFieldDistribution() { return (dets[0])->getFlatFieldDistribution(); }
virtual int *getFlatField(int &nb, double emi, double ema) {
return (dets[0])->getFlatField(nb, emi, ema);
virtual int *getFlatField(int &nbx, int &nby, double &emi, double &ema) {
return (dets[0])->getFlatField(nbx, nby, emi, ema);
}
virtual int *setFlatField(int *h = NULL, int nb = -1, double emin = 1,
@ -40,9 +40,9 @@ class multiThreadedInterpolatingDetector
return dets[0]->writeFlatField(imgname);
};
void *readFlatField(const char *imgname, int nb = -1, double emin = 1,
void *readFlatField(const char *imgname, double emin = 1,
double emax = 0) {
return (dets[0])->readFlatField(imgname, nb, emin, emax);
return (dets[0])->readFlatField(imgname, emin, emax);
};
/* virtual int setNSubPixels(int ns) { return

View File

@ -43,7 +43,7 @@ enum DACINDEX {
#define DAC_NAMES \
"VSvP", "Vtrim", "Vrpreamp", "Vrshaper", "VSvN", "Vtgstv", "Vcmp_ll", \
"Vcmp_lr", "Vcal", "Vcmp_rl", "rxb_rb", "rxb_lb", "Vcmp_rr", "Vcp", \
"Vcn", "Vishaper"
"Vcn", "Vishaper", "Vthreshold"
#define DEFAULT_DAC_VALS \
{ \
0, /* VSvP */ \

View File

@ -480,9 +480,6 @@ void setupDetector() {
setInitialExtSignals();
// 10G UDP
enableTenGigabitEthernet(1);
#ifdef VIRTUAL
enableTenGigabitEthernet(0);
#endif
getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return;

View File

@ -95,7 +95,7 @@ enum DACINDEX {
#define DAC_NAMES \
"vcassh", "vth2", "vrshaper", "vrshaper_n", "vipre_out", "vth3", "vth1", \
"vicin", "vcas", "vrpreamp", "vcal_n", "vipre", "vishaper", "vcal_p", \
"vtrim", "vdcsh"
"vtrim", "vdcsh", "vthreshold"
#define DEFAULT_DAC_VALS \
{ \
1200, /* casSh */ \

View File

@ -886,7 +886,7 @@ class Detector {
Result<bool> getRxArping(Positions pos = {}) const;
/** Starts a thread in slsReceiver to ping the interface it is listening
/** Starts a thread in slsReceiver to arping the interface it is listening
* every minute. Useful in 10G mode. */
void setRxArping(bool value, Positions pos = {});

View File

@ -1745,10 +1745,10 @@ class CmdProxy {
"processor 1, streamer 1, arping]. If no streamer yet or there "
"is no second interface, it gives 0 in its place.");
INTEGER_COMMAND_VEC_ID(
rx_arping, getRxArping, setRxArping, StringTo<int>,
"[0, 1]\n\tStarts a thread in slsReceiver to ping the interface it is "
"listening to every minute. Useful in 10G mode.");
INTEGER_COMMAND_VEC_ID(rx_arping, getRxArping, setRxArping, StringTo<int>,
"[0, 1]\n\tStarts a thread in slsReceiver to arping "
"the interface it is "
"listening to every minute. Useful in 10G mode.");
/* File */

View File

@ -12,7 +12,7 @@ set(SOURCES
src/DataProcessor.cpp
src/DataStreamer.cpp
src/Fifo.cpp
src/ThreadArping.cpp
src/Arping.cpp
)
set(PUBLICHEADERS

View File

@ -0,0 +1,115 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Arping.h"
#include <chrono>
#include <sys/syscall.h>
#include <unistd.h>
void Arping::SetInterfacesAndIps(const int index, const std::string &interface,
const std::string &ip) {
if (interface.empty() || ip.empty()) {
throw sls::RuntimeError("Could not arping. Interface name and ip not "
"set up for interface " +
std::to_string(index));
}
// create commands to arping
std::ostringstream os;
os << "arping -c 1 -U -I " << interface << " " << ip;
// to read error messages
os << " 2>&1";
std::string cmd = os.str();
commands[index] = cmd;
}
pid_t Arping::GetThreadId() const { return threadId; }
bool Arping::IsRunning() const { return runningFlag; }
void Arping::StartThread() {
TestCommands();
try {
t = std::thread(&Arping::ThreadExecution, this);
} catch (...) {
throw sls::RuntimeError("Could not start arping thread");
}
runningFlag = true;
}
void Arping::StopThread() {
runningFlag = false;
t.join();
}
void Arping::ThreadExecution() {
threadId = syscall(SYS_gettid);
LOG(logINFOBLUE) << "Created [ Arping Thread, Tid: " << threadId << " ]";
while (runningFlag) {
std::string error = ExecuteCommands();
// just print (was already tested at thread start)
if (!error.empty()) {
LOG(logERROR) << error;
}
// wait for 60s as long as thread not killed
int nsecs = 0;
while (runningFlag && nsecs != 60) {
std::this_thread::sleep_for(std::chrono::seconds(1));
++nsecs;
}
}
LOG(logINFOBLUE) << "Exiting [ Arping Thread, Tid: " << threadId << " ]";
threadId = 0;
}
void Arping::TestCommands() {
// atleast one interface must be set up
if (commands[0].empty()) {
throw sls::RuntimeError(
"Could not arping. Interface not set up in apring thread");
}
// test if arping commands throw an error
std::string error = ExecuteCommands();
if (!error.empty()) {
throw sls::RuntimeError(error);
}
}
std::string Arping::ExecuteCommands() {
for (auto cmd : commands) {
// empty if 2nd interface not enabled
if (cmd.empty())
continue;
LOG(logDEBUG) << "Executing Arping Command: " << cmd;
// execute command
FILE *sysFile = popen(cmd.c_str(), "r");
if (sysFile == NULL) {
std::ostringstream os;
os << "Could not Arping [" << cmd << " ] : Popen fail";
return os.str();
}
// copy output
char output[MAX_STR_LENGTH] = {0};
fgets(output, sizeof(output), sysFile);
output[sizeof(output) - 1] = '\0';
// check exit status of command
if (pclose(sysFile)) {
std::ostringstream os;
os << "Could not arping[" << cmd << "] : " << output;
return os.str();
} else {
LOG(logDEBUG) << output;
}
}
return std::string();
}

View File

@ -0,0 +1,35 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
/**
*@short creates/destroys an ARPing thread to arping the interfaces slsReceiver
is listening to.
*/
#include "receiver_defs.h"
#include "sls/logger.h"
#include <atomic>
#include <thread>
class Arping : private virtual slsDetectorDefs {
public:
void SetInterfacesAndIps(const int index, const std::string &interface,
const std::string &ip);
pid_t GetThreadId() const;
bool IsRunning() const;
void StartThread();
void StopThread();
private:
void TestCommands();
std::string ExecuteCommands();
void ThreadExecution();
std::vector<std::string> commands =
std::vector<std::string>(MAX_NUMBER_OF_LISTENING_THREADS);
std::atomic<bool> runningFlag{false};
std::thread t;
pid_t threadId{0};
};

View File

@ -1401,8 +1401,7 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) {
}
// update locally to use for arping
udpips.clear();
udpips.push_back(arg.str());
udpips[0] = arg.str();
// get mac address
auto retval = sls::InterfaceNameToMac(eth);
@ -1437,7 +1436,7 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) {
impl()->setEthernetInterface2(eth);
// update locally to use for arping
udpips.push_back(arg.str());
udpips[1] = arg.str();
// get mac address
auto retval = sls::InterfaceNameToMac(eth);

View File

@ -192,5 +192,6 @@ class ClientInterface : private virtual slsDetectorDefs {
pid_t parentThreadId{0};
pid_t tcpThreadId{0};
std::vector<std::string> udpips;
std::vector<std::string> udpips =
std::vector<std::string>(MAX_NUMBER_OF_LISTENING_THREADS);
};

View File

@ -1,13 +1,13 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Implementation.h"
#include "Arping.h"
#include "DataProcessor.h"
#include "DataStreamer.h"
#include "Fifo.h"
#include "GeneralData.h"
#include "Listener.h"
#include "MasterAttributes.h"
#include "ThreadArping.h"
#include "sls/ToString.h"
#include "sls/ZmqSocket.h" //just for the zmq port define
#include "sls/file_utils.h"
@ -109,8 +109,8 @@ void Implementation::SetupFifoStructure() {
void Implementation::setDetectorType(const detectorType d) {
// object to create threads to arping
threadArping = sls::make_unique<ThreadArping>();
// object to create thread for arping
arping = sls::make_unique<Arping>();
detType = d;
switch (detType) {
@ -325,30 +325,31 @@ std::array<pid_t, NUM_RX_THREAD_IDS> Implementation::getThreadIds() const {
retval[id++] = 0;
}
}
if (threadArping->IsRunning()) {
retval[NUM_RX_THREAD_IDS - 1] = threadArping->GetThreadId();
}
retval[NUM_RX_THREAD_IDS - 1] = arping->GetThreadId();
return retval;
}
bool Implementation::getArping() const { return threadArping->IsRunning(); }
bool Implementation::getArping() const { return arping->IsRunning(); }
pid_t Implementation::getArpingThreadId() const {
return threadArping->GetThreadId();
return arping->GetThreadId();
}
void Implementation::setArping(const bool i,
const std::vector<std::string> ips) {
if (i != threadArping->IsRunning()) {
if (i != arping->IsRunning()) {
if (!i) {
threadArping->StopRunning();
arping->StopThread();
} else {
threadArping->ClearIpsAndInterfaces();
threadArping->AddIpsAndInterfaces(eth[0], ips[0]);
if (numUDPInterfaces == 2 && detType != EIGER) {
threadArping->AddIpsAndInterfaces(eth[1], ips[1]);
// setup interface
for (int i = 0; i != numUDPInterfaces; ++i) {
// ignore eiger with 2 interfaces (only udp port)
if (i == 1 && (numUDPInterfaces == 1 || detType == EIGER)) {
break;
}
arping->SetInterfacesAndIps(i, eth[i], ips[i]);
}
threadArping->StartRunning();
arping->StartThread();
}
}
}

View File

@ -11,7 +11,7 @@ class DataProcessor;
class DataStreamer;
class Fifo;
class slsDetectorDefs;
class ThreadArping;
class Arping;
#include <atomic>
#include <chrono>
@ -383,7 +383,7 @@ class Implementation : private virtual slsDetectorDefs {
std::vector<std::unique_ptr<DataProcessor>> dataProcessor;
std::vector<std::unique_ptr<DataStreamer>> dataStreamer;
std::vector<std::unique_ptr<Fifo>> fifo;
std::unique_ptr<ThreadArping> threadArping;
std::unique_ptr<Arping> arping;
std::mutex hdf5Lib;
};

View File

@ -55,9 +55,11 @@ int64_t Listener::GetNumMissingPacket(bool stoppedFlag,
bool Listener::GetStartedFlag() { return startedFlag; }
uint64_t Listener::GetCurrentFrameIndex() { return currentFrameIndex; }
uint64_t Listener::GetCurrentFrameIndex() { return lastCaughtFrameIndex; }
uint64_t Listener::GetListenedIndex() { return currentFrameIndex - firstIndex; }
uint64_t Listener::GetListenedIndex() {
return lastCaughtFrameIndex - firstIndex;
}
void Listener::SetFifo(Fifo *f) { fifo = f; }
@ -88,6 +90,7 @@ void Listener::ResetParametersforNewAcquisition() {
void Listener::RecordFirstIndex(uint64_t fnum) {
// listen to this fnum, later +1
currentFrameIndex = fnum;
lastCaughtFrameIndex = fnum;
startedFlag = true;
firstIndex = fnum;

View File

@ -1,95 +0,0 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "ThreadArping.h"
#include "sls/container_utils.h"
#include <iostream>
#include <sys/syscall.h>
#include <unistd.h>
ThreadArping::ThreadArping() {}
ThreadArping::~ThreadArping() { StopRunning(); }
pid_t ThreadArping::GetThreadId() const { return threadId; }
bool ThreadArping::IsRunning() const { return runningFlag; }
void ThreadArping::StartRunning() {
if (!runningFlag) {
if (arpInterfaceIp.size() == 0) {
throw sls::RuntimeError("No Interface added to Arping");
}
runningFlag = true;
// create thread
try {
std::thread temp = std::thread(&ThreadArping::RunningThread, this);
threadObject = temp.native_handle();
temp.detach();
} catch (...) {
throw sls::RuntimeError("Could not create arping thread");
}
}
}
void ThreadArping::StopRunning() {
pthread_cancel(threadObject);
LOG(logINFOBLUE) << "Killing [ Arping Thread, Tid: " << threadId << " ]";
runningFlag = false;
}
void ThreadArping::ClearIpsAndInterfaces() { arpInterfaceIp.clear(); }
void ThreadArping::AddIpsAndInterfaces(std::string interface, std::string ip) {
arpInterfaceIp.push_back(std::make_pair(interface, ip));
}
void ThreadArping::RunningThread() {
threadId = syscall(SYS_gettid);
{
std::ostringstream os;
os << "Created [ Arping Thread, Tid: " << threadId << " ] for ";
for (auto ethip : arpInterfaceIp) {
os << "\n\t[ " << ethip.first << ", " << ethip.second << " ]";
}
LOG(logINFOBLUE) << os.str();
}
// create the commands to ping necessary interfaces
std::vector<std::string> commands;
for (auto ethip : arpInterfaceIp) {
std::ostringstream os;
os << "arping -c 1 -U -I " << ethip.first << " " << ethip.second;
// to read error messages
os << " 2>&1";
std::string cmd = os.str();
commands.push_back(cmd);
}
while (IsRunning()) {
// arping
for (auto cmd : commands) {
LOG(logDEBUG) << "Executing Arping Command: " << cmd;
// execute command and check for errors
FILE *sysFile = popen(cmd.c_str(), "r");
char output[MAX_STR_LENGTH] = {0};
fgets(output, sizeof(output), sysFile);
output[sizeof(output) - 1] = '\0';
if (pclose(sysFile)) {
LOG(logERROR) << "Executing cmd[" << cmd
<< "]\n\tError Message : " << output;
} else {
LOG(logDEBUG) << output;
}
}
// wait for 60s
usleep(60 * 1000 * 1000);
}
LOG(logINFOBLUE) << "Exiting [ Arping Thread, Tid: " << threadId << " ]";
}

View File

@ -1,45 +0,0 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
/**
*@short creates/destroys an ARPing thread to ping the interfaces slsReceiver is
listening to.
*/
#include "sls/logger.h"
#include "sls/sls_detector_defs.h"
#include <atomic>
#include <string>
#include <thread>
#include <utility> // pair, make_pair
class ThreadArping : private virtual slsDetectorDefs {
private:
std::atomic<bool> killThread{false};
std::atomic<bool> runningFlag{false};
pthread_t threadObject;
std::vector<std::pair<std::string, std::string>> arpInterfaceIp;
std::vector<std::string> commands;
pid_t threadId;
public:
ThreadArping();
virtual ~ThreadArping();
pid_t GetThreadId() const;
bool IsRunning() const;
void StartRunning();
void StopRunning();
void ClearIpsAndInterfaces();
void AddIpsAndInterfaces(std::string interface, std::string ip);
private:
/**
* Thread called: An infinite while loop that runs arping as long as
* RunningMask is satisfied Then it exits the thread on its own if
* killThread is true
*/
void RunningThread();
};

View File

@ -21,14 +21,6 @@ class ThreadObject : private virtual slsDetectorDefs {
protected:
const int index{0};
private:
std::atomic<bool> killThread{false};
std::atomic<bool> runningFlag{false};
std::thread threadObject;
sem_t semaphore;
const std::string type;
pid_t threadId{0};
public:
ThreadObject(int threadIndex, std::string threadType);
virtual ~ThreadObject();
@ -47,4 +39,11 @@ class ThreadObject : private virtual slsDetectorDefs {
* Then it exits the thread on its own if killThread is true
*/
void RunningThread();
std::atomic<bool> killThread{false};
std::atomic<bool> runningFlag{false};
std::thread threadObject;
sem_t semaphore;
const std::string type;
pid_t threadId{0};
};

View File

@ -563,6 +563,8 @@ enum streamingInterface {
#ifdef __cplusplus
};
//operators needed in ToString
inline slsDetectorDefs::streamingInterface
operator|(const slsDetectorDefs::streamingInterface &a,
const slsDetectorDefs::streamingInterface &b) {
@ -576,6 +578,9 @@ operator&(const slsDetectorDefs::streamingInterface &a,
return slsDetectorDefs::streamingInterface(static_cast<int32_t>(a) &
static_cast<int32_t>(b));
};
#endif
#ifdef __cplusplus

View File

@ -6,10 +6,10 @@
#define APIRECEIVER 0x211124
#define APIGUI 0x211124
#define APICTB 0x220131
#define APIGOTTHARD 0x220131
#define APIGOTTHARD2 0x220131
#define APIJUNGFRAU 0x220131
#define APIMYTHEN3 0x220131
#define APIMOENCH 0x220131
#define APIEIGER 0x220202
#define APICTB 0x220203
#define APIGOTTHARD 0x220203
#define APIGOTTHARD2 0x220203
#define APIJUNGFRAU 0x220203
#define APIMYTHEN3 0x220203
#define APIMOENCH 0x220203
#define APIEIGER 0x220203