Merge pull request #114 from slsdetectorgroup/gotthard2

Gotthard2
This commit is contained in:
Dhanya Thattil 2020-07-17 13:00:07 +02:00 committed by GitHub
commit 97ddfed819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 1420 additions and 167 deletions

View File

@ -78,14 +78,11 @@
/* Status register */
#define STATUS_REG (0x04 * REG_OFFSET + BASE_CONTROL)
/* Look at me read only register */
#define LOOK_AT_ME_REG (0x05 * REG_OFFSET + BASE_CONTROL)
/* System status register */
#define SYSTEM_STATUS_REG (0x06 * REG_OFFSET + BASE_CONTROL)
#define SYSTEM_STATUS_REG (0x05 * REG_OFFSET + BASE_CONTROL)
/* Config RW regiseter */
#define CONFIG_REG (0x20 * REG_OFFSET + BASE_CONTROL)
#define CONFIG_REG (0x08 * REG_OFFSET + BASE_CONTROL)
#define CONFIG_VETO_ENBL_OFST (0)
#define CONFIG_VETO_ENBL_MSK (0x00000001 << CONFIG_VETO_ENBL_OFST)
@ -93,7 +90,7 @@
#define CONFIG_VETO_CH_10GB_ENBL_MSK (0x00000001 << CONFIG_VETO_CH_10GB_ENBL_OFST)
/* Control RW register */
#define CONTROL_REG (0x21 * REG_OFFSET + BASE_CONTROL)
#define CONTROL_REG (0x09 * REG_OFFSET + BASE_CONTROL)
#define CONTROL_STRT_ACQSTN_OFST (0)
#define CONTROL_STRT_ACQSTN_MSK (0x00000001 << CONTROL_STRT_ACQSTN_OFST)
@ -111,12 +108,16 @@
#define CONTROL_PWR_CHIP_MSK (0x00000001 << CONTROL_PWR_CHIP_OFST)
/** DTA Offset Register */
#define DTA_OFFSET_REG (0x24 * REG_OFFSET + BASE_CONTROL)
#define DTA_OFFSET_REG (0x0A * REG_OFFSET + BASE_CONTROL)
/** Mask Strip Registers (40) */
#define MASK_STRIP_START_REG (0x18 * REG_OFFSET + BASE_CONTROL)
#define MASK_STRIP_NUM_REGS (40)
/* ASIC registers --------------------------------------------------*/
/* ASIC Config register */
#define ASIC_CONFIG_REG (0x00 * REG_OFFSET + BASE_ASIC)
#define ASIC_CONFIG_REG (0x00 * REG_OFFSET + BASE_ASIC)
#define ASIC_CONFIG_RUN_MODE_OFST (0)
#define ASIC_CONFIG_RUN_MODE_MSK (0x00000003 << ASIC_CONFIG_RUN_MODE_OFST)

14
slsDetectorServers/gotthard2DetectorServer/config.txt Executable file → Normal file
View File

@ -7,20 +7,20 @@ vchip_ref_comp_fe -1 0x100
vchip_cs -1 0x0D0
#dacs value (max 4096)
vref_h_adc 2099
vref_h_adc 2116
vb_comp_fe 0
vb_comp_adc 0
vcom_cds 1400
vref_rstore 640
vcom_cds 705
vref_rstore 205
vb_opa_1st 0
vref_comp_fe 0
vcom_adc1 1400
vref_prech 1720
vcom_adc1 705
vref_prech 900
vref_l_adc 700
vref_cds 1200
vref_cds 600
vb_cs 2799
vb_opa_fd 0
vcom_adc2 1400
vcom_adc2 704
#configure adc chip index adc index value(max 0x7F)
confadc -1 -1 0x22

View File

