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

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mfbase/MF.cc

    r5883 r5911  
    350350    if (!fF)
    351351    {
     352        if (IsAllowEmpty())
     353            return kTRUE;
     354
    352355        *fLog << err << dbginf << "No filter rule available." << endl;
    353356        return kFALSE;
     
    370373Int_t MF::Process()
    371374{
    372     return fF->CallProcess();
     375    return fF ? fF->CallProcess() : kTRUE;
    373376}
    374377
     
    379382Int_t MF::PostProcess()
    380383{
    381     return fF->CallPostProcess();
    382 }
    383 
    384 // --------------------------------------------------------------------------
    385 //
    386 // Return the result of the filter rule.
     384    return fF ? fF->CallPostProcess() : kTRUE;
     385}
     386
     387// --------------------------------------------------------------------------
     388//
     389// Return the result of the filter rule. If no filter available the
     390// condition is always true
    387391//
    388392Bool_t MF::IsExpressionTrue() const
    389393{
    390     return fF->IsConditionTrue();
     394    return fF ? fF->IsConditionTrue() : kTRUE;
    391395}
    392396
     
    398402TString MF::GetDataMember() const
    399403{
    400     return fF->GetDataMember();
     404    return fF ? fF->GetDataMember() : "";
    401405}
    402406
     
    422426}
    423427
     428// --------------------------------------------------------------------------
     429//
     430// Print the rule.
     431// if now filter is set up '<n/a>' is printed.
     432//
    424433void MF::Print(Option_t *opt) const
    425434{
    426435    *fLog << all << underline << GetDescriptor() << endl;
    427     fF->Print();
     436    if (fF)
     437        fF->Print();
     438    else
     439        *fLog << "<n/a>";
    428440    *fLog << endl << endl;
    429441}
     442
     443// --------------------------------------------------------------------------
     444//
     445// Check for corresponding entries in resource file and setup filters.
     446//
     447// Assuming your MF-filter is called (Set/GetName): MyFilter
     448//
     449// First you can setup whether the filter is inverted or not:
     450//     MyFilter.Inverted: yes, no  <default=no>
     451//
     452// Now setup the condition, eg:
     453//     MyFilter.Condition: MHillas.fSize<1000
     454// or
     455//     MyFilter.Condition: MHillas.fSize>500 && MHillas.fSize<10000
     456//
     457// If you want to use more difficult filters you can split the
     458// condition into subcondistions. Subcondistions are identified
     459// by {}-brackets. Avoid trailing 0's! For example:
     460//
     461//     MyFilter.Condition: MHillas.fSize>500 && {0} && {1}
     462//     MyFilter.0: MHillas.fSize>1000
     463//     MyFilter.1: MHillas.fSize<10000
     464//
     465// The numbering must be continous and start with 0. You can use
     466// a subcondition more than once. All {}-brackets are simply replaced
     467// by the correspodning conditions. The rules how conditions can
     468// be written can be found in the class description of MF and MDataChain.
     469//
     470Int_t MF::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
     471{
     472    Bool_t rc = kFALSE;
     473    if (IsEnvDefined(env, prefix, "Inverted", print))
     474    {
     475        rc = kTRUE;
     476        SetInverted(GetEnvValue(env, prefix, "Inverted", IsInverted()));
     477    }
     478
     479    if (!IsEnvDefined(env, prefix, "Condition", print))
     480        return rc;
     481
     482    TString rule = GetEnvValue(env, prefix, "Condition", "");
     483    rule.ReplaceAll(" ", "");
     484
     485    Int_t idx=0;
     486    while (1)
     487    {
     488        TString cond;
     489        if (IsEnvDefined(env, prefix, Form("%d", idx), print))
     490        {
     491            cond += "(";
     492            cond += GetEnvValue(env, prefix, Form("%d", idx), "");
     493            cond += ")";
     494        }
     495
     496        if (cond.IsNull())
     497            break;
     498
     499        rule.ReplaceAll(Form("{%d}", idx), cond);
     500        idx++;
     501    }
     502
     503    if (fF)
     504    {
     505        delete fF;
     506        fF = 0;
     507    }
     508
     509    if (rule.IsNull())
     510    {
     511        *fLog << warn << "MF::ReadEnv - WARNING: Empty condition found." << endl;
     512        SetAllowEmpty();
     513        return kTRUE;
     514    }
     515
     516    SetAllowEmpty(kFALSE);
     517
     518    if (!(fF=ParseString(rule, 1)))
     519    {
     520        *fLog << err << "MF::ReadEnv - ERROR: Parsing '" << rule << "' failed." << endl;
     521        return kERROR;
     522    }
     523
     524    if (print)
     525    {
     526        *fLog << inf << "found: ";
     527        fF->Print();
     528        *fLog << endl;
     529    }
     530
     531    return kTRUE;
     532}
  • trunk/MagicSoft/Mars/mfbase/MF.h

    r5875 r5911  
    3232    void StreamPrimitive(ofstream &out) const;
    3333
     34    enum { kAllowEmpty = BIT(14) };
     35
    3436public:
    3537    MF();
     
    3739    ~MF();
    3840
     41    // MF
     42    void SetAllowEmpty(Bool_t b=kTRUE) { b ? SetBit(kAllowEmpty) : ResetBit(kAllowEmpty); }
     43    Bool_t IsAllowEmpty() const { return TestBit(kAllowEmpty); }
     44
     45    // MFilter
    3946    TString GetRule() const { return fF ? fF->GetRule() : MFilter::GetRule(); }
    4047    TString GetDataMember() const;
     
    4249    Bool_t IsExpressionTrue() const;
    4350
     51    // MTask
    4452    Int_t PreProcess(MParList *pList);
    4553    Int_t Process();
    4654    Int_t PostProcess();
    4755
     56    // TObject
    4857    void Print(Option_t *opt="") const;
    4958
     59    // MParContainer
    5060    void SetVariables(const TArrayD &arr) { if (fF) fF->SetVariables(arr); }
     61    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
    5162
    5263    ClassDef(MF, 0) // A Filter for cuts in any data member
  • trunk/MagicSoft/Mars/mfbase/MFilterList.cc

    r5875 r5911  
    439439}
    440440
    441 
     441// --------------------------------------------------------------------------
     442//
     443// Loop over all set filters and distribute arr to their SetVariables.
     444// Make sure, that the values are unique (not two filters using the
     445// same index in the array with different meanings)
     446//
    442447void MFilterList::SetVariables(const TArrayD &arr)
    443448{
Note: See TracChangeset for help on using the changeset viewer.