// @(#)root/proofx:$Id$
// Author: G.Ganis, S.Ryu Feb 2011

/*************************************************************************
 * 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_TProofBench
#define ROOT_TProofBench

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TProofBench                                                          //
//                                                                      //
// Steering class for PROOF benchmarks                                  //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TProofBenchTypes
#include "TProofBenchTypes.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif


class TF1;
class TFile;
class TGraphErrors;
class TProfile;
class TProof;
class TProofBenchRunCPU;
class TProofBenchRunDataRead;
class TProofBenchDataSet;

class TProofBench : public TObject {

private:
   Bool_t  fUnlinkOutfile;       // Whether to remove empty output files

protected:

   TProof* fProof;               // Proof
   TProof* fProofDS;             // Proof to be used for dataset actions
   TFile  *fOutFile;             // Output file
   TString fOutFileName;         // Name of the output file
   Int_t   fNtries;              // Number of times a measurement is repeated
   TPBHistType *fHistType;       // Type of histograms for CPU runs
   Int_t   fNHist;               // Number of histograms to be created in default CPU runs
   TPBReadType *fReadType;       // Type of read (partial, full)
   TString fDataSet;             // Name of the dataset
   Int_t   fNFilesWrk;           // Number of files generated files per worker
   Int_t   fNumWrkMax;           // Max number of workers (required for dynamic setups)
   Bool_t  fReleaseCache;        // Release cache for data reads between runs

   TString fCPUSel;              // Selector to be used for CPU benchmarks
   TString fCPUPar;              // List of par files to be loaded for CPU benchmarks
   TString fDataSel;             // Selector to be used for data benchmarks
   TString fDataPar;             // List of par files to be loaded for data benchmarks
   TString fDataGenSel;          // Selector to be used for generate data for benchmarks
   TString fDataGenPar;          // List of par files to be loaded to generate data for benchmarks
   TString fSelOption;           // Option field for processing the selector

   TProofBenchRunCPU      *fRunCPU; // Instance to run CPU scans
   TProofBenchRunDataRead *fRunDS;  // Instance to run data-read scans
   TProofBenchDataSet     *fDS;     // Instance to handle datasets operations

   Bool_t fDebug;                // Debug switch

   TNamed *fDescription;         // Strings describing the cluster for this test (saved in the output file)

   static TGraphErrors *GetGraph(TDirectory *d, const char *pfn,
                                 Int_t &nb, Double_t &xmi, Double_t &xmx,
                                 Double_t &ymi, Double_t &ymx, Int_t &kmx, TProfile *&pf);

   static TF1 *fgFp1;                 // Simple 1st degree polynomial
   static TF1 *fgFp1n;                // Normalized 1st degree
   static TF1 *fgFp2;                 // Simple 2nd degree polynomial
   static TF1 *fgFp2n;                // Normalized 2nd degree
   static TF1 *fgFp3;                 // Function with varying Rcpu
   static TF1 *fgFp3n;                // Normalized Function with varying Rcpu

   static TF1 *fgFio;                 // Function used for I/O rate fits
   static TF1 *fgFioV;                // Function used for I/O rate fits with non-constant Rcpu

   static TList *fgGraphs;        // List of TGraphErrors created by Draw actions

   static void AssertFittingFun(Double_t mi, Double_t mx);

public:

   TProofBench(const char *url, const char *outfile = "<default>", const char *proofopt = 0);

   virtual ~TProofBench();

   Int_t RunCPU(Long64_t nevents=-1, Int_t start=-1, Int_t stop=-1, Int_t step=-1);
   Int_t RunCPUx(Long64_t nevents=-1, Int_t start=-1, Int_t stop=-1);
   Int_t RunDataSet(const char *dset = "BenchDataSet",
                    Int_t start = 1, Int_t stop = -1, Int_t step = 1);
   Int_t RunDataSetx(const char *dset = "BenchDataSet", Int_t start = 1, Int_t stop = -1);

   Int_t CopyDataSet(const char *dset, const char *dsetdst, const char *destdir);
   Int_t MakeDataSet(const char *dset = 0, Long64_t nevt = -1, const char *fnroot = "event",
                     Bool_t regenerate = kFALSE);
   Int_t ReleaseCache(const char *dset);
   Int_t RemoveDataSet(const char *dset);

   void  CloseOutFile();
   Int_t OpenOutFile(Bool_t wrt = kFALSE, Bool_t verbose = kTRUE);
   Int_t SetOutFile(const char *outfile, Bool_t verbose = kTRUE);
   const char *GetOutFileName() const { return fOutFileName; }
   void  SetNFilesWrk(Int_t nf = 0) { fNFilesWrk = (nf > 0) ? nf : 4; }
   void  SetNTries(Int_t nt) { if (nt > 0) fNtries = nt; }
   void  SetHistType(TPBHistType *histtype) { fHistType = histtype; }
   void  SetNHist(Int_t nh) { fNHist = nh; }
   void  SetReadType(TPBReadType *readtype) { fReadType = readtype; }
   void  SetReleaseCache(Bool_t on = kTRUE) { fReleaseCache = on; }

   void  SetCPUSel(const char *sel) { fCPUSel = sel; }
   void  SetCPUPar(const char *par) { fCPUPar = par; }
   void  SetDataSel(const char *sel) { fDataSel = sel; }
   void  SetDataPar(const char *par) { fDataPar = par; }
   void  SetDataGenSel(const char *sel) { fDataGenSel = sel; }
   void  SetDataGenPar(const char *par) { fDataGenPar = par; }
   void  SetSelOption(const char *opt) { fSelOption = opt; }

   void  SetProofDS(TProof *p);

   void  SetDebug(Bool_t debug = kTRUE) { fDebug = debug; }

   Bool_t GetDebug() { return fDebug; }

   static void DrawCPU(const char *outfile, const char *opt = "std:", Bool_t verbose = kFALSE,
                      Int_t dofit = 0, Int_t n0 = -1, Int_t n1 = -1);
   static void DrawDataSet(const char *outfile, const char *opt = "std:", const char *type = "mbs", Bool_t verbose = kFALSE,
                           Int_t dofit = 0, Int_t n0 = -1, Int_t n1 = -1);
   static void GetPerfSpecs(const char *path = ".", Int_t degfit = 1);
   static void DrawEfficiency(const char *outfile, const char *opt = "", Bool_t verbose = kFALSE);

   static TList *GetGraphs() { return fgGraphs; }

   ClassDef(TProofBench, 0)   // Steering class for PROOF benchmarks
};

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