View Javadoc

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 org.lcsim.event.LCRelation;
9   
10  /**
11   * SIO-based I/O implementation of the LCRelation interface
12   *
13   * @author Guilherme Lima
14   * @version $Id: SIOLCRelation.java,v 1.4 2007/10/17 02:06:23 tonyj Exp $
15   */
16  class SIOLCRelation implements LCRelation
17  {
18     protected SIORef from;
19     protected SIORef to;
20     protected float weight;
21     
22     protected SIOLCRelation() {      
23     }
24  
25      /** Constructor for reading objects from file
26       */
27      SIOLCRelation(SIOInputStream in, int flags, int version) throws IOException
28      {
29         from = in.readPntr();
30         to = in.readPntr();
31         if (LCIOUtil.bitTest(flags,LCIOConstants.LCREL_WEIGHTED)) weight = in.readFloat();
32      }
33  
34      /** Returns the 'from' object
35       */
36      public Object getFrom() {
37         return from.getObject();
38      }
39      /** Returns the 'to' object
40       */
41      public Object getTo() {
42  	return to.getObject();
43      }
44  
45      /** Returns the weight of the relation
46       */
47      public float getWeight() {
48  	return weight;
49      }
50  
51      /** Weight should be between zero and one
52       */
53      public void setWeight(float weight) {
54  	this.weight = weight;
55      }
56  
57      /** Writes relations out to LCIO stream
58       */
59     static void write(LCRelation rel, SIOOutputStream out, int flags) throws IOException
60     {
61        out.writePntr( rel.getFrom() );
62        out.writePntr( rel.getTo() );
63        if (LCIOUtil.bitTest(flags,LCIOConstants.LCREL_WEIGHTED)) out.writeFloat( rel.getWeight() );
64     }
65  }