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(
'[')) {
93 if (info==
nullptr) info = branch->
GetInfo();
109 bool skipped =
false;
113 TIter peek = branches;
117 containerName =
"TClonesArray";
118 }
else if (desc && desc->
IsSTL()) {
119 outer_isclones =
kSTL;
124 containerName =
"TClonesArray";
126 outer_isclones =
kSTL;
144 subBranchPrefix = mom->
GetName();
145 if (subBranchPrefix[subBranchPrefix.
Length()-1]==
'.') {
148 subBranchPrefix =
"";
164 bool usedBranch =
true;
166 TIter peek = branches;
171 if (branch==
nullptr) {
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",
177 info->
GetName(), element->GetName());
186 if (element->GetType() == -1) {
195 if (leaf && outer_isclones ==
kOut
197 else branchEndName = branch->
GetName();
199 pos = branchEndName.
Index(
".");
201 if (subBranchPrefix.
Length() && branchEndName.
BeginsWith(subBranchPrefix)) {
209 bool ispointer =
false;
212 switch(element->GetType()) {
289 TClass *cl = element->GetClassPointer();
295 containerName =
"TClonesArray";
296 if (outer_isclones !=
kOut) {
297 isclones = outer_isclones;
298 dataType =
"TClonesArray";
306 if (outer_isclones !=
kOut || containerName.
EqualTo(
"vector<bool>")) {
312 isclones = outer_isclones;
318 dataType = valueClass->
GetName();
322 if (valueClassBuiltIn) dataType = valueClassBuiltIn->
GetName();
323 else Error(
"AnalyzeBranches",
"Could not get type from collection %s in branch %s", cl->
GetName(), branch->
GetName());
347 if (element->IsBase()) {
356 if (branchEndName == element->GetName()) {
367 isclones, containerName, desc);
380 if (objInfo ==
nullptr) {
385 isclones, containerName, desc);
393 if (branchEndName == element->GetName()) {
398 if (isclones !=
kOut) {
404 isclones, containerName, desc);
411 if (local_prefix.
Length()) local_prefix +=
".";
412 local_prefix += element->GetName();
418 if (isclones !=
kOut) {
424 isclones, containerName, desc);
436 Error(
"AnalyzeBranch",
"Unsupported type for %s (%d).", branch->
GetName(), element->GetType());
439 if (!isBase && !skipped) {
441 Error(
"AnalyzeBranch",
"Arrays inside collections are not supported yet (branch: %s).", branch->
GetName());
443 if (outer_isclones !=
kOut || isclones !=
kOut) {
475 for(
int l=0;
l<nleaves;
l++) {
480 return extraLookedAt;
489 Error(
"AnalyzeOldLeaf",
"TLeafObject not supported yet");
499 std::vector<Int_t> maxDim;
503 pos = temp.
Index(
"[");
505 if (pos) temp.
Remove(0, pos);
509 pos = temp.
Index(
"[");
511 if (pos) temp.
Remove(0, pos);
518 const char *current = dimensions.
Data();
524 if (current[0] ==
']') {
525 maxDim.push_back(-1);
527 scanindex = sscanf(current,
"%d",&
index);
529 maxDim.push_back(
index);
531 maxDim.push_back(-2);
535 current = (
char*)strstr( current,
"[" );
548 dataType = leafTypeName;
553 dataType = leafTypeName;
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());
657 while ( (branch = (
TBranch*)next()) ) {
660 const char *branchName = branch->
GetName();
665 if (branchClassName && strlen(branchClassName)) {
678 containerName =
"TClonesArray";
688 "Introspection of TClonesArray in older file not implemented yet.");
704 "Introspection of TClonesArray for %s failed.",branch->
GetName());
719 if (containerName.
EqualTo(
"vector<bool>")) {
746 cl->
GetName(), branchName, branchName,
nullptr,
true);
773 Error(
"AnalyzeTree",
"Cannot analyze branch %s because it is not a TBranchElement.", branchName);
798 treefile =
"Memory Directory";
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).
869 <<
"> " << descriptor->
fName
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.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
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.
TString fBranchName
Branch corresponding to the reader.
ReaderType fType
Type of the reader: Value or Array.
TString fDataType
Data type of reader.
TString fName
Reader name.
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.
TBranchElement * GetBranchCount() const
TStreamerInfo * GetInfo() const
Get streamer info for the branch class.
A TTree is a list of TBranches.
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any.
virtual char * GetAddress() const
TObjArray * GetListOfBranches()
Int_t GetSplitLevel() const
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all leaves of entry and return total number of bytes read.
TClass * IsA() const override
TBranch * GetSubBranch(const TBranch *br) const
Find the parent branch of child.
virtual void SetAddress(void *add)
Set address of this branch.
TObjArray * GetListOfLeaves()
TBranch * GetMother() const
Get our top-level parent branch in the tree.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Bool_t CanIgnoreTObjectStreamer()
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...
const char * AsString() const
Return the date & time as a string (ctime() format).
virtual TFile * GetFile() const
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual const char * GetTypeName() const
TClass * IsA() const override
TBranch * GetBranch() const
void Add(TObject *obj) override
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Int_t GetEntriesFast() const
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
TObject * UncheckedAt(Int_t i) const
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
Ssiz_t Last(char c) const
Find last occurrence of a character c.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Remove(Ssiz_t pos)
TString & Append(const char *cs)
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
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.
@ kUChar
Equal to TDataType's kchar.
virtual TObjArray * GetElements() const =0
virtual TClass * GetClass() const =0
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...