Index: trunk/MagicSoft/Mars/mmain/MGCamDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MGCamDisplay.cc	(revision 2501)
+++ trunk/MagicSoft/Mars/mmain/MGCamDisplay.cc	(revision 2501)
@@ -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 "MGCamDisplay.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(MGCamDisplay);
+
+// --------------------------------------------------------------------------
+//
+//  Constructor.
+//
+MGCamDisplay::MGCamDisplay(const char *filename) : MStatusDisplay()
+{
+    //
+    // Setup Task list for hillas calculation
+    //
+    SetupTaskList("Events", filename);
+
+    //
+    // Add MGCamDisplay 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
+//
+MGCamDisplay::~MGCamDisplay()
+{
+    fEvtLoop->PostProcess();
+    delete fEvtLoop;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Return reading task
+//
+MReadTree *MGCamDisplay::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 MGCamDisplay::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 MGCamDisplay::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 MGCamDisplay::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 MGCamDisplay::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 MGCamDisplay::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 MGCamDisplay::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 MGCamDisplay::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 MGCamDisplay::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/MGCamDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mmain/MGCamDisplay.h	(revision 2501)
+++ trunk/MagicSoft/Mars/mmain/MGCamDisplay.h	(revision 2501)
@@ -0,0 +1,41 @@
+#ifndef MARS_MGCamDisplay
+#define MARS_MGCamDisplay
+
+#ifndef MARS_MGEvtDisplay
+#include "MGEvtDisplay.h"
+#endif
+
+class TGListBox;
+
+class MGeomCam;
+class MHCamera;
+
+class MGCamDisplay : public MGEvtDisplay
+{
+private:
+    Bool_t fDisplayRaw;
+    Bool_t fDisplayHillas;
+
+    TGListBox   *fPixelList;
+
+    MHCamera *fDisplay[5];
+    TCanvas  *fCanvas2[5];
+
+    void AddSetupElements();
+    void UpdateDisplay();
+
+    void SetupTaskList();
+
+public:
+    MGCamDisplay(const char *filename,
+                 const TGWindow *p, /*const TGWindow *main,*/
+                 UInt_t w, UInt_t h);
+
+    Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
+
+    ClassDef(MGCamDisplay, 0) // Display for camera images (cerenkov events)
+};
+
+#endif
+
+
Index: trunk/MagicSoft/Mars/mmain/MGDisplayAdc.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MGDisplayAdc.cc	(revision 2501)
+++ trunk/MagicSoft/Mars/mmain/MGDisplayAdc.cc	(revision 2501)
@@ -0,0 +1,461 @@
+/* ======================================================================== *\
+!
+! *
+! * 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  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Harald Kornmayer 1/2001
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+#include "MGDisplayAdc.h"
+
+#include <stdlib.h>              // mkstemp
+#include <iostream>              // cout for debugging
+
+#include <TSystem.h>             // gSystem
+#include <TCanvas.h>             // TCanvas.h
+#include <TGSlider.h>            // TGVSlider
+#include <TGButton.h>            // TGTextButton
+#include <TGMsgBox.h>            // TGMsgBox
+#include <TGListBox.h>           // TGListBox
+#include <TGButtonGroup.h>       // TGVButtonGroup
+#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
+
+#include "MHFadcCam.h"
+
+using namespace std;
+
+enum ComIdentDisplayAdc
+{
+    M_BUTTON_SAVE,
+    M_BUTTON_PRINT,
+    M_BUTTON_PRINTALL,
+    M_BUTTON_CLOSE,
+
+    M_BUTTON_PREV,
+    M_BUTTON_NEXT,
+
+    M_LIST_HISTO,
+    M_RADIO_HI,
+    M_RADIO_LO,
+    M_RADIO_LH,
+    M_BUTTON_RESET,
+    M_VSId1
+};
+
+void MGDisplayAdc::AddFrameTop(TGHorizontalFrame *frame)
+{
+    //
+    // left part of top frame
+    //
+    TGVerticalFrame *left = new TGVerticalFrame(frame, 80, 300, kFitWidth);
+    fList->Add(left);
+
+    fHistoList = new TGListBox (left, M_LIST_HISTO);
+    fHistoList->Associate(this);
+    fHistoList->Resize(100, 405);
+
+    fList->Add(fHistoList);
+
+    TGLayoutHints *laylist = new TGLayoutHints(kLHintsNormal, 10, 10, 10, 10);
+    fList->Add(laylist);
+
+    left->AddFrame(fHistoList, laylist);
+
+    //
+    //    middle part of top frame
+    //
+    TGVerticalFrame *mid = new TGVerticalFrame(frame, 80, 20, kFitWidth);
+    fList->Add(mid);
+
+    // ---
+
+    TGTextButton *prev = new TGTextButton(mid, "Prev Histo", M_BUTTON_PREV);
+    TGTextButton *next = new TGTextButton(mid, "Next Histo", M_BUTTON_NEXT);
+    prev->Associate(this);
+    next->Associate(this);
+
+    fList->Add(prev);
+    fList->Add(next);
+
+    // ---
+
+    fSlider = new TGVSlider(mid, 250, kSlider1|kScaleBoth, M_VSId1);
+    fSlider->Associate(this);
+
+    fList->Add(fSlider);
+
+    // ---
+
+    TGVButtonGroup *group = new TGVButtonGroup(mid);
+    fList->Add(group);
+
+    TGRadioButton *radio1 = new TGRadioButton(group, "&High Gain",     M_RADIO_HI);
+    TGRadioButton *radio2 = new TGRadioButton(group, "&Low Gain",      M_RADIO_LO);
+    TGRadioButton *radio3 = new TGRadioButton(group, "H&igh/Low Gain", M_RADIO_LH);
+
+    /* FIXME:
+
+    ~TGRadioButton calls TGRadioButton::TGFrame::GetMainFrame
+    which calles fParent->GetFrame()
+
+    fList->Add(radio1);
+    fList->Add(radio2);
+    fList->Add(radio3);
+    */
+
+    radio3->SetState(kButtonDown);
+
+    radio1->Associate(this);
+    radio2->Associate(this);
+    radio3->Associate(this);
+
+    // ---
+
+    TGLayoutHints *laybut1 = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10,  0, 10);
+    TGLayoutHints *laybut2 = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 10,  5);
+    TGLayoutHints *layslid = new TGLayoutHints(kLHintsCenterX|kLHintsTop);
+
+    fList->Add(laybut1);
+    fList->Add(laybut2);
+    fList->Add(layslid);
+
+    mid->AddFrame(prev,    laybut1);
+    mid->AddFrame(fSlider, layslid);
+    mid->AddFrame(next,    laybut2);
+    mid->AddFrame(group,   laybut2);
+
+    //
+    //    right part of top frame
+    //
+    TGVerticalFrame *right = new TGVerticalFrame(frame, 100, 100, kFitWidth);
+    fList->Add(right);
+
+    TRootEmbeddedCanvas *canvas = new TRootEmbeddedCanvas("fECanv", right, 100, 100);
+    fList->Add(canvas);
+
+    TGLayoutHints *laycanv = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|kLHintsExpandX|kLHintsExpandY, 10, 10, 10, 10);
+    fList->Add(laycanv);
+
+    right->AddFrame(canvas, laycanv);
+
+
+    TGTextButton *reset = new TGTextButton(right, "Reset histo", M_BUTTON_RESET);
+    reset->Associate(this);
+    fList->Add(reset);
+
+    TGLayoutHints *layreset = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 0, 10);
+    fList->Add(layreset);
+
+    right->AddFrame(reset, layreset);
+
+    // ---
+
+    fCanvas = canvas->GetCanvas();
+
+    //
+    // layout the three subframes
+    //
+    TGLayoutHints *layframe1 = new TGLayoutHints(kLHintsTop, 10, 10, 10, 10);
+    TGLayoutHints *layframe2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|kLHintsExpandX|kLHintsExpandY, 10, 10, 10, 10);
+    fList->Add(layframe1);
+    fList->Add(layframe2);
+
+    frame->AddFrame(left,  layframe1);
+    frame->AddFrame(mid,   layframe1);
+    frame->AddFrame(right, layframe2);
+}
+
+void MGDisplayAdc::AddFrameLow(TGHorizontalFrame *frame)
+{
+    //
+    //   the low frame for the control buttons
+    //
+    TGTextButton *but1 = new TGTextButton(frame, "Save",     M_BUTTON_SAVE);
+    TGTextButton *but2 = new TGTextButton(frame, "Print",    M_BUTTON_PRINT);
+    TGTextButton *but3 = new TGTextButton(frame, "PrintAll", M_BUTTON_PRINTALL);
+    TGTextButton *but4 = new TGTextButton(frame, "Close",    M_BUTTON_CLOSE);
+
+    but1->Associate(this);
+    but2->Associate(this);
+    but3->Associate(this);
+    but4->Associate(this);
+
+    fList->Add(but1);
+    fList->Add(but2);
+    fList->Add(but3);
+    fList->Add(but4);
+
+    TGLayoutHints *laybut = new TGLayoutHints(kLHintsNormal, 10, 10, 5, 5);
+    fList->Add(laybut);
+
+    frame->AddFrame(but1, laybut);
+    frame->AddFrame(but2, laybut);
+    frame->AddFrame(but3, laybut);
+    frame->AddFrame(but4, laybut);
+}
+
+MGDisplayAdc::MGDisplayAdc(MHFadcCam *histos,
+                           const TGWindow *p, const TGWindow *main,
+                           UInt_t w, UInt_t h,
+                           UInt_t options)
+: TGTransientFrame(p?p:gClient->GetRoot(), main?main:gClient->GetRoot(), w, h, options),
+  fHistoType(M_RADIO_LH)
+{
+    fHists = (MHFadcCam*)histos->Clone();
+
+    fList = new TList;
+    fList->SetOwner();
+
+    //
+    // Create the to frames
+    //
+    TGHorizontalFrame *frametop = new TGHorizontalFrame(this, 60, 20, kFitWidth);
+    TGHorizontalFrame *framelow = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
+
+    //
+    // Add frames to 'autodel'
+    //
+    fList->Add(frametop);
+    fList->Add(framelow);
+
+    //
+    // Add the gui elements to the two frames
+    //
+    AddFrameTop(frametop);
+    AddFrameLow(framelow);
+
+    //
+    // layout the two frames in this frame
+    //
+    TGLayoutHints *laytop = new TGLayoutHints(kLHintsTop|kLHintsExpandX,    10, 10, 10, 10);
+    TGLayoutHints *laylow = new TGLayoutHints(kLHintsBottom|kLHintsExpandX, 10, 10, 10, 10);
+
+    AddFrame(frametop, laytop);
+    AddFrame(framelow, laylow);
+
+    //
+    // Setup interieur
+    //
+    BuildHistoList();
+
+    //
+    // Here the initial display is set to entry with id 1
+    //
+    fHistoList->Select(1);
+    UpdateHist();
+
+    //
+    // Setup frame
+    //
+    MapSubwindows();
+
+    Layout();
+
+    SetWindowName("ADC Spectra");
+    SetIconName("ADC Spectra");
+
+    MapWindow();
+    SetWMSizeHints(950, 500, 1000, 1000, 1, 1);
+}  
+
+MGDisplayAdc::~MGDisplayAdc()
+{ 
+    delete fList;
+    delete fHists;
+}  
+
+void MGDisplayAdc::CloseWindow()
+{
+    //
+    // The close message is generated by the window manager when its close
+    // window menu item is selected.
+    //
+    delete this;
+}
+
+Bool_t MGDisplayAdc::BuildHistoList()
+{
+    //
+    //   looks in the container of the AdcSpectra and reads in the
+    //   Histogramms in there.
+    //
+    //   In the class MHFadcCam are in fact two lists. One for the high and
+    //   one for the low gain. Here we will use only the high gain list!!!
+    //   With some special options (settings in the gui) we will also be able
+    //   to plot the low gain
+    //
+    const Int_t nhi = fHists->GetEntries();
+
+    Int_t n=1;
+    for (Int_t i=0; i<nhi; i++)
+        if (fHists->HasHi(i))
+            fHistoList->AddEntry(fHists->GetHistHi(i)->GetName(), n++);
+
+    fSlider->SetRange(1, n);
+
+    fHistoList->MapSubwindows();
+    fHistoList->Layout();
+
+    return kTRUE;
+} 
+
+void MGDisplayAdc::UpdateHist()
+{
+    const Int_t selected = fHistoList->GetSelected();
+
+    if (selected<0)
+    {
+        cout << "MGDisplayAdc: No histograms found in list. " << endl;
+        return;
+    }
+
+    fHistoList->Select(selected); // ???
+
+    fCanvas->Clear();
+
+    const Int_t idx = fHistoList->GetSelectedEntry()->EntryId(); //selected-1;
+
+    if (!fHists->HasHi(idx))
+        return;
+
+    const Int_t type = fHists->HasLo(idx) ? fHistoType : M_RADIO_HI;
+
+    switch (type)
+    {
+    case M_RADIO_HI:
+    case M_RADIO_LO:
+        fCanvas->Divide(1, 1);
+
+        fCanvas->cd();
+        if (type==M_RADIO_HI)
+            fHists->DrawHi(idx);
+        else
+            fHists->DrawLo(idx);
+        break;
+
+    case M_RADIO_LH:
+        fCanvas->Divide(1, 2);
+
+        fCanvas->cd(1);
+        fHists->DrawHi(idx);
+
+        fCanvas->cd(2);
+        fHists->DrawLo(idx);
+        break;
+    }
+
+    fHistoList->SetTopEntry(selected);
+
+    fCanvas->Modified();
+    fCanvas->Update();
+
+    fSlider->SetPosition(selected);
+}
+
+Bool_t MGDisplayAdc::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
+{     
+    //
+    // Process events generated by the buttons in the frame.
+    //
+    switch (GET_MSG(msg))
+    {
+    case kC_COMMAND:
+        switch (GET_SUBMSG(msg))
+        {
+        case kCM_BUTTON:
+            switch (parm1)
+            {
+            case M_BUTTON_SAVE:
+                fCanvas->SaveAs();
+                cout << "Sorry, no well implemented!" << endl;
+                return kTRUE;
+
+            case M_BUTTON_PRINT:
+                {
+                    char *txt = (char*)"canvasXXXXXX";
+                    mkstemp(txt);
+                    TString name = txt;
+                    name += ".ps";
+                    fCanvas->SaveAs(name);
+                    cout << "Calling 'lpr " << name << ".ps'" << endl;
+                    gSystem->Exec(TString("lpr ")+name+".ps");
+                    gSystem->Exec(TString("rm ")+name+".ps");
+                }
+                cout << "Sorry, not well implemented!" << endl;
+                return kTRUE;
+
+            case M_BUTTON_RESET:
+                cout << "Sorry, not yet implemented!" << endl;
+                return kTRUE;
+
+            case M_BUTTON_CLOSE:
+                CloseWindow();
+                return kTRUE;
+
+            case M_BUTTON_PREV:
+            case M_BUTTON_NEXT:
+                {
+                    const Int_t selected = fHistoList->GetSelected();
+
+                    if ((parm1==M_BUTTON_PREV && selected==1) ||
+                        (parm1==M_BUTTON_NEXT && selected==fHistoList->GetNumberOfEntries()))
+                        return kTRUE;
+
+                    fHistoList->Select(parm1==M_BUTTON_PREV ? selected-1 : selected+1);
+                    UpdateHist();
+                }
+                return kTRUE;
+            }
+            return kTRUE;
+
+        case kCM_RADIOBUTTON:
+            switch(parm1)
+            {
+            case M_RADIO_HI:
+            case M_RADIO_LO:
+            case M_RADIO_LH:
+                fHistoType = parm1;
+                UpdateHist();
+                return kTRUE;
+            }
+            return kTRUE;
+        }
+		
+    case kCM_LISTBOX:
+        if (GET_SUBMSG(msg) == M_LIST_HISTO)
+            UpdateHist();
+
+        return kTRUE;
+
+    case kC_VSLIDER:
+        if (GET_SUBMSG(msg)!=kSL_POS || parm1!=M_VSId1)
+            return kTRUE;
+
+        // Check for the slider movement and synchronise with TGListBox
+        if (parm2<1 || parm2>fHistoList->GetNumberOfEntries())
+            return kTRUE;
+
+        fHistoList->Select(parm2);
+        UpdateHist();
+        return kTRUE;
+    }
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mmain/MGDisplayAdc.h
===================================================================
--- trunk/MagicSoft/Mars/mmain/MGDisplayAdc.h	(revision 2501)
+++ trunk/MagicSoft/Mars/mmain/MGDisplayAdc.h	(revision 2501)
@@ -0,0 +1,55 @@
+#ifndef MARS_MGDisplayAdc
+#define MARS_MGDisplayAdc
+
+#ifndef ROOT_TFrame
+#include <TGFrame.h>    // TGTransientFrame
+#endif
+
+class TList;
+class TCanvas;
+
+class MHFadcCam;
+
+class TGVSlider;
+class TGListBox;
+class TGTextButton;
+class TGRadioButton;
+class TRootEmbeddedCanvas;
+
+class MGDisplayAdc : public TGTransientFrame
+{
+private:
+    MHFadcCam *fHists;		// Pointer to Container with the histograms
+
+    TList     *fList;
+    TCanvas   *fCanvas;
+    TGVSlider *fSlider;
+    TGListBox *fHistoList;
+
+    Int_t      fHistoType;
+
+    void AddFrameTop(TGHorizontalFrame *frame);
+    void AddFrameLow(TGHorizontalFrame *frame);
+
+    //
+    // Create a main frame with a number of different buttons.
+    //
+    void   UpdateHist();
+    Bool_t BuildHistoList();
+
+public:
+
+    MGDisplayAdc(MHFadcCam *fHists ,
+                 const TGWindow *p=NULL, const TGWindow *main=NULL,
+                 UInt_t w=800, UInt_t h=500,
+                 UInt_t options = kMainFrame|kVerticalFrame);
+    ~MGDisplayAdc();
+
+    void  CloseWindow();
+
+    Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
+};
+
+#endif
+
+
