ATLAS Offline Software
hltResult.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 from __future__ import print_function
4 import cppyy
5 from CLIDComps.clidGenerator import clidGenerator
6 
7 clidg = clidGenerator("")
8 from ROOT import HLT
9 stringSerializer = cppyy.gbl.StringSerializer()
10 
12  def __init__(self):
13  super( hltResult, self ).__init__()
14  self.as_int_v = cppyy.gbl.std.vector('unsigned int')()
15 
16  def load(self, rob):
17  self.nav_payload = []
18 
19  data = list(rob.rod_data())
20  self.as_int_v.clear()
21  self.as_int_v.reserve(len(data))
22  [ self.as_int_v.push_back(i) for i in data ]
23 
24  if self.deserialize(self.as_int_v) is False:
25  raise Exception('deserialization of the HLT result failed')
26  self.__unpack_navigation()
27 
28 
29  def __unpack_navigation(self):
30  nav_data = list(self.getNavigationResult())
31  if len(nav_data) <= 1:
32  return
33 
34  fidx=nav_data[2]
35  blob = get_feature_data_blob(nav_data, fidx)
36  while len(blob):
37  fsize = len(blob)
38  clid = blob[0]
39  stidx = blob[1]
40  slabel = blob[2]
41  lwords = blob[3:3+slabel]
42  sdata = len(blob)-slabel-3
43 
44  label = deserialize_string(lwords)
45  self.nav_payload.append( (clidg.getNameFromClid(clid), label, fsize*4, sdata*4, clid, stidx) )
46  fidx = fidx+fsize+1
47  blob = get_feature_data_blob(nav_data, fidx)
48 
49  def appName(self):
50  if self.getExtras().size()>1:
51  return deserialize_string(self.getExtras())
52  else:
53  return ''
54 
55 
56 def get_feature_data_blob(data, index):
57  if index == len(data):
58  return []
59  size = data[index]
60  begin = index
61  begin += 1
62  end = index
63  end +=1
64  end += size
65  if end <= len(data):
66  index = end
67  #print "getting blob of data from: ", begin, " to ", end
68  return data[begin:end]
69  else:
70  return []
71 
72 
73 def deserialize_string(lwords):
74  """Wrapper for the C++ StringSerializer"""
75 
76  v = cppyy.gbl.std.vector('unsigned int')()
77  s = cppyy.gbl.std.string()
78  v.reserve(len(lwords))
79  for w in lwords:
80  v.push_back(w)
81  stringSerializer.deserialize(v, s)
82  return str(s)
83 
84 
85 
88 
89 def print_ranges(l):
90  for i in range(len(l)):
91  print("%-16d%16d" % ( (i+1)*32, i*32))
92 
93 def print_chain(counter, s):
94  ch = cppyy.makeClass('HLT::Chain')(s)
95  #ch.deserialize(s)
96  print(".... chain %-3d Counter:%-4d Passed: %d (Raw:%d Prescaled: %d PassThrough:%d) Rerun: %d LastStep: %d Err: %s"\
97  % ( counter, ch.getChainCounter(), ch.chainPassed(), ch.chainPassedRaw(), ch.isPrescaled(), ch.isPassedThrough(),\
98  ch.isResurrected(), ch.getChainStep(), ch.getErrorCode().str()))
99 
101  print("... chains:")
102  for i in range(len(blob)):
103  print_chain(i, blob[i])
104 
105 
107  print("... features")
108  for f in result.nav_payload:
109  print(".... %-52s %6d B " % (str(f[0])+'#'+str(f[1]), f[2]))
110  return
111 
112 
113 def print_HLTResult(result, opt):
114  if opt.sizes:
115  print("... Payload size: ", result.as_int_v.size(), " ", (4.0*result.as_int_v.size())/(1024), "kB")
116 
117  if result.as_int_v.size() == 0:
118  print("... Payload size is 0")
119 
120  # header info
121 
122  version = result.getHLTResultClassVersion()
123  l1id = result.getLvl1Id()
124  acc = result.isAccepted()
125  pt = result.isPassThrough()
126  status = result.getHLTStatus()
127  cnvstatus = result.getLvlConverterStatus()
128  level = result.getHLTLevel()
129  nosigs = result.getNumOfSatisfiedSigs()
130  bad = result.isCreatedOutsideHLT()
131  trunc = result.isHLTResultTruncated()
132  print('... Version:', version ,' Lvl1Id:',l1id ,' Decision:',acc ,
133  ' PassThrough:',pt,' Status:',status.str(),
134  ' ConverterStatus:', cnvstatus.str(),' LVL:',level,' Signatures:',nosigs,' Bad:',bad,' Truncated:', trunc,
135  ' App:', result.appName())
136  print()
137 
138  chains_data = list(result.getChainResult())
139  nchains = chains_data[0] if chains_data else 0
140  nav_data = list(result.getNavigationResult())
141  nnav = len(nav_data)
142  nver = nav_data[0] if nav_data else 0
143 
144  if opt.sizes:
145  print('... tot:', result.as_int_v.size(), ' chains:', nchains, ' chains (expected):', len(chains_data)-1,
146  ' navigation:', nnav, ' navigation (expected):',result.getNavigationResult()[1] if nnav > 1 else "0 or 1")
147 
148  if opt.conf:
149  try:
150  print("... SMkey: ", result.getConfigSuperMasterKey(), " Prescalers key ", result.getConfigPrescalesKey())
151  except Exception:
152  print("... No config info ")
153 
154  if opt.chains:
155  print_all_chains(chains_data[1:])
156 
157 
158  print("... Navigation version: ", nver)
159  if opt.tes:
160  if nnav > 3:
161  tessize = result.getNavigationResult()[2]
162  tescount = result.getNavigationResult()[3]
163  print("... Number of TEs: ", tescount, " and size: ", tessize, " ", 4.0*tessize/(1024), "kB")
164  else:
165  print("... Cannot print TriggerElement details (not enough navigation data)")
166 
167  if opt.features:
168  print_all_navigation(result)
169 
170 
171 
173 def collect_feature_sizes(dest, result):
174  for f in result.nav_payload:
175  key = f[0]+'#'+f[1]
176  if key not in dest:
177  dest[key] = 0
178  dest[key] += f[2]
179 
180  # keyed by type
181  key = f[0]
182  if key not in dest:
183  dest[key] = 0
184  dest[key] += f[2]
185 
186  if 'Total' not in dest:
187  dest['Total'] = 0
188  dest['Total'] += 4*result.as_int_v.size()
python.hltResult.hltResult.__init__
def __init__(self)
Definition: hltResult.py:12
python.hltResult.hltResult.__unpack_navigation
def __unpack_navigation(self)
Definition: hltResult.py:29
GenericResult::deserialize
virtual bool deserialize(const std::vector< uint32_t > &source)=0
unpacking raw result into the usable high level object
python.hltResult.print_all_navigation
def print_all_navigation(result)
Definition: hltResult.py:106
python.hltResult.hltResult.appName
def appName(self)
Definition: hltResult.py:49
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.hltResult.get_feature_data_blob
def get_feature_data_blob(data, index)
Definition: hltResult.py:56
python.hltResult.hltResult.nav_payload
nav_payload
Definition: hltResult.py:17
python.hltResult.print_ranges
def print_ranges(l)
printing utils
Definition: hltResult.py:89
HLT::HLTResult::getNavigationResult
const std::vector< uint32_t > & getNavigationResult() const
retrieve the sub-payloads (can be used to retrieve/write data)
Definition: HLTResult.h:256
HLT::HLTResult::getExtras
const std::vector< uint32_t > & getExtras() const
Definition: HLTResult.h:259
python.hltResult.hltResult
Definition: hltResult.py:11
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.hltResult.deserialize_string
def deserialize_string(lwords)
Definition: hltResult.py:73
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
HLT::HLTResult
HLT::HLTResult is sumarising result of trigger decision evaluation (online/offline) It contains basic...
Definition: HLTResult.h:57
python.hltResult.hltResult.as_int_v
as_int_v
Definition: hltResult.py:14
python.hltResult.collect_feature_sizes
def collect_feature_sizes(dest, result)
collect the sizes
Definition: hltResult.py:173
python.hltResult.hltResult.load
def load(self, rob)
Definition: hltResult.py:16
python.hltResult.print_HLTResult
def print_HLTResult(result, opt)
Definition: hltResult.py:113
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
python.hltResult.print_chain
def print_chain(counter, s)
Definition: hltResult.py:93
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
HLT::HLTResult::size
unsigned int size() const
Definition: HLTResult.cxx:614
str
Definition: BTagTrackIpAccessor.cxx:11
python.hltResult.print_all_chains
def print_all_chains(blob)
Definition: hltResult.py:100