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(
'.',
'_');
75 while (
name.Index(
'[') >= 0 &&
name.Index(
']') >= 0 &&
name.Index(
']') >
name.Index(
'[')) {
87 if (info==0) info = branch->
GetInfo();
107 TIter peek = branches;
111 containerName =
"TClonesArray";
112 }
else if (desc && desc->
IsSTL()) {
113 outer_isclones =
kSTL;
118 containerName =
"TClonesArray";
120 outer_isclones =
kSTL;
138 subBranchPrefix = mom->
GetName();
139 if (subBranchPrefix[subBranchPrefix.
Length()-1]==
'.') {
142 subBranchPrefix =
"";
160 TIter peek = branches;
167 Error(
"AnalyzeBranches",
"Ran out of branches when looking in branch %s, class %s",
170 Error(
"AnalyzeBranches",
"Ran out of branches when looking in class %s, element %s",
171 info->
GetName(), element->GetName());
180 if (element->GetType() == -1) {
189 if (leaf && outer_isclones ==
kOut
191 else branchEndName = branch->
GetName();
193 pos = branchEndName.
Index(
".");
195 if (subBranchPrefix.
Length() && branchEndName.
BeginsWith(subBranchPrefix)) {
206 switch(element->GetType()) {
283 TClass *cl = element->GetClassPointer();
287 if (cl == TClonesArray::Class()) {
289 containerName =
"TClonesArray";
290 if (outer_isclones !=
kOut) {
291 isclones = outer_isclones;
292 dataType =
"TClonesArray";
300 if (outer_isclones !=
kOut || containerName.
EqualTo(
"vector<bool>")) {
306 isclones = outer_isclones;
312 dataType = valueClass->
GetName();
316 if (valueClassBuiltIn) dataType = valueClassBuiltIn->
GetName();
317 else Error(
"AnalyzeBranches",
"Could not get type from collection %s in branch %s", cl->
GetName(), branch->
GetName());
341 if (element->IsBase()) {
350 if (branchEndName == element->GetName()) {
361 isclones, containerName, desc);
379 isclones, containerName, desc);
387 if (branchEndName == element->GetName()) {
392 if (isclones !=
kOut) {
398 isclones, containerName, desc);
405 if (local_prefix.
Length()) local_prefix +=
".";
406 local_prefix += element->GetName();
412 if (isclones !=
kOut) {
418 isclones, containerName, desc);
430 Error(
"AnalyzeBranch",
"Unsupported type for %s (%d).", branch->
GetName(), element->GetType());
433 if (!isBase && !skipped) {
435 Error(
"AnalyzeBranch",
"Arrays inside collections are not supported yet (branch: %s).", branch->
GetName());
437 if (outer_isclones !=
kOut || isclones !=
kOut) {
469 for(
int l=0;
l<nleaves;
l++) {
474 return extraLookedAt;
482 if (leaf->IsA()==TLeafObject::Class()) {
483 Error(
"AnalyzeOldLeaf",
"TLeafObject not supported yet");
493 std::vector<Int_t> maxDim;
497 pos = temp.
Index(
"[");
499 if (pos) temp.
Remove(0, pos);
503 pos = temp.
Index(
"[");
505 if (pos) temp.
Remove(0, pos);
512 const char *current = dimensions.
Data();
518 if (current[0] ==
']') {
519 maxDim.push_back(-1);
521 scanindex = sscanf(current,
"%d",&index);
523 maxDim.push_back(index);
525 maxDim.push_back(-2);
529 current = (
char*)strstr( current,
"[" );
533 if (dim == 0 && leaf->IsA() == TLeafC::Class()) {
542 dataType = leafTypeName;
547 dataType = leafTypeName;
626 if ( token.
Length() == 0 || (token.
Length() == 1 && token[0] ==
'@') ) {
627 Warning(
"ParseOptions",
"Ignored empty branch name in option string.");
628 }
else if (token[0] ==
'@') {
651 while ( (branch = (
TBranch*)next()) ) {
654 const char *branchName = branch->
GetName();
659 if (branchClassName && strlen(branchClassName)) {
670 if (cl == TClonesArray::Class()) {
672 containerName =
"TClonesArray";
673 if (branch->IsA()==TBranchElement::Class()) {
682 "Introspection of TClonesArray in older file not implemented yet.");
698 "Introspection of TClonesArray for %s failed.",branch->
GetName());
713 if (containerName.
EqualTo(
"vector<bool>")) {
767 Error(
"AnalyzeTree",
"Cannot analyze branch %s because it is not a TBranchElement.", branchName);
792 treefile =
"Memory Directory";
805 std::ofstream ofs (thead, std::ofstream::out);
807 Error(
"WriteSelector",
"cannot open output file %s", thead.
Data());
813R
"CODE(//////////////////////////////////////////////////////////
814// This class has been automatically generated on
815// )CODE" << td.AsString() << R"CODE( by ROOT version )CODE" << gROOT->GetVersion() << std::endl;
818 <<
"// found on file: " << treefile << std::endl;
823R
"CODE(//////////////////////////////////////////////////////////
832 if (isHbook) ofs <<
"#include <THbookFile.h>" << std::endl;
834R
"CODE(#include <TSelector.h>
835#include <TTreeReader.h>
836#include <TTreeReaderValue.h>
837#include <TTreeReaderArray.h>
839// Headers needed by this particular selector
844 while ( (header = next()) ) {
845 ofs << header->
GetTitle() << std::endl;
847 ofs << std::endl << std::endl;
851R
"CODE(class )CODE" << fClassname << R"CODE( : public TSelector {
853 TTreeReader fReader; //!the tree reader
854 TTree *fChain = 0; //!pointer to the analyzed TTree or TChain
856 // Readers to access the data (delete the ones you do not need).
863 <<
"> " << descriptor->
fName
864 <<
" = {fReader, \"" << descriptor->
fBranchName <<
"\"};" << std::endl;
870 )CODE" << fClassname << R"CODE((TTree * /*tree*/ =0) { }
871 virtual ~)CODE" << fClassname << R"CODE(() { }
872 virtual Int_t Version() const { return 2; }
873 virtual void Begin(TTree *tree);
874 virtual void SlaveBegin(TTree *tree);
875 virtual void Init(TTree *tree);
876 virtual Bool_t Notify();
877 virtual Bool_t Process(Long64_t entry);
878 virtual Int_t GetEntry(Long64_t entry, Int_t getall = 0) { return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0; }
879 virtual void SetOption(const char *option) { fOption = option; }
880 virtual void SetObject(TObject *obj) { fObject = obj; }
881 virtual void SetInputList(TList *input) { fInput = input; }
882 virtual TList *GetOutputList() const { return fOutput; }
883 virtual void SlaveTerminate();
884 virtual void Terminate();
893void )CODE" << fClassname << R"CODE(::Init(TTree *tree)
895 // The Init() function is called when the selector needs to initialize
896 // a new tree or chain. Typically here the reader is initialized.
897 // It is normally not necessary to make changes to the generated
898 // code, but the routine can be extended by the user if needed.
899 // Init() will be called many times when running on PROOF
900 // (once per file to be processed).
902 fReader.SetTree(tree);
905Bool_t )CODE" << fClassname << R"CODE(::Notify()
907 // The Notify() function is called when a new file is opened. This
908 // can be either for a new TTree in a TChain or when when a new TTree
909 // is started when using PROOF. It is normally not necessary to make changes
910 // to the generated code, but the routine can be extended by the
911 // user if needed. The return value is currently not used.
917#endif // #ifdef )CODE" << fClassname << R"CODE(_cxx
924 std::ofstream ofsc (tcimp, std::ofstream::out);
926 Error(
"WriteSelector",
"cannot open output file %s", tcimp.
Data());
931R
"CODE(#define )CODE" << fClassname << R"CODE(_cxx
932// The class definition in )CODE" << fClassname << R"CODE(.h has been generated automatically
933// by the ROOT utility TTree::MakeSelector(). This class is derived
934// from the ROOT class TSelector. For more information on the TSelector
935// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
938// The following methods are defined in this file:
939// Begin(): called every time a loop on the tree starts,
940// a convenient place to create your histograms.
941// SlaveBegin(): called after Begin(), when on PROOF called only on the
943// Process(): called for each event, in this function you decide what
944// to read and fill your histograms.
945// SlaveTerminate: called at the end of the loop on the tree, when on PROOF
946// called only on the slave servers.
947// Terminate(): called at the end of the loop on the tree,
948// a convenient place to draw/fit your histograms.
950// To use this file, try the following session on your Tree T:
952// root> T->Process(")CODE" << fClassname << R"CODE(.C")
953// root> T->Process(")CODE" << fClassname << R"CODE(.C","some options")
954// root> T->Process(")CODE" << fClassname << R"CODE(.C+")
958#include ")CODE" << thead << R"CODE("
962void )CODE" << fClassname << R"CODE(::Begin(TTree * /*tree*/)
964 // The Begin() function is called at the start of the query.
965 // When running with PROOF Begin() is only called on the client.
966 // The tree argument is deprecated (on PROOF 0 is passed).
968 TString option = GetOption();
971void )CODE" << fClassname << R"CODE(::SlaveBegin(TTree * /*tree*/)
973 // The SlaveBegin() function is called after the Begin() function.
974 // When running with PROOF SlaveBegin() is called on each slave server.
975 // The tree argument is deprecated (on PROOF 0 is passed).
977 TString option = GetOption();
981Bool_t )CODE" << fClassname << R"CODE(::Process(Long64_t entry)
983 // The Process() function is called for each entry in the tree (or possibly
984 // keyed object in the case of PROOF) to be processed. The entry argument
985 // specifies which entry in the currently loaded tree is to be processed.
986 // When processing keyed objects with PROOF, the object is already loaded
987 // and is available via the fObject pointer.
989 // This function should contain the \"body\" of the analysis. It can contain
990 // simple or elaborate selection criteria, run algorithms on the data
991 // of the event and typically fill histograms.
993 // The processing can be stopped by calling Abort().
995 // Use fStatus to set the return value of TTree::Process().
997 // The return value is currently not used.
999 fReader.SetLocalEntry(entry);
1004void )CODE" << fClassname << R"CODE(::SlaveTerminate()
1006 // The SlaveTerminate() function is called after all entries or objects
1007 // have been processed. When running with PROOF SlaveTerminate() is called
1008 // on each slave server.
1012void )CODE" << fClassname << R"CODE(::Terminate()
1014 // The Terminate() function is the last function to be called during
1015 // a query. It always runs on the client, it can be used to present
1016 // the results graphically or save the results to file.
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.
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.
TString GetContainedClassName(TBranchElement *branch, TStreamerElement *element, Bool_t ispointer)
Get name of class inside a container.
TTree * fTree
Pointer to the tree.
TString fOptionStr
User options as a string.
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_t fIncludeAllTopmost
Should all topmost branches be included.
TTreeReaderGenerator(TTree *tree, const char *classname, Option_t *option)
Constructor. Analyzes the tree and writes selector.
TList fListOfReaders
List of readers.
void AddReader(TTreeReaderDescriptor::ReaderType type, TString dataType, TString name, TString branchName, TBranchDescriptor *parent=0, Bool_t isLeaf=kTRUE)
Add a reader to the generated code.
Bool_t BranchNeedsReader(TString branchName, TBranchDescriptor *parent, Bool_t isLeaf)
Check whether a branch should have a corresponding reader added, depending on the options provided by...
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.
Bool_t fIncludeAllLeaves
Should all leaves be included.
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.
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
TBranch * GetBranch() const
virtual void Add(TObject *obj)
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
Int_t GetEntriesFast() const
Int_t GetEntries() const
Return the number of objects in array (i.e.
TObject * UncheckedAt(Int_t i) const
TObject * At(Int_t idx) const
Collectable string class.
Mother of all ROOT objects.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
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
virtual TClass * GetValueClass() const =0
Abstract Interface class describing Streamer information for one class.
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...