mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-15 06:17:12 +02:00
M3badchannels (#526)
* badchannels for m3 and modify for g2 (file from single and multi) * m3: invert polarity of bit 7 and 11 signals from setmodule, allow commas in bad channel file * badchannel file can take commas, colons and comments (also taking care of spaces at the end of channel numbers) * tests 'badchannels' and 'Channel file reading' added, removing duplicates in badchannel list, defining macro for num counters in client side * fix segfault when list from file is empty, * fix tests assertion for ctbconfig (adding message) for c++11 * fixed badchannels in m3server (clocking in trimming) * badchannel tests can be run from any folder (finds the file)
This commit is contained in:
@ -498,6 +498,40 @@ void Module::setSynchronization(const bool value) {
|
||||
sendToDetector(F_SET_SYNCHRONIZATION, static_cast<int>(value), nullptr);
|
||||
}
|
||||
|
||||
std::vector<int> Module::getBadChannels() const {
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_GET_BAD_CHANNELS);
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
throw DetectorError("Detector " + std::to_string(moduleIndex) +
|
||||
" returned error: " + client.readErrorMessage());
|
||||
}
|
||||
// receive badchannels
|
||||
auto nch = client.Receive<int>();
|
||||
std::vector<int> badchannels(nch);
|
||||
if (nch > 0) {
|
||||
client.Receive(badchannels);
|
||||
for (size_t i = 0; i < badchannels.size(); ++i) {
|
||||
LOG(logDEBUG1) << i << ":" << badchannels[i];
|
||||
}
|
||||
}
|
||||
return badchannels;
|
||||
}
|
||||
|
||||
void Module::setBadChannels(std::vector<int> list) {
|
||||
auto nch = static_cast<int>(list.size());
|
||||
LOG(logDEBUG1) << "Sending bad channels to detector, nch:" << nch;
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_SET_BAD_CHANNELS);
|
||||
client.Send(nch);
|
||||
if (nch > 0) {
|
||||
client.Send(list);
|
||||
}
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
throw DetectorError("Detector " + std::to_string(moduleIndex) +
|
||||
" returned error: " + client.readErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
bool Module::isVirtualDetectorServer() const {
|
||||
return sendToDetector<int>(F_IS_VIRTUAL);
|
||||
}
|
||||
@ -2136,73 +2170,6 @@ void Module::setADCConfiguration(const int chipIndex, const int adcIndex,
|
||||
sendToDetector(F_SET_ADC_CONFIGURATION, args, nullptr);
|
||||
}
|
||||
|
||||
void Module::getBadChannels(const std::string &fname) const {
|
||||
LOG(logDEBUG1) << "Getting bad channels to " << fname;
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_GET_BAD_CHANNELS);
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
throw DetectorError("Detector " + std::to_string(moduleIndex) +
|
||||
" returned error: " + client.readErrorMessage());
|
||||
}
|
||||
// receive badchannels
|
||||
auto nch = client.Receive<int>();
|
||||
std::vector<int> badchannels(nch);
|
||||
if (nch > 0) {
|
||||
client.Receive(badchannels);
|
||||
for (size_t i = 0; i < badchannels.size(); ++i) {
|
||||
LOG(logDEBUG1) << i << ":" << badchannels[i];
|
||||
}
|
||||
}
|
||||
|
||||
// save to file
|
||||
std::ofstream outfile(fname);
|
||||
if (!outfile) {
|
||||
throw RuntimeError("Could not create file to save bad channels");
|
||||
}
|
||||
for (auto ch : badchannels)
|
||||
outfile << ch << '\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) {
|
||||
throw RuntimeError("Could not open bad channels file " + fname +
|
||||
" for reading");
|
||||
}
|
||||
std::vector<int> badchannels;
|
||||
for (std::string line; std::getline(input_file, line);) {
|
||||
line.erase(std::remove_if(begin(line), end(line), isspace),
|
||||
end(line)); // remove space
|
||||
if (!line.empty()) {
|
||||
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
|
||||
auto nch = static_cast<int>(badchannels.size());
|
||||
LOG(logDEBUG1) << "Sending bad channels to detector, nch:" << nch;
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_SET_BAD_CHANNELS);
|
||||
client.Send(nch);
|
||||
if (nch > 0) {
|
||||
client.Send(badchannels);
|
||||
}
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
throw DetectorError("Detector " + std::to_string(moduleIndex) +
|
||||
" returned error: " + client.readErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Mythen3 Specific
|
||||
|
||||
uint32_t Module::getCounterMask() const {
|
||||
|
Reference in New Issue
Block a user