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 @@
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
import re, click, json
import re
import logging
import click
from PyConf.Algorithms import (
FilterDecays,
......@@ -22,51 +24,9 @@ from PyConf.application import (
from Hlt2Conf.algorithms import make_dvalgorithm
from PyConf.components import force_location
from Gaudi.Configuration import WARNING
from .utils import load_file
# needed for backwards compatibility with old style .tck.json files
__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>",
}
from GaudiConf import reading
log = logging.getLogger(__name__)
def set_filter(name, code, dec_reports):
......@@ -197,6 +157,48 @@ def define_fsr_writer(options):
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):
"""
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):
stream = options.stream
reading_algs = []
if process == "Spruce":
TES_ROOT = '/Event/Spruce'
else:
TES_ROOT = '/Event/HLT2'
if unpack_only_mc:
if options.simulation:
reading_algs += reading.mc_unpackers(
process=process, filtered_mc=False, configurables=False)
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(
f"{click.style('WARNING', bold=True, fg='yellow')} {click.style(message, fg='white')}"
)
elif options.annsvc_config:
# NOTE: this has _nothing_ to do with the ANNSvc
d = json.loads(load_file(options.annsvc_config))
ann = d.get("HltANNSvc/HltANNSvc", None)
if ann is not None:
# this is an old style .tck.json file -- adapt it on the fly
fix_prefix = lambda x, prefix: prefix + x.removeprefix(prefix + 'p') if x.startswith(prefix + 'p') else x
manifest = {
'PackedLocations':
[(fix_prefix(
fix_prefix(loc, '/Event/Spruce/'), '/Event/HLT2/'),
__lookup[t % 10000])
for loc, t in ann['PackedObjectTypes'].items()]
}
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)
# but unfortunately that's what the option is currently called...
assert not options.input_manifest_file, "annsvc_config and input_manifest_file are mutually exclusive"
log.warning(
'deprecated option: \'annsvc_config\'. Please use \'input_manifest_file\' instead'
)
reading_algs += __configure_unpacking(
reading.load_manifest(options.annsvc_config), process, stream,
options.simulation)
elif options.input_manifest_file:
reading_algs += __configure_unpacking(
reading.load_manifest(options.input_manifest_file), process,
stream, options.simulation)
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