Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:30

0001 // @(#)root/treeplayer:$Id$
0002 // Author: Akos Hajdu 22/06/2015
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers and al.        *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TTreeReaderGenerator
0013 #define ROOT_TTreeReaderGenerator
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TTreeReaderGenerator                                                 //
0018 //                                                                      //
0019 // Generate a Selector using the TTreeReader interface                  //
0020 // (TTreeReaderValue, TTreeReaderArray) to access the data in the tree. //
0021 //                                                                      //
0022 //////////////////////////////////////////////////////////////////////////
0023 
0024 #include "TTreeGeneratorBase.h"
0025 
0026 #include "TNamed.h"
0027 #include <vector>
0028 
0029 class TBranch;
0030 class TBranchElement;
0031 class TLeaf;
0032 
0033 namespace ROOT {
0034 namespace Internal {
0035 
0036    /// 0 for the general case, 1 when this a split clases inside a TClonesArray,
0037    /// 2 when this is a split classes inside an STL container.
0038    enum ELocation { kOut=0, kClones, kSTL };
0039 
0040    class TTreeReaderDescriptor : public TObject {
0041    public:
0042       enum ReaderType { kValue, kArray };
0043       ReaderType fType;    ///< Type of the reader: Value or Array
0044       TString fDataType;   ///< Data type of reader
0045       TString fName;       ///< Reader name
0046       TString fBranchName; ///< Branch corresponding to the reader
0047 
0048       TTreeReaderDescriptor(ReaderType type, TString dataType, TString name, TString branchName) :
0049          fType(type),
0050          fDataType(dataType),
0051          fName(name),
0052          fBranchName(branchName) { }
0053    };
0054 
0055    class TBranchDescriptor : public TNamed {
0056    public:
0057       ELocation             fIsClones;       ///< Type of container
0058       TString               fContainerName;  ///< Name of the container
0059       TString               fBranchName;     ///< Name of the branch
0060       TString               fSubBranchPrefix;///< Prefix (e.g. if the branch name is "A." the prefix is "A"
0061       TVirtualStreamerInfo *fInfo;           ///< Streamer info
0062       TBranchDescriptor    *fParent;         ///< Descriptor of the parent branch (NULL for topmost)
0063 
0064       TBranchDescriptor(const char *type, TVirtualStreamerInfo *info,
0065                         const char *branchname, const char *subBranchPrefix, ELocation isclones,
0066                         const TString &containerName, TBranchDescriptor *parent = nullptr) :
0067          TNamed(type,type),
0068          fIsClones(isclones),
0069          fContainerName(containerName),
0070          fBranchName(branchname),
0071          fSubBranchPrefix(subBranchPrefix),
0072          fInfo(info),
0073          fParent(parent)
0074          {
0075             if (fSubBranchPrefix.Length() && fSubBranchPrefix[fSubBranchPrefix.Length() - 1] == '.') {
0076                fSubBranchPrefix.Remove(fSubBranchPrefix.Length()-1);
0077             }
0078          }
0079 
0080       bool IsClones() const { return fIsClones == kClones; }
0081 
0082       bool IsSTL() const { return fIsClones == kSTL; }
0083    };
0084 
0085    class TTreeReaderGenerator : public TTreeGeneratorBase
0086    {
0087       TString               fClassname;         ///< Class name of the selector
0088       TList                 fListOfReaders;     ///< List of readers
0089       bool                  fIncludeAllLeaves;  ///< Should all leaves be included
0090       bool                  fIncludeAllTopmost; ///< Should all topmost branches be included
0091       std::vector<TString>  fIncludeLeaves;     ///< Branches whose leaves should be included
0092       std::vector<TString>  fIncludeStruct;     ///< Branches whom should be included
0093 
0094       void   AddReader(TTreeReaderDescriptor::ReaderType type, TString dataType, TString name,
0095                        TString branchName, TBranchDescriptor *parent = nullptr, bool isLeaf = true);
0096       UInt_t AnalyzeBranches(TBranchDescriptor *desc, TBranchElement *branch, TVirtualStreamerInfo *info);
0097       UInt_t AnalyzeBranches(TBranchDescriptor *desc, TIter &branches, TVirtualStreamerInfo *info);
0098       UInt_t AnalyzeOldBranch(TBranch *branch);
0099       UInt_t AnalyzeOldLeaf(TLeaf *leaf, Int_t nleaves);
0100       bool   BranchNeedsReader(TString branchName, TBranchDescriptor *parent, bool isLeaf);
0101 
0102       void   ParseOptions();
0103       void   AnalyzeTree(TTree *tree);
0104       void   WriteSelector();
0105 
0106    public:
0107       TTreeReaderGenerator(TTree* tree, const char *classname, Option_t *option);
0108    };
0109 }
0110 }
0111 
0112 #endif