4 // Author: I. Hrivnacova
6 // Class AliLVStructure
7 // --------------------
8 // See the class description in the header file.
10 #include "AliLVStructure.h"
11 #include "AliGlobals.h"
14 #include "AliColourStore.h"
16 #include <G4Colour.hh>
17 #include <G4VisAttributes.hh>
19 #include <G4LogicalVolume.hh>
20 #include <G4BooleanSolid.hh>
22 //_____________________________________________________________________________
23 AliLVStructure::AliLVStructure(G4String path)
29 G4int i = fDirName.length();
32 G4int isl = fDirName.last('/');
33 fDirName.remove(0,isl+1);
38 //_____________________________________________________________________________
39 AliLVStructure::AliLVStructure(const AliLVStructure& right)
45 //_____________________________________________________________________________
46 AliLVStructure::AliLVStructure() {
50 //_____________________________________________________________________________
51 AliLVStructure::~AliLVStructure() {
53 fStructures.clearAndDestroy();
54 fLogicalVolumes.clear();
59 //_____________________________________________________________________________
60 AliLVStructure& AliLVStructure::operator=(const AliLVStructure &right)
62 // check assignement to self
63 if (this == &right) return *this;
65 // copy vector of structures
66 fStructures.clearAndDestroy();
68 for (i=0; i<right.fStructures.entries(); i++) {
69 // new full structure tree has to be created
70 AliLVStructure* rhsStructure = right.fStructures[i];
71 fStructures.insert(new AliLVStructure(*rhsStructure));
74 // copy vector of logical volumes
75 fLogicalVolumes.clear();
76 for (i=0; i<right.fLogicalVolumes.entries(); i++) {
77 G4LogicalVolume* rhsLV = right.fLogicalVolumes[i];
78 fLogicalVolumes.insert(rhsLV);
81 fPathName = right.fPathName;
82 fDirName = right.fPathName;
83 fVerboseLevel = right.fVerboseLevel;
88 //_____________________________________________________________________________
89 G4int AliLVStructure::operator==(const AliLVStructure &right) const
92 if (this == &right) return true;
99 //_____________________________________________________________________________
100 AliLVStructure* AliLVStructure::FindSubDirectory(const G4String& subDir) const
102 // Finds the subdirectory.
105 for( G4int i=0; i<fStructures.entries(); i++ ) {
106 if (subDir == fStructures(i)->fDirName) return fStructures(i);
111 //_____________________________________________________________________________
112 G4String AliLVStructure::ExtractDirName(const G4String& name) const
114 // Extracts the directory name from the path.
117 G4String subDir = name;
118 G4int i = name.first('/');
119 if (i != G4std::string::npos) subDir.remove(i+1);
125 //_____________________________________________________________________________
126 void AliLVStructure::AddNewVolume(G4LogicalVolume* lv,
127 const G4String& treeStructure)
129 // Adds new logical volume to the structure.
132 G4String remainingPath = treeStructure;
133 remainingPath.remove(0, fPathName.length());
134 if (!remainingPath.isNull()) {
135 // The lv should be kept in subdirectory.
136 // First, check if the subdirectoy exists.
137 G4String subDir = ExtractDirName( remainingPath );
138 AliLVStructure* targetLVS = FindSubDirectory(subDir);
139 if (targetLVS == 0) {
140 // Subdirectory not found. Create a new directory.
141 subDir.prepend(fPathName);
142 targetLVS = new AliLVStructure(subDir);
143 fStructures.insert( targetLVS );
145 targetLVS->AddNewVolume(lv, treeStructure);
148 // the logical volumes should be kept in this directory.
149 G4LogicalVolume* targetLV = GetVolume(lv->GetName());
151 // G4cout << lv->GetName() << " had already stored in "
152 // << fPathName << G4endl;
155 fLogicalVolumes.insert(lv);
160 //_____________________________________________________________________________
161 G4LogicalVolume* AliLVStructure::GetVolume(const G4String& lvName) const
163 // Returns logical volume of lvName if present in the structure,
164 // returns 0 otherwise.
167 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
168 G4LogicalVolume* targetLV = fLogicalVolumes(i);
169 if (lvName == targetLV->GetName()) return targetLV;
174 //_____________________________________________________________________________
175 G4LogicalVolume* AliLVStructure::FindVolume(const G4String& name) const
177 // Finds logical volume of given name in all structure tree.
180 G4String path = name;
181 path.remove(0, fPathName.length());
182 if (path.first('/') != G4std::string::npos) {
183 // SD exists in sub-directory
184 G4String subDir = ExtractDirName(path);
185 AliLVStructure* targetLVS = FindSubDirectory(subDir);
186 if (targetLVS == 0) {
187 // The subdirectory is not found
188 G4String text = subDir + " is not found in " + fPathName;
189 AliGlobals:: Warning(text);
193 return targetLVS->FindVolume(name);
197 // LV must exist in this directory
198 G4LogicalVolume* targetLV = GetVolume(path);
200 // The fLogicalVolumes is not found.
201 G4String text = path + " is not found in " + fPathName;
202 AliGlobals::Warning(text);
208 //_____________________________________________________________________________
209 void AliLVStructure::ListTree() const
211 // Prints LV tree structure.
214 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
215 G4LogicalVolume* lv = fLogicalVolumes(i);
216 G4cout << fPathName << lv->GetName() << G4endl;
218 for (G4int j=0; j<fStructures.entries(); j++) {
219 fStructures(j)->ListTree();
223 //_____________________________________________________________________________
224 void AliLVStructure::ListTreeLong() const
226 // Prints LV tree structure with number of
227 // daughters (physical volume), indicates Boolean solid.
230 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
231 G4LogicalVolume* lv = fLogicalVolumes(i);
233 G4cout << fPathName << lv->GetName() << " (" << lv->GetNoDaughters();
235 if (dynamic_cast<G4BooleanSolid*>(lv->GetSolid()))
238 G4cout << ")" << G4endl;
240 for (G4int j=0; j<fStructures.entries(); j++) {
241 fStructures(j)->ListTreeLong();
245 //_____________________________________________________________________________
246 void AliLVStructure::SetVerboseLevel(G4int verbose)
248 // Sets verbose level.
251 fVerboseLevel = verbose;
252 for (G4int i=0; i<fStructures.entries(); i++) {
253 fStructures(i)->SetVerboseLevel(verbose);
258 //_____________________________________________________________________________
259 void AliLVStructure::SetTreeVisibility(G4bool visibility)
261 // Sets visibility to all logical volumes in the structure
265 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
266 G4LogicalVolume* lv = fLogicalVolumes(i);
268 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes();
269 G4VisAttributes* newVisAttributes;
270 if (kpVisAttributes) {
271 G4Colour colour = kpVisAttributes->GetColour();
272 newVisAttributes = new G4VisAttributes(colour);
275 newVisAttributes = new G4VisAttributes();
276 delete kpVisAttributes;
278 newVisAttributes->SetVisibility(visibility);
280 lv->SetVisAttributes(newVisAttributes);
282 for (G4int j=0; j<fStructures.entries(); j++) {
283 fStructures(j)->SetTreeVisibility(visibility);
287 //_____________________________________________________________________________
288 void AliLVStructure::SetTreeColour(const G4String& colName)
290 // Sets colour specified by name to all logical volumes
291 // in the structure tree.
294 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
295 G4LogicalVolume* lv = fLogicalVolumes(i);
297 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
298 G4VisAttributes* newVisAttributes;
299 if (kpVisAttributes) {
300 G4bool oldVisibility = kpVisAttributes->IsVisible();
301 newVisAttributes = new G4VisAttributes(oldVisibility);
304 newVisAttributes = new G4VisAttributes();
305 delete kpVisAttributes;
307 AliColourStore* pColours = AliColourStore::Instance();
308 G4Colour colour = pColours->GetColour(colName);
309 newVisAttributes->SetColour(colour);
311 lv->SetVisAttributes(newVisAttributes);
313 for (G4int j=0; j<fStructures.entries(); j++) {
314 fStructures(j)->SetTreeColour(colName);