import hep.analysis.*;
import hep.analysis.partition.*;
import java.util.Random;

public class CSCTest
{
	private final static int NHISTS = 100;
	private final static int NITER = 100000;
	
	// This is designed to run as a standalone (Batch) job.
	public static void main(String[] args)
	{
		final int niter = args.length == 0 ? NITER : Integer.parseInt(args[0]);
		long start = System.currentTimeMillis();
		
		// Create a Job, which will own all the histograms
		Job job = new Job("CSCTest");
		Histogram[] hists = new Histogram[NHISTS];
	
		// Java's built in random number generator
		Random random = new Random(); 
		
		for (int i=0; i<NHISTS; i++)
		{
			hists[i] = new Histogram("histo number: "+i);
			// Force HBOOOK style fixed binning 
			// (by default JAS keeps all the points for rebinning)
			hists[i].setPartition(new FixedPartition(0,1));
		}
		for (int i=0; i<niter; i++)
		{
			int index = random.nextInt(NHISTS);
			hists[index].fill(random.nextDouble());
		}
		job.save(); // saves histograms (as CSCTest.javahist)
		
		// Print out timing info
		long end = System.currentTimeMillis();
		System.out.println("Elapsed time "+(end-start)+"ms");
	}
}
