43 fIncludeAllLeaves(
false), fIncludeAllTopmost(
false)
59 Warning(
"TTreeReaderGenerator::AddReader",
"Ignored branch %s because type is unsupported.",
branchName.Data());
67 Warning(
"AddReader",
"Ignored branch %s because a branch with the same name already exists. "
68 "TTreeReader requires an unique name for the branches. You may need to "
69 "put a dot at the end of the name of top-level branches.",
branchName.Data());
73 name.ReplaceAll(
'.',
'_');
74 name.ReplaceAll(
',',
'_');
75 name.ReplaceAll(
':',
'_');
76 name.ReplaceAll(
'<',
'_');
77 name.ReplaceAll(
'>',
'_');
78 name.ReplaceAll(
'#',
'_');
79 name.ReplaceAll(
'@',
'_');
81 while (
name.Index(
'[') >= 0 &&
name.Index(
']') >= 0 &&
name.Index(
']') >
name.Index(
'[')) {
118 }
else if (desc && desc->
IsSTL()) {
147 }
else if (
mom->GetType()!=3 &&
mom->GetType() != 4) {
173 Error(
"AnalyzeBranches",
"Ran out of branches when looking in branch %s, class %s",
176 Error(
"AnalyzeBranches",
"Ran out of branches when looking in class %s, element %s",
182 if (
info->GetClass()->GetCollectionProxy() &&
strcmp(
element->GetName(),
"This")==0) {
186 if (
element->GetType() == -1) {
323 else Error(
"AnalyzeBranches",
"Could not get type from collection %s in branch %s", cl->
GetName(),
branch->GetName());
342 if (
branch->GetListOfBranches()->GetEntries()) {
357 if (
branch->GetListOfBranches()->GetEntries() == 0) {
394 if (
branch->GetListOfBranches()->GetEntries() == 0) {
436 Error(
"AnalyzeBranch",
"Unsupported type for %s (%d).",
branch->GetName(),
element->GetType());
441 Error(
"AnalyzeBranch",
"Arrays inside collections are not supported yet (branch: %s).",
branch->GetName());
489 Error(
"AnalyzeOldLeaf",
"TLeafObject not supported yet");
499 std::vector<Int_t>
maxDim;
503 pos = temp.
Index(
"[");
505 if (pos) temp.
Remove(0, pos);
508 temp =
leaf->GetTitle();
509 pos = temp.
Index(
"[");
511 if (pos) temp.
Remove(0, pos);
524 if (current[0] ==
']') {
535 current = (
char*)
strstr( current,
"[" );
632 if (
token.Length() == 0 || (
token.Length() == 1 &&
token[0] ==
'@') ) {
633 Warning(
"ParseOptions",
"Ignored empty branch name in option string.");
634 }
else if (
token[0] ==
'@') {
653 TIter next(tree->GetListOfBranches());
688 "Introspection of TClonesArray in older file not implemented yet.");
704 "Introspection of TClonesArray for %s failed.",
branch->GetName());
753 if (
branch->GetListOfBranches()->GetEntries() == 0) {
773 Error(
"AnalyzeTree",
"Cannot analyze branch %s because it is not a TBranchElement.",
branchName);
811 std::ofstream ofs (
thead, std::ofstream::out);
813 Error(
"WriteSelector",
"cannot open output file %s",
thead.Data());
819R
"CODE(//////////////////////////////////////////////////////////
820// This class has been automatically generated on
821// )CODE" << td.AsString() << R"CODE( by ROOT version )CODE" << gROOT->GetVersion() << std::endl;
824 <<
"// found on file: " <<
treefile << std::endl;
829R
"CODE(//////////////////////////////////////////////////////////
838 if (
isHbook) ofs <<
"#include <THbookFile.h>" << std::endl;
840R
"CODE(#include <TSelector.h>
841#include <TTreeReader.h>
842#include <TTreeReaderValue.h>
843#include <TTreeReaderArray.h>
845// Headers needed by this particular selector
850 while ( (header = next()) ) {
851 ofs << header->
GetTitle() << std::endl;
853 ofs << std::endl << std::endl;
857R
"CODE(class )CODE" << fClassname << R"CODE( : public TSelector {
859 TTreeReader fReader; //!the tree reader
860 TTree *fChain = 0; //!pointer to the analyzed TTree or TChain
862 // Readers to access the data (delete the ones you do not need).
870 <<
" = {fReader, \"" <<
descriptor->fBranchName <<
"\"};" << std::endl;
876 )CODE" << fClassname << R"CODE((TTree * /*tree*/ =0) { }
877 ~)CODE" << fClassname << R"CODE(() override { }
878 Int_t Version() const override { return 2; }
879 void Begin(TTree *tree) override;
880 void SlaveBegin(TTree *tree) override;
881 void Init(TTree *tree) override;
882 bool Notify() override;
883 bool Process(Long64_t entry) override;
884 Int_t GetEntry(Long64_t entry, Int_t getall = 0) override { return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0; }
885 void SetOption(const char *option) override { fOption = option; }
886 void SetObject(TObject *obj) override { fObject = obj; }
887 void SetInputList(TList *input) override { fInput = input; }
888 TList *GetOutputList() const override { return fOutput; }
889 void SlaveTerminate() override;
890 void Terminate() override;
892 ClassDefOverride()CODE" << fClassname << R"CODE(,0);
899void )CODE" << fClassname << R"CODE(::Init(TTree *tree)
901 // The Init() function is called when the selector needs to initialize
902 // a new tree or chain. Typically here the reader is initialized.
903 // It is normally not necessary to make changes to the generated
904 // code, but the routine can be extended by the user if needed.
905 // Init() will be called many times when running on PROOF
906 // (once per file to be processed).
908 fReader.SetTree(tree);
913 // The Notify() function is called when a new file is opened. This
914 // can be either for a new TTree in a TChain or when when a new TTree
915 // is started when using PROOF. It is normally not necessary to make changes
916 // to the generated code, but the routine can be extended by the
917 // user if needed. The return value is currently not used.
923#endif // #ifdef )CODE" << fClassname << R"CODE(_cxx
930 std::ofstream
ofsc (
tcimp, std::ofstream::out);
932 Error(
"WriteSelector",
"cannot open output file %s",
tcimp.Data());
937R
"CODE(#define )CODE" << fClassname << R"CODE(_cxx
938// The class definition in )CODE" << fClassname << R"CODE(.h has been generated automatically
939// by the ROOT utility TTree::MakeSelector(). This class is derived
940// from the ROOT class TSelector. For more information on the TSelector
941// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
944// The following methods are defined in this file:
945// Begin(): called every time a loop on the tree starts,
946// a convenient place to create your histograms.
947// SlaveBegin(): called after Begin(), when on PROOF called only on the
949// Process(): called for each event, in this function you decide what
950// to read and fill your histograms.
951// SlaveTerminate: called at the end of the loop on the tree, when on PROOF
952// called only on the slave servers.
953// Terminate(): called at the end of the loop on the tree,
954// a convenient place to draw/fit your histograms.
956// To use this file, try the following session on your Tree T:
958// root> T->Process(")CODE" << fClassname << R"CODE(.C")
959// root> T->Process(")CODE" << fClassname << R"CODE(.C","some options")
960// root> T->Process(")CODE" << fClassname << R"CODE(.C+")
964#include ")CODE" << thead << R"CODE("
968void )CODE" << fClassname << R"CODE(::Begin(TTree * /*tree*/)
970 // The Begin() function is called at the start of the query.
971 // When running with PROOF Begin() is only called on the client.
972 // The tree argument is deprecated (on PROOF 0 is passed).
974 TString option = GetOption();
977void )CODE" << fClassname << R"CODE(::SlaveBegin(TTree * /*tree*/)
979 // The SlaveBegin() function is called after the Begin() function.
980 // When running with PROOF SlaveBegin() is called on each slave server.
981 // The tree argument is deprecated (on PROOF 0 is passed).
983 TString option = GetOption();
987bool )CODE" << fClassname << R"CODE(::Process(Long64_t entry)
989 // The Process() function is called for each entry in the tree (or possibly
990 // keyed object in the case of PROOF) to be processed. The entry argument
991 // specifies which entry in the currently loaded tree is to be processed.
992 // When processing keyed objects with PROOF, the object is already loaded
993 // and is available via the fObject pointer.
995 // This function should contain the \"body\" of the analysis. It can contain
996 // simple or elaborate selection criteria, run algorithms on the data
997 // of the event and typically fill histograms.
999 // The processing can be stopped by calling Abort().
1001 // Use fStatus to set the return value of TTree::Process().
1003 // The return value is currently not used.
1005 fReader.SetLocalEntry(entry);
1010void )CODE" << fClassname << R"CODE(::SlaveTerminate()
1012 // The SlaveTerminate() function is called after all entries or objects
1013 // have been processed. When running with PROOF SlaveTerminate() is called
1014 // on each slave server.
1018void )CODE" << fClassname << R"CODE(::Terminate()
1020 // The Terminate() function is the last function to be called during
1021 // a query. It always runs on the client, it can be used to present
1022 // the results graphically or save the results to file.
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
TString fBranchName
Name of the branch.
TBranchDescriptor * fParent
Descriptor of the parent branch (NULL for topmost)
TString fContainerName
Name of the container.
TString fSubBranchPrefix
Prefix (e.g. if the branch name is "A." the prefix is "A".
Base class for code generators like TTreeProxyGenerator and TTreeReaderGenerator.
TList fListOfHeaders
List of included headers.
void AddHeader(TClass *cl)
Add a header inclusion request.
TVirtualStreamerInfo * GetStreamerInfo(TBranch *branch, TIter current, TClass *cl)
Return the correct TStreamerInfo of class 'cl' in the list of branches (current) [Assuming these bran...
TVirtualStreamerInfo * GetBaseClass(TStreamerElement *element)
Check if element is a base class and if yes, return the base class.
TTree * fTree
Pointer to the tree.
TString fOptionStr
User options as a string.
TString GetContainedClassName(TBranchElement *branch, TStreamerElement *element, bool ispointer)
Get name of class inside a container.
std::vector< TString > fIncludeStruct
Branches whom should be included.
void AnalyzeTree(TTree *tree)
Analyze tree and extract readers.
TString fClassname
Class name of the selector.
std::vector< TString > fIncludeLeaves
Branches whose leaves should be included.
UInt_t AnalyzeBranches(TBranchDescriptor *desc, TBranchElement *branch, TVirtualStreamerInfo *info)
Analyse sub-branches of 'branch' recursively and extract readers.
void ParseOptions()
Parse the user options.
bool fIncludeAllTopmost
Should all topmost branches be included.
void AddReader(TTreeReaderDescriptor::ReaderType type, TString dataType, TString name, TString branchName, TBranchDescriptor *parent=nullptr, bool isLeaf=true)
Add a reader to the generated code.
bool BranchNeedsReader(TString branchName, TBranchDescriptor *parent, bool isLeaf)
Check whether a branch should have a corresponding reader added, depending on the options provided by...
bool fIncludeAllLeaves
Should all leaves be included.
TTreeReaderGenerator(TTree *tree, const char *classname, Option_t *option)
Constructor. Analyzes the tree and writes selector.
TList fListOfReaders
List of readers.
UInt_t AnalyzeOldLeaf(TLeaf *leaf, Int_t nleaves)
Analyze the leaf and add the variables found.
UInt_t AnalyzeOldBranch(TBranch *branch)
Analyze branch and add the variables found.
void WriteSelector()
Generate code for selector class.
A Branch for the case of an object.
A TTree is a list of TBranches.
TClass instances represent classes, structs and namespaces in the ROOT type system.
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0, Bool_t isTransient=kFALSE) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist,...
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
An array of clone (identical) objects.
TClass * GetClass() const
Basic data type descriptor (datatype information is obtained from CINT).
static TDataType * GetDataType(EDataType type)
Given a EDataType type, get the TDataType* that represents it.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
virtual TFile * GetFile() const
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
void Add(TObject *obj) override
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Collectable string class.
Mother of all ROOT objects.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual const char * GetTitle() const
Returns title of object.
const char * Data() const
Bool_t EqualTo(const char *cs, ECaseCompare cmp=kExact) const
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
TString & Remove(Ssiz_t pos)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
A TTree represents a columnar dataset.
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
TDirectory * GetDirectory() const
virtual EDataType GetType() const =0
If the value type is a fundamental data type, return its type (see enumeration EDataType).
virtual TClass * GetValueClass() const =0
If the value type is a user-defined class, return a pointer to the TClass representing the value type...
Abstract Interface class describing Streamer information for one class.
ELocation
0 for the general case, 1 when this a split clases inside a TClonesArray, 2 when this is a split clas...
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...