Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AttUtils Namespace Reference

Functions

template<typename T >
G4bool ExtractAttDef (const T &object, const G4String &name, G4AttDef &def)
 
template<typename T >
G4bool ExtractAttValue (const T &object, const G4String &name, G4AttValue &attVal)
 
G4TypeKey GetKey (const G4AttDef &def)
 

Function Documentation

◆ ExtractAttDef()

template<typename T >
G4bool G4AttUtils::ExtractAttDef ( const T &  object,
const G4String name,
G4AttDef def 
)

Definition at line 61 of file G4AttUtils.hh.

62 {
63 const std::map<G4String, G4AttDef>* attDefs = object.GetAttDefs();
64
65 // NOLINTNEXTLINE(modernize-use-auto): Explicitly want a const_iterator despite attDefs being const
66 std::map<G4String, G4AttDef>::const_iterator iter = attDefs->find(name);
67 if (iter == attDefs->end()) return false;
68
69 def = iter->second;
70
71 return true;
72 }

Referenced by G4TrajectoryDrawByAttribute::Draw(), and G4AttributeFilterT< T >::Evaluate().

◆ ExtractAttValue()

template<typename T >
G4bool G4AttUtils::ExtractAttValue ( const T &  object,
const G4String name,
G4AttValue attVal 
)

Definition at line 76 of file G4AttUtils.hh.

77 {
78 std::vector<G4AttValue>* attValues = object.CreateAttValues();
79
80 auto iter = std::find_if(attValues->cbegin(), attValues->cend(),
81 HasName<G4AttValue>(name));
82 if (iter == attValues->cend()) return false;
83
84 attVal = *iter;
85
86 // Clean up
87 delete attValues;
88
89 return true;
90 }

Referenced by G4TrajectoryDrawByAttribute::Draw(), and G4AttributeFilterT< T >::Evaluate().

◆ GetKey()

G4TypeKey G4AttUtils::GetKey ( const G4AttDef def)

Definition at line 40 of file G4AttUtils.cc.

41 {
42 G4String type = def.GetValueType();
43
44 G4bool withUnit = (def.GetExtra() == "G4BestUnit");
45
46 // Known conversions
47 if (type == "G4String") return G4TypeKeyT<G4String>();
48 if (type == "G4int") return G4TypeKeyT<G4int>();
49 if (type == "G4double" && !withUnit) return G4TypeKeyT<G4double>();
50 if (type == "G4double" && withUnit) return G4TypeKeyT<G4DimensionedDouble>();
51 if (type == "G4ThreeVector" && !withUnit) return G4TypeKeyT<G4ThreeVector>();
52 if (type == "G4ThreeVector" && withUnit) return G4TypeKeyT<G4DimensionedThreeVector>();
53 if (type == "G4bool") return G4TypeKeyT<G4bool>();
54
55 // Return default (invalid) key
56 return G4TypeKey();
57 }
bool G4bool
Definition: G4Types.hh:86
const G4String & GetExtra() const
Definition: G4AttDef.hh:86
const G4String & GetValueType() const
Definition: G4AttDef.hh:87

Referenced by G4AttFilterUtils::GetNewFilter().