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