]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliLVStructure.cxx
New Clusterization by IHEP (yuri)
[u/mrichter/AliRoot.git] / AliGeant4 / AliLVStructure.cxx
CommitLineData
676fb573 1// $Id$
2// Category: geometry
3//
7005154f 4// Author: I. Hrivnacova
5//
6// Class AliLVStructure
7// --------------------
676fb573 8// See the class description in the header file.
9
10#include "AliLVStructure.h"
11#include "AliGlobals.h"
12
13#ifdef ALICE_VISUALIZE
14#include "AliColourStore.h"
15
16#include <G4Colour.hh>
17#include <G4VisAttributes.hh>
18#endif //ALICE_VISUALIZE
c97337f9 19#include <G4LogicalVolume.hh>
676fb573 20
78ca1e9c 21//_____________________________________________________________________________
676fb573 22AliLVStructure::AliLVStructure(G4String path)
23 : fPathName(path),
24 fDirName(path),
25 fVerboseLevel(0)
26{
27//
28 G4int i = fDirName.length();
29 if (i > 1) {
30 fDirName.remove(i-1);
31 G4int isl = fDirName.last('/');
32 fDirName.remove(0,isl+1);
33 fDirName += "/";
34 }
35}
36
78ca1e9c 37//_____________________________________________________________________________
676fb573 38AliLVStructure::AliLVStructure(const AliLVStructure& right)
39{
58c0119e 40 // copy stuff
41 *this = right;
676fb573 42}
43
78ca1e9c 44//_____________________________________________________________________________
676fb573 45AliLVStructure::AliLVStructure() {
46//
47}
48
78ca1e9c 49//_____________________________________________________________________________
676fb573 50AliLVStructure::~AliLVStructure() {
51//
52 fStructures.clearAndDestroy();
53 fLogicalVolumes.clear();
54}
55
56// operators
57
78ca1e9c 58//_____________________________________________________________________________
676fb573 59AliLVStructure& AliLVStructure::operator=(const AliLVStructure &right)
60{
61 // check assignement to self
62 if (this == &right) return *this;
63
64 // copy vector of structures
65 fStructures.clearAndDestroy();
66 G4int i;
67 for (i=0; i<right.fStructures.entries(); i++) {
68 // new full structure tree has to be created
69 AliLVStructure* rhsStructure = right.fStructures[i];
70 fStructures.insert(new AliLVStructure(*rhsStructure));
71 }
72
73 // copy vector of logical volumes
74 fLogicalVolumes.clear();
75 for (i=0; i<right.fLogicalVolumes.entries(); i++) {
76 G4LogicalVolume* rhsLV = right.fLogicalVolumes[i];
77 fLogicalVolumes.insert(rhsLV);
78 }
79
80 fPathName = right.fPathName;
81 fDirName = right.fPathName;
82 fVerboseLevel = right.fVerboseLevel;
83
84 return *this;
85}
86
78ca1e9c 87//_____________________________________________________________________________
676fb573 88G4int AliLVStructure::operator==(const AliLVStructure &right) const
89{
90 // check == to self
91 if (this == &right) return true;
92
93 return false;
94}
95
96// private methods
97
78ca1e9c 98//_____________________________________________________________________________
cbac26a9 99AliLVStructure* AliLVStructure::FindSubDirectory(const G4String& subDir) const
676fb573 100{
101// Finds the subdirectory.
102// ---
103
104 for( G4int i=0; i<fStructures.entries(); i++ ) {
105 if (subDir == fStructures(i)->fDirName) return fStructures(i);
106 }
107 return 0;
108}
109
78ca1e9c 110//_____________________________________________________________________________
cbac26a9 111G4String AliLVStructure::ExtractDirName(const G4String& name) const
676fb573 112{
113// Extracts the directory name from the path.
114// ---
115
116 G4String subDir = name;
117 G4int i = name.first('/');
118 if (i != G4std::string::npos) subDir.remove(i+1);
119 return subDir;
120}
121
122// public methods
123
78ca1e9c 124//_____________________________________________________________________________
676fb573 125void AliLVStructure::AddNewVolume(G4LogicalVolume* lv,
cbac26a9 126 const G4String& treeStructure)
676fb573 127{
128// Adds new logical volume to the structure.
129// ---
130
131 G4String remainingPath = treeStructure;
132 remainingPath.remove(0, fPathName.length());
133 if (!remainingPath.isNull()) {
134 // The lv should be kept in subdirectory.
135 // First, check if the subdirectoy exists.
136 G4String subDir = ExtractDirName( remainingPath );
137 AliLVStructure* targetLVS = FindSubDirectory(subDir);
138 if (targetLVS == 0) {
139 // Subdirectory not found. Create a new directory.
140 subDir.prepend(fPathName);
141 targetLVS = new AliLVStructure(subDir);
142 fStructures.insert( targetLVS );
143 }
144 targetLVS->AddNewVolume(lv, treeStructure);
145 }
146 else {
147 // the logical volumes should be kept in this directory.
148 G4LogicalVolume* targetLV = GetVolume(lv->GetName());
149 if (targetLV != 0) {
150 // G4cout << lv->GetName() << " had already stored in "
5f1d09c5 151 // << fPathName << G4endl;
676fb573 152 }
153 else {
154 fLogicalVolumes.insert(lv);
155 }
156 }
157}
158
78ca1e9c 159//_____________________________________________________________________________
cbac26a9 160G4LogicalVolume* AliLVStructure::GetVolume(const G4String& lvName) const
676fb573 161{
162// Returns logical volume of lvName if present in the structure,
163// returns 0 otherwise.
164// ---
165
166 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
167 G4LogicalVolume* targetLV = fLogicalVolumes(i);
168 if (lvName == targetLV->GetName()) return targetLV;
169 }
170 return 0;
171}
172
78ca1e9c 173//_____________________________________________________________________________
cbac26a9 174G4LogicalVolume* AliLVStructure::FindVolume(const G4String& name) const
676fb573 175{
176// Finds logical volume of given name in all structure tree.
177// ---
178
179 G4String path = name;
180 path.remove(0, fPathName.length());
181 if (path.first('/') != G4std::string::npos) {
182 // SD exists in sub-directory
183 G4String subDir = ExtractDirName(path);
184 AliLVStructure* targetLVS = FindSubDirectory(subDir);
185 if (targetLVS == 0) {
186 // The subdirectory is not found
187 G4String text = subDir + " is not found in " + fPathName;
188 AliGlobals:: Warning(text);
189 return 0;
190 }
191 else {
192 return targetLVS->FindVolume(name);
193 }
194 }
195 else {
196 // LV must exist in this directory
197 G4LogicalVolume* targetLV = GetVolume(path);
198 if (targetLV == 0) {
199 // The fLogicalVolumes is not found.
200 G4String text = path + " is not found in " + fPathName;
201 AliGlobals::Warning(text);
202 }
203 return targetLV;
204 }
205}
206
78ca1e9c 207//_____________________________________________________________________________
676fb573 208void AliLVStructure::ListTree() const
209{
210// Prints LV tree structure.
211// ---
212
213 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
214 G4LogicalVolume* lv = fLogicalVolumes(i);
5f1d09c5 215 G4cout << fPathName << lv->GetName() << G4endl;
676fb573 216 }
217 for (G4int j=0; j<fStructures.entries(); j++) {
218 fStructures(j)->ListTree();
219 }
220}
221
78ca1e9c 222//_____________________________________________________________________________
676fb573 223void AliLVStructure::ListTreeLong() const
224{
225// Prints LV tree structure with number of
226// daughters (physical volume)
227// ---
228
229 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
230 G4LogicalVolume* lv = fLogicalVolumes(i);
231 G4cout << fPathName << lv->GetName()
5f1d09c5 232 << " (" << lv->GetNoDaughters() << ")" << G4endl;
676fb573 233 }
234 for (G4int j=0; j<fStructures.entries(); j++) {
235 fStructures(j)->ListTreeLong();
236 }
237}
238
78ca1e9c 239//_____________________________________________________________________________
676fb573 240void AliLVStructure::SetVerboseLevel(G4int verbose)
241{
242// Sets verbose level.
243// ---
244
245 fVerboseLevel = verbose;
246 for (G4int i=0; i<fStructures.entries(); i++) {
247 fStructures(i)->SetVerboseLevel(verbose);
248 }
249}
250
251#ifdef ALICE_VISUALIZE
78ca1e9c 252//_____________________________________________________________________________
676fb573 253void AliLVStructure::SetTreeVisibility(G4bool visibility)
254{
255// Sets visibility to all logical volumes in the structure
256// tree.
257// ---
258
259 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
260 G4LogicalVolume* lv = fLogicalVolumes(i);
261
30a3cbee 262 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes();
263 G4VisAttributes* newVisAttributes;
264 if (kpVisAttributes) {
265 G4Colour colour = kpVisAttributes->GetColour();
266 newVisAttributes = new G4VisAttributes(colour);
267 }
268 else
269 newVisAttributes = new G4VisAttributes();
676fb573 270 delete kpVisAttributes;
271
272 newVisAttributes->SetVisibility(visibility);
273
274 lv->SetVisAttributes(newVisAttributes);
275 }
276 for (G4int j=0; j<fStructures.entries(); j++) {
277 fStructures(j)->SetTreeVisibility(visibility);
278 }
279}
280
78ca1e9c 281//_____________________________________________________________________________
cbac26a9 282void AliLVStructure::SetTreeColour(const G4String& colName)
676fb573 283{
284// Sets colour specified by name to all logical volumes
285// in the structure tree.
286// ---
287
288 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
289 G4LogicalVolume* lv = fLogicalVolumes(i);
290
291 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
30a3cbee 292 G4VisAttributes* newVisAttributes;
293 if (kpVisAttributes) {
294 G4bool oldVisibility = kpVisAttributes->IsVisible();
295 newVisAttributes = new G4VisAttributes(oldVisibility);
296 }
297 else
298 newVisAttributes = new G4VisAttributes();
676fb573 299 delete kpVisAttributes;
300
301 AliColourStore* pColours = AliColourStore::Instance();
302 G4Colour colour = pColours->GetColour(colName);
303 newVisAttributes->SetColour(colour);
304
305 lv->SetVisAttributes(newVisAttributes);
306 }
307 for (G4int j=0; j<fStructures.entries(); j++) {
308 fStructures(j)->SetTreeColour(colName);
309 }
310}
311#endif
312
313