Ignore:
Timestamp:
03/15/04 12:04:09 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MTask.cc

    r2858 r3497  
    9090
    9191#include <fstream>
    92 #include <TBaseClass.h>
     92
     93#include <TBaseClass.h> // OverwritesProcess
     94#include <TStopwatch.h> // TStopwatch
    9395
    9496#include "MLog.h"
     
    103105
    104106MTask::MTask(const char *name, const char *title)
    105     : fFilter(NULL), fSerialNumber(0), fIsPreprocessed(kFALSE), fNumExecutions(0)
     107    : fFilter(NULL), fSerialNumber(0), fIsPreprocessed(kFALSE),
     108    fNumExecutions(0), fStopwatch(0)
    106109{
    107110    fName  = name  ? name  : "MTask";
     
    110113    fListOfBranches = new TList;
    111114    fListOfBranches->SetOwner();
     115
     116    fStopwatch = new TStopwatch;
    112117}
    113118
    114119MTask::~MTask()
    115120{
     121    delete fStopwatch;
    116122    delete fListOfBranches;
    117123}
     
    184190// Mapper function for PreProcess.
    185191// Sets the preprocessed flag dependend on the return value of PreProcess.
     192// Resets number of executions and cpu consumtion timer.
    186193//
    187194Int_t MTask::CallPreProcess(MParList *plist)
    188195{
    189196    fNumExecutions = 0;
     197    fStopwatch->Reset();
    190198
    191199    *fLog << all << fName << "... " << flush;
     
    218226// return value.
    219227// If Process is executed, the execution counter is increased.
     228// Count cpu consumtion time.
    220229//
    221230Int_t MTask::CallProcess()
     
    232241
    233242    fNumExecutions++;
    234     return Process();
     243
     244    fStopwatch->Start(kFALSE);
     245    const Int_t rc = Process();
     246    fStopwatch->Stop();
     247
     248    return rc;
    235249}
    236250
     
    332346// --------------------------------------------------------------------------
    333347//
    334 //  Prints the number of times all the tasks in the list has been.
     348//  Return total CPU execution time of task
     349//
     350Double_t MTask::GetCpuTime() const
     351{
     352    return fStopwatch->CpuTime();
     353}
     354
     355// --------------------------------------------------------------------------
     356//
     357//  Return total real execution time of task
     358//
     359Double_t MTask::GetRealTime() const
     360{
     361    return fStopwatch->RealTime();
     362}
     363
     364// --------------------------------------------------------------------------
     365//
     366//  Prints the relative time spent in Process() (relative means relative to
     367//  its parent Tasklist) and the number of times Process() was executed.
    335368//  For convinience the lvl argument results in a number of spaces at the
    336369//  beginning of the line. So that the structur of a tasklist can be
     
    338371//  filter is printer in <>-brackets behind the number of executions.
    339372//  Use MTaskList::PrintStatistics without an argument.
    340 //
    341 void MTask::PrintStatistics(const Int_t lvl, Bool_t title) const
    342 {
    343     *fLog << all << setfill(' ') << setw(lvl) << " " << GetDescriptor() << "\t";
     373//  For tasks which don't overwrite Process() no action is perfomed.
     374//
     375void MTask::PrintStatistics(const Int_t lvl, Bool_t title, Double_t time) const
     376{
     377    if (!OverwritesProcess())
     378        return;
     379
     380    *fLog << all << setfill(' ') << setw(lvl) << " ";
     381    if (fStopwatch->CpuTime()>0 && time>0)
     382        *fLog << setw(3) << (Int_t)(fStopwatch->CpuTime()/time*100+.5) << "% ";
     383    else
     384        *fLog << "     ";
     385    *fLog << GetDescriptor() << "\t";
    344386    *fLog << dec << fNumExecutions;
    345387    if (fFilter)
  • trunk/MagicSoft/Mars/mbase/MTask.h

    r2589 r3497  
    1515
    1616class TList;
     17class TStopwatch;
    1718
    1819class MFilter;
     
    2930    Bool_t fIsPreprocessed; //! Indicates the success of the PreProcessing (set by MTaskList)
    3031    UInt_t fNumExecutions;  //! Number of Excutions
     32
     33    TStopwatch *fStopwatch; //!
    3134
    3235    virtual Int_t PreProcess(MParList *pList);
     
    6669    virtual ~MTask();
    6770
     71    const TList *GetListOfBranches() const { return fListOfBranches; }
     72    Bool_t OverwritesProcess(TClass *cls=NULL) const;
     73
     74    // Filter functions
    6875    virtual void SetFilter(MFilter *filter) { fFilter=filter; }
    6976    const MFilter *GetFilter() const      { return fFilter; }
    7077    MFilter *GetFilter()  { return fFilter; } // for MContinue only
    7178
     79    // Display functions
    7280    void SetDisplay(MStatusDisplay *d);
    73     virtual void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE) const;
    7481
     82    // Function for parallel executions
    7583    static TString AddSerialNumber(const char *str, UInt_t num) { TString s(str); if (num==0) return s; s += ";"; s += num; return s; }
    7684    static TString AddSerialNumber(const TString &str, UInt_t num) { return AddSerialNumber((const char*)str, num); }
     
    8391    const char *GetDescriptor() const;
    8492
     93    // Task execution statistics
    8594    UInt_t GetNumExecutions() const { return fNumExecutions; }
     95    Double_t GetCpuTime() const;
     96    Double_t GetRealTime() const;
     97    virtual void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE, Double_t time=0) const;
    8698
     99    // Task overwrite functions
    87100    virtual Bool_t ReInit(MParList *pList);
    88101
     
    90103    virtual Int_t CallProcess();
    91104    virtual Int_t CallPostProcess();
    92 
    93     const TList *GetListOfBranches() const { return fListOfBranches; }
    94 
    95     Bool_t OverwritesProcess(TClass *cls=NULL) const;
    96105
    97106    void SavePrimitive(ofstream &out, Option_t *o="");
  • trunk/MagicSoft/Mars/mbase/MTaskList.cc

    r2958 r3497  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
     18!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2001
     20!   Copyright: MAGIC Software Development, 2000-2004
    2121!
    2222!
     
    2424
    2525/////////////////////////////////////////////////////////////////////////////
    26 //                                                                         //
    27 // MTaskList                                                               //
    28 //                                                                         //
    29 // Collection of tasks.                                                    //
    30 //                                                                         //
    31 // A tasklist is necessary to run the eventloop. It contains the scheduled //
    32 // tasks, which should be executed in your program.                        //
    33 //                                                                         //
    34 // To add a task use AddToList.                                            //
    35 //                                                                         //
    36 // The tasklist itself is a task, too. You can add a tasklist to another   //
    37 // tasklist. This makes sense, if you want to filter the execution of      //
    38 // more than one task of your tasklist using the same filter.              //
    39 //                                                                         //
    40 // The tasks in the list are idetified by their names. If more than one    //
    41 // task has the same name, the tasklist will still work correctly, but     //
    42 // you might run into trouble trying to get a pointer to a task by name    //
    43 // from the list.                                                          //
    44 //                                                                         //
    45 // Warning:                                                                //
    46 //  Be carefull if you are writing your tasklist                           //
    47 //  (eg. MWriteRootFile("file.root", "MTaskList")) to a file. You may      //
    48 //  not be able to initialize a new working tasklist from a file if        //
    49 //   a) Two Paramerer containers with the same names are existing in the   //
    50 //      MParList.                                                          //
    51 //   b) You used a container somewhere which is not part of MParList.      //
    52 //      (eg. You specified a pointer to a MH container in MFillH which is  //
    53 //      not added to the parameter list.                                   //
    54 //                                                                         //
     26//
     27// MTaskList
     28//
     29// Collection of tasks.
     30//
     31// A tasklist is necessary to run the eventloop. It contains the scheduled
     32// tasks, which should be executed in your program.
     33//
     34// To add a task use AddToList.
     35//
     36// The tasklist itself is a task, too. You can add a tasklist to another
     37// tasklist. This makes sense, if you want to filter the execution of
     38// more than one task of your tasklist using the same filter.
     39//
     40// The tasks in the list are idetified by their names. If more than one
     41// task has the same name, the tasklist will still work correctly, but
     42// you might run into trouble trying to get a pointer to a task by name
     43// from the list.
     44//
     45// Warning:
     46//  Be carefull if you are writing your tasklist
     47//  (eg. MWriteRootFile("file.root", "MTaskList")) to a file. You may
     48//  not be able to initialize a new working tasklist from a file if
     49//   a) Two Paramerer containers with the same names are existing in the
     50//      MParList.
     51//   b) You used a container somewhere which is not part of MParList.
     52//      (eg. You specified a pointer to a MH container in MFillH which is
     53//      not added to the parameter list.
     54//
    5555/////////////////////////////////////////////////////////////////////////////
    56 
    5756#include "MTaskList.h"
    5857
    59 #include <fstream>        // ofstream, SavePrimitive
    60 
    61 #include <TClass.h>
    62 #include <TSystem.h>        // gSystem
    63 #include <TOrdCollection.h>
     58#include <fstream>           // ofstream, SavePrimitive
     59
     60#include <TSystem.h>         // gSystem
     61#include <TOrdCollection.h>  // TOrdCollection
    6462
    6563#include "MLog.h"
     
    627625//  Use MTaskList::PrintStatistics without an argument.
    628626//
    629 void MTaskList::PrintStatistics(const Int_t lvl, Bool_t title) const
     627void MTaskList::PrintStatistics(const Int_t lvl, Bool_t title, Double_t time) const
    630628{
    631629    if (lvl==0)
    632630    {
    633         *fLog << all << underline << "Execution Statistics:" << endl;
     631        *fLog << all << underline << "Process execution Statistics:" << endl;
    634632        *fLog << GetDescriptor();
    635633        if (GetFilter())
     
    640638    }
    641639    else
    642         MTask::PrintStatistics(lvl, title);
     640        MTask::PrintStatistics(lvl, title, time);
    643641
    644642    //
    645643    //  create the Iterator for the TaskList
    646644    //
    647     fTasks->ForEach(MTask, PrintStatistics)(lvl+1, title);
     645    fTasks->ForEach(MTask, PrintStatistics)(lvl+1, title, GetCpuTime());
    648646
    649647    if (lvl==0)
     
    651649}
    652650
    653 
    654 // --------------------------------------------------------------------------
     651// --------------------------------------------------------------------------
     652//
     653// Call 'Print()' of all tasks
     654//
    655655void MTaskList::Print(Option_t *t) const
    656656{
  • trunk/MagicSoft/Mars/mbase/MTaskList.h

    r2470 r3497  
    7070
    7171    void Print(Option_t *opt = "") const;
    72     void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE) const;
     72    void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE, Double_t time=0) const;
    7373    void SetOwner(Bool_t enable=kTRUE);
    7474
Note: See TracChangeset for help on using the changeset viewer.