Print("all");> file script not working

Hello dear Rooters!

Sorry if i fell in to the wrong place…
I am in a very tight spot concerning this problem. It has annoyed me hellofalot. So here it goes:
I have to export histograms from ROOT files to ASCII. Currently i am using this.

[code]TFile f = TFile(“xxx.root”);

// file xxx.root is in the same local directory
// where i opened ANY root file

TH1D* histY = (TH1D*)f.Get(“Z”);
histY->Print(“all”); > ZZZZ.dat[/code]

As long as i throw this code row by row, while ANY root file is open, in to the “Command (local):” box everything works fine. But earlier, i had to export only few of histograms from one file, so it was allright. Now it gets to around 10-20, and it gets very annoying and time consuming.

I decided to script it in a xyz.C file. So the main problem is that, when i run it, which should extract those graphs in theory, the intepreter just throws up at the third line. Sometimes i get ZZZZ.dat is out of scope, or something like that the ; is missing somewhere.

For example, this is the script code:

{ TFile f = TFile("D:/Geant4_10.0.0/share/Geant4-10.0.0/examples/extended/electromagnetic/TestEm18antras-build3/Release/pixeErdvinisKampas.root"); TH1D* hist5 = (TH1D*)f.Get("5"); hist5->Print("all"); > histfilename.dat }

And this is what i get in the interpreter:

fSumw[1000]=0, x=19.99, error=0
fSumw[1001]=0, x=20.01, error=0
Syntax Error: > histfilename.dat Maybe missing ‘;’ D:\root\macros\dataout2.c(5)
*** Interpreter error recovered ***

The script file is in the macros directory.

I just cannot understand, why it works if you feed it line by line, but otherwise not…
Can anyone help?

Hi,
You should do as following (in a macro):

TH1D* histY = (TH1D*)f.Get("Z");
gROOT->ProcessLine(".> ZZZZ.dat");
histY->Print("all");

and when using in the prompt you can remove the gROOT->ProcessLine and just type “.> ZZZZ.dat”

Best Regards

Lorenzo

Thank You for reply!

Either way you provided, just the empty file is getting created at best. No data gets into it. Although, i get to see the data on the screen. I tried both ways.

For example:

{ TFile f = TFile("D:/Geant4_10.0.0/share/Geant4-10.0.0/examples/extended/electromagnetic/TestEm18antras-build3/Release/pixeErdvEksp.root"); gROOT->ProcessLine(".> pixeErdvEksp_Pabege.dat"); TH1D* hist5 = (TH1D*)f.Get("5"); hist5->Print("all"); }
yields

[quote]fSumw[1000]=0, x=19.99, error=0
fSumw[1001]=0, x=20.01, error=0
root [2] .x dataout2.c
Error: Symbol f is not defined in current scope C:\root\macros\dataout2.c(4)
Error: Failed to evaluate f.Get(“5”)
*** Interpreter error recovered ***[/quote]

Tried updating ROOT to 5.34/18. No effect whatsoever.

Antanas.

Solved myself. Thanks for the gROOT->ProcessLine("")! :slight_smile:

{ gROOT->Reset(); TFile f = TFile("D:/Geant4_10.0.0/share/Geant4-10.0.0/examples/extended/electromagnetic/TestEm18antras-build3/Release/pixeErdvEksp.root"); TH1D* hist5 = (TH1D*)f.Get("5"); gROOT->ProcessLine("hist5->Print(\"all\"); >durns5.dat"); }

Regards,
Antanas.

I started working on Ubuntu. Got everything running well, but the same script I used for exporting histogram data in Windows, just does not work here, in Ubuntu, sadly… Got back here for help…

[code]void DataOutput()
{
gROOT->Reset();
TFile f = TFile("~/Universitetas/geant4.10.02-install/share/Geant4-10.2.0/examples/extended/radioactivedecay/rdecaymod-build/Co60_h22.root");
TH1D* hist2 = (TH1D*)f.Get(“11;1”);
gROOT->ProcessLine(“hist2->Print(“all”);>/home/antanas/Universitetas/geant4.10.02-install/share/Geant4-10.2.0/examples/extended/radioactivedecay/rdecaymod-build/Co60_h0_export.txe”);

//hist2->Print(“all”);

f.Close();
}[/code]

If i use the commented hist2->Print(“all”);, i get the right output to the screen, but yielding the ProcessLine command I get the

[quote]Error: Symbol hist2 is not defined in current scope (tmpfile):1:
Error: Failed to evaluate hist2->Print(‘all’)
*** Interpreter error recovered ***[/quote]

I am greatly perplexed.

Root version 5.34/14.

Thanks in advance for quick answers!

Somehow magically worked.
Probably because before i tried
.L dataout.C then
DataOutput() yields in error.

.X dataout.C yields successful outcome.