@ -56,6 +56,8 @@ int64_t numTriggersReg = 1;
int64_t delayReg = 0;
int64_t numBurstsReg = 1;
int64_t burstPeriodReg = 0;
int filter = 0;
int cdsGain = 0;
int detPos[2] = {};
int isInitCheckDone() { return initCheckDone; }
@ -369,6 +371,8 @@ void setupDetector() {
delayReg = 0;
numBurstsReg = 1;
burstPeriodReg = 0;
filter = 0;
cdsGain = 0;
for (int i = 0; i < NUM_CLOCKS; ++i) {
clkPhase[i] = 0;
}
@ -450,6 +454,8 @@ void setupDetector() {
return;
}
setBurstMode(DEFAULT_BURST_MODE);
setFilter(DEFAULT_FILTER);
setCDSGain(DEFAILT_CDS_GAIN);
setSettings(DEFAULT_SETTINGS);
// Initialization of acquistion parameters
@ -497,7 +503,7 @@ int readConfigFile() {
memset(line, 0, LZ);
char command[LZ];
int nadcRead = 0;
int nAdcTotal = 0;
// keep reading a line
while (fgets(line, LZ, fd)) {
@ -611,7 +617,7 @@ int readConfigFile() {
break;
}
// validations
if (value > ASIC_ADC_MAX_VAL) {
if (value < 0 || value > ASIC_ADC_MAX_VAL) {
sprintf(initErrorMessage,
"Could not configure adc from on-board server config "
"file. Invalid value (max 0x%x). Line:[%s].\n",
@ -619,28 +625,23 @@ int readConfigFile() {
break;
}
int chipmin = 0;
int chipmax = NCHIP;
int adcmin = 0;
int adcmax = NADC;
// specific chip
if (ichip != -1) {
chipmin = ichip;
chipmax = ichip + 1;
}
// specific adc
if (iadc != -1) {
adcmin = iadc;
adcmax = iadc + 1;
if (setADCConfiguration(ichip, iadc, value) == FAIL) {
sprintf(initErrorMessage,
"Could not configure adc from on-board server "
"config file. Line:[%s].\n",
line);
break;
}
for (int i = chipmin; i < chipmax; ++i) {
for (int j = adcmin; j < adcmax; ++j) {
adcConfiguration[i][j] = (uint8_t)value;
++nadcRead;
}
// to ensure all adcs are configured at start up
int nadc = 1;
if (iadc == -1) {
nadc = NADC;
}
if (ichip == -1) {
nadc *= NCHIP;
}
nAdcTotal += nadc;
}
// vchip command
@ -756,17 +757,11 @@ int readConfigFile() {
fclose(fd);
if (!strlen(initErrorMessage)) {
if (nadcRead != NADC * NCHIP) {
if (nAdcTotal != NADC * NCHIP) {
sprintf(initErrorMessage,
"Could not configure adc from on-board server config file. "
"Insufficient adcconf commands. Read %d, expected %d\n",
nadcRead, NADC * NCHIP);
}
}
for (int i = 0; i < NCHIP; ++i) {
for (int j = 0; j < NADC; ++j) {
LOG(logDEBUG2,
("adc read %d %d: 0x%02hhx\n", i, j, adcConfiguration[i][j]));
nAdcTotal, NADC * NCHIP);
}
}
@ -1797,29 +1792,31 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
("Setting veto photon [chip:%d, G%d]\n", chipIndex, gainIndex));
// add gain bits
{
int gainValue = 0;
switch (gainIndex) {
case 0:
gainValue = ASIC_G0_VAL;
break;
case 1:
gainValue = ASIC_G1_VAL;
break;
case 2:
gainValue = ASIC_G2_VAL;
break;
default:
LOG(logERROR, ("Unknown gain index %d\n", gainIndex));
return FAIL;
}
LOG(logDEBUG2, ("Adding gain bits\n"));
for (int i = 0; i < NCHAN; ++i) {
values[i] |= gainValue;
LOG(logDEBUG2, ("Value %d: 0x%x\n", i, values[i]));
}
int gainValue = 0;
switch (gainIndex) {
case 0:
gainValue = ASIC_G0_VAL;
break;
case 1:
gainValue = ASIC_G1_VAL;
break;
case 2:
gainValue = ASIC_G2_VAL;
break;
default:
LOG(logERROR, ("Unknown gain index %d\n", gainIndex));
return FAIL;
}
LOG(logDEBUG2, ("Adding gain bits\n"));
for (int i = 0; i < NCHAN; ++i) {
values[i] |= gainValue;
LOG(logDEBUG2, ("Value %d: 0x%x\n", i, values[i]));
}
return configureASICVetoReference(chipIndex, values);
}
int configureASICVetoReference(int chipIndex, int *values) {
const int lenDataBitsPerchannel = ASIC_GAIN_MAX_BITS + ADU_MAX_BITS; // 14
const int lenBits = lenDataBitsPerchannel * NCHAN; // 1792
const int padding = 4; // due to address (4) to make it byte aligned
@ -1900,24 +1897,78 @@ int getVetoPhoton(int chipIndex, int *retvals) {
return OK;
}
int configureSingleADCDriver(int chipIndex) {
LOG(logINFO, ("Configuring ADC for %s chips [chipIndex:%d Burst Mode:%d]\n",
chipIndex == -1 ? "All" : "Single", chipIndex, burstMode));
int setVetoFile(int chipIndex, int *gainIndices, int *values) {
LOG(logINFO, ("Setting veto file [chip:%d]\n", chipIndex));
// correct gain bits and integrate into values
for (int i = 0; i < NCHAN; ++i) {
switch (gainIndices[i]) {
case 0:
gainIndices[i] = ASIC_G0_VAL;
break;
case 1:
gainIndices[i] = ASIC_G1_VAL;
break;
case 2:
gainIndices[i] = ASIC_G2_VAL;
break;
default:
LOG(logERROR,
("Unknown gain index %d for channel %d\n", gainIndices[i], i));
return FAIL;
}
values[i] |= gainIndices[i];
LOG(logDEBUG2, ("Values[%d]: 0x%x\n", i, values[i]));
}
return configureASICVetoReference(chipIndex, values);
}
int setADCConfiguration(int chipIndex, int adcIndex, int value) {
LOG(logINFO, ("Configuring ADC [chipIndex:%d, adcIndex:%d, value:0x%x]\n",
chipIndex, adcIndex, value));
// validations
if (chipIndex < -1 || chipIndex >= NCHIP) {
LOG(logERROR, ("Invalid chip index %d\n", chipIndex));
return FAIL;
}
if (adcIndex < -1 || adcIndex >= NADC) {
LOG(logERROR, ("Invalid adc index %d\n", adcIndex));
return FAIL;
}
// validations
if (value < 0 || value > ASIC_ADC_MAX_VAL) {
LOG(logERROR, ("Invalid value 0x%x\n", value));
return FAIL;
}
int chipmin = 0;
int chipmax = NCHIP;
int adcmin = 0;
int adcmax = NADC;
// specific chip
if (chipIndex != -1) {
chipmin = chipIndex;
chipmax = chipIndex + 1;
}
// specific adc
if (adcIndex != -1) {
adcmin = adcIndex;
adcmax = adcIndex + 1;
}
// update values
for (int i = chipmin; i < chipmax; ++i) {
for (int j = adcmin; j < adcmax; ++j) {
adcConfiguration[i][j] = (uint8_t)value;
LOG(logDEBUG1,
("Value [%d][%d]: 0x%02hhx\n", i, j, adcConfiguration[i][j]));
}
}
// single chip configuration
int ind = chipIndex;
// all chips, take the first one as all equal
if (ind == -1) {
ind = 0;
}
uint8_t values[NADC];
memcpy(values, adcConfiguration + ind * NADC, NADC);
// change adc values if continuous mode
for (int i = 0; i < NADC; ++i) {
if (burstMode == BURST_OFF) {
values[i] |= ASIC_CONTINUOUS_MODE_MSK;
}
LOG(logDEBUG2, ("Value %d: 0x%02hhx\n", i, values[i]));
}
const int lenDataBitsPerADC = ASIC_ADC_MAX_BITS; // 7
const int lenBits = lenDataBitsPerADC * NADC; // 224
@ -1932,8 +1983,9 @@ int configureSingleADCDriver(int chipIndex) {
for (int ich = 0; ich < NADC; ++ich) {
// loop through all bits in a value
for (int iBit = 0; iBit < lenDataBitsPerADC; ++iBit) {
commandBytes[offset++] =
((values[ich] >> (lenDataBitsPerADC - 1 - iBit)) & 0x1);
commandBytes[offset++] = ((adcConfiguration[ind][ich] >>
(lenDataBitsPerADC - 1 - iBit)) &
0x1);
}
}
@ -1960,29 +2012,46 @@ int configureSingleADCDriver(int chipIndex) {
return OK;
}
int configureADC() {
LOG(logINFO, ("Configuring ADC \n"));
int getADCConfiguration(int chipIndex, int adcIndex) {
// already validated at tcp interface
if (chipIndex < -1 || chipIndex >= NCHIP) {
LOG(logERROR, ("Invalid chip index %d\n", chipIndex));
return -1;
}
if (adcIndex < -1 || adcIndex >= NADC) {
LOG(logERROR, ("Invalid adc index %d\n", adcIndex));
return -1;
}
int chipmin = 0;
int chipmax = NCHIP;
int adcmin = 0;
int adcmax = NADC;
// specific chip
if (chipIndex != -1) {
chipmin = chipIndex;
chipmax = chipIndex + 1;
}
// specific adc
if (adcIndex != -1) {
adcmin = adcIndex;
adcmax = adcIndex + 1;
}
int val = adcConfiguration[chipmin][adcmin];
int equal = 1;
for (int i = 0; i < NADC; ++i) {
int val = adcConfiguration[0][i];
for (int j = 1; j < NCHIP; ++j) {
if (adcConfiguration[j][i] != val) {
equal = 0;
break;
// ensure same values for chip and adc in question
for (int i = chipmin; i < chipmax; ++i) {
for (int j = adcmin; j < adcmax; ++j) {
if (adcConfiguration[i][j] != val) {
LOG(logINFO,
("\tADC configuration 0x%x at [%d][%d] differs from 0x%x "
"at "
"[%d][%d], returning -1\n",
adcConfiguration[i][j], i, j, val, chipmin, adcmin));
return -1;
}
}
}
if (equal) {
return configureSingleADCDriver(-1);
} else {
for (int i = 0; i < NCHIP; ++i) {
if (configureSingleADCDriver(i) == FAIL) {
return FAIL;
}
}
}
return OK;
return val;
}
int setBurstModeinFPGA(enum burstMode value) {
@ -2087,10 +2156,20 @@ int setBurstMode(enum burstMode burst) {
}
}
LOG(logINFO, ("\tDone Updating registers\n"))
return configureASICGlobalSettings();
}
LOG(logINFO, ("\tSetting %s Mode in Chip\n",
burstMode == BURST_OFF ? "Continuous" : "Burst"));
int value = burstMode ? ASIC_GLOBAL_BURST_VALUE : ASIC_GLOBAL_CONT_VALUE;
int configureASICGlobalSettings() {
int modeValue =
burstMode ? ASIC_GLOBAL_BURST_VALUE : ASIC_GLOBAL_CONT_VALUE;
int value = ((modeValue << ASIC_GLOBAL_MODE_OFST) & ASIC_GLOBAL_MODE_MSK) |
((filter << ASIC_FILTER_OFST) & ASIC_FILTER_MSK) |
((cdsGain << ASIC_CDS_GAIN_OFST) & ASIC_CDS_GAIN_MSK);
LOG(logINFO,
("\tSending Global Chip settings:0x%x (mode:%d(%s), filter:%d, "
"cdsgain:%d)\n",
value, modeValue, (burstMode == BURST_OFF ? "Continuous" : "Burst"),
filter, cdsGain));
const int padding = 6; // due to address (4) to make it byte aligned
const int lenTotalBits = padding + ASIC_GLOBAL_SETT_MAX_BITS +
@ -2128,7 +2207,7 @@ int setBurstMode(enum burstMode burst) {
return FAIL;
}
return configureADC();
return OK;
}
enum burstMode getBurstMode() {
@ -2151,6 +2230,30 @@ enum burstMode getBurstMode() {
return burstMode;
}
int setCDSGain(int enable) {
if (enable >= 0) {
cdsGain = (enable == 0 ? 0 : 1);
LOG(logINFO,
("%s CDS Gain\n", (cdsGain == 0 ? "Disabling" : "Enabling")));
return configureASICGlobalSettings();
}
return FAIL;
}
int getCDSGain() { return cdsGain; }
int setFilter(int value) {
if (value < 0 || value > ASIC_FILTER_MAX_VALUE) {
LOG(logERROR, ("Invalid filter value %d\n", value));
return FAIL;
}
filter = value;
LOG(logINFO, ("Setting Filter to %d\n", filter));
return configureASICGlobalSettings();
}
int getFilter() { return filter; }
void setCurrentSource(int value) {
uint32_t addr = ASIC_CONFIG_REG;
if (value > 0) {
@ -2213,6 +2316,72 @@ int getVeto() {
CONFIG_VETO_ENBL_OFST);
}
void setBadChannels(int nch, int *channels) {
LOG(logINFO, ("Setting %d bad channels\n", nch));
int numAddr = MASK_STRIP_NUM_REGS;
int startAddr = MASK_STRIP_START_REG;
// resetting all mask registers first
for (int iaddr = 0; iaddr < numAddr; ++iaddr) {
uint32_t addr = startAddr + iaddr * REG_OFFSET;
bus_w(addr, 0);
}
// setting badchannels, loop through list
for (int i = 0; i < nch; ++i) {
LOG(logINFO, ("\t[%d]: %d\n", i, channels[i]));
int iaddr = channels[i] / 32;
int iBit = channels[i] % 32;
uint32_t addr = startAddr + iaddr * REG_OFFSET;
LOG(logDEBUG1,
("val:%d iaddr:%d iBit:%d, addr:0x%x old:0x%x val:0x%x\n",
channels[i], iaddr, iBit, addr, bus_r(addr), (1 << iBit)));
bus_w(addr, bus_r(addr) | (1 << iBit));
}
}
int *getBadChannels(int *nch) {
int *retvals = NULL;
// count number of bad channels
*nch = 0;
for (int i = 0; i < MASK_STRIP_NUM_REGS; ++i) {
uint32_t addr = MASK_STRIP_START_REG + i * REG_OFFSET;
*nch += __builtin_popcount(bus_r(addr));
}
if (*nch > 0) {
// get list of bad channels
retvals = malloc(*nch * sizeof(int));
if (retvals == NULL) {
*nch = -1;
return NULL;
}
int chIndex = 0;
int numAddr = MASK_STRIP_NUM_REGS;
// loop through registers
for (int iaddr = 0; iaddr < numAddr; ++iaddr) {
// calculate address and get value
uint32_t addr = MASK_STRIP_START_REG + iaddr * REG_OFFSET;
uint32_t val = bus_r(addr);
// loop through 32 bits
for (int iBit = 0; iBit < 32; ++iBit) {
// masked, add to list
if ((val >> iBit) & 0x1) {
LOG(logDEBUG1, ("iaddr:%d iBit:%d val:0x%x, ch:%d\n", iaddr,
iBit, val, iaddr * 32 + iBit));
retvals[chIndex++] = iaddr * 32 + iBit;
}
}
}
}
// debugging
LOG(logDEBUG1, ("Reading Bad channel list\n"));
for (int i = 0; i < (*nch); ++i) {
LOG(logDEBUG1, ("[%d]: %d\n", i, retvals[i]));
}
return retvals;
}
/* aquisition */
int startStateMachine() {

View File

@ -1,7 +1,7 @@
#pragma once
#include "sls_detector_defs.h"
#define REQRD_FRMWRE_VRSN (0x190000)
#define REQRD_FRMWRE_VRSN (0x200707)
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
@ -31,6 +31,8 @@
/** Default Parameters */
#define DEFAULT_BURST_MODE (BURST_INTERNAL)
#define DEFAULT_FILTER (0)
#define DEFAILT_CDS_GAIN (0)
#define DEFAULT_NUM_FRAMES (1)
#define DEFAULT_NUM_CYCLES (1)
#define DEFAULT_NUM_BURSTS (1)
@ -135,7 +137,14 @@ enum PLLINDEX { READOUT_PLL, SYSTEM_PLL };
#define ASIC_ADC_MAX_VAL (0x7F)
#define ASIC_GLOBAL_SETT_MAX_BITS (6)
#define ASIC_GLOBAL_BURST_VALUE (0x0)
#define ASIC_GLOBAL_CONT_VALUE (0x1E)
#define ASIC_GLOBAL_CONT_VALUE (0x6)
#define ASIC_GLOBAL_MODE_OFST (0)
#define ASIC_GLOBAL_MODE_MSK (0x7 << ASIC_GLOBAL_MODE_OFST)
#define ASIC_FILTER_OFST (3)
#define ASIC_FILTER_MSK (0x3 << ASIC_FILTER_OFST)
#define ASIC_FILTER_MAX_VALUE (3)
#define ASIC_CDS_GAIN_OFST (5)
#define ASIC_CDS_GAIN_MSK (0x1 << ASIC_CDS_GAIN_OFST)
/* Struct Definitions */
typedef struct udp_header_struct {

View File

@ -504,18 +504,27 @@ int setInjectChannel(int offset, int increment);
void getInjectedChannels(int *offset, int *increment);
int setVetoReference(int gainIndex, int value);
int setVetoPhoton(int chipIndex, int gainIndex, int *values);
int configureASICVetoReference(int chipIndex, int *values);
int getVetoPhoton(int chipIndex, int *retvals);
int configureSingleADCDriver(int chipIndex);
int configureADC();
int setVetoFile(int chipIndex, int *gainIndices, int *values);
int setADCConfiguration(int chipIndex, int adcIndex, int value);
int getADCConfiguration(int chipIndex, int adcIndex);
int setBurstModeinFPGA(enum burstMode value);
int setBurstMode(enum burstMode burst);
int configureASICGlobalSettings();
enum burstMode getBurstMode();
int setCDSGain(int enable);
int getCDSGain();
int setFilter(int value);
int getFilter();
void setCurrentSource(int value);
int getCurrentSource();
void setTimingSource(enum timingSourceType value);
enum timingSourceType getTimingSource();
void setVeto(int enable);
int getVeto();
void setBadChannels(int nch, int *channels);
int *getBadChannels(int *nch);
#endif
#if defined(JUNGFRAUD) || defined(EIGERD)

View File

@ -228,4 +228,13 @@ int set_veto(int);
int set_pattern(int);
int get_scan(int);
int set_scan(int);
int get_scan_error_message(int);
int get_scan_error_message(int);
int get_cds_gain(int);
int set_cds_gain(int);
int get_filter(int);
int set_filter(int);
int set_veto_file(int);
int get_adc_config(int);
int set_adc_config(int);
int get_bad_channels(int);
int set_bad_channels(int);

View File

@ -343,9 +343,18 @@ void function_table() {
flist[F_GET_VETO] = &get_veto;
flist[F_SET_VETO] = &set_veto;
flist[F_SET_PATTERN] = &set_pattern;
flist[F_GET_SCAN] = get_scan;
flist[F_SET_SCAN] = set_scan;
flist[F_GET_SCAN_ERROR_MESSAGE] = get_scan_error_message;
flist[F_GET_SCAN] = &get_scan;
flist[F_SET_SCAN] = &set_scan;
flist[F_GET_SCAN_ERROR_MESSAGE] = &get_scan_error_message;
flist[F_GET_CDS_GAIN] = &get_cds_gain;
flist[F_SET_CDS_GAIN] = &set_cds_gain;
flist[F_GET_FILTER] = &get_filter;
flist[F_SET_FILTER] = &set_filter;
flist[F_SET_VETO_FILE] = &set_veto_file;
flist[F_GET_ADC_CONFIGURATION] = &get_adc_config;
flist[F_SET_ADC_CONFIGURATION] = &set_adc_config;
flist[F_GET_BAD_CHANNELS] = &get_bad_channels;
flist[F_SET_BAD_CHANNELS] = &set_bad_channels;
// check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -637,8 +646,7 @@ int get_server_version(int file_des) {
memset(mess, 0, sizeof(mess));
int64_t retval = -1;
retval = getServerVersion();
LOG(logDEBUG1,
("server version retval: 0x%llx\n", (long long int)retval));
LOG(logDEBUG1, ("server version retval: 0x%llx\n", (long long int)retval));
return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
}
@ -647,8 +655,7 @@ int get_serial_number(int file_des) {
memset(mess, 0, sizeof(mess));
int64_t retval = -1;
retval = getDetectorNumber();
LOG(logDEBUG1,
("detector number retval: 0x%llx\n", (long long int)retval));
LOG(logDEBUG1, ("detector number retval: 0x%llx\n", (long long int)retval));
return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
}
@ -6317,6 +6324,7 @@ int set_veto_photon(int file_des) {
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
int values[args[2]];
memset(values, 0, sizeof(values));
if (receiveData(file_des, values, sizeof(values), INT32) < 0)
return printSocketReadError();
LOG(logINFO, ("Setting Veto Photon: [chipIndex:%d, G%d, nch:%d]\n", args[0],
@ -6354,7 +6362,7 @@ int set_veto_photon(int file_des) {
sprintf(mess,
"Could not set veto photon. Invalid ADU value 0x%x "
"for channel %d, must be 12 bit.\n",
i, values[i]);
values[i], i);
LOG(logERROR, (mess));
break;
}
@ -7645,4 +7653,375 @@ int get_scan_error_message(int file_des) {
LOG(logDEBUG1, ("scan retval err message: [%s]\n", retvals));
return Server_SendResult(file_des, OTHER, retvals, sizeof(retvals));
}
}
int get_cds_gain(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int retval = -1;
LOG(logDEBUG1, ("Getting cds gain enable\n"));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// get only
retval = getCDSGain();
LOG(logDEBUG1, ("cds gain enable retval: %u\n", retval));
#endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}
int set_cds_gain(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int arg = 0;
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError();
LOG(logINFO, ("Setting cds gain enable: %u\n", arg));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
if (arg != 0 && arg != 1) {
ret = FAIL;
sprintf(mess,
"Could not set CDS gain. Invalid value %d. "
"Options [0-1]\n",
arg);
LOG(logERROR, (mess));
} else {
setCDSGain(arg);
int retval = getCDSGain();
LOG(logDEBUG1, ("cds gain enable retval: %u\n", retval));
validate(arg, retval, "set cds gain enable", DEC);
}
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}
int get_filter(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int retval = -1;
LOG(logDEBUG1, ("Getting filter\n"));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// get only
retval = getFilter();
LOG(logDEBUG1, ("filter retval: %u\n", retval));
#endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}
int set_filter(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int arg = 0;
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError();
LOG(logINFO, ("Setting filter: %u\n", arg));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
if (arg < 0 || arg > ASIC_FILTER_MAX_VALUE) {
ret = FAIL;
sprintf(mess,
"Could not set filter. Invalid filter %d. "
"Options [0-%d]\n",
arg, ASIC_FILTER_MAX_VALUE);
LOG(logERROR, (mess));
} else {
setFilter(arg);
int retval = getFilter();
LOG(logDEBUG1, ("filter retval: %u\n", retval));
validate(arg, retval, "set filter", DEC);
}
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}
int set_veto_file(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[2] = {-1, -1};
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
int chipIndex = args[0];
int nch = args[1];
int gainIndices[nch];
memset(gainIndices, 0, sizeof(gainIndices));
int values[nch];
memset(values, 0, sizeof(values));
if (receiveData(file_des, gainIndices, sizeof(gainIndices), INT32) < 0)
return printSocketReadError();
if (receiveData(file_des, values, sizeof(values), INT32) < 0)
return printSocketReadError();
LOG(logINFO,
("Setting Veto file: [chipIndex:%d, nch:%d]\n", chipIndex, nch));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
if (chipIndex < -1 || chipIndex >= NCHIP) {
ret = FAIL;
sprintf(mess, "Could not set veto file. Invalid chip index %d\n",
chipIndex);
LOG(logERROR, (mess));
} else if (nch != NCHAN) {
ret = FAIL;
sprintf(mess,
"Could not set veto file. Invalid number of channels %d. "
"Expected %d\n",
nch, NCHAN);
LOG(logERROR, (mess));
} else {
for (int i = 0; i < NCHAN; ++i) {
if (values[i] < 0 || values[i] > ADU_MAX_VAL) {
ret = FAIL;
sprintf(mess,
"Could not set veto file. Invalid ADU value 0x%x "
"for channel %d, must be 12 bit.\n",
values[i], i);
LOG(logERROR, (mess));
break;
}
if (gainIndices[i] < 0 || gainIndices[i] > 2) {
ret = FAIL;
sprintf(mess,
"Could not set veto file. Invalid gain index %d "
"for channel %d\n",
gainIndices[i], i);
LOG(logERROR, (mess));
break;
}
}
if (ret == OK) {
ret = setVetoFile(chipIndex, gainIndices, values);
if (ret == FAIL) {
sprintf(mess, "Could not set veto file for chip index %d\n",
chipIndex);
LOG(logERROR, (mess));
}
}
}
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}
int get_adc_config(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[2] = {-1, -1};
int retval = -1;
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
LOG(logDEBUG1, ("Getting adc configuration [chipIndex:%d, adcIndex:%d]\n",
args[0], args[1]));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// get only
int chipIndex = args[0];
int adcIndex = args[1];
if (chipIndex < -1 || chipIndex >= NCHIP) {
ret = FAIL;
sprintf(mess,
"Could not get adc configuration. Invalid chip index %d\n",
chipIndex);
LOG(logERROR, (mess));
} else if (adcIndex < -1 || adcIndex >= NADC) {
ret = FAIL;
sprintf(mess, "Could not get adc configuration. Invalid adc index %d\n",
adcIndex);
LOG(logERROR, (mess));
} else {
retval = getADCConfiguration(chipIndex, adcIndex);
LOG(logDEBUG1, ("adc config retval: %u\n", retval));
if (retval == -1) {
ret = FAIL;
sprintf(mess,
"Could not get a single adc configuration. Different "
"values for "
"selected adc (%d) and chip (%d) range.\n",
chipIndex, adcIndex);
LOG(logERROR, (mess));
}
}
#endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}
int set_adc_config(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[3] = {-1, -1, -1};
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
LOG(logDEBUG1,
("Setting adc configuration [chipIndex:%d, adcIndex:%d, value:0x%x]\n",
args[0], args[1], args[2]));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
int chipIndex = args[0];
int adcIndex = args[1];
int value = args[2];
if (chipIndex < -1 || chipIndex >= NCHIP) {
ret = FAIL;
sprintf(mess,
"Could not get adc configuration. Invalid chip index %d. "
"Options: [-1 to %d]\n",
chipIndex, NCHIP);
LOG(logERROR, (mess));
} else if (adcIndex < -1 || adcIndex >= NADC) {
ret = FAIL;
sprintf(mess,
"Could not get adc configuration. Invalid adc index %d. "
"Options: [-1 to %d]\n",
adcIndex, NADC);
LOG(logERROR, (mess));
} else if (value < 0 || value > ASIC_ADC_MAX_VAL) {
ret = FAIL;
sprintf(mess,
"Could not get adc configuration. Invalid value 0x%x. "
"Options: [0 to 0x%x]\n",
value, ASIC_ADC_MAX_VAL);
LOG(logERROR, (mess));
} else {
ret = setADCConfiguration(chipIndex, adcIndex, value);
if (ret == FAIL) {
sprintf(mess,
"Could not set adc configuration in chip (chipIndex: "
"%d, adcIndex: %d, value:0x%x).\n",
chipIndex, adcIndex, value);
LOG(logERROR, (mess));
} else {
int retval = getADCConfiguration(chipIndex, adcIndex);
LOG(logDEBUG1, ("adc config retval: %u\n", retval));
validate(value, retval, "configure adc", HEX);
}
}
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}
int get_bad_channels(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int nretvals = 0;
int *retvals = NULL;
LOG(logDEBUG1, ("Getting bad channels\n"));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// get only
retvals = getBadChannels(&nretvals);
if (nretvals == -1) {
ret = FAIL;
strcpy(mess, "Could not get bad channels. Memory allcoation error\n");
LOG(logERROR, (mess));
}
#endif
Server_SendResult(file_des, INT32, NULL, 0);
if (ret != FAIL) {
sendData(file_des, &nretvals, sizeof(nretvals), INT32);
if (nretvals > 0) {
sendData(file_des, retvals, sizeof(int) * nretvals, INT32);
}
}
if (retvals != NULL) {
free(retvals);
}
return ret;
}
int set_bad_channels(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int nargs = 0;
int *args = NULL;
if (receiveData(file_des, &nargs, sizeof(nargs), INT32) < 0)
return printSocketReadError();
if (nargs > 0) {
args = malloc(nargs * sizeof(int));
if (receiveData(file_des, args, nargs * sizeof(int), INT32) < 0)
return printSocketReadError();
}
LOG(logDEBUG1, ("Setting %d bad channels\n", nargs));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
// validate bad channel number
for (int i = 0; i < nargs; ++i) {
LOG(logDEBUG1, ("\t[%d]:%d\n", i, args[i]));
if (args[i] < 0 || args[i] >= (NCHAN * NCHIP)) {
ret = FAIL;
sprintf(mess,
"Could not set bad channels. Invalid bad channel "
"number %d. Options [0-%d]\n",
args[i], NCHIP * NCHAN - 1);
LOG(logERROR, (mess));
break;
}
}
if (ret == OK) {
setBadChannels(nargs, args);
int nretvals = 0;
int *retvals = getBadChannels(&nretvals);
if (nretvals == -1) {
ret = FAIL;
strcpy(mess,
"Could not get bad channels. Memory allcoation error\n");
LOG(logERROR, (mess));
} else if (nretvals != nargs) {
ret = FAIL;
sprintf(
mess,
"Could not set bad channels. Set %d channels, but read %d "
"channels\n",
nargs, nretvals);
LOG(logERROR, (mess));
}
if (retvals != NULL) {
free(retvals);
}
}
}
if (args != NULL) {
free(args);
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}

View File

@ -695,6 +695,15 @@ class Detector {
*/
void setRxZmqTimer(int time_in_ms, Positions pos = {});
Result<int> getRxZmqStartingFrame(Positions pos = {}) const;
/**
* The starting frame index to stream out. 0 by default, which streams
* the first frame in an acquisition, and then depending on the rx zmq
* frequency/ timer.
*/
void setRxZmqStartingFrame(int fnum, Positions pos = {});
Result<int> getRxZmqPort(Positions pos = {}) const;
/**
@ -983,12 +992,28 @@ class Detector {
void setVetoReference(const int gainIndex, const int value,
Positions pos = {});
/** [Gotthard2] */
void setVetoFile(const int chipIndex, const std::string &fname,
Positions pos = {});
/** [Gotthard2] */
Result<defs::burstMode> getBurstMode(Positions pos = {});
/** [Gotthard2] BURST_OFF, BURST_INTERNAL (default), BURST_EXTERNAL */
void setBurstMode(defs::burstMode value, Positions pos = {});
/** [Gotthard2] */
Result<bool> getCDSGain(Positions pos = {}) const;
/** default disabled */
void setCDSGain(bool value, Positions pos = {});
/** [Gotthard2] */
Result<int> getFilter(Positions pos = {}) const;
/** default 0 */
void setFilter(int value, Positions pos = {});
/** [Gotthard2] */
Result<bool> getCurrentSource(Positions pos = {}) const;
@ -1007,6 +1032,20 @@ class Detector {
/** [Gotthard2] */
void setVeto(const bool enable, Positions pos = {});
/** [Gotthard2] */
Result<int> getADCConfiguration(const int chipIndex, const int adcIndex,
Positions pos = {}) const;
/** [Gotthard2] */
void setADCConfiguration(const int chipIndex, const int adcIndex,
const int value, Positions pos = {});
/** [Gotthard2] */
void getBadChannels(const std::string &fname, Positions pos = {}) const;
/** [Gotthard2] */
void setBadChannels(const std::string &fname, Positions pos = {});
/**************************************************
* *
* Mythen3 Specific *

View File

@ -1669,6 +1669,29 @@ std::string CmdProxy::VetoReference(int action) {
return os.str();
}
std::string CmdProxy::VetoFile(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[chip index 0-10, -1 for all] [file name] \n\t[Gotthard2] Set "
"veto reference for each 128 channels for specific chip. The "
"file should have 128 rows of gain index and 12 bit value in hex"
<< '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError(
"cannot get vetofile. Did you mean vetophoton?");
} else if (action == defs::PUT_ACTION) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setVetoFile(StringTo<int>(args[0]), args[1], {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::BurstMode(int action) {
std::ostringstream os;
os << cmd << ' ';
@ -1715,6 +1738,62 @@ std::string CmdProxy::BurstMode(int action) {
return os.str();
}
std::string CmdProxy::ConfigureADC(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[chip index 0-10, -1 for all] [adc index 0-31, -1 for all] [12 "
"bit configuration value in hex]\n\t[Gotthard2] Sets "
"configuration for specific chip and adc, but configures 1 chip "
"(all adcs for that chip) at a time."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
auto t = det->getADCConfiguration(StringTo<int>(args[0]),
StringTo<int>(args[1]), {det_id});
os << OutStringHex(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 3) {
WrongNumberOfParameters(3);
}
int value = StringTo<int>(args[2]);
det->setADCConfiguration(StringTo<int>(args[0]), StringTo<int>(args[1]),
value, {det_id});
os << '[' << args[0] << ", " << args[1] << ", " << ToStringHex(value)
<< "]\n";
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::BadChannels(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[fname]\n\t[Gotthard2] Sets the bad channels (from file of bad "
"channel numbers) to be masked out."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->getBadChannels(args[0], {det_id});
os << "successfully retrieved" << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->setBadChannels(args[0], {det_id});
os << "successfully loaded" << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* Mythen3 Specific */
std::string CmdProxy::Counters(int action) {

View File

@ -283,7 +283,7 @@
WrongNumberOfParameters(0); \
} \
auto t = det->GETFCN(DAC_INDEX, mv, {det_id}); \
os << OutString(t) << (!args.empty() ? " mv\n" : "\n"); \
os << OutString(t) << (!args.empty() ? " mv\n" : "\n"); \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
bool mv = false; \
if (args.size() == 2) { \
@ -372,6 +372,27 @@
return os.str(); \
}
/** set only, 1 argument */
#define EXECUTE_SET_COMMAND_1ARG(CMDNAME, SETFCN, HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
os << cmd << ' '; \
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
else if (action == slsDetectorDefs::GET_ACTION) { \
throw sls::RuntimeError("Cannot get"); \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() != 1) { \
WrongNumberOfParameters(1); \
} \
det->SETFCN(args[0]); \
os << args.front() << '\n'; \
} else { \
throw sls::RuntimeError("Unknown action"); \
} \
return os.str(); \
}
/** get only */
#define GET_COMMAND(CMDNAME, GETFCN, HLPSTR) \
std::string CMDNAME(const int action) { \
@ -786,6 +807,7 @@ class CmdProxy {
/* ZMQ Streaming Parameters (Receiver<->Client) */
{"rx_datastream", &CmdProxy::rx_datastream},
{"rx_readfreq", &CmdProxy::rx_readfreq},
{"rx_zmqstartfnum", &CmdProxy::rx_zmqstartfnum},
{"rx_zmqport", &CmdProxy::rx_zmqport},
{"zmqport", &CmdProxy::zmqport},
{"rx_zmqip", &CmdProxy::rx_zmqip},
@ -834,10 +856,15 @@ class CmdProxy {
{"inj_ch", &CmdProxy::InjectChannel},
{"vetophoton", &CmdProxy::VetoPhoton},
{"vetoref", &CmdProxy::VetoReference},
{"vetofile", &CmdProxy::VetoFile},
{"burstmode", &CmdProxy::BurstMode},
{"cdsgain", &CmdProxy::cdsgain},
{"filter", &CmdProxy::filter},
{"currentsource", &CmdProxy::currentsource},
{"timingsource", &CmdProxy::timingsource},
{"veto", &CmdProxy::veto},
{"confadc", &CmdProxy::ConfigureADC},
{"badchannels", &CmdProxy::BadChannels},
/* Mythen3 Specific */
{"counters", &CmdProxy::Counters},
@ -1013,7 +1040,10 @@ class CmdProxy {
std::string InjectChannel(int action);
std::string VetoPhoton(int action);
std::string VetoReference(int action);
std::string VetoFile(int action);
std::string BurstMode(int action);
std::string ConfigureADC(int action);
std::string BadChannels(int action);
/* Mythen3 Specific */
std::string Counters(int action);
std::string GateDelay(int action);
@ -1087,7 +1117,7 @@ class CmdProxy {
"g2_lc_hg | g2_lc_lg | g4_hg | g4_lg]"
"\n\t[Eiger] Use threshold or thresholdnotb.");
EXECUTE_SET_COMMAND_NOID_1ARG(
EXECUTE_SET_COMMAND_1ARG(
trimbits, loadTrimbits,
"[fname]\n\t[Eiger][Mythen3] Loads the trimbit file to detector. If no "
"extension specified, serial number of each module is attached.");
@ -1119,10 +1149,6 @@ class CmdProxy {
"ns|us|ms|s]\n\t[Jungfrau][Gotthard][Mythen3][Gotthard2][Ctb]["
"Moench] Delay after trigger");
TIME_COMMAND(burstperiod, getBurstPeriod, setBurstPeriod,
"[duration] [(optional unit) ns|us|ms|s]\n\t[Gotthard2] Burst "
"period. Only in burst mode and auto timing mode.");
GET_COMMAND(framesl, getNumberOfFramesLeft,
"\n\t[Gotthard][Jungfrau][Mythen3][Gotthard2][CTB][Moench] "
"Number of frames left in acquisition."
@ -1759,6 +1785,10 @@ class CmdProxy {
"[nth frame]\n\tStream out every nth frame. Default is 1. 0 means "
"streaming every 200 ms and discarding frames in this interval.");
INTEGER_COMMAND(
rx_zmqstartfnum, getRxZmqStartingFrame, setRxZmqStartingFrame, StringTo<int>,
"[fnum]\n\tThe starting frame index to stream out. 0 by default, which streams the first frame in an acquisition, and then depending on the rx zmq frequency/ timer");
INTEGER_COMMAND(
rx_zmqport, getRxZmqPort, setRxZmqPort, StringTo<int>,
"[port]\n\tZmq port for data to be streamed out of the receiver. Also "
@ -1906,6 +1936,18 @@ class CmdProxy {
"timing mode and burst mode. Use timing command to set timing mode and "
"burstmode command to set burst mode.");
TIME_COMMAND(burstperiod, getBurstPeriod, setBurstPeriod,
"[duration] [(optional unit) ns|us|ms|s]\n\t[Gotthard2] Burst "
"period. Only in burst mode and auto timing mode.");
INTEGER_COMMAND(cdsgain, getCDSGain, setCDSGain, StringTo<bool>,
"[0, 1]\n\t[Gotthard2] Enable or disable CDS gain. Default "
"is disabled.");
INTEGER_COMMAND(
filter, getFilter, setFilter, StringTo<int>,
"[0|1|2|3]\n\t[Gotthard2] Set filter resistor. Default is 0.");
INTEGER_COMMAND(currentsource, getCurrentSource, setCurrentSource,
StringTo<int>,
"[0, 1]\n\t[Gotthard2] Enable or disable current source. "

View File

@ -954,6 +954,14 @@ void Detector::setRxZmqTimer(int time_in_ms, Positions pos) {
pimpl->Parallel(&Module::setReceiverStreamingTimer, pos, time_in_ms);
}
Result<int> Detector::getRxZmqStartingFrame(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverStreamingStartingFrame, pos);
}
void Detector::setRxZmqStartingFrame(int fnum, Positions pos) {
pimpl->Parallel(&Module::setReceiverStreamingStartingFrame, pos, fnum);
}
Result<int> Detector::getRxZmqPort(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverStreamingPort, pos);
}
@ -1297,6 +1305,11 @@ void Detector::setVetoReference(const int gainIndex, const int value,
pimpl->Parallel(&Module::setVetoReference, pos, gainIndex, value);
}
void Detector::setVetoFile(const int chipIndex, const std::string &fname,
Positions pos) {
pimpl->Parallel(&Module::setVetoFile, pos, chipIndex, fname);
}
Result<defs::burstMode> Detector::getBurstMode(Positions pos) {
return pimpl->Parallel(&Module::getBurstMode, pos);
}
@ -1305,6 +1318,22 @@ void Detector::setBurstMode(defs::burstMode value, Positions pos) {
pimpl->Parallel(&Module::setBurstMode, pos, value);
}
Result<bool> Detector::getCDSGain(Positions pos) const {
return pimpl->Parallel(&Module::getCDSGain, pos);
}
void Detector::setCDSGain(bool value, Positions pos) {
pimpl->Parallel(&Module::setCDSGain, pos, value);
}
Result<int> Detector::getFilter(Positions pos) const {
return pimpl->Parallel(&Module::getFilter, pos);
}
void Detector::setFilter(int value, Positions pos) {
pimpl->Parallel(&Module::setFilter, pos, value);
}
Result<bool> Detector::getCurrentSource(Positions pos) const {
return pimpl->Parallel(&Module::getCurrentSource, pos);
}
@ -1329,6 +1358,27 @@ void Detector::setVeto(bool enable, Positions pos) {
pimpl->Parallel(&Module::setVeto, pos, enable);
}
Result<int> Detector::getADCConfiguration(const int chipIndex,
const int adcIndex,
Positions pos) const {
return pimpl->Parallel(&Module::getADCConfiguration, pos, chipIndex,
adcIndex);
}
void Detector::setADCConfiguration(const int chipIndex, const int adcIndex,
const int value, Positions pos) {
pimpl->Parallel(&Module::setADCConfiguration, pos, chipIndex, adcIndex,
value);
}
void Detector::getBadChannels(const std::string &fname, Positions pos) const {
pimpl->Parallel(&Module::getBadChannels, pos, fname);
}
void Detector::setBadChannels(const std::string &fname, Positions pos) {
pimpl->Parallel(&Module::setBadChannels, pos, fname);
}
// Mythen3 Specific
Result<uint32_t> Detector::getCounterMask(Positions pos) const {

View File

@ -967,6 +967,18 @@ void Module::setReceiverStreamingTimer(int time_in_ms) {
sendToReceiver<int>(F_RECEIVER_STREAMING_TIMER, time_in_ms);
}
int Module::getReceiverStreamingStartingFrame() {
return sendToReceiver<int>(F_GET_RECEIVER_STREAMING_START_FNUM);
}
void Module::setReceiverStreamingStartingFrame(int fnum) {
if (fnum < 0) {
throw RuntimeError("Invalid streaming starting frame number " +
std::to_string(fnum));
}
sendToReceiver(F_SET_RECEIVER_STREAMING_START_FNUM, fnum, nullptr);
}
int Module::getReceiverStreamingPort() {
return sendToReceiver<int>(F_GET_RECEIVER_STREAMING_PORT);
}
@ -1400,18 +1412,17 @@ std::vector<int> Module::getVetoPhoton(const int chipIndex) {
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Detector " + std::to_string(moduleId) +
" returned error: " + std::string(mess));
} else {
int nch = -1;
client.Receive(&nch, sizeof(nch));
int adus[nch];
memset(adus, 0, sizeof(adus));
client.Receive(adus, sizeof(adus));
std::vector<int> retvals(adus, adus + nch);
LOG(logDEBUG1) << "Getting veto photon [" << chipIndex << "]: " << nch
<< " channels\n";
return retvals;
}
int nch = -1;
client.Receive(&nch, sizeof(nch));
int adus[nch];
memset(adus, 0, sizeof(adus));
client.Receive(adus, sizeof(adus));
std::vector<int> retvals(adus, adus + nch);
LOG(logDEBUG1) << "Getting veto photon [" << chipIndex << "]: " << nch
<< " channels\n";
return retvals;
}
void Module::setVetoPhoton(const int chipIndex, const int numPhotons,
@ -1460,7 +1471,8 @@ void Module::setVetoPhoton(const int chipIndex, const int numPhotons,
// first line: caluclate gain index from gain thresholds from file
if (firstLine) {
int g0 = -1, g1 = -1;
if (!(ss >> g0 >> g1)) {
ss >> g0 >> g1;
if (ss.fail()) {
throw RuntimeError(
"Could not set veto photon. Invalid gain thresholds");
}
@ -1477,7 +1489,8 @@ void Module::setVetoPhoton(const int chipIndex, const int numPhotons,
// read pedestal and gain values
else {
double p[3] = {-1, -1, -1}, g[3] = {-1, -1, -1};
if (!(ss >> p[0] >> p[1] >> p[2] >> g[0] >> g[1] >> g[2])) {
ss >> p[0] >> p[1] >> p[2] >> g[0] >> g[1] >> g[2];
if (ss.fail()) {
throw RuntimeError("Could not set veto photon. Invalid "
"pedestal or gain values for channel " +
std::to_string(nRead));
@ -1521,6 +1534,83 @@ void Module::setVetoReference(const int gainIndex, const int value) {
sendToDetector(F_SET_VETO_REFERENCE, args, nullptr);
}
void Module::setVetoFile(const int chipIndex, const std::string &fname) {
if (shm()->myDetectorType != GOTTHARD2) {
throw RuntimeError(
"Set Veto file is not implemented for this detector");
}
if (chipIndex < -1 || chipIndex >= shm()->nChip.x) {
throw RuntimeError("Could not set veto file. Invalid chip index: " +
std::to_string(chipIndex));
}
std::ifstream infile(fname.c_str());
if (!infile.is_open()) {
throw RuntimeError("Could not set veto file for chip " +
std::to_string(chipIndex) +
". Could not open file: " + fname);
}
std::ifstream input_file(fname);
if (!input_file.is_open()) {
throw RuntimeError("Could not open veto file " + fname +
" for reading");
}
int ch = shm()->nChan.x;
int nRead = 0;
int gainIndices[ch];
memset(gainIndices, 0, sizeof(gainIndices));
int values[ch];
memset(values, 0, sizeof(values));
for (std::string line; std::getline(input_file, line);) {
if (line.find('#') != std::string::npos) {
line.erase(line.find('#'));
}
LOG(logDEBUG1) << "line after removing comments:\n\t" << line;
if (line.length() > 1) {
// convert command and string to a vector
std::istringstream iss(line);
std::string val;
iss >> gainIndices[nRead] >> val;
if (iss.fail()) {
throw RuntimeError("Could not set veto file. Invalid gain "
"or reference value for channel " +
std::to_string(nRead));
}
try {
values[nRead] = StringTo<int>(val);
} catch (...) {
throw RuntimeError("Could not set veto file. Invalid value " +
val + " for channel " +
std::to_string(nRead));
}
++nRead;
if (nRead >= ch) {
break;
}
}
}
int fnum = F_SET_VETO_FILE;
int ret = FAIL;
int args[]{chipIndex, ch};
LOG(logDEBUG) << "Sending veto file value to detector [chip:" << chipIndex
<< "]: " << args;
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(&fnum, sizeof(fnum));
client.Send(args, sizeof(args));
client.Send(gainIndices, sizeof(gainIndices));
client.Send(values, sizeof(values));
client.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Detector " + std::to_string(moduleId) +
" returned error: " + std::string(mess));
}
}
slsDetectorDefs::burstMode Module::getBurstMode() {
auto r = sendToDetector<int>(F_GET_BURST_MODE);
return static_cast<slsDetectorDefs::burstMode>(r);
@ -1534,6 +1624,18 @@ void Module::setBurstMode(slsDetectorDefs::burstMode value) {
}
}
bool Module::getCDSGain() { return sendToDetector<int>(F_GET_CDS_GAIN); }
void Module::setCDSGain(bool value) {
sendToDetector(F_SET_CDS_GAIN, static_cast<int>(value), nullptr);
}
int Module::getFilter() { return sendToDetector<int>(F_GET_FILTER); }
void Module::setFilter(int value) {
sendToDetector(F_SET_FILTER, value, nullptr);
}
bool Module::getCurrentSource() {
return sendToDetector<int>(F_GET_CURRENT_SOURCE);
}
@ -1557,6 +1659,101 @@ void Module::setVeto(bool enable) {
sendToDetector(F_SET_VETO, static_cast<int>(enable), nullptr);
}
int Module::getADCConfiguration(const int chipIndex, const int adcIndex) {
int args[]{chipIndex, adcIndex};
return sendToDetector<int>(F_GET_ADC_CONFIGURATION, args);
}
void Module::setADCConfiguration(const int chipIndex, const int adcIndex,
int value) {
int args[]{chipIndex, adcIndex, value};
sendToDetector(F_SET_ADC_CONFIGURATION, args, nullptr);
}
void Module::getBadChannels(const std::string &fname) {
LOG(logDEBUG1) << "Getting bad channels to " << fname;
int fnum = F_GET_BAD_CHANNELS;
int ret = FAIL;
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(&fnum, sizeof(fnum));
client.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Detector " + std::to_string(moduleId) +
" returned error: " + std::string(mess));
}
// receive badchannels
int nch = -1;
std::vector<int> badchannels;
client.Receive(&nch, sizeof(nch));
if (nch > 0) {
int temp[nch];
memset(temp, 0, sizeof(temp));
client.Receive(temp, sizeof(temp));
badchannels.insert(badchannels.end(), &temp[0], &temp[nch]);
for (int i = 0; i < (int)badchannels.size(); ++i) {
LOG(logDEBUG1) << i << ":" << badchannels[i];
}
}
// save to file
std::ofstream outfile;
outfile.open(fname.c_str(), std::ios_base::out);
if (!outfile.is_open()) {
throw RuntimeError("Could not create file to save pattern");
}
for (int i = 0; i < nch; ++i) {
outfile << badchannels[i] << '\n';
}
LOG(logDEBUG1) << nch << " bad channels saved to file";
}
void Module::setBadChannels(const std::string &fname) {
// read bad channels file
std::ifstream input_file(fname);
if (!input_file.is_open()) {
throw RuntimeError("Could not open bad channels file " + fname +
" for reading");
}
std::vector<int> badchannels;
for (std::string line; std::getline(input_file, line);) {
if (line.find(' ') != std::string::npos) {
line.erase(line.find(' '));
}
if (line.length() >= 1) {
std::istringstream iss(line);
int ival = 0;
iss >> ival;
if (iss.fail()) {
throw RuntimeError("Could not load bad channels file. Invalid "
"channel number at position " +
std::to_string(badchannels.size()));
}
badchannels.push_back(ival);
}
}
// send bad channels to module
int fnum = F_SET_BAD_CHANNELS;
int ret = FAIL;
int nch = badchannels.size();
LOG(logDEBUG1) << "Sending bad channels to detector, nch:" << nch;
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(&fnum, sizeof(fnum));
client.Send(&nch, sizeof(nch));
if (nch > 0) {
client.Send(badchannels.data(), sizeof(int) * nch);
}
client.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Detector " + std::to_string(moduleId) +
" returned error: " + std::string(mess));
}
}
// Mythen3 Specific
uint32_t Module::getCounterMask() {

View File

@ -274,6 +274,8 @@ class Module : public virtual slsDetectorDefs {
void setReceiverStreamingFrequency(int freq);
int getReceiverStreamingTimer();
void setReceiverStreamingTimer(int time_in_ms = 200);
int getReceiverStreamingStartingFrame();
void setReceiverStreamingStartingFrame(int fnum);
int getReceiverStreamingPort();
void setReceiverStreamingPort(int port);
sls::IpAddr getReceiverStreamingIP();
@ -373,14 +375,24 @@ class Module : public virtual slsDetectorDefs {
void setVetoPhoton(const int chipIndex, const int numPhotons,
const int energy, const std::string &fname);
void setVetoReference(const int gainIndex, const int value);
void setVetoFile(const int chipIndex, const std::string &fname);
burstMode getBurstMode();
void setBurstMode(burstMode value);
bool getCDSGain();
void setCDSGain(bool value);
int getFilter();
void setFilter(int value);
bool getCurrentSource();
void setCurrentSource(bool value);
slsDetectorDefs::timingSourceType getTimingSource();
void setTimingSource(slsDetectorDefs::timingSourceType value);
bool getVeto();
void setVeto(bool enable);
int getADCConfiguration(const int chipIndex, const int adcIndex);
void setADCConfiguration(const int chipIndex, const int adcIndex,
int value);
void getBadChannels(const std::string &fname);
void setBadChannels(const std::string &fname);
/**************************************************
* *

View File

@ -343,6 +343,20 @@ TEST_CASE("vetoref", "[.cmd][.new]") {
}
}
TEST_CASE("vetofile", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
REQUIRE_THROWS(proxy.Call("vetofile", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vetofile", {"12", "/tmp/bla.txt"}, -1,
PUT)); // invalid chip index
} else {
REQUIRE_THROWS(proxy.Call("vetofile", {"-1"}, -1, GET));
}
}
TEST_CASE("burstmode", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
@ -374,6 +388,66 @@ TEST_CASE("burstmode", "[.cmd][.new]") {
}
}
TEST_CASE("cdsgain", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto prev_val = det.getCDSGain();
{
std::ostringstream oss;
proxy.Call("cdsgain", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "cdsgain 1\n");
}
{
std::ostringstream oss;
proxy.Call("cdsgain", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "cdsgain 0\n");
}
{
std::ostringstream oss;
proxy.Call("cdsgain", {}, -1, GET, oss);
REQUIRE(oss.str() == "cdsgain 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setCDSGain(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("cdsgain", {}, -1, GET));
}
}
TEST_CASE("filter", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto prev_val = det.getFilter();
{
std::ostringstream oss;
proxy.Call("filter", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "filter 1\n");
}
{
std::ostringstream oss;
proxy.Call("filter", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "filter 0\n");
}
{
std::ostringstream oss;
proxy.Call("filter", {}, -1, GET, oss);
REQUIRE(oss.str() == "filter 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setFilter(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("filter", {}, -1, GET));
}
}
TEST_CASE("currentsource", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
@ -462,4 +536,65 @@ TEST_CASE("veto", "[.cmd][.new]") {
} else {
REQUIRE_THROWS(proxy.Call("veto", {}, -1, GET));
}
}
TEST_CASE("confadc", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
int ndet = det.size();
int nchip = 10;
int nadc = 32;
int prev_val[ndet][nchip][nadc];
for (int i = 0; i != ndet; ++i) {
for (int j = 0; j != nchip; ++j) {
for (int k = 0; k != nadc; ++k) {
prev_val[i][j][k] =
det.getADCConfiguration(j, k, {i}).squash();
}
}
}
REQUIRE_THROWS(proxy.Call("confadc", {"11", "2", "0x3ff"}, -1,
PUT)); // invalid chip index
REQUIRE_THROWS(proxy.Call("confadc", {"-1", "10", "0x3ff"}, -1,
PUT)); // invalid adc index
REQUIRE_THROWS(proxy.Call("confadc", {"-1", "10", "0x1fff"}, -1,
PUT)); // invalid value
{
std::ostringstream oss;
proxy.Call("confadc", {"-1", "-1", "0x11"}, -1, PUT, oss);
REQUIRE(oss.str() == "confadc [-1, -1, 0x11]\n");
}
{
std::ostringstream oss;
proxy.Call("confadc", {"2", "3"}, -1, GET, oss);
REQUIRE(oss.str() == "confadc 0x11\n");
}
for (int i = 0; i != ndet; ++i) {
for (int j = 0; j != nchip; ++j) {
for (int k = 0; k != nadc; ++k) {
det.setADCConfiguration(j, k, prev_val[i][j][k], {i});
}
}
}
} else {
REQUIRE_THROWS(proxy.Call("confadc", {}, -1, GET));
}
}
TEST_CASE("badchannels", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
REQUIRE_THROWS(proxy.Call("badchannels", {}, -1, GET));
REQUIRE_NOTHROW(proxy.Call("badchannels", {"/tmp/bla.txt"}, -1, GET));
REQUIRE_NOTHROW(proxy.Call("badchannels", {"/tmp/bla.txt"}, -1, PUT));
} else {
REQUIRE_THROWS(proxy.Call("badchannels", {}, -1, GET));
}
}

View File

@ -620,6 +620,30 @@ TEST_CASE("rx_readfreq", "[.cmd][.rx][.new]") {
}
}
TEST_CASE("rx_zmqstartfnum", "[.cmd][.rx][.new]") {
Detector det;
CmdProxy proxy(&det);
auto prev_val = det.getRxZmqStartingFrame();
{
std::ostringstream oss;
proxy.Call("rx_zmqstartfnum", {"5"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqstartfnum 5\n");
}
{
std::ostringstream oss;
proxy.Call("rx_zmqstartfnum", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_zmqstartfnum 5\n");
}
{
std::ostringstream oss;
proxy.Call("rx_zmqstartfnum", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_zmqstartfnum 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setRxZmqStartingFrame(prev_val[i], {i});
}
}
TEST_CASE("rx_zmqport", "[.cmd][.rx][.new]") {
Detector det;
CmdProxy proxy(&det);

View File

@ -199,6 +199,8 @@ int ClientInterface::functionTable(){
flist[F_SET_RECEIVER_NUM_GATES] = &ClientInterface::set_num_gates;
flist[F_SET_RECEIVER_GATE_DELAY] = &ClientInterface::set_gate_delay;
flist[F_GET_RECEIVER_THREAD_IDS] = &ClientInterface::get_thread_ids;
flist[F_GET_RECEIVER_STREAMING_START_FNUM] = &ClientInterface::get_streaming_start_fnum;
flist[F_SET_RECEIVER_STREAMING_START_FNUM] = &ClientInterface::set_streaming_start_fnum;
for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) {
LOG(logDEBUG1) << "function fnum: " << i << " (" <<
@ -1707,4 +1709,25 @@ int ClientInterface::get_thread_ids(Interface &socket) {
auto retval = impl()->getThreadIds();
LOG(logDEBUG1) << "thread ids retval: " << sls::ToString(retval);
return socket.sendResult(retval);
}
}
int ClientInterface::get_streaming_start_fnum(Interface &socket) {
int retval = impl()->getStreamingStartingFrameNumber();
LOG(logDEBUG1) << "streaming start fnum:" << retval;
return socket.sendResult(retval);
}
int ClientInterface::set_streaming_start_fnum(Interface &socket) {
auto index = socket.Receive<int>();
if (index < 0) {
throw RuntimeError("Invalid streaming start frame number: " +
std::to_string(index));
}
verifyIdle(socket);
LOG(logDEBUG1) << "Setting streaming start fnum: " << index;
impl()->setStreamingStartingFrameNumber(index);
int retval = impl()->getStreamingStartingFrameNumber();
validate(index, retval, "set streaming start fnum", DEC);
return socket.Send(OK);
}

View File

@ -155,6 +155,8 @@ class ClientInterface : private virtual slsDetectorDefs {
int set_num_gates(sls::ServerInterface &socket);
int set_gate_delay(sls::ServerInterface &socket);
int get_thread_ids(sls::ServerInterface &socket);
int get_streaming_start_fnum(sls::ServerInterface &socket);
int set_streaming_start_fnum(sls::ServerInterface &socket);
Implementation *impl() {
if (receiver != nullptr) {

View File

@ -24,16 +24,17 @@ const std::string DataProcessor::TypeName = "DataProcessor";
DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo *f,
fileFormat *ftype, bool fwenable, bool *mfwenable,
bool *dsEnable, uint32_t *dr, uint32_t *freq,
uint32_t *timer, bool *fp, bool *act,
bool *depaden, bool *sm, bool *qe,
uint32_t *timer, uint32_t *sfnum, bool *fp,
bool *act, bool *depaden, bool *sm, bool *qe,
std::vector<int> *cdl, int *cdo, int *cad)
: ThreadObject(ind, TypeName), fifo(f), myDetectorType(dtype),
dataStreamEnable(dsEnable), fileFormatType(ftype),
fileWriteEnable(fwenable), masterFileWriteEnable(mfwenable),
dynamicRange(dr), streamingFrequency(freq), streamingTimerInMs(timer),
activated(act), deactivatedPaddingEnable(depaden), silentMode(sm),
quadEnable(qe), framePadding(fp), ctbDbitList(cdl), ctbDbitOffset(cdo),
ctbAnalogDataBytes(cad) {
streamingStartFnum(sfnum), activated(act),
deactivatedPaddingEnable(depaden), silentMode(sm), quadEnable(qe),
framePadding(fp), ctbDbitList(cdl), ctbDbitOffset(cdo),
ctbAnalogDataBytes(cad), firstStreamerFrame(false) {
LOG(logDEBUG) << "DataProcessor " << ind << " created";
memset((void *)&timerBegin, 0, sizeof(timespec));
}
@ -60,6 +61,7 @@ void DataProcessor::ResetParametersforNewAcquisition() {
numFramesCaught = 0;
firstIndex = 0;
currentFrameIndex = 0;
firstStreamerFrame = true;
}
void DataProcessor::RecordFirstIndex(uint64_t fnum) {
@ -182,13 +184,21 @@ void DataProcessor::ThreadExecution() {
return;
}
ProcessAnImage(buffer);
uint64_t fnum = ProcessAnImage(buffer);
// stream (if time/freq to stream) or free
if (*dataStreamEnable && SendToStreamer())
if (*dataStreamEnable && SendToStreamer()) {
// if first frame to stream, add frame index to fifo header (might not
// be the first)
if (firstStreamerFrame) {
firstStreamerFrame = false;
(*((uint32_t *)(buffer + FIFO_DATASIZE_NUMBYTES))) =
(uint32_t)(fnum - firstIndex);
}
fifo->PushAddressToStream(buffer);
else
} else {
fifo->FreeAddress(buffer);
}
}
void DataProcessor::StopProcessing(char *buf) {
@ -206,7 +216,7 @@ void DataProcessor::StopProcessing(char *buf) {
LOG(logDEBUG1) << index << ": Processing Completed";
}
void DataProcessor::ProcessAnImage(char *buf) {
uint64_t DataProcessor::ProcessAnImage(char *buf) {
auto *rheader = (sls_receiver_header *)(buf + FIFO_HEADER_NUMBYTES);
sls_detector_header header = rheader->detHeader;
@ -221,7 +231,6 @@ void DataProcessor::ProcessAnImage(char *buf) {
if (!startedFlag) {
RecordFirstIndex(fnum);
if (*dataStreamEnable) {
// restart timer
clock_gettime(CLOCK_REALTIME, &timerBegin);
@ -229,7 +238,7 @@ void DataProcessor::ProcessAnImage(char *buf) {
timerBegin.tv_nsec -= ((*streamingTimerInMs) % 1000) * 1000000;
// to send first image
currentFreqCount = *streamingFrequency;
currentFreqCount = *streamingFrequency - *streamingStartFnum;
}
}
@ -278,6 +287,7 @@ void DataProcessor::ProcessAnImage(char *buf) {
// stopReceiver tcp)
}
}
return fnum;
}
bool DataProcessor::SendToStreamer() {

View File

@ -37,6 +37,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
* @param dr pointer to dynamic range
* @param freq pointer to streaming frequency
* @param timer pointer to timer if streaming frequency is random
* @param sfnum pointer to streaming starting fnum
* @param fp pointer to frame padding enable
* @param act pointer to activated
* @param depaden pointer to deactivated padding enable
@ -48,9 +49,9 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
*/
DataProcessor(int ind, detectorType dtype, Fifo *f, fileFormat *ftype,
bool fwenable, bool *mfwenable, bool *dsEnable, uint32_t *dr,
uint32_t *freq, uint32_t *timer, bool *fp, bool *act,
bool *depaden, bool *sm, bool *qe, std::vector<int> *cdl,
int *cdo, int *cad);
uint32_t *freq, uint32_t *timer, uint32_t *sfnum, bool *fp,
bool *act, bool *depaden, bool *sm, bool *qe,
std::vector<int> *cdl, int *cdo, int *cad);
/**
* Destructor
@ -201,8 +202,9 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
* Process an image popped from fifo,
* write to file if fw enabled & update parameters
* @param buf address of pointer
* @returns frame number
*/
void ProcessAnImage(char *buf);
uint64_t ProcessAnImage(char *buf);
/**
* Calls CheckTimer and CheckCount for streaming frequency and timer
@ -275,6 +277,9 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
/** Pointer to the timer if Streaming frequency is random */
uint32_t *streamingTimerInMs;
/** Pointer to streaming starting fnum */
uint32_t *streamingStartFnum;
/** Current frequency count */
uint32_t currentFreqCount{0};
@ -319,6 +324,9 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
/** Frame Number of latest processed frame number */
std::atomic<uint64_t> currentFrameIndex{0};
/** first streamer frame to add frame index in fifo header */
bool firstStreamerFrame{false};
// call back
/**
* Call back for raw data

View File

@ -48,11 +48,14 @@ void DataStreamer::ResetParametersforNewAcquisition(const std::string &fname) {
}
}
void DataStreamer::RecordFirstIndex(uint64_t fnum) {
void DataStreamer::RecordFirstIndex(uint64_t fnum, char *buf) {
startedFlag = true;
firstIndex = fnum;
// streamer first index needn't be
uint64_t firstVal = fnum - (*((uint32_t *)(buf + FIFO_DATASIZE_NUMBYTES)));
LOG(logDEBUG1) << index << " First Index: " << firstIndex;
firstIndex = firstVal;
LOG(logDEBUG1) << index << " First Index: " << firstIndex
<< ", First Streamer Index:" << fnum;
}
void DataStreamer::SetGeneralData(GeneralData *g) { generalData = g; }
@ -137,7 +140,7 @@ void DataStreamer::ProcessAnImage(char *buf) {
LOG(logDEBUG1) << "DataStreamer " << index << ": fnum:" << fnum;
if (!startedFlag) {
RecordFirstIndex(fnum);
RecordFirstIndex(fnum, buf);
}
// shortframe gotthard

View File

@ -101,9 +101,10 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
private:
/**
* Record First Index
* @param fnum frame index to record
* @param fnum current frame number
* @param buf get frame index from buffer to calculate first index to record
*/
void RecordFirstIndex(uint64_t fnum);
void RecordFirstIndex(uint64_t fnum, char *buf);
/**
* Thread Exeution for DataStreamer Class

View File

@ -91,6 +91,7 @@ void Implementation::InitializeMembers() {
dataStreamEnable = false;
streamingFrequency = 1;
streamingTimerInMs = DEFAULT_STREAMING_TIMER_IN_MS;
streamingStartFnum = 0;
streamingPort = 0;
streamingSrcIP = sls::IpAddr{};
@ -292,7 +293,7 @@ void Implementation::setDetectorType(const detectorType d) {
dataProcessor.push_back(sls::make_unique<DataProcessor>(
i, myDetectorType, fifo_ptr, &fileFormatType, fileWriteEnable,
&masterFileWriteEnable, &dataStreamEnable, &dynamicRange,
&streamingFrequency, &streamingTimerInMs, &framePadding,
&streamingFrequency, &streamingTimerInMs, &streamingStartFnum, &framePadding,
&activated, &deactivatedPaddingEnable, &silentMode, &quadEnable,
&ctbDbitList, &ctbDbitOffset, &ctbAnalogDataBytes));
} catch (...) {
@ -1017,7 +1018,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) {
dataProcessor.push_back(sls::make_unique<DataProcessor>(
i, myDetectorType, fifo_ptr, &fileFormatType,
fileWriteEnable, &masterFileWriteEnable, &dataStreamEnable,
&dynamicRange, &streamingFrequency, &streamingTimerInMs,
&dynamicRange, &streamingFrequency, &streamingTimerInMs, &streamingStartFnum,
&framePadding, &activated, &deactivatedPaddingEnable,
&silentMode, &quadEnable, &ctbDbitList, &ctbDbitOffset,
&ctbAnalogDataBytes));
@ -1232,6 +1233,18 @@ void Implementation::setStreamingTimer(const uint32_t time_in_ms) {
LOG(logINFO) << "Streamer Timer: " << streamingTimerInMs;
}
uint32_t Implementation::getStreamingStartingFrameNumber() const {
LOG(logDEBUG3) << __SHORT_AT__ << " called";
return streamingStartFnum;
}
void Implementation::setStreamingStartingFrameNumber(const uint32_t fnum) {
if (streamingStartFnum != fnum) {
streamingStartFnum = fnum;
}
LOG(logINFO) << "Streaming Start Frame num: " << streamingStartFnum;
}
uint32_t Implementation::getStreamingPort() const {
LOG(logDEBUG3) << __SHORT_AT__ << " called";
return streamingPort;

View File

@ -121,6 +121,8 @@ class Implementation : private virtual slsDetectorDefs {
void setStreamingFrequency(const uint32_t freq);
uint32_t getStreamingTimer() const;
void setStreamingTimer(const uint32_t time_in_ms);
uint32_t getStreamingStartingFrameNumber() const;
void setStreamingStartingFrameNumber(const uint32_t fnum);
uint32_t getStreamingPort() const;
void setStreamingPort(const uint32_t i);
sls::IpAddr getStreamingSourceIP() const;
@ -299,6 +301,7 @@ class Implementation : private virtual slsDetectorDefs {
bool dataStreamEnable;
uint32_t streamingFrequency;
uint32_t streamingTimerInMs;
uint32_t streamingStartFnum;
uint32_t streamingPort;
sls::IpAddr streamingSrcIP;
std::map<std::string, std::string> additionalJsonHeader;

View File

@ -290,6 +290,7 @@ template <> defs::timingSourceType StringTo(const std::string &s);
template <> uint32_t StringTo(const std::string &s);
template <> uint64_t StringTo(const std::string &s);
template <> int StringTo(const std::string &s);
template <> bool StringTo(const std::string &s);
template <> int64_t StringTo(const std::string &s);
/** For types with a .str() method use this for conversion */

View File

@ -203,6 +203,15 @@ enum detFuncs {
F_GET_SCAN,
F_SET_SCAN,
F_GET_SCAN_ERROR_MESSAGE,
F_GET_CDS_GAIN,
F_SET_CDS_GAIN,
F_GET_FILTER,
F_SET_FILTER,
F_SET_VETO_FILE,
F_GET_ADC_CONFIGURATION,
F_SET_ADC_CONFIGURATION,
F_GET_BAD_CHANNELS,
F_SET_BAD_CHANNELS,
NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this
@ -299,6 +308,8 @@ enum detFuncs {
F_SET_RECEIVER_NUM_GATES,
F_SET_RECEIVER_GATE_DELAY,
F_GET_RECEIVER_THREAD_IDS,
F_GET_RECEIVER_STREAMING_START_FNUM,
F_SET_RECEIVER_STREAMING_START_FNUM,
NUM_REC_FUNCTIONS
};
@ -504,6 +515,15 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_GET_SCAN: return "F_GET_SCAN";
case F_SET_SCAN: return "F_SET_SCAN";
case F_GET_SCAN_ERROR_MESSAGE: return "F_GET_SCAN_ERROR_MESSAGE";
case F_GET_CDS_GAIN: return "F_GET_CDS_GAIN";
case F_SET_CDS_GAIN: return "F_SET_CDS_GAIN";
case F_GET_FILTER: return "F_GET_FILTER";
case F_SET_FILTER: return "F_SET_FILTER";
case F_SET_VETO_FILE: return "F_SET_VETO_FILE";
case F_SET_ADC_CONFIGURATION: return "F_SET_ADC_CONFIGURATION";
case F_GET_ADC_CONFIGURATION: return "F_GET_ADC_CONFIGURATION";
case F_GET_BAD_CHANNELS: return "F_GET_BAD_CHANNELS";
case F_SET_BAD_CHANNELS: return "F_SET_BAD_CHANNELS";
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";
@ -600,6 +620,9 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_SET_RECEIVER_GATE_DELAY: return "F_SET_RECEIVER_GATE_DELAY";
case F_GET_RECEIVER_THREAD_IDS: return "F_GET_RECEIVER_THREAD_IDS";
case F_GET_RECEIVER_STREAMING_START_FNUM: return "F_GET_RECEIVER_STREAMING_START_FNUM";
case F_SET_RECEIVER_STREAMING_START_FNUM: return "F_SET_RECEIVER_STREAMING_START_FNUM";
case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS";
default: return "Unknown Function";
}

View File

@ -3,10 +3,10 @@
#define APILIB 0x200409
#define APIRECEIVER 0x200409
#define APIGUI 0x200409
#define APIJUNGFRAU 0x200716
#define APICTB 0x200716
#define APIMOENCH 0x200707
#define APIGOTTHARD 0x200716
#define APIMYTHEN3 0x200716
#define APIGOTTHARD2 0x200716
#define APIEIGER 0x200716
#define APICTB 0x200717
#define APIGOTTHARD 0x200717
#define APIGOTTHARD2 0x200717
#define APIJUNGFRAU 0x200717
#define APIMYTHEN3 0x200717
#define APIMOENCH 0x200717
#define APIEIGER 0x200717

View File

@ -891,6 +891,18 @@ template <> int StringTo(const std::string &s) {
return std::stoi(s, nullptr, base);
}
template <> bool StringTo(const std::string &s) {
int i = std::stoi(s, nullptr, 10);
switch (i) {
case 0:
return false;
case 1:
return true;
default:
throw sls::RuntimeError("Unknown boolean. Expecting be 0 or 1.");
}
}
template <> int64_t StringTo(const std::string &s) {
int base = s.find("0x") != std::string::npos ? 16 : 10;
return std::stol(s, nullptr, base);