# Reading more than one root files

**URL:** <https://root-forum.cern.ch/t/reading-more-than-one-root-files/35850>\
**Category:** Newbie\
**Created:** [September 2, 2019, 3:00pm UTC](https://root-forum.cern.ch/t/reading-more-than-one-root-files/35850 "2019-09-02T15:00:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![NewR](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/7bcc69/32.png) [@NewR](https://root-forum.cern.ch/u/NewR)\
**Post date:** [September 2, 2019, 3:00pm UTC](https://root-forum.cern.ch/t/reading-more-than-one-root-files/35850/1 "2019-09-02T15:00:34Z")

</div>

Hi,

I am trying to open recursively root files; I try this code:

```auto
  TFile *file[5];
  TTree *T1[5];

  f[1]->Open("/home/daqmgr/neutroni/DataAnalysis/dst/run328.root");

  T1[0]=(TTree*) f[1]->Get("T");

```

but I obtain an error.  
The point, to be clear, is that I need to initialize a TFile array to get the TTree contained in the files in a TTree array.

Thanks, NewR

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 2, 2019, 3:27pm UTC](https://root-forum.cern.ch/t/reading-more-than-one-root-files/35850/2 "2019-09-02T15:27:39Z")

</div>

> [@NewR](#):
>
> but I obtain an error.

Can tell us which error you get ?

---

<div class="post-metadata">

**Author:** ![NewR](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/7bcc69/32.png) [@NewR](https://root-forum.cern.ch/u/NewR)\
**Post date:** [September 2, 2019, 4:05pm UTC](https://root-forum.cern.ch/t/reading-more-than-one-root-files/35850/3 "2019-09-02T16:05:16Z")

</div>

Thx,

I obtain:

f[1]-\>Open("/home/daqmgr/neutroni/DataAnalysis/dst/run328.root");  
input\_line\_29:2:3: error: use of undeclared identifier ‘f’  
(f[1]-\>Open("/home/daqmgr/neutroni/DataAnalysis/dst/run328.root"))  
^  
Error in : Error evaluating expression (f[1]-\>Open("/home/daqmgr/neutroni/DataAnalysis/dst/run328.root")).  
Execution of your code was aborted.

but using f[1].Open I get the same error!

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [September 2, 2019, 7:01pm UTC](https://root-forum.cern.ch/t/reading-more-than-one-root-files/35850/4 "2019-09-02T19:01:50Z")

</div>

Hi,

You should do something like:

```auto
f[1] = TFile::Open("/home/daqmgr/neutroni/DataAnalysis/dst/run328.root");

```

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![NewR](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/7bcc69/32.png) [@NewR](https://root-forum.cern.ch/u/NewR)\
**Post date:** [September 3, 2019, 1:29pm UTC](https://root-forum.cern.ch/t/reading-more-than-one-root-files/35850/5 "2019-09-03T13:29:22Z")

</div>

It doesn’t work. I fixed by opening and closing the same temporary root file recursively as:

TFile \*f;  
Char\_t filenm[80];

for (Int\_t i=0; i\<5; i++) {  
nrun = 330 + i;  
sprintf(filenm,"…/dst/run%3i.root",nrun);  
f = new TFile(filenm);  
T1[i]=(TTree\*) f-\>Get(“T”);  
f-\>Close();

delete f;  
}

Many thanks, NewR

---

<div class="post-metadata">

**Author:** ![b\_h](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/b_h/32/19653_2.png) [@b\_h](https://root-forum.cern.ch/u/b_h)\
**Post date:** [September 4, 2019, 7:00pm UTC](https://root-forum.cern.ch/t/reading-more-than-one-root-files/35850/6 "2019-09-04T19:00:09Z")

</div>

Is your error due to the act that you called your array TFile \*file[5] and not f[] as in your following code?

---

<div class="post-metadata">

**Author:** ![NewR](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/7bcc69/32.png) [@NewR](https://root-forum.cern.ch/u/NewR)\
**Post date:** [September 5, 2019, 8:59am UTC](https://root-forum.cern.ch/t/reading-more-than-one-root-files/35850/7 "2019-09-05T08:59:12Z")

</div>

Yes, you are right!!! Very stupid error!!

Thank you very much!
