Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ShipSoft/FairShip/llms.txt
Use this file to discover all available pages before exploring further.
ShipGeoConfig provides the geometry configuration layer for FairShip. At its core is AttrDict, a dictionary subclass that supports attribute-style access so that deeply nested detector parameters can be read as ship_geo.strawtubes.width instead of ship_geo['strawtubes']['width']. The Config class extends AttrDict with serialisation to/from both Python pickle (legacy) and JSON (current) formats. The module-level helper load_from_root_file transparently handles both formats when reading a ShipGeo object stored in a ROOT geometry file, making it the primary entry point for analysis scripts.
AttrDict
AttrDict is a dict subclass that maps its own __dict__ to itself, enabling transparent attribute access for all keys.
Constructor
Positional arguments forwarded verbatim to the
dict constructor. Accepts an existing mapping, an iterable of key-value pairs, or nothing.Keyword arguments forwarded to the
dict constructor; each becomes an initial key-value pair accessible as an attribute.Methods
clone() -> AttrDict
Returns a shallow-recursive deep clone of this AttrDict. For every value that is itself an AttrDict, clone() is called recursively; all other values are copied by reference.
A new
AttrDict that is a deep clone of this instance, with nested AttrDict values also cloned.Config
Config extends AttrDict with serialisation helpers for persisting geometry configurations to disk or ROOT files. It supports two wire formats — JSON (current default) and pickle (legacy) — and detects the format automatically on load.
Constructor
Passed through to
AttrDict.__init__.Passed through to
AttrDict.__init__.loads(buff: bytes) -> Config
Deserialise configuration from pickle bytes, replacing the current contents of this Config object in place.
Pickle-serialised bytes, typically obtained from
Config.dumps() or read from a legacy binary file.Returns
self after updating, enabling chained construction such as Config().loads(data).loads_json(json_str: str) -> Config
Deserialise configuration from a JSON string. All nested dict objects in the JSON are recursively converted to AttrDict instances so that attribute access works at every nesting level.
A valid JSON string, typically the output of
Config.dumps_json() or a stored TObjString in a ROOT file.Returns
self after populating, enabling chained construction such as Config().loads_json(json_str).dumps() -> bytes
Serialise this Config to pickle bytes.
Pickle-serialised representation of the configuration.
dumps_json() -> str
Serialise this Config to a JSON string with two-space indentation. Non-serialisable values are converted to strings via default=str.
A pretty-printed JSON string representation of the configuration.
load(filename) -> Config
Load configuration from a file on disk in pickle format. The filename may contain environment variable references (expanded via os.path.expandvars).
Path to a pickle-format configuration file. Environment variables such as
$FAIRSHIP are expanded automatically.Returns
self after loading.dump(filename) -> int
Write this Config to a file on disk in pickle format.
Destination file path. Environment variables in the path are expanded via
os.path.expandvars.Number of bytes written to the file.
clone() -> Config
Returns a recursive deep clone of this Config. Nested AttrDict values are cloned recursively; all other values are copied by reference.
A new
Config that is a deep clone of this instance.__str__() -> str
Returns a human-readable summary of the configuration, listing all non-private keys (those not beginning with _) in sorted order.
load_from_root_file
Config from an open ROOT TFile or a file path string. This is the standard entry point for analysis scripts that need to access detector geometry parameters. The function automatically detects whether the stored object is in the current JSON format (a string beginning with {) or the legacy pickle format, and deserialises accordingly.
Either an already-open
ROOT.TFile object or a string path to a ROOT file. When a string path is given, the file is opened and closed automatically within this call.The key name of the configuration object stored in the ROOT file. Defaults to
"ShipGeo". Raises ValueError if no object with this key exists in the file.A fully populated
Config object with attribute-style access to all geometry parameters.