Reading data of custom classes


ROOT Version: 6.28/02
Platform: Windows 11
Compiler: Not Provided

Dear ROOT experts,

I have a rather old ROOT file which uses a custom class to organize data, i.e. I have the 3 files (sorry - I am not allowed to put links here)

  • medusa_run78850.root
  • TMedusa.cxx
  • TMedusa.h

It was written using an older ROOT version and succesfully resisted my attempts to read the content with the newer ROOT version 6.28/02 (Built for win64 on Mar 21 2023, 11:11:48). However, I learned that data of ROOT files are accessible, regardless of the ROOT version. By using

root [0] TFile myFile(“[folder_path]/medusa_run78850.root”)

root [1] myFile.GetListOfKeys()->Print()

ROOT identifies the custom TMedusa objects but I was not able to go any further, although the structure of the TMedusa object is describend in the header file. I wonder what would be the easiest way for a ROOT newbie to read data from the file using the newer ROOT version? Any suggestions (or a reference where to look at) would be highly appreciated!

Hi Gerrit,
Welcome to the ROOT forum.
Do you get an error when executing the two lines you shared?
Lukas

Hi Gerrit,

If you want to let the ROOT prompt know about your custom classes, you can run

.L TMedusa.h

before opening the file. This will load the header into the current interactive session.

You can also (with and without loading the header) open the browser like

TFile f("[folder_path]/medusa_run78850.root")
new TBrowser

and inspect the contents of the file.

I guess you have a ROOT Tree with data in your file? In this case, you can read and analyze the data with RDataFrame, like

.L TMedusa.h
ROOT::RDataFrame df ("[treename]", "[folder_path]/medusa_run78850.root")
df.Display()->Print()

Hope this helps,
Jakob

Hi Lucas, no - so far everything went well and I got a list of 1023 TMedusa objects from the last command. I know from TMedusa.h that there are 2 histograms of dimensions 64 x 256 (with 4 bit values) in this class but I don’t know how to access them, e.g.

root [2] TMedusa* med = (TMedusa*) gDirectory->GetObjectChecked(“medusa.2”, “TMedusa”);
Error in TInterpreter::TCling::AutoLoad: failure loading library TMedusa_cxx for TMedusa
Error in TInterpreter::TCling::AutoLoad: failure loading library TMedusa_cxx for TMedusa
ROOT_prompt_5:1:25: error: expected expression
TMedusa* med = (TMedusa*) gDirectory->GetObjectChecked(“medusa.2”, “TMedusa”);
_______________________^

Hi Jakob,

I failed to load the header file and got

root [0] .L [folder_path]/TMedusa.h
Error in TInterpreter::TCling::AutoLoad failure loading library TMedusa_cxx for TMedusa
Error in TInterpreter::TCling::AutoLoad failure loading library TMedusa_cxx for TMedusa
Error in TInterpreter::TCling::AutoLoad failure loading library TMedusa_cxx for TMedusa
Error in TInterpreter::TCling::AutoLoad failure loading library TMedusa_cxx for TMedusa
Error in TInterpreter::TCling::AutoLoad failure loading library TMedusa_cxx for TMedusa

Also the TBrowser only lists the TMedusa objects but doesn’t allow me to look into it.

I don’t think that there is a TTree involved.

Maybe it could help: I was able to implement TMedusa.cxx in an older (32-bit) ROOT version with

OS: Ubuntu 14.04.6 LTS Trusty Tahr, 32-bit PC (i386) desktop image
ROOT: root-system-bin Version 5.34.14-1build1

Here, I could implement the class by running a provided makefile and loading the TMedusa class in ROOT by

[0] gSystem->Load(“libTMedusa”)

Then I was able to read the data (e.g. using the TBrowser) and use the methods provided by the TMedusa class. However, I believe I learned from the ROOT documentation that the data should still be accessible in newer versions of ROOT (albeit without the full functionality of the TMedusa class). I would really like to know how it works.

Would it be possible to share the ROOT file with us privately? Or, if that is not possible, to share the header file?