4 // See the class description in the header file.
6 #include "AliLVStructure.h"
7 #include "AliGlobals.h"
10 #include "AliColourStore.h"
12 #include <G4Colour.hh>
13 #include <G4VisAttributes.hh>
14 #endif //ALICE_VISUALIZE
15 #include <G4LogicalVolume.hh>
17 AliLVStructure::AliLVStructure(G4String path)
23 G4int i = fDirName.length();
26 G4int isl = fDirName.last('/');
27 fDirName.remove(0,isl+1);
32 AliLVStructure::AliLVStructure(const AliLVStructure& right)
38 AliLVStructure::AliLVStructure() {
42 AliLVStructure::~AliLVStructure() {
44 fStructures.clearAndDestroy();
45 fLogicalVolumes.clear();
50 AliLVStructure& AliLVStructure::operator=(const AliLVStructure &right)
52 // check assignement to self
53 if (this == &right) return *this;
55 // copy vector of structures
56 fStructures.clearAndDestroy();
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));
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);
71 fPathName = right.fPathName;
72 fDirName = right.fPathName;
73 fVerboseLevel = right.fVerboseLevel;
78 G4int AliLVStructure::operator==(const AliLVStructure &right) const
81 if (this == &right) return true;
88 AliLVStructure* AliLVStructure::FindSubDirectory(G4String subDir)
90 // Finds the subdirectory.
93 for( G4int i=0; i<fStructures.entries(); i++ ) {
94 if (subDir == fStructures(i)->fDirName) return fStructures(i);
99 G4String AliLVStructure::ExtractDirName(G4String name)
101 // Extracts the directory name from the path.
104 G4String subDir = name;
105 G4int i = name.first('/');
106 if (i != G4std::string::npos) subDir.remove(i+1);
112 void AliLVStructure::AddNewVolume(G4LogicalVolume* lv,
113 G4String treeStructure)
115 // Adds new logical volume to the structure.
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 );
131 targetLVS->AddNewVolume(lv, treeStructure);
134 // the logical volumes should be kept in this directory.
135 G4LogicalVolume* targetLV = GetVolume(lv->GetName());
137 // G4cout << lv->GetName() << " had already stored in "
138 // << fPathName << G4endl;
141 fLogicalVolumes.insert(lv);
146 G4LogicalVolume* AliLVStructure::GetVolume(G4String lvName)
148 // Returns logical volume of lvName if present in the structure,
149 // returns 0 otherwise.
152 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
153 G4LogicalVolume* targetLV = fLogicalVolumes(i);
154 if (lvName == targetLV->GetName()) return targetLV;
159 G4LogicalVolume* AliLVStructure::FindVolume(G4String name)
161 // Finds logical volume of given name in all structure tree.
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);
177 return targetLVS->FindVolume(name);
181 // LV must exist in this directory
182 G4LogicalVolume* targetLV = GetVolume(path);
184 // The fLogicalVolumes is not found.
185 G4String text = path + " is not found in " + fPathName;
186 AliGlobals::Warning(text);
192 void AliLVStructure::ListTree() const
194 // Prints LV tree structure.
197 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
198 G4LogicalVolume* lv = fLogicalVolumes(i);
199 G4cout << fPathName << lv->GetName() << G4endl;
201 for (G4int j=0; j<fStructures.entries(); j++) {
202 fStructures(j)->ListTree();
206 void AliLVStructure::ListTreeLong() const
208 // Prints LV tree structure with number of
209 // daughters (physical volume)
212 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
213 G4LogicalVolume* lv = fLogicalVolumes(i);
214 G4cout << fPathName << lv->GetName()
215 << " (" << lv->GetNoDaughters() << ")" << G4endl;
217 for (G4int j=0; j<fStructures.entries(); j++) {
218 fStructures(j)->ListTreeLong();
222 void AliLVStructure::SetVerboseLevel(G4int verbose)
224 // Sets verbose level.
227 fVerboseLevel = verbose;
228 for (G4int i=0; i<fStructures.entries(); i++) {
229 fStructures(i)->SetVerboseLevel(verbose);
233 #ifdef ALICE_VISUALIZE
234 void AliLVStructure::SetTreeVisibility(G4bool visibility)
236 // Sets visibility to all logical volumes in the structure
240 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
241 G4LogicalVolume* lv = fLogicalVolumes(i);
243 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes();
244 G4VisAttributes* newVisAttributes;
245 if (kpVisAttributes) {
246 G4Colour colour = kpVisAttributes->GetColour();
247 newVisAttributes = new G4VisAttributes(colour);
250 newVisAttributes = new G4VisAttributes();
251 delete kpVisAttributes;
253 newVisAttributes->SetVisibility(visibility);
255 lv->SetVisAttributes(newVisAttributes);
257 for (G4int j=0; j<fStructures.entries(); j++) {
258 fStructures(j)->SetTreeVisibility(visibility);
262 void AliLVStructure::SetTreeColour(G4String colName)
264 // Sets colour specified by name to all logical volumes
265 // in the structure tree.
268 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
269 G4LogicalVolume* lv = fLogicalVolumes(i);
271 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
272 G4VisAttributes* newVisAttributes;
273 if (kpVisAttributes) {
274 G4bool oldVisibility = kpVisAttributes->IsVisible();
275 newVisAttributes = new G4VisAttributes(oldVisibility);
278 newVisAttributes = new G4VisAttributes();
279 delete kpVisAttributes;
281 AliColourStore* pColours = AliColourStore::Instance();
282 G4Colour colour = pColours->GetColour(colName);
283 newVisAttributes->SetColour(colour);
285 lv->SetVisAttributes(newVisAttributes);
287 for (G4int j=0; j<fStructures.entries(); j++) {
288 fStructures(j)->SetTreeColour(colName);