Home | News | Documentation | Download

List determinated KEY (Histogram) inside a root file

Hi,
I have a file.root with a lot histograms inside and i want to list only the TH2F histograms from a remote host on console.

I tried with:

TFile f(file.root)
.L Macro.C
Macro(&f)

there is no subdirectories in the root file, i wonder if there is some other feature of ls command like f->ls("TH2F")

Regards

$f ? what does that mean ?

I ran:

void buscaHIST (TDirectory *dir) {

TIter nextkey (dir->GetListOfKeys());

TKey *key;

while ((key = (TKey*)nextkey())) { 
 
if (strstr(key->GetClassName(),"TH2F")) {
printf (" %s :: %s :: %s\n",key->GetName(),key->GetClassName(),dir->GetPath());
}

if (!strcmp(key->GetClassName(),"TDirectoryFile")) {
 
dir->cd(key->GetName());
TDirectory *subdir = gDirectory;
buscaHIST(subdir);
dir->cd();
}
}
}

This is the error:

root [0] TFile *f = TFile::Open("input.root")
(TFile *) 0x26e6960
root [1] .L buscaHIST.C
root [2] buscaHIST(&f)
ROOT_prompt_2:1:1: error: no matching function for call to 'buscaHIST'
buscaHIST(&f)
^~~~~~~~~
directoriemine/run/buscaHIST.C:1:6: note: candidate function not viable: no known conversion from 'TFile **' to 'TDirectory *' for 1st argument; remove &
void buscaHIST (TDirectory *dir) {
     ^

(there is not subdirectories on the root file)

As f is already a point and your function takes a pointer as input,
can you try:

root [2] buscaHIST(f)