Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2478)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2479)
@@ -1,3 +1,17 @@
                                                  -*-*- END OF LINE -*-*-
+
+  2003/11/07: Thomas Bretz
+  
+   * mmain/MCameraDisplay.cc:
+     - changed MGCamDisplay to MEventDisplay
+     
+   * mmain/MMars.cc:
+     - removed 'Event Display' button
+     - removed MEvtDisp
+
+   * mmain/MEventDisplay.[h,cc]:
+     - added
+
+
 
   2003/11/06: Antonio Stamerra
@@ -5,4 +19,5 @@
    * manalysis/MMcTriggerLvl2.cc
      - Removed annoying warning message and put it in the Print method.
+
 
 
Index: /trunk/MagicSoft/Mars/mmain/MCameraDisplay.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MCameraDisplay.cc	(revision 2478)
+++ /trunk/MagicSoft/Mars/mmain/MCameraDisplay.cc	(revision 2479)
@@ -29,5 +29,5 @@
 
 #include "MGList.h"
-#include "MGCamDisplay.h"
+#include "MEventDisplay.h"
 
 ClassImp(MCameraDisplay)
@@ -90,6 +90,5 @@
         {
         case kButDisplay:
-            new MGCamDisplay(fInputFile,
-                             fClient->GetRoot(), /*this,*/ 600, 500);
+            new MEventDisplay(fInputFile);
             return kTRUE;
         }
