FairShip
Loading...
Searching...
No Matches
saveBasicParameters Namespace Reference

Functions

def retrieveGitTags (o)
 
def execute (f, ox, name="ShipGeo")
 

Function Documentation

◆ execute()

def saveBasicParameters.execute (   f,
  ox,
  name = "ShipGeo" 
)
Save geometry configuration to ROOT file as JSON string

Definition at line 36 of file saveBasicParameters.py.

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()

◆ retrieveGitTags()

def saveBasicParameters.retrieveGitTags (   o)

Definition at line 11 of file saveBasicParameters.py.

11def retrieveGitTags(o):
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