Changeset 5994


Ignore:
Timestamp:
01/25/05 14:47:59 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r5991 r5994  
    2828
    2929
     30
    3031 2005/01/25 Thomas Bretz
    3132
     
    3738     - moved the empty Reset() function into the source file and
    3839       added a lot of comments
     40     - implemented new helper-functions: GetNewObject
     41
     42   * mbase/MContinue.[h,cc]:
     43     - allow to use MFilter-classes as filter in ReadEnv
     44
     45   * mbase/MTaskEnv.cc:
     46     - replaced some code by GetNewObject
     47
     48   * mhbase/MFillH.cc:
     49     - handle DrawOption "same" to be able to draw to the same pad
     50
     51   * mhbase/MH.[h,cc]:
     52     - added same-argument to DrawSame
     53
     54   * mhbase/MH3.cc:
     55     - removed some obsolete comments
     56     - remove own drawing options before calling fHist->Draw
     57
     58   * mimage/MHHillas.cc, mimage/MHImagePar.cc:
     59     - first try of implementing 'same' drawing option
    3960
    4061
  • trunk/MagicSoft/Mars/mbase/MContinue.cc

    r5956 r5994  
    241241//     MyContinue.0: MHillas.fSize>1000
    242242//     MyContinue.1: MHillas.fSize<10000
    243 //   or
     243//   or (the syntax might change in the future!)
    244244//     MyContinue.Condition: <MMyClass>
    245245//     MMyClass.Variable1: ...
     
    250250Int_t MContinue::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
    251251{
     252    MFilter *f = 0;
    252253    if (IsEnvDefined(env, prefix, "Condition", print))
    253254    {
     
    256257        if (txt.BeginsWith("<") && txt.EndsWith(">"))
    257258        {
    258             *fLog << err << "NOT YET IMPLEMENTED..." << endl;
    259             return kERROR;
     259            const TString name = txt(1, txt.Length()-2);
     260            f = (MFilter*)GetNewObject(name, MFilter::Class());
     261            if (!f)
     262                return kERROR;
    260263        }
    261264    }
    262265
    263     MF *f = new MF;
     266    if (!f)
     267        f = new MF;
    264268    f->SetName(fName);
    265269
  • trunk/MagicSoft/Mars/mbase/MContinue.h

    r5956 r5994  
    3030    Int_t PostProcess();
    3131
     32    // MContinue
    3233    enum { kIsOwner = BIT(14), kFilterIsPrivate = BIT(15), kAllowEmpty = BIT(16) };
    3334
  • trunk/MagicSoft/Mars/mbase/MParContainer.cc

    r5986 r5994  
    465465}
    466466
     467// --------------------------------------------------------------------------
     468//
     469// Return the pointer to the TClass (from the root dictionary) which
     470// corresponds to the class with name name.
     471//
     472// Make sure, that a new object of this type can be created.
     473//
     474// In case of failure return NULL
     475//
     476TClass *MParContainer::GetConstructor(const char *name) const
     477{
     478    //
     479    // try to get class from root environment
     480    //
     481    TClass *cls = gROOT->GetClass(name);
     482    Int_t rc = 0;
     483    if (!cls)
     484        rc =1;
     485    else
     486    {
     487        if (!cls->Property())
     488            rc = 5;
     489        if (!cls->Size())
     490            rc = 4;
     491        if (!cls->IsLoaded())
     492            rc = 3;
     493        if (!cls->HasDefaultConstructor())
     494            rc = 2;
     495    }
     496
     497    if (!rc)
     498        return cls;
     499
     500    *fLog << err << dbginf << GetDescriptor() << " - Cannot create new instance of class '" << name << "': ";
     501    switch (rc)
     502    {
     503    case 1:
     504        *fLog << "gROOT->GetClass() returned NULL." << endl;
     505        return NULL;
     506    case 2:
     507        *fLog << "no default constructor." << endl;
     508        return NULL;
     509    case 3:
     510        *fLog << "not loaded." << endl;
     511        return NULL;
     512    case 4:
     513        *fLog << "zero size." << endl;
     514        return NULL;
     515    case 5:
     516        *fLog << "no property." << endl;
     517        return NULL;
     518    }
     519
     520    *fLog << "rtlprmft." << endl;
     521
     522    return NULL;
     523}
     524
     525// --------------------------------------------------------------------------
     526//
     527// Return a new object of class 'name'. Make sure that the object
     528// derives from the class base.
     529//
     530// In case of failure return NULL
     531//
     532// The caller is responsible of deleting the object!
     533//
     534MParContainer *MParContainer::GetNewObject(const char *name, TClass *base) const
     535{
     536    TClass *cls = GetConstructor(name);
     537    if (!cls || !base)
     538        return NULL;
     539
     540    if (!cls->InheritsFrom(base))
     541    {
     542        *fLog << " - Class doesn't inherit from " << base->GetName() << endl;
     543        return NULL;
     544    }
     545
     546    //
     547    // create the parameter container of the the given class type
     548    //
     549    TObject *obj = (TObject*)cls->New();
     550    if (!obj)
     551    {
     552        *fLog << " - Class has no default constructor." << endl;
     553        *fLog << " - An abstract member functions of a base class is not overwritten." << endl;
     554        return NULL;
     555    }
     556
     557    return (MParContainer*)obj;
     558}
     559
     560// --------------------------------------------------------------------------
     561//
     562// Return a new object of class 'name'. Make sure that the object
     563// derives from the class base.
     564//
     565// In case of failure return NULL
     566//
     567// The caller is responsible of deleting the object!
     568//
     569MParContainer *MParContainer::GetNewObject(const char *name, const char *base) const
     570{
     571    TClass *cls = GetConstructor(name);
     572    if (!cls || !base)
     573        return NULL;
     574
     575    if (!cls->InheritsFrom(base))
     576    {
     577        *fLog << " - Class doesn't inherit from " << base << endl;
     578        return NULL;
     579    }
     580
     581    //
     582    // create the parameter container of the the given class type
     583    //
     584    TObject *obj = (TObject*)cls->New();
     585    if (!obj)
     586    {
     587        *fLog << " - Class has no default constructor." << endl;
     588        *fLog << " - An abstract member functions of a base class is not overwritten." << endl;
     589        return NULL;
     590    }
     591
     592    return (MParContainer*)obj;
     593}
     594
    467595TMethodCall *MParContainer::GetterMethod(const char *name) const
    468596{
  • trunk/MagicSoft/Mars/mbase/MParContainer.h

    r5986 r5994  
    5353
    5454    Bool_t  fReadyToSave; // should be set to true if the contents of the container is changed somehow
     55
     56    TClass *GetConstructor(const char *name) const;
    5557
    5658public:
     
    140142    const char *GetEnvValue(const TEnv &env, TString prefix, const char *dflt) const;
    141143
     144    MParContainer *GetNewObject(const char *name, const char *base) const;
     145    MParContainer *GetNewObject(const char *name, TClass *base=MParContainer::Class()) const;
     146
    142147    ClassDef(MParContainer, 0)  //The basis for all parameter containers
    143148};
  • trunk/MagicSoft/Mars/mbase/MTaskEnv.cc

    r5307 r5994  
    100100MTask *MTaskEnv::GetTask(const char *name) const
    101101{
    102     //
    103     // try to get class from root environment
    104     //
    105     TClass *cls = gROOT->GetClass(name);
    106     Int_t rc = 0;
    107     if (!cls)
    108         rc =1;
    109     else
    110     {
    111         if (!cls->Property())
    112             rc = 5;
    113         if (!cls->Size())
    114             rc = 4;
    115         if (!cls->IsLoaded())
    116             rc = 3;
    117         if (!cls->HasDefaultConstructor())
    118             rc = 2;
    119     }
    120 
    121     if (rc)
    122     {
    123         *fLog << err << dbginf << "Cannot create new instance of class '" << name << "': ";
    124         switch (rc)
    125         {
    126         case 1:
    127             *fLog << "gROOT->GetClass() returned NULL." << endl;
    128             return NULL;
    129         case 2:
    130             *fLog << "no default constructor." << endl;
    131             return NULL;
    132         case 3:
    133             *fLog << "not loaded." << endl;
    134             return NULL;
    135         case 4:
    136             *fLog << "zero size." << endl;
    137             return NULL;
    138         case 5:
    139             *fLog << "no property." << endl;
    140             return NULL;
    141         }
    142     }
    143 
    144     if (!cls->InheritsFrom(MTask::Class()))
    145     {
    146         *fLog << " - Class doesn't inherit from MTask." << endl;
     102    MTask *task = (MTask*)GetNewObject(name, MTask::Class());
     103    if (!task)
    147104        return NULL;
    148     }
    149 
    150     //
    151     // create the parameter container of the the given class type
    152     //
    153     MTask *task = (MTask*)cls->New();
    154     if (!task)
    155     {
    156         *fLog << " - Class has no default constructor." << endl;
    157         *fLog << " - An abstract member functions of a base class is not overwritten." << endl;
    158         return NULL;
    159     }
    160105
    161106    task->SetName(fName);
  • trunk/MagicSoft/Mars/mhbase/MFillH.cc

    r5713 r5994  
    358358// if fDisplay is set and the MH-class overwrites the Draw function
    359359//
     360// If the draw-option contains 'same' (case insensitive) a tab with the
     361// same name as the one which would be created is searched and the
     362// MH is drawn to this canvas. If it is not found a new tab is created.
     363//
    360364Bool_t MFillH::DrawToDisplay()
    361365{
     
    371375        return kTRUE;
    372376
    373     fCanvas = &fDisplay->AddTab(fNameTab.IsNull() ? fH->GetName() : fNameTab.Data());
     377    const TString tabname = fNameTab.IsNull() ? fH->GetName() : fNameTab.Data();
     378
     379    fCanvas = 0;
     380    if (fDrawOption.Contains("same", TString::kIgnoreCase))
     381        fCanvas = fDisplay->GetCanvas(tabname);
     382    if (!fCanvas)
     383        fCanvas = &fDisplay->AddTab(tabname);
     384
     385    fCanvas->cd();
    374386    fH->Draw(fDrawOption);
    375387
  • trunk/MagicSoft/Mars/mhbase/MH.cc

    r5869 r5994  
    795795// Also layout the two statistic boxes and a legend.
    796796//
    797 void MH::DrawSame(TH1 &hist1, TH1 &hist2, const TString title)
     797void MH::DrawSame(TH1 &hist1, TH1 &hist2, const TString title, Bool_t same)
    798798{
    799799    //
    800800    // Draw first histogram
    801801    //
    802     hist1.Draw();
     802    hist1.Draw(same?"same":"");
    803803    gPad->SetBorderMode(0);
    804804    gPad->Update();
  • trunk/MagicSoft/Mars/mhbase/MH.h

    r4991 r5994  
    8585
    8686    static void DrawSameCopy(const TH1 &hist1, const TH1 &hist2, const TString title);
    87     static void DrawSame(TH1 &hist1, TH1 &hist2, const TString title);
     87    static void DrawSame(TH1 &hist1, TH1 &hist2, const TString title, Bool_t same=kFALSE);
    8888
    8989    TObject *Clone(const char *name="") const;
  • trunk/MagicSoft/Mars/mhbase/MH3.cc

    r5956 r5994  
    103103//
    104104MH3::MH3(const unsigned int dim)
    105     : fDimension(dim>3?3:dim), fHist(NULL)/*,
    106     fNameProfX(Form("ProfX_%p", this)),
    107     fNameProfY(Form("ProfY_%p", this))*/
     105    : fDimension(dim>3?3:dim), fHist(NULL)
    108106
    109107    switch (fDimension)
     
    205203//
    206204MH3::MH3(const char *memberx, const char *membery)
    207     : fDimension(2)/*, fNameProfX(Form("ProjX_%p", this)), fNameProfY(Form("ProjY_%p", this))*/
     205    : fDimension(2)
    208206{
    209207    fHist = new TH2F;
     
    539537
    540538    TString str(o);
    541     str = str.Strip(TString::kBoth);
    542 
    543     Bool_t only = str.Contains("ONLY", TString::kIgnoreCase) && fDimension==2;
    544     Bool_t same = str.Contains("SAME", TString::kIgnoreCase) && fDimension==2;
    545     Bool_t blue = str.Contains("BLUE", TString::kIgnoreCase) && fDimension==2;
     539    str.ToLower();
     540
     541    const Bool_t only  = str.Contains("only")  && fDimension==2;
     542    const Bool_t same  = str.Contains("same")  && fDimension==2;
     543    const Bool_t blue  = str.Contains("blue")  && fDimension==2;
     544    const Bool_t profx = str.Contains("profx") && fDimension==2;
     545    const Bool_t profy = str.Contains("profy") && fDimension==2;
     546    // Do NOT replace 'same'-option
     547    str.ReplaceAll("only",  "");
     548    str.ReplaceAll("blue",  "");
     549    str.ReplaceAll("profx", "");
     550    str.ReplaceAll("profy", "");
    546551
    547552    // FIXME: We may have to remove all our own options from str!
     
    549554        fHist->Draw(str);
    550555
    551     if (str.Contains("PROFX", TString::kIgnoreCase) && fDimension==2)
     556    if (profx)
    552557    {
    553558        TProfile *p = ((TH2*)fHist)->ProfileX("ProfX", -1, 9999, "s");
     
    563568        }
    564569    }
    565     if (str.Contains("PROFY", TString::kIgnoreCase) && fDimension==2)
     570    if (profy)
    566571    {
    567572        TProfile *p = ((TH2*)fHist)->ProfileY("ProfY", -1, 9999, "s");
  • trunk/MagicSoft/Mars/mimage/MHHillas.cc

    r5142 r5994  
    286286// together with the canvas.
    287287//
    288 void MHHillas::Draw(Option_t *)
     288void MHHillas::Draw(Option_t *o)
    289289{
    290290    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
     
    293293    AppendPad("");
    294294
    295     pad->Divide(2,3);
     295    TString opt(o);
     296    opt.ToLower();
     297
     298    // FIXME: If same-option given make two independant y-axis!
     299    const Bool_t same = opt.Contains("same");
     300
     301    if (!same)
     302        pad->Divide(2,3);
     303    else
     304    {
     305        fDistC->SetLineColor(kGreen);
     306        fSize->SetLineColor(kGreen);
     307        fDelta->SetLineColor(kGreen);
     308
     309        fWidth->SetLineColor(kMagenta);
     310        fLength->SetLineColor(kCyan);
     311    }
    296312
    297313    pad->cd(1);
    298314    gPad->SetBorderMode(0);
    299     MH::DrawSame(*fWidth, *fLength, "Width'n'Length");
     315    MH::DrawSame(*fWidth, *fLength, "Width'n'Length", same);
    300316
    301317    pad->cd(2);
    302318    gPad->SetBorderMode(0);
    303     fDistC->Draw();
     319    fDistC->Draw(same?"same":"");
    304320
    305321    pad->cd(3);
     
    307323    gPad->SetLogx();
    308324    gPad->SetLogy();
    309     fSize->Draw();
    310 
    311     pad->cd(4);
    312     gPad->SetBorderMode(0);
    313     gPad->SetPad(0.51, 0.01, 0.99, 0.65);
    314     SetColors();
    315     fCenter->Draw("colz");
    316     if (fGeomCam)
    317     {
    318         MHCamera *cam = new MHCamera(*fGeomCam);
    319         cam->Draw("same");
    320         cam->SetBit(kCanDelete);
     325    fSize->Draw(same?"same":"");
     326
     327    if (!same)
     328    {
     329        pad->cd(4);
     330        gPad->SetBorderMode(0);
     331        gPad->SetPad(0.51, 0.01, 0.99, 0.65);
     332        SetColors();
     333        fCenter->Draw("colz");
     334        if (fGeomCam)
     335        {
     336            MHCamera *cam = new MHCamera(*fGeomCam);
     337            cam->Draw("same");
     338            cam->SetBit(kCanDelete);
     339        }
    321340    }
    322341
    323342    pad->cd(5);
    324343    gPad->SetBorderMode(0);
    325     fDelta->Draw();
     344    fDelta->Draw(same?"same":"");
    326345
    327346    pad->cd(6);
    328     delete gPad;
     347    if (gPad && !same)
     348        delete gPad;
    329349
    330350    pad->Modified();
  • trunk/MagicSoft/Mars/mimage/MHImagePar.cc

    r5142 r5994  
    136136void MHImagePar::Paint(Option_t *o)
    137137{
    138     if (TString(o)==(TString)"log1" && fHistSatHi.GetMaximum()>0)
    139         gPad->SetLogy();
    140     if (TString(o)==(TString)"log2" && fHistIslands.GetMaximum()>0)
    141         gPad->SetLogy();
     138    /*
     139     if (TString(o)==(TString)"log1" && fHistSatHi.GetMaximum()>0)
     140     gPad->SetLogy();
     141     if (TString(o)==(TString)"log2" && fHistIslands.GetMaximum()>0)
     142     gPad->SetLogy();
     143     */
     144     if (fHistSatHi.GetMaximum()>0 && gPad->GetPad(1))
     145         gPad->GetPad(1)->SetLogy();
     146     if (fHistIslands.GetMaximum()>0 && gPad->GetPad(2))
     147         gPad->GetPad(2)->SetLogy();
    142148}
    143149
     
    148154// together with the canvas.
    149155//
    150 void MHImagePar::Draw(Option_t *)
     156void MHImagePar::Draw(Option_t *o)
    151157{
    152158    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
     
    155161    AppendPad("");
    156162
    157     pad->Divide(1,2);
    158 
    159     pad->cd(1);
    160     gPad->SetBorderMode(0);
    161     MH::DrawSame(fHistSatHi, fHistSatLo, "Saturating Pixels");
    162     fHistSatHi.SetMinimum(); // switch off to allow log-scale
    163     fHistSatLo.SetMinimum(); // switch off to allow log-scale
    164     fHistSatLo.SetMaximum(0.1);   // dummy value to allow log-scale
    165     AppendPad("log1");
     163    TString opt(o);
     164    opt.ToLower();
     165
     166    // FIXME: If same-option given make two independant y-axis!
     167    const Bool_t same = opt.Contains("same");
     168
     169    if (!same)
     170        pad->Divide(1,2);
     171    else
     172        fHistIslands.SetLineColor(kGreen);
     173
     174    if (!same)
     175    {
     176        pad->cd(1);
     177        gPad->SetBorderMode(0);
     178        MH::DrawSame(fHistSatHi, fHistSatLo, "Saturating Pixels");
     179        fHistSatHi.SetMinimum(); // switch off to allow log-scale
     180        fHistSatLo.SetMinimum(); // switch off to allow log-scale
     181        fHistSatLo.SetMaximum(0.1);   // dummy value to allow log-scale
     182        //AppendPad("log1");
     183    }
    166184
    167185    pad->cd(2);
    168186    gPad->SetBorderMode(0);
    169     fHistIslands.Draw();
    170     AppendPad("log2");
     187    fHistIslands.Draw(same?"same":"");
     188    //AppendPad("log2");
    171189}
    172190
Note: See TracChangeset for help on using the changeset viewer.