1 package org.lcsim.lcio;
2
3 import hep.io.sio.SIOInputStream;
4 import hep.io.sio.SIOOutputStream;
5 import hep.io.sio.SIORef;
6
7 import java.io.IOException;
8 import java.util.ArrayList;
9 import java.util.List;
10 import org.lcsim.event.TrackerHit;
11
12
13
14
15
16
17
18 class SIOTrackerHit implements TrackerHit
19 {
20 private List<SIORef> tempHits;
21 private List rawHits;
22 private int type;
23 private double[] position = new double[3];
24 private double[] covMatrix = new double[6];
25 private float dEdx;
26 private float time;
27 private float edepError;
28 private int quality;
29 private long id;
30
31 SIOTrackerHit(SIOInputStream in, int flags, int version) throws IOException
32 {
33
34 if(version >= 1060)
35 {
36 int cellID0 = in.readInt();
37 int cellID1 = 0;
38 if( (flags & (1 << LCIOConstants.THBIT_ID1)) != 0 )
39 {
40 cellID1 = in.readInt();
41 }
42 id = ((long) cellID1) << 32 | cellID0;
43 }
44
45 type = in.readInt();
46 for (int i = 0; i < 3; i++)
47 position[i] = in.readDouble();
48
49 for (int i = 0; i < 6; i++)
50 covMatrix[i] = in.readFloat();
51
52 dEdx = in.readFloat();
53
54 if ( version > 1012 )
55 {
56 edepError = in.readFloat();
57 }
58
59 time = in.readFloat();
60
61 if ( version > 1011 )
62 {
63 quality = in.readInt();
64 }
65
66 int nRawHits = 1 ;
67 if( version > 1002)
68 {
69 nRawHits = in.readInt() ;
70 }
71
72 tempHits = new ArrayList<SIORef>(nRawHits) ;
73 for (int i = 0; i < nRawHits ; i++)
74 {
75 tempHits.add(in.readPntr());
76 }
77 rawHits = null;
78
79 in.readPTag(this);
80 }
81
82 static void write(TrackerHit hit, SIOOutputStream out, int flags) throws IOException
83 {
84
85 long cellID = hit.getCellID();
86 out.writeInt((int) cellID);
87 if (LCIOUtil.bitTest(flags, LCIOConstants.THBIT_ID1))
88 {
89 out.writeInt((int) (cellID >> 32));
90 }
91
92 out.writeInt(hit.getType());
93
94 double[] pos = hit.getPosition();
95 for (int i = 0; i < 3; i++)
96 out.writeDouble(pos[i]);
97
98 double[] matrix = hit.getCovMatrix();
99 for (int i = 0; i < 6; i++)
100 out.writeFloat((float) matrix[i]);
101
102 out.writeFloat((float) hit.getdEdx());
103 out.writeFloat((float) hit.getEdepError());
104 out.writeFloat((float) hit.getTime());
105 out.writeInt((int) hit.getQuality());
106
107 List rawHits = hit.getRawHits() ;
108 out.writeInt( rawHits.size()) ;
109 for (int i = 0; i < rawHits.size() ; i++)
110 {
111 out.writePntr( rawHits.get(i) );
112 }
113
114 out.writePTag(hit);
115 }
116
117 public List getRawHits()
118 {
119 if (rawHits == null && tempHits != null)
120 {
121 rawHits = new ArrayList(tempHits.size());
122 for (SIORef ref : tempHits)
123 {
124 rawHits.add(ref.getObject());
125 }
126 tempHits = null;
127 }
128 return rawHits;
129 }
130
131 public long getCellID()
132 {
133 return id;
134 }
135
136 public double getdEdx()
137 {
138 return dEdx;
139 }
140
141 public int getType()
142 {
143 return type;
144 }
145
146 public double getTime()
147 {
148 return time;
149 }
150
151 public double[] getPosition()
152 {
153 return position;
154 }
155
156 public double[] getCovMatrix()
157 {
158 return covMatrix;
159 }
160
161 public double getEdepError()
162 {
163 return edepError;
164 }
165
166 public int getQuality()
167 {
168 return quality;
169 }
170 }