Combination of TFile with libc temporary files

Hi,

For creating a temporary TFile, I’m wondering if I can do something smarter than my so-far standard

TFile* dummy = new TFile("/tmp/dummy.root","recreate");
// create tons of temporary objects
// do work
TFile* of = new TFile(targetfilename.c_str(),"recreate");
of->WriteTObject(thing_i_want_to_store);
of->Close();
delete of;

I’m thining about using something from gnu.org/software/libc/manual … Files.html (such that i can run several instances of the same program). On stackoverflow mkstemp() or tmpfile() are recommended, yet these already open the file and return a filedescriptor, of which i don’t know if i can use it in combination with TFile.

Any recommendations?
Thanks,
Paul

Hi Paul,

You can use TSystem::TempFileName to get a unique name.

However (as mentioned in response to your other post), it is very likely to using a temporary file is not the best solution to your problem as usually there are better alternative.

Cheers,
Philippe.

Hi Philippe,

thanks for your answers! I also use temporary files for other things than just inappropriate buffer volumes. So I will also use the TSystem::TempFileName (just not on what i’m working on today).

Cheers,
Paul