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