I am trying to use Uproot to read some existing trees. I can open the ROOT file with trees, I can "get" the trees and "show" their branches. I've met branches for which I don't know how to "dump" them and/or get their content.
Some branches contain standard ROOT objects:
Vtx/Vtx.NuFileName | TObjString*[] | AsObjects(AsArray(True, False, AsPointer(Model_TObjString), ()))
SYST/SYST._cov_matrix | TMatrixT<double>[] | AsObjects(AsArray(True, False, Model_TMatrixT_3c_double_3e_, ()))
Some branches are "experiment specific" / "custom" (I don't have ROOT "dictionaries" for them):
POTInfo_v2 | Header | AsObjects(Model_Header)
SEL/SEL._rootStep | StepBase*[] | AsObjects(AsArray(True, False, AsPointer(Model_StepBase), ()))
SEL/SEL._firstSteps | std::vector<StepBase*>[] | AsObjects(AsArray(True, False, AsVector(False, AsPointer(Model_StepBase)), ()))
CATEG/CATEG._types | std::vector<TrackTypeDefinition>[] | AsObjects(AsArray(True, False, AsVector(False, Model_TrackTypeDefinition), ()))
CONF/CONF._toys | std::vector<ToyVariationWrite>[] | AsObjects(AsArray(True, False, AsVector(False, Model_ToyVariationWrite), ()))
Thanks in advance.
The
TTree.showmethod only displays a summary of the TBranches, a tabular view ofTBranch.typename(C++ type name) andTBranch.interpretation(Pythonic interpretation). In both cases, this will show you some levels of depth (e.g.std::vectorcontaining XYZ), but classes are opaque.If you want to know what fields are in a class definition, even if it is a user-defined class, you can get that information from the ROOT file's "streamer info." Here's an example:
This file, uproot-issue283.root, was from a search for supernovas in IceCube, and it has custom data types with names like
SN_Analysis_Configuration_t,I3Eval_t, andSN_File_t. Knowing the C++ type name of the class (not the Python name, which starts with "Model_"), you can look it up with uproot.ReadOnlyFile.streamer_named:The information here includes the class version (
v7), its inheritance (TObject (v1)), its class attributes, their C++ types, and the ROOT streamer than maintains them (e.g.TStreamerBasicType). Note that ROOT can only store attributes, which are usually private in C++, not any methods or functions. When you get an instance of one of these C++ classes, you can access any member with the uproot.Model.member method (see also members, all_members to include superclasses, and has_member):If you're getting the objects from a TTree, rather than directly out of a TDirectory as in the above example, you'll (probably) have to get the data with
library="np"(NumPy arrays of Python objects) instead of the defaultlibrary="ak"(Awkward Arrays).To see all of the streamers, there's an uproot.ReadOnlyFile.show_streamers method:
and you can limit its output to a class and the classes that class depends on by passing the C++ name: