Skip to content
Snippets Groups Projects
Commit ebfb4d26 authored by Gerhard Raven's avatar Gerhard Raven
Browse files

Move code dealing with old .tck.json files to LHCb

parent 006586e2
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!733Adapt to LHCb!3528 - Enforce use of an encoding/decoding key (TCK) in all Hlt encoders/decoders, do not use online-reserved bits in SourceID, remove explicit mention of 'packed' locations, enable 'stable' persist reco locations
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
# granted to it by virtue of its status as an Intergovernmental Organization # # granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. # # or submit itself to any jurisdiction. #
############################################################################### ###############################################################################
import re, click, json import re
import logging
import click
from PyConf.Algorithms import ( from PyConf.Algorithms import (
FilterDecays, FilterDecays,
...@@ -22,51 +24,9 @@ from PyConf.application import ( ...@@ -22,51 +24,9 @@ from PyConf.application import (
from Hlt2Conf.algorithms import make_dvalgorithm from Hlt2Conf.algorithms import make_dvalgorithm
from PyConf.components import force_location from PyConf.components import force_location
from Gaudi.Configuration import WARNING from Gaudi.Configuration import WARNING
from .utils import load_file from GaudiConf import reading
# needed for backwards compatibility with old style .tck.json files log = logging.getLogger(__name__)
__lookup = {
1006:
"LHCb::RecSummary",
1541:
"KeyedContainer<LHCb::CaloCluster,Containers::KeyedObjectManager<Containers::hashmap> >",
1542:
"KeyedContainer<LHCb::CaloDigit,Containers::KeyedObjectManager<Containers::hashmap> >",
1543:
"KeyedContainer<LHCb::CaloAdc,Containers::KeyedObjectManager<Containers::hashmap> >",
1550:
"KeyedContainer<LHCb::Event::v1::Track,Containers::KeyedObjectManager<Containers::hashmap> >",
1551:
"KeyedContainer<LHCb::CaloHypo,Containers::KeyedObjectManager<Containers::hashmap> >",
1552:
"KeyedContainer<LHCb::ProtoParticle,Containers::KeyedObjectManager<Containers::hashmap> >",
1553:
"KeyedContainer<LHCb::RecVertex,Containers::KeyedObjectManager<Containers::hashmap> >",
1554:
"KeyedContainer<LHCb::TwoProngVertex,Containers::KeyedObjectManager<Containers::hashmap> >",
1555:
"KeyedContainer<LHCb::WeightsVector,Containers::KeyedObjectManager<Containers::hashmap> >",
1560:
"LHCb::Relation1D<LHCb::Particle,LHCb::VertexBase>",
1561:
"KeyedContainer<LHCb::RichPID,Containers::KeyedObjectManager<Containers::hashmap> >",
1562:
"LHCb::RelationWeighted1D<LHCb::ProtoParticle,LHCb::MCParticle,double>",
1571:
"KeyedContainer<LHCb::MuonPID,Containers::KeyedObjectManager<Containers::hashmap> >",
1581:
"KeyedContainer<LHCb::Particle,Containers::KeyedObjectManager<Containers::hashmap> >",
1582:
"KeyedContainer<LHCb::Vertex,Containers::KeyedObjectManager<Containers::hashmap> >",
1583:
"KeyedContainer<LHCb::FlavourTag,Containers::KeyedObjectManager<Containers::hashmap> >",
1584:
"LHCb::Relation1D<LHCb::Particle,LHCb::RelatedInfoMap>",
1591:
"LHCb::Relation1D<LHCb::Particle,int>",
1660:
"LHCb::Relation1D<LHCb::Particle,LHCb::MCParticle>",
}
def set_filter(name, code, dec_reports): def set_filter(name, code, dec_reports):
...@@ -197,6 +157,48 @@ def define_fsr_writer(options): ...@@ -197,6 +157,48 @@ def define_fsr_writer(options):
return algs return algs
def __configure_unpacking(manifest, process, stream, simulation):
unpack_raw_event = reading.unpack_rawevent(
bank_types=['ODIN', 'DstData', 'HltDecReports'],
process=process,
stream=stream,
output_level=5,
configurables=False)
if process == "Spruce":
TES_ROOT = '/Event/Spruce'
else:
TES_ROOT = '/Event/HLT2'
reading_algs = []
locations = reading.make_locations(manifest, TES_ROOT)
reading_algs += [unpack_raw_event]
packed_decoder = reading.decoder(
process=process, stream=stream, output_level=5, configurables=False)
reading_algs += [packed_decoder]
mc_unpackers = []
if simulation:
mc_unpackers = reading.mc_unpackers(
process=process, configurables=False)
reading_algs += mc_unpackers
reading_algs += reading.unpackers(
locations,
manifest,
packed_decoder.OutputBuffers,
mc=mc_unpackers,
process=process,
output_level=5,
configurables=False)
# TODO: return a dictionary of handles to the data instead!!!
return reading_algs
def unpack_locations(options, unpack_only_mc): def unpack_locations(options, unpack_only_mc):
""" """
Configures algorithms for reading HLT2/Spruce output. Location are found using stream as prefix. Configures algorithms for reading HLT2/Spruce output. Location are found using stream as prefix.
...@@ -215,69 +217,29 @@ def unpack_locations(options, unpack_only_mc): ...@@ -215,69 +217,29 @@ def unpack_locations(options, unpack_only_mc):
stream = options.stream stream = options.stream
reading_algs = [] reading_algs = []
if process == "Spruce":
TES_ROOT = '/Event/Spruce'
else:
TES_ROOT = '/Event/HLT2'
if unpack_only_mc: if unpack_only_mc:
if options.simulation: if options.simulation:
reading_algs += reading.mc_unpackers( reading_algs += reading.mc_unpackers(
process=process, filtered_mc=False, configurables=False) process=process, filtered_mc=False, configurables=False)
else: else:
message = "Requested unpacking MC but simulation is set False. Check your DV options." message = 'Requested unpacking MC but simulation is set False. Check your DV options.'
click.echo( click.echo(
f"{click.style('WARNING', bold=True, fg='yellow')} {click.style(message, fg='white')}" f"{click.style('WARNING', bold=True, fg='yellow')} {click.style(message, fg='white')}"
) )
elif options.annsvc_config: elif options.annsvc_config:
# NOTE: this has _nothing_ to do with the ANNSvc # NOTE: this has _nothing_ to do with the ANNSvc
d = json.loads(load_file(options.annsvc_config)) # but unfortunately that's what the option is currently called...
ann = d.get("HltANNSvc/HltANNSvc", None) assert not options.input_manifest_file, "annsvc_config and input_manifest_file are mutually exclusive"
if ann is not None: log.warning(
# this is an old style .tck.json file -- adapt it on the fly 'deprecated option: \'annsvc_config\'. Please use \'input_manifest_file\' instead'
fix_prefix = lambda x, prefix: prefix + x.removeprefix(prefix + 'p') if x.startswith(prefix + 'p') else x )
manifest = { reading_algs += __configure_unpacking(
'PackedLocations': reading.load_manifest(options.annsvc_config), process, stream,
[(fix_prefix( options.simulation)
fix_prefix(loc, '/Event/Spruce/'), '/Event/HLT2/'), elif options.input_manifest_file:
__lookup[t % 10000]) reading_algs += __configure_unpacking(
for loc, t in ann['PackedObjectTypes'].items()] reading.load_manifest(options.input_manifest_file), process,
} stream, options.simulation)
else:
manifest = d
unpack_raw_event = reading.unpack_rawevent(
bank_types=['ODIN', 'DstData', 'HltDecReports'],
process=process,
stream=stream,
output_level=5,
configurables=False)
locations = reading.make_locations(manifest, TES_ROOT)
reading_algs += [unpack_raw_event]
packed_decoder = reading.decoder(
process=process,
stream=stream,
output_level=5,
configurables=False)
reading_algs += [packed_decoder]
mc_unpackers = []
if options.simulation:
mc_unpackers = reading.mc_unpackers(
process=process, configurables=False)
reading_algs += mc_unpackers
reading_algs += reading.unpackers(
locations,
manifest,
packed_decoder.OutputBuffers,
mc=mc_unpackers,
process=process,
output_level=5,
configurables=False)
return reading_algs return reading_algs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment