ATLAS Offline Software
L1Menu2JSON.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon.Logging import logging
4 log = logging.getLogger(__name__)
5 
6 
8 
9  def __init__(self, l1menu = None, outputFile = None, bgsOutputFile = None, inputFile = None ):
10  self.menu = l1menu
11  self.inputFile = inputFile
12  self.outputFile = outputFile
13  self.bgsOutputFile = bgsOutputFile
14 
15  def writeJSON(self,pretty=False):
16 
17  if not self.outputFile:
18  log.warning("Can't write json file since no name was provided")
19  return
20 
21  # L1Menu json
22  confObj = self.generateJSON()
23  with open( self.outputFile, mode="wt" ) as fh:
24  import json
25  json.dump(confObj, fh, indent = 4 if pretty else None, separators=(',', ': '))
26  fh.write("\n")
27  log.info("Wrote %s", self.outputFile)
28 
29  if self.bgsOutputFile is not None:
30  confObj = self.generateJsonBunchgroupset()
31  with open( self.bgsOutputFile, mode="wt" ) as fh:
32  import json
33  json.dump(confObj, fh, indent = 4 if pretty else None, separators=(',', ': '))
34  fh.write("\n")
35  log.info("Wrote %s", self.bgsOutputFile)
36 
37 
38  return self.outputFile
39 
40 
41 
42  def generateJSON(self):
43  # import json
44  from collections import OrderedDict as odict
45  confObj = odict()
46 
47  confObj["filetype"] = "l1menu"
48 
49  confObj["name"] = self.menu.menuName
50 
51  confObj["run"] = 3 # will be useful for later (we also record this for Run 1 and 2)
52 
53  # items
54  confObj["items"] = self.menu.items.json()
55 
56  # thresholds
57  confObj["thresholds"] = odict()
58  confObj["thresholds"]["internal"] = odict()
59  confObj["thresholds"]["internal"]["type"] = "internal"
60  confObj["thresholds"]["internal"]["names"] = [ "BGRP%i" % bg.internalNumber for bg in self.menu.ctp.bunchGroupSet.bunchGroups] + \
61  [ "RNDM%i" % i for i in range(0,len(self.menu.ctp.random.names)) ]
62  confObj["thresholds"]["internal"]["randoms"] = odict( [ ("RNDM%i" %i , { "cut" : c }) for i,c in enumerate( self.menu.ctp.random.cuts) ] )
63 
64  # run 3 thresholds
65  confObj["thresholds"].update( self.menu.thresholds.json() )
66 
67  # legacy calo thresholds
68  confObj["thresholds"]["legacyCalo"] = self.menu.thresholds.jsonLegacy()
69 
70  # topo algorithms
71  confObj["topoAlgorithms"] = self.menu.topoAlgos.json()
72 
73  # board definition
74  confObj["boards"] = self.menu.boards.json()
75 
76  # connectors definition
77  confObj["connectors"] = self.menu.connectors.json()
78 
79  # CTP input cabling definition
80  confObj["ctp"] = self.menu.ctp.json()
81 
82  return confObj
83 
84 
86  from collections import OrderedDict as odict
87  confObj = odict()
88 
89  confObj["filetype"] = "bunchgroupset"
90 
91  confObj["name"] = self.menu.menuName
92 
93  # bunchgroups
94  confObj["bunchGroups"] = self.menu.ctp.bunchGroupSet.json()
95 
96  return confObj
python.L1.Base.L1Menu2JSON.L1MenuJSONConverter.__init__
def __init__(self, l1menu=None, outputFile=None, bgsOutputFile=None, inputFile=None)
Definition: L1Menu2JSON.py:9
python.L1.Base.L1Menu2JSON.L1MenuJSONConverter
Definition: L1Menu2JSON.py:7
python.L1.Base.L1Menu2JSON.L1MenuJSONConverter.bgsOutputFile
bgsOutputFile
Definition: L1Menu2JSON.py:13
python.L1.Base.L1Menu2JSON.L1MenuJSONConverter.menu
menu
Definition: L1Menu2JSON.py:10
python.L1.Base.L1Menu2JSON.L1MenuJSONConverter.generateJSON
def generateJSON(self)
Definition: L1Menu2JSON.py:42
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.L1.Base.L1Menu2JSON.L1MenuJSONConverter.writeJSON
def writeJSON(self, pretty=False)
Definition: L1Menu2JSON.py:15
Trk::open
@ open
Definition: BinningType.h:40
dqt_zlumi_pandas.update
update
Definition: dqt_zlumi_pandas.py:42
python.L1.Base.L1Menu2JSON.L1MenuJSONConverter.inputFile
inputFile
Definition: L1Menu2JSON.py:11
python.L1.Base.L1Menu2JSON.L1MenuJSONConverter.generateJsonBunchgroupset
def generateJsonBunchgroupset(self)
Definition: L1Menu2JSON.py:85
pickleTool.object
object
Definition: pickleTool.py:30
python.L1.Base.L1Menu2JSON.L1MenuJSONConverter.outputFile
outputFile
Definition: L1Menu2JSON.py:12