5 Module for applying L1 prescales to the input data
7 Used as a "-Z" plugin to athenaHLT:
8 athenaHLT -Z TrigByteStreamTools.trigbs_prescaleL1 ...
14 from AthenaCommon.Logging
import logging
19 cppyy.load_library(
'libTrigByteStreamToolsDict')
20 from ROOT
import CTPdataformat
21 from TrigByteStreamTools
import CTPfragment
24 log = logging.getLogger(
'trigbs_prescaleL1.py')
25 log.setLevel(logging.INFO)
28 """Load L1 prescales from DB"""
30 database = config[
'db-server']
31 l1psk =
int(config[
'db-extra'][
'lvl1key'])
33 log.info(
'Applying L1 prescale set %s from %s', l1psk, database)
34 from TrigConfigSvc.TrigConfigSvcUtils
import getL1Prescales
36 log.debug(
'Prescales: %s',
str(prescales))
41 """Prescale L1 items in CTP fragment used by HLT"""
47 event = kwargs[
"event"]
50 seed =
'%s%s' % (event.bc_time_seconds(),event.bc_time_nanoseconds())
51 random.seed(zlib.crc32(seed))
53 new_event=eformat.write.FullEventFragment()
54 new_event.copy_header(event)
56 if rob.source_id()!=eformat.helper.SourceIdentifier(eformat.helper.SubDetector.TDAQ_CTP,1):
57 new_event.append_unchecked(rob)
59 data = [d
for d
in rob.rod_data()]
60 v = CTPfragment.ctpFormatVersion(rob)
61 TBPpos = CTPfragment._versioned(CTPdataformat,
'TBPpos',v)
62 TBPwords = CTPfragment._versioned(CTPdataformat,
'TBPwords',v)
63 TAVpos = CTPfragment._versioned(CTPdataformat,
'TAVpos',v)
65 L1TBP = CTPfragment.decodeTriggerBits(data[TBPpos:TBPpos+TBPwords])
66 log.debug(
'L1TBP: %s', L1TBP)
71 if random.uniform(0,prescales[ctp])>1:
75 log.debug(
'New L1TAV: %s', newL1TAV)
76 newL1TAVBits = CTPfragment.encodeTriggerBits(newL1TAV,TBPwords)
77 for i,value
in enumerate(newL1TAVBits):
78 data[TAVpos+i] = value
81 newrob = eformat.write.ROBFragment(rob)
83 new_event.append(newrob)
85 l1bits = [b
for b
in event.lvl1_trigger_info()]
86 new_event.lvl1_trigger_info(l1bits[0:TBPwords]+data[TAVpos:TAVpos+TBPwords]*2)
88 return new_event.readonly()
92 if __name__ ==
"__main__":
94 print(
"Syntax: trigbs_prescaleL1.py FILE")
97 log.setLevel(logging.DEBUG)
98 kwargs = {
'configuration' : {
'db-server':
'TRIGGERDB_RUN1',
99 'db-extra' : {
'lvl1key' : 300}}}
101 kwargs = {
'configuration' : {
'db-server':
'TRIGGERDBREPR',
102 'db-extra' : {
'lvl1key' : 30}}}
104 ost = eformat.ostream()
105 for e
in eformat.istream(sys.argv[1]):