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