badchannel segfault for multi module (#620)

* badchannels segfaults when there are no badchannels for next modules, fixed

* added example badchannels

* refactoring casting
This commit is contained in:
Dhanya Thattil 2023-01-20 17:39:25 +01:00 committed by GitHub
parent 3682644e15
commit 946e6aa817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

6
examples/badchannel.txt Normal file
View File

@ -0,0 +1,6 @@
0
10, 30
40:45 50:52
1279
# all bad channels are applied for all counters in deector

View File

@ -1794,20 +1794,23 @@ void DetectorImpl::setBadChannels(const std::string &fname, Positions pos) {
" out of bounds.");
}
int ch = badchannel % nchan;
int imod = badchannel / nchan;
if (imod >= (int)modules.size()) {
size_t imod = badchannel / nchan;
if (imod >= modules.size()) {
throw RuntimeError("Invalid bad channel list. " +
std::to_string(badchannel) +
" out of bounds.");
}
if ((int)badchannels.size() != imod + 1) {
if (badchannels.size() != imod + 1) {
badchannels.push_back(std::vector<int>{});
}
badchannels[imod].push_back(ch);
}
for (int imod = 0; imod != (int)modules.size(); ++imod) {
Parallel(&Module::setBadChannels, {imod}, badchannels[imod]);
for (size_t imod = 0; imod != modules.size(); ++imod) {
// add empty vector if no bad channels in this module
if (badchannels.size() != imod + 1) {
badchannels.push_back(std::vector<int>{});
}
Parallel(&Module::setBadChannels, {static_cast<int>(imod)}, badchannels[imod]);
}
} else if (pos.size() != 1) {