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)
34 // copy vector of structures
35 fStructures.clearAndDestroy();
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));
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);
50 fPathName = right.fPathName;
51 fDirName = right.fPathName;
52 fVerboseLevel = right.fVerboseLevel;
55 AliLVStructure::AliLVStructure() {
59 AliLVStructure::~AliLVStructure() {
61 fStructures.clearAndDestroy();
62 fLogicalVolumes.clear();
67 AliLVStructure& AliLVStructure::operator=(const AliLVStructure &right)
69 // check assignement to self
70 if (this == &right) return *this;
72 // copy vector of structures
73 fStructures.clearAndDestroy();
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));
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);
88 fPathName = right.fPathName;
89 fDirName = right.fPathName;
90 fVerboseLevel = right.fVerboseLevel;
95 G4int AliLVStructure::operator==(const AliLVStructure &right) const
98 if (this == &right) return true;
105 AliLVStructure* AliLVStructure::FindSubDirectory(G4String subDir)
107 // Finds the subdirectory.
110 for( G4int i=0; i<fStructures.entries(); i++ ) {
111 if (subDir == fStructures(i)->fDirName) return fStructures(i);
116 G4String AliLVStructure::ExtractDirName(G4String name)
118 // Extracts the directory name from the path.
121 G4String subDir = name;
122 G4int i = name.first('/');
123 if (i != G4std::string::npos) subDir.remove(i+1);
129 void AliLVStructure::AddNewVolume(G4LogicalVolume* lv,
130 G4String treeStructure)
132 // Adds new logical volume to the structure.
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 );
148 targetLVS->AddNewVolume(lv, treeStructure);
151 // the logical volumes should be kept in this directory.
152 G4LogicalVolume* targetLV = GetVolume(lv->GetName());
154 // G4cout << lv->GetName() << " had already stored in "
155 // << fPathName << G4endl;
158 fLogicalVolumes.insert(lv);
163 G4LogicalVolume* AliLVStructure::GetVolume(G4String lvName)
165 // Returns logical volume of lvName if present in the structure,
166 // returns 0 otherwise.
169 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
170 G4LogicalVolume* targetLV = fLogicalVolumes(i);
171 if (lvName == targetLV->GetName()) return targetLV;
176 G4LogicalVolume* AliLVStructure::FindVolume(G4String name)
178 // Finds logical volume of given name in all structure tree.
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);
194 return targetLVS->FindVolume(name);
198 // LV must exist in this directory
199 G4LogicalVolume* targetLV = GetVolume(path);
201 // The fLogicalVolumes is not found.
202 G4String text = path + " is not found in " + fPathName;
203 AliGlobals::Warning(text);
209 void AliLVStructure::ListTree() const
211 // Prints LV tree structure.
214 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
215 G4LogicalVolume* lv = fLogicalVolumes(i);
216 G4cout << fPathName << lv->GetName() << G4endl;
218 for (G4int j=0; j<fStructures.entries(); j++) {
219 fStructures(j)->ListTree();
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 void AliLVStructure::SetVerboseLevel(G4int verbose)
241 // Sets verbose level.
244 fVerboseLevel = verbose;
245 for (G4int i=0; i<fStructures.entries(); i++) {
246 fStructures(i)->SetVerboseLevel(verbose);
250 #ifdef ALICE_VISUALIZE
251 void AliLVStructure::SetTreeVisibility(G4bool visibility)
253 // Sets visibility to all logical volumes in the structure
257 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
258 G4LogicalVolume* lv = fLogicalVolumes(i);
260 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes();
261 G4VisAttributes* newVisAttributes;
262 if (kpVisAttributes) {
263 G4Colour colour = kpVisAttributes->GetColour();
264 newVisAttributes = new G4VisAttributes(colour);
267 newVisAttributes = new G4VisAttributes();
268 delete kpVisAttributes;
270 newVisAttributes->SetVisibility(visibility);
272 lv->SetVisAttributes(newVisAttributes);
274 for (G4int j=0; j<fStructures.entries(); j++) {
275 fStructures(j)->SetTreeVisibility(visibility);
279 void AliLVStructure::SetTreeColour(G4String colName)
281 // Sets colour specified by name to all logical volumes
282 // in the structure tree.
285 for (G4int i=0; i<fLogicalVolumes.entries(); i++) {
286 G4LogicalVolume* lv = fLogicalVolumes(i);
288 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
289 G4VisAttributes* newVisAttributes;
290 if (kpVisAttributes) {
291 G4bool oldVisibility = kpVisAttributes->IsVisible();
292 newVisAttributes = new G4VisAttributes(oldVisibility);
295 newVisAttributes = new G4VisAttributes();
296 delete kpVisAttributes;
298 AliColourStore* pColours = AliColourStore::Instance();
299 G4Colour colour = pColours->GetColour(colName);
300 newVisAttributes->SetColour(colour);
302 lv->SetVisAttributes(newVisAttributes);
304 for (G4int j=0; j<fStructures.entries(); j++) {
305 fStructures(j)->SetTreeColour(colName);