]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliLVTree.cxx
Comments updated and merge problems solved.
[u/mrichter/AliRoot.git] / AliGeant4 / AliLVTree.cxx
CommitLineData
2f310734 1// $Id$
2// Category: geometry
3//
4// Author: I. Hrivnacova
5//
6// Class AliLVTree
7// ---------------------------
8// See the class description in the header file.
9
10#include "AliLVTree.h"
11#include "AliGlobals.h"
12#include "AliLVStructure.h"
2b49a442 13#ifdef G4VIS_USE
2f310734 14#include "AliColourStore.h"
15#endif
16
17#include "TG4GeometryServices.h"
18
19#include <G4LogicalVolumeStore.hh>
20#include <G4LogicalVolume.hh>
2b49a442 21#ifdef G4VIS_USE
2f310734 22#include <G4Colour.hh>
23#include <G4VisAttributes.hh>
24#endif
25
26AliLVTree* AliLVTree::fgInstance = 0;
27
28//_____________________________________________________________________________
29AliLVTree* AliLVTree::Instance()
30{
31// Static singleton access method.
32// ---
33
34 if (!fgInstance) new AliLVTree();
35
36 return fgInstance;
37}
38
39//_____________________________________________________________________________
40AliLVTree::AliLVTree()
41 : fMessenger(this)
42{
43// Protected singleton constructor.
44// ---
45
46 fgInstance = this;
47}
48
49//_____________________________________________________________________________
50AliLVTree::AliLVTree(const AliLVTree& right)
51 : fMessenger(this)
52{
53// Protected singleton copy constructor.
54// ---
55//
56 AliGlobals::Exception(
57 "Attempt to copy AliLVTree singleton.");
58}
59
60//_____________________________________________________________________________
61AliLVTree::~AliLVTree() {
62//
63}
64
65// operators
66
67//_____________________________________________________________________________
68AliLVTree& AliLVTree::operator=(const AliLVTree& right)
69{
70 // check assignement to self
71 if (this == &right) return *this;
72
73 AliGlobals::Exception(
74 "Attempt to assign AliLVTree singleton.");
75
76 return *this;
77
78}
79
80// protected methods
81
82//_____________________________________________________________________________
83void AliLVTree::RegisterLogicalVolume(G4LogicalVolume* lv, const G4String& path,
84 AliLVStructure& lvStructure) const
85{
86// Registers logical volume lv in the structure.
87// ---
88
89 lvStructure.AddNewVolume(lv, path);
90
91 // register daughters
92 G4int nofDaughters = lv->GetNoDaughters();
93 if (nofDaughters>0) {
94 G4String previousName = "";
95 for (G4int i=0; i<nofDaughters; i++) {
96 G4LogicalVolume* lvd = lv->GetDaughter(i)->GetLogicalVolume();
97 G4String currentName = lvd->GetName();
98 if (currentName != lv->GetName() && currentName != previousName) {
99 G4String newPath = path + lv->GetName() +"/";
100 RegisterLogicalVolume(lvd, newPath, lvStructure);
101 previousName = currentName;
102 }
103 }
104 }
105}
106
107//_____________________________________________________________________________
108void AliLVTree::Warn(const G4String& where, const G4String& lvName) const
109{
110// Prints warning "volume not found".
111// ---
112
113 G4String text("AliLVTree::" + where + ": " + lvName + " volume not found.");
114 AliGlobals::Warning(text);
115}
116
117//_____________________________________________________________________________
118void AliLVTree::Warn(const G4String& where) const
119{
120// Prints warning "volume not specified".
121// ---
122
123 G4String text("AliLVTree::" + where + ": " + " volume not specified.");
124 AliGlobals::Warning(text);
125}
126
127// public methods
128
129//_____________________________________________________________________________
130void AliLVTree::List(const G4String& lvName) const
131{
132// Lists logical volumes tree (daughters) of the logical volume
133// with specified lvName.
134// ----
135
136 G4LogicalVolume* lv
137 = TG4GeometryServices::Instance()->FindLogicalVolume(lvName);
138
139 if (lv) {
140 G4String path = "";
141 AliLVStructure lvStructure(path);
142 RegisterLogicalVolume(lv, path, lvStructure);
143 lvStructure.ListTree();
144 }
145 else
146 Warn("List", lvName);
147}
148
149//_____________________________________________________________________________
150void AliLVTree::List(G4LogicalVolume* lv) const
151{
152// Lists logical volumes tree of the given lv.
153// ----
154
155 if (!lv) {
156 Warn("List");
157 return;
158 }
159
160 List(lv->GetName());
161}
162
163//_____________________________________________________________________________
164void AliLVTree::ListLong(const G4String& lvName) const
165{
166// Lists logical volumes tree (daughters) of the logical volume
167// with specified lvName with numbers of daughters (physical volumes).
168// ----
169
170 G4LogicalVolume* lv
171 = TG4GeometryServices::Instance()->FindLogicalVolume(lvName);
172
173 if (lv) {
174 G4String path = "";
175 AliLVStructure lvStructure(path);
176 RegisterLogicalVolume(lv, path, lvStructure);
177 lvStructure.ListTreeLong();
178 }
179 else
180 Warn("ListLong", lvName);
181}
182
183//_____________________________________________________________________________
184void AliLVTree::ListLong(G4LogicalVolume* lv) const
185{
186// Lists logical volumes tree with numbers of daughters
187// (physical volumes) of the given lv.
188// ----
189
190 if (!lv) {
191 Warn("ListLong");
192 return;
193 }
194
195 ListLong(lv->GetName());
196}
197
198#ifdef G4VIS_USE
199
200//_____________________________________________________________________________
201void AliLVTree::SetLVTreeVisibility(G4LogicalVolume* lv,
202 G4bool visibility) const
203{
204// Sets visibility to the logical volumes tree (daughters) of
205// the logical volume lv.
206// ---
207
208 if (!lv) {
209 Warn("SetLVTreeVisibility");
210 return;
211 }
212
213 G4String path = "";
214 AliLVStructure lvStructure(path);
215 RegisterLogicalVolume(lv, path, lvStructure);
216 lvStructure.SetTreeVisibility(visibility);
217}
218
219//_____________________________________________________________________________
220void AliLVTree::SetVolumeVisibility(G4LogicalVolume* lv,
221 G4bool visibility) const
222{
223// Sets visibility to the specified logical volume.
224// ---
225
226 if (!lv) {
227 Warn("SetVolumeVisibility");
228 return;
229 }
230
231 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
232 G4VisAttributes* newVisAttributes;
233 if (kpVisAttributes) {
234 G4Colour oldColour = kpVisAttributes->GetColour();
235 newVisAttributes = new G4VisAttributes(oldColour);
236 }
237 else
238 newVisAttributes = new G4VisAttributes();
239 delete kpVisAttributes;
240
241 newVisAttributes->SetVisibility(visibility);
242
243 lv->SetVisAttributes(newVisAttributes);
244}
245
246//_____________________________________________________________________________
247void AliLVTree::SetLVTreeColour(G4LogicalVolume* lv,
248 const G4String& colName) const
249{
250// Sets colour to the logical volumes tree (daughters) of
251// the logical volume lv.
252// ---
253
254 if (!lv) {
255 Warn("SetLVTreeColour");
256 return;
257 }
258
259 G4String path = "";
260 AliLVStructure lvStructure(path);
261 RegisterLogicalVolume(lv, path, lvStructure);
262 lvStructure.SetTreeVisibility(true);
263 lvStructure.SetTreeColour(colName);
264}
265
266//_____________________________________________________________________________
267void AliLVTree::SetVolumeColour(G4LogicalVolume* lv,
268 const G4String& colName) const
269{
270// Sets colour to the specified logical volume.
271// ---
272
273 if (!lv) {
274 Warn("SetVolumeColour");
275 return;
276 }
277
278 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
279 delete kpVisAttributes;
280
281 G4VisAttributes* newVisAttributes = new G4VisAttributes();
282
283 AliColourStore* pColours = AliColourStore::Instance();
284 const G4Colour kColour = pColours->GetColour(colName);
285 newVisAttributes->SetVisibility(true);
286 newVisAttributes->SetColour(kColour);
287
288 lv->SetVisAttributes(newVisAttributes);
289}
290
291#endif //G4VIS_USE
292