Can't create output root file


I have made a simple macro. I am trying to save the histograms to output root file, but the issue the root file is not being created either by using the method TFile *f = new TFile("output.root", "option"); where option = recreate or create or new it fails using all these options. I also used TFile f("output.root", "recreate"); but nothing works.

run macro with:

 .x test.C 

.L test.C

in root prompt.

More info:

Platform: Ubuntu-18.04
ROOT_version: root-6.18.04

I have uploaded the macro, may be I miss something, but couldn’t catch.

Thanks in advance,
test.C (16.7 KB)

Make sure that you are allowed to create a file in the current working directory:

.! pwd
.! ls -al

Thanks for reply! I checked it. I have the right to create such files.

When I run the method TFile f("output.root", "recreate"); in root prompt, the file is created, isn’t this weird?

The file you uploaded doesn’t run:

root [0] .x test.C
Error: Function test() is not defined in current scope  (0)

It would be better if you provide something that runs. Anyhow, given that this macro is perhaps called by other code (and we don’t know what this other code is doing) some possibilities could be:

  • The output file is being created in some other folder (=> try explicitly giving the full path when creating the TFile).
  • The code never actually reaches test::Loop (print out a “hello” message as soon as you enter Loop).
  • fChain is not defined and this macro just returns (line 55; add a printout message before doing return).
  • The code crashes somewhere.

@Aya_Beshr It seems to me that you are not following instructions given in the “test.C” file:

.L test.C
test t;

I followed the instructions in the post above. Anyway, the code still doesn’t run with these instructions and only the provided file, at least for me, and I guess my suggestions are still worth checking.

@dastudillo ,so sorry for that mistake, the file is created with MakeClass, it needs a header I have just uploaded
test.h (69.8 KB)

@Wile_E_Coyote You are totally right. sorry for that silly mistake. I have done this and the loop still running.


Hi @Aya_Beshr ,
can we mark this as solved then? :slight_smile:

Hi @eguiraud

Yah sure thanks!

Thanks for this information.