]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliModuleConstruction.cxx
corrected includes from g4std
[u/mrichter/AliRoot.git] / AliGeant4 / AliModuleConstruction.cxx
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
19 #include <fstream.h>
20
21 AliModuleConstruction::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
35 AliModuleConstruction::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
52 AliModuleConstruction::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
65 AliModuleConstruction::~AliModuleConstruction()
66 {
67 //
68   delete fMessenger;
69   delete fAliModule;
70 }
71
72 // operators
73
74 AliModuleConstruction& 
75 AliModuleConstruction::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
91 G4int 
92 AliModuleConstruction::operator==(const AliModuleConstruction& right) const
93 {
94 //    
95   return 0;
96 }
97
98 G4int 
99 AliModuleConstruction::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
110 void 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
137 void 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
152 void 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
162 void 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
177 void 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
192 void 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
208 void 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
223 G4LogicalVolume* 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
247 void 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
263 void 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
278 void 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 ();
286     G4VisAttributes* newVisAttributes = new G4VisAttributes(kpVisAttributes); 
287     delete kpVisAttributes;
288
289     newVisAttributes->SetVisibility(visibility); 
290
291     lv->SetVisAttributes(newVisAttributes);
292   }
293 }
294
295 void AliModuleConstruction::SetDetColour(G4String colName)
296 {
297 // Sets colour to all detector logical volumes if
298 // frame logical volume is defined.
299 // ---
300
301   if (fModuleFrameLV) 
302     SetLVTreeColour(fModuleFrameLV, colName);  
303   else { 
304     G4String text = "AliModuleConstruction::SetDetColour:\n";
305     text = text + "    Detector frame is not defined.";    
306     AliGlobals::Warning(text);
307   }  
308 }
309
310 void AliModuleConstruction::SetLVTreeColour(G4LogicalVolume* lv, 
311                              G4String colName)
312
313 // Sets colour to the logical volumes tree (daughters) of 
314 // the logical volume lv.
315 // ---
316
317   if (lv) {
318     G4String path = "";
319     AliLVStructure lvStructure(path);
320     RegisterLogicalVolume(lv, path, lvStructure);
321     lvStructure.SetTreeVisibility(true);
322     lvStructure.SetTreeColour(colName);
323   }
324 }
325
326 void AliModuleConstruction::SetVolumeColour(G4LogicalVolume* lv,
327                              G4String colName)
328 {
329 // Sets colour to the specified logical volume.
330 // ---
331
332   if (lv) {
333     const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
334     G4VisAttributes* newVisAttributes = new G4VisAttributes(kpVisAttributes); 
335     delete kpVisAttributes;
336
337     AliColourStore* pColours = AliColourStore::Instance();
338     const G4Colour kColour = pColours->GetColour(colName);
339     newVisAttributes->SetVisibility(true); 
340     newVisAttributes->SetColour(kColour);
341
342     lv->SetVisAttributes(newVisAttributes);
343   }      
344 }
345
346 #endif //ALICE_VISUALIZE
347