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

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.