All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.esrf.TangoDs.PollRing Maven / Gradle / Ivy

There is a newer version: 10.0.0
Show newest version
//+======================================================================
// $Source$
//
// Project:   Tango
//
// Description:  java source code for the TANGO client/server API.
//
// $Author: pascal_verdier $
//
// Copyright (C) :      2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,
//						European Synchrotron Radiation Facility
//                      BP 220, Grenoble 38043
//                      FRANCE
//
// This file is part of Tango.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with Tango.  If not, see .
//
// $Revision: 25297 $
//
//-======================================================================


package fr.esrf.TangoDs;

/**
 * Java code to define Polled Ring buffer.
 *	Command result or attribute values are stored in this
 *	buffer manages as a ring buffer.
 *
 * @author $Author: pascal_verdier $
 * @version $Revision: 25297 $
 */

import fr.esrf.Tango.*;
import org.omg.CORBA.Any;

import java.util.Date;
import java.util.Vector;

public class PollRing extends Vector implements TangoConst
{
	
	private int		max_elt;

	
//==========================================================================
/**
 *	Constructor for the PollRing class.
 *	It does not take any argument and construct a black box
 *	with the default depth.
 */
//==========================================================================
	PollRing()
	{
		super();
		max_elt = Tango_DefaultPollRingDepth;
	}
//==========================================================================
/**
 *	Constructor for the PollRing class.
 *	It creates a black box with a depth defined by input argument.
 *
 * @param	max_size	The black box depth
 */
//==========================================================================
	PollRing(int max_size)
	{
		super();
		if (max_size<=0)
			max_elt = Tango_DefaultPollRingDepth;
		else
			max_elt = max_size;
	}
//==========================================================================
/**
 *	This method insert a new element in the ring buffer
 *	when its real data
 *
 * @param	any	The Any returned by the command
 * @param	t	the date
 */
//==========================================================================
	void insert_data(Any any, TimeVal t)
	{
		if (size()>=max_elt)
			remove(0);
		add(new RingElt(any, t));
	}

//==========================================================================
/**
 *	This method insert a new element in the ring buffer
 *	when its real data
 *
 * @param	attr_val	the attribute returned by read_attribute.
 * @param	t	the date
 */
//==========================================================================
	void insert_data(AttributeValue attr_val, TimeVal t)
	{
		if (size()>=max_elt)
			remove(0);
		add(new RingElt(attr_val, t));
		/*
		for (int i=0 ; i=max_elt)
			remove(0);
		add(new RingElt(ex, t));
	}
//==========================================================================
/**
 *	This method computes the delta time between records
 *	in the ring buffer
 *
 *	@param	nb	The number of delta t to be computed
 */
//==========================================================================
	double[] get_delta_t(int nb) throws DevFailed
	{
		// Throw exception if nothing in ring
		if (size() < 2)
		{
			Except.throw_exception("API_PollRingBufferEmpty",
				        "Not enough data stored yet in polling ring buffer",
				        "PollRing.get_delta_t");
		}

		// Compute how many delta can be computed
		if (nb >= size())
			nb = size() - 1;
		double[]	result = new double[nb];
		int	start = size() - nb - 1;
		if (start<0)
			start = 0;

		// The delta t computing loop
		for (int i=start, idx=0 ; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy