/*
 * Tuple.java
 *
 * Created on May 6, 2002, 2:05 pm
 */

package hep.aida.ref.tuple;

import hep.aida.IManagedObject;
import hep.aida.ITuple;

import org.freehep.util.Value;

/**
 *
 * @author  The AIDA team @ SLAC.
 *
 */
public class ChainedTuple extends ReadOnlyAbstractTuple {
    
    private ITuple[] set;
    private int currentRow;
    private ITuple currentTuple;
    private int currentTupleID;
    private int currentTupleRow;
    private ChainedTuple[] tuples;
    
    /**
     * Tuple constructor.
     * @param name the Tuple's name
     * @param title the Tuple's title
     * @param set Array of ITuples to be chained
     */
    public ChainedTuple(String name, String title, ITuple[] set) {
        super(name, title);

        int nCol = 0;;        
        
        // Check if ITuples are compatible
        if (set.length > 1) {
            nCol = set[0].columns();        
            String[] colNames = new String[nCol];
            Class[] colTypes = new Class[nCol];
            for (int i=0; imax) max = tmp;
        }
        return max;
    }
    
    /**
     * Get the mean value of a column.
     * @param column The column's index.
     * @return The mean value of the column. If the mean
     *         cannot be calculated Double.NaN is returned.
     *
     */
    public double columnMean(int column) {
        double mean = 0.;
        int  rows = 0;
        for (int i=0; i0) rows += r;
        }
        return rows;
    }
    
    /**
     * Get the current row.
     * @return The current row;
     *
     */
    public int getRow() {
        return currentRow;
    }
    
    public hep.aida.ITuple findTuple(int column) {
        return tuples[column];
    }

    
    /**
     * Set the current row.
     * @param row The current row;
     * @return True if the opeartion was succesfull.
     *
     */
    public void setRow( int row ) {
        if (row > rows())
            throw new IllegalArgumentException("Row "+row+" is bigger than the length of this ChainedTuple ("+rows()+")");
        int rows = 0;
        int i = 0;
        int r = 0;
        ITuple tup = null;
        for (i=0; irow) break;
            if (r>0) rows += r;
        }
        currentRow = row;
        currentTupleID = i;
        currentTuple = set[currentTupleID];
        currentTupleRow = row-rows;
        currentTuple.setRow(currentTupleRow);
    }
    
    /**
     * Positions the read cursor immediately before the first row.
     */
    public void start() {
        currentRow = -1;
        currentTupleID = 0;
        currentTuple = set[currentTupleID];
        currentTuple.start();
        currentTupleRow = -1;
    }
    
    /**
     * Skips rows.
     * @param rows number of rows to skip, greater than 0.
     * @return false if it cannot skip rows.
     */
    public void skip(int rows) {
        setRow(currentRow+rows);
    }
    
    /**
     * Positions the cursor at the next row.
     * @return false if there is no next row.
     */
    public boolean next() {
        if (currentTuple.next()) {
            currentRow++;
            currentTupleRow++;
            return true;
        } else if (currentTupleID < set.length-1) {
            currentTupleID++;
            currentTuple = set[currentTupleID];
            currentTuple.start();
            currentTupleRow = 0;
            if ( !currentTuple.next()) return next();
            currentRow++;
            return true;
        }
        return false;
    }
    
    /**
     * Convert a name to a column index.
     * Note: C++ version may return -1 if column not found
     * @return the column number for a given name
     */
    public int findColumn(String name) throws IllegalArgumentException {
        return set[0].findColumn(name);
    }
        
    public Object columnDefaultValue(int column) {
        return set[0].columnDefaultValue(column);
    }    
}

 

Ads help maintain this website.