Bug #1340
Allow creation of subdirectories with TFileService
100%
Description
When writing to a histogram file, art puts the histograms in a directory named for the producing module. It would be nice to have finer grained control, ie to be able to create subdirectories within this structure.
I have a large number of output histograms, enough to make TBrowser unhappy. It would be good to be able to separate them logically.
Whilst you can get at the underlying output file from the TFileService and create directories, it always cd's back before writing histograms.
I'm not sure what the best interface for this would be, maybe parsing the names of objects created in the TFileService for slashes and interpreting them as directory separators, creating all necessary containing directories?
Related issues
History
#1 Updated by Marc Paterno over 9 years ago
- Category set to Infrastructure
- Status changed from New to Feedback
We request an official statement from NOvA regarding the importance and the desired behavior.
#2 Updated by Andrew Norman over 9 years ago
The following example code was provided that produces the behavior:
//...................................................................... void DemoModule::beginJob() { art::ServiceHandle<art::TFileService> tfs; fHisto = tfs->make<TH1F>("fHisto", "title;xlabel;ylabel", 100,0.,100.); tfs->file().mkdir("foo"); tfs->file().cd("foo"); tfs->make<TH1F>("fHistofoo", "title;xlabel;ylabel", 100,0.,100.); tfs->file().mkdir("bar"); } I would expect to get a fHisto and the foo directory inside of the overall "demo" directory, with fHistofoo and the bar directory nested inside that. Instead, I seem to have "demo", "foo" and "bar" directories at toplevel, and both histograms inside "demo". I suspect I've misunderstood something here... (There also seems to be a mkdir, but no cd, on tfs itself, without using file(), but that didn't seem to do anything at all).
We would request that this be examined for consistency with the expected behavior.
#3 Updated by Christopher Green over 9 years ago
- Status changed from Feedback to Accepted
#4 Updated by Walter E Brown about 9 years ago
To be verified with Mu2e.
#5 Updated by Rob Kutschke about 9 years ago
The following fragment works for Mu2e:
art::ServiceHandle<art::TFileService> tfs; art::TFileDirectory tfdir = tfs->mkdir( "ConversionGun" ); _hMultiplicity = tfdir.make<TH1F>( "hMultiplicity", "Conversion Multiplicity", 10, 0., 10. ); _hcz = tfdir.make<TH1F>( "hcz", "Conversion Electron cos(theta) at Production;(MeV)", 100, -1., 1. );
where the _h* variables are member data of type TH1F*.
This was taken from:
#6 Updated by Christopher Green about 9 years ago
- Tracker changed from Feature to Support
- Assignee set to Christopher Green
- % Done changed from 0 to 90
Chris, Andrew,
First, please accept my apologies that this issue became moribund.
Second: please review Rob's recent comment to see if this prescription works for you and let us know whether it solves your problem (or in fact, you resolved this on your own).
Thanks,
Chris.
#7 Updated by Christopher Backhouse about 9 years ago
I just checked. That mu2e code sample also works in my package. Thanks!
#8 Updated by Christopher Green about 9 years ago
- Tracker changed from Support to Bug
- Category changed from Infrastructure to User Code
- % Done changed from 90 to 100
#9 Updated by Christopher Green about 9 years ago
- Tracker changed from Bug to Support
#10 Updated by Christopher Green about 9 years ago
- Tracker changed from Support to Bug
#11 Updated by Christopher Green about 9 years ago
- Status changed from Accepted to Resolved
#12 Updated by Christopher Green about 9 years ago
- Status changed from Resolved to Closed