From 1cee99c6b7aaf513a6280895b74393cde65d5461 Mon Sep 17 00:00:00 2001
From: scott snyder <snyder@bnl.gov>
Date: Wed, 7 Oct 2020 03:36:25 +0200
Subject: [PATCH] ByteStreamCnvSvc: Byte stream metadata adjustments.

Don't crash in ByteStreamEventStorageOutputSvc if there's no
bytestream metadata.  (Can happen for example if we're reading pool
and writing bytestream.)

In RDP_ByteStream_jobOptions, add EventInfo as an additional dependency
of StreamBS.  (Needed for SCT_RawDataByteStreamCnv tests.)
---
 .../share/RDP_ByteStream_jobOptions.py                 |  3 ++-
 .../src/ByteStreamEventStorageOutputSvc.cxx            | 10 +++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/Event/ByteStreamCnvSvc/share/RDP_ByteStream_jobOptions.py b/Event/ByteStreamCnvSvc/share/RDP_ByteStream_jobOptions.py
index dc0cffe0722..8d3ec14abea 100644
--- a/Event/ByteStreamCnvSvc/share/RDP_ByteStream_jobOptions.py
+++ b/Event/ByteStreamCnvSvc/share/RDP_ByteStream_jobOptions.py
@@ -25,7 +25,8 @@ from AthenaServices.AthenaServicesConf import AthenaOutputStream
 topSequence += AthenaOutputStream(
     "StreamBS",
     EvtConversionSvc = "ByteStreamCnvSvc",
-    OutputFile = "ByteStreamRDP_OutputSvc"
+    OutputFile = "ByteStreamRDP_OutputSvc",
+    ExtraInputs = [( 'xAOD::EventInfo' , 'StoreGateSvc+EventInfo' ) ],
     )
 # ByteStreamCnvSvc is an input CnvSvc now. 
 EventPersistencySvc = svcMgr.EventPersistencySvc
diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.cxx b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.cxx
index 3ccda05b67d..b19f9a571fd 100644
--- a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.cxx
+++ b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.cxx
@@ -291,12 +291,12 @@ ByteStreamEventStorageOutputSvc::io_reinit() {
 
 const ByteStreamMetadata *
 ByteStreamEventStorageOutputSvc::getByteStreamMetadata(
-    const EventContext* ctx) {
-  const ByteStreamMetadataContainer* metaDataCont = ctx == nullptr
-      ? SG::get(m_byteStreamMetadataKey)
-      : SG::get(m_byteStreamMetadataKey, *ctx);
+    const EventContext* ctx)
+{
+  if (!ctx) ctx = &Gaudi::Hive::currentContext();
+  SG::ReadHandle<ByteStreamMetadataContainer> metaDataCont (m_byteStreamMetadataKey, *ctx);
 
-  if (metaDataCont == nullptr) return nullptr;
+  if (!metaDataCont.isValid()) return nullptr;
 
   if (metaDataCont->size() > 1)
     ATH_MSG_WARNING("Multiple run parameters in MetaDataStore. "
-- 
GitLab