gotthard2: vetophoton now has gain thresholds for each row and the get writes to file gain indices and adu for each channel, adus written in dec instead of hex, veto file in server removed and uses vetophoton instead

This commit is contained in:
2020-07-29 13:24:42 +02:00
parent df3ae7f409
commit 74a7ca9b71
13 changed files with 485 additions and 414 deletions

View File

@ -50,6 +50,7 @@ int onChipdacValues[ONCHIP_NDAC][NCHIP] = {};
int injectedChannelsOffset = 0;
int injectedChannelsIncrement = 0;
int vetoReference[NCHIP][NCHAN];
int vetoGainIndices[NCHIP][NCHAN];
uint8_t adcConfiguration[NCHIP][NADC];
int burstMode = BURST_INTERNAL;
int64_t numTriggersReg = 1;
@ -387,6 +388,7 @@ void setupDetector() {
for (int i = 0; i < NCHIP; ++i) {
for (int j = 0; j < NCHAN; ++j) {
vetoReference[i][j] = 0;
vetoGainIndices[i][j] = 0;
}
for (int j = 0; j < NADC; ++j) {
adcConfiguration[i][j] = 0;
@ -1786,49 +1788,23 @@ void getInjectedChannels(int *offset, int *increment) {
int setVetoReference(int gainIndex, int value) {
LOG(logINFO, ("Setting veto reference [chip:-1, G%d, value:0x%x]\n",
gainIndex, value));
int vals[NCHAN];
memset(vals, 0, sizeof(vals));
int values[NCHAN];
memset(values, 0, sizeof(values));
int gainIndices[NCHAN];
memset(gainIndices, 0, sizeof(gainIndices));
for (int ich = 0; ich < NCHAN; ++ich) {
vals[ich] = value;
values[ich] = value;
gainIndices[ich] = gainIndex;
}
return setVetoPhoton(-1, gainIndex, vals);
return configureASICVetoReference(-1, gainIndices, values);
}
int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
LOG(logINFO,
("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]));
}
return configureASICVetoReference(chipIndex, values);
int setVetoPhoton(int chipIndex, int *gainIndices, int *values) {
return configureASICVetoReference(chipIndex, gainIndices, 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
const int lenTotalBits = padding + lenBits + ASIC_ADDR_MAX_BITS; // 1800
const int len = lenTotalBits / 8; // 225
int configureASICVetoReference(int chipIndex, int *gainIndices, int *values) {
LOG(logINFO, ("Setting veto photon/file/reference [chip:%d]\n", chipIndex));
// reversing the values sent to the chip
int revValues[NCHAN] = {};
@ -1836,6 +1812,34 @@ int configureASICVetoReference(int chipIndex, int *values) {
revValues[i] = values[NCHAN - 1 - i];
}
// correct gain bits and integrate into revValues
for (int i = 0; i < NCHAN; ++i) {
int gainValue = 0;
switch (gainIndices[i]) {
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 for channel %d\n", gainIndices[i], i));
return FAIL;
}
revValues[i] |= gainValue;
LOG(logDEBUG2, ("Values[%d]: 0x%x\n", i, revValues[i]));
}
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
const int lenTotalBits = padding + lenBits + ASIC_ADDR_MAX_BITS; // 1800
const int len = lenTotalBits / 8; // 225
// assign each bit into 4 + 1792 into byte array
uint8_t commandBytes[lenTotalBits];
memset(commandBytes, 0, sizeof(commandBytes));
@ -1873,6 +1877,7 @@ int configureASICVetoReference(int chipIndex, int *values) {
for (int ichan = 0; ichan < NCHAN; ++ichan) {
for (int ichip = 0; ichip < NCHIP; ++ichip) {
vetoReference[ichip][ichan] = values[ichan];
vetoGainIndices[ichip][ichan] = gainIndices[ichan];
}
}
}
@ -1880,17 +1885,19 @@ int configureASICVetoReference(int chipIndex, int *values) {
// specific chip
else {
for (int ichan = 0; ichan < NCHAN; ++ichan) {
vetoReference[chipIndex][chipIndex] = values[ichan];
;
vetoReference[chipIndex][ichan] = values[ichan];
vetoGainIndices[chipIndex][ichan] = gainIndices[ichan];
}
}
return OK;
}
int getVetoPhoton(int chipIndex, int *retvals) {
int getVetoPhoton(int chipIndex, int *retvals, int *gainRetvals) {
if (chipIndex == -1) {
// if chipindex is -1, check that all values and gain indices are same
for (int i = 0; i < NCHAN; ++i) {
int val = vetoReference[0][i];
int gval = vetoGainIndices[0][i];
for (int j = 1; j < NCHIP; ++j) {
if (vetoReference[j][i] != val) {
LOG(logERROR,
@ -1900,6 +1907,14 @@ int getVetoPhoton(int chipIndex, int *retvals) {
chipIndex, j, i, vetoReference[j][i], i, val));
return FAIL;
}
if (vetoGainIndices[j][i] != gval) {
LOG(logERROR,
("Get vet photon fail for chipIndex:%d. Different "
"gain indices between [nchip:%d, nchan:%d, gain "
"index:%d] and [nchip:0, nchan:%d, gain index:%d]\n",
chipIndex, j, i, vetoGainIndices[j][i], i, gval));
return FAIL;
}
}
}
chipIndex = 0;
@ -1907,35 +1922,12 @@ int getVetoPhoton(int chipIndex, int *retvals) {
memcpy((char *)retvals,
((char *)vetoReference) + NCHAN * chipIndex * sizeof(int),
sizeof(int) * NCHAN);
memcpy((char *)gainRetvals,
((char *)vetoGainIndices) + NCHAN * chipIndex * sizeof(int),
sizeof(int) * NCHAN);
return OK;
}
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));

View File

@ -504,10 +504,9 @@ int getClockDivider(enum CLKINDEX ind);
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 setVetoFile(int chipIndex, int *gainIndices, int *values);
int setVetoPhoton(int chipIndex, int *gainIndices, int *values);
int configureASICVetoReference(int chipIndex, int *gainIndices, int *values);
int getVetoPhoton(int chipIndex, int *retvals, int *gainRetvals);
int setADCConfiguration(int chipIndex, int adcIndex, int value);
int getADCConfiguration(int chipIndex, int adcIndex);
int setBurstModeinFPGA(enum burstMode value);

View File

@ -233,7 +233,6 @@ 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);

View File

@ -350,7 +350,6 @@ void function_table() {
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;
@ -6329,35 +6328,37 @@ int get_inject_channel(int file_des) {
int set_veto_photon(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[3] = {-1, -1, -1};
int args[2] = {-1, -1};
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
int values[args[2]];
int chipIndex = args[0];
int numChannels = args[1];
int gainIndices[args[1]];
memset(gainIndices, 0, sizeof(gainIndices));
if (receiveData(file_des, gainIndices, sizeof(gainIndices), INT32) < 0)
return printSocketReadError();
int values[args[1]];
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],
args[1], args[2]));
LOG(logINFO, ("Setting Veto Photon: [chipIndex:%d, nch:%d]\n", chipIndex,
numChannels));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
int chipIndex = args[0];
int gainIndex = args[1];
int numChannels = args[2];
if (chipIndex < -1 || chipIndex >= NCHIP) {
ret = FAIL;
sprintf(mess, "Could not set veto photon. Invalid chip index %d\n",
chipIndex);
LOG(logERROR, (mess));
} else if (gainIndex < 0 || gainIndex > 2) {
ret = FAIL;
sprintf(mess, "Could not set veto photon. Invalid gain index %d\n",
gainIndex);
LOG(logERROR, (mess));
} else if (numChannels != NCHAN) {
ret = FAIL;
sprintf(mess,
@ -6367,6 +6368,15 @@ int set_veto_photon(int file_des) {
LOG(logERROR, (mess));
} else {
for (int i = 0; i < NCHAN; ++i) {
if (gainIndices[i] < 0 || gainIndices[i] > 2) {
ret = FAIL;
sprintf(mess,
"Could not set veto photon. Invalid gain index %d "
"for channel %d.\n",
gainIndices[i], i);
LOG(logERROR, (mess));
break;
}
if (values[i] > ADU_MAX_VAL) {
ret = FAIL;
sprintf(mess,
@ -6378,7 +6388,7 @@ int set_veto_photon(int file_des) {
}
}
if (ret == OK) {
ret = setVetoPhoton(chipIndex, gainIndex, values);
ret = setVetoPhoton(chipIndex, gainIndices, values);
if (ret == FAIL) {
sprintf(mess,
"Could not set veto photon for chip index %d\n",
@ -6398,6 +6408,8 @@ int get_veto_photon(int file_des) {
int arg = -1;
int retvals[NCHAN];
memset(retvals, 0, sizeof(retvals));
int gainRetvals[NCHAN];
memset(gainRetvals, 0, sizeof(gainRetvals));
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError();
@ -6414,14 +6426,16 @@ int get_veto_photon(int file_des) {
chipIndex);
LOG(logERROR, (mess));
} else {
ret = getVetoPhoton(chipIndex, retvals);
ret = getVetoPhoton(chipIndex, retvals, gainRetvals);
if (ret == FAIL) {
strcpy(mess, "Could not get veto photon for chipIndex -1. Not the "
"same for all chips.\n");
strcpy(mess,
"Could not get veto photon for chipIndex -1. Not the "
"same for all chips. Select specific chip index instead.\n");
LOG(logERROR, (mess));
} else {
for (int i = 0; i < NCHAN; ++i) {
LOG(logDEBUG1, ("%d:0x%x\n", i, retvals[i]));
LOG(logDEBUG1,
("%d:[%d, %d]\n", i, retvals[i], gainRetvals[i]));
}
}
}
@ -6430,6 +6444,7 @@ int get_veto_photon(int file_des) {
if (ret != FAIL) {
int nch = NCHAN;
sendData(file_des, &nch, sizeof(nch), INT32);
sendData(file_des, gainRetvals, sizeof(gainRetvals), INT32);
sendData(file_des, retvals, sizeof(retvals), INT32);
}
return ret;
@ -7763,78 +7778,6 @@ int set_filter(int file_des) {
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));