How to add a txt file in a rootuple

Hello,

I’m using Geant4 for producing a simulation and I saving the results in a rootfile.
I would like to keep my Geant4 configuration file (which is a txt file) into the final rootuple.
I don’t know if it exists a way to do it properly.
If not, a friend suggested me to cat the txt file at the end of the root file but I have no idea how to do that and it doesn’t seem to be very clean.
Have you some suggestion ?

Thank you

Hi,

You can use TObjString. For example:

string str; ifstream lunin; lunin.open(fname, ios::in); if (lunin.is_open()) { string line; while (!lunin.eof()) { getline(lunin, line); str += line; str += "\n"; } lunin.close(); } TFile *f = TFile::Open("objstring.root", "recreate", "", 0); TObjString objstr(str.c_str()); objstr.Write("objstr"); delete f;
Cheers, Bertrand.

Hi,

or better yet use a TMacro which you can view / edit as a file in the (new) TBrowser.

Cheers, Axel.

The first method worked perfectly but I’ll test the second one.
Thank you both of you.

I must admit, the TMacro method is powerfull.

TFile* file = new TFile(“file.root”,“recreate”);
TMacro mac(“YourSrcFile.C”);
mac.Write()

And that’s done !