1 package org.lcsim.detector;
2
3 import org.lcsim.detector.material.IMaterial;
4 import org.lcsim.detector.solids.ISolid;
5
6
7
8
9
10
11
12 public class LogicalVolume
13 implements ILogicalVolume
14 {
15 IMaterial material;
16 ISolid solid;
17 String name;
18
19
20
21
22 IPhysicalVolumeContainer physicalVolumes = new PhysicalVolumeContainer(true,true,false);
23
24 public LogicalVolume(String name, ISolid solid, IMaterial material)
25 {
26 if (name == null)
27 throw new IllegalArgumentException("LogicalVolume name points to null!");
28 this.name = name;
29 if (solid == null)
30 throw new IllegalArgumentException("Solid for LogicalVolume " + name + " points to null!");
31 this.solid = solid;
32 if (material == null)
33 throw new IllegalArgumentException("Material for LogicalVolume " + name + " points to null!");
34 this.material = material;
35
36
37 LogicalVolumeStore.getInstance().add(this);
38 }
39
40 public String getName()
41 {
42 return name;
43 }
44
45 public IMaterial getMaterial()
46 {
47 return material;
48 }
49
50 public ISolid getSolid()
51 {
52 return solid;
53 }
54
55 public IPhysicalVolumeContainer getDaughters()
56 {
57 return physicalVolumes;
58 }
59
60 public void addDaughter(IPhysicalVolume physvol)
61 {
62 physicalVolumes.add(physvol);
63 }
64
65 public IPhysicalVolume getDaughter(String name)
66 {
67 IPhysicalVolume pvfnd=null;
68 for (IPhysicalVolume pv : physicalVolumes)
69 {
70 if (pv.getName().equals(name))
71 {
72 pvfnd = pv;
73 break;
74 }
75 }
76 return pvfnd;
77 }
78
79 public IPhysicalVolume getDaughter(int i)
80 {
81 return physicalVolumes.get(i);
82 }
83
84 public boolean isDaughter(IPhysicalVolume physvol)
85 {
86 return physicalVolumes.contains(physvol);
87 }
88
89 public int getNumberOfDaughters()
90 {
91 return physicalVolumes.size();
92 }
93
94 public boolean isAncestor(IPhysicalVolume physvol)
95 {
96 boolean isDaughter = isDaughter(physvol);
97 if (!isDaughter)
98 {
99 for (IPhysicalVolume iphysvol : physicalVolumes)
100 {
101 isDaughter = iphysvol.getLogicalVolume().isAncestor(physvol);
102 if (isDaughter) break;
103 }
104 }
105 return isDaughter;
106 }
107 }