Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions hist/hist/test/test_TH1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "TH3.h"
#include "TH1F.h"
#include "THLimitsFinder.h"
#include "TDirectory.h"
#include "TList.h"
#include "TROOT.h"

#include <cmath>
#include <cstddef>
Expand Down Expand Up @@ -167,6 +170,51 @@ TEST(TH1, Normalize)
EXPECT_FLOAT_EQ(v2.GetMaximum(), 7.9999990);
}

TEST(TH1, RegistrationToTDirectory_ImplicitOwnershipOn)
{
TH1D histo1("histo1", "Test Histogram", 10, 0, 10);
Comment thread
hageboeck marked this conversation as resolved.
auto histo2 = std::make_unique<TH1D>("histo2", "Test Histogram", 10, 0, 10);
TH1D *histo3 = new TH1D("histo3", "Test Histogram", 10, 0, 10);

{
TDirectory dir("dir", "Test Directory");
histo3->SetDirectory(&dir);

dir.cd();

TH1D histo4("histo4", "Test Histogram", 10, 0, 10);
auto histo5 = std::make_unique<TH1D>("histo5", "Test Histogram", 10, 0, 10);

EXPECT_EQ(dir.GetList()->GetSize(), 3);
EXPECT_EQ(dir.Get<TH1D>("histo1"), nullptr);
EXPECT_EQ(dir.Get<TH1D>("histo2"), nullptr);
EXPECT_EQ(dir.Get<TH1D>("histo3"), histo3);
Comment thread
hageboeck marked this conversation as resolved.
EXPECT_EQ(dir.Get<TH1D>("histo4"), &histo4);
EXPECT_EQ(dir.Get<TH1D>("histo5"), histo5.get());
Comment thread
hageboeck marked this conversation as resolved.

EXPECT_EQ(histo1.GetDirectory(), gROOT);
EXPECT_EQ(histo2->GetDirectory(), gROOT);
EXPECT_EQ(histo3->GetDirectory(), &dir);
EXPECT_EQ(histo4.GetDirectory(), &dir);
EXPECT_EQ(histo5->GetDirectory(), &dir);

histo5.reset();

EXPECT_EQ(dir.GetList()->GetSize(), 2);
EXPECT_EQ(dir.Get<TH1D>("histo1"), nullptr);
EXPECT_EQ(dir.Get<TH1D>("histo2"), nullptr);
EXPECT_EQ(dir.Get<TH1D>("histo3"), histo3);
EXPECT_EQ(dir.Get<TH1D>("histo4"), &histo4);
EXPECT_EQ(dir.Get<TH1D>("histo5"), nullptr);
}

EXPECT_STREQ(histo1.GetName(), "histo1");
EXPECT_STREQ(histo2->GetName(), "histo2");

EXPECT_EQ(histo1.GetDirectory(), gROOT);
EXPECT_EQ(histo2->GetDirectory(), gROOT);
}

TEST(TAxis, BinComputation_FPAccuracy)
{
// Example from 1703c54
Expand Down
5 changes: 3 additions & 2 deletions roottest/python/JupyROOT/ROOT_kernel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
],
"source": [
"%%cpp -a\n",
"#include <sstream> \n",
"#include <sstream>\n",
"\n",
"template<class T>\n",
"class B{};\n",
Expand Down Expand Up @@ -172,7 +172,8 @@
"outputs": [],
"source": [
"%%python\n",
"h = ROOT.TH1F(\"s\",\"s\",10,0,1)"
"h = ROOT.TH1F(\"s\",\"s\",10,0,1)\n",
"h.SetDirectory(ROOT.gDirectory)"
]
},
{
Expand Down
2 changes: 2 additions & 0 deletions roottest/root/hist/misc/runownership.C
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ void write(const char *filename = "histo.root")
{
TFile * f = TFile::Open(filename,"RECREATE");
TH1F *histo = new TH1F_inst("h1","h1",10,0,10); histo->Fill(3);
histo->SetDirectory(f);
histo = new TH1F_inst("h2","h2",10,0,10); histo->Fill(3);
histo->SetDirectory(f);
TCanvas *c1 = new TCanvas("c1");
histo->SetBit(kCanDelete);
histo->Draw();
Expand Down
31 changes: 16 additions & 15 deletions roottest/root/io/directory/testFindObjectAny.C
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
void doit()
{
TFile* base = new TFile("f.db","recreate");
TDirectory* a = base->mkdir("a","First Level Dir");
a->cd();
TDirectory *a = base->mkdir("a", "First Level Dir");
TH1D* ha = new TH1D("ha","ha",10,0,1);
TDirectory* aa = a->mkdir("aa","Second Level Dira");
aa->cd();
ha->SetDirectory(a);
TDirectory *aa = a->mkdir("aa", "Second Level Dira");
TH1D* haa = new TH1D("haa","haa",10,0,1);

haa->SetDirectory(aa);

a->ls();

printf(" a: created@ %p found@ %p\n", a,base->FindObjectAny("a"));
Expand Down Expand Up @@ -92,13 +92,13 @@ void testing(TObject *orig, TObject *found)
}
}

int testFindObjectAny()
{
TDirectory* db = gROOT->mkdir("db","db");
TDirectory* a = db->mkdir("a","a");
TDirectory* aa = a->mkdir("aa","aa");
aa->cd();
TH1D* haa_new = new TH1D("haa","haa",10,0,1);
int testFindObjectAny()
{
TDirectory *db = gROOT->mkdir("db", "db");
TDirectory *a = db->mkdir("a", "a");
TDirectory *aa = a->mkdir("aa", "aa");
TH1D *haa_new = new TH1D("haa", "haa", 10, 0, 1);
haa_new->SetDirectory(aa);
TH1D* haa_find = (TH1D*)db->FindObjectAny("haa");
#ifdef ClingWorkAroundMissingDynamicScope
TH1D* haa = haa_find;
Expand All @@ -108,15 +108,15 @@ int testFindObjectAny()
} else if (haa_new != haa_find) {
cout << "haa not found correctly!\n";
}

TFile* base = new TFile("fdb.root","recreate");
#ifdef ClingReinstateRedeclarationAllowed
TDirectory* a = base->mkdir("a","First Level Dir");
#else
a = base->mkdir("a","First Level Dir");
#endif
a->cd();
TH1D* ha = new TH1D("ha","ha",10,0,1);
ha->SetDirectory(a);
#ifdef ClingReinstateRedeclarationAllowed
TDirectory* aa = a->mkdir("aa","Second Level Dira");
#else
Expand All @@ -128,7 +128,8 @@ int testFindObjectAny()
#else
TH1D* haa = new TH1D("haa","haa",10,0,1);
#endif

haa->SetDirectory(aa);

testing( a, base->FindObjectAny("a"));
testing( ha, base->FindObjectAny("ha"));
testing( ha, a->FindObjectAny("ha"));
Expand Down
5 changes: 3 additions & 2 deletions roottest/root/io/filemerger/execFileMerger.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
#include "THStack.h"
#include "TTree.h"

void createInputs(int n = 2)
void createInputs(int n = 2)
{
for(UInt_t i = 0; i < (UInt_t)n; ++i ) {
TFile *file = TFile::Open(TString::Format("input%d.root",i),"RECREATE");
TH1F * h = new TH1F("h1","",10,0,100);
h->SetDirectory(file);
h->Fill(10.5); h->Fill(20.5);

Int_t nbins[5];
Double_t xmin[5];
Double_t xmax[5];
Expand Down
Loading