/*
 * RemoteCloud1D.java
 *
 * Created on February 17, 2005, 3:14 PM
 */

package hep.aida.ref.remote;

import java.util.*;

import hep.aida.*;
import hep.aida.dev.*;

import hep.aida.ref.*;
import hep.aida.ref.event.*;

/**
 *
 * @author  serbo
 */
public class RemoteCloud1D extends RemoteManagedObject implements ICloud1D {
    
    private RemoteHistogram1D hist;
    private boolean isConverted;
    
    private int entries;
    private int maxEntries;
    private double lowerEdge;
    private double upperEdge;
    protected double sumOfWeights;
    
    private double mean;
    private double rms;
    private double[] values;
    private double[] weights;
    
    /** Creates a new instance of RemoteCloud1D */
    public RemoteCloud1D(String name) {
        this(null, name);
    }
    
    public RemoteCloud1D(IDevMutableStore store, String name) {
        this(store, name, name);
    }
    
    public RemoteCloud1D(IDevMutableStore store, String name, String title) {
        super(name);
        aidaType = "ICloud1D";
        this.store = store;
        this.hist = new RemoteHistogram1D(name);
        this.hist.setFillable(true);
        this.hist.setDataValid(true);
        if (!name.equals(title)) hist.setTitle(title);
        dataIsValid = false;
    }
    
    
    // AIDAObservable methods
    protected java.util.EventObject createEvent()
    {
       return new HistogramEvent(this);
    }

    
    
    
    // Service Methods
    
    public void setConverted(boolean b) { isConverted = b; }
    public void setMaxEntries(int i) { maxEntries = i; }
    
    public void setEntries(int i) { entries = i; }
    public void setLowerEdge(double d) { lowerEdge = d; }
    public void setUpperEdge(double d) { upperEdge = d; }
    public void setSummOfWeights(double d) { sumOfWeights = d; }
    
    public void setMean(double d) { mean = d; }
    public void setRms(double d) { rms = d; }
    
    public void setValues(double[] a)  { values = a;  }
    public void setWeights(double[] a) { weights = a; } 
    
    
    
    // ICloud1D Methods
    
    
    public hep.aida.IAnnotation annotation() {
        makeSureDataIsValid();
        return hist.annotation();
    }
    
    public int dimension() {
        makeSureDataIsValid();
        return 1;
    }
    
    public int entries() {
        makeSureDataIsValid();
        if (isConverted()) return hist.allEntries();
        return entries;
    }
    
    public hep.aida.IHistogram1D histogram() throws java.lang.RuntimeException {
        makeSureDataIsValid();
        return hist;
    }
    
    public boolean isConverted() {
        makeSureDataIsValid();
        return isConverted;
    }
    
    public double lowerEdge() {
        makeSureDataIsValid();
        return lowerEdge;
    }
    
    public int maxEntries() {
        makeSureDataIsValid();
        return maxEntries;
    }
    
    public double mean() {
        makeSureDataIsValid();
        if (isConverted()) return hist.mean();
        return mean;
    }
    
    public double rms() {
        makeSureDataIsValid();
        if (isConverted()) return hist.rms();
        return rms;
    }
    
    public void setTitle(String str) throws java.lang.IllegalArgumentException {
        hist.setTitle(str);
    }
    
    public double sumOfWeights() {
        makeSureDataIsValid();
        if (isConverted()) return hist.sumAllBinHeights();
        return sumOfWeights;
    }
    
    public String title() {
        makeSureDataIsValid();
        return hist.title();
    }
    
    public double upperEdge() {
        makeSureDataIsValid();
        return upperEdge;
    }
    
    public double value(int param) throws hep.aida.AlreadyConvertedException {
        makeSureDataIsValid();
        if (isConverted()) throw new RuntimeException("Cloud has been converted");
        return values[param];        
    }
    
    public double weight(int param) throws hep.aida.AlreadyConvertedException {
        makeSureDataIsValid();
        if (isConverted()) throw new RuntimeException("Cloud has been converted");
        return weights[param];
    }
    
    public void convert(double[] values) throws hep.aida.AlreadyConvertedException {
        throw new ReadOnlyException();
    }
    
    public void convert(int param, double param1, double param2) throws hep.aida.AlreadyConvertedException {
        throw new ReadOnlyException();
    }
    
    public void convertToHistogram() throws hep.aida.AlreadyConvertedException {
        throw new ReadOnlyException();
    }
    
    public void fill(double param) throws java.lang.IllegalArgumentException {
         throw new ReadOnlyException();
   }
    
    public void fill(double param, double param1) throws java.lang.IllegalArgumentException {
        throw new ReadOnlyException();
    }
    
    public void fillHistogram(hep.aida.IHistogram1D iHistogram1D) throws java.lang.RuntimeException {
         throw new ReadOnlyException();
   }
    
    public void reset() throws java.lang.RuntimeException {
        throw new ReadOnlyException();
    }
    
    public void scale(double param) throws java.lang.IllegalArgumentException {
        throw new ReadOnlyException();
    }
    
}