Index: /trunk/MagicSoft/Mars/mmain/MEventDisplay.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 2479)
+++ /trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 2479)
@@ -0,0 +1,548 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 10/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+#include "MEventDisplay.h"
+
+//
+// C-lib
+//
+#include <stdlib.h>              // atoi
+
+//
+// root
+//
+#include <TList.h>               // TList::Add
+#include <TStyle.h>              // gStyle->SetOptStat
+#include <TCanvas.h>             // TCanvas::cd
+
+//
+// root GUI
+//
+#include <TGLabel.h>             // TGLabel
+#include <TGButton.h>            // TGPictureButton
+#include <TG3DLine.h>            // TGHorizontal3DLine
+#include <TGTextEntry.h>         // TGTextEntry
+#include <TGButtonGroup.h>       // TGVButtonGroup
+#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
+
+//
+// General
+//
+#include "MGList.h"              // MGList
+
+#include "MParList.h"            // MParList::AddToList
+#include "MEvtLoop.h"            // MEvtLoop::GetParList
+#include "MTaskList.h"           // MTaskList::AddToList
+
+//
+// Tasks
+//
+#include "MReadMarsFile.h"       // MReadMarsFile
+#include "MGeomApply.h"          // MGeomApply
+#include "MMcPedestalCopy.h"     // MMcPedestalCopy
+#include "MMcPedestalNSBAdd.h"   // MMcPedestalNSBAdd
+#include "MCerPhotCalc.h"        // MCerPhotCalc
+#include "MImgCleanStd.h"        // MImgCleanStd
+#include "MHillasCalc.h"         // MHillasCalc
+#include "MHillasSrcCalc.h"      // MHillasSrcCalc
+#include "MBlindPixelCalc.h"     // MBlindPixelCalc
+#include "MFillH.h"              // MFillH
+
+//
+// Container
+//
+#include "MHEvent.h"             // MHEvent
+#include "MHCamera.h"            // MHCamera
+
+ClassImp(MEventDisplay);
+
+// --------------------------------------------------------------------------
+//
+//  Constructor.
+//
+MEventDisplay::MEventDisplay(const char *filename) : MStatusDisplay()
+{
+    //
+    // Setup Task list for hillas calculation
+    //
+    SetupTaskList("Events", filename);
+
+    //
+    // Add MEventDisplay GUI elements to the display
+    //
+    AddUserFrame(filename);
+
+    //
+    // Show new part of the window, resize to correct aspect ratio
+    //
+    // FIXME: This should be done by MStatusDisplay automatically
+    Resize(GetWidth(), GetHeight() + fUserFrame->GetDefaultHeight());
+    SetWindowName("Event Display");
+    MapSubwindows();
+
+    //
+    // Readin foirst event and display it
+    //
+    ReadFirstEvent();
+}
+
+// --------------------------------------------------------------------------
+//
+//  Destructor: PostProcess eventloop, delete eventloop with all containers
+//
+MEventDisplay::~MEventDisplay()
+{
+    fEvtLoop->PostProcess();
+    delete fEvtLoop;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Return reading task
+//
+MReadTree *MEventDisplay::GetReader() const
+{
+    MParList  *plist  = (MParList*)fEvtLoop->GetParList();
+    MTaskList *tlist  = (MTaskList*)plist->FindObject("MTaskList");
+    MReadTree *reader = (MReadTree*)tlist->FindObject("MRead");
+    return reader;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Setup Task and parameter list for hillas calculation,
+//  preprocess tasks and read in first event (process)
+//
+void MEventDisplay::SetupTaskList(const char *tname, const char *fname)
+{
+    //
+    // Setup an empty job, with a reader task only.
+    // All tasks and parameter containers are deleted automatically
+    // (via SetOwner())
+    //
+    MTaskList *tlist = new MTaskList;
+    tlist->SetOwner();
+
+    MReadMarsFile *read = new MReadMarsFile(tname, fname);
+    read->DisableAutoScheme();
+    tlist->AddToList(read);
+
+    MGeomApply *apl = new MGeomApply;
+    tlist->AddToList(apl);
+
+    MParList *plist = new MParList;
+    plist->SetOwner();
+    plist->AddToList(tlist);
+
+    fEvtLoop = new MEvtLoop;
+    fEvtLoop->SetOwner();
+    fEvtLoop->SetParList(plist);
+
+    MHEvent *evt1 = new MHEvent(MHEvent::kEvtSignal);
+    MHEvent *evt2 = new MHEvent(MHEvent::kEvtSignal);
+    MHEvent *evt3 = new MHEvent(MHEvent::kEvtPedestal);
+    MHEvent *evt4 = new MHEvent(MHEvent::kEvtPedestalRMS);
+    MHEvent *evt5 = new MHEvent(MHEvent::kEvtRelativeSignal);
+    MHEvent *evt6 = new MHEvent(MHEvent::kEvtCleaningLevels);
+    evt1->SetName("Signal");
+    evt2->SetName("Cleaned");
+    evt3->SetName("Pedestal");
+    evt4->SetName("PedRMS");
+    evt5->SetName("Signal/PedRMS");
+    evt6->SetName("CleanLevels");
+    plist->AddToList(evt1);
+    plist->AddToList(evt2);
+    plist->AddToList(evt3);
+    plist->AddToList(evt4);
+    plist->AddToList(evt5);
+    plist->AddToList(evt6);
+
+    MMcPedestalCopy   *pcopy = new MMcPedestalCopy;
+    MMcPedestalNSBAdd *pdnsb = new MMcPedestalNSBAdd;
+    MCerPhotCalc      *ncalc = new MCerPhotCalc;
+    MFillH            *fill1 = new MFillH(evt1, "MCerPhotEvt",  "MFillH1");
+    MImgCleanStd      *clean = new MImgCleanStd;
+    MFillH            *fill2 = new MFillH(evt2, "MCerPhotEvt",  "MFillH2");
+    MFillH            *fill3 = new MFillH(evt3, "MPedestalCam", "MFillH3");
+    MFillH            *fill4 = new MFillH(evt4, "MPedestalCam", "MFillH4");
+    MFillH            *fill5 = new MFillH(evt5, "MRelSignal",   "MFillH5");
+    MFillH            *fill6 = new MFillH(evt6, "MRelSignal",   "MFillH6");
+    MBlindPixelCalc   *blind = new MBlindPixelCalc;
+    MHillasCalc       *hcalc = new MHillasCalc;
+    MHillasSrcCalc    *scalc = new MHillasSrcCalc;
+
+    tlist->AddToList(pcopy);
+    tlist->AddToList(pdnsb);
+    tlist->AddToList(ncalc);
+    tlist->AddToList(fill1);
+    tlist->AddToList(clean);
+    tlist->AddToList(fill2);
+    tlist->AddToList(fill3);
+    tlist->AddToList(fill4);
+//    tlist->AddToList(fill5);
+//    tlist->AddToList(fill6);
+    tlist->AddToList(blind);
+    tlist->AddToList(hcalc);
+    tlist->AddToList(scalc);
+
+    //
+    // Now distribute Display to all tasks
+    //
+    tlist->SetDisplay(this);
+}
+
+// --------------------------------------------------------------------------
+//
+//  Add the top part of the frame: This is filename and treename display
+//
+void MEventDisplay::AddTopFramePart1(TGCompositeFrame *frame,
+                                    const char *filename,
+                                    const char *treename)
+{
+    //
+    //  --- the top1 part of the window ---
+    //
+    TGHorizontalFrame *top1 = new TGHorizontalFrame(frame, 1, 1);
+    fList->Add(top1);
+
+    //
+    // create gui elements
+    //
+    TGLabel *file = new TGLabel(top1, new TGString(Form("%s#%s", filename, treename)));
+    fList->Add(file);
+
+    //
+    // layout and add gui elements in/to frame
+    //
+    TGLayoutHints *laystd = new TGLayoutHints(kLHintsCenterX, 5, 5);
+    fList->Add(laystd);
+
+    top1->AddFrame(file,  laystd);
+
+    //
+    //  --- the top1 part of the window ---
+    //
+    TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 1, 1);
+    fList->Add(top2);
+
+    //
+    // layout and add frames
+    //
+    TGLayoutHints *laytop1 = new TGLayoutHints(kLHintsCenterX, 5, 5, 5);
+    fList->Add(laytop1);
+    frame->AddFrame(top1, laytop1);
+    frame->AddFrame(top2, laytop1);
+}
+
+// --------------------------------------------------------------------------
+//
+//  Add the second part of the top frame: This are the event number controls
+//
+void MEventDisplay::AddTopFramePart2(TGCompositeFrame *frame)
+{
+    //
+    // --- the top2 part of the window ---
+    //
+    TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 1, 1);
+    fList->Add(top2);
+
+    //
+    // Create the gui elements
+    //
+    TGTextButton *prevevt = new TGTextButton(top2, "<< Previous Event", kEvtPrev);
+    prevevt->Associate(this);
+
+    TGLabel *evtnr = new TGLabel(top2, new TGString("Event: "));
+
+    TGTextEntry *entry=new TGTextEntry(top2, new TGTextBuffer(100), kEvtNumber);
+    entry->Resize(60, entry->GetDefaultHeight());
+    entry->Associate(this);
+
+    fNumOfEvts = new TGLabel(top2, "out of           Events.");
+
+    TGTextButton *nextevt = new TGTextButton (top2, "Next Event >>", kEvtNext);
+    nextevt->Associate(this);
+
+    //
+    // Add gui elements to 'atotodel'
+    //
+    fList->Add(prevevt);
+    fList->Add(evtnr);
+    fList->Add(entry);
+    fList->Add(fNumOfEvts);
+    fList->Add(nextevt);
+
+    //
+    // add the gui elements to the frame
+    //
+    TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 5, 5);
+    fList->Add(laystd);
+
+    top2->AddFrame(prevevt,    laystd);
+    top2->AddFrame(evtnr,      laystd);
+    top2->AddFrame(entry,      laystd);
+    top2->AddFrame(fNumOfEvts, laystd);
+    top2->AddFrame(nextevt,    laystd);
+
+    TGLayoutHints *laystd2 = new TGLayoutHints(kLHintsCenterX, 5, 5, 5, 5);
+    fList->Add(laystd2);
+    frame->AddFrame(top2, laystd2);
+
+    //
+    // Add trailing line...
+    //
+    TGHorizontal3DLine *line = new TGHorizontal3DLine(frame);
+    TGLayoutHints *layline = new TGLayoutHints(kLHintsExpandX);
+    fList->Add(line);
+    fList->Add(layline);
+    frame->AddFrame(line, layline);
+}
+
+// --------------------------------------------------------------------------
+//
+//  Add the user frame part of the display
+//
+void MEventDisplay::AddUserFrame(const char* filename)
+{
+    fUserFrame->ChangeOptions(kHorizontalFrame);
+
+    TGCompositeFrame *vf1 = new TGVerticalFrame(fUserFrame, 1, 1);
+    TGCompositeFrame *vf2 = new TGVerticalFrame(fUserFrame, 1, 1);
+
+    AddTopFramePart1(vf1, filename, "Events");
+    AddTopFramePart2(vf1);
+
+    // create root embedded canvas and add it to the tab
+    TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas("Slices", vf2, vf1->GetDefaultHeight()*3/2, vf1->GetDefaultHeight(), 0);
+    vf2->AddFrame(ec);
+    fList->Add(ec);
+
+    // set background and border mode of the canvas
+    fCanvas = ec->GetCanvas();
+    fCanvas->SetBorderMode(0);
+    gROOT->GetListOfCanvases()->Add(fCanvas);
+    //fCanvas->SetBorderSize(1);
+    //fCanvas->SetBit(kNoContextMenu);
+    //fCanvas->SetFillColor(16);
+
+    TGLayoutHints *lay = new TGLayoutHints(kLHintsExpandX);
+    fUserFrame->AddFrame(vf1, lay);
+    fUserFrame->AddFrame(vf2);
+}
+
+// --------------------------------------------------------------------------
+//
+//  Checks if the event number is valid, and if so reads the new event
+//  and updates the display
+//
+void MEventDisplay::ReadinEvent(Int_t dir)
+{
+    MParList    *plist = (MParList*)fEvtLoop->GetParList();
+    MTaskList   *tlist = (MTaskList*)plist->FindObject("MTaskList");
+    MRawEvtData *raw = (MRawEvtData*)plist->FindObject("MRawEvtData");
+    if (!raw)
+        return;
+
+    //
+    // Read first event.
+    //
+    MReadTree *reader = GetReader();
+
+    const Int_t num = reader->GetNumEntry();
+
+    do
+    {
+        if (dir<0 && !reader->DecEventNum())
+        {
+            reader->SetEventNum(num);
+            return;
+        }
+        if (dir>0 && !reader->IncEventNum())
+        {
+            reader->SetEventNum(num);
+            return;
+        }
+
+        if (!tlist->Process())
+            return;
+
+        reader->DecEventNum();
+
+    } while (raw->GetNumPixels()<1 && dir!=0);
+
+    //
+    // Cleare the 'FADC canvas'
+    //
+    fCanvas->Clear();
+    fCanvas->Modified();
+    fCanvas->Update();
+
+    //
+    // Print parameters
+    //
+    plist->FindObject("MHillas")->Print();
+    plist->FindObject("MHillasExt")->Print();
+    plist->FindObject("MHillasSrc")->Print();
+    plist->FindObject("MNewImagePar")->Print();
+
+    //
+    // UpdateDisplay
+    //
+    gStyle->SetOptStat(1101);
+    Update();
+
+    TGTextEntry *entry = (TGTextEntry*)fList->FindWidget(kEvtNumber);
+    entry->SetText(Form("%d", reader->GetNumEntry()+1));
+}
+
+// --------------------------------------------------------------------------
+//
+//  Read first event to get display booted
+//
+void MEventDisplay::ReadFirstEvent()
+{
+    if (!fEvtLoop->PreProcess())
+        return;
+
+    //
+    // Get parlist
+    //
+    MParList *plist = (MParList*)fEvtLoop->GetParList();
+
+    //
+    // Add Geometry tab
+    //
+    MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
+
+    TCanvas &c=AddTab("Geometry");
+
+    MHCamera *cam = new MHCamera(*geom);
+    cam->SetBit(TH1::kNoStats);
+    cam->Draw();
+    cam->DrawPixelIndices();
+    fList->Add(cam);
+
+    c.Modified();
+    c.Update();
+
+    //
+    // Now read event...
+    //
+    ReadinEvent();
+
+    TGString *txt = new TGString(Form("out of %d Events", GetReader()->GetEntries()));
+    fNumOfEvts->SetText(txt);
+
+    //
+    // Set name for 'FADC canvas'. The name is the anchor for MHCamera.
+    // and clear the canvas
+    //
+    MHEvent *o = (MHEvent*)plist->FindObject("Signal");
+    fCanvas->SetName(Form("%p;%p;PixelContent", o->GetHist(),
+                          GetCanvas(1)->GetPad(1)->GetPad(1)));
+
+    //
+    // Draw ellipse on top of all pads
+    //
+    TObject *hillas = plist->FindObject("MHillas");
+    for (int i=1; i<5;i++)
+    {
+        TCanvas *c = GetCanvas(i);
+        c->GetPad(1)->cd(1);
+        hillas->Draw();
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+//  Adds the geometry tab 
+//
+void MEventDisplay::AddGeometryTab()
+{
+    MGeomCam *geom = (MGeomCam*)fEvtLoop->GetParList()->FindObject("MGeomCam");
+    if (!geom)
+        return;
+
+    TCanvas &c=AddTab("Geometry");
+
+    MHCamera *cam = new MHCamera(*geom);
+    cam->SetBit(TH1::kNoStats);
+    cam->Draw();
+    cam->DrawPixelIndices();
+    fList->Add(cam);
+
+    c.Modified();
+    c.Update();
+}
+
+// --------------------------------------------------------------------------
+//
+//  ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
+//
+// Processes information from all GUI items.
+// Selecting an item usually generates an event with 4 parameters.
+// The first two are packed into msg (first and second bytes).
+// The other two are parm1 and parm2.
+//
+Bool_t MEventDisplay::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
+{
+    switch (GET_MSG(msg))
+    {
+    case kC_TEXTENTRY:
+        switch(GET_SUBMSG(msg))
+        {
+        case kTE_ENTER:
+            switch(GET_SUBMSG(msg))
+            {
+            case kTE_ENTER:
+                {
+                    TGTextEntry *entry = (TGTextEntry*)fList->FindWidget(kEvtNumber);
+                    if (GetReader()->SetEventNum(atoi(entry->GetText())-1))
+                        ReadinEvent();
+                }
+                return kTRUE;
+            }
+            return kTRUE;
+        }
+        break;
+
+    case kC_COMMAND:
+        switch (GET_SUBMSG(msg))
+        {
+        case kCM_BUTTON:
+            switch (parm1)
+            {
+            case kEvtPrev:
+                ReadinEvent(-1);
+                return kTRUE;
+
+            case kEvtNext:
+                ReadinEvent(+1);
+                return kTRUE;
+            }
+            return kTRUE;
+        }
+        break;
+    }
+    return MStatusDisplay::ProcessMessage(msg, parm1, parm2);
+}
Index: /trunk/MagicSoft/Mars/mmain/MEventDisplay.h
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MEventDisplay.h	(revision 2479)
+++ /trunk/MagicSoft/Mars/mmain/MEventDisplay.h	(revision 2479)
@@ -0,0 +1,58 @@
+#ifndef MARS_MEventDisplay
+#define MARS_MEventDisplay
+
+#ifndef MARS_MStatusDisplay
+#include "MStatusDisplay.h"
+#endif
+
+class TGLabel;
+class TGTextEntry;
+class MEvtLoop;
+
+class MParList;
+class MTaskList;
+class MReadTree;
+
+class MEventDisplay : public MStatusDisplay
+{
+private:
+    enum
+    {
+        kEvtPrev = MStatusDisplay::kSearch + 1,
+        kEvtNext,
+        kEvtNumber
+    };
+
+    TGCompositeFrame *fTab1;
+    TGCompositeFrame *fTab2;
+
+    TGLabel  *fNumOfEvts;
+    TCanvas  *fCanvas;
+    MEvtLoop *fEvtLoop;
+
+    void AddTopFramePart1(TGCompositeFrame *frame,
+                          const char *filename, const char *treename);
+    void AddTopFramePart2(TGCompositeFrame *frame);
+    void AddGeometryTab();
+    void AddUserFrame(const char *filename);
+
+    void UpdateDisplay();
+    void SetupTaskList(const char *tname, const char *fname);
+
+    void ReadFirstEvent();
+    void ReadinEvent(Int_t dir=0);
+
+    MReadTree *GetReader() const;
+
+    Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
+
+public:
+    MEventDisplay(const char *filename);
+    ~MEventDisplay();
+
+    ClassDef(MEventDisplay, 0) // Display for camera images (cerenkov events)
+};
+
+#endif
+
+
Index: /trunk/MagicSoft/Mars/mmain/MMars.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MMars.cc	(revision 2478)
+++ /trunk/MagicSoft/Mars/mmain/MMars.cc	(revision 2479)
@@ -55,5 +55,5 @@
     kPicMars,
 
-    kButEvtDisplay,
+    //kButEvtDisplay,
     kButDataCheck,
     kButAnalysis,
@@ -170,6 +170,6 @@
     fList->Add(tab);
 
-    CreateTextButton(tab, "Event Display",  "Histograms: Pix per Event",
-                     kButEvtDisplay);
+//    CreateTextButton(tab, "Event Display",  "Histograms: Pix per Event",
+//                     kButEvtDisplay);
     CreateTextButton(tab, "Data Check",     "Histograms: Pix per Run",
                      kButDataCheck);
@@ -277,9 +277,9 @@
             switch (parm1)
             {
-
+/*
             case kButEvtDisplay:
-                new MEvtDisp(/*this*/);
-                return kTRUE;
-
+                new MEvtDisp();
+                return kTRUE;
+*/
             case kButDataCheck:
                 new MDataCheck(/*this*/);
Index: /trunk/MagicSoft/Mars/mmain/MainLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MainLinkDef.h	(revision 2478)
+++ /trunk/MagicSoft/Mars/mmain/MainLinkDef.h	(revision 2479)
@@ -8,5 +8,5 @@
 
 #pragma link C++ class MMars+;
-#pragma link C++ class MEvtDisp+;
+//#pragma link C++ class MEvtDisp+;
 #pragma link C++ class MAnalysis+;
 //#pragma link C++ class MTextEntry+;
@@ -16,4 +16,5 @@
 #pragma link C++ class MProgressBar+;
 #pragma link C++ class MCameraDisplay+;
+#pragma link C++ class MEventDisplay+;
 #pragma link C++ class MStatusDisplay+;
 
