Skip to content

Conversation

@hageboeck
Copy link
Member

  • Go from implicit to explicit writing in makeExample.C tutorial
  • Also explicitly write histograms in testHistFactoryPlotting.cxx

By making the writes explicit, the tests become independent of gDirectory and whether or not histograms register themselves.

TFile* file = new TFile("dataDriven.root", "RECREATE");

TH1F* FlatHist = new TH1F("FlatHist","FlatHist", 2,0,2);
FlatHist->SetDirectory(file);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it yet 🙂 If you later explicitly write the histograms with file->WriteTObject(histo), why do you need to do SetDirectory(file) before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You indeed don't need it to write, but you do need it to destroy the histogram. Alternatively, you can of course take the ownership "manually".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me do a solution that doesn't need SetDirectory

If implicit object ownership gets in TDirectories gets switched off, the
example histograms need to be added to directories or written
explicitly.
git clang-format applied enough changes to make it worth formatting the
entire file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants