Geant4-11
Public Member Functions | Private Types | Private Attributes
G4TrajectoryDrawByAttribute Class Reference

#include <G4TrajectoryDrawByAttribute.hh>

Inheritance diagram for G4TrajectoryDrawByAttribute:
G4VTrajectoryModel

Public Member Functions

void AddIntervalContext (const G4String &name, G4VisTrajContext *context)
 
void AddValueContext (const G4String &name, G4VisTrajContext *context)
 
virtual void Draw (const G4VTrajectory &trajectory, const G4bool &visible=true) const
 
 G4TrajectoryDrawByAttribute (const G4String &name="Unspecified", G4VisTrajContext *context=0)
 
const G4VisTrajContextGetContext () const
 
G4bool GetVerbose () const
 
G4String Name () const
 
virtual void Print (std::ostream &ostr) const
 
void Set (const G4String &attribute)
 
void SetVerbose (const G4bool &)
 
virtual ~G4TrajectoryDrawByAttribute ()
 

Private Types

enum  Config { Interval , SingleValue }
 
typedef std::map< Pair, G4VisTrajContext * > ContextMap
 
typedef std::pair< G4String, ConfigPair
 

Private Attributes

G4String fAttName
 
ContextMap fContextMap
 
G4bool fFirst
 
G4VAttValueFilterfilter
 
G4String fName
 
G4VisTrajContextfpContext
 
G4bool fVerbose
 
G4bool fWarnedMissingAttribute
 

Detailed Description

Definition at line 41 of file G4TrajectoryDrawByAttribute.hh.

Member Typedef Documentation

◆ ContextMap

Definition at line 68 of file G4TrajectoryDrawByAttribute.hh.

◆ Pair

typedef std::pair<G4String, Config> G4TrajectoryDrawByAttribute::Pair
private

Definition at line 67 of file G4TrajectoryDrawByAttribute.hh.

Member Enumeration Documentation

◆ Config

Constructor & Destructor Documentation

◆ G4TrajectoryDrawByAttribute()

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

Definition at line 40 of file G4TrajectoryDrawByAttribute.cc.

42 ,fAttName("")
43 ,fFirst(true)
45 ,filter(0)
46{}
G4VTrajectoryModel(const G4String &name, G4VisTrajContext *fpContext=0)
const char * name(G4int ptype)
context
Definition: g4zmq.py:11

◆ ~G4TrajectoryDrawByAttribute()

G4TrajectoryDrawByAttribute::~G4TrajectoryDrawByAttribute ( )
virtual

Definition at line 48 of file G4TrajectoryDrawByAttribute.cc.

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

References fContextMap, and filter.

Member Function Documentation

◆ AddIntervalContext()

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

Definition at line 204 of file G4TrajectoryDrawByAttribute.cc.

205{
206 // Takes ownership of context
207 std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::Interval);
208
209 ContextMap::iterator iter = fContextMap.find(myPair);
210
211 if (iter != fContextMap.end()) {
213 ed <<"Interval "<< name <<" already exists";
215 ("G4TrajectoryDrawByAttribute::AddIntervalContext",
216 "modeling0119", FatalErrorInArgument, ed, ". Invalid interval");
217 }
218
219 fContextMap[myPair] = context;
220}
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40

References g4zmq::context, FatalErrorInArgument, fContextMap, G4Exception(), Interval, and G4InuclParticleNames::name().

◆ AddValueContext()

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

Definition at line 223 of file G4TrajectoryDrawByAttribute.cc.

224{
225 // Takes ownership of context
226 std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::SingleValue);
227
228 ContextMap::iterator iter = fContextMap.find(myPair);
229
230 if (iter != fContextMap.end()) {
232 ed <<"Single value "<< name <<" already exists";
234 ("G4TrajectoryDrawByAttribute::AddSingleValueContext",
235 "modeling0120", FatalErrorInArgument, ed, ". Invalid value");
236 }
237
238 fContextMap[myPair] = context;
239}

References g4zmq::context, FatalErrorInArgument, fContextMap, G4Exception(), G4InuclParticleNames::name(), and SingleValue.

◆ Draw()

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

Implements G4VTrajectoryModel.

