Ignore:
Timestamp:
11/05/01 10:35:36 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r1020 r1030  
    7878MReadTree::MReadTree(const char *tname, const char *fname,
    7979                     const char *name, const char *title)
    80     : fNumEntry(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE)
     80    : fNumEntry(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE), fProgress(NULL)
    8181{
    8282    fName  = name  ? name  : "MReadTree";
     
    165165// --------------------------------------------------------------------------
    166166//
    167 // This is the implementation of the Auto Enabling Scheme.
    168 // For more information see MTask::AddBranchToList.
    169 // This function loops over all tasks in the tasklist and enables
    170 // all branches which are requested by the tasks.
    171 //
    172 // To enable 'unknown' branches which are not in the Branchlist of
    173 // the tasks you can call EnableBranch
     167// Checks whether a branch with the given name exists in the chain
     168// and sets the branch status of this branch corresponding to status.
     169//
     170void MReadTree::SetBranchStatus(TObject *branch, Bool_t status)
     171{
     172    //
     173    // Get branch name
     174    //
     175    const char *name = branch->GetName();
     176
     177    //
     178    // Check whether this branch really exists
     179    //
     180    if (!fChain->GetBranch(name))
     181        return;
     182
     183    //
     184    // Set the branch status
     185    //
     186    fChain->SetBranchStatus(name, status);
     187    *fLog << (status ? "Enabled" : "Disabled");
     188    *fLog << " subbranch '" << name << "'." << endl;
     189}
     190
     191// --------------------------------------------------------------------------
     192//
     193// Set the status of all branches in the list to status.
     194//
     195void MReadTree::SetBranchStatus(const TOrdCollection *list, Bool_t status)
     196{
     197    //
     198    // Loop over all subbranches in this master branch
     199    //
     200    TIter Next(list);
     201
     202    TObject *obj;
     203    while ((obj=Next()))
     204        SetBranchStatus(obj, status);
     205}
     206
     207// --------------------------------------------------------------------------
     208//
     209//  This is the implementation of the Auto Enabling Scheme.
     210//  For more information see MTask::AddBranchToList.
     211//  This function loops over all tasks in the tasklist and enables
     212//  all branches which are requested by the tasks.
     213//
     214//  To enable 'unknown' branches which are not in the Branchlist of
     215//  the tasks you can call EnableBranch
    174216//
    175217void MReadTree::EnableBranches(MParList *plist)
    176218{
    177     //
    178     // if auto enabling is off reject the request
    179     //
    180     if (!fAutoEnable)
    181         return;
    182 
    183219    //
    184220    // check whether branch choosing must be switched on
     
    198234
    199235    //
    200     // Loo over all tasks in the task list.
     236    // Loop over all tasks in the task list.
    201237    //
    202238    MTask *task;
    203239    TIter NextTask(tlist->GetList());
    204240    while ((task=(MTask*)NextTask()))
    205     {
    206         //
    207         // Loop over all branches of this task
    208         //
    209         TNamed *branch;
    210         TIter NextBranch(task->GetListOfBranches());
    211         while ((branch=(TNamed*)NextBranch()))
    212         {
    213             //
    214             // Get branch name to enable and enable the branch
    215             //
    216             const char *name = branch->GetName();
    217 
    218             *fLog << "Enabeling '" << name << "'." << endl;
    219 
    220             fChain->SetBranchStatus(name, kTRUE);
    221         }
    222     }
     241        SetBranchStatus(task->GetListOfBranches(), kTRUE);
     242}
     243
     244// --------------------------------------------------------------------------
     245//
     246//  The disables all subbranches of the given master branch.
     247//
     248void MReadTree::DisableSubBranches(TBranch *branch)
     249{
     250    //
     251    // This is not necessary, it would work without. But the output
     252    // may confuse the user...
     253    //
     254    if (fAutoEnable || fBranchChoosing)
     255        return;
     256
     257    SetBranchStatus(branch->GetListOfBranches(), kFALSE);
    223258}
    224259
     
    244279    if (!fNumEntries)
    245280    {
    246         *fLog << dbginf << "No entries found in chain (file/s)." << endl;
     281        *fLog << dbginf << "No entries found in file(s)." << endl;
    247282        return kFALSE;
    248283    }
     
    276311        if (fVetoList->FindObject(name))
    277312        {
    278             *fLog << "Branch " << name << " has veto... skipped." << endl;
     313            *fLog << "Master branch " << name << " has veto... skipped." << endl;
     314            DisableSubBranches(branch);
    279315            continue;
    280316        }
     
    299335            //
    300336            *fLog << dbginf << "Warning: Class '" << name << "' not existing in dictionary. Branch skipped." << endl;
     337            DisableSubBranches(branch);
    301338            continue;
    302339        }
     
    308345        fChain->SetBranchAddress(name, pcont);
    309346
    310         *fLog << "Branch " << name << " setup for reading." << endl;
     347        *fLog << "Master branch address " << name << " setup for reading." << endl;
    311348
    312349        num++;
    313350    }
    314351
    315     *fLog << "MReadTree setup " << num << " branches." << endl;
    316 
    317     EnableBranches(pList);
    318 
     352    *fLog << "MReadTree setup " << num << " master branches addresses." << endl;
     353
     354    //
     355    // If auto enabling scheme isn't disabled, do auto enabling
     356    //
     357    if (fAutoEnable)
     358        EnableBranches(pList);
     359
     360    //
     361    // If a progress bar is given set its range.
     362    //
    319363    if (fProgress)
    320364        fProgress->SetRange(0, fNumEntries);
     
    351395Bool_t MReadTree::DecEventNum(UInt_t dec)
    352396{
    353     //!
    354     //! this function makes Process() read the event one (or more) before
    355     //! the actual position (event) in the tree
    356     //!
    357     if (fNumEntry < dec/*+1*/)
    358     {
    359         *fLog << "MReadTree::SetPrevEvent: WARNING: " << fNumEntry/*-1*/ << "-" << dec << " out of Range." << endl;
     397    if (fNumEntry-dec >= fNumEntries)
     398    {
     399        *fLog << "MReadTree::DecEventNum: WARNING - Event " << fNumEntry << "-";
     400        *fLog << dec << "=" << (Int_t)fNumEntry-dec << " out of Range." << endl;
    360401        return kFALSE;
    361402    }
    362403
    363     fNumEntry -= dec/*+1*/;
     404    fNumEntry -= dec;
    364405    return kTRUE;
    365406}
     
    372413Bool_t MReadTree::IncEventNum(UInt_t inc)
    373414{
    374     //!
    375     //! this function makes Process() read the next (or more) after
    376     //! the actual position (event) in the tree
    377     //! (Be careful: IncEventNum() or IncEventNum(1) does not chenge anything
    378     //!  in the standard behaviour of the task)
    379     //!
    380     if (fNumEntry+inc/*-1*/ >= fNumEntries)
    381     {
    382         *fLog << "MReadTree::SkipEvents: WARNING: " << fNumEntry/*-1*/ << "+" << inc << " out of Range." << endl;
     415    if (fNumEntry+inc >= fNumEntries)
     416    {
     417        *fLog << "MReadTree::IncEventNum: WARNING - Event " << fNumEntry << "+";
     418        *fLog << inc << "=" << (Int_t)fNumEntry+inc << " out of Range." << endl;
    383419        return kFALSE;
    384420    }
    385421
    386     fNumEntry += inc/*-1*/;
     422    fNumEntry += inc;
    387423    return kTRUE;
    388424}
     
    390426// --------------------------------------------------------------------------
    391427//
    392 // this function makes Process() read event number nr next
     428// This function makes Process() read event number nr next
    393429//
    394430// Remark: You can use this function after instatiating you MReadTree-object
     
    397433Bool_t MReadTree::SetEventNum(UInt_t nr)
    398434{
    399     if (nr>=fNumEntries)
    400     {
    401         *fLog << "MReadTree::SetEventNum: WARNING: " << nr << " out of Range." << endl;
     435    if (nr >= fNumEntries)
     436    {
     437        *fLog << "MReadTree::SetEventNum: WARNING - " << nr << " out of Range." << endl;
    402438        return kFALSE;
    403439    }
     
    409445// --------------------------------------------------------------------------
    410446//
    411 // If you don't want that an object is created for this branch
    412 // and/or the branch address is set in the Preprocessing of
    413 // MReadTree use VetoBranch. This saves mainly memory space.
     447//  For the branch with the given name:
     448//   1) no object is automatically created
     449//   2) the branch address for this branch is not set
     450//      (because we lack the object, see 1)
     451//   3) The whole branch (exactly: all its subbranches) are disabled
     452//      this means are not read in memory by TTree:GetEntry
    414453//
    415454void MReadTree::VetoBranch(const char *name)
Note: See TracChangeset for help on using the changeset viewer.