ATLAS Offline Software
Classes | Functions
TriggerMenuDB2JSONConverter Namespace Reference

Classes

class  Silence
 

Functions

def main ()
 

Function Documentation

◆ main()

def TriggerMenuDB2JSONConverter.main ( )

Definition at line 20 of file TriggerMenuDB2JSONConverter.py.

20 def main():
21 
22 
23  parser = OptionParser(usage="usage: %prog [options] smk")
24 
25  parser.add_option("-v", "--verbose",
26  action = "store_true",
27  dest = "verbose",
28  default = False,
29  help="verbose output [default: %default]")
30 
31  actions = OptionGroup(parser, "actions")
32 
33  actions.add_option( "",
34  "--l1",
35  dest = "l1psk",
36  metavar = "PSK",
37  default = 0,
38  help = "Level 1 prescale key PSK for L1 prescale set to convert" )
39 
40  actions.add_option( "",
41  "--hlt",
42  type="int",
43  dest = "hltpsk",
44  metavar="PSK",
45  default = 0,
46  help = "HLT prescale key PSK for HLT prescale set to convert" )
47 
48  actions.add_option( "",
49  "--showpsk",
50  dest = "showpsk",
51  action = "store_true",
52  default = False,
53  help = "only prints prescale keys attached to SMK [default: %default]" )
54 
55  parser.add_option_group(actions)
56 
57  parser.add_option( "",
58  "--db",
59  dest = "db",
60  default = "TRIGGERDB",
61  help = "database alias TRIGGERDB|TRIGGERDBREPR|TRIGGERDBMC [default: %default]" )
62 
63 
64  (options, args) = parser.parse_args()
65 
66  if len(args) != 1:
67  parser.error("Please specify the SMK")
68 
69  try:
70  smk = int(args[0])
71  except ValueError:
72  parser.error("SMK must be an integer")
73 
74 
75  if not (options.l1psk or options.hltpsk or options.showpsk):
76  parser.print_help()
77  parser.error("Please specify one of the actions")
78 
79  if options.showpsk:
80  with Silence(options.verbose):
81  from TrigConfigSvc.TrigConfigSvcUtils import getHLTPrescalesFromSMK
82  hltpsk = getHLTPrescalesFromSMK(options.db,smk)
83  print("Trigger keys connected to SM %i are %r" % (smk, [int(k[0]) for k in hltpsk]))
84 
85 
86  if options.hltpsk:
87  with Silence(options.verbose): # suppress all the output from loading the athena modules
88  from TrigConfigSvc.TrigConfigSvcUtils import queryHLTPrescaleTableRun2
89  res = queryHLTPrescaleTableRun2(options.db,options.hltpsk,smk)
90 
91  from collections import defaultdict
92  d = defaultdict(lambda : list())
93 
94  for e in res:
95  d[(int(e[1]),e[0])] += [ (e[2],e[4]) ]
96 
97  # building json structure
98  prescaleSet = []
99  for (chainID, chainName),prescales in sorted(d.items()):
100  entry = {}
101  entry['chainId'] = chainID
102  entry['chainName'] =chainName
103  entry.update(prescales)
104  prescaleSet.append( entry )
105 
106  # saving to file
107  filename = "HLTPrescales_smk%i_psk%i.json" % (smk, options.hltpsk)
108  FH = open(filename, "w")
109  json.dump(prescaleSet, FH, indent=4, separators=(',', ': '))
110  FH.close()
111  print("Wrote file %s" % filename)
112 
113  if options.l1psk:
114  with Silence(options.verbose): # suppress all the output from loading the athena modules
115  from TrigConfigSvc.TrigConfigSvcUtils import queryHLTPrescaleTableRun2
116  res = queryHLTPrescaleTableRun2(options.db,options.hltpsk,smk)
117 
118  from collections import defaultdict
119  d = defaultdict(lambda : list())
120 
121  for e in res:
122  d[(int(e[1]),e[0])] += [ (e[2],e[4]) ]
123 
124  # building json structure
125  prescaleSet = []
126  for (chainID, chainName),prescales in sorted(d.items()):
127  entry = {}
128  entry['chainId'] = chainID
129  entry['chainName'] =chainName
130  entry.update(prescales)
131  prescaleSet.append( entry )
132 
133  # saving to file
134  filename = "HLTPrescales_smk%i_psk%i.json" % (smk, options.hltpsk)
135  FH = open(filename, "w")
136  json.dump(prescaleSet, FH, indent=4, separators=(',', ': '))
137  FH.close()
138  print("Wrote file %s" % filename)
139 
140 
141 
142 
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
python.TrigConfigSvcUtils.getHLTPrescalesFromSMK
def getHLTPrescalesFromSMK(connection, smk)
Definition: TrigConfigSvcUtils.py:924
TriggerMenuDB2JSONConverter.main
def main()
Definition: TriggerMenuDB2JSONConverter.py:20
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.TrigConfigSvcUtils.queryHLTPrescaleTableRun2
def queryHLTPrescaleTableRun2(connection, psk, smk)
Definition: TrigConfigSvcUtils.py:884
Trk::open
@ open
Definition: BinningType.h:40
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45