Ignore:
Timestamp:
03/27/01 16:05:54 (24 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r666 r706  
    1818
    1919#include <TFile.h>
    20 #include <TTree.h>
     20#include <TChain.h>
    2121#include <TObjArray.h>
    2222
    2323#include "MLog.h"
     24#include "MLogManip.h"
     25
    2426#include "MTime.h"
    2527#include "MParList.h"
     
    2729ClassImp(MReadTree)
    2830
    29 MReadTree::MReadTree(const char *fname, const char *tname,
     31MReadTree::MReadTree(const char *tname, const char *fname,
    3032                     const char *name, const char *title)
    3133{
     
    3638    // open the input stream
    3739    //
    38     fFileName = fname;
    39     fTreeName = tname;
     40    fChain = new TChain(tname);
     41
     42    if (fname)
     43        fChain->Add(fname);
     44}
     45
     46MReadTree::~MReadTree()
     47{
     48    delete fChain;
     49}
     50
     51/*Int_t*/ void MReadTree::AddFile(const char *fname)
     52{
     53    //
     54    // FIXME! A check is missing whether the file already exists or not.
     55    //
     56    //
     57    // returns the number of file which were added
     58    //
     59    /*return  root >3.0*/ fChain->Add(fname);
    4060}
    4161
     
    4565    // open file and check if file is really open
    4666    //
    47     fFile = new TFile(fFileName, "READ");
    48 
    49     if (!fFile->IsOpen())
    50     {
    51         *fLog << "MReadTree::PreProcess: ERROR: Cannot open file '";
    52         *fLog << fFileName << "'" << endl;
    53         return kFALSE;
    54     }
    55 
    56     //
    57     // try to get the tree and check if it was found
    58     //
    59     fTree = (TTree*)fFile->Get(fTreeName);
    60     if (!fTree)
    61     {
    62         *fLog << "MReadTree::PreProcess: ERROR: Cannot open tree '";
    63         *fLog << fTreeName << "'" << endl;
    64         return kFALSE;
    65     }
    6667
    6768    //
    6869    // get number of events in this tree
    6970    //
    70     fNumEntries = (UInt_t)fTree->GetEntries();
     71    fNumEntries = (UInt_t)fChain->GetEntries();
     72
     73    if (!fNumEntries)
     74    {
     75        *fLog << dbginf << "No Entries found in chain (file/s)." << endl;
     76        return kFALSE;
     77    }
    7178
    7279    //
     
    7885    // output logging information
    7986    //
    80     *fLog << "File: '" << fFileName << "'  Tree: '" << fTreeName;
    81     *fLog << "' with " << fNumEntries << " Entries opened." << endl;
     87    *fLog << fNumEntries << " Entries found in file(s)." << endl;
    8288
    8389    //
     
    8591    // create the Iterator to loop over all branches
    8692    //
    87     TIter Next(fTree->GetListOfBranches());
     93    TIter Next(fChain->GetListOfBranches());
    8894    TBranch *branch=NULL;
    8995   
     
    102108        //
    103109        MParContainer *pcont = pList->FindCreateObj(name);
     110       
    104111
    105112        if (!pcont)
     
    134141    // get entry
    135142    //
    136     fTree->GetEntry(fNumEntry );
     143    fChain->GetEntry(fNumEntry );
    137144
    138145    fNumEntry ++ ;
     
    146153    // Close File
    147154    //
    148     fFile->Close();
     155    //fFile->Close();
    149156
    150157    return kTRUE;
     
    156163    // Get the Event with the current EventNumber fNumEntry
    157164    //
    158     fTree->GetEntry(fNumEntry);
     165    fChain->GetEntry(fNumEntry);
    159166
    160167    return kTRUE;
Note: See TracChangeset for help on using the changeset viewer.