]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliLVStructure.cxx
removed a warning due to unused variable
[u/mrichter/AliRoot.git] / AliGeant4 / AliLVStructure.cxx
1 // $Id$
2 // Category: geometry
3 //
4 // See the class description in the header file.
5
6 #include "AliLVStructure.h"
7 #include "AliGlobals.h"
8
9 #ifdef ALICE_VISUALIZE
10 #include "AliColourStore.h"
11
12 #include <G4Colour.hh>
13 #include <G4VisAttributes.hh>
14 #endif //ALICE_VISUALIZE
15 #include <G4LogicalVolume.hh>
16
17 AliLVStructure::AliLVStructure(G4String path)
18   : fPathName(path),
19     fDirName(path),
20     fVerboseLevel(0)
21 {
22 //
23   G4int i = fDirName.length();
24   if (i > 1) {
25     fDirName.remove(i-1);
26     G4int isl = fDirName.last('/');
27     fDirName.remove(0,isl+1);
28     fDirName += "/";
29   }
30 }
31
32 AliLVStructure::AliLVStructure(const AliLVStructure& right)
33 {
34   // copy stuff
35   *this = right;
36 }
37
38 AliLVStructure::AliLVStructure() {
39 //
40 }
41
42 AliLVStructure::~AliLVStructure() {
43 //
44   fStructures.clearAndDestroy();
45   fLogicalVolumes.clear();
46 }
47
48 // operators
49
50 AliLVStructure& AliLVStructure::operator=(const AliLVStructure &right)
51 {
52   // check assignement to self
53   if (this == &right) return *this;
54
55   // copy vector of structures
56   fStructures.clearAndDestroy();
57   G4int i;
58   for (i=0; i<right.fStructures.entries(); i++) {
59     // new full structure tree has to be created
60     AliLVStructure* rhsStructure = right.fStructures[i];
61     fStructures.insert(new AliLVStructure(*rhsStructure)); 
62   }  
63   
64   // copy vector of logical volumes
65   fLogicalVolumes.clear();
66   for (i=0; i<right.fLogicalVolumes.entries(); i++) {
67     G4LogicalVolume* rhsLV = right.fLogicalVolumes[i];
68     fLogicalVolumes.insert(rhsLV); 
69   }  
70   
71   fPathName = right.fPathName;
72   fDirName = right.fPathName;
73   fVerboseLevel = right.fVerboseLevel;
74
75   return *this;
76 }
77
78 G4int AliLVStructure::operator==(const AliLVStructure &right) const
79 {
80   // check == to self
81   if (this == &right) return true;
82
83   return false;
84 }
85
86 // private methods
87
88 AliLVStructure* AliLVStructure::FindSubDirectory(G4String subDir)
89 {
90 // Finds the subdirectory.
91 // ---
92
93   for( G4int i=0; i<fStructures.entries(); i++ ) {
94     if (subDir == fStructures(i)->fDirName) return fStructures(i);
95   } 
96   return 0;
97 }
98
99 G4String AliLVStructure::ExtractDirName(G4String name)
100 {
101 // Extracts the directory name from the path.
102 // ---
103
104   G4String subDir = name;
105   G4int i = name.first('/');
106   if (i != G4std::string::npos) subDir.remove(i+1);
107   return subDir;
108 }
109
110 // public methods
111
112 void AliLVStructure::AddNewVolume(G4LogicalVolume* lv, 
113                       G4String treeStructure)
114 {
115 // Adds new logical volume to the structure.
116 // ---
117
118   G4String remainingPath = treeStructure;
119   remainingPath.remove(0, fPathName.length());  
120   if (!remainingPath.isNull()) { 
121     // The lv should be kept in subdirectory.
122     // First, check if the subdirectoy exists.
123     G4String subDir = ExtractDirName( remainingPath );
124     AliLVStructure* targetLVS = FindSubDirectory(subDir);
125     if (targetLVS == 0) { 
126       // Subdirectory not found. Create a new directory.
127       subDir.prepend(fPathName);
128       targetLVS = new AliLVStructure(subDir);
129       fStructures.insert( targetLVS );
130     }
131     targetLVS->AddNewVolume(lv, treeStructure);
132   }
133   else { 
134     // the logical volumes should be kept in this directory.
135     G4LogicalVolume* targetLV = GetVolume(lv->GetName());
136     if (targetLV != 0) {
137       // G4cout << lv->GetName() << " had already stored in "
138       //        << fPathName << G4endl;
139     }
140     else {
141       fLogicalVolumes.insert(lv);
142     }
143   }
144 }
145
146 G4LogicalVolume* AliLVStructure::GetVolume(G4String lvName)
147 {
148 // Returns logical volume of lvName if present in the structure,
149 // returns 0 otherwise.
150 // ---
151
152   for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
153     G4LogicalVolume* targetLV = fLogicalVolumes(i);
154     if (lvName == targetLV->GetName()) return targetLV;
155   }
156   return 0;
157 }
158
159 G4LogicalVolume* AliLVStructure::FindVolume(G4String name)
160 {
161 // Finds logical volume of given name in all structure tree.
162 // ---
163
164   G4String path = name;
165   path.remove(0, fPathName.length());
166   if (path.first('/') != G4std::string::npos) { 
167     // SD exists in sub-directory
168     G4String subDir = ExtractDirName(path);
169     AliLVStructure* targetLVS = FindSubDirectory(subDir);
170     if (targetLVS == 0) {  
171       // The subdirectory is not found
172       G4String text = subDir + " is not found in " + fPathName;
173       AliGlobals:: Warning(text);
174       return 0;
175     }
176     else { 
177       return targetLVS->FindVolume(name); 
178     }
179   }
180   else { 
181     // LV must exist in this directory
182     G4LogicalVolume* targetLV = GetVolume(path);
183     if (targetLV == 0) {  
184       // The fLogicalVolumes is not found.
185       G4String text = path + " is not found in " + fPathName;
186       AliGlobals::Warning(text);
187     }
188     return targetLV;
189   }
190 }
191
192 void AliLVStructure::ListTree() const
193 {
194 // Prints LV tree structure.
195 // ---
196
197   for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
198     G4LogicalVolume* lv = fLogicalVolumes(i);
199     G4cout << fPathName << lv->GetName() << G4endl;
200   }
201   for (G4int j=0; j<fStructures.entries(); j++) { 
202     fStructures(j)->ListTree(); 
203   }
204 }
205         
206 void AliLVStructure::ListTreeLong() const
207 {
208 // Prints LV tree structure with number of
209 // daughters (physical volume)
210 // ---
211
212   for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
213     G4LogicalVolume* lv = fLogicalVolumes(i);
214     G4cout << fPathName << lv->GetName() 
215            << " (" << lv->GetNoDaughters() << ")" << G4endl;
216   }
217   for (G4int j=0; j<fStructures.entries(); j++) { 
218     fStructures(j)->ListTreeLong(); 
219   }
220 }
221         
222 void AliLVStructure::SetVerboseLevel(G4int verbose) 
223 {
224 // Sets verbose level.
225 // ---
226
227   fVerboseLevel = verbose;  
228   for (G4int i=0; i<fStructures.entries(); i++) { 
229     fStructures(i)->SetVerboseLevel(verbose); 
230   }
231 }
232
233 #ifdef ALICE_VISUALIZE
234 void AliLVStructure::SetTreeVisibility(G4bool visibility)       
235 {
236 // Sets visibility to all logical volumes in the structure 
237 // tree.
238 // ---
239
240   for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
241     G4LogicalVolume* lv = fLogicalVolumes(i);
242
243     const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes();
244     G4VisAttributes* newVisAttributes; 
245     if (kpVisAttributes) {
246       G4Colour colour   = kpVisAttributes->GetColour();
247       newVisAttributes = new G4VisAttributes(colour); 
248     }
249     else
250       newVisAttributes = new G4VisAttributes();
251     delete kpVisAttributes;
252
253     newVisAttributes->SetVisibility(visibility); 
254
255     lv->SetVisAttributes(newVisAttributes);
256   }
257   for (G4int j=0; j<fStructures.entries(); j++) { 
258     fStructures(j)->SetTreeVisibility(visibility); 
259   }
260 }
261
262 void AliLVStructure::SetTreeColour(G4String colName)
263 {
264 // Sets colour specified  by name to all logical volumes
265 // in the structure tree.
266 // ---
267
268   for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
269     G4LogicalVolume* lv = fLogicalVolumes(i);
270
271     const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
272     G4VisAttributes* newVisAttributes; 
273     if (kpVisAttributes) {
274       G4bool oldVisibility = kpVisAttributes->IsVisible();
275       newVisAttributes = new G4VisAttributes(oldVisibility); 
276     }
277     else
278       newVisAttributes = new G4VisAttributes();
279     delete kpVisAttributes;
280
281     AliColourStore* pColours = AliColourStore::Instance();
282     G4Colour colour = pColours->GetColour(colName);
283     newVisAttributes->SetColour(colour);
284
285     lv->SetVisAttributes(newVisAttributes);
286   }
287   for (G4int j=0; j<fStructures.entries(); j++) { 
288     fStructures(j)->SetTreeColour(colName); 
289   }
290 }
291 #endif             
292
293