Changeset 9025


Ignore:
Timestamp:
07/21/08 09:11:21 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MParContainer.cc

    r8957 r9025  
    750750// --------------------------------------------------------------------------
    751751//
     752// Check if an object can be created through gROOT->GetClass(classname)
     753// return the correspodning TClass or NULL if this is not possible.
     754// A message containing the reason is returned in msg.
     755//
     756TClass *MParContainer::GetClass(const char *classname, TString &msg)
     757{
     758    TClass *cls = gROOT->GetClass(classname);
     759    Int_t rcc = 0;
     760    if (!cls)
     761        rcc = 1;
     762    else
     763    {
     764        if (!cls->Property())
     765            rcc = 5;
     766        if (!cls->Size())
     767            rcc = 4;
     768        if (!cls->IsLoaded())
     769            rcc = 3;
     770        if (!cls->HasDefaultConstructor())
     771            rcc = 2;
     772    }
     773
     774    // Everything is ok.
     775    if (rcc==0)
     776        return cls;
     777
     778    msg += "Cannot create instance of class '";
     779    msg += classname;
     780    msg += "': ";
     781
     782    switch (rcc)
     783    {
     784    case 1:
     785        msg += "gROOT->GetClass() returned NULL.";
     786        break;
     787    case 2:
     788        msg += "no default constructor.";
     789        break;
     790    case 3:
     791        msg += "not loaded.";
     792        break;
     793    case 4:
     794        msg += "zero size.";
     795        break;
     796    case 5:
     797        msg += "no property.";
     798        break;
     799    default:
     800        msg += "Unknown error.";
     801        break;
     802    }
     803
     804    return 0;
     805}
     806
     807// --------------------------------------------------------------------------
     808//
     809// Check if an object can be created through gROOT->GetClass(classname)
     810// return the correspodning TClass or NULL if this is not possible.
     811// A message with the reason is ouput.
     812//
     813TClass *MParContainer::GetClass(const char *classname, MLog *log)
     814{
     815    TString msg;
     816    TClass *cls = GetClass(classname, msg);
     817
     818    if (!cls && log)
     819        *log << msg << endl;
     820
     821    return cls;
     822}
     823
     824
     825// --------------------------------------------------------------------------
     826//
    752827// Read the contents/setup of a parameter container/task from a TEnv
    753828// instance (steering card/setup file).
  • trunk/MagicSoft/Mars/mbase/MParContainer.h

    r8724 r9025  
    151151    MParContainer *GetNewObject(const char *name, TClass *base=MParContainer::Class()) const;
    152152
     153    static TClass *GetClass(const char *classname, TString &msg);
     154    static TClass *GetClass(const char *classname, MLog *log=NULL);
     155
    153156    void RecursiveRemove(TObject *obj);
    154157
  • trunk/MagicSoft/Mars/mbase/MParList.cc

    r8744 r9025  
    130130
    131131    TIter Next(fContainer);
    132     TObject *o;
     132    TObject *o=0;
    133133    while ((o=Next()))
    134134        if (o->TestBit(kCanDelete))
     
    136136
    137137    // FIXME? If fContainer is owner do we have to remove the object
    138     //   from fAutodelete due to the acces when checking for a
     138    //   from fAutodelete due to the access when checking for a
    139139    //   garbage collection?
    140 
    141140    delete fContainer;
    142141    delete fAutodelete;
     
    572571    // try to get class from root environment
    573572    //
    574     TClass *cls = gROOT->GetClass(cname);
    575     Int_t rc = 0;
     573    *fLog << err;
     574    TClass *cls = GetClass(cname, fLog);
    576575    if (!cls)
    577         rc =1;
    578     else
    579     {
    580         if (!cls->Property())
    581             rc = 5;
    582         if (!cls->Size())
    583             rc = 4;
    584         if (!cls->IsLoaded())
    585             rc = 3;
    586         if (!cls->HasDefaultConstructor())
    587             rc = 2;
    588     }
    589 
    590     if (rc)
    591     {
    592         *fLog << err << dbginf << "Cannot create new instance of class '" << cname << "': ";
    593         switch (rc)
    594         {
    595         case 1:
    596             *fLog << "gROOT->GetClass() returned NULL." << endl;
    597             return NULL;
    598         case 2:
    599             *fLog << "no default constructor." << endl;
    600             return NULL;
    601         case 3:
    602             *fLog << "not loaded." << endl;
    603             return NULL;
    604         case 4:
    605             *fLog << "zero size." << endl;
    606             return NULL;
    607         case 5:
    608             *fLog << "no property." << endl;
    609             return NULL;
    610         }
    611     }
     576        return NULL;
    612577
    613578    if (!cls->InheritsFrom(MParContainer::Class()))
     
    811776    // try to get class from root environment
    812777    //
    813     TClass *cls = gROOT->GetClass(cname);
     778    TClass *cls = GetClass(cname);
    814779    if (!cls)
    815     {
    816         //
    817         // if class is not existing in the root environment
    818         //
    819         gLog << dbginf << "Class '" << cname << "' not existing in dictionary." << endl;
     780        return list;
     781
     782    if (!cls->InheritsFrom(MParContainer::Class()))
     783    {
     784        *fLog << err << dbginf << "Cannot create new instance of class '" << cname << "': " << endl;
     785        *fLog << "Class doesn't inherit from MParContainer." << endl;
    820786        return list;
    821787    }
Note: See TracChangeset for help on using the changeset viewer.