G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
G4OCCTSensitiveDetectorMap.cc
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2// Copyright (C) 2026 G4OCCT Contributors
3
6
8
9#include <G4Exception.hh>
10#include <G4VSensitiveDetector.hh>
11
12#include <algorithm>
13#include <cctype>
14
15void G4OCCTSensitiveDetectorMap::Add(const G4String& pattern, G4VSensitiveDetector* sd) {
16 if (!sd) {
17 G4Exception("G4OCCTSensitiveDetectorMap::Add", "G4OCCT_SDMap000", FatalException,
18 ("Null G4VSensitiveDetector passed for pattern '" + pattern + "'.").c_str());
19 return;
20 }
21 for (auto& entry : fEntries) {
22 if (entry.first == pattern) {
23 entry.second = sd;
24 return;
25 }
26 }
27 fEntries.emplace_back(pattern, sd);
28}
29
30G4VSensitiveDetector* G4OCCTSensitiveDetectorMap::Resolve(const G4String& volumeName) const {
31 for (const auto& entry : fEntries) {
32 const G4String& pattern = entry.first;
33
34 // Exact match
35 if (volumeName == pattern) {
36 return entry.second;
37 }
38
39 // Prefix match: volumeName starts with pattern+"_" and suffix is all digits
40 const G4String prefix = pattern + "_";
41 if (volumeName.rfind(prefix, 0) == 0) {
42 const G4String suffix = volumeName.substr(prefix.size());
43 if (!suffix.empty() && std::all_of(suffix.begin(), suffix.end(), [](char c) {
44 return std::isdigit(static_cast<unsigned char>(c));
45 })) {
46 return entry.second;
47 }
48 }
49 }
50 return nullptr;
51}
Declaration of G4OCCTSensitiveDetectorMap.
void Add(const G4String &pattern, G4VSensitiveDetector *sd)
G4VSensitiveDetector * Resolve(const G4String &volumeName) const