Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsBenchController.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software
00003  * 
00004  * The Software has been developped within the Siames Project. 
00005  * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights
00006  * 
00007  * The Software has been registered with the Agence pour la Protection des
00008  * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200
00009  *
00010  * This file may be distributed under the terms of the Q Public License
00011  * version 1.0 as defined by Trolltech AS of Norway and appearing in the file
00012  * LICENSE.QPL included in the packaging of this file.
00013  *
00014  * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 
00015  * for the software may use this file in accordance with that specific license 
00016  *
00017  */
00018 #ifndef PsBenchControllerHEADER
00019 #define PsBenchControllerHEADER
00020 
00021 #include <fstream>
00022 #include <PsController.h>
00023 #include <PsTimerController.h>
00024 
00025 
00035 template <typename BenchedController>
00036 class PsBenchController : public PsTimerController<BenchedController>
00037 {
00038 public:
00040    PsBenchController(PsObjectDescriptor & scenario, const PsDate & initialDate );
00041    
00043    PsBenchController(PsObjectDescriptor & scenario, const PsDate & initialDate, int argc, char * argv [] );
00044 
00047    virtual ~PsBenchController();
00048    
00050    virtual PsnScheduler * createScheduler() ; 
00051 
00053   virtual void advanceSimulatedDate();
00054    
00055 protected :
00057    PsString _resultFilename;
00058 
00060    int _sampleIndex ;
00061 
00063    ofstream * _file ;
00064 }; // PsBenchController
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 #include <sys/time.h>
00074 #ifdef _SGI
00075 #include <sys/syssgi.h>
00076 #endif
00077 #include <unistd.h>
00078 
00079 #include "PsnBenchScheduler.h"
00080 #include "PsConfigurationParameterDescriptor.h"
00081 
00082 template <typename BenchedController>
00083 PsBenchController<BenchedController>::PsBenchController(PsObjectDescriptor & scenario, const PsDate & initialDate ) : 
00084    PsTimerController<BenchedController>(scenario, initialDate),
00085    _resultFilename (""),
00086    _sampleIndex ( -1 ),
00087    _file (NULL )
00088 {
00089    if (getConfigurationParameters() != NULL )
00090       {
00091          const PsConfigurationParameterDescriptor * param = getConfigurationParameters()->getSubDescriptorByName("BenchResultFile") ;
00092          if ( param != NULL )
00093             {
00094                _resultFilename = param->getAssociatedString() ;
00095                _file = new ofstream ( _resultFilename.getCString() );
00096                assert ( _file->good() ) ;
00097             }
00098       }
00099 }
00100 
00101 template <typename BenchedController>
00102 PsBenchController<BenchedController>::PsBenchController(PsObjectDescriptor & scenario, const PsDate & initialDate, int argc, char * argv [] ) 
00103    :  PsTimerController<BenchedController>(scenario, initialDate, argc, argv),
00104       _resultFilename (""),
00105       _sampleIndex ( 0 ),
00106       _file (NULL )
00107 {
00108    if (getConfigurationParameters() != NULL )
00109       {
00110          const PsConfigurationParameterDescriptor * param = getConfigurationParameters()->getSubDescriptorByName("BenchResultFile") ;
00111          if ( param != NULL )
00112             {
00113                _resultFilename = param->getAssociatedString() ;
00114                _file = new ofstream ( _resultFilename.getCString() );
00115                assert ( _file->good() ) ;
00116             }
00117       }
00118 }
00119 
00120 template <typename BenchedController>
00121 PsBenchController<BenchedController>::~PsBenchController() 
00122 {
00123    // delete the scheduler because it has a pointer to the file we opened   
00124   if ( _scheduler != NULL ) 
00125      {
00126         delete _scheduler ;
00127         _scheduler = NULL ;
00128      }
00129 
00130    if ( _file != NULL )
00131       {
00132          _file->close() ;
00133          delete _file ;
00134          _file = NULL ;
00135       }
00136 }
00137 
00138 
00139 
00140 template <typename BenchedController>
00141 PsnScheduler * PsBenchController<BenchedController>::createScheduler() 
00142 {
00143    PsnScheduler * res ;
00144 
00145    if (_startSamplingDate<PsController::initialSimulationDate) 
00146       {
00147          _startSamplingDate=PsController::initialSimulationDate;
00148          cout<<"PsBenchController::WARNING : no values before PsController::initialSimulationDate ("
00149              <<PsController::initialSimulationDate<<")"<<endl;
00150       }
00151 
00152    _numberOfSamples = (_endSamplingDate-_startSamplingDate)/_stepPeriod + 1;
00153 
00154    if ( _file != NULL ) 
00155       {
00156          res = new PsnBenchScheduler(_nbStepsByCycle, _sampleIndex, _numberOfSamples,*_file) ;
00157       }
00158    else 
00159       {
00160          res = new PsnBenchScheduler(_nbStepsByCycle, _sampleIndex, _numberOfSamples, cout ) ;
00161       }
00162    return res ;
00163 }
00164 
00165 template <typename BenchedController>
00166 void PsBenchController<BenchedController>::advanceSimulatedDate()
00167 {
00168    if ( (_date >= _startSamplingDate) && 
00169         (_date <= _endSamplingDate) )
00170       {
00171          ++_sampleIndex ;
00172       }
00173    PsTimerController<BenchedController>::advanceSimulatedDate() ;
00174 }
00175 
00176 #endif
00177 
00178 
00179 

logo OpenMask

Documentation generated on Mon Nov 25 15:24:59 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001