Redirecting output, root 6

Dear experts,
I recently installed v6-02-02, and I am no longer able to interactively redirect output (e.g., from cout lines in my macros) to log files. Using ofstream inside the macros is not desirable, since I’m talking about quick checks, and the idea is to be able to quickly select whether to see the output onscreen or save it to a log file.
If I execute this macro:
void hello() {
cout << “Hello!” << endl;
return;
}
like this:
root [] .x hello.C() > aa.log
I can see the output in the root window (as if the redirection were not there) but not even an empty aa.log file is created. I’m using ubuntu 14.04, and compiled root with the python option, if it matters.
Any ideas?
Thanks,
Daniel

Hi,

We have changed the syntax for prompt redirections - the old one was really nasty / ambiguous to parse, e.g.:

.x foo.C(1>var) // var should always be > 0
.x foo.C(1>var) // var should always exist > log.out

So now it’s much more explicit:

.> aa.log
.x hello.C()
.>

Cheers, Axel.

Hi Axel,
Thanks for the reply. However, I’m afraid your suggestion doesn’t work either, a log file is created but it’s empty, and the output still goes to the root window.
I also wonder if your first example is valid, i.e., including a “>” in the arguments… has ROOT ever allowed that?

  • Daniel

Any updates, or suggestions from other experts?

Hi,

Sorry - you are right, that’s a change in behavior in ROOT 6. I have opened a ticket sft.its.cern.ch/jira/browse/ROOT-7053

As a workaround, gSystem->RedirectOutput() might help.

Cheers, Axel.

Hi Axel,
Thanks for the help, I’ll use that in the meantime.
Cheers,
Daniel

Hi again,
I changed the status back to unsolved, because I found another issue, again with output redirection.
Consider this macro:

void hi() { TFile *f = new TFile("hsimple.root"); TH2F *h = (TH2F*)f->Get("hpxpy"); h->Draw(); cout << "Hello!" << endl; return; }
Using ROOT 6-04-00, I see this:

root [0] .x hi.C Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1 Hello!
which is as expected. But if I try to redirect the output, this happens:

root [0] .> aa.log root [1] .x hi.C Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1 Hello!
The file aa.log is created but it’s empty, and the output is still printed inside root.
Disabling the first 3 lines in the code above (opening the file, getting and drawing h2), the redirection works ok.
Disabling only the 2 lines of the histogram, the problem remains, so it seems related specifically to the TFile line.
Regards,
Daniel

Hello experts,

I think its not yet fixed at least for all cases. I am trying to redirect the output of Scan command in a log file. For that I am doing following:

But I am getting an empty geo1X.log file.

Please let me know if I am doing something wrong.

with regards,
Ram

Hi,

This works fine with me on master branch

.x $ROOTSYS/tutorials/hsimple.C
TFile f("hsimple.root")
.> a.log
ntuple->Scan("px:py:pz")
.>

Maybe you are using an old ROOT version before sft.its.cern.ch/jira/browse/ROOT-7053 was fixed. Which version are you using ?

Lorenzo

Hi Lorenzo,

I tried again but it did not worked. I even tried with hsimple.C and followed the same step as you did but again I got an empty file.

I am using root 6.04.00. As per the link you gave, I think this version is fixed. But I don’t know why its not working.

with regards,
Ram

Hi Lorenzo,
I am using “v6-04-00, 2 June 2015”, so the solution from that bug should have been included in this version, but my example code (above) does not work. I gave yours a try (without running the hsimple.C macro, since I already have the hsimple.root file) and it does not work for me, the output goes to the root prompt and the log file is created but remains empty.

  • Daniel

HI,

Yes it is true that it does not work the first time. If you repeat the TTree::Scan command it will work.
So, what I posted before did not work, but this works for me (in both master and 6.04)

TFile f("hsimple.root");
ntuple->Scan("px:py:pz");
.> a.log
ntuple->Scan("px:py:pz");
.>

We will investigate why it does not work the first time. This seems to be a problem with TTree::Scan. In other cases it works fine

Lorenzo

Yes, when I run twice Scan command then it worked.

Thanks. Lorenzo.

Dear Lorenzo,

I am not able to understand the reason what you told. But I followed exactly the same steps that you mentioned.

TFile f("hsimple.root");
auto ntuple = (TTree*) f.Get("ntuple");
.> a.log
ntuple->Scan("px:py:pz");
.>

But it did not worked for me. But, your previous suggestion is working. I mean when I run

twice then its working.

with regards,
Ram

You are right. I will delete these last two posts

Lorenzo

Hi Lorenzo,
Are you involved in programming root? I only ask because I think your suggestion is only a workaround; useful indeed, but not optimal. I don’t see why one should need to run Scan, for instance, twice in order to be able to export the output. It works for Ram’s case but for me this is not desirable because my actual macro is quite more complex than the simple example I posted. In view of my example, it seems to me that opening root files is creating a strange redirection behaviour, unless there’s something else I don’t understand.

  • Daniel

Hello Daniel,

Don’t worry we plan to fix this issue. It is certainly not acceptable to run a command two times to make this to work. I have re-opened the bug sft.its.cern.ch/jira/browse/ROOT-7053 to track this problem.

Best Regards

Lorenzo

Hi,

This is now fixed in the master, v6-04 and v6-02. Thanks for reporting!

Axel.

Thanks Axel for information.

But I would like to ask that I installed root 6.04 using the git. And as you said that it is fixed now so can I update my root directory using git pull and then configuring that directory again?

with regards,
Ram

Hi Ram,

That’s correct.

Cheers, Axel