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