4 // Author: I. Hrivnacova
7 // ---------------------------
8 // See the class description in the header file.
10 #include "AliLVTree.h"
11 #include "AliGlobals.h"
12 #include "AliLVStructure.h"
14 #include "AliColourStore.h"
17 #include "TG4GeometryServices.h"
19 #include <G4LogicalVolumeStore.hh>
20 #include <G4LogicalVolume.hh>
22 #include <G4Colour.hh>
23 #include <G4VisAttributes.hh>
26 AliLVTree* AliLVTree::fgInstance = 0;
28 //_____________________________________________________________________________
29 AliLVTree* AliLVTree::Instance()
31 // Static singleton access method.
34 if (!fgInstance) new AliLVTree();
39 //_____________________________________________________________________________
40 AliLVTree::AliLVTree()
43 // Protected singleton constructor.
49 //_____________________________________________________________________________
50 AliLVTree::AliLVTree(const AliLVTree& right)
53 // Protected singleton copy constructor.
56 AliGlobals::Exception(
57 "Attempt to copy AliLVTree singleton.");
60 //_____________________________________________________________________________
61 AliLVTree::~AliLVTree() {
67 //_____________________________________________________________________________
68 AliLVTree& AliLVTree::operator=(const AliLVTree& right)
70 // check assignement to self
71 if (this == &right) return *this;
73 AliGlobals::Exception(
74 "Attempt to assign AliLVTree singleton.");
82 //_____________________________________________________________________________
83 void AliLVTree::RegisterLogicalVolume(G4LogicalVolume* lv, const G4String& path,
84 AliLVStructure& lvStructure) const
86 // Registers logical volume lv in the structure.
89 lvStructure.AddNewVolume(lv, path);
92 G4int nofDaughters = lv->GetNoDaughters();
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;
107 //_____________________________________________________________________________
108 void AliLVTree::Warn(const G4String& where, const G4String& lvName) const
110 // Prints warning "volume not found".
113 G4String text("AliLVTree::" + where + ": " + lvName + " volume not found.");
114 AliGlobals::Warning(text);
117 //_____________________________________________________________________________
118 void AliLVTree::Warn(const G4String& where) const
120 // Prints warning "volume not specified".
123 G4String text("AliLVTree::" + where + ": " + " volume not specified.");
124 AliGlobals::Warning(text);
129 //_____________________________________________________________________________
130 void AliLVTree::List(const G4String& lvName) const
132 // Lists logical volumes tree (daughters) of the logical volume
133 // with specified lvName.
137 = TG4GeometryServices::Instance()->FindLogicalVolume(lvName);
141 AliLVStructure lvStructure(path);
142 RegisterLogicalVolume(lv, path, lvStructure);
143 lvStructure.ListTree();
146 Warn("List", lvName);
149 //_____________________________________________________________________________
150 void AliLVTree::List(G4LogicalVolume* lv) const
152 // Lists logical volumes tree of the given lv.
163 //_____________________________________________________________________________
164 void AliLVTree::ListLong(const G4String& lvName) const
166 // Lists logical volumes tree (daughters) of the logical volume
167 // with specified lvName with numbers of daughters (physical volumes).
171 = TG4GeometryServices::Instance()->FindLogicalVolume(lvName);
175 AliLVStructure lvStructure(path);
176 RegisterLogicalVolume(lv, path, lvStructure);
177 lvStructure.ListTreeLong();
180 Warn("ListLong", lvName);
183 //_____________________________________________________________________________
184 void AliLVTree::ListLong(G4LogicalVolume* lv) const
186 // Lists logical volumes tree with numbers of daughters
187 // (physical volumes) of the given lv.
195 ListLong(lv->GetName());
200 //_____________________________________________________________________________
201 void AliLVTree::SetLVTreeVisibility(G4LogicalVolume* lv,
202 G4bool visibility) const
204 // Sets visibility to the logical volumes tree (daughters) of
205 // the logical volume lv.
209 Warn("SetLVTreeVisibility");
214 AliLVStructure lvStructure(path);
215 RegisterLogicalVolume(lv, path, lvStructure);
216 lvStructure.SetTreeVisibility(visibility);
219 //_____________________________________________________________________________
220 void AliLVTree::SetVolumeVisibility(G4LogicalVolume* lv,
221 G4bool visibility) const
223 // Sets visibility to the specified logical volume.
227 Warn("SetVolumeVisibility");
231 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
232 G4VisAttributes* newVisAttributes;
233 if (kpVisAttributes) {
234 G4Colour oldColour = kpVisAttributes->GetColour();
235 newVisAttributes = new G4VisAttributes(oldColour);
238 newVisAttributes = new G4VisAttributes();
239 delete kpVisAttributes;
241 newVisAttributes->SetVisibility(visibility);
243 lv->SetVisAttributes(newVisAttributes);
246 //_____________________________________________________________________________
247 void AliLVTree::SetLVTreeColour(G4LogicalVolume* lv,
248 const G4String& colName) const
250 // Sets colour to the logical volumes tree (daughters) of
251 // the logical volume lv.
255 Warn("SetLVTreeColour");
260 AliLVStructure lvStructure(path);
261 RegisterLogicalVolume(lv, path, lvStructure);
262 lvStructure.SetTreeVisibility(true);
263 lvStructure.SetTreeColour(colName);
266 //_____________________________________________________________________________
267 void AliLVTree::SetVolumeColour(G4LogicalVolume* lv,
268 const G4String& colName) const
270 // Sets colour to the specified logical volume.
274 Warn("SetVolumeColour");
278 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
279 delete kpVisAttributes;
281 G4VisAttributes* newVisAttributes = new G4VisAttributes();
283 AliColourStore* pColours = AliColourStore::Instance();
284 const G4Colour kColour = pColours->GetColour(colName);
285 newVisAttributes->SetVisibility(true);
286 newVisAttributes->SetColour(kColour);
288 lv->SetVisAttributes(newVisAttributes);