4 // See the class description in the header file.
6 #include "AliModuleConstruction.h"
7 #include "AliModuleConstructionMessenger.h"
8 #include "AliGlobals.h"
9 #include "AliLVStructure.h"
10 #include "AliModule.h"
12 #ifdef ALICE_VISUALIZE
13 #include "AliColourStore.h"
15 #include <G4Colour.hh>
16 #include <G4VisAttributes.hh>
17 #endif //ALICE_VISUALIZE
18 #include <G4LogicalVolumeStore.hh>
19 #include <G4LogicalVolume.hh>
21 //_____________________________________________________________________________
22 AliModuleConstruction::AliModuleConstruction(G4String moduleName)
23 : fModuleName(moduleName),
24 fModuleFrameName(moduleName),
28 fWriteGeometry(false),
33 fMessenger = new AliModuleConstructionMessenger(this, moduleName);
36 //_____________________________________________________________________________
37 AliModuleConstruction::AliModuleConstruction(const AliModuleConstruction& right)
40 // allocation in assignement operator
47 //_____________________________________________________________________________
48 AliModuleConstruction::AliModuleConstruction()
55 fWriteGeometry(false),
61 //_____________________________________________________________________________
62 AliModuleConstruction::~AliModuleConstruction()
71 //_____________________________________________________________________________
72 AliModuleConstruction&
73 AliModuleConstruction::operator=(const AliModuleConstruction& right)
75 // check assignement to self
76 if (this == &right) return *this;
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;
87 if (fMessenger) delete fMessenger;
88 G4String moduleName = fModuleName;
90 fMessenger = new AliModuleConstructionMessenger(this, moduleName);
95 //_____________________________________________________________________________
97 AliModuleConstruction::operator==(const AliModuleConstruction& right) const
103 //_____________________________________________________________________________
105 AliModuleConstruction::operator!=(const AliModuleConstruction& right) const
108 G4int returnValue = 1;
109 if (*this == right) returnValue = 0;
116 //_____________________________________________________________________________
117 void AliModuleConstruction::RegisterLogicalVolume(G4LogicalVolume* lv,
118 G4String path, AliLVStructure& lvStructure)
120 // Registers logical volume lv in the structure.
123 G4String lvName = lv->GetName();
124 lvStructure.AddNewVolume(lv, path);
126 // register daughters
127 G4int nofDaughters = lv->GetNoDaughters();
128 if (nofDaughters>0) {
129 G4String previousName = "";
130 for (G4int i=0; i<nofDaughters; i++) {
131 G4LogicalVolume* lvd = lv->GetDaughter(i)->GetLogicalVolume();
132 G4String currentName = lvd->GetName();
133 if (currentName != lvName && currentName != previousName) {
134 G4String newPath = path + lvName +"/";
135 RegisterLogicalVolume(lvd, newPath, lvStructure);
136 previousName = currentName;
144 //_____________________________________________________________________________
145 void AliModuleConstruction::SetDetFrame(G4bool warn)
147 // The logical volume with name identical with
148 // fModuleName is retrieved from G4LogicalVolumeStore.
151 fModuleFrameLV = FindLogicalVolume(fModuleFrameName, true);
153 if (fModuleFrameLV == 0 && warn) {
154 G4String text = "AliModuleConstruction: Detector frame for ";
155 text = text + fModuleFrameName + " has not been found.";
156 AliGlobals::Warning(text);
160 //_____________________________________________________________________________
161 void AliModuleConstruction::SetDetFrame(G4String frameName, G4bool warn)
163 // The logical volume with frameName
164 // is retrieved from G4LogicalVolumeStore.
167 fModuleFrameName = frameName;
171 //_____________________________________________________________________________
172 void AliModuleConstruction::ListAllLVTree()
174 // Lists all logical volumes tree if the frame logical volume
179 ListLVTree(fModuleFrameLV->GetName());
181 G4String text = "AliModuleConstruction::ListAllLVTree:\n";
182 text = text + " Detector frame is not defined.";
183 AliGlobals::Warning(text);
187 //_____________________________________________________________________________
188 void AliModuleConstruction::ListAllLVTreeLong()
190 // Lists all logical volume tree if the frame logical volume
191 // is defined with numbers of daughters (physical volumes).
195 ListLVTreeLong(fModuleFrameLV->GetName());
197 G4String text = "AliModuleConstruction::ListAllLVTreeLong:\n";
198 text = text + " Detector frame is not defined.";
199 AliGlobals::Warning(text);
203 //_____________________________________________________________________________
204 void AliModuleConstruction::ListLVTree(G4String lvName)
206 // Lists logical volumes tree (daughters) of the logical volume
207 // with specified lvName.
210 G4LogicalVolume* lv = FindLogicalVolume(lvName);
214 AliLVStructure lvStructure(path);
215 RegisterLogicalVolume(lv, path, lvStructure);
216 lvStructure.ListTree();
220 //_____________________________________________________________________________
221 void AliModuleConstruction::ListLVTreeLong(G4String lvName)
223 // Lists logical volumes tree (daughters) of the logical volume
224 // with specified lvName with numbers of daughters (physical volumes).
227 G4LogicalVolume* lv = FindLogicalVolume(lvName);
230 AliLVStructure lvStructure(path);
231 RegisterLogicalVolume(lv, path, lvStructure);
232 lvStructure.ListTreeLong();
236 //_____________________________________________________________________________
237 G4LogicalVolume* AliModuleConstruction::FindLogicalVolume(
238 G4String name, G4bool silent) const
240 // Finds logical volume with specified name in G4LogicalVolumeStore.
241 // (To do: use this method only for retrieving detector frame;
242 // add method FindLogicalVolumeInDet - that will search only
243 // in the detector frame LVTree.)
246 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
248 for (G4int i=0; i<pLVStore->size(); i++) {
249 G4LogicalVolume* lv = (*pLVStore)[i];
250 if (lv->GetName() == name) return lv;
253 G4String text = "AliModuleConstruction: Logical volume ";
254 text = text + name + " does not exist.";
255 if (!silent) AliGlobals::Warning(text);
259 #ifdef ALICE_VISUALIZE
261 //_____________________________________________________________________________
262 void AliModuleConstruction::SetDetVisibility(G4bool visibility)
264 // Sets visibility to all detector logical volumes if
265 // frame logical volume is defined.
269 SetLVTreeVisibility(fModuleFrameLV, visibility);
271 G4String text = "AliModuleConstruction::SetDetVisibility:\n";
272 text = text + " Detector frame is not defined.";
273 AliGlobals::Warning(text);
278 //_____________________________________________________________________________
279 void AliModuleConstruction::SetLVTreeVisibility(G4LogicalVolume* lv,
282 // Sets visibility to the logical volumes tree (daughters) of
283 // the logical volume lv.
288 AliLVStructure lvStructure(path);
289 RegisterLogicalVolume(lv, path, lvStructure);
290 lvStructure.SetTreeVisibility(visibility);
294 //_____________________________________________________________________________
295 void AliModuleConstruction::SetVolumeVisibility(G4LogicalVolume* lv,
298 // Sets visibility to the specified logical volume.
302 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
303 G4VisAttributes* newVisAttributes;
304 if (kpVisAttributes) {
305 G4Colour oldColour = kpVisAttributes->GetColour();
306 newVisAttributes = new G4VisAttributes(oldColour);
309 newVisAttributes = new G4VisAttributes();
310 delete kpVisAttributes;
312 newVisAttributes->SetVisibility(visibility);
314 lv->SetVisAttributes(newVisAttributes);
318 //_____________________________________________________________________________
319 void AliModuleConstruction::SetDetColour(G4String colName)
321 // Sets colour to all detector logical volumes if
322 // frame logical volume is defined.
326 SetLVTreeColour(fModuleFrameLV, colName);
328 G4String text = "AliModuleConstruction::SetDetColour:\n";
329 text = text + " Detector frame is not defined.";
330 AliGlobals::Warning(text);
334 //_____________________________________________________________________________
335 void AliModuleConstruction::SetLVTreeColour(G4LogicalVolume* lv,
338 // Sets colour to the logical volumes tree (daughters) of
339 // the logical volume lv.
344 AliLVStructure lvStructure(path);
345 RegisterLogicalVolume(lv, path, lvStructure);
346 lvStructure.SetTreeVisibility(true);
347 lvStructure.SetTreeColour(colName);
351 //_____________________________________________________________________________
352 void AliModuleConstruction::SetVolumeColour(G4LogicalVolume* lv,
355 // Sets colour to the specified logical volume.
359 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
360 delete kpVisAttributes;
362 G4VisAttributes* newVisAttributes = new G4VisAttributes();
364 AliColourStore* pColours = AliColourStore::Instance();
365 const G4Colour kColour = pColours->GetColour(colName);
366 newVisAttributes->SetVisibility(true);
367 newVisAttributes->SetColour(kColour);
369 lv->SetVisAttributes(newVisAttributes);
373 #endif //ALICE_VISUALIZE