#includevoid listFileContents() { TFile file("myFile.root"); file.ls(); }
#includeThis example demonstrates how to list the objects in a ROOT file by retrieving the list of keys in the file using GetListOfKeys(), and then iterating over those keys to retrieve the object using Get(). The object's type and name are then printed out. The package library for this code is ROOT, a C++ data analysis framework used in high-energy physics.#include void listObjects() { TFile file("myFile.root"); TList* objects = file.GetListOfKeys(); for (auto* key : *objects) { TObject* obj = file.Get(key->GetName()); std::cout << "Object Type: " << obj->ClassName() << ", Name: " << obj->GetName() << std::endl; } }