127 gROOT->GetListOfCleanups()->Add(
this);
144 gROOT->GetListOfCleanups()->Remove(
this);
159 if (
dynamic_cast<const TChain*
>(T)) {
160 index =
new TChainIndex(T, majorname, minorname, long64major, long64minor);
163 Warning(
"BuildIndex",
"Creating a TChainIndex unsuccessful - switching to TTreeIndex (much slower)");
168 return new TTreeIndex(T, majorname, minorname, long64major, long64minor);
207 if (tree ==
nullptr)
return nullptr;
212 for (
Int_t i = 0; i < nb; ++i) {
226 if (strlen(selection)) {
228 if (!select || !select->GetNdim()) {
238 for (entry=firstentry;entry<firstentry+
nentries;entry++) {
239 entryNumber =
fTree->GetEntryNumber(entry);
240 if (entryNumber < 0)
break;
242 if (localEntry < 0)
break;
243 if (tnumber !=
fTree->GetTreeNumber()) {
244 tnumber =
fTree->GetTreeNumber();
245 if (select) select->UpdateFormulaLeaves();
248 Int_t ndata = select->GetNdata();
250 for(
Int_t current = 0; current<ndata && !keep; current++) {
251 keep |= (select->EvalInstance(current) != 0);
255 fTree->GetEntry(entryNumber);
310 const char *macrofilename,
const char *cutfilename,
313 if (!macrofilename || strlen(macrofilename)==0)
return 0;
319 if (cutfilename && strlen(cutfilename))
320 realcutname =
gSystem->SplitAclicMode(cutfilename, aclicMode, arguments, io);
323 TString realname =
gSystem->SplitAclicMode(macrofilename, aclicMode, arguments, io);
325 TString selname = wrapperPrefix;
330 if (aclicMode.
Length()==0) {
331 Warning(
"DrawScript",
"TTreeProxy does not work in interpreted mode yet. The script will be compiled.");
334 selname.
Append(aclicMode);
336 Info(
"DrawScript",
"%s",
Form(
"Will process tree/chain using %s",selname.
Data()));
338 fTree->SetNotify(
nullptr);
355 if (
fTree->GetEntriesFriend() == 0)
return 0;
360 TString possibleFilename = varexp0;
362 if ( dot_pos !=
kNPOS
363 && possibleFilename.
Index(
"Alt$")<0 && possibleFilename.
Index(
"Entries$")<0
364 && possibleFilename.
Index(
"LocalEntries$")<0
365 && possibleFilename.
Index(
"Length$")<0 && possibleFilename.
Index(
"Entry$")<0
366 && possibleFilename.
Index(
"LocalEntry$")<0
367 && possibleFilename.
Index(
"Min$")<0 && possibleFilename.
Index(
"Max$")<0
368 && possibleFilename.
Index(
"MinIf$")<0 && possibleFilename.
Index(
"MaxIf$")<0
369 && possibleFilename.
Index(
"Iteration$")<0 && possibleFilename.
Index(
"Sum$")<0
370 && possibleFilename.
Index(
">")<0 && possibleFilename.
Index(
"<")<0
371 &&
gSystem->IsFileInIncludePath(possibleFilename.
Data())) {
373 if (selection && strlen(selection) && !
gSystem->IsFileInIncludePath(selection)) {
375 "Drawing using a C++ file currently requires that both the expression and the selection are files\n\t\"%s\" is not a file",
382 possibleFilename = selection;
383 if (possibleFilename.
Index(
"Alt$")<0 && possibleFilename.
Index(
"Entries$")<0
384 && possibleFilename.
Index(
"LocalEntries$")<0
385 && possibleFilename.
Index(
"Length$")<0 && possibleFilename.
Index(
"Entry$")<0
386 && possibleFilename.
Index(
"LocalEntry$")<0
387 && possibleFilename.
Index(
"Min$")<0 && possibleFilename.
Index(
"Max$")<0
388 && possibleFilename.
Index(
"MinIf$")<0 && possibleFilename.
Index(
"MaxIf$")<0
389 && possibleFilename.
Index(
"Iteration$")<0 && possibleFilename.
Index(
"Sum$")<0
390 && possibleFilename.
Index(
">")<0 && possibleFilename.
Index(
"<")<0
391 &&
gSystem->IsFileInIncludePath(possibleFilename.
Data())) {
394 "Drawing using a C++ file currently requires that both the expression and the selection are files\n\t\"%s\" is not a file",
403 if (evlist && elist){
408 if (cvarexp) cvarexp->
SetTitle(varexp0);
409 if (cselection) cselection->
SetTitle(selection);
413 bool optpara =
false;
414 bool optcandle =
false;
415 bool optgl5d =
false;
416 bool optnorm =
false;
418 if (opt.
Contains(
"para")) optpara =
true;
419 if (opt.
Contains(
"candle")) optcandle =
true;
420 if (opt.
Contains(
"gl5d")) optgl5d =
true;
421 bool pgl =
gStyle->GetCanvasPreferGL();
425 if (pgl ==
false)
gStyle->SetCanvasPreferGL(
true);
426 gROOT->ProcessLineFast(
"new TCanvas();");
440 fTree->SetEstimate(oldEstimate);
443 fTree->SetEntryList(elist);
453 if (!drawflag && !opt.
Contains(
"goff")) draw =
true;
463 gPad->DrawFrame(-1.,-1.,1.,1.);
472 Warning(
"DrawSelect",
"The selected TTree subset is empty.");
477 if (
fDimension == 1 && !(optpara||optcandle)) {
482 }
else if (
fDimension == 2 && !(optpara||optcandle)) {
490 if (
l == 0 || opt ==
"same") graph =
true;
501 }
else if (
fDimension == 3 && !(optpara||optcandle)) {
507 }
else if (action == 33) {
514 if (opt.
Contains(
"same")) noscat -= 4;
522 }
else if (
fDimension == 4 && !(optpara||optcandle)) {
529 for (
Int_t col=0;col<ncolors;col++) {
532 if (draw) pm3d->
Draw();
535 }
else if (
fDimension > 1 && (optpara || optcandle)) {
538 fTree->Draw(
">>enlist",selection,
"entrylist",
nentries,firstentry);
540 gROOT->ProcessLine(
Form(
"TParallelCoord::SetEntryList((TParallelCoord*)0x%zx,(TEntryList*)0x%zx)",
541 (
size_t)para, (
size_t)enlist));
545 gROOT->ProcessLineFast(
Form(
"(new TGL5DDataSet((TTree *)0x%zx))->Draw(\"%s\");", (
size_t)
fTree, opt.
Data()));
546 gStyle->SetCanvasPreferGL(pgl);
577 Int_t nch = option ? strlen(option) + 10 : 10;
578 char *opt =
new char[nch];
579 if (option) strlcpy(opt,option,nch-1);
580 else strlcpy(opt,
"goff",5);
585 Int_t fitResult = -1;
588 fitResult =
fHistogram->Fit(formula,option,goption);
609 fTree->SetNotify(
nullptr);
621 if (lastentry >
fTree->GetEntriesFriend()-1) {
622 lastentry =
fTree->GetEntriesFriend() - 1;
623 nentries = lastentry - firstentry + 1;
640 TTHREAD_TLS_DECL(std::string,column);
641 if (colindex<0 )
return "";
643 i1 = index[colindex] + 1;
644 n = index[colindex+1] - i1;
645 column = varexp(i1,
n).
Data();
647 return column.c_str();
664 const char* ltitle = leaf->
GetTitle();
665 if (mother && mother!=branch) {
666 branchname = mother->
GetName();
667 if (branchname[branchname.
Length()-1]!=
'.') {
670 if (strncmp(branchname.
Data(),ltitle,branchname.
Length())==0) {
676 branchname += ltitle;
681 char *bname = (
char*)branchname.
Data();
682 char *twodim = (
char*)strstr(bname,
"[");
683 if (twodim) *twodim = 0;
685 if (*bname ==
'.') *bname=
'_';
686 if (*bname ==
',') *bname=
'_';
687 if (*bname ==
':') *bname=
'_';
688 if (*bname ==
'<') *bname=
'_';
689 if (*bname ==
'>') *bname=
'_';
690 if (*bname ==
'#') *bname=
'_';
691 if (*bname ==
'@') *bname=
'_';
742 const TString fileNameStem = classname ? classname :
fTree->GetName();
744 if (cppClassName != fileNameStem)
745 Warning(
"TTreePlayer::MakeClass",
"The %s name provided ('%s') is not a valid C++ identifier and will be converted to '%s'.",(classname ?
"class" :
"tree"), fileNameStem.
Data(), cppClassName.
Data());
748 thead.
Form(
"%s.h", fileNameStem.
Data());
749 FILE *fp = fopen(thead,
"w");
751 Error(
"MakeClass",
"cannot open output file %s", thead.
Data());
755 tcimp.
Form(
"%s.C", fileNameStem.
Data());
756 FILE *fpc = fopen(tcimp,
"w");
758 Error(
"MakeClass",
"cannot open output file %s", tcimp.
Data());
763 if (
fTree->GetDirectory() &&
fTree->GetDirectory()->GetFile()) {
764 treefile =
fTree->GetDirectory()->GetFile()->GetName();
766 treefile =
"Memory Directory";
772 bool isHbook =
fTree->InheritsFrom(
"THbookTree");
774 treefile =
fTree->GetTitle();
781 fprintf(fp,
"//////////////////////////////////////////////////////////\n");
782 fprintf(fp,
"// This class has been automatically generated on\n");
783 fprintf(fp,
"// %s by ROOT version %s\n",td.
AsString(),
gROOT->GetVersion());
785 fprintf(fp,
"// from TTree %s/%s\n",
fTree->GetName(),
fTree->GetTitle());
786 fprintf(fp,
"// found on file: %s\n",treefile.
Data());
788 fprintf(fp,
"// from TChain %s/%s\n",
fTree->GetName(),
fTree->GetTitle());
790 fprintf(fp,
"//////////////////////////////////////////////////////////\n");
792 fprintf(fp,
"#ifndef %s_h\n",cppClassName.
Data());
793 fprintf(fp,
"#define %s_h\n",cppClassName.
Data());
795 fprintf(fp,
"#include <TROOT.h>\n");
796 fprintf(fp,
"#include <TChain.h>\n");
797 fprintf(fp,
"#include <TFile.h>\n");
798 if (isHbook) fprintf(fp,
"#include <THbookFile.h>\n");
799 if (opt.
Contains(
"selector")) fprintf(fp,
"#include <TSelector.h>\n");
803 fprintf(fp,
"\n// Header file for the classes stored in the TTree if any.\n");
806 constexpr auto length = std::char_traits<char>::length;
807 for (
l=0;
l<nleaves;
l++) {
813 if (declfile && declfile[0]) {
814 static const char *precstl =
"prec_stl/";
815 static const unsigned int precstl_len = strlen(precstl);
816 static const char *rootinclude =
"include/";
817 static const unsigned int rootinclude_len = strlen(rootinclude);
818 if (strncmp(declfile,precstl,precstl_len) == 0) {
819 fprintf(fp,
"#include <%s>\n",declfile+precstl_len);
821 }
else if (strncmp(declfile,
"/usr/include/",13) == 0) {
822 fprintf(fp,
"#include <%s>\n",declfile+length(
"/include/c++/"));
823 listOfHeaders.
Add(
new TNamed(cl->
GetName(),declfile+length(
"/include/c++/")));
824 }
else if (strstr(declfile,
"/include/c++/") !=
nullptr) {
825 fprintf(fp,
"#include <%s>\n",declfile+length(
"/include/c++/"));
826 listOfHeaders.
Add(
new TNamed(cl->
GetName(),declfile+length(
"/include/c++/")));
827 }
else if (strncmp(declfile,rootinclude,rootinclude_len) == 0) {
828 fprintf(fp,
"#include <%s>\n",declfile+rootinclude_len);
831 fprintf(fp,
"#include \"%s\"\n",declfile);
844 for (
l=0;
l<nleaves;
l++) {
854 Int_t ntrees = chain->GetNtrees();
855 for (
Int_t file=0;file<ntrees;file++) {
856 Long64_t first = chain->GetTreeOffset()[file];
857 chain->LoadTree(first);
858 for (
l=0;
l<nleaves;
l++) {
871 fprintf(fp,
"class %s : public TSelector {\n",cppClassName.
Data());
872 fprintf(fp,
"public :\n");
873 fprintf(fp,
" TTree *fChain; ///<!pointer to the analyzed TTree or TChain\n");
875 fprintf(fp,
"class %s {\n",cppClassName.
Data());
876 fprintf(fp,
"public :\n");
877 fprintf(fp,
" TTree *fChain; ///<!pointer to the analyzed TTree or TChain\n");
878 fprintf(fp,
" Int_t fCurrent; ///<!current Tree number in a TChain\n");
881 fprintf(fp,
"\n// Fixed size dimensions of array or collections stored in the TTree if any.\n");
882 leaves =
fTree->GetListOfLeaves();
883 for (
l=0;
l<nleaves;
l++) {
885 strlcpy(blen,leaf->
GetName(),
sizeof(blen));
888 if (*bname ==
'.') *bname=
'_';
889 if (*bname ==
',') *bname=
'_';
890 if (*bname ==
':') *bname=
'_';
891 if (*bname ==
'<') *bname=
'_';
892 if (*bname ==
'>') *bname=
'_';
896 if (blen[lenb-1] ==
'_') {
899 if (len <= 0) len = 1;
900 fprintf(fp,
" static constexpr Int_t kMax%s = %d;\n",blen,len);
908 fprintf(fp,
"\n // Declaration of leaf types\n");
912 const char *headOK =
" ";
913 const char *headcom =
" //";
915 char branchname[1024];
922 for (
l=0;
l<nleaves;
l++) {
927 len = leaf->
GetLen();
if (len<=0) len = 1;
931 strlcpy(branchname,branch->
GetName(),
sizeof(branchname));
932 strlcpy(aprefix,branch->
GetName(),
sizeof(aprefix));
934 else leafStatus[
l] = 1;
937 strlcat(branchname,
".",
sizeof(branchname));
938 strlcat(branchname,leaf->
GetTitle(),
sizeof(branchname));
941 char *dim = (
char*)strstr(branchname,
"[");
if (dim) dim[0] = 0;
944 strlcpy(branchname,branch->
GetName(),
sizeof(branchname));
946 char *twodim = (
char*)strstr(leaf->
GetTitle(),
"][");
949 if (*bname ==
'.') *bname=
'_';
950 if (*bname ==
',') *bname=
'_';
951 if (*bname ==
':') *bname=
'_';
952 if (*bname ==
'<') *bname=
'_';
953 if (*bname ==
'>') *bname=
'_';
959 if (!leafobj->
GetClass()) {leafStatus[
l] = 1; head = headcom;}
961 if (leafStatus[
l] == 0) mustInit.
Add(leafobj);
967 strlcpy(blen,leafcount->
GetName(),
sizeof(blen));
970 if (*bname ==
'.') *bname=
'_';
971 if (*bname ==
',') *bname=
'_';
972 if (*bname ==
':') *bname=
'_';
973 if (*bname ==
'<') *bname=
'_';
974 if (*bname ==
'>') *bname=
'_';
978 if (blen[lenb-1] ==
'_') {blen[lenb-1] = 0; kmax = 1;}
979 else snprintf(blen,
sizeof(blen),
"%d",len);
1010 if (leafStatus[
l] == 0) mustInit.
Add(bre);
1015 if (!cle) {leafStatus[
l] = 1;
continue;}
1018 strlcpy(brename,bre->
GetName(),255);
1019 char *bren = brename;
1020 char *adot = strrchr(bren,
'.');
1021 if (adot) bren = adot+1;
1022 char *brack = strchr(bren,
'[');
1023 if (brack) *brack = 0;
1038 if (strlen(leaf->
GetTypeName()) == 0) {leafStatus[
l] = 1;
continue;}
1049 const char *stars =
" ";
1056 char *dimInName = (
char*) strstr(branchname,
"[");
1057 if ( twodim || dimInName ) {
1059 dimensions = dimInName;
1062 if (twodim) dimensions += (
char*)(twodim+1);
1064 const char* leafcountName = leafcount->
GetName();
1068 strlcpy(b2len,l2->
GetName(),
sizeof(b2len));
1071 if (*bname ==
'.') *bname=
'_';
1072 if (*bname ==
',') *bname=
'_';
1073 if (*bname ==
':') *bname=
'_';
1074 if (*bname ==
'<') *bname=
'_';
1075 if (*bname ==
'>') *bname=
'_';
1078 leafcountName = b2len;
1080 if (dimensions.
Length()) {
1081 if (kmax) fprintf(fp,
" %-14s %s%s[kMax%s]%s; //[%s]\n",leaf->
GetTypeName(), stars,
1083 else fprintf(fp,
" %-14s %s%s[%d]%s; //[%s]\n",leaf->
GetTypeName(), stars,
1089 if (stars[0]==
'*') {
1091 if (kmax)
n =
new TNamed(branchname,
Form(
"kMax%s",blen));
1096 if (strstr(branchname,
"[")) len = 1;
1107 fprintf(fp,
" // List of branches\n");
1108 for (
l=0;
l<nleaves;
l++) {
1109 if (leafStatus[
l])
continue;
1117 fprintf(fp,
" %s(TTree * /*tree*/ =0) : fChain(0) { }\n",cppClassName.
Data()) ;
1118 fprintf(fp,
" ~%s() override { }\n",cppClassName.
Data());
1119 fprintf(fp,
" Int_t Version() const override { return 2; }\n");
1120 fprintf(fp,
" void Begin(TTree *tree) override;\n");
1121 fprintf(fp,
" void SlaveBegin(TTree *tree) override;\n");
1122 fprintf(fp,
" void Init(TTree *tree) override;\n");
1123 fprintf(fp,
" bool Notify() override;\n");
1124 fprintf(fp,
" bool Process(Long64_t entry) override;\n");
1125 fprintf(fp,
" Int_t GetEntry(Long64_t entry, Int_t getall = 0) override { return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0; }\n");
1126 fprintf(fp,
" void SetOption(const char *option) override { fOption = option; }\n");
1127 fprintf(fp,
" void SetObject(TObject *obj) override { fObject = obj; }\n");
1128 fprintf(fp,
" void SetInputList(TList *input) override { fInput = input; }\n");
1129 fprintf(fp,
" TList* GetOutputList() const override { return fOutput; }\n");
1130 fprintf(fp,
" void SlaveTerminate() override;\n");
1131 fprintf(fp,
" void Terminate() override;\n\n");
1132 fprintf(fp,
" ClassDefOverride(%s,0);\n",cppClassName.
Data());
1135 fprintf(fp,
"#endif\n");
1139 fprintf(fp,
" %s(TTree *tree=0);\n",cppClassName.
Data());
1140 fprintf(fp,
" virtual ~%s();\n",cppClassName.
Data());
1141 fprintf(fp,
" virtual Int_t Cut(Long64_t entry);\n");
1142 fprintf(fp,
" virtual Int_t GetEntry(Long64_t entry);\n");
1143 fprintf(fp,
" virtual Long64_t LoadTree(Long64_t entry);\n");
1144 fprintf(fp,
" virtual void Init(TTree *tree);\n");
1145 fprintf(fp,
" virtual void Loop();\n");
1146 fprintf(fp,
" virtual bool Notify();\n");
1147 fprintf(fp,
" virtual void Show(Long64_t entry = -1);\n");
1150 fprintf(fp,
"#endif\n");
1154 fprintf(fp,
"#ifdef %s_cxx\n",cppClassName.
Data());
1156 fprintf(fp,
"%s::%s(TTree *tree) : fChain(0) \n",cppClassName.
Data(),cppClassName.
Data());
1158 fprintf(fp,
"// if parameter tree is not specified (or zero), connect the file\n");
1159 fprintf(fp,
"// used to generate this class and read the Tree.\n");
1160 fprintf(fp,
" if (tree == 0) {\n");
1162 fprintf(fp,
"\n#ifdef SINGLE_TREE\n");
1163 fprintf(fp,
" // The following code should be used if you want this class to access\n");
1164 fprintf(fp,
" // a single tree instead of a chain\n");
1167 fprintf(fp,
" THbookFile *f = (THbookFile*)gROOT->GetListOfBrowsables()->FindObject(\"%s\");\n",
1169 fprintf(fp,
" if (!f) {\n");
1170 fprintf(fp,
" f = new THbookFile(\"%s\");\n",treefile.
Data());
1173 sscanf(
fTree->GetName(),
"h%d",&hid);
1174 fprintf(fp,
" tree = (TTree*)f->Get(%d);\n\n",hid);
1176 fprintf(fp,
" TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(\"%s\");\n",treefile.
Data());
1177 fprintf(fp,
" if (!f || !f->IsOpen()) {\n");
1178 fprintf(fp,
" f = new TFile(\"%s\");\n",treefile.
Data());
1180 if (
fTree->GetDirectory() !=
fTree->GetCurrentFile()) {
1181 fprintf(fp,
" TDirectory * dir = (TDirectory*)f->Get(\"%s\");\n",
fTree->GetDirectory()->GetPath());
1182 fprintf(fp,
" dir->GetObject(\"%s\",tree);\n\n",
fTree->GetName());
1184 fprintf(fp,
" f->GetObject(\"%s\",tree);\n\n",
fTree->GetName());
1188 fprintf(fp,
"#else // SINGLE_TREE\n\n");
1189 fprintf(fp,
" // The following code should be used if you want this class to access a chain\n");
1190 fprintf(fp,
" // of trees.\n");
1191 fprintf(fp,
" TChain * chain = new TChain(\"%s\",\"%s\");\n",
1198 fprintf(fp,
" chain->Add(\"%s/%s\");\n",element->
GetTitle(),element->
GetName());
1201 fprintf(fp,
" tree = chain;\n");
1202 fprintf(fp,
"#endif // SINGLE_TREE\n\n");
1205 fprintf(fp,
" Init(tree);\n");
1212 fprintf(fp,
"%s::~%s()\n",cppClassName.
Data(),cppClassName.
Data());
1214 fprintf(fp,
" if (!fChain) return;\n");
1218 fprintf(fp,
" delete fChain->GetCurrentFile();\n");
1225 fprintf(fp,
"Int_t %s::GetEntry(Long64_t entry)\n",cppClassName.
Data());
1227 fprintf(fp,
"// Read contents of entry.\n");
1229 fprintf(fp,
" if (!fChain) return 0;\n");
1230 fprintf(fp,
" return fChain->GetEntry(entry);\n");
1235 fprintf(fp,
"Long64_t %s::LoadTree(Long64_t entry)\n",cppClassName.
Data());
1237 fprintf(fp,
"// Set the environment to read one entry\n");
1238 fprintf(fp,
" if (!fChain) return -5;\n");
1239 fprintf(fp,
" Long64_t centry = fChain->LoadTree(entry);\n");
1240 fprintf(fp,
" if (centry < 0) return centry;\n");
1241 fprintf(fp,
" if (fChain->GetTreeNumber() != fCurrent) {\n");
1242 fprintf(fp,
" fCurrent = fChain->GetTreeNumber();\n");
1243 fprintf(fp,
" Notify();\n");
1245 fprintf(fp,
" return centry;\n");
1251 fprintf(fp,
"void %s::Init(TTree *tree)\n",cppClassName.
Data());
1253 fprintf(fp,
" // The Init() function is called when the selector needs to initialize\n"
1254 " // a new tree or chain. Typically here the branch addresses and branch\n"
1255 " // pointers of the tree will be set.\n"
1256 " // It is normally not necessary to make changes to the generated\n"
1257 " // code, but the routine can be extended by the user if needed.\n\n");
1258 if (mustInit.
Last()) {
1259 TIter next(&mustInit);
1261 fprintf(fp,
" // Set object pointer\n");
1262 while( (obj = next()) ) {
1264 strlcpy(branchname,((
TBranch*)obj)->
GetName(),
sizeof(branchname));
1266 strlcpy(branchname,((
TLeaf*)obj)->
GetName(),
sizeof(branchname));
1271 if (*bname ==
'.') *bname=
'_';
1272 if (*bname ==
',') *bname=
'_';
1273 if (*bname ==
':') *bname=
'_';
1274 if (*bname ==
'<') *bname=
'_';
1275 if (*bname ==
'>') *bname=
'_';
1281 if (mustInitArr.
Last()) {
1282 TIter next(&mustInitArr);
1284 fprintf(fp,
" // Set array pointer\n");
1285 while( (info = (
TNamed*)next()) ) {
1286 fprintf(fp,
" for(int i=0; i<%s; ++i) %s[i] = 0;\n",info->
GetTitle(),info->
GetName());
1290 fprintf(fp,
" // Set branch addresses and branch pointers\n");
1291 fprintf(fp,
" if (!tree) return;\n");
1292 fprintf(fp,
" fChain = tree;\n");
1293 if (!opt.
Contains(
"selector")) fprintf(fp,
" fCurrent = -1;\n");
1294 fprintf(fp,
" fChain->SetMakeClass(1);\n");
1296 for (
l=0;
l<nleaves;
l++) {
1297 if (leafStatus[
l])
continue;
1302 strlcpy(aprefix,branch->
GetName(),
sizeof(aprefix));
1306 strlcpy(branchname,branch->
GetName(),
sizeof(branchname));
1307 strlcat(branchname,
".",
sizeof(branchname));
1308 strlcat(branchname,leaf->
GetTitle(),
sizeof(branchname));
1311 char *dim = (
char*)strstr(branchname,
"[");
if (dim) dim[0] = 0;
1314 strlcpy(branchname,branch->
GetName(),
sizeof(branchname));
1317 if (bre->
GetType() == 3 || bre->
GetType()==4) strlcat(branchname,
"_",
sizeof(branchname));
1321 char *brak = strstr(branchname,
"[");
if (brak) *brak = 0;
1322 char *twodim = (
char*)strstr(bname,
"[");
if (twodim) *twodim = 0;
1324 if (*bname ==
'.') *bname=
'_';
1325 if (*bname ==
',') *bname=
'_';
1326 if (*bname ==
':') *bname=
'_';
1327 if (*bname ==
'<') *bname=
'_';
1328 if (*bname ==
'>') *bname=
'_';
1331 const char *maybedisable =
"";
1333 Error(
"MakeClass",
"The branch named %s (full path name: %s) is hidden by another branch of the same name and its data will not be loaded.",branch->
GetName(),
R__GetBranchPointerName(leaf,
false).Data());
1334 maybedisable =
"// ";
1341 strlcpy(branchname,branch->
GetName(),
sizeof(branchname));
1347 if (leafcount) len = leafcount->
GetMaximum()+1;
1348 if (len > 1) fprintf(fp,
"%s fChain->SetBranchAddress(\"%s\", %s, &b_%s);\n",
1350 else fprintf(fp,
"%s fChain->SetBranchAddress(\"%s\", &%s, &b_%s);\n",
1355 fprintf(fp,
" Notify();\n");
1362 fprintf(fp,
"bool %s::Notify()\n",cppClassName.
Data());
1364 fprintf(fp,
" // The Notify() function is called when a new file is opened. This\n"
1365 " // can be for a new TTree in a TChain. It is normally not necessary to make changes\n"
1366 " // to the generated code, but the routine can be extended by the\n"
1367 " // user if needed. The return value is currently not used.\n\n");
1368 fprintf(fp,
" return true;\n");
1374 fprintf(fp,
"void %s::Show(Long64_t entry)\n",cppClassName.
Data());
1376 fprintf(fp,
"// Print contents of entry.\n");
1377 fprintf(fp,
"// If entry is not specified, print current entry\n");
1379 fprintf(fp,
" if (!fChain) return;\n");
1380 fprintf(fp,
" fChain->Show(entry);\n");
1385 fprintf(fp,
"Int_t %s::Cut(Long64_t entry)\n",cppClassName.
Data());
1387 fprintf(fp,
"// This function may be called from Loop.\n");
1388 fprintf(fp,
"// returns 1 if entry is accepted.\n");
1389 fprintf(fp,
"// returns -1 otherwise.\n");
1391 fprintf(fp,
" return 1;\n");
1394 fprintf(fp,
"#endif // #ifdef %s_cxx\n",cppClassName.
Data());
1399 fprintf(fpc,
"#define %s_cxx\n",cppClassName.
Data());
1400 fprintf(fpc,
"#include \"%s\"\n",thead.
Data());
1401 fprintf(fpc,
"#include <TH2.h>\n");
1402 fprintf(fpc,
"#include <TStyle.h>\n");
1403 fprintf(fpc,
"#include <TCanvas.h>\n");
1405 fprintf(fpc,
"void %s::Loop()\n",cppClassName.
Data());
1407 fprintf(fpc,
"// In a ROOT session, you can do:\n");
1408 fprintf(fpc,
"// root> .L %s.C\n",fileNameStem.
Data());
1409 fprintf(fpc,
"// root> %s t\n",cppClassName.
Data());
1410 fprintf(fpc,
"// root> t.GetEntry(12); // Fill t data members with entry number 12\n");
1411 fprintf(fpc,
"// root> t.Show(); // Show values of entry 12\n");
1412 fprintf(fpc,
"// root> t.Show(16); // Read and show values of entry 16\n");
1413 fprintf(fpc,
"// root> t.Loop(); // Loop on all entries\n");
1414 fprintf(fpc,
"//\n");
1415 fprintf(fpc,
"\n// This is the loop skeleton where:\n");
1416 fprintf(fpc,
"// jentry is the global entry number in the chain\n");
1417 fprintf(fpc,
"// ientry is the entry number in the current Tree\n");
1418 fprintf(fpc,
"// Note that the argument to GetEntry must be:\n");
1419 fprintf(fpc,
"// jentry for TChain::GetEntry\n");
1420 fprintf(fpc,
"// ientry for TTree::GetEntry and TBranch::GetEntry\n");
1421 fprintf(fpc,
"//\n");
1422 fprintf(fpc,
"// To read only selected branches, Insert statements like:\n");
1423 fprintf(fpc,
"// METHOD1:\n");
1424 fprintf(fpc,
"// fChain->SetBranchStatus(\"*\",0); // disable all branches\n");
1425 fprintf(fpc,
"// fChain->SetBranchStatus(\"branchname\",1); // activate branchname\n");
1426 fprintf(fpc,
"// METHOD2: replace line\n");
1427 fprintf(fpc,
"// fChain->GetEntry(jentry); //read all branches\n");
1428 fprintf(fpc,
"//by b_branchname->GetEntry(ientry); //read only this branch\n");
1429 fprintf(fpc,
" if (fChain == 0) return;\n");
1430 fprintf(fpc,
"\n Long64_t nentries = fChain->GetEntriesFast();\n");
1431 fprintf(fpc,
"\n Long64_t nbytes = 0, nb = 0;\n");
1432 fprintf(fpc,
" for (Long64_t jentry=0; jentry<nentries;jentry++) {\n");
1433 fprintf(fpc,
" Long64_t ientry = LoadTree(jentry);\n");
1434 fprintf(fpc,
" if (ientry < 0) break;\n");
1435 fprintf(fpc,
" nb = fChain->GetEntry(jentry); nbytes += nb;\n");
1436 fprintf(fpc,
" // if (Cut(ientry) < 0) continue;\n");
1437 fprintf(fpc,
" }\n");
1442 fprintf(fpc,
"#define %s_cxx\n",cppClassName.
Data());
1443 fprintf(fpc,
"// The class definition in %s.h has been generated automatically\n",fileNameStem.
Data());
1444 fprintf(fpc,
"// by the ROOT utility TTree::MakeSelector(). This class is derived\n");
1445 fprintf(fpc,
"// from the ROOT class TSelector. For more information on the TSelector\n"
1446 "// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.\n\n");
1447 fprintf(fpc,
"// The following methods are defined in this file:\n");
1448 fprintf(fpc,
"// Begin(): called every time a loop on the tree starts,\n");
1449 fprintf(fpc,
"// a convenient place to create your histograms.\n");
1450 fprintf(fpc,
"// SlaveBegin(): called after Begin()\n");
1451 fprintf(fpc,
"// Process(): called for each event, in this function you decide what\n");
1452 fprintf(fpc,
"// to read and fill your histograms.\n");
1453 fprintf(fpc,
"// SlaveTerminate: called at the end of the loop on the tree.\n");
1454 fprintf(fpc,
"// Terminate(): called at the end of the loop on the tree,\n");
1455 fprintf(fpc,
"// a convenient place to draw/fit your histograms.\n");
1456 fprintf(fpc,
"//\n");
1457 fprintf(fpc,
"// To use this file, try the following session on your Tree T:\n");
1458 fprintf(fpc,
"//\n");
1459 fprintf(fpc,
"// root> T->Process(\"%s.C\")\n",fileNameStem.
Data());
1460 fprintf(fpc,
"// root> T->Process(\"%s.C\",\"some options\")\n",fileNameStem.
Data());
1461 fprintf(fpc,
"// root> T->Process(\"%s.C+\")\n",fileNameStem.
Data());
1462 fprintf(fpc,
"//\n\n");
1463 fprintf(fpc,
"#include \"%s\"\n",thead.
Data());
1464 fprintf(fpc,
"#include <TH2.h>\n");
1465 fprintf(fpc,
"#include <TStyle.h>\n");
1469 fprintf(fpc,
"void %s::Begin(TTree * /*tree*/)\n",cppClassName.
Data());
1471 fprintf(fpc,
" // The Begin() function is called at the start of the query.\n");
1472 fprintf(fpc,
" // The tree argument is deprecated.\n");
1474 fprintf(fpc,
" TString option = GetOption();\n");
1479 fprintf(fpc,
"void %s::SlaveBegin(TTree * /*tree*/)\n",cppClassName.
Data());
1481 fprintf(fpc,
" // The SlaveBegin() function is called after the Begin() function.\n");
1482 fprintf(fpc,
" // The tree argument is deprecated.\n");
1484 fprintf(fpc,
" TString option = GetOption();\n");
1489 fprintf(fpc,
"bool %s::Process(Long64_t entry)\n",cppClassName.
Data());
1491 fprintf(fpc,
" // The Process() function is called for each entry in the tree to be processed. The entry argument\n"
1492 " // specifies which entry in the currently loaded tree is to be processed.\n"
1493 " // It can be passed to either %s::GetEntry() or TBranch::GetEntry()\n"
1494 " // to read either all or the required parts of the data.\n"
1496 " // This function should contain the \"body\" of the analysis. It can contain\n"
1497 " // simple or elaborate selection criteria, run algorithms on the data\n"
1498 " // of the event and typically fill histograms.\n"
1500 " // The processing can be stopped by calling Abort().\n"
1502 " // Use fStatus to set the return value of TTree::Process().\n"
1504 " // The return value is currently not used.\n\n", cppClassName.
Data());
1506 fprintf(fpc,
" return true;\n");
1510 fprintf(fpc,
"void %s::SlaveTerminate()\n",cppClassName.
Data());
1512 fprintf(fpc,
" // The SlaveTerminate() function is called after all entries or objects\n"
1513 " // have been processed.");
1519 fprintf(fpc,
"void %s::Terminate()\n",cppClassName.
Data());
1521 fprintf(fpc,
" // The Terminate() function is the last function to be called during\n"
1522 " // a query. It always runs on the client, it can be used to present\n"
1523 " // the results graphically or save the results to file.");
1528 Info(
"MakeClass",
"Files: %s and %s generated from TTree: %s",thead.
Data(),tcimp.
Data(),
fTree->GetName());
1529 delete [] leafStatus;
1567 FILE *fp = fopen(tfile,
"w");
1569 Error(
"MakeCode",
"cannot open output file %s", tfile.
Data());
1573 if (
fTree->GetDirectory() &&
fTree->GetDirectory()->GetFile()) {
1574 treefile =
fTree->GetDirectory()->GetFile()->GetName();
1576 treefile =
"Memory Directory";
1588 fprintf(fp,
"//////////////////////////////////////////////////////////\n");
1589 fprintf(fp,
"// This file has been automatically generated \n");
1590 fprintf(fp,
"// (%s by ROOT version%s)\n",td.
AsString(),
gROOT->GetVersion());
1592 fprintf(fp,
"// from TTree %s/%s\n",
fTree->GetName(),
fTree->GetTitle());
1593 fprintf(fp,
"// found on file: %s\n",treefile.
Data());
1595 fprintf(fp,
"// from TChain %s/%s\n",
fTree->GetName(),
fTree->GetTitle());
1597 fprintf(fp,
"//////////////////////////////////////////////////////////\n");
1603 fprintf(fp,
"//Reset ROOT and connect tree file\n");
1604 fprintf(fp,
" gROOT->Reset();\n");
1606 fprintf(fp,
"\n#ifdef SINGLE_TREE\n");
1607 fprintf(fp,
" // The following code should be used if you want this code to access\n");
1608 fprintf(fp,
" // a single tree instead of a chain\n");
1610 fprintf(fp,
" TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(\"%s\");\n",treefile.
Data());
1611 fprintf(fp,
" if (!f) {\n");
1612 fprintf(fp,
" f = new TFile(\"%s\");\n",treefile.
Data());
1614 if (
fTree->GetDirectory() !=
fTree->GetCurrentFile()) {
1615 fprintf(fp,
" TDirectory * dir = (TDirectory*)f->Get(\"%s\");\n",
fTree->GetDirectory()->GetPath());
1616 fprintf(fp,
" dir->GetObject(\"%s\",tree);\n\n",
fTree->GetName());
1618 fprintf(fp,
" f->GetObject(\"%s\",tree);\n\n",
fTree->GetName());
1621 fprintf(fp,
"#else // SINGLE_TREE\n\n");
1622 fprintf(fp,
" // The following code should be used if you want this code to access a chain\n");
1623 fprintf(fp,
" // of trees.\n");
1624 fprintf(fp,
" TChain *%s = new TChain(\"%s\",\"%s\");\n",
1634 fprintf(fp,
"#endif // SINGLE_TREE\n\n");
1638 fprintf(fp,
"//Declaration of leaves types\n");
1643 const char *headOK =
" ";
1644 const char *headcom =
" //";
1646 char branchname[1024];
1647 for (
l=0;
l<nleaves;
l++) {
1656 strlcpy(branchname,branch->
GetName(),
sizeof(branchname));
1657 strlcat(branchname,
".",
sizeof(branchname));
1658 strlcat(branchname,leaf->
GetTitle(),
sizeof(branchname));
1661 char *dim = (
char*)strstr(branchname,
"[");
1662 if (dim) dim[0] = 0;
1665 if (leafcount) strlcpy(branchname,branch->
GetName(),
sizeof(branchname));
1666 else strlcpy(branchname,leaf->
GetTitle(),
sizeof(branchname));
1668 char *twodim = (
char*)strstr(leaf->
GetTitle(),
"][");
1671 if (*bname ==
'.') *bname=
'_';
1672 if (*bname ==
',') *bname=
'_';
1673 if (*bname ==
':') *bname=
'_';
1674 if (*bname ==
'<') *bname=
'_';
1675 if (*bname ==
'>') *bname=
'_';
1680 if (leafobj->
GetClass()) head = headOK;
1681 else head = headcom;
1689 char *dimInName = (
char*) strstr(branchname,
"[");
1691 if ( twodim || dimInName ) {
1693 dimensions = dimInName;
1696 if (twodim) dimensions += (
char*)(twodim+1);
1698 if (dimensions.
Length()) {
1699 fprintf(fp,
" %-15s %s[%d]%s;\n",leaf->
GetTypeName(), branchname,len,dimensions.
Data());
1701 fprintf(fp,
" %-15s %s[%d];\n",leaf->
GetTypeName(), branchname,len);
1704 if (strstr(branchname,
"[")) len = 1;
1705 if (len < 2) fprintf(fp,
" %-15s %s;\n",leaf->
GetTypeName(), branchname);
1706 else fprintf(fp,
" %-15s %s[%d];\n",leaf->
GetTypeName(), branchname,len);
1711 fprintf(fp,
"\n // Set branch addresses.\n");
1712 for (
l=0;
l<nleaves;
l++) {
1720 strlcpy(branchname,branch->
GetName(),
sizeof(branchname));
1721 strlcat(branchname,
".",
sizeof(branchname));
1722 strlcat(branchname,leaf->
GetTitle(),
sizeof(branchname));
1725 char *dim = (
char*)strstr(branchname,
"[");
1726 if (dim) dim[0] = 0;
1729 if (leafcount) strlcpy(branchname,branch->
GetName(),
sizeof(branchname));
1730 else strlcpy(branchname,leaf->
GetTitle(),
sizeof(branchname));
1734 if (*bname ==
'.') *bname=
'_';
1735 if (*bname ==
',') *bname=
'_';
1736 if (*bname ==
':') *bname=
'_';
1737 if (*bname ==
'<') *bname=
'_';
1738 if (*bname ==
'>') *bname=
'_';
1741 char *brak = strstr(branchname,
"[");
1742 if (brak) *brak = 0;
1745 strlcpy(branchname,branch->
GetName(),
sizeof(branchname));
1747 if (!leafobj->
GetClass()) head = headcom;
1749 if (leafcount) len = leafcount->
GetMaximum()+1;
1750 if (len > 1 || brak) fprintf(fp,
"%s%s->SetBranchAddress(\"%s\",%s);\n",head,
fTree->GetName(),branch->
GetName(),branchname);
1751 else fprintf(fp,
"%s%s->SetBranchAddress(\"%s\",&%s);\n",head,
fTree->GetName(),branch->
GetName(),branchname);
1755 fprintf(fp,
"\n// This is the loop skeleton\n");
1756 fprintf(fp,
"// To read only selected branches, Insert statements like:\n");
1757 fprintf(fp,
"// %s->SetBranchStatus(\"*\",0); // disable all branches\n",
fTree->GetName());
1758 fprintf(fp,
"// %s->SetBranchStatus(\"branchname\",1); // activate branchname\n",
GetName());
1759 fprintf(fp,
"\n Long64_t nentries = %s->GetEntries();\n",
fTree->GetName());
1760 fprintf(fp,
"\n Long64_t nbytes = 0;\n");
1761 fprintf(fp,
"// for (Long64_t i=0; i<nentries;i++) {\n");
1762 fprintf(fp,
"// nbytes += %s->GetEntry(i);\n",
fTree->GetName());
1763 fprintf(fp,
"// }\n");
1766 printf(
"Macro: %s generated from Tree: %s\n",tfile.
Data(),
fTree->GetName());
1925 const char *macrofilename,
const char *cutfilename,
1926 const char *option,
Int_t maxUnrolling)
1928 if (macrofilename==
nullptr || strlen(macrofilename)==0 ) {
1930 Error(
"MakeProxy",
"A file name for the user script is required");
1934 ROOT::Internal::TTreeProxyGenerator gp(
fTree,macrofilename,cutfilename,proxyClassname,option,maxUnrolling);
1986 if (!classname) classname =
fTree->GetName();
2017 std::vector<TString> cnames;
2026 if (nleaves < ncols) ncols = nleaves;
2027 nch = varexp ? strlen(varexp) : 0;
2033 if (strlen(selection)) {
2035 if (!select)
return principal;
2036 if (!select->GetNdim()) {
delete select;
return principal; }
2041 if (varexp && !strcmp(varexp,
"*")) { ncols = nleaves; allvar = 1; }
2042 if (nch == 0 || allvar) {
2043 for (i=0;i<ncols;i++) {
2044 cnames.push_back( ((
TLeaf*)leaves->
At(i))->GetName() );
2048 ncols =
fSelector->SplitNames(varexp,cnames);
2054 for (i=0;i<ncols;i++) {
2076 for (entry=firstentry;entry<firstentry+
nentries;entry++) {
2077 entryNumber =
fTree->GetEntryNumber(entry);
2078 if (entryNumber < 0)
break;
2080 if (localEntry < 0)
break;
2081 if (tnumber !=
fTree->GetTreeNumber()) {
2082 tnumber =
fTree->GetTreeNumber();
2090 for(
int inst=0;inst<ndata;inst++) {
2091 bool loaded =
false;
2093 if (select->EvalInstance(inst) == 0) {
2098 if (inst==0) loaded =
true;
2102 for (i=0;i<ncols;i++) {
2108 for (i=0;i<ncols;i++) {
2111 principal->AddRow(xvars);
2117 principal->MakePrincipals();
2118 if (opt.
Contains(
"d")) principal->Print();
2119 if (opt.
Contains(
"h")) principal->MakeHistograms();
2120 if (opt.
Contains(
"c")) principal->MakeCode();
2203 if (!selector)
return -1;
2238 fTree->SetNotify(selector);
2268 fTree->EnableCache();
2277 if (!
gROOT->IsBatch() && interval)
2281 Long64_t entry, entryNumber, localEntry;
2283 bool useCutFill = selector->
Version() == 0;
2295 for (entry = firstentry; entry - firstentry <
nentries; entry++) {
2296 entryNumber =
fTree->GetEntryNumber(entry);
2297 if (entryNumber < 0)
break;
2299 if (
gROOT->IsInterrupted())
break;
2300 localEntry =
fTree->LoadTree(entryNumber);
2301 if (localEntry < 0)
break;
2306 selector->
Process(localEntry);
2313 entry +=
fTree->GetTree()->GetEntries() - localEntry;
2322 if (curfile2 &&
fTree->GetCacheSize() > 0) {
2337 fTree->SetNotify(
nullptr);
2454 constexpr auto length = std::char_traits<char>::length;
2459 UInt_t colDefaultSize = 9;
2461 std::vector<TString> colFormats;
2462 std::vector<Int_t> colSizes;
2466 int numpos =
start + length(
"lenmax=");
2469 while( (numpos+numlen<len) && isdigit(opt[numpos+numlen]) ) numlen++;
2470 TString num = opt(numpos,numlen);
2473 lenmax = atoi(num.
Data());
2477 int numpos =
start + length(
"colsize=");
2480 while( (numpos+numlen<len) && isdigit(opt[numpos+numlen]) ) numlen++;
2481 TString num = opt(numpos,numlen);
2484 colDefaultSize = atoi(num.
Data());
2485 colPrecision = colDefaultSize;
2486 if (colPrecision>18) colPrecision = 18;
2490 int numpos =
start + length(
"precision=");
2493 while( (numpos+numlen<len) && isdigit(opt[numpos+numlen]) ) numlen++;
2494 TString num = opt(numpos,numlen);
2497 colPrecision = atoi(num.
Data());
2499 TString defFormat =
Form(
"%d.%d",colDefaultSize,colPrecision);
2502 int numpos =
start + length(
"col=");
2505 while( (numpos+numlen<len) &&
2506 (isdigit(opt[numpos+numlen])
2507 || opt[numpos+numlen] ==
'c'
2508 || opt[numpos+numlen] ==
'd'
2509 || opt[numpos+numlen] ==
'i'
2510 || opt[numpos+numlen] ==
'o'
2511 || opt[numpos+numlen] ==
'x'
2512 || opt[numpos+numlen] ==
'X'
2513 || opt[numpos+numlen] ==
'u'
2514 || opt[numpos+numlen] ==
'f'
2515 || opt[numpos+numlen] ==
'e'
2516 || opt[numpos+numlen] ==
'E'
2517 || opt[numpos+numlen] ==
'g'
2518 || opt[numpos+numlen] ==
'G'
2519 || opt[numpos+numlen] ==
'l'
2520 || opt[numpos+numlen] ==
'L'
2521 || opt[numpos+numlen] ==
'h'
2522 || opt[numpos+numlen] ==
's'
2523 || opt[numpos+numlen] ==
'#'
2524 || opt[numpos+numlen]==
'.'
2525 || opt[numpos+numlen]==
':')) numlen++;
2526 TString flist = opt(numpos,numlen);
2530 while(i<flist.
Length() && flist[i]==
':') {
2531 colFormats.push_back(defFormat);
2532 colSizes.push_back(colDefaultSize);
2535 for(; i<flist.
Length(); ++i) {
2536 int next = flist.
Index(
":",i);
2538 colFormats.push_back(defFormat);
2539 }
else if (next==
kNPOS) {
2540 colFormats.push_back(flist(i,flist.
Length()-i));
2543 colFormats.push_back(flist(i,next-i));
2546 UInt_t siz = atoi(colFormats[colFormats.size()-1].Data());
2547 colSizes.push_back( siz ? siz : colDefaultSize );
2552 std::vector<TString> cnames;
2558 const char *fname =
nullptr;
2561 fTree->SetScanField(0);
2563 if (!fname) fname =
"";
2564 Int_t lenfile = strlen(fname);
2566 fownname =
fTree->GetName();
2567 fownname.
Append(
"-scan.dat");
2568 fname = fownname.
Data();
2570 out.open(fname, std::ios::out);
2572 Error(
"Scan",
"Can not open file for redirection");
2577 if (leaves==
nullptr)
return 0;
2579 if (nleaves < ncols) ncols = nleaves;
2580 nch = varexp ? strlen(varexp) : 0;
2586 if (selection && strlen(selection)) {
2588 if (!select)
return -1;
2589 if (!select->GetNdim()) {
delete select;
return -1; }
2594 if (varexp && !strcmp(varexp,
"*")) { ncols = nleaves; allvar = 1; }
2595 if (nch == 0 || allvar) {
2598 for (ui=0;ui<ncs;++ui) {
2602 if (cnames[ncols] == lf->
GetName() ) {
2604 }
else if (cnames[ncols][cnames[ncols].Length()-1]==
'.') {
2617 cnames[ncols].Append(
'.');
2623 cnames[ncols].Append(
'.');
2624 cnames[ncols].Append( lf->
GetName() );
2631 ncols =
fSelector->SplitNames(varexp, cnames);
2636 for(ui=colFormats.size();ui<ncols;++ui) {
2637 colFormats.push_back(defFormat);
2638 colSizes.push_back(colDefaultSize);
2642 for (ui=0;ui<ncols;ui++) {
2649 bool hasArray =
false;
2650 bool forceDim =
false;
2653 if (select->GetManager()->GetMultiplicity() > 0 ) {
2680 onerow =
"***********";
2681 if (hasArray) onerow +=
"***********";
2683 for (ui=0;ui<ncols;ui++) {
2684 TString starFormat =
Form(
"*%%%d.%ds",colSizes[ui]+2,colSizes[ui]+2);
2688 out<<onerow.
Data()<<
"*"<<std::endl;
2690 printf(
"%s*\n",onerow.
Data());
2692 if (hasArray) onerow +=
"* Instance ";
2693 for (ui=0;ui<ncols;ui++) {
2694 TString numbFormat =
Form(
"* %%%d.%ds ",colSizes[ui],colSizes[ui]);
2698 out<<onerow.
Data()<<
"*"<<std::endl;
2700 printf(
"%s*\n",onerow.
Data());
2701 onerow =
"***********";
2702 if (hasArray) onerow +=
"***********";
2703 for (ui=0;ui<ncols;ui++) {
2704 TString starFormat =
Form(
"*%%%d.%ds",colSizes[ui]+2,colSizes[ui]+2);
2708 out<<onerow.
Data()<<
"*"<<std::endl;
2710 printf(
"%s*\n",onerow.
Data());
2714 bool exitloop =
false;
2715 for (entry = firstentry; entry - firstentry <
nentries && !exitloop; entry++) {
2716 entryNumber =
fTree->GetEntryNumber(entry);
2717 if (entryNumber < 0)
break;
2719 if (localEntry < 0)
break;
2720 if (tnumber !=
fTree->GetTreeNumber()) {
2721 tnumber =
fTree->GetTreeNumber();
2740 for (ui=0;ui<ncols;ui++) {
2741 if (ndata < var[ui]->GetNdata() ) {
2745 if (select && select->GetNdata()==0) ndata = 0;
2750 if (lenmax && ndata>(
int)lenmax) ndata = lenmax;
2751 bool loaded =
false;
2752 for(
int inst=0;inst<ndata;inst++) {
2754 if (select->EvalInstance(inst) == 0) {
2758 if (inst==0) loaded =
true;
2762 for (ui=0;ui<ncols;ui++) {
2767 onerow =
Form(
"* %8lld ",entryNumber);
2769 onerow +=
Form(
"* %8d ",inst);
2771 for (ui=0;ui<ncols;++ui) {
2772 TString numbFormat =
Form(
"* %%%d.%ds ",colSizes[ui],colSizes[ui]);
2773 if (var[ui]->GetNdim()) onerow +=
Form(numbFormat.
Data(),var[ui]->
PrintValue(0,inst,colFormats[ui].Data()));
2775 TString emptyForm =
Form(
"* %%%dc ",colSizes[ui]);
2776 onerow +=
Form(emptyForm.
Data(),
' ');
2781 out<<onerow.
Data()<<
"*"<<std::endl;
2783 printf(
"%s*\n",onerow.
Data());
2786 fprintf(stderr,
"Type <CR> to continue or q to quit ==> ");
2790 while (readch !=
'\n' && readch != EOF) readch = getchar();
2791 if (answer ==
'q' || answer ==
'Q') {
2799 onerow =
"***********";
2800 if (hasArray) onerow +=
"***********";
2801 for (ui=0;ui<ncols;ui++) {
2802 TString starFormat =
Form(
"*%%%d.%ds",colSizes[ui]+2,colSizes[ui]+2);
2806 out<<onerow.
Data()<<
"*"<<std::endl;
2808 printf(
"%s*\n",onerow.
Data());
2831 std::vector<TString> cnames;
2838 if (nleaves < ncols) ncols = nleaves;
2839 nch = varexp ? strlen(varexp) : 0;
2845 if (strlen(selection)) {
2847 if (!select)
return nullptr;
2848 if (!select->GetNdim()) {
delete select;
return nullptr; }
2854 if (varexp && !strcmp(varexp,
"*")) { ncols = nleaves; allvar = 1; }
2855 if (nch == 0 || allvar) {
2856 for (i=0;i<ncols;i++) {
2857 cnames.push_back( ((
TLeaf*)leaves->
At(i))->GetName() );
2861 ncols =
fSelector->SplitNames(varexp,cnames);
2866 for (i=0;i<ncols;i++) {
2873 for (i = 0; i < ncols; i++) {
2874 res->
AddField(i, var[i]->PrintValue(-1));
2888 const char *aresult;
2890 char *arow =
new char[ncols*50];
2894 for (entry=firstentry;entry<firstentry+
nentries;entry++) {
2895 entryNumber =
fTree->GetEntryNumber(entry);
2896 if (entryNumber < 0)
break;
2898 if (localEntry < 0)
break;
2899 if (tnumber !=
fTree->GetTreeNumber()) {
2900 tnumber =
fTree->GetTreeNumber();
2911 if (select->EvalInstance(0) == 0)
continue;
2914 bool loaded =
false;
2915 for(
int inst=0;inst<ndata;inst++) {
2917 if (select->EvalInstance(inst) == 0) {
2922 if (inst==0) loaded =
true;
2926 for (i=0;i<ncols;i++) {
2931 for (i=0;i<ncols;i++) {
2933 len = strlen(aresult)+1;
2935 memcpy(arow,aresult,len);
2938 memcpy(arow+fields[i-1],aresult,len);
2939 fields[i] = fields[i-1] + len;
2981 TString hname =
gEnv->GetValue(
"TreeViewer.Name",
"TTreeViewer");
2985 gApplication->InitializeGraphics(hname ==
"RTreeViewer");
2987 if (
gROOT->IsBatch()) {
2988 if ((hname !=
"RTreeViewer") ||
gROOT->IsWebDisplayBatch()) {
2989 Warning(
"StartViewer",
"The tree viewer cannot run in batch mode");
2994 if (
auto h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualTreeViewer", hname.
Data())) {
2995 if (
h->LoadPlugin() != -1)
3074 TF1* fitfunc = (
TF1*)
gROOT->GetFunction(funcname);
3075 if (!fitfunc) {
Error(
"UnbinnedFit",
"Unknown function: %s",funcname);
return 0; }
3078 if (npar <=0) {
Error(
"UnbinnedFit",
"Illegal number of parameters = %d",npar);
return 0; }
3099 if (!fitOption.
Nograph) drawOpt =
"";
3103 Info(
"UnbinnedFit",
"Ignore option D with more than 4 variables");
3111 Error(
"UnbinnedFit",
"Cannot fit: no entries selected");
3122 std::vector<double *> vlist(ndim);
3123 for (
int i = 0; i < ndim; ++i)
3137 fTree->SetEstimate(oldEstimate);
3149 for (
Int_t bin=1;bin<=nbins;bin++) {
3153 fHistogram->GetListOfFunctions()->Add(hf,
"lsame");
int Int_t
Signed integer 4 bytes (int).
int Ssiz_t
String size (currently int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
double Double_t
Double 8 bytes.
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
long long Long64_t
Portable signed long integer 8 bytes.
const char Option_t
Option string (const char).
externTApplication * gApplication
externTVirtualMutex * gROOTMutex
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
static TString R__GetBranchPointerName(TLeaf *leaf, bool replace=true)
Return the name of the branch pointer needed by MakeClass/MakeSelector.
externTVirtualMonitoringWriter * gMonitoringWriter
#define R__LOCKGUARD(mutex)
Class describing the un-binned data sets (just x coordinates values) of any dimensions.
const char * GetFileName()
static void CreateApplication()
Static function used to create a default application environment.
static void NeedGraphicsLibs()
Static method.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
A Branch for the case of an object.
const char * GetClassName() const override
Return the name of the user class whose content is stored in this branch, if any.
Int_t GetStreamerType() const
TBranchElement * GetBranchCount2() const
bool IsBranchFolder() const
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.
TObjArray * GetListOfBranches()
TClass * IsA() const override
TObjArray * GetListOfLeaves()
TBranch * GetMother() const
Get our top-level parent branch in the tree.
A TChainElement describes a component of a TChain.
A chain is a collection of files containing TTree objects.
TClass instances represent classes, structs and namespaces in the ROOT type system.
void AdoptReferenceProxy(TVirtualRefProxy *proxy)
Adopt the Reference proxy pointer to indicate that this class represents a reference.
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process's memory.
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,...
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
const char * GetDeclFileName() const
Return name of the file containing the declaration of this class.
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.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
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).
TDirectory::TContext keeps track and restore the current directory.
virtual void SetTree(const TTree *tree)
virtual Long64_t GetN() const
<div class="legacybox"><h2>Legacy Code</h2> TEventList is a legacy interface: there will be no bug fi...
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
virtual Int_t GetNpar() const
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
static Long64_t GetFileBytesRead()
Static function returning the total number of bytes read from all files.
TFileCacheRead * GetCacheRead(const TObject *tree=nullptr) const
Return a pointer to the current read cache.
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
TH1 is the base class of all histogram classes in ROOT.
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
@ kNoAxis
NOTE: Must always be 0 !!!
A TLeaf for a general object derived from TObject.
TClass * GetClass() const
const char * GetTypeName() const override
Returns name of leaf type.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual Int_t GetMaximum() const
virtual const char * GetTypeName() const
virtual Int_t GetLen() const
Return the number of effective elements of this leaf, for the current entry.
virtual TLeaf * GetLeafCount() const
If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has vari...
TBranch * GetBranch() const
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
void Add(TObject *obj) override
The TNamed class is the base class for all named ROOT classes.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Int_t GetEntriesFast() const
void AddAt(TObject *obj, Int_t idx) override
Add object at position ids.
TObject * Last() const override
Return the object in the last filled slot. Returns 0 if no entries.
Int_t GetEntries() const override
Return the number of objects in array (i.e.
void Delete(Option_t *option="") override
Remove all objects from the array AND delete all heap based objects.
TObject * At(Int_t idx) const override
TObject * UncheckedAt(Int_t i) const
TObject * FindObject(const char *name) const override
Find an object in this collection using its name.
void Add(TObject *obj) override
Wrapper around a TObject so it can be stored in a TList.
TObject * GetObject() const
Collectable string class.
const char * GetName() const override
Returns name of object.
virtual Bool_t Notify()
This method must be overridden to handle object notification (the base implementation is no-op).
virtual const char * GetName() const
Returns name of object.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
TObject()
TObject constructor.
@ kCanDelete
if object in a list can be deleted
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
void Draw(Option_t *option="") override
Draws 3-D polymarker with its current attributes.
Bool_t ProcessEvents()
Process events if timer did time out.
A container proxy, which allows to access references stored in a TRefArray from TTree::Draw.
A specialized TSelector for TTree::Draw.
The class is derived from the ROOT class TSelector.
virtual Long64_t GetSelectedRows() const
A TSelector object is used by the TTree::Draw, TTree::Scan, TTree::Process to navigate in a TTree and...
virtual EAbort GetAbort() const
virtual void ProcessFill(Long64_t)
This method is called for all selected entries.
virtual void Init(TTree *)
virtual int Version() const
virtual bool ProcessCut(Long64_t)
This method is called before processing entry.
virtual bool Process(Long64_t)
The Process() function is called for each entry in the tree to be processed.
TClass * IsA() const override
virtual void SlaveBegin(TTree *)
bool Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
virtual void SetOption(const char *option)
virtual Long64_t GetStatus() const
virtual void SlaveTerminate()
virtual void ResetAbort()
virtual void Begin(TTree *)
static TSelector * GetSelector(const char *filename)
The code in filename is loaded (interpreted or compiled, see below), filename must contain a valid cl...
Describe one element (data member) to be Streamed.
const char * GetTypeName() const
TClass * IsA() const override
void ToLower()
Change string to lower-case.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Ssiz_t Last(char c) const
Find last occurrence of a character c.
void ToUpper()
Change string to upper case.
TString & Remove(Ssiz_t pos)
TString & Append(const char *cs)
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
A cache to speed-up the reading of ROOT datasets.
virtual void SetEntryRange(Long64_t emin, Long64_t emax)
Set the minimum and maximum entry number to be processed this information helps to optimize the numbe...
A Tree Index with majorname and minorname.
Int_t MakeCode(const char *filename) override
Generate skeleton function for this Tree.
TTree * CopyTree(const char *selection, Option_t *option, Long64_t nentries, Long64_t firstentry) override
Copy a Tree with selection, make a clone of this Tree header, then copy the selected entries.
Long64_t DrawSelect(const char *varexp, const char *selection, Option_t *option, Long64_t nentries, Long64_t firstentry) override
Draw expression varexp for specified entries that matches the selection.
TList * fInput
! input list to the selector
void DeleteSelectorFromFile()
Delete any selector created by this object.
void SetEstimate(Long64_t n) override
Set number of entries to estimate variable limits.
Int_t UnbinnedFit(const char *formula, const char *varexp, const char *selection, Option_t *option, Long64_t nentries, Long64_t firstentry) override
Unbinned fit of one or more variable(s) from a Tree.
void RecursiveRemove(TObject *obj) override
cleanup pointers in the player pointing to obj
Long64_t DrawScript(const char *wrapperPrefix, const char *macrofilename, const char *cutfilename, Option_t *option, Long64_t nentries, Long64_t firstentry) override
Draw the result of a C++ script.
TSelectorDraw * fSelector
! Pointer to current selector
Long64_t GetSelectedRows() const override
Int_t MakeReader(const char *classname, Option_t *option) override
Generate a skeleton analysis class for this Tree using TBranchProxy.
const char * GetNameByIndex(TString &varexp, Int_t *index, Int_t colindex)
Return name corresponding to colindex in varexp.
Long64_t fSelectedRows
Number of selected entries.
Long64_t Scan(const char *varexp, const char *selection, Option_t *option, Long64_t nentries, Long64_t firstentry) override
Loop on Tree and print entries passing selection.
TSelector * fSelectorFromFile
! Pointer to a user defined selector created by this TTreePlayer object
const char * fScanFileName
Name of the file where Scan is redirected.
TList * fFormulaList
! Pointer to a list of coordinated list TTreeFormula (used by Scan and Query)
bool fScanRedirect
Switch to redirect TTree::Scan output to a file.
TTree * fTree
! Pointer to current Tree
void StartViewer(Int_t ww, Int_t wh) override
Start the TTreeViewer on this TTree.
Int_t MakeProxy(const char *classname, const char *macrofilename=nullptr, const char *cutfilename=nullptr, const char *option=nullptr, Int_t maxUnrolling=3) override
Int_t MakeClass(const char *classname, Option_t *option) override
Generate skeleton analysis class for this Tree.
TPrincipal * Principal(const char *varexp, const char *selection, Option_t *option, Long64_t nentries, Long64_t firstentry) override
Interface to the Principal Components Analysis class.
TSelector * fSelectorUpdate
! Set to the selector address when it's entry list needs to be updated by the UpdateFormulaLeaves fun...
TH1 * fHistogram
! Pointer to histogram used for the projection
void UpdateFormulaLeaves() override
this function is called by TChain::LoadTree when a new Tree is loaded.
Long64_t Process(const char *filename, Option_t *option, Long64_t nentries, Long64_t firstentry) override
Process this tree executing the TSelector code in the specified filename.
TSQLResult * Query(const char *varexp, const char *selection, Option_t *option, Long64_t nentries, Long64_t firstentry) override
Loop on Tree and return TSQLResult object containing entries passing selection.
TClass * fSelectorClass
! Pointer to the actual class of the TSelectorFromFile
Long64_t GetEntries(const char *selection) override
Return the number of entries matching the selection.
Int_t GetDimension() const override
Int_t fDimension
Dimension of the current expression.
TTreePlayer()
Default Tree constructor.
TVirtualIndex * BuildIndex(const TTree *T, const char *majorname, const char *minorname, bool long64major=false, bool long64minor=false) override
Build the index for the tree (see TTree::BuildIndex) In some cases, a warning is printed about switch...
~TTreePlayer() override
Tree destructor.
Int_t Fit(const char *formula, const char *varexp, const char *selection, Option_t *option, Option_t *goption, Long64_t nentries, Long64_t firstentry) override
Fit a projected item(s) from a Tree.
virtual Long64_t GetEntriesToProcess(Long64_t firstentry, Long64_t nentries) const
return the number of entries to be processed this function checks that nentries is not bigger than th...
Class defining interface to a TTree query result with the same interface as for SQL databases.
void AddRow(TSQLRow *row)
Adopt a row to result set.
void AddField(Int_t field, const char *fieldname)
Add field name to result set.
Class defining interface to a row of a TTree query result.
A TTree represents a columnar dataset.
virtual Int_t Fill()
Fill all branches.
virtual TObjArray * GetListOfBranches()
Abstract Base Class for Fitting.
Abstract interface for Tree Index.
virtual TObjArray * GetElements() const =0
TFitResultPtr UnBinFit(ROOT::Fit::UnBinData *data, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption)
fit an unbin data set (from tree or from histogram buffer) using a TF1 pointer and fit options.
TString GetCppName(TString name)
Convert a valid TTree branch name or filename into a valid C++ variable name.
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.