library: libTree
#include "TChain.h"

TChain


class description - header file - source file - inheritance tree (.pdf)

class TChain : public TTree

Inheritance Chart:
TObject
<-
TNamed
TAttLine
TAttFill
TAttMarker
<-
TTree
<-
TChain

    protected:
TChain(const TChain&) virtual TDSet* MakeTDSetWithoutFriends() const TChain& operator=(const TChain&) void ReleaseChainProof() public:
TChain() TChain(const char* name, const char* title = "") virtual ~TChain() virtual Int_t Add(TChain* chain) virtual Int_t Add(const char* name, Long64_t nentries = kBigNumber) virtual Int_t AddFile(const char* name, Long64_t nentries = kBigNumber, const char* tname = "") virtual Int_t AddFileInfoList(TList* list, Long64_t nfiles = kBigNumber) virtual TFriendElement* AddFriend(const char* chainname, const char* dummy = "") virtual TFriendElement* AddFriend(const char* chainname, TFile* dummy) virtual TFriendElement* AddFriend(TTree* chain, const char* alias, Bool_t warn = kFALSE) virtual void Browse(TBrowser* b) virtual void CanDeleteRefs(Bool_t flag = kTRUE) static TClass* Class() virtual void CreatePackets() virtual Long64_t Draw(const char* varexp, const TCut& selection, Option_t* option = "", Long64_t nentries = kBigNumber, Long64_t firstentry = 0) virtual Long64_t Draw(const char* varexp, const char* selection, Option_t* option = "", Long64_t nentries = kBigNumber, Long64_t firstentry = 0) virtual void Draw(Option_t* opt) virtual Int_t Fill() virtual TBranch* FindBranch(const char* name) virtual TLeaf* FindLeaf(const char* name) virtual const char* GetAlias(const char* aliasName) const virtual TBranch* GetBranch(const char* name) virtual Bool_t GetBranchStatus(const char* branchname) const virtual Long64_t GetChainEntryNumber(Long64_t entry) const virtual Long64_t GetEntries() const virtual Int_t GetEntry(Long64_t entry = 0, Int_t getall = 0) virtual Int_t GetEntryWithIndex(Int_t major, Int_t minor = 0) TFile* GetFile() const virtual TLeaf* GetLeaf(const char* name) virtual TObjArray* GetListOfBranches() TObjArray* GetListOfFiles() const virtual TObjArray* GetListOfLeaves() virtual Double_t GetMaximum(const char* columname) virtual Double_t GetMinimum(const char* columname) virtual Int_t GetNbranches() Int_t GetNtrees() const virtual Long64_t GetReadEntry() const TList* GetStatus() const virtual TTree* GetTree() const virtual Int_t GetTreeNumber() const Long64_t* GetTreeOffset() const Int_t GetTreeOffsetLen() const virtual Double_t GetWeight() const virtual TClass* IsA() const virtual Int_t LoadBaskets(Long64_t maxmemory) virtual Long64_t LoadTree(Long64_t entry) void Lookup() virtual void Loop(Option_t* option = "", Long64_t nentries = kBigNumber, Long64_t firstentry = 0) virtual void ls(Option_t* option = "") const virtual TDSet* MakeTDSet() const virtual Long64_t Merge(const char* name, Option_t* option = "") virtual Long64_t Merge(TCollection* list, Option_t* option = "") virtual Long64_t Merge(TFile* file, Int_t basketsize, Option_t* option = "") virtual void Print(Option_t* option = "") const virtual Long64_t Process(const char* filename, Option_t* option = "", Long64_t nentries = kBigNumber, Long64_t firstentry = 0) virtual Long64_t Process(TSelector* selector, Option_t* option = "", Long64_t nentries = kBigNumber, Long64_t firstentry = 0) virtual void Reset(Option_t* option = "") virtual void ResetBranchAddresses() virtual Long64_t Scan(const char* varexp = "", const char* selection = "", Option_t* option = "", Long64_t nentries = 1000000000, Long64_t firstentry = 0) virtual void SetAutoDelete(Bool_t autodel = kTRUE) virtual void SetBranchAddress(const char* bname, void* add, TBranch** ptr = 0) virtual void SetBranchAddress(const char* bname, void* add, TBranch** ptr, TClass* realClass, EDataType datatype, Bool_t isptr) virtual void SetBranchAddress(const char* bname, void* add, TClass* realClass, EDataType datatype, Bool_t isptr) virtual void SetBranchStatus(const char* bname, Bool_t status = 1, UInt_t* found = 0) virtual void SetDirectory(TDirectory* dir) virtual void SetMakeClass(Int_t make) virtual void SetPacketSize(Int_t size = 100) virtual void SetProof(TVirtualProof* proof = (TVirtualProof*)-1, Bool_t refresh = kFALSE, Bool_t gettreeheader = kFALSE) virtual void SetWeight(Double_t w = 1, Option_t* option = "") virtual void ShowMembers(TMemberInspector& insp, char* parent) virtual void Streamer(TBuffer& b) void StreamerNVirtual(TBuffer& b) virtual void UseCache(Int_t maxCacheSize = 10, Int_t pageSize = 0)

