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