Choose path for saving histogram

Hi!

I would like to select the folder where I want to save a histogram.
Or to have just “Save As” file chooser.

Would that be possible with TGFileBrowser?
Could you please give me an example?

Thank you!
A

Hi,

[quote=“AryaStark”]I would like to select the folder where I want to save a histogram.
Or to have just “Save As” file chooser.[/quote]You can simply use the “SaveAs” context menu entry (but then you have to give the full path)

Cheers, Bertrand.

Hi,

I’m already using TEveBrowser, and I want the users to specify a folder/path for saving histograms.
Maybe using the TFileBrowser? :question:

I cannot specify the path myself because users (students) usually don’t have permission to write on C disk - and then they cannot save the histogram. :frowning:

Thanks!

Well, I don’t understand what you mean, but anyway, you can customize the context menu (as shown in customContextMenu.C tutorial) and use a TGFileDialog…

Cheers, Bertrand.

Dear Bertrand,

Here is a picture of what I need:

http://oi59.tinypic.com/1zfpg7o.jpg

and I have a code for that helpPopUP.c which works fine!

BUT, when I try the same thing using TEveBrowser (when I call the popup window from the TEveBrowser) it has some problem with shared fmainframe space!

I have tried to do so in the example markTracks.c.

Could you please take a look?

Thank you!
helpPopUp.C (6.19 KB)
markTracks.c (6.61 KB)

Hi,

You forgot to add

at the end of the makeGui() function

Cheers, Bertrand.

Thank you very much! This solved my problem!

BUT now I have another one :slight_smile:

This is my code:

fTextEntry994->SetText("C:/Users/astark/Histogram"); //user's input
---------------
void saveHistogram()
{
     pathSave=fTextEntry994->GetText();
     TFile *saveH2=new TFile(histName1,"RECREATE");
     saveH2->cd(pathSave);
     a->Write(); //a is TH1F
     saveH2->Close();
}

I just want to save my histogram in that place and I get the error:

Could you help me with this too?
Thank you!

Replace: saveH2->cd(pathSave);
By: gSystem->cd(pathSave);
Cheers, Bertrand.

I’ve tried that, and I printed the current path (and that was OK), but in the end, histogram was saved in the previous place! :neutral_face:
Do you maybe have other suggestions?

Try this way (obviously you will have to adapt it to your own code):

void saveHistogram() { TString histName1 = "histogram.root"; TString pathSave = "C:/Users/astark/Histogram"; if (!pathSave.EndsWith("/")) pathSave += "/"; TH1F *h1 = new TH1F("h1", "histo from a gaussian", 100, -3, 3); h1->FillRandom("gaus", 10000); TFile *saveH2 = TFile::Open(pathSave+histName1, "RECREATE"); h1->Write(); saveH2->Close(); delete saveH2; }
Cheers, Bertrand.

There is a TSystem method that allows you to join directory names and file names without needing to check for “/” manually, and it does so for all platforms:

http://root.cern.ch/root/html/TSystem.html#TSystem:PrependPathName

E.g.:

root [0] gSystem->PrependPathName("/var/foo","myfile.root")
(const char* 0x7fc11c920b30)"/var/foo/myfile.root"
root [1] gSystem->PrependPathName("/var/foo/","myfile.root")
(const char* 0x7fc11cacf8a0)"/var/foo/myfile.root"

For some reason there is also “ConcatFileName” which has a better method name (shouldn’t these be just overloaded methods?), but unfortunately returns a pointer to a “new’ed” character array. PrependPathName is less likely to lead to memory leaks, according to my reading of the docs.

Jean-François

Thank you very much for your help! =D>

Btw I’ve discovered that this line of code made the difference, and it’s not necessary to use cd() function.

   TFile *saveH2 = TFile::Open(pathSave+histName1, "RECREATE");

My program works very well on Windows, but on Linux every time when I click OK button I get this error:

[quote]*** Break *** segmentation violation
Error in : BadDrawable (invalid Pixmap or Window parameter) (TGTextEntry XID: 6291592, XREQ: 74)
TGTextEntry: 6291592

*** Break *** segmentation violation
Error in : BadDrawable (invalid Pixmap or Window parameter) (TGTextEntry XID: 6291592, XREQ: 66)
TGTextEntry: 6291592

*** Break *** segmentation violation
Error in : BadDrawable (invalid Pixmap or Window parameter) (TGTextEntry XID: 6291592, XREQ: 66)
TGTextEntry: 6291592

*** Break *** segmentation violation
Error in : BadDrawable (invalid Pixmap or Window parameter) (TGTextEntry XID: 6291592, XREQ: 66)
TGTextEntry: 6291592

*** Break *** segmentation violation
Error in : BadDrawable (invalid Pixmap or Window parameter) (TGTextEntry XID: 6291592, XREQ: 66)

TGTextEntry: 6291592
[/quote]

I have added the following lines of code (just for the pop up window):

fMainFrame1599->Connect("CloseWindow()","className", this, "ButtonOk()"); fMainFrame1599->DontCallClose(); fMainFrame1599->SetCleanup(kDeepCleanup);
and I get a crash on Windows when I click OK.

Could you please help me?