Skip to content

Commit 23733e1

Browse files
committed
fix: throw on data in both old and new API structs
1 parent 1dd9a68 commit 23733e1

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

source/ChargedParticle.cc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@
1212
// -------------------------------------------------------------------------------------
1313

1414
ChargedParticle::TrajectoryData ChargedParticle::GetTrajectoryData(CherenkovRadiator* radiator, RadiatorHistory* history) const {
15-
// Try new API first, fall back to deprecated API for backwards compatibility
16-
if (history->GetLocations().empty() && !radiator->GetLocations().empty()) {
17-
// Using deprecated API (backwards compatibility mode)
15+
bool history_has_data = !history->GetLocations().empty();
16+
bool radiator_has_data = !radiator->GetLocations().empty();
17+
18+
// Both APIs populated indicates accidental misuse
19+
if (history_has_data && radiator_has_data) {
20+
throw std::runtime_error("Both RadiatorHistory and CherenkovRadiator have trajectory data");
21+
}
22+
23+
// Prefer new thread-safe API, fall back to deprecated API for backwards compatibility
24+
if (history_has_data) {
25+
return {history->GetTrajectoryBinCount(), history->GetLocations()};
26+
} else if (radiator_has_data) {
1827
return {radiator->GetTrajectoryBinCount(), radiator->GetLocations()};
1928
} else {
20-
// Using new thread-safe API
21-
return {history->GetTrajectoryBinCount(), history->GetLocations()};
29+
static const std::vector<std::pair<TVector3, TVector3>> empty_locations;
30+
return {0, empty_locations};
2231
}
2332
}
2433

0 commit comments

Comments
 (0)