4 // See the class description in the header file.
6 #include "AliModuleConstruction.h"
7 #include "AliGlobals.h"
8 #include "AliLVStructure.h"
10 #ifdef ALICE_VISUALIZE
11 #include "AliColourStore.h"
13 #include <G4Colour.hh>
14 #include <G4VisAttributes.hh>
15 #endif //ALICE_VISUALIZE
16 #include <G4LogicalVolumeStore.hh>
17 #include <G4LogicalVolume.hh>
19 AliModuleConstruction::AliModuleConstruction(G4String moduleName)
20 : fModuleName(moduleName),
21 fModuleFrameName(moduleName),
25 fWriteGeometry(false),
30 fMessenger = new AliModuleConstructionMessenger(this, moduleName);
33 AliModuleConstruction::AliModuleConstruction(const AliModuleConstruction& right)
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;
45 G4String moduleName = fModuleName;
47 fMessenger = new AliModuleConstructionMessenger(this, moduleName);
50 AliModuleConstruction::AliModuleConstruction()
57 fWriteGeometry(false),
63 AliModuleConstruction::~AliModuleConstruction()
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;
90 AliModuleConstruction::operator==(const AliModuleConstruction& right) const
97 AliModuleConstruction::operator!=(const AliModuleConstruction& right) const
100 G4int returnValue = 1;
101 if (*this == right) returnValue = 0;
108 void AliModuleConstruction::RegisterLogicalVolume(G4LogicalVolume* lv,
109 G4String path, AliLVStructure& lvStructure)
111 // Registers logical volume lv in the structure.
114 G4String lvName = lv->GetName();
115 lvStructure.AddNewVolume(lv, path);
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;
135 void AliModuleConstruction::SetDetFrame(G4bool warn)
137 // The logical volume with name identical with
138 // fModuleName is retrieved from G4LogicalVolumeStore.
141 fModuleFrameLV = FindLogicalVolume(fModuleFrameName, true);
143 if (fModuleFrameLV == 0 && warn) {
144 G4String text = "AliModuleConstruction: Detector frame for ";
145 text = text + fModuleFrameName + " has not been found.";
146 AliGlobals::Warning(text);
150 void AliModuleConstruction::SetDetFrame(G4String frameName, G4bool warn)
152 // The logical volume with frameName
153 // is retrieved from G4LogicalVolumeStore.
156 fModuleFrameName = frameName;
160 void AliModuleConstruction::ListAllLVTree()
162 // Lists all logical volumes tree if the frame logical volume
167 ListLVTree(fModuleFrameLV->GetName());
169 G4String text = "AliModuleConstruction::ListAllLVTree:\n";
170 text = text + " Detector frame is not defined.";
171 AliGlobals::Warning(text);
175 void AliModuleConstruction::ListAllLVTreeLong()
177 // Lists all logical volume tree if the frame logical volume
178 // is defined with numbers of daughters (physical volumes).
182 ListLVTreeLong(fModuleFrameLV->GetName());
184 G4String text = "AliModuleConstruction::ListAllLVTreeLong:\n";
185 text = text + " Detector frame is not defined.";
186 AliGlobals::Warning(text);
190 void AliModuleConstruction::ListLVTree(G4String lvName)
192 // Lists logical volumes tree (daughters) of the logical volume
193 // with specified lvName.
196 G4LogicalVolume* lv = FindLogicalVolume(lvName);
200 AliLVStructure lvStructure(path);
201 RegisterLogicalVolume(lv, path, lvStructure);
202 lvStructure.ListTree();
206 void AliModuleConstruction::ListLVTreeLong(G4String lvName)
208 // Lists logical volumes tree (daughters) of the logical volume
209 // with specified lvName with numbers of daughters (physical volumes).
212 G4LogicalVolume* lv = FindLogicalVolume(lvName);
215 AliLVStructure lvStructure(path);
216 RegisterLogicalVolume(lv, path, lvStructure);
217 lvStructure.ListTreeLong();
221 G4LogicalVolume* AliModuleConstruction::FindLogicalVolume(
222 G4String name, G4bool silent) const
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.)
230 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
232 for (G4int i=0; i<pLVStore->entries(); i++) {
233 G4LogicalVolume* lv = pLVStore->at(i);
234 if (lv->GetName() == name) return lv;
237 G4String text = "AliModuleConstruction: Logical volume ";
238 text = text + name + " does not exist.";
239 if (!silent) AliGlobals::Warning(text);
243 #ifdef ALICE_VISUALIZE
245 void AliModuleConstruction::SetDetVisibility(G4bool visibility)
247 // Sets visibility to all detector logical volumes if
248 // frame logical volume is defined.
252 SetLVTreeVisibility(fModuleFrameLV, visibility);
254 G4String text = "AliModuleConstruction::SetDetVisibility:\n";
255 text = text + " Detector frame is not defined.";
256 AliGlobals::Warning(text);
261 void AliModuleConstruction::SetLVTreeVisibility(G4LogicalVolume* lv,
264 // Sets visibility to the logical volumes tree (daughters) of
265 // the logical volume lv.
270 AliLVStructure lvStructure(path);
271 RegisterLogicalVolume(lv, path, lvStructure);
272 lvStructure.SetTreeVisibility(visibility);
276 void AliModuleConstruction::SetVolumeVisibility(G4LogicalVolume* lv,
279 // Sets visibility to the specified logical volume.
283 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
284 G4VisAttributes* newVisAttributes;
285 if (kpVisAttributes) {
286 G4Colour oldColour = kpVisAttributes->GetColour();
287 newVisAttributes = new G4VisAttributes(oldColour);
290 newVisAttributes = new G4VisAttributes();
291 delete kpVisAttributes;
293 newVisAttributes->SetVisibility(visibility);
295 lv->SetVisAttributes(newVisAttributes);
299 void AliModuleConstruction::SetDetColour(G4String colName)
301 // Sets colour to all detector logical volumes if
302 // frame logical volume is defined.
306 SetLVTreeColour(fModuleFrameLV, colName);
308 G4String text = "AliModuleConstruction::SetDetColour:\n";
309 text = text + " Detector frame is not defined.";
310 AliGlobals::Warning(text);
314 void AliModuleConstruction::SetLVTreeColour(G4LogicalVolume* lv,
317 // Sets colour to the logical volumes tree (daughters) of
318 // the logical volume lv.
323 AliLVStructure lvStructure(path);
324 RegisterLogicalVolume(lv, path, lvStructure);
325 lvStructure.SetTreeVisibility(true);
326 lvStructure.SetTreeColour(colName);
330 void AliModuleConstruction::SetVolumeColour(G4LogicalVolume* lv,
333 // Sets colour to the specified logical volume.
337 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
338 delete kpVisAttributes;
340 G4VisAttributes* newVisAttributes = new G4VisAttributes();
342 AliColourStore* pColours = AliColourStore::Instance();
343 const G4Colour kColour = pColours->GetColour(colName);
344 newVisAttributes->SetVisibility(true);
345 newVisAttributes->SetColour(kColour);
347 lv->SetVisAttributes(newVisAttributes);
351 #endif //ALICE_VISUALIZE