Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4TrajectoryDrawByAttribute Class Reference

#include <G4TrajectoryDrawByAttribute.hh>

Inheritance diagram for G4TrajectoryDrawByAttribute:
Collaboration diagram for G4TrajectoryDrawByAttribute:

Public Member Functions

 G4TrajectoryDrawByAttribute (const G4String &name="Unspecified", G4VisTrajContext *context=0)
 
virtual ~G4TrajectoryDrawByAttribute ()
 
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 ()
 
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 ( 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 {}
G4VTrajectoryModel(const G4String &name, G4VisTrajContext *fpContext=0)
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

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

Definition at line 207 of file G4TrajectoryDrawByAttribute.cc.

208 {
209  // Takes ownership of context
210  std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::Interval);
211 
212  ContextMap::iterator iter = fContextMap.find(myPair);
213 
214  if (iter != fContextMap.end()) {
216  ed <<"Interval "<< name <<" already exists";
218  ("G4TrajectoryDrawByAttribute::AddIntervalContext",
219  "modeling0119", FatalErrorInArgument, ed, ". Invalid interval");
220  }
221 
222  fContextMap[myPair] = context;
223 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const XML_Char * context
Definition: expat.h:434

Here is the call graph for this function:

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

Definition at line 226 of file G4TrajectoryDrawByAttribute.cc.

227 {
228  // Takes ownership of context
229  std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::SingleValue);
230 
231  ContextMap::iterator iter = fContextMap.find(myPair);
232 
233  if (iter != fContextMap.end()) {
235  ed <<"Single value "<< name <<" already exists";
237  ("G4TrajectoryDrawByAttribute::AddSingleValueContext",
238  "modeling0120", FatalErrorInArgument, ed, ". Invalid value");
239  }
240 
241  fContextMap[myPair] = context;
242 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const XML_Char * context
Definition: expat.h:434

Here is the call graph for this function:

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

Implements G4VTrajectoryModel.

Definition at line 62 of file G4TrajectoryDrawByAttribute.cc.

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

Here is the call graph for this function:

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

Implements G4VTrajectoryModel.

Definition at line 180 of file G4TrajectoryDrawByAttribute.cc.

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

Here is the call graph for this function:

void G4TrajectoryDrawByAttribute::Set ( const G4String attribute)

Definition at line 201 of file G4TrajectoryDrawByAttribute.cc.

202 {
203  fAttName = name;
204 }
const XML_Char * name
Definition: expat.h:151

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