Skip to content

Commit b894456

Browse files
committed
[SPLIT?] Prepare hist and directory for ROOT without implicit ownership.
1 parent 75de80a commit b894456

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

roottest/root/hist/misc/runownership.C

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ void write(const char *filename = "histo.root")
2828
{
2929
TFile * f = TFile::Open(filename,"RECREATE");
3030
TH1F *histo = new TH1F_inst("h1","h1",10,0,10); histo->Fill(3);
31+
histo->SetDirectory(f);
3132
histo = new TH1F_inst("h2","h2",10,0,10); histo->Fill(3);
33+
histo->SetDirectory(f);
3234
TCanvas *c1 = new TCanvas("c1");
3335
histo->SetBit(kCanDelete);
3436
histo->Draw();

roottest/root/io/directory/testFindObjectAny.C

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ void doit()
22
{
33
TFile* base = new TFile("f.db","recreate");
44
TDirectory* a = base->mkdir("a","First Level Dir");
5-
a->cd();
65
TH1D* ha = new TH1D("ha","ha",10,0,1);
6+
a->Append(ha, true);
77
TDirectory* aa = a->mkdir("aa","Second Level Dira");
8-
aa->cd();
98
TH1D* haa = new TH1D("haa","haa",10,0,1);
10-
9+
aa->Append(haa, true);
10+
1111
a->ls();
1212

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

95-
int testFindObjectAny()
96-
{
97-
TDirectory* db = gROOT->mkdir("db","db");
98-
TDirectory* a = db->mkdir("a","a");
99-
TDirectory* aa = a->mkdir("aa","aa");
100-
aa->cd();
101-
TH1D* haa_new = new TH1D("haa","haa",10,0,1);
95+
int testFindObjectAny()
96+
{
97+
TDirectory* db = gROOT->mkdir("db","db");
98+
TDirectory* a = db->mkdir("a","a");
99+
TDirectory* aa = a->mkdir("aa","aa");
100+
TH1D* haa_new = new TH1D("haa","haa",10,0,1);
101+
aa->Append(haa_new, true);
102102
TH1D* haa_find = (TH1D*)db->FindObjectAny("haa");
103103
#ifdef ClingWorkAroundMissingDynamicScope
104104
TH1D* haa = haa_find;
@@ -108,15 +108,15 @@ int testFindObjectAny()
108108
} else if (haa_new != haa_find) {
109109
cout << "haa not found correctly!\n";
110110
}
111-
111+
112112
TFile* base = new TFile("fdb.root","recreate");
113113
#ifdef ClingReinstateRedeclarationAllowed
114114
TDirectory* a = base->mkdir("a","First Level Dir");
115115
#else
116116
a = base->mkdir("a","First Level Dir");
117117
#endif
118-
a->cd();
119118
TH1D* ha = new TH1D("ha","ha",10,0,1);
119+
a->Append(ha, true);
120120
#ifdef ClingReinstateRedeclarationAllowed
121121
TDirectory* aa = a->mkdir("aa","Second Level Dira");
122122
#else
@@ -128,7 +128,8 @@ int testFindObjectAny()
128128
#else
129129
TH1D* haa = new TH1D("haa","haa",10,0,1);
130130
#endif
131-
131+
aa->Append(haa, true);
132+
132133
testing( a, base->FindObjectAny("a"));
133134
testing( ha, base->FindObjectAny("ha"));
134135
testing( ha, a->FindObjectAny("ha"));

0 commit comments

Comments
 (0)