#ifndef MARS_MEvtLoop
#define MARS_MEvtLoop

/////////////////////////////////////////////////////////////////////////////
//                                                                         //
// MEvtLoop                                                                //
//                                                                         //
// Class to execute the tasks in a tasklist                                //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////

#ifndef MARS_MParContainer
#include "MParContainer.h"
#endif

class MTask;
class MParList;
class MTaskList;
class TGProgressBar;
#ifdef __MARS__
class MProgressBar;
#endif

class MEvtLoop : public MParContainer
{
private:
    MParList  *fParList;
    MTaskList *fTaskList;      //!

    TGProgressBar   *fProgress;  //!

    enum { kIsOwner = BIT(14) };

    Bool_t HasDuplicateNames(const TString txt) const;
    Bool_t HasDuplicateNames(TObjArray &arr, const TString txt) const;

    void StreamPrimitive(ofstream &out) const;

    Bool_t ProcessGuiEvents(Int_t num);

public:
    MEvtLoop(const char *name="Evtloop");
    virtual ~MEvtLoop();

    void       SetParList(MParList *p)  { fParList = p; }
    MParList  *GetParList() const       { return fParList; }
    MTaskList *GetTaskList() const      { return fTaskList; }

    MTask *FindTask(const char *name) const;
    MTask *FindTask(const MTask *obj) const;

    MStatusDisplay *GetDisplay() { return fDisplay; }

    void SetOwner(Bool_t enable=kTRUE);

    void SetProgressBar(TGProgressBar *bar) { fProgress = bar; }
#ifdef __MARS__
    void SetProgressBar(MProgressBar *bar);
#endif

    Bool_t PreProcess(const char *tlist="MTaskList");
    Bool_t Process(Int_t maxcnt);
    Bool_t PostProcess() const;

    Bool_t Eventloop(Int_t maxcnt=-1, const char *tlist="MTaskList");

    void MakeMacro(const char *filename="evtloop.C");

    void SavePrimitive(ofstream &out, Option_t *o="");

    Int_t Read(const char *name="Evtloop");
    Int_t Write(const char *name="Evtloop", Int_t option=0, Int_t bufsize=0);

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

    Bool_t ReadEnv(const TEnv &env, TString prefix="", Bool_t print=kFALSE);
    Bool_t WriteEnv(TEnv &env, TString prefix="", Bool_t print=kFALSE) const;

    ClassDef(MEvtLoop, 1) // Class to execute the tasks in a tasklist
};

R__EXTERN TList *gListOfPrimitives; // instantiation in MEvtLoop

#endif
