View Javadoc

1   package org.lcsim.lcio;
2   
3   import hep.io.sio.SIOInputStream;
4   import hep.io.sio.SIOOutputStream;
5   import org.lcsim.event.GenericObject;
6   
7   import java.io.IOException;
8   
9   /**
10   *
11   * @author gaede
12   * @version $Id: SIOGenericObject.java,v 1.8 2011/03/22 16:48:36 tonyj Exp $
13   */
14  class SIOGenericObject implements GenericObject
15  {
16     private boolean _isFixedSize ;
17     private int[] _intVec;
18     private float[] _floatVec;
19     private double[] _doubleVec;
20     
21     // Creates a new instance of SIOGenericObject with variable size
22     
23     SIOGenericObject(SIOInputStream in, int flag, int version) throws IOException
24     {
25        int nInt = in.readInt();
26        int nFloat = in.readInt();
27        int nDouble = in.readInt();
28        read(in,flag,version,nInt,nFloat,nDouble);
29        _isFixedSize = false;
30     }
31     
32     SIOGenericObject(SIOInputStream in, int flag, int version, int nInt, int nFloat, int nDouble) throws IOException
33     {	
34        read(in,flag,version,nInt,nFloat,nDouble);
35        _isFixedSize = true;
36     }   
37     
38     private void read(SIOInputStream in, int flag, int version, int nInt, int nFloat, int nDouble ) throws IOException
39     {
40        _intVec = new int[nInt] ;
41        for (int i=0; i<nInt; i++)
42        {
43           _intVec[i] = in.readInt();
44        }
45  
46        _floatVec = new float[nFloat] ;
47        for (int i=0; i<nFloat; i++)
48        {
49           _floatVec[i] = in.readFloat();
50        }
51        
52        _doubleVec = new double[nDouble] ;
53        for (int i=0; i<nDouble; i++)
54        {
55           _doubleVec[i] = in.readDouble();
56        }
57        in.readPTag(this); 
58     }
59     
60     static void write(GenericObject object, SIOOutputStream out, int flags) throws IOException
61     {
62        if (!LCIOUtil.bitTest(flags, LCIOConstants.GOBIT_FIXED))
63        {
64           out.writeInt(object.getNInt());
65           out.writeInt(object.getNFloat());
66           out.writeInt(object.getNDouble());
67        }
68        for(int i=0;i<object.getNInt();i++)
69           out.writeInt( object.getIntVal(i)) ;
70        for(int i=0;i<object.getNFloat();i++)
71           out.writeFloat( object.getFloatVal(i)) ;
72        for(int i=0;i<object.getNDouble();i++)
73           out.writeDouble( object.getDoubleVal(i)) ;
74        
75        out.writePTag(object);
76     }
77     public int getNInt()
78     {
79        return _intVec.length;
80     }
81  
82     public int getNFloat()
83     {
84        return _floatVec.length;
85     }
86  
87     public int getNDouble()
88     {
89        return _doubleVec.length;
90     }
91  
92     public int getIntVal(int index)
93     {
94        return _intVec[index];
95     }
96     
97     public float getFloatVal(int index)
98     {
99        return _floatVec[index];
100    }
101    
102    public double getDoubleVal(int index)
103    {
104       return _doubleVec[index];
105    }
106 
107    public boolean isFixedSize()
108    {
109       return _isFixedSize;
110    }
111 }