Geant4 9.6.0
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// $Id$
27//
28// Filter manager. Manages filter models, factories, messengers,
29// command placement, filter mode etc
30//
31// Jane Tinslay, March 2006
32//
33#ifndef G4VISFILTERMANAGER_HH
34#define G4VISFILTERMANAGER_HH
35
36#include "G4String.hh"
37#include "G4UImessenger.hh"
38#include "G4VFilter.hh"
39#include "G4VModelFactory.hh"
40#include <vector>
41
42namespace FilterMode {
43 enum Mode {Soft, Hard};
44}
45
46template <typename T>
48
49public:
50
51 // Construct with command placement
53
55
56 // Useful typedef's
59
60 // Registration methods
63
64 // Do filtering
65 bool Accept(const T&);
66
67 // Command placement
69
70 // Filter mode operations
72 void SetMode(const G4String&);
74
75 // Print configuration
76 void Print(std::ostream& ostr, const G4String& name="") const;
77
78 // Accessors
79 const std::vector<Filter*>& FilterList() const;
80 const std::vector<Factory*>& FactoryList() const;
81
82private:
83
84 // Data members
85 G4String fPlacement; // Placement
86 FilterMode::Mode fMode;
87 std::vector<Factory*> fFactoryList;
88 std::vector<Filter*> fFilterList;
89 std::vector<G4UImessenger*> fMessengerList;
90
91};
92
93template <typename T>
95 :fPlacement(placement)
96{
97 fMode = FilterMode::Hard;
98}
99
100template <typename T>
102{
103 // Cleanup
104 std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin();
105
106 while (iterMsgr != fMessengerList.end()) {
107 delete *iterMsgr;
108 iterMsgr++;
109 }
110
111 typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin();
112
113 while (iterFactory != fFactoryList.end()) {
114 delete *iterFactory;
115 iterFactory++;
116 }
117
118 typename std::vector<Filter*>::iterator iterFilter = fFilterList.begin();
119
120 while (iterFilter != fFilterList.end()) {
121 delete *iterFilter;
122 iterFilter++;
123 }
124}
125
126template <typename T>
127void
129{
130 fFilterList.push_back(filter);
131}
132
133template <typename T>
134void
136{
137 fFactoryList.push_back(factory);
138
139 fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
140}
141
142template <typename T>
143bool
145{
146 typename std::vector<Filter*>::const_iterator iter = fFilterList.begin();
147 bool passed(true);
148
149 while (passed && (iter != fFilterList.end())) {
150 passed = (*iter)->Accept(obj);
151 iter++;
152 }
153
154 return passed;
155}
156
157template <typename T>
160{
161 return fPlacement;
162}
163
164template <typename T>
165void
167{
168 bool result(false);
169
170 G4String myMode(mode);
171 myMode.toLower();
172
173 if (myMode == "soft") {result = true; SetMode(FilterMode::Soft);}
174 else if (myMode == "hard") {result = true; SetMode(FilterMode::Hard);}
175
176 if (!result) {
178 ed << "Invalid Filter mode: "<<mode;
180 ("G4VisFilterManager::SetMode(const G4String& mode)", "visman0101", JustWarning, ed);
181 }
182}
183
184template <typename T>
185void
187{
188 fMode = mode;
189}
190
191template <typename T>
194{
195 return fMode;
196}
197
198template <typename T>
199void
200G4VisFilterManager<T>::Print(std::ostream& ostr, const G4String& name) const
201{
202 ostr<<"Registered filter factories:"<<std::endl;
203 typename std::vector<Factory*>::const_iterator iterFactory = fFactoryList.begin();
204
205 while (iterFactory != fFactoryList.end()) {
206 (*iterFactory)->Print(ostr);
207 iterFactory++;
208 }
209
210 if (0 == fFactoryList.size()) ostr<<" None"<<std::endl;
211
212 ostr<<std::endl;
213 ostr<<"Registered filters:"<<std::endl;
214
215 typename std::vector<Filter*>::const_iterator iterFilter = fFilterList.begin();
216
217 while (iterFilter != fFilterList.end()) {
218 if (!name.isNull()) {
219 if ((*iterFilter)->Name() == name) (*iterFilter)->PrintAll(ostr);
220 }
221 else {
222 (*iterFilter)->PrintAll(ostr);
223 }
224 iterFilter++;
225 }
226
227 if (0 == fFilterList.size()) ostr<<" None"<<std::endl;
228}
229
230template <typename T>
231const std::vector< G4VFilter<T>* >&
233{
234 return fFilterList;
235}
236
237template <typename T>
238const std::vector< G4VModelFactory< G4VFilter<T> >* >&
240{
241 return fFactoryList;
242}
243
244#endif
@ JustWarning
G4bool isNull() const
void toLower()
void SetMode(const G4String &)
void Register(Factory *)
bool Accept(const T &)
void SetMode(const FilterMode::Mode &)
G4VisFilterManager(const G4String &)
FilterMode::Mode GetMode() const
G4String Placement() const
const std::vector< Filter * > & FilterList() const
G4VModelFactory< Filter > Factory
const std::vector< Factory * > & FactoryList() const
void Print(std::ostream &ostr, const G4String &name="") const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76