Changeset 3573 for trunk/MagicSoft


Ignore:
Timestamp:
03/22/04 14:30:09 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r3572 r3573  
    9999     
    100100   * mdata/MDataArray.[h,cc], mdata/MDataElement.h,
    101      mdata/MDataList.[h,cc], mdata/MDataMember.h:
     101     mdata/MDataList.[h,cc], mdata/MDataMember.h,
     102     mfbase/MFDataMember.[h,cc], mfbase/MFilterList.[h,cc]:
    102103     - added SetVariables
    103104
     
    110111     - added support for an index
    111112     - added SetVariables
    112      
     113
     114   * mfbase/MF.[h,cc]:
     115     - removed support for {}. This case is now detected
     116       automatically
     117     - added SetVariables
     118     - added support for expressiond like
     119       "MHillas.fLength<2*MHillas.fWidth"
     120
     121   * mfbase/MFDataChain.[h,cc]:
     122     - added fCond data member
     123     - addednew constructor to support fCond
     124     - added support for new condition type
     125     - adapted Print and GetRule
    113126
    114127
  • trunk/MagicSoft/Mars/NEWS

    r3393 r3573  
    11                                                               -*-*- END -*-*-
    22 *** Version <cvs>
     3 
     4   - added support in MF for expressiond like
     5     "MHillas.fWidth<2*MHillas.fLength"
     6
     7   - MDataChain is now able to support variables like [0], [1], ...
     8     which can be used in fit functions as parameters. The interface
     9     is implemented through the new virtual function
     10     MParContainer::SetVariables
    311
    412   - added new class MArrivalTimeCam/MArrivalTimePix:
  • trunk/MagicSoft/Mars/mfbase/MF.cc

    r3330 r3573  
    7171//
    7272//
    73 //  If you intend to use Data Chains in filters enclose the chains in
    74 //  this {}-parenthesis, eg.
    75 //
    76 //   "{MHillas.fSize*MHillas.fWidth}<0.5"
    77 //
    7873// FIXME: The possibility to use also complete filters is missing.
    7974//        Maybe we can use gInterpreter->Calc("") for this.
     
    166161MFilter *MF::ParseRule(TString &txt, MFilter *filter0, Int_t level) const
    167162{
    168     TString text;
    169 
    170     Bool_t isrule = kFALSE;
    171 
    172     if (txt[0]=='{')
    173     {
    174         //
    175         // Search for the corresponding bracket
    176         //
    177         Int_t first=1;
    178         for (int cnt=0; first<txt.Length(); first++)
    179         {
    180             if (txt[first]=='{')
    181                 cnt++;
    182             if (txt[first]=='}')
    183                 cnt--;
    184 
    185             if (cnt==-1)
    186                 break;
    187         }
    188 
    189         if (first==txt.Length())
    190         {
    191             *fLog << err << dbginf << "Syntax Error: '}' missing." << endl;
    192             return NULL;
    193         }
    194 
    195         //
    196         // Make a copy of the 'interieur' and delete the substringä
    197         // including the brackets
    198         //
    199         TString sub = txt(1, first-1);
    200         txt.Remove(0, first+1);
    201 
    202         text=sub;
    203         isrule = kTRUE;
    204     }
    205     else
    206     {
    207         int i = IsAlNum(txt);
    208 
    209         if (i==0)
    210         {
    211             *fLog << err << dbginf << "Syntax Error: Name of data member missing in '" << txt << "'" << endl;
    212             return NULL;
    213         }
    214 
    215         text = txt(0, i);
    216 
    217         txt.Remove(0, i);
    218     }
    219 
    220     txt = txt.Strip(TString::kBoth);
    221 
    222     if (txt.IsNull())
    223     {
    224         *fLog << err << dbginf << "Syntax Error: No conditional in '" << text << "'" << endl;
     163    // For backward compatibility
     164    txt.ReplaceAll("{", "(");
     165    txt.ReplaceAll("}", ")");
     166
     167    const Int_t fg = txt.First('>');
     168    const Int_t lg = txt.First('>');
     169    const Int_t fl = txt.First('<');
     170    const Int_t ll = txt.First('<');
     171
     172    if (fg<0 && fl<0)
     173    {
     174        *fLog << err << dbginf << "Syntax Error: No coditional sign found in " << txt << endl;
    225175        return NULL;
    226176    }
    227 
    228     char c;
    229     switch (txt[0])
    230     {
    231     case '>':
    232     case '<':
    233         c = txt[0];
    234         txt.Remove(0, 1);
    235         break;
    236 
    237     default:
    238         *fLog << err << dbginf << "Syntax Error: Conditional '" << txt[0] << "' unknown." << endl;
     177    if (fg>=0 && fl>=0)
     178    {
     179        *fLog << err << dbginf << "Syntax Error: Two coditional signs found in " << txt << endl;
     180        *fLog << "Currently you have to enclose all conditions in brackets, like: \"(x<y) && (z<5)\"" << endl;
    239181        return NULL;
    240182    }
    241 
    242     char *end;
    243     Double_t num = strtod(txt.Data(), &end);
    244     if (!end || txt.Data()==end)
    245     {
    246         *fLog << err << dbginf << "Error trying to convert '" << txt << "' to value." << endl;
     183    if (fg!=lg || fl!=ll)
     184    {
     185        *fLog << err << dbginf << "Syntax Error: Coditional sign found twice " << txt << endl;
    247186        return NULL;
    248187    }
    249188
    250     txt.Remove(0, end-txt.Data());
    251 
    252     MFilter *newfilter;
    253     if (isrule)
    254     {
    255         Int_t lvl = gLog.GetDebugLevel();
    256         gLog.SetDebugLevel(1);
    257         newfilter = new MFDataChain(text.Data(), c, num);
    258         newfilter->SetName(Form("Chain%02d%c%f", level, c, num));
    259         gLog.SetDebugLevel(lvl);
    260     }
    261     else
    262     {
    263         newfilter = new MFDataMember(text.Data(), c, num);
    264         newfilter->SetName(Form("%s%c%f", text.Data(), c, num));
    265     }
    266 
    267     return newfilter;
     189    const Int_t cond = fg<0 ? fl : fg;
     190
     191    const TString rule1 = txt(0, cond);
     192    const TString rule2 = txt(cond+1, txt.Length());
     193
     194    Int_t lvl = gLog.GetDebugLevel();
     195    gLog.SetDebugLevel(1);
     196    MFilter *f = new MFDataChain(rule1.Data(), txt[cond], rule2.Data());
     197    f->SetName(Form("Chain%02d%c", level, txt[cond]));
     198    gLog.SetDebugLevel(lvl);
     199
     200    txt = "";
     201
     202    return f;
    268203}
    269204// --------------------------------------------------------------------------
  • trunk/MagicSoft/Mars/mfbase/MF.h

    r3330 r3573  
    2323    MFilter *fF; // Filter
    2424
     25    Int_t IsRule(TString &txt, TString &rule) const;
     26    Int_t IsVal(const TString &txt) const;
    2527    Int_t IsAlNum(TString txt) const;
    2628
     
    4345    void Print(Option_t *opt="") const;
    4446
     47    void SetVariables(const TArrayD &arr) { if (fF) fF->SetVariables(arr); }
     48
    4549    ClassDef(MF, 0) // A Filter for cuts in any data member
    4650};
  • trunk/MagicSoft/Mars/mfbase/MFDataChain.cc

    r3330 r3573  
    4040// For example:
    4141//   MFDataChain filter("sqr(MHillas.fLength)", '<', 150);
     42//   MFDataChain filter("MHillas.fLength", '<', "MHillas.fWidth");
    4243//
    4344/////////////////////////////////////////////////////////////////////////////
     
    5051#include "MParList.h"
    5152
     53#include "MDataValue.h"
     54
    5255#include "MLog.h"
    5356#include "MLogManip.h"
     
    5760using namespace std;
    5861
     62MFDataChain::MFDataChain(const char *name, const char *title)
     63    : fCond(0)
     64{
     65    fName  = name  ? name  : "MFDataChain";
     66    fTitle = title ? title : "Filter using any data member of a class";
     67}
     68
    5969// --------------------------------------------------------------------------
    6070//
    61 MFDataChain::MFDataChain(const char *member, const char type, const Double_t val,
     71MFDataChain::MFDataChain(const char *rule, const char type, const Double_t val,
    6272                         const char *name, const char *title)
    63     : fData(member), fValue(val)
     73    : fData(rule), fCond(new MDataValue(val))
    6474{
    6575    fName  = name  ? name  : "MFDataChain";
     
    7484}
    7585
     86MFDataChain::MFDataChain(const char *rule, const char type, const char *cond,
     87                         const char *name, const char *title)
     88    : fData(rule), fCond(new MDataChain(cond))
     89{
     90    fName  = name  ? name  : "MFDataChain";
     91    fTitle = title ? title : "Filter using any data member of a class";
     92
     93    //AddToBranchList(member);
     94
     95    fFilterType = (type=='<' ? kELowerThan : kEGreaterThan);
     96
     97    if (type!='<' && type!='>')
     98        *fLog << warn << dbginf << "Warning: Neither '<' nor '>' specified... using '>'." << endl;
     99}
     100
     101MFDataChain::~MFDataChain()
     102{
     103    if (fCond)
     104        delete fCond;
     105}
     106
    76107// --------------------------------------------------------------------------
    77108//
    78109Int_t MFDataChain::PreProcess(MParList *plist)
    79110{
    80     return fData.PreProcess(plist);
     111    if (!fCond)
     112    {
     113        *fLog << "No condition available - don't call default constructor!" << endl;
     114        return kFALSE;
     115    }
     116    return fData.PreProcess(plist) && fCond->PreProcess(plist);
    81117}
    82118
     
    85121Int_t MFDataChain::Process()
    86122{
     123    const Double_t data = fData.GetValue();
     124    const Double_t cond = fCond->GetValue();
     125
    87126    switch (fFilterType)
    88127    {
    89128    case kELowerThan:
    90         fResult = (fData.GetValue() < fValue);
     129        fResult = (data < cond);
    91130        return kTRUE;
    92131    case kEGreaterThan:
    93         fResult = (fData.GetValue() > fValue);
     132        fResult = (data > cond);
    94133        return kTRUE;
    95134    }
     
    108147    out << fData.GetRule() << "\", '";
    109148    out << (fFilterType==kELowerThan?"<":">");
    110     out << "', " << fValue << ");" << endl;
     149    out << "', ";
     150
     151    if (fCond->InheritsFrom(MDataValue::Class()))
     152        out << ((MDataValue*)fCond)->GetValue();
     153    else
     154        out << "\"" << fCond->GetRule() << "\"";
     155
     156    out << ");" << endl;
    111157}
    112158
    113159TString MFDataChain::GetRule() const
    114160{
    115     TString ret = "{";
     161    TString ret;// = "{";
    116162    ret += fData.GetRule();
    117     ret += "}";
     163    //ret += "}";
    118164    ret += fFilterType==kELowerThan?"<":">";
    119165
    120166    TString str;
    121     str += fValue;
    122 
     167    str += fCond->GetRule();
    123168    ret += str.Strip(TString::kBoth);
    124169    return ret;
    125170}
    126 
  • trunk/MagicSoft/Mars/mfbase/MFDataChain.h

    r3330 r3573  
    2121private:
    2222    MDataChain fData;
     23    MData     *fCond;
    2324
    2425    typedef enum { kELowerThan, kEGreaterThan } FilterType_t;
     
    2627
    2728    Bool_t  fResult;           //!
    28     Double_t fValue;
    2929
    3030    void StreamPrimitive(ofstream &out) const;
     
    3434
    3535public:
    36     MFDataChain(const char *member, const char type, const Double_t val,
     36    MFDataChain(const char *name=NULL, const char *title=NULL);
     37    MFDataChain(const char *rule, const char type, const Double_t val,
    3738                const char *name=NULL, const char *title=NULL);
     39    MFDataChain(const char *rule, const char type, const char *cond,
     40                const char *name=NULL, const char *title=NULL);
     41    ~MFDataChain();
    3842
    3943    Bool_t IsExpressionTrue() const { return fResult; }
     
    4246    TString GetRule() const;
    4347
     48    void SetVariables(const TArrayD &arr)
     49    {
     50        fData.SetVariables(arr);
     51        if (fCond)
     52            fCond->SetVariables(arr);
     53    }
     54
    4455    ClassDef(MFDataChain, 1) // A Filter for cuts in any data member
    4556};
  • trunk/MagicSoft/Mars/mfbase/MFDataMember.cc

    r3330 r3573  
    167167    return ret+str.Strip(TString::kBoth);
    168168}
    169 
  • trunk/MagicSoft/Mars/mfbase/MFDataMember.h

    r3330 r3573  
    3939    TString GetRule() const;
    4040
     41    void SetVariables(const TArrayD &arr) { fData.SetVariables(arr); }
     42
    4143    ClassDef(MFDataMember, 1) // A Filter for cuts in any data member
    4244};
  • trunk/MagicSoft/Mars/mfbase/MFilterList.cc

    r3330 r3573  
    379379    return ret+")";
    380380}
     381
     382void MFilterList::SetVariables(const TArrayD &arr)
     383{
     384    fFilters.ForEach(MFilter, SetVariables)(arr);
     385}
  • trunk/MagicSoft/Mars/mfbase/MFilterList.h

    r3330 r3573  
    5353    Int_t PostProcess();
    5454
     55    void SetVariables(const TArrayD &arr);
     56
    5557    ClassDef(MFilterList, 1)            // List to combine several filters logically
    5658};
Note: See TracChangeset for help on using the changeset viewer.