Refering to a file containing huge data

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
Check e.g. chapter 11 on Input/output.

1 Like

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”);

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:



  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
1 Like

thanks for your help. I do appreciate it

I will, thanks for the help