]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliLVStructure.cxx
conditional include G4UItcsh.hh added
[u/mrichter/AliRoot.git] / AliGeant4 / AliLVStructure.cxx
CommitLineData
676fb573 1// $Id$
2// Category: geometry
3//
7005154f 4// Author: I. Hrivnacova
5//
6// Class AliLVStructure
7// --------------------
676fb573 8// See the class description in the header file.
9
10#include "AliLVStructure.h"
11#include "AliGlobals.h"
12
e117bcaa 13#ifdef G4VIS_USE
676fb573 14#include "AliColourStore.h"
15
16#include <G4Colour.hh>
17#include <G4VisAttributes.hh>
e117bcaa 18#endif //G4VIS_USE
c97337f9 19#include <G4LogicalVolume.hh>
e117bcaa 20#include <G4BooleanSolid.hh>
7c02bbad 21#include <g4std/set>
676fb573 22
78ca1e9c 23//_____________________________________________________________________________
676fb573 24AliLVStructure::AliLVStructure(G4String path)
25 : fPathName(path),
26 fDirName(path),
27 fVerboseLevel(0)
28{
29//
30 G4int i = fDirName.length();
31 if (i > 1) {
32 fDirName.remove(i-1);
33 G4int isl = fDirName.last('/');
34 fDirName.remove(0,isl+1);
35 fDirName += "/";
36 }
37}
38
78ca1e9c 39//_____________________________________________________________________________
676fb573 40AliLVStructure::AliLVStructure(const AliLVStructure& right)
41{
58c0119e 42 // copy stuff
43 *this = right;
676fb573 44}
45
78ca1e9c 46//_____________________________________________________________________________
676fb573 47AliLVStructure::AliLVStructure() {
48//
49}
50
78ca1e9c 51//_____________________________________________________________________________
676fb573 52AliLVStructure::~AliLVStructure() {
53//
7c02bbad 54
55
56 ClearAndDestroy(&fStructures);
57
58
59 fLogicalVolumes.resize(0);
676fb573 60}
61
62// operators
63
78ca1e9c 64//_____________________________________________________________________________
676fb573 65AliLVStructure& AliLVStructure::operator=(const AliLVStructure &right)
66{
67 // check assignement to self
68 if (this == &right) return *this;
69
70 // copy vector of structures
7c02bbad 71 ClearAndDestroy(&fStructures);
676fb573 72 G4int i;
7c02bbad 73 for (i=0; i<right.fStructures.size(); i++) {
676fb573 74 // new full structure tree has to be created
75 AliLVStructure* rhsStructure = right.fStructures[i];
7c02bbad 76 fStructures.push_back(new AliLVStructure(*rhsStructure));
676fb573 77 }
78
79 // copy vector of logical volumes
7c02bbad 80 fLogicalVolumes.resize(0);
81 for (i=0; i<right.fLogicalVolumes.size(); i++) {
676fb573 82 G4LogicalVolume* rhsLV = right.fLogicalVolumes[i];
7c02bbad 83 fLogicalVolumes.push_back(rhsLV);
676fb573 84 }
85
86 fPathName = right.fPathName;
87 fDirName = right.fPathName;
88 fVerboseLevel = right.fVerboseLevel;
89
90 return *this;
91}
92
78ca1e9c 93//_____________________________________________________________________________
676fb573 94G4int AliLVStructure::operator==(const AliLVStructure &right) const
95{
96 // check == to self
97 if (this == &right) return true;
98
99 return false;
100}
101
102// private methods
103
78ca1e9c 104//_____________________________________________________________________________
cbac26a9 105AliLVStructure* AliLVStructure::FindSubDirectory(const G4String& subDir) const
676fb573 106{
107// Finds the subdirectory.
108// ---
109
7c02bbad 110 for( G4int i=0; i<fStructures.size(); i++ ) {
111 if (subDir == fStructures[i]->fDirName) return fStructures[i];
676fb573 112 }
113 return 0;
114}
115
78ca1e9c 116//_____________________________________________________________________________
cbac26a9 117G4String AliLVStructure::ExtractDirName(const G4String& name) const
676fb573 118{
119// Extracts the directory name from the path.
120// ---
121
122 G4String subDir = name;
123 G4int i = name.first('/');
124 if (i != G4std::string::npos) subDir.remove(i+1);
125 return subDir;
126}
127
7c02bbad 128void AliLVStructure::ClearAndDestroy(LVStructuresVector* structures)
129{
130// Clears the structures vectors and deletes all contained
131// elements.
132// (According to geant4.3.2/source/global/STLInterface/g4rw/tpordvec.icc.)
133// ---
134
135 G4std::set<AliLVStructure*,G4std::greater<AliLVStructure*> > tmp;
136 for (size_t sz=0; sz<structures->size(); sz++)
137 {
138 AliLVStructure* current;
139 current=(*structures)[sz];
140 if (current)
141 tmp.insert(current);
142 }
143
144 typename G4std::set<AliLVStructure*, G4std::greater<AliLVStructure*> >::iterator it;
145 for (it=tmp.begin(); it!=tmp.end(); it++)
146 {
147 delete *it;
148 }
149 // std_pvector::erase(std_pvector::begin(), std_pvector::end());
150 structures->resize(0);
151}
152
676fb573 153// public methods
154
78ca1e9c 155//_____________________________________________________________________________
676fb573 156void AliLVStructure::AddNewVolume(G4LogicalVolume* lv,
cbac26a9 157 const G4String& treeStructure)
676fb573 158{
159// Adds new logical volume to the structure.
160// ---
161
162 G4String remainingPath = treeStructure;
163 remainingPath.remove(0, fPathName.length());
164 if (!remainingPath.isNull()) {
165 // The lv should be kept in subdirectory.
166 // First, check if the subdirectoy exists.
167 G4String subDir = ExtractDirName( remainingPath );
168 AliLVStructure* targetLVS = FindSubDirectory(subDir);
169 if (targetLVS == 0) {
170 // Subdirectory not found. Create a new directory.
171 subDir.prepend(fPathName);
172 targetLVS = new AliLVStructure(subDir);
7c02bbad 173 fStructures.push_back( targetLVS );
676fb573 174 }
175 targetLVS->AddNewVolume(lv, treeStructure);
176 }
177 else {
178 // the logical volumes should be kept in this directory.
179 G4LogicalVolume* targetLV = GetVolume(lv->GetName());
180 if (targetLV != 0) {
181 // G4cout << lv->GetName() << " had already stored in "
5f1d09c5 182 // << fPathName << G4endl;
676fb573 183 }
184 else {
7c02bbad 185 fLogicalVolumes.push_back(lv);
676fb573 186 }
187 }
188}
189
78ca1e9c 190//_____________________________________________________________________________
cbac26a9 191G4LogicalVolume* AliLVStructure::GetVolume(const G4String& lvName) const
676fb573 192{
193// Returns logical volume of lvName if present in the structure,
194// returns 0 otherwise.
195// ---
196
7c02bbad 197 for (G4int i=0; i<fLogicalVolumes.size(); i++) {
198 G4LogicalVolume* targetLV = fLogicalVolumes[i];
676fb573 199 if (lvName == targetLV->GetName()) return targetLV;
200 }
201 return 0;
202}
203
78ca1e9c 204//_____________________________________________________________________________
cbac26a9 205G4LogicalVolume* AliLVStructure::FindVolume(const G4String& name) const
676fb573 206{
207// Finds logical volume of given name in all structure tree.
208// ---
209
210 G4String path = name;
211 path.remove(0, fPathName.length());
212 if (path.first('/') != G4std::string::npos) {
213 // SD exists in sub-directory
214 G4String subDir = ExtractDirName(path);
215 AliLVStructure* targetLVS = FindSubDirectory(subDir);
216 if (targetLVS == 0) {
217 // The subdirectory is not found
218 G4String text = subDir + " is not found in " + fPathName;
219 AliGlobals:: Warning(text);
220 return 0;
221 }
222 else {
223 return targetLVS->FindVolume(name);
224 }
225 }
226 else {
227 // LV must exist in this directory
228 G4LogicalVolume* targetLV = GetVolume(path);
229 if (targetLV == 0) {
230 // The fLogicalVolumes is not found.
231 G4String text = path + " is not found in " + fPathName;
232 AliGlobals::Warning(text);
233 }
234 return targetLV;
235 }
236}
237
78ca1e9c 238//_____________________________________________________________________________
676fb573 239void AliLVStructure::ListTree() const
240{
241// Prints LV tree structure.
242// ---
243
7c02bbad 244 for (G4int i=0; i<fLogicalVolumes.size(); i++) {
245 G4LogicalVolume* lv = fLogicalVolumes[i];
5f1d09c5 246 G4cout << fPathName << lv->GetName() << G4endl;
676fb573 247 }
7c02bbad 248 for (G4int j=0; j<fStructures.size(); j++) {
249 fStructures[j]->ListTree();
676fb573 250 }
251}
252
78ca1e9c 253//_____________________________________________________________________________
676fb573 254void AliLVStructure::ListTreeLong() const
255{
256// Prints LV tree structure with number of
e117bcaa 257// daughters (physical volume), indicates Boolean solid.
676fb573 258// ---
259
7c02bbad 260 for (G4int i=0; i<fLogicalVolumes.size(); i++) {
261 G4LogicalVolume* lv = fLogicalVolumes[i];
e117bcaa 262
263 G4cout << fPathName << lv->GetName() << " (" << lv->GetNoDaughters();
264
265 if (dynamic_cast<G4BooleanSolid*>(lv->GetSolid()))
266 G4cout << ", B";
267
268 G4cout << ")" << G4endl;
676fb573 269 }
7c02bbad 270 for (G4int j=0; j<fStructures.size(); j++) {
271 fStructures[j]->ListTreeLong();
676fb573 272 }
273}
274
78ca1e9c 275//_____________________________________________________________________________
676fb573 276void AliLVStructure::SetVerboseLevel(G4int verbose)
277{
278// Sets verbose level.
279// ---
280
281 fVerboseLevel = verbose;
7c02bbad 282 for (G4int i=0; i<fStructures.size(); i++) {
283 fStructures[i]->SetVerboseLevel(verbose);
676fb573 284 }
285}
286
e117bcaa 287#ifdef G4VIS_USE
78ca1e9c 288//_____________________________________________________________________________
676fb573 289void AliLVStructure::SetTreeVisibility(G4bool visibility)
290{
291// Sets visibility to all logical volumes in the structure
292// tree.
293// ---
294
7c02bbad 295 for (G4int i=0; i<fLogicalVolumes.size(); i++) {
296 G4LogicalVolume* lv = fLogicalVolumes[i];
676fb573 297
30a3cbee 298 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes();
299 G4VisAttributes* newVisAttributes;
300 if (kpVisAttributes) {
301 G4Colour colour = kpVisAttributes->GetColour();
302 newVisAttributes = new G4VisAttributes(colour);
303 }
304 else
305 newVisAttributes = new G4VisAttributes();
676fb573 306 delete kpVisAttributes;
307
308 newVisAttributes->SetVisibility(visibility);
309
310 lv->SetVisAttributes(newVisAttributes);
311 }
7c02bbad 312 for (G4int j=0; j<fStructures.size(); j++) {
313 fStructures[j]->SetTreeVisibility(visibility);
676fb573 314 }
315}
316
78ca1e9c 317//_____________________________________________________________________________
cbac26a9 318void AliLVStructure::SetTreeColour(const G4String& colName)
676fb573 319{
320// Sets colour specified by name to all logical volumes
321// in the structure tree.
322// ---
323
7c02bbad 324 for (G4int i=0; i<fLogicalVolumes.size(); i++) {
325 G4LogicalVolume* lv = fLogicalVolumes[i];
676fb573 326
327 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
30a3cbee 328 G4VisAttributes* newVisAttributes;
329 if (kpVisAttributes) {
330 G4bool oldVisibility = kpVisAttributes->IsVisible();
331 newVisAttributes = new G4VisAttributes(oldVisibility);
332 }
333 else
334 newVisAttributes = new G4VisAttributes();
676fb573 335 delete kpVisAttributes;
336
337 AliColourStore* pColours = AliColourStore::Instance();
338 G4Colour colour = pColours->GetColour(colName);
339 newVisAttributes->SetColour(colour);
340
341 lv->SetVisAttributes(newVisAttributes);
342 }
7c02bbad 343 for (G4int j=0; j<fStructures.size(); j++) {
344 fStructures[j]->SetTreeColour(colName);
676fb573 345 }
346}
347#endif
348
349