579 def execute(self):
580
581 if self._eif_totentries < 100:
582 _info = self.msg.info
583 else:
584 _info = lambda *x: None
585 _warning = self.msg.warning
586
587 _info("POOL2EI::execute")
588
589 if self._eif_spb is not None:
590 eventPB = self.eipbof.EIEvent()
591
592
593
594
595
596 store = self.evtStore
597
598 if self.item_xaod_eventinfo:
599
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()
607 try:
608 time_stamp_ns = xei.timeStampNSOffset()
609 except Exception:
610 _info('## Event does not have xAOD::EventInfo::'
611 'timeStampNSOffset()')
612 time_stamp_ns = 0
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
618 mc_event_weight = 0.
619 if isSimulation:
620 try:
621 mc_channel_number = xei.mcChannelNumber()
622 mc_event_weight = xei.mcEventWeight()
623 except Exception:
624 pass
625 try:
626 extendedLevel1ID = xei.extendedLevel1ID()
627 except Exception:
628 _info('## Event does not have xAOD::EventInfo::'
629 'extendedLevel1ID()')
630 extendedLevel1ID = 0
631
632 eInfoTrigger = None
633
634 del xei
635
636 elif self.item_eventinfo:
637
638
639 evt_info_keys = [
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))
647 eid = ei.event_ID()
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)
658
659 isSimulation = True if 'IS_SIMULATION' in bm else False
660
661 isTestBeam = True if 'IS_TESTBEAM' in bm else False
662
663 isCalibration = True if 'IS_CALIBRATION' in bm else False
664 extendedLevel1ID = 0
665 eInfoTrigger = ei.trigger_info()
666 extendedLevel1ID = eInfoTrigger.extendedLevel1ID()
667
668 del ei
669
670 else:
671
672 raise RuntimeError('Unable to find neither '
673 'xAOD::EventInfo nor EventInfo')
674
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))
687
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
701
702
703
704
705
706 if self.item_xaod_TrigConfKeys:
707 _info("Retrieve TrigConfKeys from xAOD::TrigConfKeys")
708 tck = store.retrieve('xAOD::TrigConfKeys', 'TrigConfKeys')
709 evt_smk = tck.smk()
710 evt_l1psk = tck.l1psk()
711 evt_hltpsk = tck.hltpsk()
712 del tck
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))
719 else:
720 _info("Unable to retrieve TrigConfKeys")
721 evt_smk = 0
722 evt_l1psk = 0
723 evt_hltpsk = 0
724
725 _info('## smk: {}'.format(evt_smk))
726 _info('## hltpsk: {}'.format(evt_hltpsk))
727 _info('## l1psk: {}'.format(evt_l1psk))
728
729 if self._eif_spb is not None:
730 eventPB.SMK = evt_smk
731 eventPB.HLTPSK = evt_hltpsk
732 eventPB.L1PSK = evt_l1psk
733
734
735
736
737
738 if self.DoTriggerInfo:
739
740 def v2b(v):
741 res = ""
742 for e in v:
743 res += "{0:032b}".format(e)[::-1]
744 return res
745
746 trigL1 = ""
747 trigL2 = ""
748 trigEF = ""
749
750 if self.item_xaod_TrigDecision:
751
752 _info("Get trigger bit masks form xAOD::TrigDecision")
753
754
755 xtd = store.retrieve('xAOD::TrigDecision', 'xTrigDecision')
756
757
758 tbp = xtd.tbp()
759 tap = xtd.tap()
760 tav = xtd.tav()
761 trigL1 = compressB64(v2b(tbp) + v2b(tap) + v2b(tav))
762 del tbp
763 del tap
764 del tav
765
766
767 trigL2_PH = xtd.lvl2PassedPhysics()
768 trigL2_PT = xtd.lvl2PassedThrough()
769 trigL2_RS = xtd.lvl2Resurrected()
770 trigL2 = "{};{};{}".format(
771 compressB64(v2b(trigL2_PH)),
772 compressB64(v2b(trigL2_PT)),
773 compressB64(v2b(trigL2_RS)))
774 del trigL2_PH
775 del trigL2_PT
776 del trigL2_RS
777
778
779 trigEF_PH = xtd.efPassedPhysics()
780 trigEF_PT = xtd.efPassedThrough()
781 trigEF_RS = xtd.efResurrected()
782 trigEF = "{};{};{}".format(
783 compressB64(v2b(trigEF_PH)),
784 compressB64(v2b(trigEF_PT)),
785 compressB64(v2b(trigEF_RS)))
786 del trigEF_PH
787 del trigEF_PT
788 del trigEF_RS
789
790 del xtd
791
792 else:
793
794 _info("Get trigger bit masks form eventInfo.trigger_info()")
795
796
797 if eInfoTrigger is not None:
798 trigL1 = compressB64(v2b(eInfoTrigger.level1TriggerInfo()))
799 trigL2 = compressB64(v2b(eInfoTrigger.level2TriggerInfo()))
800 trigEF = compressB64(v2b(eInfoTrigger.eventFilterInfo()))
801
802 _info("## trigL1: {}".format(trigL1))
803 _info("## trigL2: {}".format(trigL2))
804 _info("## trigEF: {}".format(trigEF))
805
806 if self._eif_spb is not None:
807
808 eventPB.L1PassedTrigMask = trigL1
809 eventPB.L2PassedTrigMask = trigL2
810 eventPB.EFPassedTrigMask = trigEF
811
812 if eInfoTrigger is not None:
813 del eInfoTrigger
814
815
816
817
818
819 def guid2string(guid):
820
821
822
823
824
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]))
831 return s
832
833 def token2string (tk, replace_empty_cntID=False):
834
835
836
837 cntID = tk.contID()
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)
843 return stk
844
845 Pstream_refs = {}
846 procTag = None
847
848
849 dh = store.retrieve('DataHeader', 'EventSelector')
850 procTag = dh.getProcessTag()
851
852 if procTag == "":
853
854 for el in dh.elements():
855 if el.getPrimaryClassID() == 222376821:
856 procTag = el.getKey()
857 break
858 _info("## ProcessTag: " + procTag)
859
860 if self.DoProvenanceRef:
861
862
863 if dh.sizeProvenance() > 0:
864 prv = dh.beginProvenance()
865 for i in range(dh.sizeProvenance()):
866 key = prv.getKey()
867 tk = prv.getToken()
868 if key.startswith("Output"):
869 _warning('Provenance token starts with Output: {}'
870 .format(key))
871 key = key[6:]
872 if key.startswith("Input"):
873 _warning('Provenance token starts with Input: {}'
874 .format(key))
875 key = key[5:]
876
877 if key == "StreamRAW":
878 stk = token2string(tk, replace_empty_cntID=False)
879 elif key in ("StreamAOD", "StreamESD", "StreamRDO",
880 "StreamHITS", "StreamEVGEN",
881 "EmbeddingStream"):
882 stk = token2string(tk, replace_empty_cntID=True)
883 else:
884 stk = token2string(tk, replace_empty_cntID=False)
885 _info("provenance {}={}".format(key, stk))
886 _info('Unknown provenance stream: {}'.format(key))
887
888
889
890 del tk
891 del key
892 prv += 1
893 continue
894 _info("## P" + key + "_ref: " + stk)
895 if key not in Pstream_refs:
896
897 Pstream_refs[key] = stk
898 del tk
899 del key
900 prv += 1
901 del prv
902
903
904
905
906 if self._eif_spb is not None:
907 tokenPB0 = eventPB.eitoken.add()
908 if dh.size() > 0:
909 dhe = dh.begin()
910 for i in range(dh.size()):
911 key = dhe.getKey()
912 if key.startswith('Stream'):
913 _info("## Stream: " + key)
914 if key in [procTag, 'StreamAOD']:
915 tk = dhe.getToken()
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))
922 tokenPB0.name = key
923 tokenPB0.token = stk
924 del tk
925 del key
926 dhe += 1
927 dh.end()
928 del dhe
929
930
931 try:
932 stk = store.proxy(dh).address().par().c_str()
933 if self._eif_spb is not None:
934 tokenPB0.token = stk
935 _info("Updated ref token " + stk)
936 del stk
937 except Exception:
938 pass
939
940
941 if self._eif_spb is not None:
942 for sr in Pstream_refs:
943 try:
944 tokenPB = eventPB.eitoken.add()
945 tokenPB.name = sr
946 tokenPB.token = Pstream_refs[sr]
947 except Exception:
948 _info("Unable to insert {} in provenance stream "
949 "references with value {}".format(
950 sr, Pstream_refs[sr]))
951 pass
952
953 del dh
954
955
956
957
958
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)
965 del eventPB
966 if (self._eif_entries % 1000 == 0):
967 self._eif_spb.flush()
968
969 self._eif_entries += 1
970 self._eif_totentries += 1
971
972 store.clearStore()
973
974 return StatusCode.Success
975
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)