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"
13 #ifdef ALICE_VISUALIZE
14 #include "AliColourStore.h"
16 #include <G4Colour.hh>
17 #include <G4VisAttributes.hh>
18 #endif //ALICE_VISUALIZE
19 #include <G4LogicalVolume.hh>
21 //_____________________________________________________________________________
22 AliLVStructure::AliLVStructure(G4String path)
28 G4int i = fDirName.length();
31 G4int isl = fDirName.last('/');
32 fDirName.remove(0,isl+1);
37 //_____________________________________________________________________________
38 AliLVStructure::AliLVStructure(const AliLVStructure& right)
44 //_____________________________________________________________________________
45 AliLVStructure::AliLVStructure() {
49 //_____________________________________________________________________________
50 AliLVStructure::~AliLVStructure() {
52 fStructures.clearAndDestroy();
53 fLogicalVolumes.clear();
58 //_____________________________________________________________________________
59 AliLVStructure& AliLVStructure::operator=(const AliLVStructure &right)
61 // check assignement to self
62 if (this == &right) return *this;
64 // copy vector of structures
65 fStructures.clearAndDestroy();
67 for (i=0; i<right.fStructures.entries(); i++) {
68 // new full structure tree has to be created
69 AliLVStructure* rhsStructure = right.fStructures[i];
70 fStructures.insert(new AliLVStructure(*rhsStructure));
73 // copy vector of logical volumes
74 fLogicalVolumes.clear();
75 for (i=0; i<right.fLogicalVolumes.entries(); i++) {
76 G4LogicalVolume* rhsLV = right.fLogicalVolumes[i];
77 fLogicalVolumes.insert(rhsLV);
80 fPathName = right.fPathName;
81 fDirName = right.fPathName;
82 fVerboseLevel = right.fVerboseLevel;
87 //_____________________________________________________________________________
88 G4int AliLVStructure::operator==(const AliLVStructure &right) const
91 if (this == &right) return true;
98 //_____________________________________________________________________________
99 AliLVStructure* AliLVStructure::FindSubDirectory(const G4String& subDir) const
101 // Finds the subdirectory.
104 for( G4int i=0; i<fStructures.entries(); i++ ) {
105 if (subDir == fStructures(i)->fDirName) return fStructures(i);
110 //_____________________________________________________________________________
111 G4String AliLVStructure::ExtractDirName(const G4String& name) const
113 // Extracts the directory name from the path.
116 G4String subDir = name;
117 G4int i = name.first('/');
118 if (i != G4std::string::npos) subDir.remove(i+1);
124 //_____________________________________________________________________________
125 void AliLVStructure::AddNewVolume(G4LogicalVolume* lv,
126 const G4String& treeStructure)
128 // Adds new logical volume to the structure.
131 G4String remainingPath = treeStructure;
132 remainingPath.remove(0, fPathName.length());
133 if (!remainingPath.isNull()) {
134 // The lv should be kept in subdirectory.
135 // First, check if the subdirectoy exists.
136 G4String subDir = ExtractDirName( remainingPath );
137 AliLVStructure* targetLVS = FindSubDirectory(subDir);
138 if (targetLVS == 0) {
139 // Subdirectory not found. Create a new directory.
140 subDir.prepend(fPathName);
141 targetLVS = new AliLVStructure(subDir);
142 fStructures.insert( targetLVS );
144 targetLVS->AddNewVolume(lv, treeStructure);
147 // the logical volumes should be kept in this directory.
148 G4LogicalVolume* targetLV = GetVolume(lv->GetName());
150 // G4cout << lv->GetName() << " had already stored in "
151 // << fPathName << G4endl;
154 fLogicalVolumes.insert(lv);
159 //_____________________________________________________________________________
160 G4LogicalVolume* AliLVStructure::GetVolume(const G4String& lvName) const
162 // Returns logical volume of lvName if present in the structure,
163 // returns 0 otherwise.
166 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
167 G4LogicalVolume* targetLV = fLogicalVolumes(i);
168 if (lvName == targetLV->GetName()) return targetLV;
173 //_____________________________________________________________________________
174 G4LogicalVolume* AliLVStructure::FindVolume(const G4String& name) const
176 // Finds logical volume of given name in all structure tree.
179 G4String path = name;
180 path.remove(0, fPathName.length());
181 if (path.first('/') != G4std::string::npos) {
182 // SD exists in sub-directory
183 G4String subDir = ExtractDirName(path);
184 AliLVStructure* targetLVS = FindSubDirectory(subDir);
185 if (targetLVS == 0) {
186 // The subdirectory is not found
187 G4String text = subDir + " is not found in " + fPathName;
188 AliGlobals:: Warning(text);
192 return targetLVS->FindVolume(name);
196 // LV must exist in this directory
197 G4LogicalVolume* targetLV = GetVolume(path);
199 // The fLogicalVolumes is not found.
200 G4String text = path + " is not found in " + fPathName;
201 AliGlobals::Warning(text);
207 //_____________________________________________________________________________
208 void AliLVStructure::ListTree() const
210 // Prints LV tree structure.
213 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
214 G4LogicalVolume* lv = fLogicalVolumes(i);
215 G4cout << fPathName << lv->GetName() << G4endl;
217 for (G4int j=0; j<fStructures.entries(); j++) {
218 fStructures(j)->ListTree();
222 //_____________________________________________________________________________
223 void AliLVStructure::ListTreeLong() const
225 // Prints LV tree structure with number of
226 // daughters (physical volume)
229 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
230 G4LogicalVolume* lv = fLogicalVolumes(i);
231 G4cout << fPathName << lv->GetName()
232 << " (" << lv->GetNoDaughters() << ")" << G4endl;
234 for (G4int j=0; j<fStructures.entries(); j++) {
235 fStructures(j)->ListTreeLong();
239 //_____________________________________________________________________________
240 void AliLVStructure::SetVerboseLevel(G4int verbose)
242 // Sets verbose level.
245 fVerboseLevel = verbose;
246 for (G4int i=0; i<fStructures.entries(); i++) {
247 fStructures(i)->SetVerboseLevel(verbose);
251 #ifdef ALICE_VISUALIZE
252 //_____________________________________________________________________________
253 void AliLVStructure::SetTreeVisibility(G4bool visibility)
255 // Sets visibility to all logical volumes in the structure
259 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
260 G4LogicalVolume* lv = fLogicalVolumes(i);
262 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes();
263 G4VisAttributes* newVisAttributes;
264 if (kpVisAttributes) {
265 G4Colour colour = kpVisAttributes->GetColour();
266 newVisAttributes = new G4VisAttributes(colour);
269 newVisAttributes = new G4VisAttributes();
270 delete kpVisAttributes;
272 newVisAttributes->SetVisibility(visibility);
274 lv->SetVisAttributes(newVisAttributes);
276 for (G4int j=0; j<fStructures.entries(); j++) {
277 fStructures(j)->SetTreeVisibility(visibility);
281 //_____________________________________________________________________________
282 void AliLVStructure::SetTreeColour(const G4String& colName)
284 // Sets colour specified by name to all logical volumes
285 // in the structure tree.
288 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
289 G4LogicalVolume* lv = fLogicalVolumes(i);
291 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
292 G4VisAttributes* newVisAttributes;
293 if (kpVisAttributes) {
294 G4bool oldVisibility = kpVisAttributes->IsVisible();
295 newVisAttributes = new G4VisAttributes(oldVisibility);
298 newVisAttributes = new G4VisAttributes();
299 delete kpVisAttributes;
301 AliColourStore* pColours = AliColourStore::Instance();
302 G4Colour colour = pColours->GetColour(colName);
303 newVisAttributes->SetColour(colour);
305 lv->SetVisAttributes(newVisAttributes);
307 for (G4int j=0; j<fStructures.entries(); j++) {
308 fStructures(j)->SetTreeColour(colName);