# Refering to a file containing huge data

**URL:** <https://root-forum.cern.ch/t/refering-to-a-file-containing-huge-data/39236>\
**Category:** General Chat\
**Created:** [May 3, 2020, 6:02pm UTC](https://root-forum.cern.ch/t/refering-to-a-file-containing-huge-data/39236 "2020-05-03T18:02:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jabr76](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@jabr76](https://root-forum.cern.ch/u/jabr76)\
**Post date:** [May 3, 2020, 6:02pm UTC](https://root-forum.cern.ch/t/refering-to-a-file-containing-huge-data/39236/1 "2020-05-03T18:02:06Z")

</div>

hello everyone  
i have a root file containing lots of data, but don’t know how to include it in my .C code.  
i need to refer to that file so that the code opens it.  
would you plz help  
thanks in advance

---

<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:** [May 4, 2020, 5:50am UTC](https://root-forum.cern.ch/t/refering-to-a-file-containing-huge-data/39236/2 "2020-05-04T05:50:16Z")

</div>

[https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html](https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html)  
Check e.g. chapter 11 on Input/output.

---

<div class="post-metadata">

**Author:** ![jabr76](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@jabr76](https://root-forum.cern.ch/u/jabr76)\
**Post date:** [May 12, 2020, 10:38pm UTC](https://root-forum.cern.ch/t/refering-to-a-file-containing-huge-data/39236/3 "2020-05-12T22:38:27Z")

</div>

thanks for your help. I managed to get to some of the files and it worked smoothly, but since the main folder have another folder which have about 50 sub folders each of which has two files, i tried a for-loop but it didn’t work because of different file names in different sub-folders. So, would you plz help if you know how to overcome this for-loop problem.

here is part of the code which i have to repeat 50 times for each main folder.

TFile f (“DEADPIXELS.root”);  
TDirectory _d1=(TDirectory_)f. Get(“badPixelAndy;1”);  
TDirectory _d2=(TDirectory_)d1-\> Get(“A16-2;1”); TH1D _h2 = (TH1D_)d2-\>Get(“A16-2\_analog\_bad;1”);  
TDirectory _d3=(TDirectory_)d1-\> Get(“A16-1;1”); TH1D _h3 = (TH1D_)d3-\>Get(“A16-1\_analog\_bad;1”);  
TDirectory _d4=(TDirectory_)d1-\> Get(“A15-2;1”); TH1D _h4 = (TH1D_)d4-\>Get(“A15-2\_analog\_bad;1”);  
TDirectory _d5=(TDirectory_)d1-\> Get(“A15-1;1”); TH1D _h5 = (TH1D_)d5-\>Get(“A15-1\_analog\_bad;1”);  
TDirectory _d6=(TDirectory_)d1-\> Get(“A14-2;1”); TH1D _h6 = (TH1D_)d6-\>Get(“A14-2\_analog\_bad;1”);  
TDirectory _d7=(TDirectory_)d1-\> Get(“A14-1;1”); TH1D _h7 = (TH1D_)d7-\>Get(“A14-1\_analog\_bad;1”);

---

<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:** [May 13, 2020, 8:59am UTC](https://root-forum.cern.ch/t/refering-to-a-file-containing-huge-data/39236/4 "2020-05-13T08:59:09Z")

</div>

If the names are too variable to be expressed with a formula/s that depends on the loop variable/s, then you will probably have to write them by hand. Or maybe you can save a list of the paths/names to a text file and read the names from this file in a loop. You can get an on-the-fly listing of the file contents (but if you will not use all the items in the list, you will need to implement a way to skip the ones you don’t want); read for example here, or search for similar threads:

> [@Loop over all objects in a ROOT file](https://root-forum.cern.ch/t/loop-over-all-objects-in-a-root-file/10807):
>
> After having looked for a hint in the forum, I found this thread [http://root.cern.ch/phpBB3//viewtopic.php?f=3&t=7246&p=30333](http://root.cern.ch/phpBB3//viewtopic.php?f=3&t=7246&p=30333) Here I post my version of the small pyroot function, where you can specify a folder path inside the ROOT file. def GetKeyNames( self, dir = "" ): self.cd(dir) return [key.GetName() for key in gDirectory.GetListOfKeys()] TFile.GetKeyNames = GetKeyNames keyList = f.GetKeyNames(internalPath) print "\nKeys in file:", keyList I post it here, with an explic…

---

<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:** [May 13, 2020, 9:06am UTC](https://root-forum.cern.ch/t/refering-to-a-file-containing-huge-data/39236/5 "2020-05-13T09:06:26Z")

</div>

Try:

```cpp
{
  TFile f("DEADPIXELS.root");
  for (Int_t a = 14; a <= 16; a++) {
    for (Int_t i = 1; i <= 2; i++) {
      TH1 *h;
      f.GetObject(TString::Format("badPixelAndy/A%d-%d/A%d-%d_analog_bad", a, i, a, i), h);
      if (h) h->Print();
      // delete h; // no longer needed
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![jabr76](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@jabr76](https://root-forum.cern.ch/u/jabr76)\
**Post date:** [May 13, 2020, 11:17pm UTC](https://root-forum.cern.ch/t/refering-to-a-file-containing-huge-data/39236/6 "2020-05-13T23:17:20Z")

</div>

thanks for your help. I do appreciate it

---

<div class="post-metadata">

**Author:** ![jabr76](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@jabr76](https://root-forum.cern.ch/u/jabr76)\
**Post date:** [May 13, 2020, 11:18pm UTC](https://root-forum.cern.ch/t/refering-to-a-file-containing-huge-data/39236/7 "2020-05-13T23:18:08Z")

</div>

I will, thanks for the help
