Ignore:
Timestamp:
08/05/02 14:30:21 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
7 edited

Legend:

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

    r1476 r1481  
    7070#include "MEvtLoop.h"
    7171
    72 #include <time.h>
    73 #include <fstream.h>     // ofstream, SavePrimitive
     72#include <time.h>           // time_t
     73#include <fstream.h>        // ofstream, SavePrimitive
    7474#include <iostream.h>
    7575
    76 #include <TSystem.h>
     76#include <TFile.h>          // gFile
     77#include <TSystem.h>        // gSystem
    7778#include <TStopwatch.h>
    7879#include <TGProgressBar.h>
     
    352353// to a macro. In the original root implementation it is used to write
    353354// gui elements to a macro-file.
    354 
    355355//
    356356void MEvtLoop::SavePrimitive(ofstream &out, Option_t *)
    357357{
    358     fParList->SavePrimitive(out);
     358    if (HasDuplicateNames("MEvtLoop::SavePrimitive"))
     359    {
     360        out << "   // !" << endl;
     361        out << "   // ! WARNING - Your eventloop (MParList, MTaskList, ...) contains more than" << endl;
     362        out << "   // ! one object (MParContainer, MTask, ...) with the same name. The created macro" << endl;
     363        out << "   // ! may need manual intervention before it can be used." << endl;
     364        out << "   // !" << endl;
     365        out << endl;
     366    }
     367
     368    if (fParList)
     369        fParList->SavePrimitive(out);
    359370
    360371    out << "   MEvtLoop evtloop;" << endl;
    361     out << "   evtloop.SetParList(&" << ToLower(fParList->GetName()) << ");" << endl;
     372    if (fParList)
     373        out << "   evtloop.SetParList(&" << ToLower(fParList->GetName()) << ");" << endl;
     374    else
     375        out << "   // fParList empty..." << endl;
    362376    out << "   if (!evtloop.Eventloop())" << endl;
    363377    out << "      return;" << endl;
    364378}
    365379
     380// --------------------------------------------------------------------------
     381//
     382// Get a list of all conmtainer names which are somehow part of the
     383// eventloop. Chack for duplicate members and print a warning if
     384// duplicates are found. Return kTRUE if duplicates are found, otherwise
     385// kFALSE;
     386//
     387Bool_t MEvtLoop::HasDuplicateNames(TObjArray &arr, const TString txt) const
     388{
     389    arr.Sort();
     390
     391    TIter Next(&arr);
     392    TObject *obj;
     393    TString name;
     394    Bool_t found = kFALSE;
     395    while ((obj=Next()))
     396    {
     397        if (name==obj->GetName())
     398        {
     399            if (!found)
     400            {
     401                *fLog << warn << endl;
     402                *fLog << " ! WARNING (" << txt << ")" << endl;
     403                *fLog << " ! Your eventloop (MParList, MTaskList, ...) contains more than" << endl;
     404                *fLog << " ! one object (MParContainer, MTask, ...) with the same name." << endl;
     405                *fLog << " ! Creating a macro from it using MEvtLoop::MakeMacro may create" << endl;
     406                *fLog << " ! a macro which needs manual intervention before it can be used." << endl;
     407                found = kTRUE;
     408            }
     409            *fLog << " ! Please rename: " << obj->GetName() << endl;
     410        }
     411        name = obj->GetName();
     412    }
     413
     414    return found;
     415}
     416
     417// --------------------------------------------------------------------------
     418//
     419// Get a list of all conmtainer names which are somehow part of the
     420// eventloop. Chack for duplicate members and print a warning if
     421// duplicates are found. Return kTRUE if duplicates are found, otherwise
     422// kFALSE;
     423//
     424Bool_t MEvtLoop::HasDuplicateNames(const TString txt) const
     425{
     426    if (!fParList)
     427        return kFALSE;
     428
     429    TObjArray list;
     430    list.SetOwner();
     431
     432    fParList->GetNames(list);
     433
     434    return HasDuplicateNames(list, txt);
     435}
     436
     437// --------------------------------------------------------------------------
     438//
     439// Reads a saved eventloop from a file. The default name is "Evtloop".
     440// Therefor an open file must exist (See TFile for more information)
     441//
     442//  eg:
     443//        TFile file("myfile.root", "READ");
     444//        MEvtLoop evtloop;
     445//        evtloop.Read();
     446//        evtloop.MakeMacro("mymacro");
     447//
    366448Int_t MEvtLoop::Read(const char *name)
    367449{
     450    if (!gFile)
     451    {
     452        *fLog << err << "MEvtloop::Read: No file found. Please create a TFile first." << endl;
     453        return 0;
     454    }
     455
     456    if (!gFile->IsOpen())
     457    {
     458        *fLog << err << "MEvtloop::Read: File not open. Please open the TFile first." << endl;
     459        return 0;
     460    }
     461
    368462    Int_t n = 0;
    369463    TObjArray list;
    370464
    371465    n += TObject::Read(name);
     466
     467    if (n==0)
     468    {
     469        *fLog << err << "MEvtloop::Read: No objects read." << endl;
     470        return 0;
     471    }
     472
    372473    n += list.Read((TString)name+"_names");
    373474
    374475    fParList->SetNames(list);
    375476
     477    HasDuplicateNames(list, "MEvtLoop::Read");
     478
    376479    return n;
    377480}
    378481
     482// --------------------------------------------------------------------------
     483//
     484// Writes a eventloop to a file. The default name is "Evtloop".
     485// Therefor an open file must exist (See TFile for more information)
     486//
     487//  eg:
     488//        TFile file("myfile.root", "RECREATE");
     489//        MEvtLoop evtloop;
     490//        evtloop.Write();
     491//        file.Close();
     492//
    379493Int_t MEvtLoop::Write(const char *name, Int_t option, Int_t bufsize)
    380494{
     495    if (!gFile)
     496    {
     497        *fLog << err << "MEvtloop::Write: No file found. Please create a TFile first." << endl;
     498        return 0;
     499    }
     500
     501    if (!gFile->IsOpen())
     502    {
     503        *fLog << err << "MEvtloop::Write: File not open. Please open the TFile first." << endl;
     504        return 0;
     505    }
     506
     507    if (!gFile->IsWritable())
     508    {
     509        *fLog << err << "MEvtloop::Write: File not writable." << endl;
     510        return 0;
     511    }
     512
    381513    Int_t n = 0;
    382514
     
    386518    fParList->GetNames(list);
    387519
     520    n += TObject::Write(name, option, bufsize);
     521
     522    if (n==0)
     523    {
     524        *fLog << err << "MEvtloop::Read: No objects written." << endl;
     525        return 0;
     526    }
     527
    388528    n += list.Write((TString)name+"_names", kSingleKey);
    389     n += TObject::Write(name, option, bufsize);
     529
     530    HasDuplicateNames(list, "MEvtLoop::Write");
    390531
    391532    return n;
  • trunk/MagicSoft/Mars/mbase/MEvtLoop.h

    r1474 r1481  
    2727
    2828    enum { kIsOwner = BIT(14) };
     29
     30    Bool_t HasDuplicateNames(const TString txt) const;
     31    Bool_t HasDuplicateNames(TObjArray &arr, const TString txt) const;
    2932
    3033public:
  • trunk/MagicSoft/Mars/mbase/MFilter.cc

    r1211 r1481  
    9898    return kTRUE;
    9999}
     100
     101TString MFilter::GetRule() const
     102{
     103    return "<GetRule not available for " + fName + ">";
     104}
  • trunk/MagicSoft/Mars/mbase/MFilter.h

    r1211 r1481  
    1919    virtual Bool_t PostProcess();
    2020
     21    virtual TString GetRule() const;
     22
    2123    ClassDef(MFilter, 0)                // Abstract base class for the filters
    2224};
  • trunk/MagicSoft/Mars/mbase/MFilterList.cc

    r1283 r1481  
    3131#include "MFilterList.h"
    3232
     33#include <fstream.h>
     34
    3335#include <TString.h>
    3436
     
    5355//      lor, ||  : is a logical or
    5456//
    55 MFilterList::MFilterList(const char *type)
    56 {
     57MFilterList::MFilterList(const char *type, const char *name, const char *title)
     58{
     59    fName  = name  ? name  : "MFilterList";
     60    fTitle = title ? title : "List combining filters logically.";
     61
    5762    fFilterType = kEAnd;
    5863
     
    236241void MFilterList::Print(Option_t *opt) const
    237242{
     243    *fLog << all << GetRule(opt) << flush;
     244}
     245
     246// --------------------------------------------------------------------------
     247//
     248// Implementation of SavePrimitive. Used to write the call to a constructor
     249// to a macro. In the original root implementation it is used to write
     250// gui elements to a macro-file.
     251//
     252void MFilterList::StreamPrimitive(ofstream &out) const
     253{
     254    out << "   MFilterList " << ToLower(fName) << "(\"";
     255
     256    switch (fFilterType)
     257    {
     258    case kEAnd:
     259        out << "&";
     260        break;
     261
     262    case kEOr:
     263        out  << "|";
     264        break;
     265
     266    case kEXor:
     267        out  << "^";
     268        break;
     269
     270    case kELAnd:
     271        out << "&&";
     272        break;
     273
     274    case kELOr:
     275        out << "||";
     276        break;
     277    }
     278
     279    out << fName << "\", \"" << fName << "\", \"" << fTitle << "\");" << endl << endl;
     280
     281    TIter Next(&fFilters);
     282
     283    TObject *cont = NULL;
     284    while ((cont=Next()))
     285    {
     286        cont->SavePrimitive(out, "");
     287
     288        out << "   " << ToLower(fName) << ".AddToList(&";
     289        out << ToLower(cont->GetName()) << ");" << endl << endl;
     290    }
     291}
     292
     293TString MFilterList::GetRule(Option_t *opt) const
     294{
    238295    TString str(opt);
    239296    const Bool_t verbose = str.Contains("V", TString::kIgnoreCase);
    240297
    241     //*fLog << all << "(" << GetName() << "=" << (int)fFilterType << ")";
    242 
    243     *fLog << all << "(";
     298    TString ret = "(";
    244299
    245300    TIter Next(&fFilters);
     
    251306    //
    252307    if (!filter)
    253     {
    254         *fLog << "<empty>)" << flush;
    255         return;
    256     }
    257 
    258     filter->Print();
     308        return "<empty>";
     309
     310    ret += filter->GetRule();
    259311
    260312    while ((filter=(MFilter*)Next()))
     
    263315        {
    264316        case kEAnd:
    265             *fLog << (verbose?" and ":" & ");
     317            ret += (verbose?" and ":" & ");
    266318            break;
    267319
    268320        case kEOr:
    269             *fLog << (verbose?" or ":" | ");
     321            ret += (verbose?" or ":" | ");
    270322            break;
    271323
    272324        case kEXor:
    273             *fLog << (verbose?" xor ":" ^ ");
     325            ret += (verbose?" xor ":" ^ ");
    274326            break;
    275327
    276328        case kELAnd:
    277             *fLog << (verbose?" land ":" && ");
     329            ret += (verbose?" land ":" && ");
    278330            break;
    279331
    280332        case kELOr:
    281             *fLog << (verbose?" lor ":" || ");
     333            ret += (verbose?" lor ":" || ");
    282334            break;
    283335        }
    284336
    285         filter->Print();
    286     }
    287 
    288     *fLog << ")" << flush;
    289 }
    290 
     337        ret += filter->GetRule();
     338    }
     339
     340    return ret+")";
     341}
  • trunk/MagicSoft/Mars/mbase/MFilterList.h

    r1020 r1481  
    2929    enum { kIsOwner = BIT(14) };
    3030
     31    void StreamPrimitive(ofstream &out) const;
     32
    3133public:
    32     MFilterList(const char *type="&&");
     34    MFilterList(const char *type="&&", const char *name=NULL, const char *title=NULL);
    3335    MFilterList(MFilterList &ts);
    3436    ~MFilterList()
     
    4850
    4951    void Print(Option_t *opt = "") const;
     52    TString GetRule(Option_t *opt="") const;
    5053
    51     ClassDef(MFilterList, 0)            // List to combine several filters logically
     54    ClassDef(MFilterList, 1)            // List to combine several filters logically
    5255};
    5356
  • trunk/MagicSoft/Mars/mbase/MTask.h

    r1477 r1481  
    2424    TList *fListOfBranches; //! List of Branch names for auto enabeling scheme
    2525
    26     const MFilter *fFilter; // Filter for conditional task execution
     26    MFilter *fFilter;      // Filter for conditional task execution
    2727
    2828    Bool_t fIsPreprocessed; //! Indicates the success of the PreProcessing (set by MTaskList)
     
    6868    virtual ~MTask();
    6969
    70     void SetFilter(const MFilter *filter) { fFilter=filter; }
     70    void SetFilter(MFilter *filter) { fFilter=filter; }
    7171    const MFilter *GetFilter() const      { return fFilter; }
    7272    virtual void PrintStatistics(const Int_t lvl=0) const;
Note: See TracChangeset for help on using the changeset viewer.