Data Members


    protected:
Int_t fTreeOffsetLen Current size of fTreeOffset array Int_t fNtrees Number of Trees Int_t fTreeNumber ! Current Tree number in fTreeOffset table Long64_t* fTreeOffset [fTreeOffsetLen]Array of variables Bool_t fCanDeleteRefs ! if true, TProcessIDs are deleted when closing a file TTree* fTree ! Pointer to current tree TFile* fFile ! Pointer to current file TObjArray* fFiles -> List of file names containing the Trees TList* fStatus -> List of active/inactive branches TChainProof* fChainProof ! wrapper class for a TDSet if this chain is to be public:
static const enum TChain:: kGlobalWeight static const enum TChain:: kAutoDelete static const enum TChain:: kBigNumber

Class Description

                                                                      
 TChain                                                               
                                                                      
 A chain is a collection of files containg TTree objects.             
 When the chain is created, the first parameter is the default name   
 for the Tree to be processed later on.                               
                                                                      
 Enter a new element in the chain via the TChain::Add function.       
 Once a chain is defined, one can use the normal TTree functions      
 to Draw,Scan,etc.                                                    
                                                                      
 Use TChain::SetBranchStatus to activate one or more branches for all 
 the trees in the chain.                                              
                                                                      

TChain()
*-*-*-*-*-*Default constructor for Chain*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*        ==============================
TChain(const char *name, const char *title)
*-*-*-*-*-*-*-*-*-*-*-*-*Create a Chain*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*                      ==============

   A TChain is a collection of TFile objects.
    the first parameter "name" is the name of the TTree object
    in the files added with Add.
   Use TChain::Add to add a new element to this chain.

   In case the Tree is in a subdirectory, do, eg:
     TChain ch("subdir/treename");

    Example:
  Suppose we have 3 files f1.root, f2.root and f3.root. Each file
  contains a TTree object named "T".
     TChain ch("T");  creates a chain to process a Tree called "T"
     ch.Add("f1.root");
     ch.Add("f2.root");
     ch.Add("f3.root");
     ch.Draw("x");
       The Draw function above will process the variable "x" in Tree "T"
       reading sequentially the 3 files in the chain ch.

*-*
TChain(const TChain& tc)
copy constructor
TChain& operator=(const TChain& tc)
assignement operator
~TChain()
 destructor for a Chain
Int_t Add(TChain *chain)
 Add all files referenced by the TChain chain to this chain.
