|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| HistogramWriter.java | 100% | 83.3% | 50% | 80% |
|
||||||||||||||
| 1 |
package baseCode.io.writer;
|
|
| 2 |
|
|
| 3 |
import hep.aida.IHistogram1D;
|
|
| 4 |
|
|
| 5 |
import java.io.IOException;
|
|
| 6 |
import java.io.OutputStream;
|
|
| 7 |
import java.io.OutputStreamWriter;
|
|
| 8 |
import java.io.Writer;
|
|
| 9 |
|
|
| 10 |
import corejava.Format;
|
|
| 11 |
|
|
| 12 |
/**
|
|
| 13 |
* Print an {@link hep.aidia.IHistogram1D}object to a text file.
|
|
| 14 |
* <p>
|
|
| 15 |
* Copyright (c) 2004
|
|
| 16 |
* </p>
|
|
| 17 |
* <p>
|
|
| 18 |
* Institution: Columbia University
|
|
| 19 |
* </p>
|
|
| 20 |
*
|
|
| 21 |
* @see <a href="http://hoschek.home.cern.ch/hoschek/colt/V1.0.3/doc/hep/aida/IHistogram1D.html">hep.aida.IHistogram1D
|
|
| 22 |
* </a>
|
|
| 23 |
* @author Paul Pavlidis
|
|
| 24 |
* @version $Id: HistogramWriter.java,v 1.5 2005/01/05 02:01:02 pavlidis Exp $
|
|
| 25 |
*/
|
|
| 26 |
public class HistogramWriter { |
|
| 27 |
|
|
| 28 |
/**
|
|
| 29 |
* Print out a IHistogram1D object.
|
|
| 30 |
*
|
|
| 31 |
* @param h IHistogram1D to be printed.
|
|
| 32 |
* @param s PrintStream to be printed to.
|
|
| 33 |
* @throws IOException
|
|
| 34 |
*/
|
|
| 35 | 1 |
public void write( IHistogram1D h, Writer s ) throws IOException { |
| 36 | 1 |
Format k = new Format( "%1.5g" ); |
| 37 | 1 |
int total = h.entries();
|
| 38 | 1 |
s.write( "Bin\tCount\tFraction\n" );
|
| 39 | 1 |
for ( int i = 0; i < h.xAxis().bins(); i++ ) { |
| 40 | 10 |
s.write( k.format( h.xAxis().binLowerEdge( i ) ) + "\t"
|
| 41 |
+ h.binEntries( i ) + "\t"
|
|
| 42 |
+ k.format( ( double ) h.binEntries( i ) / ( double ) total ) |
|
| 43 |
+ "\n" );
|
|
| 44 |
} |
|
| 45 |
} |
|
| 46 |
|
|
| 47 |
/**
|
|
| 48 |
* Print to a stream.
|
|
| 49 |
* @param h
|
|
| 50 |
* @param s
|
|
| 51 |
* @throws IOException
|
|
| 52 |
*/
|
|
| 53 | 0 |
public void write (IHistogram1D h, OutputStream s ) throws IOException { |
| 54 | 0 |
this.write(h, new OutputStreamWriter(s) ); |
| 55 |
} |
|
| 56 |
|
|
| 57 |
} |
|
||||||||||