Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:16:26

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    TString GetCppName(TString name);
0037 
0038    /// 0 for the general case, 1 when this a split clases inside a TClonesArray,
0039    /// 2 when this is a split classes inside an STL container.
0040    enum ELocation { kOut=0, kClones, kSTL };
0041 
0042    class TTreeReaderDescriptor : public TObject {
0043    public:
0044       enum ReaderType { kValue, kArray };
0045       ReaderType fType;    ///< Type of the reader: Value or Array
0046       TString fDataType;   ///< Data type of reader
0047       TString fName;       ///< Reader name
0048       TString fBranchName; ///< Branch corresponding to the reader
0049 
0050       TTreeReaderDescriptor(ReaderType type, TString dataType, TString name, TString branchName) :
0051          fType(type),
0052          fDataType(dataType),
0053          fName(name),
0054          fBranchName(branchName) { }
0055    };
0056 
0057    class TBranchDescriptor : public TNamed {
0058    public:
0059       ELocation             fIsClones;       ///< Type of container
0060       TString               fContainerName;  ///< Name of the container
0061       TString               fBranchName;     ///< Name of the branch
0062       TString               fSubBranchPrefix;///< Prefix (e.g. if the branch name is "A." the prefix is "A"
0063       TVirtualStreamerInfo *fInfo;           ///< Streamer info
0064       TBranchDescriptor    *fParent;         ///< Descriptor of the parent branch (NULL for topmost)
0065 
0066       TBranchDescriptor(const char *type, TVirtualStreamerInfo *info,
0067                         const char *branchname, const char *subBranchPrefix, ELocation isclones,
0068                         const TString &containerName, TBranchDescriptor *parent = nullptr) :
0069          TNamed(type,type),
0070          fIsClones(isclones),
0071          fContainerName(containerName),
0072          fBranchName(branchname),
0073          fSubBranchPrefix(subBranchPrefix),
0074          fInfo(info),
0075          fParent(parent)
0076          {
0077             if (fSubBranchPrefix.Length() && fSubBranchPrefix[fSubBranchPrefix.Length() - 1] == '.') {
0078                fSubBranchPrefix.Remove(fSubBranchPrefix.Length()-1);
0079             }
0080          }
0081 
0082       bool IsClones() const { return fIsClones == kClones; }
0083 
0084       bool IsSTL() const { return fIsClones == kSTL; }
0085    };
0086 
0087    class TTreeReaderGenerator : public TTreeGeneratorBase
0088    {
0089       TString               fClassname;         ///< Class name of the selector
0090       TList                 fListOfReaders;     ///< List of readers
0091       bool                  fIncludeAllLeaves;  ///< Should all leaves be included
0092       bool                  fIncludeAllTopmost; ///< Should all topmost branches be included
0093       std::vector<TString>  fIncludeLeaves;     ///< Branches whose leaves should be included
0094       std::vector<TString>  fIncludeStruct;     ///< Branches whom should be included
0095 
0096       void   AddReader(TTreeReaderDescriptor::ReaderType type, TString dataType, TString name,
0097                        TString branchName, TBranchDescriptor *parent = nullptr, bool isLeaf = true);
0098       UInt_t AnalyzeBranches(TBranchDescriptor *desc, TBranchElement *branch, TVirtualStreamerInfo *info);
0099       UInt_t AnalyzeBranches(TBranchDescriptor *desc, TIter &branches, TVirtualStreamerInfo *info);
0100       UInt_t AnalyzeOldBranch(TBranch *branch);
0101       UInt_t AnalyzeOldLeaf(TLeaf *leaf, Int_t nleaves);
0102       bool   BranchNeedsReader(TString branchName, TBranchDescriptor *parent, bool isLeaf);
0103 
0104       void   ParseOptions();
0105       void   AnalyzeTree(TTree *tree);
0106       void   WriteSelector();
0107 
0108    public:
0109       TTreeReaderGenerator(TTree* tree, const char *classname, Option_t *option);
0110    };
0111 }
0112 }
0113 
0114 #endif