FairShip
Loading...
Searching...
No Matches
saveBasicParameters.py
Go to the documentation of this file.
1# SPDX-License-Identifier: LGPL-3.0-or-later
2# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
3
4import os
5import subprocess
6
7import ROOT
8from ShipGeoConfig import AttrDict
9
10
12 # record some basic information about version of software:
13 if "FAIRSHIP_HASH" in os.environ:
14 o.FairShip = os.environ["FAIRSHIP_HASH"]
15 o.FairRoot = os.environ["FAIRROOT_HASH"]
16 else:
17 tmp = os.environ["FAIRSHIP"] + "/.git/refs/remotes/origin/master"
18 if os.path.isfile(tmp):
19 x = subprocess.check_output(["more", tmp]).replace("\n", "")
20 o.FairShip = AttrDict(origin=x)
21 tmp = os.environ["FAIRSHIP"] + "/.git/refs/heads/master"
22 if os.path.isfile(tmp):
23 x = subprocess.check_output(["more", tmp]).replace("\n", "")
24 o.FairShip = AttrDict(local=x)
25 tmp = os.environ["FAIRROOTPATH"] + "/../FairRoot/.git/refs/heads/dev"
26 if os.path.isfile(tmp):
27 x = subprocess.check_output(["more", tmp]).replace("\n", "")
28 o.FairRoot = AttrDict(dev=x)
29 tmp = os.environ["FAIRROOTPATH"] + "/../FairRoot/.git/refs/heads/master"
30 if os.path.isfile(tmp):
31 x = subprocess.check_output(["more", tmp]).replace("\n", "")
32 o.FairRoot = AttrDict(master=x)
33 return o
34
35
36def execute(f, ox, name="ShipGeo"):
37 """Save geometry configuration to ROOT file as JSON string"""
38 if isinstance(ox, str):
39 ox = AttrDict()
40 o = retrieveGitTags(ox)
41
42 if isinstance(f, str):
43 fg = ROOT.TFile.Open(f, "update")
44 else:
45 fg = f
46
47 # Serialize to JSON
48 json_str = o.dumps_json()
49
50 # Save as std::string in ROOT file
51 fg.cd()
52 config_str = ROOT.std.string(json_str)
53 fg.WriteObject(config_str, name)
54 fg.Flush()
55
56 if isinstance(f, str):
57 fg.Close()
def execute(f, ox, name="ShipGeo")