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
2 changed files with 15 additions and 6 deletions

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) {