Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TrajectoryDrawByAttribute Class Reference

#include <G4TrajectoryDrawByAttribute.hh>

+ Inheritance diagram for G4TrajectoryDrawByAttribute:

Public Member Functions

 G4TrajectoryDrawByAttribute (const G4String &name="Unspecified", G4VisTrajContext *context=0)
 
virtual ~G4TrajectoryDrawByAttribute ()
 
virtual void Draw (const G4VTrajectory &trajectory, const G4int &i_mode=0, const G4bool &visible=true) const
 
virtual void Draw (const G4VTrajectory &trajectory, const G4bool &visible=true) const
 
virtual void Print (std::ostream &ostr) const
 
void Set (const G4String &attribute)
 
void AddIntervalContext (const G4String &name, G4VisTrajContext *context)
 
void AddValueContext (const G4String &name, G4VisTrajContext *context)
 
- Public Member Functions inherited from G4VTrajectoryModel
 G4VTrajectoryModel (const G4String &name, G4VisTrajContext *fpContext=0)
 
virtual ~G4VTrajectoryModel ()
 
virtual void Draw (const G4VTrajectory &trajectory, const G4int &i_mode=0, const G4bool &visible=true) const =0
 
virtual void Draw (const G4VTrajectory &trajectory, const G4bool &visible=true) const =0
 
virtual void Print (std::ostream &ostr) const =0
 
G4String Name () const
 
const G4VisTrajContextGetContext () const
 
void SetVerbose (const G4bool &)
 
G4bool GetVerbose () const
 

Detailed Description

Definition at line 42 of file G4TrajectoryDrawByAttribute.hh.

Constructor & Destructor Documentation

◆ G4TrajectoryDrawByAttribute()

G4TrajectoryDrawByAttribute::G4TrajectoryDrawByAttribute ( const G4String name = "Unspecified",
G4VisTrajContext context = 0 
)

Definition at line 41 of file G4TrajectoryDrawByAttribute.cc.

42 :G4VTrajectoryModel(name, context)
43 ,fAttName("")
44 ,fFirst(true)
45 ,fWarnedMissingAttribute(false)
46 ,filter(0)
47{}

◆ ~G4TrajectoryDrawByAttribute()

G4TrajectoryDrawByAttribute::~G4TrajectoryDrawByAttribute ( )
virtual

Definition at line 49 of file G4TrajectoryDrawByAttribute.cc.

50{
51 ContextMap::iterator iter = fContextMap.begin();
52
53 while (iter != fContextMap.end()) {
54 delete iter->second;
55 iter++;
56 }
57
58 delete filter;
59}

Member Function Documentation

◆ AddIntervalContext()

void G4TrajectoryDrawByAttribute::AddIntervalContext ( const G4String name,
G4VisTrajContext context 
)

Definition at line 215 of file G4TrajectoryDrawByAttribute.cc.

216{
217 // Takes ownership of context
218 std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::Interval);
219
220 ContextMap::iterator iter = fContextMap.find(myPair);
221
222 if (iter != fContextMap.end()) {
224 ed <<"Interval "<< name <<" already exists";
226 ("G4TrajectoryDrawByAttribute::AddIntervalContext",
227 "modeling0119", FatalErrorInArgument, ed, "Invalid interval");
228 }
229
230 fContextMap[myPair] = context;
231}
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76

◆ AddValueContext()

void G4TrajectoryDrawByAttribute::AddValueContext ( const G4String name,
G4VisTrajContext context 
)

Definition at line 234 of file G4TrajectoryDrawByAttribute.cc.

235{
236 // Takes ownership of context
237 std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::SingleValue);
238
239 ContextMap::iterator iter = fContextMap.find(myPair);
240
241 if (iter != fContextMap.end()) {
243 ed <<"Single value "<< name <<" already exists";
245 ("G4TrajectoryDrawByAttribute::AddSingleValueContext",
246 "modeling0120", FatalErrorInArgument, ed, "Invalid value");
247 }
248
249 fContextMap[myPair] = context;
250}

◆ Draw() [1/2]

void G4TrajectoryDrawByAttribute::Draw ( const G4VTrajectory trajectory,
const G4bool visible = true 
) const
virtual

Implements G4VTrajectoryModel.

Definition at line 70 of file G4TrajectoryDrawByAttribute.cc.

