src/G4OCCTSensitiveDetectorMap.cc
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: LGPL-2.1-or-later | ||
| 2 | // Copyright (C) 2026 G4OCCT Contributors | ||
| 3 | |||
| 4 | /// @file G4OCCTSensitiveDetectorMap.cc | ||
| 5 | /// @brief Implementation of G4OCCTSensitiveDetectorMap. | ||
| 6 | |||
| 7 | #include "G4OCCT/G4OCCTSensitiveDetectorMap.hh" | ||
| 8 | |||
| 9 | #include <G4Exception.hh> | ||
| 10 | #include <G4VSensitiveDetector.hh> | ||
| 11 | |||
| 12 | #include <algorithm> | ||
| 13 | #include <cctype> | ||
| 14 | |||
| 15 | 20 | void G4OCCTSensitiveDetectorMap::Add(const G4String& pattern, G4VSensitiveDetector* sd) { | |
| 16 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1 time.
|
20 | if (!sd) { |
| 17 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | G4Exception("G4OCCTSensitiveDetectorMap::Add", "G4OCCT_SDMap000", FatalException, |
| 18 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | ("Null G4VSensitiveDetector passed for pattern '" + pattern + "'.").c_str()); |
| 19 | 1 | return; | |
| 20 | } | ||
| 21 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
|
24 | for (auto& entry : fEntries) { |
| 22 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 5 times.
|
6 | if (entry.first == pattern) { |
| 23 | 1 | entry.second = sd; | |
| 24 | 1 | return; | |
| 25 | } | ||
| 26 | } | ||
| 27 | 18 | fEntries.emplace_back(pattern, sd); | |
| 28 | 20 | } | |
| 29 | |||
| 30 | 28 | G4VSensitiveDetector* G4OCCTSensitiveDetectorMap::Resolve(const G4String& volumeName) const { | |
| 31 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7 times.
|
40 | for (const auto& entry : fEntries) { |
| 32 | 33 | const G4String& pattern = entry.first; | |
| 33 | |||
| 34 | // Exact match | ||
| 35 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 18 times.
|
33 | if (volumeName == pattern) { |
| 36 | 15 | return entry.second; | |
| 37 | } | ||
| 38 | |||
| 39 | // Prefix match: volumeName starts with pattern+"_" and suffix is all digits | ||
| 40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | const G4String prefix = pattern + "_"; |
| 41 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8 times.
|
18 | if (volumeName.rfind(prefix, 0) == 0) { |
| 42 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
8 | const G4String suffix = volumeName.substr(prefix.size()); |
| 43 |
4/6✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 6 times.
|
17 | if (!suffix.empty() && std::all_of(suffix.begin(), suffix.end(), [](char c) { |
| 44 | 9 | return std::isdigit(static_cast<unsigned char>(c)); | |
| 45 | })) { | ||
| 46 | 6 | return entry.second; | |
| 47 | } | ||
| 48 | 8 | } | |
| 49 | 18 | } | |
| 50 | 7 | return nullptr; | |
| 51 | 28 | } | |
| 52 |