# Can't create output root file

**URL:** <https://root-forum.cern.ch/t/cant-create-output-root-file/46502>\
**Category:** Newbie\
**Created:** [August 27, 2021, 7:31pm UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502 "2021-08-27T19:31:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aya\_Beshr](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/aya_beshr/32/27192_2.png) [@Aya\_Beshr](https://root-forum.cern.ch/u/Aya_Beshr)\
**Post date:** [August 27, 2021, 7:31pm UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/1 "2021-08-27T19:31:29Z")

</div>

Hi,

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 

```

or,  
.L test.C  
test();

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,  
Aya  
[test.C](https://root-forum.cern.ch/uploads/short-url/5vflEuGzJew3wAZDQ63QGCyt5Nw.C) (16.7 KB)

```auto

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 27, 2021, 8:05pm UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/2 "2021-08-27T20:05:21Z")

</div>

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

```nohighlight
.! pwd
.! ls -al

```

---

<div class="post-metadata">

**Author:** ![Aya\_Beshr](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/aya_beshr/32/27192_2.png) [@Aya\_Beshr](https://root-forum.cern.ch/u/Aya_Beshr)\
**Post date:** [August 28, 2021, 12:19am UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/3 "2021-08-28T00:19:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [August 28, 2021, 7:38am UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/4 "2021-08-28T07:38:32Z")

</div>

The file you uploaded doesn’t run:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 28, 2021, 7:44am UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/5 "2021-08-28T07:44:33Z")

</div>

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

```c++
.L test.C
test t;
t.Loop();

```

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [August 28, 2021, 8:00am UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/6 "2021-08-28T08:00:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aya\_Beshr](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/aya_beshr/32/27192_2.png) [@Aya\_Beshr](https://root-forum.cern.ch/u/Aya_Beshr)\
**Post date:** [August 28, 2021, 1:02pm UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/7 "2021-08-28T13:02:50Z")

</div>

@dastudillo ,so sorry for that mistake, the file is created with MakeClass, it needs a header I have just uploaded  
[test.h](https://root-forum.cern.ch/uploads/short-url/hby042Jx9LGMEMuoVcX61ePnxwn.h) (69.8 KB)

---

<div class="post-metadata">

**Author:** ![Aya\_Beshr](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/aya_beshr/32/27192_2.png) [@Aya\_Beshr](https://root-forum.cern.ch/u/Aya_Beshr)\
**Post date:** [August 28, 2021, 1:08pm UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/8 "2021-08-28T13:08:48Z")

</div>

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

Thanks,  
Aya

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [August 30, 2021, 7:49am UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/9 "2021-08-30T07:49:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aya\_Beshr](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/aya_beshr/32/27192_2.png) [@Aya\_Beshr](https://root-forum.cern.ch/u/Aya_Beshr)\
**Post date:** [August 30, 2021, 2:40pm UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/10 "2021-08-30T14:40:31Z")

</div>

Hi @eguiraud

Yah sure thanks!

---

<div class="post-metadata">

**Author:** ![Jacquelyn](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@Jacquelyn](https://root-forum.cern.ch/u/Jacquelyn)\
**Post date:** [September 2, 2021, 12:30pm UTC](https://root-forum.cern.ch/t/cant-create-output-root-file/46502/11 "2021-09-02T12:30:54Z")

</div>

Thanks for this information.
