314 def _do_peeking(self, peek_evt_data=False):
315 """ the real function doing all the work of peeking at the input file
316 @return a dict of peeked-at data
319 import AthenaPython.PyAthena
as PyAthena
320 _info = self.msg.info
321 _error= self.msg.error
323 def _get_detdescr_tags(evt_type):
324 ddt = evt_type.get_detdescr_tags().
split()
327 ddt = dict(zip(ddt[0::2],
333 store = self.inputStore
334 esi_keys = store.keys(
'EventStreamInfo')
337 if len(esi_keys) >= 1:
338 sg_key = esi_keys[-1]
340 stream_names = esi_keys[:]
341 for sg_key
in esi_keys:
342 esi = store.retrieve(
'EventStreamInfo', sg_key)
343 _info(
'=== [EventStreamInfo#%s] ===', sg_key)
344 nentries += esi.getNumberOfEvents()
346 evt_types = PyAthena.EventStreamInfo.evt_types(esi)
347 if len(evt_types) > 0:
348 evt_type = evt_types[0]
349 peeked_data[
'evt_type'] = evt_type.bit_mask
350 ddt = _get_detdescr_tags(evt_type)
351 peeked_data[
'det_descr_tags'] = ddt
352 from past.builtins
import long
353 peeked_data[
'mc_channel_number'] = [long(evt_type.mc_channel_number())]
355 def _make_item_list(item):
358 _typename = store._pyclidsvc.typename
361 item_list = esi.item_list()
362 item_list =
list(map(_make_item_list, item_list))
363 peeked_data[
'eventdata_items'] = item_list
365 peeked_data[
'lumi_block'] = esi.lumi_blocks()
366 peeked_data[
'run_number'] = esi.run_numbers()
368 peeked_data[
'stream_names'] = esi.processing_tags()
370 if not peeked_data[
'stream_names']:
371 stream_names = [sg_versioned_key(s).key
for s
in stream_names]
372 peeked_data[
'stream_names'] =
list(
set(stream_names))
376 if len(esi.run_numbers()) == 0:
377 bsmd_keys = store.keys(
"ByteStreamMetadataContainer")
378 if len(bsmd_keys) == 1:
379 bsmd = store[bsmd_keys[0]][0]
380 peeked_data[
'lumi_block'] = [bsmd.getLumiBlock()]
381 peeked_data[
'run_number'] = [bsmd.getRunNumber()]
383 for md
in bsmd.getFreeMetaDataStrings():
384 if md.startswith(
'Event type:'):
387 if 'is sim' in md: v.append(
'IS_SIMULATION')
388 else: v.append(
'IS_DATA')
389 if 'is atlas' in md: v.append(
'IS_ATLAS')
390 else: v.append(
'IS_TESTBEAM')
391 if 'is physics' in md: v.append(
'IS_PHYSICS')
392 else: v.append(
'IS_CALIBRATION')
393 bs_metadata[k] = tuple(v)
394 elif md.startswith(
'GeoAtlas:'):
396 v = md.split(
'GeoAtlas:')[1].strip()
398 elif md.startswith(
'IOVDbGlobalTag:'):
400 v = md.split(
'IOVDbGlobalTag:')[1].strip()
406 peeked_data[
'evt_type'] = bs_metadata.get(
'evt_type', [])
407 peeked_data[
'geometry'] = bs_metadata.get(
'geometry',
None)
408 peeked_data[
'conditions_tag'] = bs_metadata.get(
'conditions_tag',
None)
409 peeked_data[
'bs_metadata'] = bs_metadata
417 root_files =
list(ROOT.gROOT.GetListOfFiles())
418 root_files = [root_file
for root_file
in root_files
419 if root_file.GetName().
count(self.infname)]
420 if len(root_files)==1:
421 root_file = root_files[0]
422 data_hdr = root_file.Get(
"POOLContainer")
424 data_hdr = root_file.Get(
"POOLContainer_DataHeader")
425 nentries = data_hdr.GetEntriesFast()
if bool(data_hdr) \
428 _info(
'could not find correct ROOT file (looking for [%s])',
433 peeked_data[
'nentries'] = nentries
439 root_files =
list(ROOT.gROOT.GetListOfFiles())
440 root_files = [root_file
for root_file
in root_files
441 if root_file.GetName().
count(self.infname)]
442 if len(root_files)==0:
443 _info(
'could not find correct ROOT file (looking for [%s])',
447 root_file = root_files[0]
448 pool = root_file.Get(
"##Params")
452 pool_token = re.compile(
r'[\[]NAME=(?P<name>.*?)[\]]'
453 r'[\[]VALUE=(?P<value>.*?)[\]]').match
455 for i
in range(pool.GetEntries()):
456 if pool.GetEntry(i)>0:
457 match = pool_token(pool.db_string)
460 d = match.groupdict()
461 params.append((d[
'name'], d[
'value']))
462 if d[
'name'].lower() ==
'fid':
467 peeked_data[
'file_guid'] = guid
470 metadata_items = [(self.inputStore._pyclidsvc.typename(p.clID()),
472 for p
in self.inputStore.proxies()]
473 peeked_data[
'metadata_items'] = metadata_items
475 def maybe_get(o, idx, default=None):
486 def mergeMultipleDict(inDicts):
489 for k,o
in six.iteritems(d):
499 for k
in self.inputStore.
keys(
'IOVMetaDataContainer'):
500 v = self.process_metadata(self.inputStore, k)
501 metadata[k] = maybe_get(v, -1)
502 peeked_data[
'metadata'] = metadata
506 if self.metaStore.
contains(
'IOVMetaDataContainer',
'/TagInfo'):
507 v = self.process_metadata(self.metaStore,
'/TagInfo')
508 taginfo = mergeMultipleDict(v)
510 if '/TagInfo' in metadata:
511 taginfo = metadata[
'/TagInfo'].
copy()
513 self._old_file_flag =
True
517 peeked_data[
'det_descr_tags'] = ddt
518 peeked_data[
'geometry'] = ddt.get(
'GeoAtlas',
None)
519 peeked_data[
'conditions_tag'] = ddt.get(
'IOVDbGlobalTag',
None)
520 peeked_data[
'tag_info'] = taginfo
522 peeked_data[
'det_descr_tags'] = taginfo
523 peeked_data[
'geometry'] = taginfo.get(
'GeoAtlas',
None)
524 peeked_data[
'conditions_tag'] = taginfo.get(
'IOVDbGlobalTag',
None)
525 peeked_data[
'beam_type'] = [taginfo.get(
'beam_type',
'N/A')]
526 peeked_data[
'beam_energy']= [maybe_float(taginfo.get(
'beam_energy',
529 if 'geometry' not in peeked_data:
530 peeked_data[
'geometry'] =
None
531 if 'conditions_tag' not in peeked_data:
532 peeked_data[
'conditions_tag'] =
None
533 if 'det_descr_tags' not in peeked_data:
534 peeked_data[
'det_descr_tags'] = {}
537 if not self._begin_run_flag:
538 if taginfo
and taginfo.get(
'project_name',
None) ==
'IS_SIMULATION':
539 peeked_data[
'evt_type'] = (
'IS_SIMULATION',
'IS_ATLAS',
'IS_PHYSICS')
540 if '/Simulation/Parameters' in metadata:
541 peeked_data[
'run_number'] = [metadata.get(
'/Simulation/Parameters').
get(
'RunNumber',
None)]
544 if peek_evt_data
is False:
550 store = self.evtStore
551 evt_info_keys = store.keys(
'EventInfo')
552 if len(evt_info_keys) != 1:
553 _info(
'more than one EventInfo: %s', evt_info_keys)
554 _info(
' ==> we\'ll use [%s]', evt_info_keys[0])
555 sg_key = evt_info_keys[0]
556 ei = store.retrieve(
'EventInfo', sg_key)
557 _info(
'=== [EventInfo#%s] ===', sg_key)
560 dh_keys = [k
for k
in store.keys(
'DataHeader')
562 if not k.startswith(
'[DB=')]
563 if len(dh_keys) != 1:
564 _error(
'more than 1 DataHeader key after filtering: %s', dh_keys)
565 _error(
'content of store: %s', store.keys(
'DataHeader'))
566 raise RuntimeError(
'more than one DataHeader key')
569 _info(
'=== [DataHeader#%s] ===', sg_key)
570 dh = store.retrieve(
'DataHeader', sg_key)
572 def _make_item_list(dhe):
574 clid = dhe.getPrimaryClassID()
575 _typename = store._pyclidsvc.typename
579 if hasattr(dh,
'at'):
581 for ii
in range(len(dh)):
582 dhes.append(dh.at(ii))
585 dhes =
list(dh.elements())
588 for i,dhe
in enumerate(dhes):
590 clid = dhe.getPrimaryClassID()
591 _typename = store._pyclidsvc.typename
596 except Exception
as err:
597 self.msg.
info(
"no typename for clid [%s] (%s)", clid, err)
598 item_list.append((
str(clid), sgkey))
601 evt_type = ei.event_type()
602 det_descr_tags = _get_detdescr_tags(evt_type)
605 'run_number': [eid.run_number()],
606 'evt_number': [eid.event_number()],
608 'evt_type': evt_type.bit_mask,
609 'det_descr_tags': det_descr_tags,
610 'geometry': det_descr_tags.get(
'GeoAtlas',
None),
611 'conditions_tag': det_descr_tags.get(
'IOVDbGlobalTag',
None),
612 'lumi_block': [eid.lumi_block()],
613 'stream_names': [dh.getProcessTag()],
614 'eventdata_items': item_list,
615 'beam_type': [det_descr_tags.get(
'beam_type',
'N/A')],
616 'beam_energy': [maybe_float(det_descr_tags.get(
'beam_energy',
620 trigger_info= ei.trigger_info()
621 stream_tags = trigger_info.streamTags()
if trigger_info
else []
623 for st
in stream_tags:
626 obeys_lbk=
bool(st.obeysLumiblock())
627 stags.append(dict(stream_type=st_type,
629 obeys_lbk=obeys_lbk))
630 peeked_data[
'stream_tags'] = stags
633 if self._old_file_flag
or 1:
636 metadata_items = [(self.inputStore._pyclidsvc.typename(p.clID()),
638 for p
in self.inputStore.proxies()]
639 peeked_data[
'metadata_items'] = metadata_items
641 for k
in self.inputStore.
keys(
'IOVMetaDataContainer'):
642 v = self.process_metadata(self.inputStore, k)
643 metadata[k] = maybe_get(v, -1)
644 peeked_data[
'metadata'] = metadata
648 if self.metaStore.
contains(
'IOVMetaDataContainer',
'/TagInfo'):
649 v = self.process_metadata(self.metaStore,
'/TagInfo')
650 taginfo = mergeMultipleDict(v)
653 atlas_release = metadata.get(
'/TagInfo', taginfo)
654 atlas_release = atlas_release.get(
'AtlasRelease',
655 taginfo[
'AtlasRelease'])
656 taginfo[
'AtlasRelease'] = atlas_release
657 peeked_data[
'det_descr_tags'] = taginfo
658 peeked_data[
'tag_info'] = taginfo
662 ddt = peeked_data[
'det_descr_tags']
663 peeked_data[
'geometry'] = ddt.get(
'GeoAtlas',
None)
664 peeked_data[
'conditions_tag'] = ddt.get(
'IOVDbGlobalTag',
None)
667 peeked_data[
'beam_type']= [ddt.get(
'beam_type',
'N/A')]
668 beam_ene = maybe_float(ddt.get(
'beam_energy',
'N/A'))
669 peeked_data[
'beam_energy']=[beam_ene]