]>
Commit | Line | Data |
---|---|---|
676fb573 | 1 | // $Id$ |
2 | // Category: geometry | |
3 | // | |
4 | // See the class description in the header file. | |
5 | ||
6 | #include "AliModuleConstruction.h" | |
c97337f9 | 7 | #include "AliModuleConstructionMessenger.h" |
676fb573 | 8 | #include "AliGlobals.h" |
9 | #include "AliLVStructure.h" | |
c97337f9 | 10 | #include "AliModule.h" |
676fb573 | 11 | |
12 | #ifdef ALICE_VISUALIZE | |
13 | #include "AliColourStore.h" | |
14 | ||
15 | #include <G4Colour.hh> | |
16 | #include <G4VisAttributes.hh> | |
17 | #endif //ALICE_VISUALIZE | |
18 | #include <G4LogicalVolumeStore.hh> | |
19 | #include <G4LogicalVolume.hh> | |
20 | ||
78ca1e9c | 21 | //_____________________________________________________________________________ |
676fb573 | 22 | AliModuleConstruction::AliModuleConstruction(G4String moduleName) |
23 | : fModuleName(moduleName), | |
24 | fModuleFrameName(moduleName), | |
25 | fModuleFrameLV(0), | |
26 | fAliModule(0), | |
27 | fReadGeometry(false), | |
28 | fWriteGeometry(false), | |
29 | fDataFilePath("") | |
30 | { | |
31 | // | |
32 | moduleName.toLower(); | |
33 | fMessenger = new AliModuleConstructionMessenger(this, moduleName); | |
34 | } | |
35 | ||
78ca1e9c | 36 | //_____________________________________________________________________________ |
676fb573 | 37 | AliModuleConstruction::AliModuleConstruction(const AliModuleConstruction& right) |
38 | { | |
39 | // | |
58c0119e | 40 | // allocation in assignement operator |
41 | fMessenger = 0; | |
42 | ||
43 | // copy stuff | |
44 | *this = right; | |
676fb573 | 45 | } |
46 | ||
78ca1e9c | 47 | //_____________________________________________________________________________ |
676fb573 | 48 | AliModuleConstruction::AliModuleConstruction() |
49 | : fModuleName(""), | |
50 | fModuleFrameName(""), | |
51 | fModuleFrameLV(0), | |
52 | fMessenger(0), | |
53 | fAliModule(0), | |
54 | fReadGeometry(false), | |
55 | fWriteGeometry(false), | |
56 | fDataFilePath("") | |
57 | { | |
58 | // | |
59 | } | |
60 | ||
78ca1e9c | 61 | //_____________________________________________________________________________ |
676fb573 | 62 | AliModuleConstruction::~AliModuleConstruction() |
63 | { | |
64 | // | |
65 | delete fMessenger; | |
66 | delete fAliModule; | |
67 | } | |
68 | ||
69 | // operators | |
70 | ||
78ca1e9c | 71 | //_____________________________________________________________________________ |
676fb573 | 72 | AliModuleConstruction& |
73 | AliModuleConstruction::operator=(const AliModuleConstruction& right) | |
74 | { | |
75 | // check assignement to self | |
76 | if (this == &right) return *this; | |
77 | ||
78 | fModuleName = right.fModuleName; | |
79 | fModuleFrameName = right.fModuleFrameName; | |
80 | fModuleFrameLV = right.fModuleFrameLV; | |
81 | fAliModule = right.fAliModule; | |
82 | fReadGeometry = right.fReadGeometry; | |
83 | fWriteGeometry = right.fWriteGeometry; | |
84 | fDataFilePath = right.fDataFilePath; | |
85 | ||
58c0119e | 86 | // new messenger |
87 | if (fMessenger) delete fMessenger; | |
88 | G4String moduleName = fModuleName; | |
89 | moduleName.toLower(); | |
90 | fMessenger = new AliModuleConstructionMessenger(this, moduleName); | |
91 | ||
676fb573 | 92 | return *this; |
93 | } | |
94 | ||
78ca1e9c | 95 | //_____________________________________________________________________________ |
676fb573 | 96 | G4int |
97 | AliModuleConstruction::operator==(const AliModuleConstruction& right) const | |
98 | { | |
99 | // | |
100 | return 0; | |
101 | } | |
102 | ||
78ca1e9c | 103 | //_____________________________________________________________________________ |
676fb573 | 104 | G4int |
105 | AliModuleConstruction::operator!=(const AliModuleConstruction& right) const | |
106 | { | |
107 | // | |
108 | G4int returnValue = 1; | |
109 | if (*this == right) returnValue = 0; | |
110 | ||
111 | return returnValue; | |
112 | } | |
113 | ||
114 | // protected methods | |
115 | ||
78ca1e9c | 116 | //_____________________________________________________________________________ |
676fb573 | 117 | void AliModuleConstruction::RegisterLogicalVolume(G4LogicalVolume* lv, |
118 | G4String path, AliLVStructure& lvStructure) | |
119 | { | |
120 | // Registers logical volume lv in the structure. | |
121 | // --- | |
122 | ||
123 | G4String lvName = lv->GetName(); | |
124 | lvStructure.AddNewVolume(lv, path); | |
125 | ||
126 | // register daughters | |
127 | G4int nofDaughters = lv->GetNoDaughters(); | |
128 | if (nofDaughters>0) { | |
129 | G4String previousName = ""; | |
130 | for (G4int i=0; i<nofDaughters; i++) { | |
131 | G4LogicalVolume* lvd = lv->GetDaughter(i)->GetLogicalVolume(); | |
132 | G4String currentName = lvd->GetName(); | |
133 | if (currentName != lvName && currentName != previousName) { | |
134 | G4String newPath = path + lvName +"/"; | |
135 | RegisterLogicalVolume(lvd, newPath, lvStructure); | |
136 | previousName = currentName; | |
137 | } | |
138 | } | |
139 | } | |
140 | } | |
141 | ||
142 | // public methods | |
143 | ||
78ca1e9c | 144 | //_____________________________________________________________________________ |
676fb573 | 145 | void AliModuleConstruction::SetDetFrame(G4bool warn) |
146 | { | |
147 | // The logical volume with name identical with | |
148 | // fModuleName is retrieved from G4LogicalVolumeStore. | |
149 | // --- | |
150 | ||
151 | fModuleFrameLV = FindLogicalVolume(fModuleFrameName, true); | |
152 | ||
153 | if (fModuleFrameLV == 0 && warn) { | |
154 | G4String text = "AliModuleConstruction: Detector frame for "; | |
155 | text = text + fModuleFrameName + " has not been found."; | |
156 | AliGlobals::Warning(text); | |
157 | } | |
158 | } | |
159 | ||
78ca1e9c | 160 | //_____________________________________________________________________________ |
676fb573 | 161 | void AliModuleConstruction::SetDetFrame(G4String frameName, G4bool warn) |
162 | { | |
163 | // The logical volume with frameName | |
164 | // is retrieved from G4LogicalVolumeStore. | |
165 | // --- | |
166 | ||
167 | fModuleFrameName = frameName; | |
168 | SetDetFrame(warn); | |
169 | } | |
170 | ||
78ca1e9c | 171 | //_____________________________________________________________________________ |
676fb573 | 172 | void AliModuleConstruction::ListAllLVTree() |
173 | { | |
174 | // Lists all logical volumes tree if the frame logical volume | |
175 | // is defined. | |
176 | // ---- | |
177 | ||
178 | if (fModuleFrameLV) | |
179 | ListLVTree(fModuleFrameLV->GetName()); | |
180 | else { | |
181 | G4String text = "AliModuleConstruction::ListAllLVTree:\n"; | |
182 | text = text + " Detector frame is not defined."; | |
183 | AliGlobals::Warning(text); | |
184 | } | |
185 | } | |
186 | ||
78ca1e9c | 187 | //_____________________________________________________________________________ |
676fb573 | 188 | void AliModuleConstruction::ListAllLVTreeLong() |
189 | { | |
190 | // Lists all logical volume tree if the frame logical volume | |
191 | // is defined with numbers of daughters (physical volumes). | |
192 | // ---- | |
193 | ||
194 | if (fModuleFrameLV) | |
195 | ListLVTreeLong(fModuleFrameLV->GetName()); | |
196 | else { | |
197 | G4String text = "AliModuleConstruction::ListAllLVTreeLong:\n"; | |
198 | text = text + " Detector frame is not defined."; | |
199 | AliGlobals::Warning(text); | |
200 | } | |
201 | } | |
202 | ||
78ca1e9c | 203 | //_____________________________________________________________________________ |
676fb573 | 204 | void AliModuleConstruction::ListLVTree(G4String lvName) |
205 | { | |
206 | // Lists logical volumes tree (daughters) of the logical volume | |
207 | // with specified lvName. | |
208 | // ---- | |
209 | ||
210 | G4LogicalVolume* lv = FindLogicalVolume(lvName); | |
211 | if (lv) | |
212 | { | |
213 | G4String path = ""; | |
214 | AliLVStructure lvStructure(path); | |
215 | RegisterLogicalVolume(lv, path, lvStructure); | |
216 | lvStructure.ListTree(); | |
217 | } | |
218 | } | |
219 | ||
78ca1e9c | 220 | //_____________________________________________________________________________ |
676fb573 | 221 | void AliModuleConstruction::ListLVTreeLong(G4String lvName) |
222 | { | |
223 | // Lists logical volumes tree (daughters) of the logical volume | |
224 | // with specified lvName with numbers of daughters (physical volumes). | |
225 | // ---- | |
226 | ||
227 | G4LogicalVolume* lv = FindLogicalVolume(lvName); | |
228 | if (lv) { | |
229 | G4String path = ""; | |
230 | AliLVStructure lvStructure(path); | |
231 | RegisterLogicalVolume(lv, path, lvStructure); | |
232 | lvStructure.ListTreeLong(); | |
233 | } | |
234 | } | |
235 | ||
78ca1e9c | 236 | //_____________________________________________________________________________ |
676fb573 | 237 | G4LogicalVolume* AliModuleConstruction::FindLogicalVolume( |
238 | G4String name, G4bool silent) const | |
239 | { | |
240 | // Finds logical volume with specified name in G4LogicalVolumeStore. | |
241 | // (To do: use this method only for retrieving detector frame; | |
242 | // add method FindLogicalVolumeInDet - that will search only | |
243 | // in the detector frame LVTree.) | |
244 | // --- | |
245 | ||
246 | G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance(); | |
247 | ||
79f99e92 | 248 | for (G4int i=0; i<pLVStore->size(); i++) { |
249 | G4LogicalVolume* lv = (*pLVStore)[i]; | |
676fb573 | 250 | if (lv->GetName() == name) return lv; |
251 | } | |
252 | ||
253 | G4String text = "AliModuleConstruction: Logical volume "; | |
254 | text = text + name + " does not exist."; | |
255 | if (!silent) AliGlobals::Warning(text); | |
256 | return 0; | |
257 | } | |
258 | ||
259 | #ifdef ALICE_VISUALIZE | |
260 | ||
78ca1e9c | 261 | //_____________________________________________________________________________ |
676fb573 | 262 | void AliModuleConstruction::SetDetVisibility(G4bool visibility) |
263 | { | |
264 | // Sets visibility to all detector logical volumes if | |
265 | // frame logical volume is defined. | |
266 | // --- | |
267 | ||
268 | if (fModuleFrameLV) | |
269 | SetLVTreeVisibility(fModuleFrameLV, visibility); | |
270 | else { | |
271 | G4String text = "AliModuleConstruction::SetDetVisibility:\n"; | |
272 | text = text + " Detector frame is not defined."; | |
273 | AliGlobals::Warning(text); | |
274 | } | |
275 | } | |
276 | ||
277 | ||
78ca1e9c | 278 | //_____________________________________________________________________________ |
676fb573 | 279 | void AliModuleConstruction::SetLVTreeVisibility(G4LogicalVolume* lv, |
280 | G4bool visibility) | |
281 | { | |
282 | // Sets visibility to the logical volumes tree (daughters) of | |
283 | // the logical volume lv. | |
284 | // --- | |
285 | ||
286 | if (lv) { | |
287 | G4String path = ""; | |
288 | AliLVStructure lvStructure(path); | |
289 | RegisterLogicalVolume(lv, path, lvStructure); | |
290 | lvStructure.SetTreeVisibility(visibility); | |
291 | } | |
292 | } | |
293 | ||
78ca1e9c | 294 | //_____________________________________________________________________________ |
676fb573 | 295 | void AliModuleConstruction::SetVolumeVisibility(G4LogicalVolume* lv, |
296 | G4bool visibility) | |
297 | { | |
298 | // Sets visibility to the specified logical volume. | |
299 | // --- | |
300 | ||
301 | if (lv) { | |
302 | const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes (); | |
30a3cbee | 303 | G4VisAttributes* newVisAttributes; |
304 | if (kpVisAttributes) { | |
305 | G4Colour oldColour = kpVisAttributes->GetColour(); | |
306 | newVisAttributes = new G4VisAttributes(oldColour); | |
307 | } | |
308 | else | |
309 | newVisAttributes = new G4VisAttributes(); | |
676fb573 | 310 | delete kpVisAttributes; |
311 | ||
312 | newVisAttributes->SetVisibility(visibility); | |
313 | ||
314 | lv->SetVisAttributes(newVisAttributes); | |
315 | } | |
316 | } | |
317 | ||
78ca1e9c | 318 | //_____________________________________________________________________________ |
676fb573 | 319 | void AliModuleConstruction::SetDetColour(G4String colName) |
320 | { | |
321 | // Sets colour to all detector logical volumes if | |
322 | // frame logical volume is defined. | |
323 | // --- | |
324 | ||
325 | if (fModuleFrameLV) | |
326 | SetLVTreeColour(fModuleFrameLV, colName); | |
327 | else { | |
328 | G4String text = "AliModuleConstruction::SetDetColour:\n"; | |
329 | text = text + " Detector frame is not defined."; | |
330 | AliGlobals::Warning(text); | |
331 | } | |
332 | } | |
333 | ||
78ca1e9c | 334 | //_____________________________________________________________________________ |
676fb573 | 335 | void AliModuleConstruction::SetLVTreeColour(G4LogicalVolume* lv, |
336 | G4String colName) | |
337 | { | |
338 | // Sets colour to the logical volumes tree (daughters) of | |
339 | // the logical volume lv. | |
340 | // --- | |
341 | ||
342 | if (lv) { | |
343 | G4String path = ""; | |
344 | AliLVStructure lvStructure(path); | |
345 | RegisterLogicalVolume(lv, path, lvStructure); | |
346 | lvStructure.SetTreeVisibility(true); | |
347 | lvStructure.SetTreeColour(colName); | |
348 | } | |
349 | } | |
350 | ||
78ca1e9c | 351 | //_____________________________________________________________________________ |
676fb573 | 352 | void AliModuleConstruction::SetVolumeColour(G4LogicalVolume* lv, |
353 | G4String colName) | |
354 | { | |
355 | // Sets colour to the specified logical volume. | |
356 | // --- | |
357 | ||
358 | if (lv) { | |
359 | const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes (); | |
676fb573 | 360 | delete kpVisAttributes; |
361 | ||
590fb121 | 362 | G4VisAttributes* newVisAttributes = new G4VisAttributes(); |
363 | ||
676fb573 | 364 | AliColourStore* pColours = AliColourStore::Instance(); |
365 | const G4Colour kColour = pColours->GetColour(colName); | |
366 | newVisAttributes->SetVisibility(true); | |
367 | newVisAttributes->SetColour(kColour); | |
368 | ||
369 | lv->SetVisAttributes(newVisAttributes); | |
370 | } | |
371 | } | |
372 | ||
373 | #endif //ALICE_VISUALIZE | |
374 |