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"
14 #include "AliColourStore.h"
16 #include <G4Colour.hh>
17 #include <G4VisAttributes.hh>
19 #include <G4LogicalVolume.hh>
20 #include <G4BooleanSolid.hh>
23 //_____________________________________________________________________________
24 AliLVStructure::AliLVStructure(G4String path)
30 G4int i = fDirName.length();
33 G4int isl = fDirName.last('/');
34 fDirName.remove(0,isl+1);
39 //_____________________________________________________________________________
40 AliLVStructure::AliLVStructure(const AliLVStructure& right)
46 //_____________________________________________________________________________
47 AliLVStructure::AliLVStructure() {
51 //_____________________________________________________________________________
52 AliLVStructure::~AliLVStructure() {
56 ClearAndDestroy(&fStructures);
59 fLogicalVolumes.resize(0);
64 //_____________________________________________________________________________
65 AliLVStructure& AliLVStructure::operator=(const AliLVStructure &right)
67 // check assignement to self
68 if (this == &right) return *this;
70 // copy vector of structures
71 ClearAndDestroy(&fStructures);
73 for (i=0; i<right.fStructures.size(); i++) {
74 // new full structure tree has to be created
75 AliLVStructure* rhsStructure = right.fStructures[i];
76 fStructures.push_back(new AliLVStructure(*rhsStructure));
79 // copy vector of logical volumes
80 fLogicalVolumes.resize(0);
81 for (i=0; i<right.fLogicalVolumes.size(); i++) {
82 G4LogicalVolume* rhsLV = right.fLogicalVolumes[i];
83 fLogicalVolumes.push_back(rhsLV);
86 fPathName = right.fPathName;
87 fDirName = right.fPathName;
88 fVerboseLevel = right.fVerboseLevel;
93 //_____________________________________________________________________________
94 G4int AliLVStructure::operator==(const AliLVStructure &right) const
97 if (this == &right) return true;
104 //_____________________________________________________________________________
105 AliLVStructure* AliLVStructure::FindSubDirectory(const G4String& subDir) const
107 // Finds the subdirectory.
110 for( G4int i=0; i<fStructures.size(); i++ ) {
111 if (subDir == fStructures[i]->fDirName) return fStructures[i];
116 //_____________________________________________________________________________
117 G4String AliLVStructure::ExtractDirName(const G4String& name) const
119 // Extracts the directory name from the path.
122 G4String subDir = name;
123 G4int i = name.first('/');
124 if (i != G4std::string::npos) subDir.remove(i+1);
128 //_____________________________________________________________________________
129 void AliLVStructure::ClearAndDestroy(LVStructuresVector* structures)
131 // Clears the structures vectors and deletes all contained
133 // (According to geant4.3.2/source/global/STLInterface/g4rw/tpordvec.icc.)
136 G4std::set<AliLVStructure*,G4std::greater<AliLVStructure*> > tmp;
137 for (size_t sz=0; sz<structures->size(); sz++)
139 AliLVStructure* current;
140 current=(*structures)[sz];
145 G4std::set<AliLVStructure*, G4std::greater<AliLVStructure*> >::iterator it;
146 for (it=tmp.begin(); it!=tmp.end(); it++)
150 // std_pvector::erase(std_pvector::begin(), std_pvector::end());
151 structures->resize(0);
156 //_____________________________________________________________________________
157 void AliLVStructure::AddNewVolume(G4LogicalVolume* lv,
158 const G4String& treeStructure)
160 // Adds new logical volume to the structure.
163 G4String remainingPath = treeStructure;
164 remainingPath.remove(0, fPathName.length());
165 if (!remainingPath.isNull()) {
166 // The lv should be kept in subdirectory.
167 // First, check if the subdirectoy exists.
168 G4String subDir = ExtractDirName( remainingPath );
169 AliLVStructure* targetLVS = FindSubDirectory(subDir);
170 if (targetLVS == 0) {
171 // Subdirectory not found. Create a new directory.
172 subDir.prepend(fPathName);
173 targetLVS = new AliLVStructure(subDir);
174 fStructures.push_back( targetLVS );
176 targetLVS->AddNewVolume(lv, treeStructure);
179 // the logical volumes should be kept in this directory.
180 G4LogicalVolume* targetLV = GetVolume(lv->GetName());
182 // G4cout << lv->GetName() << " has been already stored in "
183 // << fPathName << G4endl;
186 fLogicalVolumes.push_back(lv);
191 //_____________________________________________________________________________
192 G4LogicalVolume* AliLVStructure::GetVolume(const G4String& lvName) const
194 // Returns logical volume of lvName if present in the structure,
195 // returns 0 otherwise.
198 for (G4int i=0; i<fLogicalVolumes.size(); i++) {
199 G4LogicalVolume* targetLV = fLogicalVolumes[i];
200 if (lvName == targetLV->GetName()) return targetLV;
205 //_____________________________________________________________________________
206 G4LogicalVolume* AliLVStructure::FindVolume(const G4String& name) const
208 // Finds logical volume of given name in all structure tree.
211 G4String path = name;
212 path.remove(0, fPathName.length());
213 if (path.first('/') != G4std::string::npos) {
214 // SD exists in sub-directory
215 G4String subDir = ExtractDirName(path);
216 AliLVStructure* targetLVS = FindSubDirectory(subDir);
217 if (targetLVS == 0) {
218 // The subdirectory is not found
219 G4String text = subDir + " is not found in " + fPathName;
220 AliGlobals:: Warning(text);
224 return targetLVS->FindVolume(name);
228 // LV must exist in this directory
229 G4LogicalVolume* targetLV = GetVolume(path);
231 // The fLogicalVolumes is not found.
232 G4String text = path + " is not found in " + fPathName;
233 AliGlobals::Warning(text);
239 //_____________________________________________________________________________
240 void AliLVStructure::ListTree() const
242 // Prints LV tree structure.
245 for (G4int i=0; i<fLogicalVolumes.size(); i++) {
246 G4LogicalVolume* lv = fLogicalVolumes[i];
247 G4cout << fPathName << lv->GetName() << G4endl;
249 for (G4int j=0; j<fStructures.size(); j++) {
250 fStructures[j]->ListTree();
254 //_____________________________________________________________________________
255 void AliLVStructure::ListTreeLong() const
257 // Prints LV tree structure with number of
258 // daughters (physical volume), indicates Boolean solid.
261 for (G4int i=0; i<fLogicalVolumes.size(); i++) {
262 G4LogicalVolume* lv = fLogicalVolumes[i];
264 G4cout << fPathName << lv->GetName() << " (" << lv->GetNoDaughters();
266 if (dynamic_cast<G4BooleanSolid*>(lv->GetSolid()))
269 G4cout << ")" << G4endl;
271 for (G4int j=0; j<fStructures.size(); j++) {
272 fStructures[j]->ListTreeLong();
276 //_____________________________________________________________________________
277 void AliLVStructure::SetVerboseLevel(G4int verbose)
279 // Sets verbose level.
282 fVerboseLevel = verbose;
283 for (G4int i=0; i<fStructures.size(); i++) {
284 fStructures[i]->SetVerboseLevel(verbose);
289 //_____________________________________________________________________________
290 void AliLVStructure::SetTreeVisibility(G4bool visibility)
292 // Sets visibility to all logical volumes in the structure
296 for (G4int i=0; i<fLogicalVolumes.size(); i++) {
297 G4LogicalVolume* lv = fLogicalVolumes[i];
299 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes();
300 G4VisAttributes* newVisAttributes;
301 if (kpVisAttributes) {
302 G4Colour colour = kpVisAttributes->GetColour();
303 newVisAttributes = new G4VisAttributes(colour);
306 newVisAttributes = new G4VisAttributes();
307 delete kpVisAttributes;
309 newVisAttributes->SetVisibility(visibility);
311 lv->SetVisAttributes(newVisAttributes);
313 for (G4int j=0; j<fStructures.size(); j++) {
314 fStructures[j]->SetTreeVisibility(visibility);
318 //_____________________________________________________________________________
319 void AliLVStructure::SetTreeColour(const G4String& colName)
321 // Sets colour specified by name to all logical volumes
322 // in the structure tree.
325 for (G4int i=0; i<fLogicalVolumes.size(); i++) {
326 G4LogicalVolume* lv = fLogicalVolumes[i];
328 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
329 G4VisAttributes* newVisAttributes;
330 if (kpVisAttributes) {
331 G4bool oldVisibility = kpVisAttributes->IsVisible();
332 newVisAttributes = new G4VisAttributes(oldVisibility);
335 newVisAttributes = new G4VisAttributes();
336 delete kpVisAttributes;
338 AliColourStore* pColours = AliColourStore::Instance();
339 G4Colour colour = pColours->GetColour(colName);
340 newVisAttributes->SetColour(colour);
342 lv->SetVisAttributes(newVisAttributes);
344 for (G4int j=0; j<fStructures.size(); j++) {
345 fStructures[j]->SetTreeColour(colName);