mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-20 16:48:01 +02:00
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:
@ -1625,17 +1625,19 @@ std::string CmdProxy::VetoPhoton(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[n_chip] [#photons] [energy in keV] [reference "
|
||||
os << "[ichip] [#photons] [energy in keV] [reference "
|
||||
"file]\n\t[Gotthard2] Set veto reference for 128 channels for "
|
||||
"chip n_chip according to referenc file and #photons and energy "
|
||||
"in keV."
|
||||
"chip ichip according to reference file and #photons and energy "
|
||||
"in keV.\n"
|
||||
<< "[ichip] [output file]\n\t Get gain indices and veto reference "
|
||||
"for 128 channels for chip ichip, saved to file."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
if (args.size() != 1) {
|
||||
WrongNumberOfParameters(1);
|
||||
if (args.size() != 2) {
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
auto t = det->getVetoPhoton(StringTo<int>(args[0]), {det_id});
|
||||
os << args[0] << ' ' << OutStringHex(t) << '\n';
|
||||
det->getVetoPhoton(StringTo<int>(args[0]), args[1], {det_id});
|
||||
os << "saved to file " << args[1] << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.size() != 4) {
|
||||
WrongNumberOfParameters(4);
|
||||
@ -1653,7 +1655,7 @@ std::string CmdProxy::VetoReference(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[gain index] [12 bit value in hex] \n\t[Gotthard2] Set veto "
|
||||
os << "[gain index] [12 bit value] \n\t[Gotthard2] Set veto "
|
||||
"reference for all 128 channels for all chips."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
@ -1677,7 +1679,7 @@ std::string CmdProxy::VetoFile(int action) {
|
||||
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"
|
||||
"file should have 128 rows of gain index and 12 bit value in dec"
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
throw sls::RuntimeError(
|
||||
|
@ -1290,9 +1290,9 @@ void Detector::setInjectChannel(const int offsetChannel,
|
||||
incrementChannel);
|
||||
}
|
||||
|
||||
Result<std::vector<int>> Detector::getVetoPhoton(const int chipIndex,
|
||||
Positions pos) {
|
||||
return pimpl->Parallel(&Module::getVetoPhoton, pos, chipIndex);
|
||||
void Detector::getVetoPhoton(const int chipIndex, const std::string &fname,
|
||||
Positions pos) {
|
||||
pimpl->Parallel(&Module::getVetoPhoton, pos, chipIndex, fname);
|
||||
}
|
||||
|
||||
void Detector::setVetoPhoton(const int chipIndex, const int numPhotons,
|
||||
|
@ -187,7 +187,7 @@ void Module::setAllTrimbits(int val) {
|
||||
sendToDetector<int>(F_SET_ALL_TRIMBITS, val);
|
||||
}
|
||||
|
||||
int64_t Module::getNumberOfFrames() const{
|
||||
int64_t Module::getNumberOfFrames() const {
|
||||
return sendToDetector<int64_t>(F_GET_NUM_FRAMES);
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ void Module::setNumberOfFrames(int64_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Module::getNumberOfTriggers() const{
|
||||
int64_t Module::getNumberOfTriggers() const {
|
||||
return sendToDetector<int64_t>(F_GET_NUM_TRIGGERS);
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ void Module::setNumberOfTriggers(int64_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Module::getExptime(int gateIndex) const{
|
||||
int64_t Module::getExptime(int gateIndex) const {
|
||||
return sendToDetector<int64_t>(F_GET_EXPTIME, gateIndex);
|
||||
}
|
||||
|
||||
@ -228,7 +228,9 @@ void Module::setExptime(int gateIndex, int64_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Module::getPeriod() const { return sendToDetector<int64_t>(F_GET_PERIOD); }
|
||||
int64_t Module::getPeriod() const {
|
||||
return sendToDetector<int64_t>(F_GET_PERIOD);
|
||||
}
|
||||
|
||||
void Module::setPeriod(int64_t value) {
|
||||
sendToDetector(F_SET_PERIOD, value, nullptr);
|
||||
@ -321,7 +323,7 @@ void Module::setClockPhase(int clkIndex, int value, bool inDegrees) {
|
||||
sendToDetector(F_SET_CLOCK_PHASE, args, nullptr);
|
||||
}
|
||||
|
||||
int Module::getMaxClockPhaseShift(int clkIndex) const{
|
||||
int Module::getMaxClockPhaseShift(int clkIndex) const {
|
||||
return sendToDetector<int>(F_GET_MAX_CLOCK_PHASE_SHIFT, clkIndex);
|
||||
}
|
||||
|
||||
@ -498,11 +500,11 @@ std::string Module::getScanErrorMessage() const {
|
||||
|
||||
// Network Configuration (Detector<->Receiver)
|
||||
|
||||
int Module::getNumberofUDPInterfacesFromShm() const{
|
||||
int Module::getNumberofUDPInterfacesFromShm() const {
|
||||
return shm()->numUDPInterfaces;
|
||||
}
|
||||
|
||||
int Module::getNumberofUDPInterfaces() const{
|
||||
int Module::getNumberofUDPInterfaces() const {
|
||||
shm()->numUDPInterfaces = sendToDetector<int>(F_GET_NUM_INTERFACES);
|
||||
return shm()->numUDPInterfaces;
|
||||
}
|
||||
@ -534,7 +536,7 @@ void Module::setSourceUDPIP(const IpAddr ip) {
|
||||
sendToDetector(F_SET_SOURCE_UDP_IP, ip, nullptr);
|
||||
}
|
||||
|
||||
sls::IpAddr Module::getSourceUDPIP2() const{
|
||||
sls::IpAddr Module::getSourceUDPIP2() const {
|
||||
return sendToDetector<sls::IpAddr>(F_GET_SOURCE_UDP_IP2);
|
||||
}
|
||||
|
||||
@ -638,7 +640,7 @@ void Module::setDestinationUDPPort(const int port) {
|
||||
}
|
||||
}
|
||||
|
||||
int Module::getDestinationUDPPort2() const{
|
||||
int Module::getDestinationUDPPort2() const {
|
||||
return sendToDetector<int>(F_GET_DEST_UDP_PORT2);
|
||||
}
|
||||
|
||||
@ -831,7 +833,8 @@ void Module::setReceiverSilentMode(bool enable) {
|
||||
nullptr);
|
||||
}
|
||||
|
||||
slsDetectorDefs::frameDiscardPolicy Module::getReceiverFramesDiscardPolicy() const {
|
||||
slsDetectorDefs::frameDiscardPolicy
|
||||
Module::getReceiverFramesDiscardPolicy() const {
|
||||
return static_cast<frameDiscardPolicy>(
|
||||
sendToReceiver<int>(F_GET_RECEIVER_DISCARD_POLICY));
|
||||
}
|
||||
@ -880,7 +883,7 @@ std::array<pid_t, NUM_RX_THREAD_IDS> Module::getReceiverThreadIds() const {
|
||||
|
||||
// File
|
||||
|
||||
slsDetectorDefs::fileFormat Module::getFileFormat() const{
|
||||
slsDetectorDefs::fileFormat Module::getFileFormat() const {
|
||||
return static_cast<fileFormat>(
|
||||
sendToReceiver<int>(F_GET_RECEIVER_FILE_FORMAT));
|
||||
}
|
||||
@ -1103,7 +1106,9 @@ void Module::setThresholdEnergy(int e_eV, detectorSettings isettings,
|
||||
}
|
||||
}
|
||||
|
||||
std::string Module::getSettingsDir() const { return std::string(shm()->settingsDir); }
|
||||
std::string Module::getSettingsDir() const {
|
||||
return std::string(shm()->settingsDir);
|
||||
}
|
||||
|
||||
std::string Module::setSettingsDir(const std::string &dir) {
|
||||
sls::strcpy_safe(shm()->settingsDir, dir.c_str());
|
||||
@ -1173,7 +1178,9 @@ void Module::setRateCorrection(int64_t t) {
|
||||
sendToDetector(F_SET_RATE_CORRECT, t, nullptr);
|
||||
}
|
||||
|
||||
int Module::getReadNLines() const { return sendToDetector<int>(F_GET_READ_N_LINES); }
|
||||
int Module::getReadNLines() const {
|
||||
return sendToDetector<int>(F_GET_READ_N_LINES);
|
||||
}
|
||||
|
||||
void Module::setReadNLines(const int value) {
|
||||
sendToDetector(F_SET_READ_N_LINES, value, nullptr);
|
||||
@ -1231,7 +1238,8 @@ void Module::setDeactivatedRxrPaddingMode(bool padding) {
|
||||
}
|
||||
|
||||
bool Module::getCounterBit() const {
|
||||
return (!static_cast<bool>(sendToDetector<int>(F_SET_COUNTER_BIT, GET_FLAG)));
|
||||
return (
|
||||
!static_cast<bool>(sendToDetector<int>(F_SET_COUNTER_BIT, GET_FLAG)));
|
||||
}
|
||||
|
||||
void Module::setCounterBit(bool cb) {
|
||||
@ -1294,8 +1302,9 @@ void Module::resetTemperatureEvent() {
|
||||
sendToDetectorStop<int>(F_TEMP_EVENT, 0);
|
||||
}
|
||||
|
||||
bool Module::getAutoComparatorDisableMode() const{
|
||||
return static_cast<bool>(sendToDetector<int>(F_AUTO_COMP_DISABLE, GET_FLAG));
|
||||
bool Module::getAutoComparatorDisableMode() const {
|
||||
return static_cast<bool>(
|
||||
sendToDetector<int>(F_AUTO_COMP_DISABLE, GET_FLAG));
|
||||
}
|
||||
|
||||
void Module::setAutoComparatorDisableMode(bool val) {
|
||||
@ -1380,7 +1389,30 @@ void Module::setInjectChannel(const int offsetChannel,
|
||||
sendToDetector(F_SET_INJECT_CHANNEL, args, nullptr);
|
||||
}
|
||||
|
||||
std::vector<int> Module::getVetoPhoton(const int chipIndex) const {
|
||||
void Module::sendVetoPhoton(const int chipIndex, int *gainIndices,
|
||||
int *values) {
|
||||
int fnum = F_SET_VETO_PHOTON;
|
||||
int ret = FAIL;
|
||||
int nch = shm()->nChan.x;
|
||||
int args[]{chipIndex, nch};
|
||||
LOG(logDEBUG1) << "Sending veto photon/file to detector [chip:" << chipIndex
|
||||
<< ", nch:" << nch << "]";
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(&fnum, sizeof(fnum));
|
||||
client.Send(args, sizeof(args));
|
||||
client.Send(gainIndices, sizeof(int) * nch);
|
||||
client.Send(values, 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));
|
||||
}
|
||||
}
|
||||
|
||||
void Module::getVetoPhoton(const int chipIndex,
|
||||
const std::string &fname) const {
|
||||
int fnum = F_GET_VETO_PHOTON;
|
||||
int ret = FAIL;
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
@ -1395,14 +1427,25 @@ std::vector<int> Module::getVetoPhoton(const int chipIndex) const {
|
||||
}
|
||||
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 gainIndices[nch];
|
||||
memset(gainIndices, 0, sizeof(gainIndices));
|
||||
client.Receive(gainIndices, sizeof(gainIndices));
|
||||
int values[nch];
|
||||
memset(values, 0, sizeof(values));
|
||||
client.Receive(values, sizeof(values));
|
||||
|
||||
// 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 veto photon");
|
||||
}
|
||||
for (int i = 0; i < nch; ++i) {
|
||||
outfile << gainIndices[i] << ' ' << values[i] << '\n';
|
||||
}
|
||||
LOG(logDEBUG1) << nch << " veto photon saved to file";
|
||||
}
|
||||
|
||||
void Module::setVetoPhoton(const int chipIndex, const int numPhotons,
|
||||
@ -1429,14 +1472,15 @@ void Module::setVetoPhoton(const int chipIndex, const int numPhotons,
|
||||
throw RuntimeError("Could not set veto photon. Could not open file: " +
|
||||
fname);
|
||||
}
|
||||
LOG(logDEBUG1) << "Setting veto photon. Reading Gain values from file";
|
||||
|
||||
int totalEnergy = numPhotons * energy;
|
||||
int ch = shm()->nChan.x;
|
||||
int gainIndex = 2;
|
||||
int nRead = 0;
|
||||
int value[ch];
|
||||
memset(value, 0, sizeof(value));
|
||||
bool firstLine = true;
|
||||
int values[ch];
|
||||
int gainIndices[ch];
|
||||
memset(values, 0, sizeof(values));
|
||||
memset(gainIndices, 0, sizeof(gainIndices));
|
||||
|
||||
while (infile.good()) {
|
||||
std::string line;
|
||||
@ -1448,65 +1492,43 @@ void Module::setVetoPhoton(const int chipIndex, const int numPhotons,
|
||||
continue;
|
||||
}
|
||||
std::istringstream ss(line);
|
||||
// first line: caluclate gain index from gain thresholds from file
|
||||
if (firstLine) {
|
||||
int g0 = -1, g1 = -1;
|
||||
ss >> g0 >> g1;
|
||||
if (ss.fail()) {
|
||||
throw RuntimeError(
|
||||
"Could not set veto photon. Invalid gain thresholds");
|
||||
}
|
||||
// set gain index and gain bit values
|
||||
if (totalEnergy < g0) {
|
||||
gainIndex = 0;
|
||||
} else if (totalEnergy < g1) {
|
||||
gainIndex = 1;
|
||||
}
|
||||
LOG(logINFO) << "Setting veto photon. Reading Gain " << gainIndex
|
||||
<< " values";
|
||||
firstLine = false;
|
||||
|
||||
// read pedestal, gain values, gain thresholds
|
||||
double gainPedestal[3] = {-1, -1, -1};
|
||||
double gainValue[3] = {-1, -1, -1};
|
||||
int gainThreshold[2] = {-1, -1};
|
||||
ss >> gainPedestal[0] >> gainPedestal[1] >> gainPedestal[2] >>
|
||||
gainValue[0] >> gainValue[1] >> gainValue[2] >> gainThreshold[0] >>
|
||||
gainThreshold[1];
|
||||
if (ss.fail()) {
|
||||
throw RuntimeError("Could not set veto photon. Invalid pedestals, "
|
||||
"gain values or gain thresholds for channel " +
|
||||
std::to_string(nRead));
|
||||
}
|
||||
// read pedestal and gain values
|
||||
else {
|
||||
double p[3] = {-1, -1, -1}, g[3] = {-1, -1, -1};
|
||||
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));
|
||||
}
|
||||
value[nRead] =
|
||||
p[gainIndex] +
|
||||
(g[gainIndex] *
|
||||
totalEnergy); // ADU value = pedestal + gain * total energy
|
||||
++nRead;
|
||||
if (nRead >= ch) {
|
||||
break;
|
||||
}
|
||||
|
||||
// caluclate gain index from gain thresholds and threhsold energy
|
||||
int gainIndex = 2;
|
||||
if (totalEnergy < gainThreshold[0]) {
|
||||
gainIndex = 0;
|
||||
} else if (totalEnergy < gainThreshold[1]) {
|
||||
gainIndex = 1;
|
||||
}
|
||||
// calculate ADU values = pedestal + gainvalue * total energy
|
||||
values[nRead] =
|
||||
gainPedestal[gainIndex] + (gainValue[gainIndex] * totalEnergy);
|
||||
gainIndices[nRead] = gainIndex;
|
||||
++nRead;
|
||||
if (nRead >= ch) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nRead != ch) {
|
||||
throw RuntimeError("Could not set veto photon. Insufficient pedestal "
|
||||
"pr gain values: " +
|
||||
"for gain values: " +
|
||||
std::to_string(nRead));
|
||||
}
|
||||
|
||||
int fnum = F_SET_VETO_PHOTON;
|
||||
int ret = FAIL;
|
||||
int args[]{chipIndex, gainIndex, ch};
|
||||
LOG(logDEBUG) << "Sending veto photon value to detector [chip:" << chipIndex
|
||||
<< ", G" << gainIndex << "]: " << args;
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(&fnum, sizeof(fnum));
|
||||
client.Send(args, sizeof(args));
|
||||
client.Send(value, sizeof(value));
|
||||
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));
|
||||
}
|
||||
sendVetoPhoton(chipIndex, gainIndices, values);
|
||||
}
|
||||
|
||||
void Module::setVetoReference(const int gainIndex, const int value) {
|
||||
@ -1572,26 +1594,10 @@ void Module::setVetoFile(const int chipIndex, const std::string &fname) {
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
sendVetoPhoton(chipIndex, gainIndices, values);
|
||||
}
|
||||
|
||||
slsDetectorDefs::burstMode Module::getBurstMode() const{
|
||||
slsDetectorDefs::burstMode Module::getBurstMode() const {
|
||||
auto r = sendToDetector<int>(F_GET_BURST_MODE);
|
||||
return static_cast<slsDetectorDefs::burstMode>(r);
|
||||
}
|
||||
@ -1681,7 +1687,7 @@ void Module::getBadChannels(const std::string &fname) const {
|
||||
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");
|
||||
throw RuntimeError("Could not create file to save bad channels");
|
||||
}
|
||||
for (int i = 0; i < nch; ++i) {
|
||||
outfile << badchannels[i] << '\n';
|
||||
@ -1750,7 +1756,9 @@ void Module::setCounterMask(uint32_t countermask) {
|
||||
}
|
||||
}
|
||||
|
||||
int Module::getNumberOfGates() const { return sendToDetector<int>(F_GET_NUM_GATES); }
|
||||
int Module::getNumberOfGates() const {
|
||||
return sendToDetector<int>(F_GET_NUM_GATES);
|
||||
}
|
||||
|
||||
void Module::setNumberOfGates(int value) {
|
||||
sendToDetector(F_SET_NUM_GATES, value, nullptr);
|
||||
@ -1885,7 +1893,7 @@ int Module::setExternalSamplingSource(int value) {
|
||||
return sendToDetector<int>(F_EXTERNAL_SAMPLING_SOURCE, value);
|
||||
}
|
||||
|
||||
bool Module::getExternalSampling() const{
|
||||
bool Module::getExternalSampling() const {
|
||||
return sendToDetector<int>(F_EXTERNAL_SAMPLING, GET_FLAG);
|
||||
}
|
||||
|
||||
|
@ -371,7 +371,8 @@ class Module : public virtual slsDetectorDefs {
|
||||
void setBurstPeriod(int64_t value);
|
||||
std::array<int, 2> getInjectChannel() const;
|
||||
void setInjectChannel(const int offsetChannel, const int incrementChannel);
|
||||
std::vector<int> getVetoPhoton(const int chipIndex) const;
|
||||
void sendVetoPhoton(const int chipIndex, int *gainIndices, int *values);
|
||||
void getVetoPhoton(const int chipIndex, const std::string &fname) const;
|
||||
void setVetoPhoton(const int chipIndex, const int numPhotons,
|
||||
const int energy, const std::string &fname);
|
||||
void setVetoReference(const int gainIndex, const int value);
|
||||
@ -519,7 +520,7 @@ class Module : public virtual slsDetectorDefs {
|
||||
|
||||
private:
|
||||
void checkArgs(const void *args, size_t args_size, void *retval,
|
||||
size_t retval_size) const;
|
||||
size_t retval_size) const;
|
||||
|
||||
/**
|
||||
* Send function parameters to detector (control server)
|
||||
|
Reference in New Issue
Block a user