View Javadoc

1   package org.lcsim.lcio;
2   
3   import hep.io.sio.SIOInputStream;
4   import hep.io.sio.SIOOutputStream;
5   import hep.physics.vec.BasicHep3Vector;
6   
7   import java.io.IOException;
8   import org.lcsim.event.CalorimeterHit;
9   import org.lcsim.event.EventHeader.LCMetaData;
10  import org.lcsim.event.base.BaseCalorimeterHit;
11  
12  /**
13   * SIO-based I/O implementation of the CalorimeterHit interface
14   *
15   * @author Guilherme Lima
16   * @version $Id: SIOCalorimeterHit.java,v 1.18 2013/02/05 00:18:34 jeremy Exp $
17   */
18  class SIOCalorimeterHit extends BaseCalorimeterHit {
19  
20      SIOCalorimeterHit(SIOInputStream in, int flags, int version, LCMetaData meta) throws IOException {
21          int cellid0 = in.readInt();
22          int cellid1 = 0;
23          if (LCIOUtil.bitTest(flags, LCIOConstants.RCHBIT_ID1) || version == 8) {
24              cellid1 = in.readInt();
25          }
26          this.id = ((long) cellid1) << 32 | cellid0;
27          this.correctedEnergy = in.readFloat();
28          if (version >= 1051 && LCIOUtil.bitTest(flags, LCIOConstants.RCHBIT_ENERGY_ERROR)) {
29              energyError = in.readFloat();
30          }
31  
32          if (version > 1002 && (flags & (1 << LCIOConstants.RCHBIT_TIME)) != 0) {
33              time = in.readFloat();
34          }
35          if ((flags & (1 << LCIOConstants.RCHBIT_LONG)) != 0) {
36              positionVec = new BasicHep3Vector(in.readFloat(), in.readFloat(), in.readFloat());
37          }
38  
39          if (version > 1002) {
40              type = in.readInt();
41              Object tempHit = in.readPntr();
42  
43              // the logic has been reverted in v1.3 !
44              if ((flags & (1 << LCIOConstants.RCHBIT_NO_PTR)) == 0) {
45                  in.readPTag(this);
46              }
47          } else {
48              if ((flags & (1 << LCIOConstants.RCHBIT_NO_PTR)) != 0) {
49                  in.readPTag(this);
50              }
51          }
52          setMetaData(meta);
53      }
54  
55      static void write(CalorimeterHit hit, SIOOutputStream out, int flags) throws IOException {
56          long cellID = hit.getCellID();
57          out.writeInt((int) cellID);
58  
59          if (LCIOUtil.bitTest(flags, LCIOConstants.RCHBIT_ID1)) {
60              out.writeInt((int) (cellID >> 32));
61          }
62  
63          out.writeFloat((float) hit.getCorrectedEnergy());
64          if (LCIOUtil.bitTest(flags, LCIOConstants.RCHBIT_ENERGY_ERROR)) {
65              out.writeFloat((float) hit.getEnergyError());
66          }
67  
68          if (LCIOUtil.bitTest(flags, LCIOConstants.RCHBIT_TIME)) {
69              out.writeFloat((float) hit.getTime());
70          }
71  
72          if ((flags & (1 << LCIOConstants.CHBIT_LONG)) != 0) {
73              double[] pos;
74              if (hit.getPosition() != null) {
75                  pos = hit.getPosition();
76              } else {
77                  pos = new double[3];
78              }
79              out.writeFloat((float) pos[0]);
80              out.writeFloat((float) pos[1]);
81              out.writeFloat((float) pos[2]);
82          }
83  
84          out.writeInt(hit.getType());
85  
86          // FIXME: Java CalorimeterHit interface does not support getRawHit()
87          if (!LCIOUtil.bitTest(flags, LCIOConstants.RCHBIT_NO_PTR)) {
88              //assert false : "Pointer to raw hit not implemented!";
89              //out.writePntr( hit.getRawHit() );
90              out.writePntr(null);
91          }
92  
93          out.writePTag(hit);
94      }
95  }