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