Int_t Add(const char *name, Long64_t nentries)
 Add a new file to this chain.
 Argument name may have the following format:
   //machine/file_name.root/subdir/tree_name
 machine, subdir and tree_name are optional. If tree_name is missing,
 the chain name will be assumed.
 Name may use the wildcarding notation, eg "xxx*.root" means all files
 starting with xxx in the current file system directory.
 NB. To add all the files of a TChain to a chain, use Add(TChain *chain).

    A- if nentries <= 0, the file is connected and the tree header read
       in memory to get the number of entries.

    B- if (nentries > 0, the file is not connected, nentries is assumed to be
       the number of entries in the file. In this case, no check is made that
       the file exists and the Tree existing in the file. This second mode
       is interesting in case the number of entries in the file is already stored
       in a run data base for example.

    C- if (nentries == kBigNumber) (default), the file is not connected.
       the number of entries in each file will be read only when the file
       will need to be connected to read an entry.
       This option is the default and very efficient if one process
       the chain sequentially. Note that in case TChain::GetEntry(entry)
       is called and entry refers to an entry in the 3rd file, for example,
       this forces the Tree headers in the first and second file
       to be read to find the number of entries in these files.
       Note that if one calls TChain::GetEntriesFast() after having created
       a chain with this default, GetEntriesFast will return kBigNumber!
       TChain::GetEntries will force of the Tree headers in the chain to be
       read to read the number of entries in each Tree.
Int_t AddFile(const char *name, Long64_t nentries, const char *tname)
       Add a new file to this chain.
       If tname is specified, the chain will load the tree named tname
       from the file, otherwise the original treename specified in the
       TChain constructor will be used.

    A- if nentries <= 0, the file is connected and the tree header read
       in memory to get the number of entries.

    B- if (nentries > 0, the file is not connected, nentries is assumed to be
       the number of entries in the file. In this case, no check is made that
       the file exists and the Tree existing in the file. This second mode
       is interesting in case the number of entries in the file is already stored
       in a run data base for example.

    C- if (nentries == kBigNumber) (default), the file is not connected.
       The number of entries in each file will be read only when the file
       will need to be connected to read an entry.
       This option is the default and very efficient if one processes
       the chain sequentially. Note that in case TChain::GetEntry(entry)
       is called and entry refers to an entry in the 3rd file, for example,
       this forces the Tree headers in the first and second file
       to be read to find the number of entries in these files.
       Note that if one calls TChain::GetEntriesFast() after having created
       a chain with this default, GetEntriesFast will return kBigNumber!
       TChain::GetEntries will force of the Tree headers in the chain to be
       read to read the number of entries in each Tree.
Int_t AddFileInfoList(TList *fileinfolist, Long64_t nfiles)
 Add all files referenced in the List of TFileInfo objects to the chain.
TFriendElement * AddFriend(const char *chain, const char *dummy)
 Add a TFriendElement to the list of friends of this chain.

   A TChain has a list of friends similar to a tree (see TTree::AddFriend).
 You can add a friend to a chain with the TChain::AddFriend method, and you
 can retrieve the list of friends with TChain::GetListOfFriends.
 This example has four chains each has 20 ROOT trees from 20 ROOT files.

 TChain ch("t"); // a chain with 20 trees from 20 files
 TChain ch1("t1");
 TChain ch2("t2");
 TChain ch3("t3");
 Now we can add the friends to the first chain.

 ch.AddFriend("t1")
 ch.AddFriend("t2")
 ch.AddFriend("t3")


 The parameter is the name of friend chain (the name of a chain is always
 the name of the tree from which it was created).
 The original chain has access to all variable in its friends.
 We can use the TChain::Draw method as if the values in the friends were
 in the original chain.
 To specify the chain to use in the Draw method, use the syntax:

 <chainname>.<branchname>.<varname>
 If the variable name is enough to uniquely identify the variable, you can
 leave out the chain and/or branch name.
 For example, this generates a 3-d scatter plot of variable "var" in the
 TChain ch versus variable v1 in TChain t1 versus variable v2 in TChain t2.

 ch.Draw("var:t1.v1:t2.v2");
 When a TChain::Draw is executed, an automatic call to TTree::AddFriend
 connects the trees in the chain. When a chain is deleted, its friend
 elements are also deleted.

 The number of entries in the friend must be equal or greater to the number
 of entries of the original chain. If the friend has fewer entries a warning
 is given and the resulting histogram will have missing entries.
 For additional information see TTree::AddFriend.
TFriendElement * AddFriend(const char *chain, TFile *dummy)
 Add the whole chain or tree as a friend of this chain
TFriendElement * AddFriend(TTree *chain, const char* alias, Bool_t /*warn*/)
{
 Add the whole chain or tree as a friend of this chain

if (!fFriends) fFriends = new TList();
TFriendElement *fe = new TFriendElement(this,chain,alias);
R__ASSERT(fe);

fFriends->Add(fe);

 We need to invalidate the loading of the current tree because its list
 of real friend is now obsolete.  It is repairable only from LoadTree
fTreeNumber = -1;

TTree *t = fe->GetTree();
if (!t) {
void Browse(TBrowser *b)
 Browse contain of the chain
void CanDeleteRefs(Bool_t flag)
 when closing a file during the chain processing, the file
 may be closed with option "R" if flag is set to kTRUE.
 by default flag is kTRUE.
 When closing a file with option "R", all TProcessIDs referenced by this
 file are deleted.
 Calling TFile::Close("R") might be necessary in case one reads a long list
 of files having TRef, writing some of the referenced objects or TRef
 to a new file. If the TRef or referenced objects of the file being closed
 will not be referenced again, it is possible to minimize the size
 of the TProcessID data structures in memory by forcing a delete of
 the unused TProcessID.
void CreatePackets()
 Initialize the packet descriptor string
Long64_t Draw(const char *varexp, const TCut &selection, Option_t *option, Long64_t nentries, Long64_t firstentry)
 Draw expression varexp for selected entries.

 This function accepts TCut objects as arguments.
 Useful to use the string operator +, example:
    ntuple.Draw("x",cut1+cut2+cut3);

Long64_t Draw(const char *varexp, const char *selection, Option_t *option,Long64_t nentries, Long64_t firstentry)
 Process all entries in this chain and draw histogram
 corresponding to expression varexp.
TBranch * GetBranch(const char *name)
 Return pointer to the branch name in the current tree.
Long64_t GetChainEntryNumber(Long64_t entry)
 Return absolute entry number in the chain the input parameter
 entry is the entry number in the current Tree of this chain.
Long64_t GetEntries()
 Return the total number of entries in the chain.  In case the
 number of entries in each tree is not yet known, the offset table
 is computed.
Int_t GetEntry(Long64_t entry, Int_t getall)
 Get entry from the file to memory

     getall = 0 : get only active branches
     getall = 1 : get all branches

 return the total number of bytes read
 o bytes read indicates a failure.
Int_t GetEntryWithIndex(Int_t major, Int_t minor)
 Return entry  corresponding to major and minor number
 For example:
     Int_t run   = 1234;
     Int_t event = 345;
     Long64_t serial= chain.GetEntryNumberWithIndex(run,event);
    now the variable serial is in the range [0,nentries] and one can do
    chain.GetEntry(serial);

 WARNING: This function will not work if teh chain has friend chains.
TFile * GetFile()
  Return a pointer to the current file.
  if no file is connected, the first file is automatically loaded.
TLeaf * GetLeaf(const char *name)
  Return pointer to the leaf name in the current tree
TObjArray * GetListOfBranches()
 Return pointer to list of branches of current tree
TObjArray * GetListOfLeaves()
 Return pointer to list of leaves of current tree
Double_t GetMaximum(const char *columname)
 Return maximum of column with name columname
Double_t GetMinimum(const char *columname)
 Return minimum of column with name columname
Int_t GetNbranches()
 Return number of branches of current tree
const char * GetAlias(const char *aliasName)
 Returns the expanded value of the alias.  Search in the friend if any
Double_t GetWeight()
  return the chain weight.
  by default, the weight is the weight of the current Tree in the TChain.
  However, if the weight has been set in TChain::SetWeight with
  the option "global", each Tree will use the same weight stored
  in TChain::fWeight.
Long64_t LoadTree(Long64_t entry)
  The input argument entry is the entry serial number in the whole chain.
  The function finds the corresponding Tree and returns the entry number
  in this tree.
void Lookup()
 Check the files in the chain.
void Loop(Option_t *option, Long64_t nentries, Long64_t firstentry)
 Loop on nentries of this chain starting at firstentry
void ls(Option_t *option)
Long64_t Merge(const char *name, Option_t *option)
 Merge all files in this chain into a new file.
 See important note in the following function Merge().

 If the chain is expecting the input tree inside a directory,
 this directory is NOT created by this routine.
 So in a case where we have:
   TChain ch("mydir/mytree");
   ch.Merge("newfile.root");
 The resulting file will have not subdirectory.  To
 recreate the directory structure do:
   TFile *file = TFile::Open("newfile.root","RECREATE");
   file->mkdir("mydir")->cd();
   ch.Merge(file);

Long64_t Merge(TFile *file, Int_t basketsize, Option_t *option)
     Merge all files in this chain into a new file
     if option ="C" is given, the compression level for all branches
        in the new Tree is set to the file compression level.
     By default, the compression level of all branches is the
     original compression level in the old Trees.

     if (basketsize > 1000, the basket size for all branches of the
     new Tree will be set to basketsize.

  example using the file generated in $ROOTSYS/test/Event
  merge two copies of Event.root

        gSystem.Load("libEvent");
        TChain ch("T");
        ch.Add("Event1.root");
        ch.Add("Event2.root");
        ch.Merge("all.root");

 If the chain is expecting the input tree inside a directory,
 this directory is NOT created by this routine.
 So in a case where we have:
   TChain ch("mydir/mytree");
   ch.Merge("newfile.root");
 The resulting file will have not subdirectory.  To
 recreate the directory structure do:
   TFile *file = TFile::Open("newfile.root","RECREATE");
   file->mkdir("mydir")->cd();
   ch.Merge(file);

 If 'option' contains the word 'fast' the merge will be done without
 unzipping or unstreaming the baskets (i.e. direct copy of the raw byte on disk).
 If 'option' also containts 'SortBasketsByBranch', for each original tree,
 the branches' baskets will be reordered so that for each branch, all its
 baskets will be stored contiguously.  Typically this will increase the performance
 when reading a low number of branches (2 to 5) but will decrease the performance
 when reading more branches (or the full entry).

 IMPORTANT Note 1: AUTOMATIC FILE OVERFLOW
 -----------------------------------------
 When merging many files, it may happen that the resulting file
 reaches a size > TTree::fgMaxTreeSize (default = 1.9 GBytes). In this case
 the current file is automatically closed and a new file started.
 If the name of the merged file was "merged.root", the subsequent files
 will be named "merged_1.root", "merged_2.root", etc.
 fgMaxTreeSize may be modified via the static function TTree::SetMaxTreeSize.

 IMPORTANT Note 2: The output file is automatically closed and deleted.
 This is required because in general the automatic file overflow described
 above may happen during the merge.
 If only the current file is produced (the file passed as first argument),
 one can instruct Merge to not close the file by specifying the option "keep".

 The function returns the total number of files produced.
 To check that all files have been merged use something like:
    if (newchain->GetEntries()!=oldchain->GetEntries()) {
      ... not all the file have been copied ...
    }
void Print(Option_t *option)
 Print the header information of each Tree in the chain.
 see TTree::Print for a list of options
Long64_t Process(const char *filename,Option_t *option, Long64_t nentries, Long64_t firstentry)
 Process all entries in this chain, calling functions in filename
 see TTree::Process
Long64_t Process(TSelector *selector,Option_t *option, Long64_t nentries, Long64_t firstentry)
 Process this chain executing the code in selector
void Reset(Option_t *)
 Resets the definition of this chain
Long64_t Scan(const char *varexp, const char *selection, Option_t *option, Long64_t nentries, Long64_t firstentry)
 Loop on Tree and print entries passing selection. If varexp is 0 (or "")
 then print only first 8 columns. If varexp = "*" print all columns.
 Otherwise a columns selection can be made using "var1:var2:var3".
 see TTreePlayer::Scan for more information
void SetAutoDelete(Bool_t autodelete)
  Set the global branch kAutoDelete bit
  When LoadTree loads a new Tree, the branches for which
  the address is set will have the option AutoDelete set
  For more details on AutoDelete, see TBranch::SetAutoDelete.
void ResetBranchAddresses()
 Reset the address of the branches.
void SetBranchAddress(const char *bname, void *add, TBranch **ptr)
 Set branch address

      bname is the name of a branch.
      add is the address of the branch.

 IMPORTANT REMARK:
 In case TChain::SetBranchStatus is called, it must be called
 BEFORE calling this function.
void SetBranchAddress(const char *bname,void *add, TClass *realClass, EDataType datatype, Bool_t isptr)
Check if bname is already in the Status list
Otherwise create a TChainElement object and set its address
void SetBranchAddress(const char *bname,void *add, TBranch **ptr, TClass *realClass, EDataType datatype, Bool_t isptr)
Check if bname is already in the Status list
Otherwise create a TChainElement object and set its address
void SetBranchStatus(const char *bname, Bool_t status, UInt_t *found)
 Set branch status Process or DoNotProcess

      bname is the name of a branch. if bname="*", apply to all branches.
      status = 1  branch will be processed
             = 0  branch will not be processed
  See IMPORTANT REMARKS in TTree::SetBranchStatus and TChain::SetBranchAddress

  If found is not 0, the number of branch(es) found matching the regular
  expression is returned in *found AND the error message 'unknown branch'
  is suppressed.
void SetDirectory(TDirectory *dir)
 Remove reference to this chain from current directory and add
 reference to new directory dir. dir can be 0 in which case the chain
 does not belong to any directory.
void SetPacketSize(Int_t size)
 Set number of entries per packet for parallel root
void SetWeight(Double_t w, Option_t *option)
  Set chain weight.
  The weight is used by TTree::Draw to automatically weight each
  selected entry in the resulting histogram.
  For example the equivalent of
     chain.Draw("x","w")
  is
     chain.SetWeight(w,"global");
     chain.Draw("x");

  By default the weight used will be the weight
  of each Tree in the TChain. However, one can force the individual
  weights to be ignored by specifying the option "global".
  In this case, the TChain global weight will be used for all Trees.
void Streamer(TBuffer &b)
 Stream a class object.
void ReleaseChainProof()
 Removes the PROOF chain (if present).
TDSet* MakeTDSet()
 Creates a new TDSet containing files from this chain
 and creates separate TDSet for each friend of this
 chain and friends of friends of this chain, and so on.
 If a chain apprears more than once in this friendship
 graph only one TDSet will be created.
 All the chains from the friendship graph will be added as
 friends to the main TDSet (so friends hierarchy in the
 result TDSet will be flat.
 Keep in mind that the destructor of a TDSet does delete
 the friend TDSets.
 Returns the created TDSet or 0 in case of error.
TDSet* MakeTDSetWithoutFriends()
 Creates a new TDSet containing files from this chain.
void SetProof(TVirtualProof *proof, Bool_t refresh, Bool_t gettreeheader)
 Sets the PROOF to be used for processing. "Draw" and "Processed" commands
 will be handled by the proof.
 If proof == (TVirtualProof*) -1 then the gProof is used.
 If proof == 0 no proof is connected and the previously connected
 proof is released.
 If gettreeheader is kTRUE the header of the tree will be read from the
 PROOF cluster: this is only needed fro browsing and should be used with
 care because it may take a long time to execute.
Long64_t GetReadEntry()
 See TTree::GetReadEntry().
TBranch * FindBranch(const char* branchname)
 See TTree::GetReadEntry().
TLeaf * FindLeaf(const char* searchname)
 See TTree::GetReadEntry()
Bool_t GetBranchStatus(const char *branchname)
 See TTree::GetReadEntry()
Long64_t Draw(const char *varexp, const TCut &selection, Option_t *option="" ,Long64_t nentries=kBigNumber, Long64_t firstentry=0)
Int_t Fill()
Int_t GetNtrees()
Int_t GetTreeNumber()
Int_t GetTreeOffsetLen()
Int_t LoadBaskets(Long64_t maxmemory)
Long64_t Merge(const char *name, Option_t *option = "")
void SetMakeClass(Int_t make)
void UseCache(Int_t maxCacheSize = 10, Int_t pageSize = 0)

Author: Rene Brun 03/02/97
Last update: root/tree:$Name: $:$Id: TChain.cxx,v 1.139 2006/07/04 10:23:52 rdm Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *


ROOT page - Class index - Class Hierarchy - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.