Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VisFilterManager.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// Filter manager. Manages filter models, factories, messengers,
28// command placement, filter mode etc
29//
30// Jane Tinslay, March 2006
31//
32#ifndef G4VISFILTERMANAGER_HH
33#define G4VISFILTERMANAGER_HH
34
35#include "G4String.hh"
36#include "G4UImessenger.hh"
37#include "G4VFilter.hh"
38#include "G4VModelFactory.hh"
39#include <vector>
40
41namespace FilterMode {
42 enum Mode {Soft, Hard};
43}
44
45template <typename T>
47
48public:
49
50 // Construct with command placement
52
54
55 // Useful typedef's
58
59 // Registration methods
62
63 // Do filtering
64 bool Accept(const T&);
65
66 // Command placement
68
69 // Filter mode operations
71 void SetMode(const G4String&);
73
74 // Print configuration
75 void Print(std::ostream& ostr, const G4String& name="") const;
76
77 // Accessors
78 const std::vector<Filter*>& FilterList() const;
79 const std::vector<Factory*>& FactoryList() const;
80
81private:
82
83 // Data members
84 G4String fPlacement; // Placement
85 FilterMode::Mode fMode;
86 std::vector<Factory*> fFactoryList;
87 std::vector<Filter*> fFilterList;
88 std::vector<G4UImessenger*> fMessengerList;
89
90};
91
92template <typename T>
94 :fPlacement(placement)
95{
96 fMode = FilterMode::Hard;
97}
98
99template <typename T>
101{
102 // Cleanup
103 std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin();
104
105 while (iterMsgr != fMessengerList.end()) {
106 delete *iterMsgr;
107 iterMsgr++;
108 }
109
110 typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin();
111
112 while (iterFactory != fFactoryList.end()) {
113 delete *iterFactory;
114 iterFactory++;
115 }
116
117 typename std::vector<Filter*>::iterator iterFilter = fFilterList.begin();
118
119 while (iterFilter != fFilterList.end()) {
120 delete *iterFilter;
121 iterFilter++;
122 }
123}
124
125template <typename T>
126void
128{
129 fFilterList.push_back(filter);
130}
131
132template <typename T>
133void
135{
136 fFactoryList.push_back(factory);
137
138 fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
139}
140
141template <typename T>
142bool
144{
145 typename std::vector<Filter*>::const_iterator iter = fFilterList.begin();
146 bool passed(true);
147
148 while (passed && (iter != fFilterList.end())) {
149 passed = (*iter)->Accept(obj);
150 iter++;
151 }
152
153 return passed;
154}
155
156template <typename T>
159{
160 return fPlacement;
161}
162
163template <typename T>
164void
166{
167 bool result(false);
168
169 G4String myMode = G4StrUtil::to_lower_copy(mode);
170
171 if (myMode == "soft") {result = true; SetMode(FilterMode::Soft);}
172 else if (myMode == "hard") {result = true; SetMode(FilterMode::Hard);}
173
174 if (!result) {
176 ed << "Invalid Filter mode: "<<mode;
178 ("G4VisFilterManager::SetMode(const G4String& mode)", "visman0101", JustWarning, ed);
179 }
180}
181
182template <typename T>
183void
185{
186 fMode = mode;
187}
188
189template <typename T>
192{
193 return fMode;
194}
195
196template <typename T>
197void
198G4VisFilterManager<T>::Print(std::ostream& ostr, const G4String& name) const
199{
200 ostr<<"Registered filter factories:"<<std::endl;
201 typename std::vector<Factory*>::const_iterator iterFactory = fFactoryList.begin();
202
203 while (iterFactory != fFactoryList.end()) {
204 (*iterFactory)->Print(ostr);
205 iterFactory++;
206 }
207
208 if (0 == fFactoryList.size()) ostr<<" None"<<std::endl;
209
210 ostr<<std::endl;
211 ostr<<"Registered filters:"<<std::endl;
212
213 typename std::vector<Filter*>::const_iterator iterFilter = fFilterList.begin();
214
215 while (iterFilter != fFilterList.end()) {
216 if (!name.empty()) {
217 if ((*iterFilter)->Name() == name) (*iterFilter)->PrintAll(ostr);
218 }
219 else {
220 (*iterFilter)->PrintAll(ostr);
221 }
222 iterFilter++;
223 }
224
225 if (0 == fFilterList.size()) ostr<<" None"<<std::endl;
226}
227
228template <typename T>
229const std::vector< G4VFilter<T>* >&
231{
232 return fFilterList;
233}
234
235template <typename T>
236const std::vector< G4VModelFactory< G4VFilter<T> >* >&
238{
239 return fFactoryList;
240}
241
242#endif
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
void SetMode(const G4String &)
void SetMode(const FilterMode::Mode &)
G4VisFilterManager(const G4String &)
G4VModelFactory< Filter > Factory
FilterMode::Mode GetMode() const
G4String Placement() const
const std::vector< Filter * > & FilterList() const
const std::vector< Factory * > & FactoryList() const
void Print(std::ostream &ostr, const G4String &name="") const