Definition at line 61 of file G4TrajectoryDrawByAttribute.cc.

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

References G4TrajectoryDrawerUtils::DrawLineAndPoints(), G4AttUtils::ExtractAttDef(), G4AttUtils::ExtractAttValue(), fAttName, fContextMap, fFirst, filter, fWarnedMissingAttribute, G4cout, G4endl, G4Exception(), G4VTrajectoryModel::GetContext(), G4AttFilterUtils::GetNewFilter(), G4VAttValueFilter::GetValidElement(), G4AttValue::GetValue(), G4VTrajectoryModel::GetVerbose(), Interval, JustWarning, G4VAttValueFilter::LoadIntervalElement(), G4VAttValueFilter::LoadSingleValueElement(), G4VTrajectoryModel::Name(), G4VisTrajContext::Print(), and SingleValue.

◆ GetContext()

const G4VisTrajContext & G4VTrajectoryModel::GetContext ( ) const
inherited

◆ GetVerbose()

G4bool G4VTrajectoryModel::GetVerbose ( ) const
inherited

◆ Name()

G4String G4VTrajectoryModel::Name ( ) const
inherited

◆ Print()

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

Implements G4VTrajectoryModel.

Definition at line 177 of file G4TrajectoryDrawByAttribute.cc.

178{
179 ostr<<"G4TrajectoryDrawByAttribute, dumping configuration for model named "<< Name() <<":"<<std::endl;;
180
181 ostr<<"Default configuration:"<<G4endl;
182 GetContext().Print(ostr);
183
184 ostr<<"\nAttribute name "<<fAttName<<std::endl;
185 ostr<<"\nKey<->Context map dump:"<<std::endl;
186
187 ContextMap::const_iterator iter = fContextMap.begin();
188
189 while (iter != fContextMap.end()) {
190 ostr<<"Context for key "<<iter->first.first<<":"<<std::endl;
191 iter->second->Print(ostr);
192
193 iter++;
194 }
195}
void Print(std::ostream &ostr) const

References fAttName, fContextMap, G4endl, G4VTrajectoryModel::GetContext(), G4VTrajectoryModel::Name(), and G4VisTrajContext::Print().

◆ Set()

void G4TrajectoryDrawByAttribute::Set ( const G4String attribute)

Definition at line 198 of file G4TrajectoryDrawByAttribute.cc.

199{
200 fAttName = name;
201}

References fAttName, and G4InuclParticleNames::name().

◆ SetVerbose()

void G4VTrajectoryModel::SetVerbose ( const G4bool verbose)
inherited

Definition at line 67 of file G4VTrajectoryModel.cc.

68{
69 fVerbose = verbose;
70}

References G4VTrajectoryModel::fVerbose.

Field Documentation

◆ fAttName

G4String G4TrajectoryDrawByAttribute::fAttName
private

Definition at line 71 of file G4TrajectoryDrawByAttribute.hh.

Referenced by Draw(), Print(), and Set().

◆ fContextMap

ContextMap G4TrajectoryDrawByAttribute::fContextMap
private

◆ fFirst

G4bool G4TrajectoryDrawByAttribute::fFirst
mutableprivate

Definition at line 75 of file G4TrajectoryDrawByAttribute.hh.

Referenced by Draw().

◆ filter

G4VAttValueFilter* G4TrajectoryDrawByAttribute::filter
mutableprivate

Definition at line 77 of file G4TrajectoryDrawByAttribute.hh.

Referenced by Draw(), and ~G4TrajectoryDrawByAttribute().

◆ fName

G4String G4VTrajectoryModel::fName
privateinherited

Definition at line 75 of file G4VTrajectoryModel.hh.

Referenced by G4VTrajectoryModel::Name().

◆ fpContext

G4VisTrajContext* G4VTrajectoryModel::fpContext
privateinherited

◆ fVerbose

G4bool G4VTrajectoryModel::fVerbose
privateinherited

◆ fWarnedMissingAttribute

G4bool G4TrajectoryDrawByAttribute::fWarnedMissingAttribute
mutableprivate

Definition at line 76 of file G4TrajectoryDrawByAttribute.hh.

Referenced by Draw().


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