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>
21 AliModuleConstruction::AliModuleConstruction(G4String moduleName)
22 : fModuleName(moduleName),
23 fModuleFrameName(moduleName),
27 fWriteGeometry(false),
32 fMessenger = new AliModuleConstructionMessenger(this, moduleName);
35 AliModuleConstruction::AliModuleConstruction(const AliModuleConstruction& right)
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;
47 G4String moduleName = fModuleName;
49 fMessenger = new AliModuleConstructionMessenger(this, moduleName);
52 AliModuleConstruction::AliModuleConstruction()
59 fWriteGeometry(false),
65 AliModuleConstruction::~AliModuleConstruction()
74 AliModuleConstruction&
75 AliModuleConstruction::operator=(const AliModuleConstruction& right)
77 // check assignement to self
78 if (this == &right) return *this;
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;
92 AliModuleConstruction::operator==(const AliModuleConstruction& right) const
99 AliModuleConstruction::operator!=(const AliModuleConstruction& right) const
102 G4int returnValue = 1;
103 if (*this == right) returnValue = 0;
110 void AliModuleConstruction::RegisterLogicalVolume(G4LogicalVolume* lv,
111 G4String path, AliLVStructure& lvStructure)
113 // Registers logical volume lv in the structure.
116 G4String lvName = lv->GetName();
117 lvStructure.AddNewVolume(lv, path);
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;
137 void AliModuleConstruction::SetDetFrame(G4bool warn)
139 // The logical volume with name identical with
140 // fModuleName is retrieved from G4LogicalVolumeStore.
143 fModuleFrameLV = FindLogicalVolume(fModuleFrameName, true);
145 if (fModuleFrameLV == 0 && warn) {
146 G4String text = "AliModuleConstruction: Detector frame for ";
147 text = text + fModuleFrameName + " has not been found.";
148 AliGlobals::Warning(text);
152 void AliModuleConstruction::SetDetFrame(G4String frameName, G4bool warn)
154 // The logical volume with frameName
155 // is retrieved from G4LogicalVolumeStore.
158 fModuleFrameName = frameName;
162 void AliModuleConstruction::ListAllLVTree()
164 // Lists all logical volumes tree if the frame logical volume
169 ListLVTree(fModuleFrameLV->GetName());
171 G4String text = "AliModuleConstruction::ListAllLVTree:\n";
172 text = text + " Detector frame is not defined.";
173 AliGlobals::Warning(text);
177 void AliModuleConstruction::ListAllLVTreeLong()
179 // Lists all logical volume tree if the frame logical volume
180 // is defined with numbers of daughters (physical volumes).
184 ListLVTreeLong(fModuleFrameLV->GetName());
186 G4String text = "AliModuleConstruction::ListAllLVTreeLong:\n";
187 text = text + " Detector frame is not defined.";
188 AliGlobals::Warning(text);
192 void AliModuleConstruction::ListLVTree(G4String lvName)
194 // Lists logical volumes tree (daughters) of the logical volume
195 // with specified lvName.
198 G4LogicalVolume* lv = FindLogicalVolume(lvName);
202 AliLVStructure lvStructure(path);
203 RegisterLogicalVolume(lv, path, lvStructure);
204 lvStructure.ListTree();
208 void AliModuleConstruction::ListLVTreeLong(G4String lvName)
210 // Lists logical volumes tree (daughters) of the logical volume
211 // with specified lvName with numbers of daughters (physical volumes).
214 G4LogicalVolume* lv = FindLogicalVolume(lvName);
217 AliLVStructure lvStructure(path);
218 RegisterLogicalVolume(lv, path, lvStructure);
219 lvStructure.ListTreeLong();
223 G4LogicalVolume* AliModuleConstruction::FindLogicalVolume(
224 G4String name, G4bool silent) const
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.)
232 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
234 for (G4int i=0; i<pLVStore->entries(); i++) {
235 G4LogicalVolume* lv = pLVStore->at(i);
236 if (lv->GetName() == name) return lv;
239 G4String text = "AliModuleConstruction: Logical volume ";
240 text = text + name + " does not exist.";
241 if (!silent) AliGlobals::Warning(text);
245 #ifdef ALICE_VISUALIZE
247 void AliModuleConstruction::SetDetVisibility(G4bool visibility)
249 // Sets visibility to all detector logical volumes if
250 // frame logical volume is defined.
254 SetLVTreeVisibility(fModuleFrameLV, visibility);
256 G4String text = "AliModuleConstruction::SetDetVisibility:\n";
257 text = text + " Detector frame is not defined.";
258 AliGlobals::Warning(text);
263 void AliModuleConstruction::SetLVTreeVisibility(G4LogicalVolume* lv,
266 // Sets visibility to the logical volumes tree (daughters) of
267 // the logical volume lv.
272 AliLVStructure lvStructure(path);
273 RegisterLogicalVolume(lv, path, lvStructure);
274 lvStructure.SetTreeVisibility(visibility);
278 void AliModuleConstruction::SetVolumeVisibility(G4LogicalVolume* lv,
281 // Sets visibility to the specified logical volume.
285 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
286 G4VisAttributes* newVisAttributes = new G4VisAttributes(kpVisAttributes);
287 delete kpVisAttributes;
289 newVisAttributes->SetVisibility(visibility);
291 lv->SetVisAttributes(newVisAttributes);
295 void AliModuleConstruction::SetDetColour(G4String colName)
297 // Sets colour to all detector logical volumes if
298 // frame logical volume is defined.
302 SetLVTreeColour(fModuleFrameLV, colName);
304 G4String text = "AliModuleConstruction::SetDetColour:\n";
305 text = text + " Detector frame is not defined.";
306 AliGlobals::Warning(text);
310 void AliModuleConstruction::SetLVTreeColour(G4LogicalVolume* lv,
313 // Sets colour to the logical volumes tree (daughters) of
314 // the logical volume lv.
319 AliLVStructure lvStructure(path);
320 RegisterLogicalVolume(lv, path, lvStructure);
321 lvStructure.SetTreeVisibility(true);
322 lvStructure.SetTreeColour(colName);
326 void AliModuleConstruction::SetVolumeColour(G4LogicalVolume* lv,
329 // Sets colour to the specified logical volume.
333 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
334 G4VisAttributes* newVisAttributes = new G4VisAttributes(kpVisAttributes);
335 delete kpVisAttributes;
337 AliColourStore* pColours = AliColourStore::Instance();
338 const G4Colour kColour = pColours->GetColour(colName);
339 newVisAttributes->SetVisibility(true);
340 newVisAttributes->SetColour(kColour);
342 lv->SetVisAttributes(newVisAttributes);
346 #endif //ALICE_VISUALIZE