Commit in java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl on MAIN
MilleBinary.java+123-11178 -> 1179
First version in java. 
Work in progress.

java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl
MilleBinary.java 1178 -> 1179
--- java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/MilleBinary.java	2014-10-14 08:06:24 UTC (rev 1178)
+++ java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/MilleBinary.java	2014-10-14 22:11:32 UTC (rev 1179)
@@ -1,5 +1,127 @@
 package org.hps.recon.tracking.gbl;
+///  Millepede-II (binary) record.
 
-public class MilleBinary {
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
+/**
+ * Containing information for local (track) and global fit.
+ *\verbatim
+ *         real array              integer array
+ *     0   0.0                     error count (this record)
+ *     1   RMEAS, measured value   0                            -+
+ *     2   local derivative        index of local derivative     |
+ *     3   local derivative        index of local derivative     |
+ *     4    ...                                                  | block
+ *         SIGMA, error (>0)       0                             |
+ *         global derivative       label of global derivative    |
+ *         global derivative       label of global derivative   -+
+ *         RMEAS, measured value   0
+ *         local derivative        index of local derivative
+ *         local derivative        index of local derivative
+ *         ...
+ *         SIGMA, error            0
+ *         global derivative       label of global derivative
+ *         global derivative       label of global derivative
+ *         ...
+ *         global derivative       label of global derivative
+ *\endverbatim
+ * 
+ *
+ * @author Norman A Graf
+ *
+ * @version $Id:
+ * 
+ */
+public class MilleBinary
+{
+    FileChannel _channel;
+    List<Integer> _intBuffer = new ArrayList<Integer>();
+    List<Float> _floatBuffer = new ArrayList<Float>();
+
+// Create binary file.
+    public MilleBinary(String outputFileName)
+    {
+        try {
+            _channel = new FileOutputStream(outputFileName).getChannel();
+        } catch (FileNotFoundException ex) {
+            Logger.getLogger(MilleBinary.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        _intBuffer.add(0); // first word is error counter
+        _floatBuffer.add(0f);
+    }
+
+    public void close()
+    {
+        try {
+            _channel.close();
+        } catch (IOException ex) {
+            Logger.getLogger(MilleBinary.class.getName()).log(Level.SEVERE, null, ex);
+        }
+    }
+
+// Add data block to (end of) record.
+///**
+// * \param [in] aMeas Value
+// * \param [in] aErr Error
+// * \param [in] indLocal List of labels of local parameters
+// * \param [in] derLocal List of derivatives for local parameters
+// * \param [in] labGlobal List of labels of global parameters
+// * \param [in] derGlobal List of derivatives for global parameters
+// */
+    public void addData(float aMeas, float aErr,
+                        List<Integer> indLocal,
+                        List<Double> derLocal,
+                        List<Integer> labGlobal,
+                        List<Double> derGlobal)
+    {
+        _intBuffer.add(0);
+        _floatBuffer.add(aMeas);
+        for (int i = 0; i < indLocal.size(); ++i) {
+            _intBuffer.add(indLocal.get(i));
+            _floatBuffer.add((float) derLocal.get(i).doubleValue());
+        }
+        _intBuffer.add(0);
+        _floatBuffer.add(aErr);
+        for (int i = 0; i < labGlobal.size(); ++i) {
+            if (derGlobal.get(i) != 0) {
+                _intBuffer.add(labGlobal.get(i));
+                _floatBuffer.add((float) derGlobal.get(i).doubleValue());
+            }
+        }
+    }
+
+// Write record to file.
+    public void writeRecord()
+    {
+        int recordLength = _intBuffer.size() * 2;
+        ByteBuffer b = ByteBuffer.allocate((recordLength + 1) * 2);
+        b.order(ByteOrder.LITTLE_ENDIAN);
+        b.putInt(recordLength);
+        for (Float f : _floatBuffer) {
+            b.putFloat(f);
+        }
+        for (Integer i : _intBuffer) {
+            b.putInt(i);
+        }
+        b.flip();
+        try {
+            _channel.write(b);
+        } catch (IOException ex) {
+            Logger.getLogger(MilleBinary.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        b.clear();
+        _floatBuffer.clear();
+        _intBuffer.clear();
+        _intBuffer.add(0); // first word is error counter
+        _floatBuffer.add(0f);
+    }
 }
SVNspam 0.1