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 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 // allocation in assignement operator
45 AliModuleConstruction::AliModuleConstruction()
52 fWriteGeometry(false),
58 AliModuleConstruction::~AliModuleConstruction()
67 AliModuleConstruction&
68 AliModuleConstruction::operator=(const AliModuleConstruction& right)
70 // check assignement to self
71 if (this == &right) return *this;
73 fModuleName = right.fModuleName;
74 fModuleFrameName = right.fModuleFrameName;
75 fModuleFrameLV = right.fModuleFrameLV;
76 fAliModule = right.fAliModule;
77 fReadGeometry = right.fReadGeometry;
78 fWriteGeometry = right.fWriteGeometry;
79 fDataFilePath = right.fDataFilePath;
82 if (fMessenger) delete fMessenger;
83 G4String moduleName = fModuleName;
85 fMessenger = new AliModuleConstructionMessenger(this, moduleName);
91 AliModuleConstruction::operator==(const AliModuleConstruction& right) const
98 AliModuleConstruction::operator!=(const AliModuleConstruction& right) const
101 G4int returnValue = 1;
102 if (*this == right) returnValue = 0;
109 void AliModuleConstruction::RegisterLogicalVolume(G4LogicalVolume* lv,
110 G4String path, AliLVStructure& lvStructure)
112 // Registers logical volume lv in the structure.
115 G4String lvName = lv->GetName();
116 lvStructure.AddNewVolume(lv, path);
118 // register daughters
119 G4int nofDaughters = lv->GetNoDaughters();
120 if (nofDaughters>0) {
121 G4String previousName = "";
122 for (G4int i=0; i<nofDaughters; i++) {
123 G4LogicalVolume* lvd = lv->GetDaughter(i)->GetLogicalVolume();
124 G4String currentName = lvd->GetName();
125 if (currentName != lvName && currentName != previousName) {
126 G4String newPath = path + lvName +"/";
127 RegisterLogicalVolume(lvd, newPath, lvStructure);
128 previousName = currentName;
136 void AliModuleConstruction::SetDetFrame(G4bool warn)
138 // The logical volume with name identical with
139 // fModuleName is retrieved from G4LogicalVolumeStore.
142 fModuleFrameLV = FindLogicalVolume(fModuleFrameName, true);
144 if (fModuleFrameLV == 0 && warn) {
145 G4String text = "AliModuleConstruction: Detector frame for ";
146 text = text + fModuleFrameName + " has not been found.";
147 AliGlobals::Warning(text);
151 void AliModuleConstruction::SetDetFrame(G4String frameName, G4bool warn)
153 // The logical volume with frameName
154 // is retrieved from G4LogicalVolumeStore.
157 fModuleFrameName = frameName;
161 void AliModuleConstruction::ListAllLVTree()
163 // Lists all logical volumes tree if the frame logical volume
168 ListLVTree(fModuleFrameLV->GetName());
170 G4String text = "AliModuleConstruction::ListAllLVTree:\n";
171 text = text + " Detector frame is not defined.";
172 AliGlobals::Warning(text);
176 void AliModuleConstruction::ListAllLVTreeLong()
178 // Lists all logical volume tree if the frame logical volume
179 // is defined with numbers of daughters (physical volumes).
183 ListLVTreeLong(fModuleFrameLV->GetName());
185 G4String text = "AliModuleConstruction::ListAllLVTreeLong:\n";
186 text = text + " Detector frame is not defined.";
187 AliGlobals::Warning(text);
191 void AliModuleConstruction::ListLVTree(G4String lvName)
193 // Lists logical volumes tree (daughters) of the logical volume
194 // with specified lvName.
197 G4LogicalVolume* lv = FindLogicalVolume(lvName);
201 AliLVStructure lvStructure(path);
202 RegisterLogicalVolume(lv, path, lvStructure);
203 lvStructure.ListTree();
207 void AliModuleConstruction::ListLVTreeLong(G4String lvName)
209 // Lists logical volumes tree (daughters) of the logical volume
210 // with specified lvName with numbers of daughters (physical volumes).
213 G4LogicalVolume* lv = FindLogicalVolume(lvName);
216 AliLVStructure lvStructure(path);
217 RegisterLogicalVolume(lv, path, lvStructure);
218 lvStructure.ListTreeLong();
222 G4LogicalVolume* AliModuleConstruction::FindLogicalVolume(
223 G4String name, G4bool silent) const
225 // Finds logical volume with specified name in G4LogicalVolumeStore.
226 // (To do: use this method only for retrieving detector frame;
227 // add method FindLogicalVolumeInDet - that will search only
228 // in the detector frame LVTree.)
231 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
233 for (G4int i=0; i<pLVStore->size(); i++) {
234 G4LogicalVolume* lv = (*pLVStore)[i];
235 if (lv->GetName() == name) return lv;
238 G4String text = "AliModuleConstruction: Logical volume ";
239 text = text + name + " does not exist.";
240 if (!silent) AliGlobals::Warning(text);
244 #ifdef ALICE_VISUALIZE
246 void AliModuleConstruction::SetDetVisibility(G4bool visibility)
248 // Sets visibility to all detector logical volumes if
249 // frame logical volume is defined.
253 SetLVTreeVisibility(fModuleFrameLV, visibility);
255 G4String text = "AliModuleConstruction::SetDetVisibility:\n";
256 text = text + " Detector frame is not defined.";
257 AliGlobals::Warning(text);
262 void AliModuleConstruction::SetLVTreeVisibility(G4LogicalVolume* lv,
265 // Sets visibility to the logical volumes tree (daughters) of
266 // the logical volume lv.
271 AliLVStructure lvStructure(path);
272 RegisterLogicalVolume(lv, path, lvStructure);
273 lvStructure.SetTreeVisibility(visibility);
277 void AliModuleConstruction::SetVolumeVisibility(G4LogicalVolume* lv,
280 // Sets visibility to the specified logical volume.
284 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
285 G4VisAttributes* newVisAttributes;
286 if (kpVisAttributes) {
287 G4Colour oldColour = kpVisAttributes->GetColour();
288 newVisAttributes = new G4VisAttributes(oldColour);
291 newVisAttributes = new G4VisAttributes();
292 delete kpVisAttributes;
294 newVisAttributes->SetVisibility(visibility);
296 lv->SetVisAttributes(newVisAttributes);
300 void AliModuleConstruction::SetDetColour(G4String colName)
302 // Sets colour to all detector logical volumes if
303 // frame logical volume is defined.
307 SetLVTreeColour(fModuleFrameLV, colName);
309 G4String text = "AliModuleConstruction::SetDetColour:\n";
310 text = text + " Detector frame is not defined.";
311 AliGlobals::Warning(text);
315 void AliModuleConstruction::SetLVTreeColour(G4LogicalVolume* lv,
318 // Sets colour to the logical volumes tree (daughters) of
319 // the logical volume lv.
324 AliLVStructure lvStructure(path);
325 RegisterLogicalVolume(lv, path, lvStructure);
326 lvStructure.SetTreeVisibility(true);
327 lvStructure.SetTreeColour(colName);
331 void AliModuleConstruction::SetVolumeColour(G4LogicalVolume* lv,
334 // Sets colour to the specified logical volume.
338 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
339 delete kpVisAttributes;
341 G4VisAttributes* newVisAttributes = new G4VisAttributes();
343 AliColourStore* pColours = AliColourStore::Instance();
344 const G4Colour kColour = pColours->GetColour(colName);
345 newVisAttributes->SetVisibility(true);
346 newVisAttributes->SetColour(kColour);
348 lv->SetVisAttributes(newVisAttributes);
352 #endif //ALICE_VISUALIZE