Ignore:
Timestamp:
04/19/03 18:39:05 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
8 edited

Legend:

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

    r1902 r1965  
    4646// Afterwards the PostProcess functions are executed.                       //
    4747//                                                                          //
    48 //                                                                          //
    49 //  Maybe we can add a TProgressMeter sometimes later to be able to show    //
    50 //  the progress graphically...                                             //
    51 //                                                                          //
     48// If you want to display the progress in a gui you can use SetProgressBar  //
     49// and a TGProgressBar or a MProgressBar. If you set a MStatusDisplay       //
     50// using SetDisplay, the Progress bar from this display is used.            //
    5251//                                                                          //
    5352// You can create a macro from a completely setup eventloop by:             //
     
    7473#include <iostream.h>
    7574
     75#include <TTime.h>          // TTime
    7676#include <TFile.h>          // gFile
    7777#include <TSystem.h>        // gSystem
     
    8787#include "MRead.h"           // for setting progress bar
    8888#include "MProgressBar.h"    // MProgressBar::GetBar
     89#include "MStatusDisplay.h"  // MStatusDisplay::GetBar
    8990#endif
    9091
     
    101102// --------------------------------------------------------------------------
    102103//
    103 // default constructor - emty
     104// default constructor
    104105//
    105106MEvtLoop::MEvtLoop(const char *name) : fParList(NULL), fProgress(NULL)
     
    112113// --------------------------------------------------------------------------
    113114//
    114 // default destructor - emty
     115// destructor
    115116//
    116117MEvtLoop::~MEvtLoop()
     
    171172    if (fLog != &gLog)
    172173        fParList->SetLogStream(fLog);
     174
     175#ifdef __MARS__
     176    //
     177    // Check whether display is still existing
     178    //
     179    if (fDisplay && !gROOT->GetListOfSpecials()->FindObject(fDisplay))
     180        fDisplay = NULL;
     181    if (fDisplay)
     182    {
     183        // Lock display to prevent user from deleting it
     184        fDisplay->Lock();
     185        // Get pointer to update Progress bar
     186        fProgress = fDisplay->GetBar();
     187        // Don't display context menus
     188        fDisplay->SetNoContextMenu();
     189        // Set window and icon name
     190        fDisplay->SetWindowName(TString("Status Display: ")+fName);
     191        fDisplay->SetIconName(fName);
     192        // Set status lines
     193        fDisplay->SetStatusLine1("PreProcessing...");
     194        fDisplay->SetStatusLine2("");
     195        // Start automatic update
     196        fDisplay->StartUpdate();
     197        // Cascade display through childs
     198        fParList->SetDisplay(fDisplay);
     199    }
     200#endif
    173201
    174202    //
     
    188216}
    189217
     218Bool_t MEvtLoop::ProcessGuiEvents(Int_t num)
     219{
     220    if (!fProgress)
     221        return kTRUE;
     222
     223    //
     224    // Check status of display
     225    //
     226    Bool_t rc = kTRUE;
     227
     228    if (fDisplay)
     229        switch (fDisplay->CheckStatus())
     230        {
     231        case MStatusDisplay::kLoopNone:
     232            break;
     233        case MStatusDisplay::kLoopStop:
     234            rc = kFALSE;
     235            fDisplay->ClearStatus();
     236            break;
     237        case MStatusDisplay::kFileExit:
     238            fParList->SetDisplay(NULL);
     239            delete fDisplay;
     240            SetDisplay(NULL);
     241            fProgress = NULL;
     242            gSystem->ProcessEvents();
     243            return kTRUE;
     244        default:
     245            fDisplay->ClearStatus();
     246            *fLog << warn << "Display shows unknown status... cleared." << endl;
     247            break;
     248        }
     249
     250    //
     251    // Check System time (don't loose too much time by updates)
     252    //
     253    static TTime t0 = gSystem->Now();
     254
     255    const TTime t1 = gSystem->Now();
     256    if (t1-t0 < (TTime)20)
     257        return rc;
     258
     259    t0 = t1;
     260
     261    //
     262    // Set new progress bar position
     263    //
     264    fProgress->SetPosition(num);
     265
     266    //
     267    // Handle GUI events (display changes)
     268    //
     269#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
     270    gSystem->ProcessEvents();
     271#else
     272    if (fDisplay)
     273        gSystem->ProcessEvents();
     274    else
     275        gClient->ProcessEventsFor(fProgress);
     276#endif
     277
     278    return rc;
     279}
     280
    190281// --------------------------------------------------------------------------
    191282//
     
    193284// for developers or use in special jobs only!
    194285//
    195 Bool_t MEvtLoop::Process(Int_t maxcnt) const
     286Bool_t MEvtLoop::Process(Int_t maxcnt)
    196287{
    197288    //
     
    208299    *fLog << " events)..." << flush;
    209300
     301    Int_t entries = INT_MAX;
     302
    210303    if (fProgress)
    211304    {
    212305        fProgress->Reset();
    213 
    214         Int_t entries = INT_MAX;
    215 
    216306#ifdef __MARS__
    217307        // limits.h
     
    228318    }
    229319
     320    if (fDisplay)
     321    {
     322        fDisplay->SetStatusLine1("Processing...");
     323        fDisplay->SetStatusLine2("");
     324    }
     325
    230326    Int_t dummy = maxcnt<0 ? 0 : maxcnt;
    231327
     
    246342    if (maxcnt<0)
    247343        // process first and increment if sucessfull
    248         if (fProgress)
    249             while ((rc=fTaskList->Process())==kTRUE)
    250             {
    251                 fProgress->SetPosition(++dummy);
    252 #if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
    253                 gSystem->ProcessEvents();
    254 #else
    255                 gClient->ProcessEventsFor(fProgress);
    256 #endif
    257                 numcnts++;
    258             }
    259         else
    260             while ((rc=fTaskList->Process())==kTRUE) numcnts++;
     344        while ((rc=fTaskList->Process())==kTRUE)
     345        {
     346            numcnts++;
     347            if (!ProcessGuiEvents(++dummy))
     348                break;
     349        }
    261350    else
    262351        // check for number and break if unsuccessfull
    263         if (fProgress)
    264             while (dummy-- && (rc=fTaskList->Process())==kTRUE)
    265             {
    266                 fProgress->SetPosition(maxcnt - dummy);
     352        while (dummy-- && (rc=fTaskList->Process())==kTRUE)
     353        {
     354            numcnts++;
     355            if (!ProcessGuiEvents(maxcnt - dummy))
     356                break;
     357        }
     358
     359    //
     360    // stop stop-watch, print results
     361    //
     362    clock.Stop();
     363
     364    if (fProgress)
     365    {
     366        fProgress->SetPosition(maxcnt>0 ? TMath::Min(maxcnt, entries) : entries);
    267367#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
    268                 gSystem->ProcessEvents();
     368        gSystem->ProcessEvents();
    269369#else
    270                 gClient->ProcessEventsFor(fProgress);
     370        gClient->ProcessEventsFor(fDisplay ? fDisplay : fProgress);
    271371#endif
    272                 numcnts++;
    273             }
    274         else
    275             while (dummy-- && (rc=fTaskList->Process())==kTRUE) numcnts++;
    276 
    277     //
    278     // stop stop-watch, print results
    279     //
    280     clock.Stop();
     372    }
    281373
    282374    *fLog << all << "Ready!" << endl << endl;
     
    306398    //  execute the post process of all tasks
    307399    //
     400    if (fDisplay)
     401    {
     402        // Set status lines
     403        fDisplay->SetStatusLine1("PostProcessing...");
     404        fDisplay->SetStatusLine2("");
     405    }
    308406    return fTaskList->PostProcess();
    309407}
     
    329427    if (!PostProcess())
    330428        return kFALSE;
     429
     430    if (!fDisplay)
     431        return rc;
     432
     433    // Set status lines
     434    fDisplay->SetStatusLine1(fName);
     435    fDisplay->SetStatusLine2(rc ? "Done." : "ERROR");
     436    // Stop automatic update
     437    fDisplay->StopUpdate();
     438    // Reallow context menus
     439    fDisplay->SetNoContextMenu(kFALSE);
     440    // Reallow user to exit window by File menu
     441    fDisplay->UnLock();
    331442
    332443    //
  • trunk/MagicSoft/Mars/mbase/MEvtLoop.h

    r1880 r1965  
    2727    MTaskList *fTaskList;      //!
    2828
    29     TGProgressBar *fProgress;  //!
     29    TGProgressBar   *fProgress;  //!
    3030
    3131    enum { kIsOwner = BIT(14) };
     
    3535
    3636    void StreamPrimitive(ofstream &out) const;
     37
     38    Bool_t ProcessGuiEvents(Int_t num);
    3739
    3840public:
     
    4446    MTaskList *GetTaskList() const      { return fTaskList; }
    4547
     48    MStatusDisplay *GetDisplay() { return fDisplay; }
     49
    4650    void SetOwner(Bool_t enable=kTRUE);
    4751
     
    5256
    5357    Bool_t PreProcess(const char *tlist="MTaskList");
    54     Bool_t Process(Int_t maxcnt) const;
     58    Bool_t Process(Int_t maxcnt);
    5559    Bool_t PostProcess() const;
    5660
  • trunk/MagicSoft/Mars/mbase/MParContainer.cc

    r1902 r1965  
    3737#include "MParContainer.h"
    3838
    39 #include <ctype.h>       // isdigit
    40 #include <fstream.h>     // ofstream, AsciiWrite
    41 
    42 #include <TEnv.h>        // Env::Lookup
    43 #include <TClass.h>      // IsA
    44 #include <TObjArray.h>   // TObjArray
    45 #include <TBaseClass.h>  // GetClassPointer
    46 #include <TMethodCall.h> // TMethodCall, AsciiWrite
    47 #include <TDataMember.h> // TDataMember, AsciiWrite
    48 #include <TVirtualPad.h> // gPad
     39#include <ctype.h>        // isdigit
     40#include <fstream.h>      // ofstream, AsciiWrite
     41
     42#include <TEnv.h>         // Env::Lookup
     43#include <TClass.h>       // IsA
     44#include <TObjArray.h>    // TObjArray
     45#include <TBaseClass.h>   // GetClassPointer
     46#include <TMethodCall.h>  // TMethodCall, AsciiWrite
     47#include <TDataMember.h>  // TDataMember, AsciiWrite
     48#include <TVirtualPad.h>  // gPad
    4949
    5050#include "MLog.h"
     
    5252
    5353#ifndef __COSY__
    54 #include "MEvtLoop.h"    // gListOfPrimitives
     54#include "MEvtLoop.h"     // gListOfPrimitives
    5555#else
    5656TList *gListOfPrimitives; // forard declaration in MParContainer.h
     
    7171
    7272    fReadyToSave = named.fReadyToSave;
     73
     74    fDisplay = named.fDisplay;
    7375}
    7476
  • trunk/MagicSoft/Mars/mbase/MParContainer.h

    r1902 r1965  
    2626class TDataMember;
    2727class TMethodCall;
     28class MStatusDisplay;
    2829
    2930class MParContainer : public TObject
     
    3435
    3536    MLog   *fLog;         // The general log facility for this object, initialized with the global object
     37
     38    MStatusDisplay *fDisplay;
    3639
    3740private:
     
    4952    };
    5053
    51     MParContainer(const char *name="", const char *title="") : fName(name), fTitle(title), fLog(&gLog), fReadyToSave(kFALSE) {  }
    52     MParContainer(const TString &name, const TString &title) : fName(name), fTitle(title), fLog(&gLog), fReadyToSave(kFALSE) {  }
     54    MParContainer(const char *name="", const char *title="") : fName(name), fTitle(title), fLog(&gLog), fDisplay(NULL), fReadyToSave(kFALSE) {  }
     55    MParContainer(const TString &name, const TString &title) : fName(name), fTitle(title), fLog(&gLog), fDisplay(NULL), fReadyToSave(kFALSE) {  }
    5356    MParContainer(const MParContainer &named);
    5457    MParContainer& operator=(const MParContainer& rhs);
     
    6467    virtual void        FillBuffer(char *&buffer);
    6568
    66     virtual const char   *GetDescriptor() const { return Form("%s [%s]", fName.Data(), ClassName()); }
     69    virtual const char   *GetDescriptor() const { return fName==ClassName() ? ClassName() : Form("%s [%s]", fName.Data(), ClassName()); }
    6770    virtual const TString GetUniqueName() const;
    6871    virtual const char   *GetName() const       { return fName.Data(); }
     
    8790    virtual void   EnableGraphicalOutput(Bool_t flag=kTRUE) { flag ? SetBit(kEnableGraphicalOutput) : ResetBit(kEnableGraphicalOutput);}
    8891    virtual Bool_t IsGraphicalOutputEnabled() const  { return TestBit(kEnableGraphicalOutput); }
     92
     93    virtual void SetDisplay(MStatusDisplay *d) { fDisplay = d; }
    8994
    9095    TMethodCall *GetterMethod(const char *name) const;
  • trunk/MagicSoft/Mars/mbase/MParList.cc

    r1902 r1965  
    138138}
    139139
     140void MParList::SetDisplay(MStatusDisplay *d)
     141{
     142    fContainer->ForEach(MParContainer, SetDisplay)(d);
     143    MParContainer::SetDisplay(d);
     144}
     145
    140146// --------------------------------------------------------------------------
    141147//
     
    149155    //  check if the object (you want to add) exists
    150156    //
    151 
    152157    if (!cont)
    153158        return kFALSE;
  • trunk/MagicSoft/Mars/mbase/MParList.h

    r1880 r1965  
    5050
    5151    void SetLogStream(MLog *log);
     52    void SetDisplay(MStatusDisplay *d);
    5253
    5354    TObject *FindObject(const char *name) const;
  • trunk/MagicSoft/Mars/mbase/MTaskList.cc

    r1935 r1965  
    5757#include "MTaskList.h"
    5858
    59 #include <fstream.h>     // ofstream, SavePrimitive
     59#include <fstream.h>        // ofstream, SavePrimitive
    6060
    6161#include <TClass.h>
     
    7070#include "MInputStreamID.h"
    7171
     72#include "MStatusDisplay.h"
     73
    7274ClassImp(MTaskList);
    7375
     
    133135    fTasks->ForEach(MTask, SetLogStream)(log);
    134136    MParContainer::SetLogStream(log);
     137}
     138
     139void MTaskList::SetDisplay(MStatusDisplay *d)
     140{
     141    fTasks->ForEach(MTask, SetDisplay)(d);
     142    MParContainer::SetDisplay(d);
    135143}
    136144
     
    350358//
    351359Bool_t MTaskList::PreProcess(MParList *pList)
    352 { 
     360{
    353361    *fLog << all << "Preprocessing... " << flush;
    354362
     
    370378    {
    371379        *fLog << all << task->GetName() << "... " << flush;
     380        if (fDisplay)
     381            fDisplay->SetStatusLine2(*task);
    372382
    373383        //
     
    539549    {
    540550        *fLog << all << task->GetName() << "... " << flush;
     551        if (fDisplay)
     552            fDisplay->SetStatusLine2(*task);
    541553
    542554        if (!task->CallPostProcess())
  • trunk/MagicSoft/Mars/mbase/MTaskList.h

    r1935 r1965  
    4444
    4545    void SetLogStream(MLog *log);
     46    void SetDisplay(MStatusDisplay *d);
    4647
    4748    Bool_t AddToListBefore(MTask *task, const MTask *where, const char *tType="All");
Note: See TracChangeset for help on using the changeset viewer.