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