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