// @(#)root/proof:$Id$
// Author: Sangsu Ryu 22/06/2010

/*************************************************************************
 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TProofBenchRunDataRead
#define ROOT_TProofBenchRunDataRead

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TProofBenchRunDataRead                                               //
//                                                                      //
// I/O-intensive PROOF benchmark test reads in event files distributed  //
// on the cluster. Number of events processed per second and size of    //
// events processed per second are plotted against number of active     //
// workers. Performance rate for unit packets and performance rate      //
// for query are plotted.                                               //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TString
#include "TString.h"
#endif

#ifndef ROOT_TProofBenchRun
#include "TProofBenchRun.h"
#endif

class TProof;
class TCanvas;
class TH2;
class TProfile;
class TLegend;
class TTree;
class TFileCollection;

class TProofBenchMode;
class TProofBenchDataSet;
class TProofNodes;
class TPBReadType;

class TProofBenchRunDataRead : public TProofBenchRun {

private:
   TProof* fProof;               //pointer to proof

   TPBReadType *fReadType; //read type
   TProofBenchDataSet *fDS;              //dataset operations handler

   Long64_t fNEvents;            //number of events per file
   Int_t fNTries;                //number of tries
   Int_t fStart;                 //start number of workers
   Int_t fStop;                  //stop number of workers
   Int_t fStep;                  //test to be performed every fStep workers
   Int_t fDebug;                 //debug switch
   Int_t fFilesPerWrk;           //# of files to be processed per worker
   Bool_t fReleaseCache;         // Release cache for data reads between runs

   TDirectory  *fDirProofBench;   //directory for proof outputs

   TProofNodes *fNodes;                //list of nodes information

   TList        *fListPerfPlots;            //list of performance plots
   TProfile     *fProfile_perfstat_event;
   TH2          *fHist_perfstat_event;
   TProfile     *fProfile_perfstat_evtmax;
   TProfile     *fNorm_perfstat_evtmax;
   TProfile     *fProfile_queryresult_event;
   TProfile     *fNorm_queryresult_event;
   TProfile     *fProfile_perfstat_IO;
   TH2          *fHist_perfstat_IO;
   TProfile     *fProfile_perfstat_IOmax;
   TProfile     *fNorm_perfstat_IOmax;
   TProfile     *fProfile_queryresult_IO;
   TProfile     *fNorm_queryresult_IO;
   TProfile     *fProfile_cpu_eff;

   TLegend     *fProfLegend_evt;            // Legend for profiles evts
   TLegend     *fNormLegend_evt;            // Legend for norms evts
   TLegend     *fProfLegend_mb;            // Legend for profiles mbs
   TLegend     *fNormLegend_mb;            // Legend for norms mbs

   TCanvas *fCPerfProfiles;      //canvas for performance profile histograms

   TString fName;                //name of this run

   void BuildHistos(Int_t start, Int_t stop, Int_t step, Bool_t nx);

protected:

   void FillPerfStatProfiles(TTree* t, Int_t nactive);

   Int_t SetParameters();
   Int_t DeleteParameters();

public:

   TProofBenchRunDataRead(TProofBenchDataSet *pbds, TPBReadType *readtype = 0,
                          TDirectory* dirproofbench=0, TProof* proof=0, TProofNodes* nodes=0,
                          Long64_t nevents=-1, Int_t ntries=2, Int_t start=1, Int_t stop=-1,
                          Int_t step=1, Int_t debug=0);

   virtual ~TProofBenchRunDataRead();

   void Run(Long64_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t) { }
   void Run(const char *dset, Int_t start, Int_t stop, Int_t step, Int_t ntries,
            Int_t debug, Int_t);

   TFileCollection *GetDataSet(const char *dset, Int_t nact, Bool_t nx);

   void DrawPerfProfiles();

   void Print(Option_t* option="") const;

   void SetReadType(TPBReadType *readtype) { fReadType = readtype; }
   void SetNEvents(Long64_t nevents) { fNEvents = nevents; }
   void SetNTries(Int_t ntries) { fNTries = ntries; }
   void SetStart(Int_t start) { fStart = start; }
   void SetStop(Int_t stop) { fStop = stop; }
   void SetStep(Int_t step) { fStep = step; }
   void SetDebug(Int_t debug) { fDebug = debug; }
   void SetDirProofBench(TDirectory* dir) { fDirProofBench = dir; }
   void SetFilesPerWrk(Int_t fpw) { fFilesPerWrk = fpw; }
   void SetReleaseCache(Bool_t on = kTRUE) { fReleaseCache = on; }

   TPBReadType *GetReadType() const { return fReadType; }
   Long64_t GetNEvents() const { return fNEvents; }
   Int_t GetNTries() const { return fNTries; }
   Int_t GetStart() const { return fStart; }
   Int_t GetStop() const { return fStop; }
   Int_t GetStep() const { return fStep; }
   Int_t GetDebug() const { return fDebug; }
   TDirectory* GetDirProofBench() const { return fDirProofBench; }
   TCanvas* GetCPerfProfiles() const { return fCPerfProfiles; }
   const char* GetName() const { return fName; }

   TString GetNameStem() const;

   ClassDef(TProofBenchRunDataRead,0)         //IO-intensive PROOF benchmark
};

#endif
 TProofBenchRunDataRead.h:1
 TProofBenchRunDataRead.h:2
 TProofBenchRunDataRead.h:3
 TProofBenchRunDataRead.h:4
 TProofBenchRunDataRead.h:5
 TProofBenchRunDataRead.h:6
 TProofBenchRunDataRead.h:7
 TProofBenchRunDataRead.h:8
 TProofBenchRunDataRead.h:9
 TProofBenchRunDataRead.h:10
 TProofBenchRunDataRead.h:11
 TProofBenchRunDataRead.h:12
 TProofBenchRunDataRead.h:13
 TProofBenchRunDataRead.h:14
 TProofBenchRunDataRead.h:15
 TProofBenchRunDataRead.h:16
 TProofBenchRunDataRead.h:17
 TProofBenchRunDataRead.h:18
 TProofBenchRunDataRead.h:19
 TProofBenchRunDataRead.h:20
 TProofBenchRunDataRead.h:21
 TProofBenchRunDataRead.h:22
 TProofBenchRunDataRead.h:23
 TProofBenchRunDataRead.h:24
 TProofBenchRunDataRead.h:25
 TProofBenchRunDataRead.h:26
 TProofBenchRunDataRead.h:27
 TProofBenchRunDataRead.h:28
 TProofBenchRunDataRead.h:29
 TProofBenchRunDataRead.h:30
 TProofBenchRunDataRead.h:31
 TProofBenchRunDataRead.h:32
 TProofBenchRunDataRead.h:33
 TProofBenchRunDataRead.h:34
 TProofBenchRunDataRead.h:35
 TProofBenchRunDataRead.h:36
 TProofBenchRunDataRead.h:37
 TProofBenchRunDataRead.h:38
 TProofBenchRunDataRead.h:39
 TProofBenchRunDataRead.h:40
 TProofBenchRunDataRead.h:41
 TProofBenchRunDataRead.h:42
 TProofBenchRunDataRead.h:43
 TProofBenchRunDataRead.h:44
 TProofBenchRunDataRead.h:45
 TProofBenchRunDataRead.h:46
 TProofBenchRunDataRead.h:47
 TProofBenchRunDataRead.h:48
 TProofBenchRunDataRead.h:49
 TProofBenchRunDataRead.h:50
 TProofBenchRunDataRead.h:51
 TProofBenchRunDataRead.h:52
 TProofBenchRunDataRead.h:53
 TProofBenchRunDataRead.h:54
 TProofBenchRunDataRead.h:55
 TProofBenchRunDataRead.h:56
 TProofBenchRunDataRead.h:57
 TProofBenchRunDataRead.h:58
 TProofBenchRunDataRead.h:59
 TProofBenchRunDataRead.h:60
 TProofBenchRunDataRead.h:61
 TProofBenchRunDataRead.h:62
 TProofBenchRunDataRead.h:63
 TProofBenchRunDataRead.h:64
 TProofBenchRunDataRead.h:65
 TProofBenchRunDataRead.h:66
 TProofBenchRunDataRead.h:67
 TProofBenchRunDataRead.h:68
 TProofBenchRunDataRead.h:69
 TProofBenchRunDataRead.h:70
 TProofBenchRunDataRead.h:71
 TProofBenchRunDataRead.h:72
 TProofBenchRunDataRead.h:73
 TProofBenchRunDataRead.h:74
 TProofBenchRunDataRead.h:75
 TProofBenchRunDataRead.h:76
 TProofBenchRunDataRead.h:77
 TProofBenchRunDataRead.h:78
 TProofBenchRunDataRead.h:79
 TProofBenchRunDataRead.h:80
 TProofBenchRunDataRead.h:81
 TProofBenchRunDataRead.h:82
 TProofBenchRunDataRead.h:83
 TProofBenchRunDataRead.h:84
 TProofBenchRunDataRead.h:85
 TProofBenchRunDataRead.h:86
 TProofBenchRunDataRead.h:87
 TProofBenchRunDataRead.h:88
 TProofBenchRunDataRead.h:89
 TProofBenchRunDataRead.h:90
 TProofBenchRunDataRead.h:91
 TProofBenchRunDataRead.h:92
 TProofBenchRunDataRead.h:93
 TProofBenchRunDataRead.h:94
 TProofBenchRunDataRead.h:95
 TProofBenchRunDataRead.h:96
 TProofBenchRunDataRead.h:97
 TProofBenchRunDataRead.h:98
 TProofBenchRunDataRead.h:99
 TProofBenchRunDataRead.h:100
 TProofBenchRunDataRead.h:101
 TProofBenchRunDataRead.h:102
 TProofBenchRunDataRead.h:103
 TProofBenchRunDataRead.h:104
 TProofBenchRunDataRead.h:105
 TProofBenchRunDataRead.h:106
 TProofBenchRunDataRead.h:107
 TProofBenchRunDataRead.h:108
 TProofBenchRunDataRead.h:109
 TProofBenchRunDataRead.h:110
 TProofBenchRunDataRead.h:111
 TProofBenchRunDataRead.h:112
 TProofBenchRunDataRead.h:113
 TProofBenchRunDataRead.h:114
 TProofBenchRunDataRead.h:115
 TProofBenchRunDataRead.h:116
 TProofBenchRunDataRead.h:117
 TProofBenchRunDataRead.h:118
 TProofBenchRunDataRead.h:119
 TProofBenchRunDataRead.h:120
 TProofBenchRunDataRead.h:121
 TProofBenchRunDataRead.h:122
 TProofBenchRunDataRead.h:123
 TProofBenchRunDataRead.h:124
 TProofBenchRunDataRead.h:125
 TProofBenchRunDataRead.h:126
 TProofBenchRunDataRead.h:127
 TProofBenchRunDataRead.h:128
 TProofBenchRunDataRead.h:129
 TProofBenchRunDataRead.h:130
 TProofBenchRunDataRead.h:131
 TProofBenchRunDataRead.h:132
 TProofBenchRunDataRead.h:133
 TProofBenchRunDataRead.h:134
 TProofBenchRunDataRead.h:135
 TProofBenchRunDataRead.h:136
 TProofBenchRunDataRead.h:137
 TProofBenchRunDataRead.h:138
 TProofBenchRunDataRead.h:139
 TProofBenchRunDataRead.h:140
 TProofBenchRunDataRead.h:141
 TProofBenchRunDataRead.h:142
 TProofBenchRunDataRead.h:143
 TProofBenchRunDataRead.h:144
 TProofBenchRunDataRead.h:145
 TProofBenchRunDataRead.h:146
 TProofBenchRunDataRead.h:147
 TProofBenchRunDataRead.h:148