/*
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          : TTMDelayData.h
Author            : Rene Wilhelm
Date              : 13-OCT-2000
Description       : The TTMDelayData class provides high level interface
		    to TTM delay data files. Depending on the 
		    program options and testbox configuration data
		    passwd to SetConfig, data files for one or more
		    days are chained for processing.
Language Version  : C++
OSs Tested        : Solaris 2.6
$Id: TTMDelayData.h,v 1.4 2003/01/22 16:31:11 ttraffic Exp $
-------------------------------------------------------------------------------
*/

#ifndef TTMDelayData_included
#define TTMDelayData_included


#include "TestBoxConfig.h"      // TTM  TestBoxConfig class
#include "TTMOptions.h"         // TTM  Program Options class
#include "TTMStatistics.h"	// TTM  Statistics class
#include "TTMHistograms.h"	// TTM  Statistics class
#include "CSVdump.h"		// CSV  Output

#include <time.h>
#include <TChain.h> 		// ROOT TChain class

enum ttmdata {
	delaystats,		// delay Statistics
	delayhist,		// One way delay Histograms
	ipdvhist,		// IP delay varations histograms
	csvdump			// CSV ascii output
};

class TTMDelayData {
private:

        TestBoxConfig *tbConfig;    // Testbox Chain Configuration
                                    // to see which boxes were ON
        TTMOptions    *progOptions; // Program options


	TestBox **sourceList;	// list of source boxes for this Data set
	int nSources;		// number of targets

	int dataProcessed;	// flag to indicate if data has been processed
	int nProcessed;		// number of packets seen for last source/target
	int numBoxes;		// number of distinct source/target boxes

	CSVdump	*csv;		// list of CSV output objects

        TTMHistograms *delayHistos; // list of statistics collecting objects 
        TTMStatistics *delayStats;  // list of statistics collecting objects 
	int numIntervals;	// number of time intervals for statistics

	int *id2index;   	// map box id to array index
	uint maxBoxId;		// largest id in target list

	TChain *chain;		// ROOT Tree Chain object

	char *dataPath;		// path to (top of) ROOT data storage
	int ipv6Chain;		// flag if we're chaining IPv6 data
	char  storageType;	// storage type: 'H' = year/month/day hierarchy
				//               'F' = flat

	char *outputFile;	// output file for Summary Info 
	char *outputDir;	// output directory for Plots
        plotformat plotFormat;  // format of output plots (gif, ps, ..)

	TTree *sumTree ;	// TTree with summary info
	DelaySummary *summary;  // pointer to summary object for TTree fills

	time_t endTime;		// endtime for TTM DelayData chain
	time_t timePeriod;	// time period of DelayData chain
				// (not necessarily integer number of days)

        void InitStorage(TestBox* source, ttmdata type);  
		// Initialize datastorage, create arrays, histograms, etc.

        void Chain(TestBox* source);  
                // Create the ROOT data chain for given source

	int ProcessPackets(TestBox* source, ttmdata type);
		// process all data in chain, fill histos etc.
		// returns number of packets seen for source/target combo

        void FillSummaryTree(TestBox* source, TFile* summaryfile);  
		// Compute summary info and store in file

	void PlotHistos(TestBox* source);
		// Plot all histograms for source box's targets


public:
	~TTMDelayData();				   // destructor
	TTMDelayData();					   // constructor

        void SetConfig(TTMOptions &opt, TestBoxConfig& conf, int numint);
                //  opt    - object holding program's options 
                //  conf   - configuration of TTM chain (at endtime)
                //  numint - (max) number of intervals per day 

	void Summarize();
		// Create summary (percentiles etc.)
		// result is a ROOT Tree with DelaySummary objects
		// on the outputfile set with SetConfig

	void Plot();
		// create plots

	void OutputCSV();
		// dump contents in CSV file

};

#endif 
