208 obj = store[metadata_name]
210 msg.warning(
'could not retrieve [{}]'.format(metadata_name))
213 msg.info(
'processing container [{}]'.format(obj.folderName()))
215 msg.info(
'container does not have folderName')
218 payloads = obj.payloadContainer()
219 payloads_sz = payloads.size()
220 if hasattr(payloads,
'at'):
224 for ii
in range(payloads_sz):
225 payloads.append(_tmp.at(ii))
227 for ii, payload
in zip(range(payloads_sz), payloads):
229 msg.info(
"**error** null-pointer ?")
233 sz = payload.name_size()
234 for idx
in range(sz):
235 chan = payload.chanNum(idx)
236 chan_name = payload.chanName(chan)
237 chan_names.append(chan_name)
240 sz = payload.iov_size()
241 for idx
in range(sz):
242 chan = payload.chanNum(idx)
243 iov_range = payload.iovRange(chan)
244 iov_start = iov_range.start()
245 iov_stop = iov_range.stop()
247 msg.info(
'({}, {}) => ({}, {}) valid={} runEvt={}'.format(
253 iov_start.isRunEvent()))
255 msg.info(
"... {} more".format(sz-9))
256 iovs.append((iov_start.run(), iov_start.event(),
257 iov_stop.run(), iov_stop.event(),
258 iov_start.isValid(), iov_start.isRunEvent(),
264 for idx
in range(sz):
265 chan = payload.chanNum(idx)
266 attr_list = payload.attributeList(chan)
268 for a
in list(
toiter(attr_list.begin(), attr_list.end())):
269 spec = a.specification()
270 a_type = spec.typeName()
271 if a_type.find(
'string') >= 0:
272 a_data = a.data[
'string']()
274 a_data = eval(a_data, {}, {})
279 a_data = a.data[a_type]()
280 attr_data.append((spec.name(), a_data))
281 attrs.append(dict(attr_data))
282 if len(attrs) == len(chan_names):
283 data.append(dict(zip(chan_names, attrs)))
287 data.append(attrs[0])
291 data.append(chan_names)
301 _info = self.
msg.info
302 _info(
"POOL2EI::beginFile")
316 root_files = list(ROOT.gROOT.GetListOfFiles())
317 if len(root_files) == 0:
318 _info(
'could not find correct ROOT file')
321 root_file = root_files[-1]
322 pool = root_file.Get(
"##Params")
326 pool_token = re.compile(
r'\[NAME=(?P<name>.*?)\]'
327 r'\[VALUE=(?P<value>.*?)\]').match
330 for i
in range(pool.GetEntries()):
331 if pool.GetEntry(i) > 0:
332 pool_string = pool.db_string.as_string()
334 n = pool_string.find(
'\0')
336 pool_string = pool_string[:n]
337 match = pool_token(pool_string)
340 d = match.groupdict()
341 params.append((d[
'name'], d[
'value']))
342 if d[
'name'].lower() ==
'fid':
343 guids.append(d[
'value'])
347 if len(self.
guids) > 0:
361 _info(
"Load trigger menu from TriggerMenu")
366 chainIds = e.chainIds()
367 chainNames = e.chainNames()
368 itemCtpIds = e.itemCtpIds()
369 itemNames = e.itemNames()
370 l1_menu = {name: id
for id, name
in
371 zip(itemCtpIds, itemNames)}
372 hlt_menu = {name: id
for id, name
in
373 zip(chainIds, chainNames)}
377 _info(
"Load trigger menu from TriggerMenuJson_L1 and "
378 "TriggerMenuJson_HLT")
380 for e
in self.
inputStore[
'TriggerMenuJson_L1']:
381 l1_menu_raw = json.loads(e.payload())
382 l1_items = l1_menu_raw[
'items']
383 l1_menu = {l1_key: l1_items[l1_key][
'ctpid']
384 for l1_key
in l1_items}
386 for e
in self.
inputStore[
'TriggerMenuJson_HLT']:
387 hlt_menu_raw = json.loads(e.payload())
388 hlt_chains = hlt_menu_raw[
'chains']
389 hlt_menu = {chain: hlt_chains[chain][
'counter']
390 for chain
in hlt_chains}
393 _info(
"Load trigger menu from /TRIGGER/LVL1/Menu and "
399 channels = [iov[6]
for iov
in l1menu_iovs]
400 names = [e[
'ItemName']
for e
in l1menu_info[0]]
401 l1_menu = {name: id
for name, id
in zip(names, channels)}
406 l2_menu = {entry[
'ChainName']: entry[
'ChainCounter']
407 for entry
in hltmenu_info[0]
408 if entry[
'ChainName'].startswith(
"L2_")}
409 ef_menu = {entry[
'ChainName']: entry[
'ChainCounter']
410 for entry
in hltmenu_info[0]
411 if entry[
'ChainName'].startswith(
"EF_")}
412 hlt_menu = {entry[
'ChainName']: entry[
'ChainCounter']
413 for entry
in hltmenu_info[0]
414 if entry[
'ChainName'].startswith(
"HLT_")}
416 _info(
"Trigger Menu not found")
425 _info(
"Load trigger config keys from TriggerMenu")
432 _info(
"Load trigger config keys from /TRIGGER/HLT/HltConfigKeys")
435 self.
inputStore,
'/TRIGGER/HLT/HltConfigKeys')
436 smk_l = [x[
'MasterConfigurationKey']
for x
in hltck_info]
437 for val, iov
in zip(smk_l, hltck_iovs):
438 self.
_iov.
add(
'SMK', val, iov[:4])
441 _info(
"Load trigger config keys from /TRIGGER/HLT/PrescaleKey")
445 hltpk_l = [x[
'HltPrescaleKey']
for x
in hltpk_info]
446 for val, iov
in zip(hltpk_l, hltpk_iovs):
447 self.
_iov.
add(
'HLTPSK', val, iov[:4])
450 _info(
"Load trigger config keys from /TRIGGER/LVL1/Lvl1ConfigKey")
453 self.
inputStore,
'/TRIGGER/LVL1/Lvl1ConfigKey')
454 l1pk_l = [x[
'Lvl1PrescaleConfigurationKey']
for x
in l1pk_info]
455 for val, iov
in zip(l1pk_l, l1pk_iovs):
456 self.
_iov.
add(
'L1PSK', val, iov[:4])
462 _info(
"Load AMITag, triggerStreamOfFile and project_name "
467 trigStream =
"Unknown"
472 amitag = tgi[
'AMITag']
473 _info(
"## AMITag: {}".format(amitag))
474 if 'triggerStreamOfFile' in tgi:
475 trigStream = tgi[
'triggerStreamOfFile']
476 _info(
"## triggerStreamOfFile: {}".format(trigStream))
477 if 'project_name' in tgi:
478 projName = tgi[
'project_name']
479 _info(
"## project_name: {}".format(projName))
486 beginGUID = self.
eipbof.BeginGUID()
487 beginGUID.startProcTime = int(time.time() * 1000)
488 beginGUID.AMITag = str(amitag)
489 beginGUID.trigStream = str(trigStream)
490 beginGUID.projName = str(projName)
491 beginGUID.guid = self.
guid
493 spb = beginGUID.SerializeToString()
494 self.
_eif_spb.write(struct.pack(
'<I', eic.EI_PROTO_BEGINGUID << 8 |
495 eic.EI_PROTO_MSGVER))
496 self.
_eif_spb.write(struct.pack(
'<I', len(spb)))
506 and l1_menu
is not None):
507 _info(
"Write trigger menu to output SPB")
508 tMenu = self.
eipbof.TriggerMenu()
511 tMenu.HLTPSK = hltpsk
514 menu = [
"{}:{}".format(d[k], k)
for k
in d]
515 return ";".join(menu)
517 if l1_menu
is not None and len(l1_menu) > 0:
518 tMenu.L1Menu = d2l(l1_menu)
519 if l2_menu
is not None and len(l2_menu) > 0:
520 tMenu.L2Menu = d2l(l2_menu)
521 if ef_menu
is not None and len(ef_menu) > 0:
522 tMenu.EFMenu = d2l(ef_menu)
523 if hlt_menu
is not None and len(hlt_menu) > 0:
524 tMenu.HLTMenu = d2l(hlt_menu)
527 if len(tMenu.L1Menu) > 0:
528 spb = tMenu.SerializeToString()
529 self.
_eif_spb.write(struct.pack(
'<I',
530 eic.EI_PROTO_TRIGGERMENU << 8 |
531 eic.EI_PROTO_MSGVER))
532 self.
_eif_spb.write(struct.pack(
'<I', len(spb)))
535 _info(
"Unable to write trigger menu to output SPB. "
536 "tMenu.L1Menu is empty")
582 _info = self.
msg.info
584 _info =
lambda *x:
None
585 _warning = self.
msg.warning
587 _info(
"POOL2EI::execute")
590 eventPB = self.
eipbof.EIEvent()
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()')
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))
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
707 _info(
"Retrieve TrigConfKeys from xAOD::TrigConfKeys")
708 tck = store.retrieve(
'xAOD::TrigConfKeys',
'TrigConfKeys')
710 evt_l1psk = tck.l1psk()
711 evt_hltpsk = tck.hltpsk()
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))
730 eventPB.SMK = evt_smk
731 eventPB.HLTPSK = evt_hltpsk
732 eventPB.L1PSK = evt_l1psk
743 res +=
"{0:032b}".format(e)[::-1]
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(
771 compressB64(v2b(trigL2_PH)),
772 compressB64(v2b(trigL2_PT)),
773 compressB64(v2b(trigL2_RS)))
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)))
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))
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)
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
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)
919 if key == tokenPB0.name:
920 _info(
"Already inserted key {0} in tokenPB0 "
921 "with value {1}".format(key, stk))
932 stk = store.proxy(dh).address().par().c_str()
935 _info(
"Updated ref token " + stk)
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]))
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)))
974 return StatusCode.Success