581 if self._eif_totentries < 100:
582 _info = self.msg.info
584 _info =
lambda *x:
None
585 _warning = self.msg.warning
587 _info(
"POOL2EI::execute")
589 if self._eif_spb
is not None:
590 eventPB = self.eipbof.EIEvent()
596 store = self.evtStore
598 if self.item_xaod_eventinfo:
600 _info(
'=== [xAOD::EventInfo] ===')
601 xei = store.retrieve(
'xAOD::EventInfo',
'EventInfo')
602 run_number = xei.runNumber()
603 event_number = xei.eventNumber()
604 lumi_block = xei.lumiBlock()
605 bunch_crossing_id = xei.bcid()
606 time_stamp = xei.timeStamp()
608 time_stamp_ns = xei.timeStampNSOffset()
610 _info(
'## Event does not have xAOD::EventInfo::'
611 'timeStampNSOffset()')
613 evt_type_bit_mask = xei.eventTypeBitmask()
614 isSimulation = (evt_type_bit_mask & xei.IS_SIMULATION != 0)
615 isTestBeam = (evt_type_bit_mask & xei.IS_TESTBEAM != 0)
616 isCalibration = (evt_type_bit_mask & xei.IS_CALIBRATION != 0)
617 mc_channel_number = 0
621 mc_channel_number = xei.mcChannelNumber()
622 mc_event_weight = xei.mcEventWeight()
626 extendedLevel1ID = xei.extendedLevel1ID()
628 _info(
'## Event does not have xAOD::EventInfo::'
629 'extendedLevel1ID()')
636 elif self.item_eventinfo:
640 x
for x
in store.keys()
if x.endswith(
"EventInfo")]
641 if len(evt_info_keys) != 1:
642 _info(
'more than one EventInfo: {}'.
format(evt_info_keys))
643 _info(
' ==> we\'ll use [{}]'.
format(evt_info_keys[0]))
644 sg_key = evt_info_keys[0]
645 ei = store.retrieve(
'EventInfo', sg_key)
646 _info(
'=== [EventInfo#{}] ==='.
format(sg_key))
648 run_number = eid.run_number()
649 event_number = eid.event_number()
650 lumi_block = eid.lumi_block()
651 bunch_crossing_id = eid.bunch_crossing_id()
652 time_stamp = eid.time_stamp()
653 time_stamp_ns = eid.time_stamp_ns_offset()
654 eitype = ei.event_type()
655 mc_channel_number = eitype.mc_channel_number()
656 mc_event_weight = eitype.mc_event_weight()
657 bm =
list(eitype.bit_mask)
659 isSimulation =
True if 'IS_SIMULATION' in bm
else False
661 isTestBeam =
True if 'IS_TESTBEAM' in bm
else False
663 isCalibration =
True if 'IS_CALIBRATION' in bm
else False
665 eInfoTrigger = ei.trigger_info()
666 extendedLevel1ID = eInfoTrigger.extendedLevel1ID()
672 raise RuntimeError(
'Unable to find neither '
673 'xAOD::EventInfo nor EventInfo')
675 _info(
'## run_number: {:d}'.
format(run_number))
676 _info(
'## event_number: {:d}'.
format(event_number))
677 _info(
'## bunch_crossing_id: {:d}'.
format(bunch_crossing_id))
678 _info(
'## extendedLevel1ID: {:d}'.
format(extendedLevel1ID))
679 _info(
'## lumi_block: {:d}'.
format(lumi_block))
680 _info(
'## time_stamp: {:d}'.
format(time_stamp))
681 _info(
'## time_stamp_ns_offset: {:d}'.
format(time_stamp_ns))
682 _info(
'## EventWeight: {:f}'.
format(mc_event_weight))
683 _info(
'## McChannelNumber: {:d}'.
format(mc_channel_number))
684 _info(
'## isSimulation: {}'.
format(isSimulation))
685 _info(
'## isTestBeam: {}'.
format(isTestBeam))
686 _info(
'## isCalibration: {}'.
format(isCalibration))
688 if self._eif_spb
is not None:
689 eventPB.runNumber = run_number
690 eventPB.eventNumber = event_number
691 eventPB.lumiBlock = lumi_block
692 eventPB.bcid = bunch_crossing_id
693 eventPB.timeStamp = time_stamp
694 eventPB.timeStampNSOffset = time_stamp_ns
695 eventPB.mcEventWeight = mc_event_weight
696 eventPB.mcChannelNumber = mc_channel_number
697 eventPB.isSimulation = isSimulation
698 eventPB.isCalibration = isCalibration
699 eventPB.isTestBeam = isTestBeam
700 eventPB.extendedLevel1ID = extendedLevel1ID
706 if self.item_xaod_TrigConfKeys:
707 _info(
"Retrieve TrigConfKeys from xAOD::TrigConfKeys")
708 tck = store.retrieve(
'xAOD::TrigConfKeys',
'TrigConfKeys')
710 evt_l1psk = tck.l1psk()
711 evt_hltpsk = tck.hltpsk()
713 elif (self.meta_hlt_hltconfigkeys
or self.meta_hlt_prescalekey
714 or self.meta_lvl1_lvl1configkey):
715 _info(
"Retrieve TrigConfKeys from /TRIGGER/**")
716 evt_smk = self._iov.
get(
'SMK', (run_number, event_number))
717 evt_l1psk = self._iov.
get(
'L1PSK', (run_number, lumi_block))
718 evt_hltpsk = self._iov.
get(
'HLTPSK', (run_number, lumi_block))
720 _info(
"Unable to retrieve TrigConfKeys")
725 _info(
'## smk: {}'.
format(evt_smk))
726 _info(
'## hltpsk: {}'.
format(evt_hltpsk))
727 _info(
'## l1psk: {}'.
format(evt_l1psk))
729 if self._eif_spb
is not None:
730 eventPB.SMK = evt_smk
731 eventPB.HLTPSK = evt_hltpsk
732 eventPB.L1PSK = evt_l1psk
738 if self.DoTriggerInfo:
743 res +=
"{0:032b}".
format(e)[::-1]
750 if self.item_xaod_TrigDecision:
752 _info(
"Get trigger bit masks form xAOD::TrigDecision")
755 xtd = store.retrieve(
'xAOD::TrigDecision',
'xTrigDecision')
761 trigL1 =
compressB64(v2b(tbp) + v2b(tap) + v2b(tav))
767 trigL2_PH = xtd.lvl2PassedPhysics()
768 trigL2_PT = xtd.lvl2PassedThrough()
769 trigL2_RS = xtd.lvl2Resurrected()
770 trigL2 =
"{};{};{}".
format(
779 trigEF_PH = xtd.efPassedPhysics()
780 trigEF_PT = xtd.efPassedThrough()
781 trigEF_RS = xtd.efResurrected()
782 trigEF =
"{};{};{}".
format(
794 _info(
"Get trigger bit masks form eventInfo.trigger_info()")
797 if eInfoTrigger
is not None:
798 trigL1 =
compressB64(v2b(eInfoTrigger.level1TriggerInfo()))
799 trigL2 =
compressB64(v2b(eInfoTrigger.level2TriggerInfo()))
800 trigEF =
compressB64(v2b(eInfoTrigger.eventFilterInfo()))
802 _info(
"## trigL1: {}".
format(trigL1))
803 _info(
"## trigL2: {}".
format(trigL2))
804 _info(
"## trigEF: {}".
format(trigEF))
806 if self._eif_spb
is not None:
808 eventPB.L1PassedTrigMask = trigL1
809 eventPB.L2PassedTrigMask = trigL2
810 eventPB.EFPassedTrigMask = trigEF
812 if eInfoTrigger
is not None:
819 def guid2string(guid):
825 s=
"{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}".
format(
826 guid.data1(), guid.data2(), guid.data3(),
827 ord(guid.data4(0)[0]), ord(guid.data4(1)[0]),
828 ord(guid.data4(2)[0]), ord(guid.data4(3)[0]),
829 ord(guid.data4(4)[0]), ord(guid.data4(5)[0]),
830 ord(guid.data4(6)[0]), ord(guid.data4(7)[0]))
833 def token2string (tk, replace_empty_cntID=False):
838 if replace_empty_cntID
and cntID ==
"":
839 cntID =
"POOLContainer(DataHeader)"
840 stk =
"[DB={}][CNT={}][CLID={}][TECH={:08X}][OID={:016X}-{:016X}]".
format(
841 guid2string(tk.dbID()), cntID, guid2string(tk.classID()),
842 tk.technology(), tk.oid().first, tk.oid().second)
849 dh = store.retrieve(
'DataHeader',
'EventSelector')
850 procTag = dh.getProcessTag()
854 for el
in dh.elements():
855 if el.getPrimaryClassID() == 222376821:
856 procTag = el.getKey()
858 _info(
"## ProcessTag: " + procTag)
860 if self.DoProvenanceRef:
863 if dh.sizeProvenance() > 0:
864 prv = dh.beginProvenance()
865 for i
in range(dh.sizeProvenance()):
868 if key.startswith(
"Output"):
869 _warning(
'Provenance token starts with Output: {}'
872 if key.startswith(
"Input"):
873 _warning(
'Provenance token starts with Input: {}'
877 if key ==
"StreamRAW":
878 stk = token2string(tk, replace_empty_cntID=
False)
879 elif key
in (
"StreamAOD",
"StreamESD",
"StreamRDO",
880 "StreamHITS",
"StreamEVGEN",
882 stk = token2string(tk, replace_empty_cntID=
True)
884 stk = token2string(tk, replace_empty_cntID=
False)
885 _info(
"provenance {}={}".
format(key, stk))
886 _info(
'Unknown provenance stream: {}'.
format(key))
894 _info(
"## P" + key +
"_ref: " + stk)
895 if key
not in Pstream_refs:
897 Pstream_refs[key] = stk
906 if self._eif_spb
is not None:
907 tokenPB0 = eventPB.eitoken.add()
910 for i
in range(dh.size()):
912 if key.startswith(
'Stream'):
913 _info(
"## Stream: " + key)
914 if key
in [procTag,
'StreamAOD']:
916 stk = token2string(tk, replace_empty_cntID=
True)
917 _info(
"## " + key +
"_ref: " + stk)
918 if self._eif_spb
is not None:
919 if key == tokenPB0.name:
920 _info(
"Already inserted key {0} in tokenPB0 "
921 "with value {1}".
format(key, stk))
933 if self._eif_spb
is not None:
935 _info(
"Updated ref token " + stk)
941 if self._eif_spb
is not None:
942 for sr
in Pstream_refs:
944 tokenPB = eventPB.eitoken.add()
946 tokenPB.token = Pstream_refs[sr]
948 _info(
"Unable to insert {} in provenance stream "
949 "references with value {}".
format(
950 sr, Pstream_refs[sr]))
959 if self._eif_spb
is not None:
960 spb = eventPB.SerializeToString()
961 self._eif_spb.
write(struct.pack(
'<I', eic.EI_PROTO_EIEVENT << 8 |
962 eic.EI_PROTO_MSGVER))
963 self._eif_spb.
write(struct.pack(
'<I', len(spb)))
964 self._eif_spb.
write(spb)
966 if (self._eif_entries % 1000 == 0):
967 self._eif_spb.
flush()
969 self._eif_entries += 1
970 self._eif_totentries += 1
974 return StatusCode.Success