ATLAS Offline Software
readDatabase.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 
4 # Author: Abhishek Nag (TU Dresden)
5 # email: abhishek.nag@cern.ch
6 import os
7 import sys
8 import yaml
9 import argparse
10 
11 SystToolsPath = "/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/dev/PMGTools/SystematicsDatabase/"
12 if os.path.exists(SystToolsPath + "DSID_Database.yaml"):
13  pass
14 elif 'SYSTTOOLSPATH' in os.environ.keys():
15  print("[WARNING] Could not find syst tools path on cvfms, defaulting to one in %s/data/" % os.environ['SYSTTOOLSPATH'])
16  SystToolsPath = '/data/' + os.environ['SYSTTOOLSPATH']
17 else:
18  print("[ERROR] Environment variable SYSTTOOLSPATH is not set. It should be set to the systematics-tools directory. Use setupSystematicsTool.sh")
19  exit(1)
20 
21 
22 def getWeights(dsid):
23  info = {}
24  keys = []
25  with open("%s/DSID_Database.yaml" % SystToolsPath) as f:
26  database = yaml.load(f)
27  if any(str(dsid) == k for k in database.keys()):
28  keys = database.get(str(dsid))
29  # print(keys)
30  if keys == ['nominal']:
31  info.update({"nominal": "nominal"})
32  else:
33  with open('%s/Weight_Database.yaml' % SystToolsPath) as d:
34  weight_data = yaml.load(d)
35  for key in keys:
36  if key in weight_data.keys():
37  info.update({key: weight_data.get(key)})
38  else:
39  print(key + ' key for ' + str(dsid) + ' not in Weight Databse')
40  else:
41  print((str(dsid) + ' not in Database'))
42  return info, keys
43 
44 
46  res = {}
47  for fn in os.listdir("%s/Weight_files" % SystToolsPath):
48  print(fn, str(dsid), (str(dsid) in fn))
49  if str(dsid) in fn:
50  with open("%s/Weight_files/%s" % (SystToolsPath, fn)) as f:
51  counter = 0
52  for line in f.readlines():
53  line = line.strip()
54  res[line] = counter
55  counter += 1
56  break
57  if len(res) == 0:
58  print((str(dsid) + ' not in Database'))
59  return res
60 
61 
62 def main(argv):
63  parser = argparse.ArgumentParser(description='Variation string needed')
64  parser.add_argument('-d', '--dsid', default=410425, type=int, help='six digit DSID')
65  args = parser.parse_args()
66  dictionary, keys = getWeights(args.dsid)
67  print(keys)
68  print(dictionary)
69 
70 
71 if __name__ == "__main__":
72  main(sys.argv[1:])
readDatabase.main
def main(argv)
Definition: readDatabase.py:62
calibdata.exit
exit
Definition: calibdata.py:236
Trk::open
@ open
Definition: BinningType.h:40
readDatabase.getOrderedWeights
def getOrderedWeights(dsid)
Definition: readDatabase.py:45
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
readDatabase.getWeights
def getWeights(dsid)
Definition: readDatabase.py:22