ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VisFilterManager.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VisFilterManager.hh
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 
41 namespace FilterMode {
42  enum Mode {Soft, Hard};
43 }
44 
45 template <typename T>
47 
48 public:
49 
50  // Construct with command placement
52 
53  virtual ~G4VisFilterManager();
54 
55  // Useful typedef's
58 
59  // Registration methods
60  void Register(Filter*);
61  void Register(Factory*);
62 
63  // Do filtering
64  bool Accept(const T&);
65 
66  // Command placement
67  G4String Placement() const;
68 
69  // Filter mode operations
70  void SetMode(const FilterMode::Mode&);
71  void SetMode(const G4String&);
72  FilterMode::Mode GetMode() const;
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 
81 private:
82 
83  // Data members
84  G4String fPlacement; // Placement
86  std::vector<Factory*> fFactoryList;
87  std::vector<Filter*> fFilterList;
88  std::vector<G4UImessenger*> fMessengerList;
89 
90 };
91 
92 template <typename T>
94  :fPlacement(placement)
95 {
97 }
98 
99 template <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 
125 template <typename T>
126 void
128 {
129  fFilterList.push_back(filter);
130 }
131 
132 template <typename T>
133 void
135 {
136  fFactoryList.push_back(factory);
137 
138  fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
139 }
140 
141 template <typename T>
142 bool
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 
156 template <typename T>
157 G4String
159 {
160  return fPlacement;
161 }
162 
163 template <typename T>
164 void
166 {
167  bool result(false);
168 
169  G4String myMode(mode);
170  myMode.toLower();
171 
172  if (myMode == "soft") {result = true; SetMode(FilterMode::Soft);}
173  else if (myMode == "hard") {result = true; SetMode(FilterMode::Hard);}
174 
175  if (!result) {
177  ed << "Invalid Filter mode: "<<mode;
179  ("G4VisFilterManager::SetMode(const G4String& mode)", "visman0101", JustWarning, ed);
180  }
181 }
182 
183 template <typename T>
184 void
186 {
187  fMode = mode;
188 }
189 
190 template <typename T>
193 {
194  return fMode;
195 }
196 
197 template <typename T>
198 void
199 G4VisFilterManager<T>::Print(std::ostream& ostr, const G4String& name) const
200 {
201  ostr<<"Registered filter factories:"<<std::endl;
202  typename std::vector<Factory*>::const_iterator iterFactory = fFactoryList.begin();
203 
204  while (iterFactory != fFactoryList.end()) {
205  (*iterFactory)->Print(ostr);
206  iterFactory++;
207  }
208 
209  if (0 == fFactoryList.size()) ostr<<" None"<<std::endl;
210 
211  ostr<<std::endl;
212  ostr<<"Registered filters:"<<std::endl;
213 
214  typename std::vector<Filter*>::const_iterator iterFilter = fFilterList.begin();
215 
216  while (iterFilter != fFilterList.end()) {
217  if (!name.isNull()) {
218  if ((*iterFilter)->Name() == name) (*iterFilter)->PrintAll(ostr);
219  }
220  else {
221  (*iterFilter)->PrintAll(ostr);
222  }
223  iterFilter++;
224  }
225 
226  if (0 == fFilterList.size()) ostr<<" None"<<std::endl;
227 }
228 
229 template <typename T>
230 const std::vector< G4VFilter<T>* >&
232 {
233  return fFilterList;
234 }
235 
236 template <typename T>
237 const std::vector< G4VModelFactory< G4VFilter<T> >* >&
239 {
240  return fFactoryList;
241 }
242 
243 #endif