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"
13 #include "AliModule.h"
15 #include "AliColourStore.h"
18 #include "TG4GeometryServices.h"
20 #include <G4LogicalVolumeStore.hh>
21 #include <G4LogicalVolume.hh>
23 #include <G4Colour.hh>
24 #include <G4VisAttributes.hh>
27 AliLVTree* AliLVTree::fgInstance = 0;
29 //_____________________________________________________________________________
30 AliLVTree* AliLVTree::Instance()
32 // Static singleton access method.
35 if (!fgInstance) new AliLVTree();
40 //_____________________________________________________________________________
41 AliLVTree::AliLVTree()
44 // Protected singleton constructor.
50 //_____________________________________________________________________________
51 AliLVTree::AliLVTree(const AliLVTree& right)
54 // Protected singleton copy constructor.
57 AliGlobals::Exception(
58 "Attempt to copy AliLVTree singleton.");
61 //_____________________________________________________________________________
62 AliLVTree::~AliLVTree() {
68 //_____________________________________________________________________________
69 AliLVTree& AliLVTree::operator=(const AliLVTree& right)
71 // check assignement to self
72 if (this == &right) return *this;
74 AliGlobals::Exception(
75 "Attempt to assign AliLVTree singleton.");
83 //_____________________________________________________________________________
84 void AliLVTree::RegisterLogicalVolume(G4LogicalVolume* lv, const G4String& path,
85 AliLVStructure& lvStructure) const
87 // Registers logical volume lv in the structure.
90 lvStructure.AddNewVolume(lv, path);
93 G4int nofDaughters = lv->GetNoDaughters();
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;
108 //_____________________________________________________________________________
109 void AliLVTree::Warn(const G4String& where, const G4String& lvName) const
111 // Prints warning "volume not found".
114 G4String text("AliLVTree::" + where + ": " + lvName + " volume not found.");
115 AliGlobals::Warning(text);
118 //_____________________________________________________________________________
119 void AliLVTree::Warn(const G4String& where) const
121 // Prints warning "volume not specified".
124 G4String text("AliLVTree::" + where + ": " + " volume not specified.");
125 AliGlobals::Warning(text);
130 //_____________________________________________________________________________
131 void AliLVTree::List(const G4String& lvName) const
133 // Lists logical volumes tree (daughters) of the logical volume
134 // with specified lvName.
138 = TG4GeometryServices::Instance()->FindLogicalVolume(lvName);
142 AliLVStructure lvStructure(path);
143 RegisterLogicalVolume(lv, path, lvStructure);
144 lvStructure.ListTree();
147 Warn("List", lvName);
150 //_____________________________________________________________________________
151 void AliLVTree::List(G4LogicalVolume* lv) const
153 // Lists logical volumes tree of the given lv.
164 //_____________________________________________________________________________
165 void AliLVTree::ListLong(const G4String& lvName) const
167 // Lists logical volumes tree (daughters) of the logical volume
168 // with specified lvName with numbers of daughters (physical volumes).
172 = TG4GeometryServices::Instance()->FindLogicalVolume(lvName);
176 AliLVStructure lvStructure(path);
177 RegisterLogicalVolume(lv, path, lvStructure);
178 lvStructure.ListTreeLong();
181 Warn("ListLong", lvName);
184 //_____________________________________________________________________________
185 void AliLVTree::ListLong(G4LogicalVolume* lv) const
187 // Lists logical volumes tree with numbers of daughters
188 // (physical volumes) of the given lv.
196 ListLong(lv->GetName());
201 //_____________________________________________________________________________
202 void AliLVTree::SetLVTreeVisibility(G4LogicalVolume* lv,
203 G4bool visibility) const
205 // Sets visibility to the logical volumes tree (daughters) of
206 // the logical volume lv.
210 Warn("SetLVTreeVisibility");
215 AliLVStructure lvStructure(path);
216 RegisterLogicalVolume(lv, path, lvStructure);
217 lvStructure.SetTreeVisibility(visibility);
220 //_____________________________________________________________________________
221 void AliLVTree::SetVolumeVisibility(G4LogicalVolume* lv,
222 G4bool visibility) const
224 // Sets visibility to the specified logical volume.
228 Warn("SetVolumeVisibility");
232 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
233 G4VisAttributes* newVisAttributes;
234 if (kpVisAttributes) {
235 G4Colour oldColour = kpVisAttributes->GetColour();
236 newVisAttributes = new G4VisAttributes(oldColour);
239 newVisAttributes = new G4VisAttributes();
240 delete kpVisAttributes;
242 newVisAttributes->SetVisibility(visibility);
244 lv->SetVisAttributes(newVisAttributes);
247 //_____________________________________________________________________________
248 void AliLVTree::SetLVTreeColour(G4LogicalVolume* lv,
249 const G4String& colName) const
251 // Sets colour to the logical volumes tree (daughters) of
252 // the logical volume lv.
256 Warn("SetLVTreeColour");
261 AliLVStructure lvStructure(path);
262 RegisterLogicalVolume(lv, path, lvStructure);
263 lvStructure.SetTreeVisibility(true);
264 lvStructure.SetTreeColour(colName);
267 //_____________________________________________________________________________
268 void AliLVTree::SetVolumeColour(G4LogicalVolume* lv,
269 const G4String& colName) const
271 // Sets colour to the specified logical volume.
275 Warn("SetVolumeColour");
279 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
280 delete kpVisAttributes;
282 G4VisAttributes* newVisAttributes = new G4VisAttributes();
284 AliColourStore* pColours = AliColourStore::Instance();
285 const G4Colour kColour = pColours->GetColour(colName);
286 newVisAttributes->SetVisibility(true);
287 newVisAttributes->SetColour(kColour);
289 lv->SetVisAttributes(newVisAttributes);