/*
Copyright (c) 2000                      RIPE NCC


All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of the author not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

/*
-------------------------------------------------------------------------------
Module Header
Filename          : DelayPlots.h
Author            : Rene Wilhelm
Date              : 17-OCT-2000
Description       : TTM DelayPlots class definition
Language Version  : C++
OSs Tested        : Solaris 2.6

The DelayPlots class groups all data and funtions needed to
create TTM plots for a given source and one or more target boxes.
The interface to the outside is provided by two methods:

  Fill() - processes data and fills ROOT histograms
  Plot() - create plot(s) from the previously filled histograms. 
	
$Id: DelayPlots.h,v 1.8 2002/08/09 14:32:09 henk Exp $
-------------------------------------------------------------------------------
*/

#ifndef DelayPlots_included
#define DelayPlots_included


#include <time.h>  
#include <TH1.h>
#include <TH2.h>
#include <TPad.h>
#include <TStyle.h>
#include "TTMDataChain.h"
#include "TestBoxConfig.h"
#include "Percentiles.h"
#include "RoutingInfo.h"
#include "utils.h"


class DelayPlots {
private:
	TestBox source;
	TestBox *target;
	int	ntargets;

	// lists of pointers to histogram objects.
	// one set of histograms is filled for each target

	TH2F	**Delay2D;
	TH1F	**Delay1D;
	TH1F	**PacketsSent;
	TH1F	**ClocksOK;
	TH1F	**BadSourceClock;
	TH1F	**BadTargetClock;
	TH1F	**BadClocks;
	TH2F	**RoutesNHops;
	TH1F	**PacketsLost;

	// the Arrived histogram is a temporary histogram only created
	// at plot time; it is reused for every target.

	TH1F	*Arrived;

	Percentiles  *LossPercentile;	  // reused for every target
	Percentiles **DelayPercentile;	  // one object per target
	RoutingInfo **RoutesInfo;	  // one object per target

	int *id2index;			  // map box id to array index
	uint MaxBoxId;
	int nMeasurements;

	time_t starttime;
	char*  cstarttime1;	// full  char reprensation of start time
	char*  cstarttime2;	// short char reprensation of start time
	time_t endtime;
	char*  cendtime1;	// full  char reprensation of end time
	char*  cendtime2;	// short char reprensation of end time

	TStyle *rootstyle;
	TChain *rootchain;
	TTMDataChain *datachain;

	// parameters for histograms

	double	mindelay;	// lower delays will go to underflow bin
	double	maxdelay;	// higher delays will go to overflow bin
	short	logscale;	// whether or not to use logscale for delays
	short	allpackets;	// also include packets with bad clocks in plots
	int	binsX;		// number of bins on X-axis
	int	binsY;		// number of bins on Y-axis

	// private methods

	void ClearHistos();
	void CreateHistos();
	void DeleteHistos();
	void PlotHistos(int index, int targetId);	
	void SetSourceTarget(TestBox src, TestBox **dest);
	void processDelay(Delay *delay);

	void write_stats(TPad* pad, const char* ptr_text, const Float_t x,
                const Float_t y, const Short_t align, Font_t font);

public:
	void Fill(TestBox src, TestBox **dest, int ndest, time_t period,
                  time_t end, double mndelay, double mxdelay, short allpckts);

	void Plot(plotformat fmt, char* outdir, short lgscale);  
	void CSV(TestBox src, TestBox **dest, int ndest, time_t period,
		 time_t end, char* output);
	DelayPlots();
	
};
#endif