72{
73 // Return if attribute name has not been set. Just print one warning
74 if (fAttName.isNull()) {
75
76 if (!fWarnedMissingAttribute) {
78 ed<<"Null attribute name";
79 G4Exception("G4TrajectoryDrawByAttribute::Draw",
80 "modeling0116",
81 JustWarning, ed);
82 fWarnedMissingAttribute = true;
83 }
84
85 return;
86 }
87
88 // Basically cache data loaded filter for efficiency
89 if (fFirst) {
90
91 fFirst = false;
92
93 // Get attribute definition
94 G4AttDef attDef;
95
96 // Expect definition to exist
97 if (!G4AttUtils::ExtractAttDef(object, fAttName, attDef)) {
98 static G4bool warnedUnableToExtract = false;
99 if (!warnedUnableToExtract) {
101 ed <<"Unable to extract attribute definition named "<<fAttName;
103 ("G4TrajectoryDrawByAttribute::Draw",
104 "modeling0117", JustWarning, ed, "Invalid attribute name");
105 G4cout << "Available attributes:\n"
106 << object.GetAttDefs();
107 warnedUnableToExtract = true;
108 }
109 return;
110 }
111
112 // Get new G4AttValue filter
113 filter = G4AttFilterUtils::GetNewFilter(attDef);
114 assert (0 != filter);
115
116 // Load both interval and single valued data. Single valued data should
117 // override interval data.
118 ContextMap::const_iterator iter = fContextMap.begin();
119
120 while (iter != fContextMap.end()) {
121 if (iter->first.second == G4TrajectoryDrawByAttribute::Interval) {
122 filter->LoadIntervalElement(iter->first.first);
123 }
124 else if (iter->first.second == G4TrajectoryDrawByAttribute::SingleValue) {
125 filter->LoadSingleValueElement(iter->first.first);
126 }
127 iter++;
128 }
129 }
130
131 // Get attribute value
132 G4AttValue attVal;
133
134 // Expect value to exist
135 if (!G4AttUtils::ExtractAttValue(object, fAttName, attVal)) {
136 static G4bool warnedUnableToExtract = false;
137 if (!warnedUnableToExtract) {
139 ed <<"Unable to extract attribute value named "<<fAttName;
141 ("G4TrajectoryDrawByAttribute::Draw",
142 "modeling0118", JustWarning, ed, "Invalid attribute name");
143 G4cout << "Available attributes:\n"
144 << object.GetAttDefs();
145 warnedUnableToExtract = true;
146 }
147 return;
148 }
149
150 G4VisTrajContext myContext(GetContext());
151 G4String key;
152
153 // If attribute value passes filter, get corresponding interval/single value
154 // key loaded into G4AttValue filter.
155 if (filter->GetValidElement(attVal, key)) {
156
157 // Extract context corresponding to valid key.
158 // Single value match should have overriden interval match.
159 ContextMap::const_iterator iter = fContextMap.begin();
160
161 G4bool gotContext(false);
162
163 while (!gotContext && (iter != fContextMap.end())) {
164 if (iter->first.first == key) {
165 myContext = *(iter->second);
166 gotContext = true;
167 }
168 iter++;
169 }
170
171 assert (gotContext);
172 }
173
174 myContext.SetVisible(visible);
175
176 if (GetVerbose()) {
177 G4cout<<"G4TrajectoryDrawByAttribute drawer named "<<Name();
178 G4cout<<", drawing style selected according to value of attribute "<<fAttName;
179 G4cout<<" : "<<attVal.GetValue()<<". Selected context:"<<G4endl;
180 myContext.Print(G4cout);
181 }
182
183 // Draw the trajectory
185}
@ JustWarning
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
const G4String & GetValue() const
Definition: G4AttValue.hh:64
G4bool isNull() const
virtual void LoadIntervalElement(const G4String &)=0
virtual G4bool GetValidElement(const G4AttValue &, G4String &) const =0
virtual void LoadSingleValueElement(const G4String &)=0
G4String Name() const
const G4VisTrajContext & GetContext() const
G4bool GetVerbose() const
G4VAttValueFilter * GetNewFilter(const G4AttDef &def)
G4bool ExtractAttDef(const T &object, const G4String &name, G4AttDef &def)
Definition: G4AttUtils.hh:62
G4bool ExtractAttValue(const T &object, const G4String &name, G4AttValue &attVal)
Definition: G4AttUtils.hh:76
void DrawLineAndPoints(const G4VTrajectory &traj, const G4VisTrajContext &, const G4int &i_mode)

◆ Draw() [2/2]

void G4TrajectoryDrawByAttribute::Draw ( const G4VTrajectory trajectory,
const G4int i_mode = 0,
const G4bool visible = true 
) const
virtual

Implements G4VTrajectoryModel.

Definition at line 62 of file G4TrajectoryDrawByAttribute.cc.

65{
66 Draw(object, visible);
67}
virtual void Draw(const G4VTrajectory &trajectory, const G4int &i_mode=0, const G4bool &visible=true) const

Referenced by Draw().

◆ Print()

void G4TrajectoryDrawByAttribute::Print ( std::ostream &  ostr) const
virtual

Implements G4VTrajectoryModel.

Definition at line 188 of file G4TrajectoryDrawByAttribute.cc.

189{
190 ostr<<"G4TrajectoryDrawByAttribute, dumping configuration for model named "<< Name() <<":"<<std::endl;;
191
192 ostr<<"Default configuration:"<<G4endl;
193 GetContext().Print(ostr);
194
195 ostr<<"\nAttribute name "<<fAttName<<std::endl;
196 ostr<<"\nKey<->Context map dump:"<<std::endl;
197
198 ContextMap::const_iterator iter = fContextMap.begin();
199
200 while (iter != fContextMap.end()) {
201 ostr<<"Context for key "<<iter->first.first<<":"<<std::endl;
202 iter->second->Print(ostr);
203
204 iter++;
205 }
206}
void Print(std::ostream &ostr) const

◆ Set()

void G4TrajectoryDrawByAttribute::Set ( const G4String attribute)

Definition at line 209 of file G4TrajectoryDrawByAttribute.cc.

210{
211 fAttName = name;
212}

The documentation for this class was generated from the following files: