Changeset 2052


Ignore:
Timestamp:
05/02/03 08:56:31 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r2049 r2052  
    11                                                 -*-*- END OF LINE -*-*-
     2
     3 2003/05/02: Thomas Bretz
     4 
     5   * manalysis/MCerPhotEvt.[h,cc:
     6     - added RemoveUnusedPixels
     7     
     8   * manalysis/MSigmabar.cc:
     9     - small simplification for compiler optimization
     10     
     11   * mbase/MEvtLoop.cc:
     12     - changed output to fDisplay
     13     - changed behaviour in case of a failed PostProcess
     14     
     15   * mbase/MLog.[h,cc]:
     16     - added flushing and tab conversion to GUI
     17     
     18   * mbase/MParList.cc:
     19     - replaced some *Iter by MIter
     20
     21   * mbase/MTask.cc, mbase/MTaskList.cc:
     22     - added output to fDisplay
     23     - replaced some *Iter by MIter
     24     
     25   * mhist/MH.cc:
     26     - don't add clones to directory
     27     
     28   * mimage/MImgCleanStd.[h,cc]:
     29     - replaced divisiond by multiplications
     30     - fixed StreamePrimitive
     31     - do not allow 0 rings
     32     
     33   * mmain/MStatusDisplay.[h,cc]:
     34     - added writing gif
     35     - added writing C
     36     - changes SaveAs to non-const (added output to status lines)
     37
    238
    339
  • trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc

    r1965 r2052  
    351351}
    352352
    353 /*
    354 // --------------------------------------------------------------------------
    355 //
    356 // Use this function to sum photons in events together.
    357 //
    358 Bool_t MCerPhotEvt::AddEvent(const MCerPhotEvt &evt)
    359 {
    360     if (evt.fNumPixels<=0)
    361     {
    362         *fLog << "Warning - Event to be added has no pixels." << endl;
    363         return kFALSE;
    364     }
    365     if (fNumPixels<=0)
    366     {
    367         *fLog << "Warning - Event to add pixels to has no pixels." << endl;
    368         return kFALSE;
    369     }
    370 
    371     for (UInt_t i=0; i<evt.fNumPixels; i++)
    372     {
    373         const UInt_t id = evt[i].GetPixId();
    374 
    375         MCerPhotPix *pix2 = GetPixById(id);
    376         if (!pix2)
    377         {
    378             *fLog << "Error - Pixel#" << dec << id << " does not exist in this event!" << endl;
    379             return kFALSE;
    380         }
    381 
    382         pix2->AddNumPhotons(evt[i].GetNumPhotons());
    383     }
    384     return kTRUE;
    385 }
    386 */
    387 
    388353void MCerPhotEvt::Scale(Double_t f)
    389354{
    390355    fPixels->ForEach(MCerPhotPix, Scale)(f);
    391356}
     357
     358void MCerPhotEvt::RemoveUnusedPixels()
     359{
     360    TIter Next(fPixels);
     361    MCerPhotPix *pix = NULL;
     362
     363    while ((pix=(MCerPhotPix*)Next()))
     364        if (!pix->IsPixelUsed())
     365            fPixels->Remove(pix);
     366
     367    fPixels->Compress();
     368    fNumPixels=fPixels->GetEntriesFast();
     369}
  • trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h

    r1965 r2052  
    4949
    5050    void Scale(Double_t f);
     51    void RemoveUnusedPixels();
    5152
    5253    MCerPhotPix *GetPixById(int id) const;
  • trunk/MagicSoft/Mars/manalysis/MSigmabar.cc

    r1961 r2052  
    172172    fSigmabarInner = 0;
    173173    fSigmabarOuter = 0;
    174     for (UInt_t i=0; i<6; i++) {
     174    for (UInt_t i=0; i<6; i++)
     175    {
    175176        fSigmabarInner += innerSquaredSum[i];
    176177        fInnerPixels   += innerPixels[i];
     
    187188    if (fOuterPixels > 0) fSigmabarOuter /= fOuterPixels;
    188189
    189   //
    190   // this is the sqrt of the average sigma^2
    191   // for the inner and outer pixels respectively
    192   //
    193   fSigmabarInner = sqrt( fSigmabarInner );
    194   fSigmabarOuter = sqrt( fSigmabarOuter );
    195 
    196   for (UInt_t i=0; i<6; i++) {
    197       fSigmabarSector[i] = innerPixels[i]+outerPixels[i]<=0?0:sqrt((innerSquaredSum[i]+outerSquaredSum[i])/(innerPixels[i]+outerPixels[i]));
    198 
    199       const Double_t is = innerPixels[i]<=0?0:innerSquaredSum[i]/innerPixels[i];
    200       const Double_t os = outerPixels[i]<=0?0:outerSquaredSum[i]/outerPixels[i];
    201 
    202       fSigmabarInnerSector[i] = sqrt( is );
    203       fSigmabarOuterSector[i] = sqrt( os );
    204   }
    205    
     190    //
     191    // this is the sqrt of the average sigma^2
     192    // for the inner and outer pixels respectively
     193    //
     194    fSigmabarInner = sqrt( fSigmabarInner );
     195    fSigmabarOuter = sqrt( fSigmabarOuter );
     196
     197    for (UInt_t i=0; i<6; i++)
     198    {
     199        const Double_t ip  = innerPixels[i];
     200        const Double_t op  = outerPixels[i];
     201        const Double_t iss = innerSquaredSum[i];
     202        const Double_t oss = outerSquaredSum[i];
     203
     204        const Double_t sum = ip + op;
     205
     206        fSigmabarSector[i]      = sum<=0 ? 0 : sqrt((iss+oss)/sum);
     207        fSigmabarInnerSector[i] = ip <=0 ? 0 : sqrt(iss/ip);
     208        fSigmabarOuterSector[i] = op <=0 ? 0 : sqrt(oss/op);
     209    }
     210
    206211  return fSigmabar;
    207212}
     
    237242
    238243}
    239 
    240 
    241 
    242 
    243 
    244 
  • trunk/MagicSoft/Mars/mbase/MEvtLoop.cc

    r2042 r2052  
    190190        fDisplay->SetWindowName(TString("Status Display: ")+fName);
    191191        fDisplay->SetIconName(fName);
    192         // Set status lines
    193         fDisplay->SetStatusLine1("PreProcessing...");
    194         fDisplay->SetStatusLine2("");
    195192        // Start automatic update
    196193        fDisplay->StartUpdate();
     
    207204    if (!fTaskList->PreProcess(fParList))
    208205    {
    209         *fLog << err << "Error detected while PreProcessing" << endl;
     206        *fLog << err << "Error detected while PreProcessing." << endl;
    210207        return kFALSE;
    211208    }
     
    422419    //  execute the post process of all tasks
    423420    //
    424     if (fDisplay)
    425     {
    426         // Set status lines
    427         fDisplay->SetStatusLine1("PostProcessing...");
    428         fDisplay->SetStatusLine2("");
    429     }
    430421    return fTaskList->PostProcess();
    431422}
     
    433424// --------------------------------------------------------------------------
    434425//
    435 //  See class description above.
     426// See class description above. Returns kTRUE if PreProcessing,
     427// Processing and PostProcessing was successfull, otherwise kFALSE.
    436428//
    437429Bool_t MEvtLoop::Eventloop(Int_t maxcnt, const char *tlist)
     
    446438
    447439    //
    448     // Now postprocess all tasks. Only successfully preprocessed tasks are
    449     // postprocessed. If the Postprocessing of one task fail return an error.
     440    // Now postprocess all tasks. Only successfully preprocessed tasks
     441    // are postprocessed. If the Postprocessing of one task fails
     442    // return an error.
    450443    //
    451444    if (!PostProcess())
    452         return kFALSE;
     445    {
     446        *fLog << err << "Error detected while PostProcessing." << endl;
     447        rc = kFALSE;
     448    }
    453449
    454450    if (!fDisplay)
     
    457453    // Set status lines
    458454    fDisplay->SetStatusLine1(fName);
    459     fDisplay->SetStatusLine2(rc ? "Done." : "ERROR");
     455    fDisplay->SetStatusLine2(rc ? "Done." : "Error!");
    460456    // Stop automatic update
    461457    fDisplay->StopUpdate();
  • trunk/MagicSoft/Mars/mbase/MLog.cc

    r1895 r2052  
    175175MLog::MLog(MLog &log)
    176176{
    177     fOutputLevel  = log.fOutputLevel;
    178     fDebugLevel   = log.fDebugLevel;
    179     fDevice       = log.fDevice;
     177    fOutputLevel = log.fOutputLevel;
     178    fDebugLevel  = log.fDebugLevel;
     179    fDevice      = log.fDevice;
    180180}
    181181
     
    208208    if (fDevice&eGui && fgui)
    209209    {
    210         char **newstr = new char*[fNumLines+1];
    211 
    212         for (int i=0; i<fNumLines; i++)
    213             newstr[i] = fGuiLines[i];
    214 
    215         if (fNumLines>0)
    216             delete fGuiLines;
    217 
    218         char *dummy = new char[len];
    219         memcpy(dummy, fBase, len-1);
    220         dummy[len-1]='\0';
    221 
    222         newstr[fNumLines++] = dummy;
    223 
    224         fGuiLines = newstr;
     210        // check whether the current text was flushed or endl'ed
     211        const Bool_t flushed = fBase[len-1]!='\n';
     212
     213        // for the gui remove trailing characters ('\n' or '\0')
     214        fBase[len-1]='\0';
     215
     216        // add new text to line storage
     217        fGuiLine += fBase;
     218
     219        if (!flushed)
     220        {
     221            // add a new TString* to the array of gui lines
     222            TString **newstr = new TString*[fNumLines+1];
     223            memcpy(newstr, fGuiLines, fNumLines*sizeof(TString*));
     224            if (fNumLines>0)
     225                delete fGuiLines;
     226            fGuiLines = newstr;
     227
     228            // add Gui line as last line of array
     229            fGuiLines[fNumLines++] = new TString(fGuiLine);
     230            fGuiLine = "";
     231        }
    225232    }
    226233}
     
    231238        return;
    232239
     240    // lock mutex
    233241    Lock();
    234242
     243    // copy lines to TGListBox
    235244    for (int i=0; i<fNumLines; i++)
    236245    {
    237         fgui->AddEntry(fGuiLines[i], fGuiLineId++);
     246        // Replace all tabs by 7 white spaces
     247        fGuiLines[i]->ReplaceAll("\t", "       ");
     248        fgui->AddEntry(*fGuiLines[i], fGuiLineId++);
    238249        delete fGuiLines[i];
    239250    }
    240 
    241251    delete fGuiLines;
    242252
    243253    fNumLines=0;
    244254
     255    // cut list box top 1000 lines
    245256    fgui->RemoveEntries(0, fGuiLineId-1000);
     257    // show last entry
    246258    fgui->SetTopEntry(fGuiLineId-1);
     259    // tell a main loop, that list box contents have changed
    247260    fgui->SetBit(kHasChanged);
    248261
     262    // release mutex
    249263    UnLock();
    250264}
  • trunk/MagicSoft/Mars/mbase/MLog.h

    r1895 r2052  
    44#ifndef ROOT_TObject
    55#include <TObject.h>
     6#endif
     7#ifndef ROOT_TString
     8#include <TString.h>
    69#endif
    710
     
    2326
    2427private:
    25     char        fBuffer;     //!
    26     char        fBase[bsz]; //! Buffer to store the data in
    27     char       *fPPtr;       //! Pointer to present position in buffer
    28     const char *fEPtr;       //! Pointer to end of buffer
     28    char        fBuffer;      //!
     29    char        fBase[bsz+1]; //! Buffer to store the data in
     30    char       *fPPtr;        //! Pointer to present position in buffer
     31    const char *fEPtr;        //! Pointer to end of buffer
    2932
    30     UInt_t fOutputLevel;     //! Present output level of the stream
    31     UInt_t fDebugLevel;      //! Present global debug level
    32     UInt_t fDevice;          //! Flag to indicate the present streams
     33    UInt_t fOutputLevel;      //! Present output level of the stream
     34    UInt_t fDebugLevel;       //! Present global debug level
     35    UInt_t fDevice;           //! Flag to indicate the present streams
    3336
    34     Bool_t fIsNull;          //! Switch output completely off
     37    Bool_t fIsNull;           //! Switch output completely off
    3538
    36     Int_t fGuiLineId;
     39    Int_t fGuiLineId;         //!
    3740
    3841    ofstream  *fout;          //! possible file output stream
     
    4043    TGListBox *fgui;          //! Listbox output
    4144
    42     Bool_t fIsDirectGui;      //! Pipe text directly to the GUI (for single threaded environments)
    43     char   **fGuiLines;      //! Lines to pipe to gui
    44     Int_t     fNumLines;
     45    Bool_t     fIsDirectGui;  //! Pipe text directly to the GUI (for single threaded environments)
     46    TString  **fGuiLines;     //! Lines to pipe to gui
     47    Int_t      fNumLines;     //!
     48//    Bool_t     fGuiLineFlushed;
     49    TString    fGuiLine;  //!
    4550
    4651#ifdef _REENTRANT
  • trunk/MagicSoft/Mars/mbase/MParList.cc

    r1965 r2052  
    222222        return;
    223223
    224     TObjArrayIter Next(list);
     224    MIter Next(list);
    225225
    226226    MParContainer *cont = NULL;
    227     while ((cont=(MParContainer*)Next()))
     227    while ((cont=Next()))
    228228        AddToList(cont);
    229229}
     
    505505    *fLog << all << " " << GetDescriptor() << endl;
    506506    *fLog << setfill('-') << setw(strlen(GetDescriptor())+2) << "" << endl;
     507
    507508    MParContainer *obj = NULL;
    508     TIter Next(fContainer);
    509     while ((obj=(MParContainer*)Next()))
     509    MIter Next(fContainer);
     510    while ((obj=Next()))
    510511    {
    511512        *fLog << " " << obj->GetDescriptor();
     
    802803    MParContainer *cont = NULL;
    803804
    804     TIter Next(fContainer);
    805     while ((cont=(MParContainer*)Next()))
     805    MIter Next(fContainer);
     806    while ((cont=Next()))
    806807    {
    807808        if (cont->InheritsFrom("MTaskList"))
     
    878879    MParContainer *cont = NULL;
    879880
    880     TIter Next(fContainer);
    881     while ((cont=(MParContainer*)Next()))
     881    MIter Next(fContainer);
     882    while ((cont=Next()))
    882883        if (!cont->WriteEnv(env, prefix, print))
    883884            return kFALSE;
  • trunk/MagicSoft/Mars/mbase/MTask.cc

    r2015 r2052  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz <mailto:tbretz@uni-sw.gwdg.de>, 12/2000
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2001
     18!   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
     19!
     20!   Copyright: MAGIC Software Development, 2000-2003
    2121!
    2222!
     
    7676#include "MFilter.h"
    7777#include "MGGroupFrame.h"
     78#include "MStatusDisplay.h"
    7879
    7980ClassImp(MTask);
     
    166167    fNumExecutions = 0;
    167168
     169    *fLog << all << fName << "... " << flush;
     170    if (fDisplay)
     171        fDisplay->SetStatusLine2(*this);
     172
    168173    switch (PreProcess(plist))
    169174    {
     
    220225
    221226    fIsPreprocessed = kFALSE;
     227
     228    *fLog << all << fName << "... " << flush;
     229    if (fDisplay)
     230        fDisplay->SetStatusLine2(*this);
    222231
    223232    return PostProcess();
  • trunk/MagicSoft/Mars/mbase/MTaskList.cc

    r2015 r2052  
    6565#include "MLogManip.h"
    6666
     67#include "MIter.h"
    6768#include "MFilter.h"
    6869#include "MParList.h"
     
    288289    MTask *task=NULL;
    289290    //
    290     // loop over all tasks for preproccesing
     291    // loop over all tasks for reinitialization
    291292    //
    292293    while ((task=(MTask*)Next()))
     
    330331{
    331332    *fLog << all << "Preprocessing... " << flush;
     333    if (fDisplay)
     334    {
     335        // Set status lines
     336        fDisplay->SetStatusLine1("PreProcessing...");
     337        fDisplay->SetStatusLine2("");
     338    }
    332339
    333340    fParList = pList;
     
    347354    while ((task=(MTask*)Next()))
    348355    {
    349         *fLog << all << task->GetName() << "... " << flush;
    350         if (fDisplay)
    351             fDisplay->SetStatusLine2(*task);
    352 
    353356        //
    354357        // PreProcess the task and check for it's return value.
     
    494497{
    495498    *fLog << all << "Postprocessing... " << flush;
     499    if (fDisplay)
     500    {
     501        // Set status lines
     502        fDisplay->SetStatusLine1("PostProcessing...");
     503        fDisplay->SetStatusLine2("");
     504    }
    496505
    497506    //
     
    518527    while ( (task=(MTask*)Next()) )
    519528    {
    520         *fLog << all << task->GetName() << "... " << flush;
    521         if (fDisplay)
    522             fDisplay->SetStatusLine2(*task);
    523 
    524529        if (!task->CallPostProcess())
    525530            return kFALSE;
     
    602607    out << ";" << endl << endl;
    603608
    604     TIter Next(fTasks);
     609    MIter Next(fTasks);
    605610
    606611    MParContainer *cont = NULL;
    607     while ((cont=(MParContainer*)Next()))
     612    while ((cont=Next()))
    608613    {
    609614        cont->SavePrimitive(out, "");
     
    654659    MParContainer *cont = NULL;
    655660
    656     TIter Next(fTasks);
    657     while ((cont=(MParContainer*)Next()))
     661    MIter Next(fTasks);
     662    while ((cont=Next()))
    658663    {
    659664        if (cont->InheritsFrom("MTaskList"))
     
    730735    MParContainer *cont = NULL;
    731736
    732     TIter Next(fTasks);
    733     while ((cont=(MParContainer*)Next()))
     737    MIter Next(fTasks);
     738    while ((cont=Next()))
    734739        if (!cont->WriteEnv(env, prefix, print))
    735740            return kFALSE;
  • trunk/MagicSoft/Mars/mhist/MH.cc

    r2043 r2052  
    763763    gROOT->SetSelectedPad(NULL);
    764764
     765    Bool_t store = TH1::AddDirectoryStatus();
     766    TH1::AddDirectory(kFALSE);
     767
    765768    TObject *o = MParContainer::DrawClone(opt);
    766769    o->SetBit(kCanDelete);
     770
     771    TH1::AddDirectory(store);
     772
    767773    return o;
    768774}
     
    787793    //
    788794    if (cls->GetMethodAny("Draw"))
    789     {
    790         *fLog << all << "FOUND: " << cls->GetName() << " " << (cls->GetName()=="MH") << endl;
    791795        return kTRUE;
    792     }
    793796
    794797    //
  • trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc

    r2040 r2052  
    285285//
    286286MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
    287                      const char *name, const char *title)
     287                           const char *name, const char *title)
    288288    : fSgb(NULL), fCleaningMethod(kStandard), fCleanLvl1(lvl1),
    289289    fCleanLvl2(lvl2), fCleanRings(1)
     
    324324        MCerPhotPix &pix = (*fEvt)[i];
    325325
    326         const Float_t entry = pix.GetNumPhotons();
    327         const Float_t noise = pix.GetErrorPhot();
    328 
    329326        const Int_t id = pix.GetPixId();
     327
     328        const Float_t  entry = pix.GetNumPhotons();
     329        const Float_t  noise = pix.GetErrorPhot();
    330330        const Double_t ratio = TMath::Sqrt(fCam->GetPixRatio(id));
    331331
    332332        // COBB: '<=' to skip entry=noise=0
    333         if (entry <= fCleanLvl1 * noise / ratio)
     333        if (entry * ratio <= fCleanLvl1 * noise)
    334334            pix.SetPixelUnused();
    335335
     
    366366        MCerPhotPix &pix = (*fEvt)[i];
    367367
    368         const Float_t entry = pix.GetNumPhotons();
    369 
    370368        const Int_t id = pix.GetPixId();
    371369
     370        const Float_t  entry = pix.GetNumPhotons();
    372371        const Double_t ratio = fCam->GetPixRatio(id);
    373372
    374373        // COBB: '<=' to skip entry=noise=0
    375         if (entry <= fCleanLvl1 * fInnerNoise / ratio)
     374        if (entry * ratio <= fCleanLvl1 * fInnerNoise)
    376375            pix.SetPixelUnused();
    377376
     
    451450            const Int_t id2 = gpix.GetNeighbor(j);
    452451
    453             // when you find an used  neighbor, break the loop
     452            // when you find an used neighbor, break the loop
    454453            if (ispixused[id2] == 1)
    455454            {
    456                 hasNeighbor = kTRUE ;
     455                hasNeighbor = kTRUE;
    457456                break;
    458457            }
     
    460459       
    461460        if (hasNeighbor == kFALSE)
    462           pix.SetPixelUnused();
     461            pix.SetPixelUnused();
    463462    }
    464463
     
    493492    // check the num of photons against the noise level
    494493    //
    495     const Float_t entry = pix.GetNumPhotons();
    496     const Float_t noise = pix.GetErrorPhot();
    497 
     494    const Float_t  entry = pix.GetNumPhotons();
     495    const Float_t  noise = pix.GetErrorPhot();
    498496    const Double_t ratio = TMath::Sqrt(fCam->GetPixRatio(id));
    499497
    500     return (entry <= fCleanLvl2 * noise / ratio);
     498    return (entry * ratio <= fCleanLvl2 * noise);
    501499}
    502500
     
    517515    // check the num of photons against the noise level
    518516    //
    519     const Float_t entry = pix.GetNumPhotons();
    520 
     517    const Float_t  entry = pix.GetNumPhotons();
    521518    const Double_t ratio = fCam->GetPixRatio(id);
    522519
    523     return (entry <= fCleanLvl2 * fInnerNoise / ratio);
     520    return (entry * ratio <= fCleanLvl2 * fInnerNoise);
    524521}
    525522
     
    583580
    584581        pix.SetRing(r);
    585             break;
     582        break;
    586583    }
    587584}
     
    819816    }
    820817    out << ");" << endl;
    821 }
     818
     819    if (fCleaningMethod!=kDemocratic)
     820        return;
     821
     822    out << "   " << GetUniqueName() << ".SetMethod(MImgCleanStd::kDemocratic);" << endl;
     823
     824    if (fCleanRings==1)
     825        return;
     826
     827    out << "   " << GetUniqueName() << ".SetCleanRings(" << fCleanRings << ");" << endl;
     828}
  • trunk/MagicSoft/Mars/mimage/MImgCleanStd.h

    r2038 r2052  
    6262    UShort_t GetCleanRings() const { return fCleanRings;}
    6363
    64     void SetCleanRings(UShort_t r) { fCleanRings=r; }
     64    void SetCleanRings(UShort_t r) { if(r==0) r=1; fCleanRings=r; }
    6565    void SetMethod(CleaningMethod_t m) { fCleaningMethod = m; }
    6666
  • trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc

    r2022 r2052  
    3131// (see Read and Write) or printed as a postscript file (see SaveAsPS).
    3232//
     33// To write gif files of C-Macros use SaveAsGif() or SaveAsC().
     34// Direct printing to the default printer (via lpr) can be done by
     35// PrintToLpr().
     36//
    3337// It has also to half status lines which can be used to display the status
    3438// or something going on. Together with the status lines it has a progress
     
    101105    // filemenu->AddEntry("S&ave [F2]", kFileSave);
    102106    // filemenu->AddEntry("Save &As... [Shift-F2]", kFileSaveAs);
    103     filemenu->AddEntry("Save As status.&ps", kFileSaveAsPS);
    104     // filemenu->AddEntry("Save As status.&gif", kFileSaveAsGIF);
    105     // filemenu->AddEntry("Save As status.&C", kFileSaveAsC);
     107    filemenu->AddEntry("Save As status.&ps",   kFileSaveAsPS);
     108    filemenu->AddEntry("Save As status.&gif", kFileSaveAsGIF);
     109    filemenu->AddEntry("Save As status.&C",    kFileSaveAsC);
    106110    filemenu->AddEntry("Save As status.&root", kFileSaveAsRoot);
    107111    filemenu->AddSeparator();
    108     filemenu->AddEntry("Print with &lpr", kFilePrint);
    109     filemenu->AddEntry("Set printer &name", kFilePrinterName);
     112    filemenu->AddEntry("Print with &lpr",      kFilePrint);
     113    filemenu->AddEntry("Set printer &name",    kFilePrinterName);
    110114    filemenu->AddSeparator();
    111115    filemenu->AddEntry("E&xit", kFileExit);
     
    118122    // tabmenu->AddEntry("S&ave [F2]", kFileSave);
    119123    // tabmenu->AddEntry("Save &As... [Shift-F2]", kFileSaveAs);
    120     tabmenu->AddEntry("Save As tab-i.&ps", kTabSaveAsPS);
    121     // tabmenu->AddEntry("Save As tab-i.&gif", kTabSaveAsGIF);
    122     // tabmenu->AddEntry("Save As tab-i.&C", kTabSaveAsC);
     124    tabmenu->AddEntry("Save As tab-i.&ps",   kTabSaveAsPS);
     125    tabmenu->AddEntry("Save As tab-i.&gif", kTabSaveAsGIF);
     126    tabmenu->AddEntry("Save As tab-i.&C",    kTabSaveAsC);
    123127    tabmenu->AddEntry("Save As tab-i.&root", kTabSaveAsRoot);
    124128    tabmenu->AddSeparator();
    125     tabmenu->AddEntry("Print with &lpr", kFilePrint);
     129    tabmenu->AddEntry("Print with &lpr",     kFilePrint);
    126130    tabmenu->AddSeparator();
    127     tabmenu->AddEntry("Next [&+]",     kTabNext);
    128     tabmenu->AddEntry("Previous [&-]", kTabPrevious);
     131    tabmenu->AddEntry("Next [&+]",           kTabNext);
     132    tabmenu->AddEntry("Previous [&-]",       kTabPrevious);
    129133    tabmenu->Associate(this);
    130134
     
    135139    loopmenu->AddEntry("&Stop", kLoopStop);
    136140    loopmenu->Associate(this);
     141
     142    //
     143    // Loop Menu
     144    //
     145    MGPopupMenu *sizemenu = new MGPopupMenu(gClient->GetRoot());
     146    sizemenu->AddEntry("Fit to 640x&480",   kSize640);
     147    sizemenu->AddEntry("Fit to 800x&600",   kSize800);
     148    sizemenu->AddEntry("Fit to 960x7&20",   kSize960);
     149    sizemenu->AddEntry("Fit to 1024x&768",  kSize1024);
     150    sizemenu->AddEntry("Fit to 1280x&1024", kSize1280);
     151    sizemenu->Associate(this);
    137152
    138153    //
     
    143158    menubar->AddPopup("&Tab",  tabmenu,  NULL);
    144159    menubar->AddPopup("&Loop", loopmenu, NULL);
     160    menubar->AddPopup("&Size", sizemenu, NULL);
    145161    menubar->BindKeys(this);
    146162    AddFrame(menubar);
     
    160176    fList->Add(filemenu);
    161177    fList->Add(loopmenu);
     178    fList->Add(sizemenu);
    162179    fList->Add(menubar);
    163180    fList->Add(tabmenu);
     
    175192
    176193    // Add MARS version
    177     TString txt = "Official Release: V";
    178     TGLabel *l = new TGLabel(f, txt+MARSVER);
     194    TGLabel *l = new TGLabel(f, Form("Official Release: V%s", MARSVER));
    179195    fList->Add(l);
    180196
     
    184200
    185201    // Add root version
    186     txt = "Using ROOT v";
    187     l = new TGLabel(f, txt+ROOTVER);
     202    l = new TGLabel(f, Form("Using ROOT v%s", ROOTVER));
    188203    fList->Add(l);
    189204
     
    238253        TGCompositeFrame *f = fTab->AddTab("-Logbook-");
    239254
    240         // Create TGListBox for logging contents
    241         fLogBox = new TGListBox(f, 1, 1);
    242         fLogBox->ChangeBackground(TGFrame::GetBlackPixel());
     255        // Create TGListBox(p, id=-1, opt, back) for logging contents
     256        fLogBox = new TGListBox(f, -1, kSunkenFrame);
     257        //fLogBox->Associate(this);
    243258
    244259        // Add List box to the tab
    245         TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY);//, 5, 6, 5);
     260        TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY,2,2,2,2);
    246261        f->AddFrame(fLogBox, lay);
    247262
     
    373388void MStatusDisplay::SetStatusLine2(const MParContainer &cont)
    374389{
    375     TString txt = cont.GetDescriptor();
    376     txt += ": ";
    377     txt += cont.GetTitle();
    378 
    379     SetStatusLine2(txt);
     390    SetStatusLine2(Form("%s: %s", cont.GetDescriptor(), cont.GetTitle()));
    380391}
    381392
     
    406417    // set the smallest and biggest size of the Main frame
    407418    // and move it to its appearance position
    408     SetWMSizeHints(640, 548, 1280, 1024, 10, 10);
     419    SetWMSizeHints(570, 480, 1280, 980, 1, 1);
    409420    Move(rand()%100+50, rand()%100+50);
     421    //Resize(740, 600);
     422    Resize(570, 480);
    410423
    411424    //
     
    603616// via SetPrinter 'lpr -Pname' is used.
    604617//
    605 Int_t MStatusDisplay::PrintToLpr(Int_t num) const
     618Int_t MStatusDisplay::PrintToLpr(Int_t num)
    606619{
    607620    TString name = "mars";
     
    613626
    614627    const Int_t pages = SaveAsPS(num, name);
     628
     629    SetStatusLine1("Printing...");
     630    SetStatusLine2("");
     631
    615632    if (!pages)
    616633    {
    617634        *fLog << warn << "MStatusDisplay::PrintToLpr: Sorry, couldn't save file as temporary postscript!" << endl;
     635        SetStatusLine2("Failed!");
    618636        return 0;
    619637    }
     
    630648    gSystem->Exec(cmd);
    631649    gSystem->Unlink(name);
     650
     651    SetStatusLine2(Form("Done (%dpages)", pages));
    632652
    633653    return pages;
     
    658678*/
    659679    case kFileSaveAsPS:
    660         //cout << "FileSaveAsPS..." << endl;
    661680        SaveAsPS();
    662681        return kTRUE;
    663 /*
     682
    664683    case kFileSaveAsGIF:
    665         cout << "FileSaveAsGIF..." << endl;
    666684        SaveAsGIF();
    667685        return kTRUE;
    668686
    669687    case kFileSaveAsC:
    670         cout << "FileSaveAsC..." << endl;
    671688        SaveAsC();
    672689        return kTRUE;
    673 */
     690
    674691    case kFileSaveAsRoot:
    675692        SaveAsRoot();
     
    683700        SaveAsPS(fTab->GetCurrent());
    684701        return kTRUE;
    685 /*
     702
    686703    case kTabSaveAsGIF:
    687         cout << "TabSaveAsGIF... " << fTab->GetCurrent() <<  endl;
    688704        SaveAsGIF(fTab->GetCurrent());
    689705        return kTRUE;
    690706
    691707    case kTabSaveAsC:
    692         cout << "TabSaveAsC... " << fTab->GetCurrent() <<  endl;
    693708        SaveAsC(fTab->GetCurrent());
    694709        return kTRUE;
    695 */
     710
    696711    case kTabSaveAsRoot:
    697712        SaveAsRoot(fTab->GetCurrent());
     
    710725        return kTRUE;
    711726
     727    case kSize640:
     728        Resize(570, 480);
     729        return kTRUE;
     730    case kSize800:
     731        Resize(740, 600);
     732        return kTRUE;
     733    case kSize960:
     734        Resize(880, 700);
     735        return kTRUE;
     736    case kSize1024:
     737        Resize(980, 768);
     738        return kTRUE;
     739    case kSize1280:
     740        Resize(1280, 980);
     741        return kTRUE;
     742
    712743    default:
    713         cout << "Command-Menu: Id=" << id << endl;
     744        cout << "Command-Menu #" << id << endl;
    714745    }
    715746    return kTRUE;
     
    726757    {
    727758    case kCM_MENU:
    728         return ProcessMessageCommandMenu(mp1);
     759        return ProcessMessageCommandMenu(mp1); // mp2=userdata
    729760
    730761    case kCM_MENUSELECT:
    731         cout << "Menuselect #" << mp1 << endl;
     762        cout << "Command-Menuselect #" << mp1 << " (UserData=" << (void*)mp2 << ")" << endl;
     763        return kTRUE;
     764
     765    case kCM_BUTTON:
     766        cout << "Command-Button." << endl;
     767        return kTRUE;
     768
     769    case kCM_CHECKBUTTON:
     770        cout << "Command-CheckButton." << endl;
     771        return kTRUE;
     772
     773    case kCM_RADIOBUTTON:
     774        cout << "Command-RadioButton." << endl;
     775        return kTRUE;
     776
     777    case kCM_LISTBOX:
     778        cout << "Command-Listbox #" << mp1 << " (LineId #" << mp2 << ")" << endl;
     779        return kTRUE;
     780
     781    case kCM_COMBOBOX:
     782        cout << "Command-ComboBox." << endl;
    732783        return kTRUE;
    733784
     
    764815Bool_t MStatusDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
    765816{
     817    // Can be found in WidgetMessageTypes.h
    766818    switch (GET_MSG(msg))
    767819    {
     
    10051057    TObject *obj;
    10061058
     1059    // See also TPad::UseCurrentStyle
    10071060    TIter Next(p.GetListOfPrimitives());
    10081061    while ((obj=Next()))
     
    10361089}
    10371090
     1091Bool_t MStatusDisplay::CheckTabForCanvas(int num) const
     1092{
     1093    if (num>=fTab->GetNumberOfTabs())
     1094    {
     1095        *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
     1096        return kFALSE;
     1097    }
     1098    if (num==0)
     1099    {
     1100        *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
     1101        return kFALSE;
     1102    }
     1103    if (fTab->GetNumberOfTabs()<2 || !gPad)
     1104    {
     1105        *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
     1106        return kFALSE;
     1107    }
     1108    return kTRUE;
     1109}
     1110
    10381111// --------------------------------------------------------------------------
    10391112//
     
    10461119// To write all tabs you can also use SaveAsPS(name)
    10471120//
    1048 Int_t MStatusDisplay::SaveAsPS(Int_t num, TString name) const
    1049 {
    1050     if (num>=fTab->GetNumberOfTabs())
    1051     {
    1052         *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
    1053         return 0;
    1054     }
    1055     if (num==0)
    1056     {
    1057         *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
    1058         return 0;
    1059     }
    1060     if (fTab->GetNumberOfTabs()<2 || !gPad)
    1061     {
    1062         *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
     1121Int_t MStatusDisplay::SaveAsPS(Int_t num, TString name)
     1122{
     1123    SetStatusLine1("Writing Postscript file...");
     1124    SetStatusLine2("");
     1125
     1126    if (!CheckTabForCanvas(num))
     1127    {
     1128        SetStatusLine2("Failed!");
    10631129        return 0;
    10641130    }
     
    11071173            continue;
    11081174        }
     1175
     1176        SetStatusLine2(Form("Tab #%d", i));
    11091177
    11101178        //
     
    11861254    *fLog << inf << "done." << endl;
    11871255
     1256    SetStatusLine2(Form("Done (%dpages)", page-1));
     1257
    11881258    return page-1;
    11891259}
    11901260
    1191 /*
    1192 void MStatusDisplay::SaveAsGIF(Int_t num, TString name) const
    1193 {
     1261Bool_t MStatusDisplay::SaveAsGIF(Int_t num, TString name)
     1262{
     1263    SetStatusLine1("Writing GIF file...");
     1264    SetStatusLine2("");
     1265
     1266    if (!CheckTabForCanvas(num))
     1267    {
     1268        SetStatusLine2("Failed!");
     1269        return 0;
     1270    }
     1271
    11941272    AddExtension(name, "gif", num);
    11951273
    1196     cout << "Open gif-File: " << name << endl;
    1197     cout << " SORRY, not implemented." << endl;
    1198 }
    1199 
    1200 void MStatusDisplay::SaveAsC(Int_t num, TString name) const
    1201 {
     1274    if (num<0)
     1275        *fLog << inf << "Writing gif-Files..." << endl;
     1276
     1277    TPad *padsav = (TPad*)gPad;
     1278
     1279    int page = 1;
     1280
     1281    //
     1282    // Maintain tab numbers
     1283    //
     1284    const Int_t from = num<0 ? 1 : num;
     1285    const Int_t to   = num<0 ? fTab->GetNumberOfTabs() : num+1;
     1286
     1287    for (int i=from; i<to; i++)
     1288    {
     1289        TCanvas *c;
     1290        if (!(c = GetCanvas(i)))
     1291        {
     1292            if (num<0)
     1293                *fLog << inf << " - ";
     1294            *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
     1295            continue;
     1296        }
     1297
     1298        SetStatusLine2(Form("Tab #%d", i));
     1299
     1300        //
     1301        // Clone canvas and change background color and schedule for
     1302        // deletion
     1303        //
     1304        //TCanvas *n = (TCanvas*)c->Clone();
     1305        //CanvasSetFillColor(*n, kWhite);
     1306
     1307        //
     1308        // Paint canvas into root file
     1309        //
     1310        TString writename = name;
     1311        if (num<0)
     1312        {
     1313            TString numname = "-";
     1314            numname += i;
     1315            writename.Insert(name.Last('.'), numname);
     1316        }
     1317        if (num<0)
     1318            *fLog << inf << " - ";
     1319        *fLog << inf << "Writing Tab #" << i << " to " << writename << ": " << c->GetName() << " (" << c << ") ";
     1320        if (num>0)
     1321            *fLog << "to " << name;
     1322        *fLog << "..." << flush;
     1323
     1324        c->Draw();
     1325        c->SaveAs(writename);
     1326        /*
     1327         n->Draw();
     1328         n->SaveAs(writename);
     1329         delete n;
     1330         */
     1331
     1332        if (num<0)
     1333            *fLog << "done." << endl;
     1334    }
     1335
     1336    padsav->cd();
     1337
     1338    *fLog << inf << "done." << endl;
     1339
     1340    SetStatusLine2("Done.");
     1341
     1342    return page-1;
     1343}
     1344
     1345Bool_t MStatusDisplay::SaveAsC(Int_t num, TString name)
     1346{
     1347    SetStatusLine1("Writing C++ file...");
     1348    SetStatusLine2("");
     1349
     1350    if (!CheckTabForCanvas(num))
     1351    {
     1352        SetStatusLine2("Failed!");
     1353        return 0;
     1354    }
     1355
    12021356    AddExtension(name, "C", num);
    12031357
    1204     cout << "Open C-File: " << name << endl;
    1205     cout << " SORRY, not implemented." << endl;
    1206 }
    1207 */
     1358    if (num<0)
     1359        *fLog << inf << "Writing C-Files..." << endl;
     1360
     1361    TPad *padsav = (TPad*)gPad;
     1362
     1363    int page = 1;
     1364
     1365    //
     1366    // Maintain tab numbers
     1367    //
     1368    const Int_t from = num<0 ? 1 : num;
     1369    const Int_t to   = num<0 ? fTab->GetNumberOfTabs() : num+1;
     1370
     1371    for (int i=from; i<to; i++)
     1372    {
     1373        TCanvas *c;
     1374        if (!(c = GetCanvas(i)))
     1375        {
     1376            if (num<0)
     1377                *fLog << inf << " - ";
     1378            *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
     1379            continue;
     1380        }
     1381
     1382        SetStatusLine2(Form("Tab #%d", i));
     1383
     1384        //
     1385        // Clone canvas and change background color and schedule for
     1386        // deletion
     1387        //
     1388        TCanvas *n = (TCanvas*)c->Clone();
     1389        CanvasSetFillColor(*n, kWhite);
     1390
     1391        //
     1392        // Paint canvas into root file
     1393        //
     1394        TString writename = name;
     1395        if (num<0)
     1396        {
     1397            TString numname = "-";
     1398            numname += i;
     1399            writename.Insert(name.Last('.'), numname);
     1400        }
     1401        if (num<0)
     1402            *fLog << inf << " - ";
     1403        *fLog << inf << "Writing Tab #" << i << " to " << writename << ": " << c->GetName() << " (" << n << ") ";
     1404        if (num>0)
     1405            *fLog << "to " << name;
     1406        *fLog << "..." << flush;
     1407
     1408        n->SaveSource(writename, "");
     1409        delete n;
     1410
     1411        if (num<0)
     1412            *fLog << "done." << endl;
     1413    }
     1414
     1415    padsav->cd();
     1416
     1417    *fLog << inf << "done." << endl;
     1418
     1419    SetStatusLine2("Done.");
     1420
     1421    return page-1;
     1422}
    12081423
    12091424// --------------------------------------------------------------------------
     
    12191434Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name)
    12201435{
    1221     if (num>=fTab->GetNumberOfTabs())
    1222     {
    1223         *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
    1224         return 0;
    1225     }
    1226     if (num==0)
    1227     {
    1228         *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
    1229         return 0;
    1230     }
    1231     if (fTab->GetNumberOfTabs()<2 || !gPad)
    1232     {
    1233         *fLog << warn << "Sorry, you must have at least one existing canvas." << endl;
     1436    SetStatusLine1("Writing root file...");
     1437    SetStatusLine2("");
     1438
     1439    if (!CheckTabForCanvas(num))
     1440    {
     1441        SetStatusLine2("Failed!");
    12341442        return 0;
    12351443    }
     
    12421450    gFile = fsave;
    12431451
     1452    SetStatusLine2("Done.");
     1453
    12441454    return keys;
    12451455}
     1456
     1457Bool_t MStatusDisplay::HandleConfigureNotify(Event_t *evt)
     1458{
     1459    //cout << "----- Start -----" << endl;
     1460
     1461    UInt_t w = evt->fWidth;
     1462    UInt_t h = evt->fHeight;
     1463
     1464    //cout << "Old: " << GetWidth() << " " << GetHeight() << " " << GetBorderWidth() << endl;
     1465    //cout << "New: " << w << " " << h << endl;
     1466
     1467    Bool_t wchanged = w!=GetWidth();
     1468    Bool_t hchanged = h!=GetHeight();
     1469
     1470    if (!wchanged && !hchanged)
     1471    {
     1472        Layout();
     1473        return kTRUE;
     1474    }
     1475
     1476    if (GetWidth()==1 && GetHeight()==1)
     1477        return kTRUE;
     1478
     1479    // calculate the constant part of the window
     1480    const UInt_t cw = GetWidth() -fTab->GetWidth();
     1481    const UInt_t ch = GetHeight()-fTab->GetHeight();
     1482
     1483    // canculate new size of frame (canvas @ 1:sqrt(2))
     1484    if (hchanged)
     1485        w = (UInt_t)((h-ch)*sqrt(2)+.5)+cw;
     1486    else
     1487        h = (UInt_t)((w-cw)/sqrt(2)+.5)+ch;
     1488
     1489    //cout << "Res: " << w << " " << h << " " << evt->fX << " " << evt->fY << endl;
     1490
     1491    // resize frame
     1492    Resize(w, h);
     1493
     1494    return kTRUE;
     1495}
     1496
     1497Bool_t MStatusDisplay::HandleEvent(Event_t *event)
     1498{
     1499    /*
     1500    if (event->fType!=9)
     1501    {
     1502        cout << "Event: " << event->fType << " ";
     1503        cout << event->fX << " " << event->fY << endl;
     1504    }
     1505    */
     1506    /*
     1507    switch (event->fType) {
     1508      case kConfigureNotify:
     1509         //while (gVirtualX->CheckEvent(fId, kConfigureNotify, *event))
     1510         //   ;
     1511         HandleConfigureNotify(event);
     1512         return kTRUE;
     1513    }
     1514    */
     1515    //   if (event->fType==kConfigureNotify && event->fX!=0 && event->fY!=0)
     1516    //        return kTRUE;
     1517
     1518    return TGMainFrame::HandleEvent(event);
     1519}
  • trunk/MagicSoft/Mars/mmain/MStatusDisplay.h

    r2015 r2052  
    5151        kTabNext,
    5252        kTabPrevious,
     53        kSize640,
     54        kSize800,
     55        kSize960,
     56        kSize1024,
     57        kSize1280,
    5358        kFileExit,
    5459        kPicMagic,
     
    8994    Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);
    9095    void   CloseWindow();
     96    Bool_t HandleConfigureNotify(Event_t *);
     97    Bool_t HandleEvent(Event_t *event);
    9198
    9299    Bool_t HandleTimer(TTimer *timer=NULL);
     
    135142     void SetNoContextMenu(Bool_t flag=kTRUE);
    136143
    137      Int_t SaveAsPS(TString name="") const { return SaveAsPS(-1, name); }
    138      //Bool_t SaveAsGIF(TString name="") const { return SaveAsGIF(-1, name); }
    139      //Bool_t SaveAsC(TString name="") const { return SaveAsC(-1, name); }
    140      Int_t SaveAsRoot(TString name="") { return SaveAsRoot(-1, name); }
    141      Int_t PrintToLpr() const { return PrintToLpr(-1); }
     144     Int_t  SaveAsPS(TString name="") { return SaveAsPS(-1, name); }
     145     Bool_t SaveAsGIF(TString name="") { return SaveAsGIF(-1, name); }
     146     Bool_t SaveAsC(TString name="") { return SaveAsC(-1, name); }
     147     Int_t  SaveAsRoot(TString name="") { return SaveAsRoot(-1, name); }
     148     Int_t  PrintToLpr() { return PrintToLpr(-1); }
    142149
    143      Int_t SaveAsPS(Int_t num, TString name="") const;
    144      //Bool_t SaveAsGIF(Int_t num, TString name="") const;
    145      //Bool_t SaveAsC(Int_t num, TString name="") const;
    146      Int_t SaveAsRoot(Int_t num, TString name="");
    147      Int_t PrintToLpr(Int_t num) const;
     150     Int_t  SaveAsPS(Int_t num, TString name="");
     151     Bool_t SaveAsGIF(Int_t num, TString name="");
     152     Bool_t SaveAsC(Int_t num, TString name="");
     153     Int_t  SaveAsRoot(Int_t num, TString name="");
     154     Int_t  PrintToLpr(Int_t num);
    148155
    149156     Status_t CheckStatus() const { return fStatus; }
     
    153160     void UnLock() { ResetBit(kIsLocked); }
    154161
     162     Bool_t CheckTabForCanvas(int num) const;
     163
    155164     ClassDef(MStatusDisplay, 0)   // Window for a status display
    156165};
Note: See TracChangeset for help on using the changeset viewer.