From ff896bd995cb701b0021e280af8140d95c61b81b Mon Sep 17 00:00:00 2001
From: Tadej Novak <tadej.novak@cern.ch>
Date: Sat, 29 Feb 2020 23:03:35 +0100
Subject: [PATCH] DoubleEventSelector: always treat ByteStream as primary

---
 .../src/DoubleEventSelectorAthenaPool.cxx     | 30 +++++++++++++++----
 .../src/DoubleEventSelectorAthenaPool.h       |  3 ++
 .../src/EventSelectorAthenaPool.cxx           | 11 +++++--
 3 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/Database/AthenaPOOL/EventSelectorAthenaPool/src/DoubleEventSelectorAthenaPool.cxx b/Database/AthenaPOOL/EventSelectorAthenaPool/src/DoubleEventSelectorAthenaPool.cxx
index ca22de7b5cf..139a5a3154f 100644
--- a/Database/AthenaPOOL/EventSelectorAthenaPool/src/DoubleEventSelectorAthenaPool.cxx
+++ b/Database/AthenaPOOL/EventSelectorAthenaPool/src/DoubleEventSelectorAthenaPool.cxx
@@ -39,6 +39,9 @@ StatusCode DoubleEventSelectorAthenaPool::initialize()
   ATH_CHECK(EventSelectorAthenaPool::initialize());
 
   ATH_CHECK(m_secondarySelector.retrieve());
+  if (dynamic_cast<EventSelectorAthenaPool *>(&*(m_secondarySelector)) == nullptr) {
+    m_secondaryByteStream = true;
+  }
 
   return StatusCode::SUCCESS;
 }
@@ -175,12 +178,22 @@ StatusCode DoubleEventSelectorAthenaPool::recordAttributeList() const
   ATH_MSG_DEBUG("AttributeList size " << attrList.size());
   auto athAttrList = std::make_unique<AthenaAttributeList>(attrList);
 
-  // Fill the new attribute list from the primary file
-  ATH_CHECK(fillAttributeList(athAttrList.get(), "", false));
-
-  // Fill the new attribute list from the secondary file
-  ATH_MSG_DEBUG("Append secondary attribute list properties to the primary one with a suffix: " << m_secondaryAttrListSuffix.value());
-  ATH_CHECK(m_secondarySelector->fillAttributeList(athAttrList.get(), "_" + m_secondaryAttrListSuffix.value(), true));
+  // Decide what to do based on the type of secondary file
+  if (m_secondaryByteStream) {
+    // Always add ByteStream as primary input
+    ATH_CHECK(m_secondarySelector->fillAttributeList(athAttrList.get(), "", false));
+
+    // Then fill the new attribute list from the primary file
+    ATH_MSG_DEBUG("Append primary attribute list properties to the secondary one with a suffix: " << m_secondaryAttrListSuffix.value());
+    ATH_CHECK(fillAttributeList(athAttrList.get(), "_" + m_secondaryAttrListSuffix.value(), true));
+  } else {
+    // Fill the new attribute list from the primary file
+    ATH_CHECK(fillAttributeList(athAttrList.get(), "", false));
+
+    // Fill the new attribute list from the secondary file
+    ATH_MSG_DEBUG("Append secondary attribute list properties to the primary one with a suffix: " << m_secondaryAttrListSuffix.value());
+    ATH_CHECK(m_secondarySelector->fillAttributeList(athAttrList.get(), "_" + m_secondaryAttrListSuffix.value(), true));
+  }
 
   // Add info about secondary input
   athAttrList->extend("hasSecondaryInput", "bool");
@@ -235,6 +248,11 @@ void DoubleEventSelectorAthenaPool::handle(const Incident& inc)
       msg(MSG::DEBUG) << "SourceID: " << source.first << " active events: " << source.second << endmsg;
   }
 
+  // Nothing to do if secondary event selector is ByteStream
+  if (m_secondaryByteStream) {
+    return;
+  }
+
   // Secondary guid
   SG::SourceID fid2;
   SG::DataProxy* dp2 = sg->proxy(ClassID_traits<DataHeader>::ID(), "SecondaryEventSelector", true);
diff --git a/Database/AthenaPOOL/EventSelectorAthenaPool/src/DoubleEventSelectorAthenaPool.h b/Database/AthenaPOOL/EventSelectorAthenaPool/src/DoubleEventSelectorAthenaPool.h
index 0c379ae3ecf..2213ce0b629 100644
--- a/Database/AthenaPOOL/EventSelectorAthenaPool/src/DoubleEventSelectorAthenaPool.h
+++ b/Database/AthenaPOOL/EventSelectorAthenaPool/src/DoubleEventSelectorAthenaPool.h
@@ -64,6 +64,9 @@ private:
   ServiceHandle<ISecondaryEventSelector> m_secondarySelector{this, "SecondaryEventSelector", "SecondaryEventSelector", ""};
 
   Gaudi::Property<std::string> m_secondaryAttrListSuffix{this, "SecondaryAttrListSuffix", "secondary", ""};
+
+  // Cache if secondary selector is ByteStream
+  bool m_secondaryByteStream{};
 };
 
 #endif
diff --git a/Database/AthenaPOOL/EventSelectorAthenaPool/src/EventSelectorAthenaPool.cxx b/Database/AthenaPOOL/EventSelectorAthenaPool/src/EventSelectorAthenaPool.cxx
index 10f3d60b410..29be28acd0d 100644
--- a/Database/AthenaPOOL/EventSelectorAthenaPool/src/EventSelectorAthenaPool.cxx
+++ b/Database/AthenaPOOL/EventSelectorAthenaPool/src/EventSelectorAthenaPool.cxx
@@ -1000,9 +1000,14 @@ StatusCode EventSelectorAthenaPool::fillAttributeList(coral::AttributeList *attr
       (*attrList)[iter.tokenName() + suffix].data<std::string>() = iter->toString();
       ATH_MSG_DEBUG("record AthenaAttribute, name = " << iter.tokenName() + suffix << " = " << iter->toString() << ".");
    }
-   attrList->extend("eventRef" + suffix, "string");
-   (*attrList)["eventRef" + suffix].data<std::string>() = m_headerIterator->eventRef().toString();
-   ATH_MSG_DEBUG("record AthenaAttribute, name = eventRef" + suffix + " = " <<  m_headerIterator->eventRef().toString() << ".");
+
+   std::string eventRef = "eventRef";
+   if (m_isSecondary.value()) {
+      eventRef.append(suffix);
+   }
+   attrList->extend(eventRef, "string");
+   (*attrList)[eventRef].data<std::string>() = m_headerIterator->eventRef().toString();
+   ATH_MSG_DEBUG("record AthenaAttribute, name = " + eventRef + " = " <<  m_headerIterator->eventRef().toString() << ".");
 
    if (copySource) {
       const coral::AttributeList& sourceAttrList = m_headerIterator->currentRow().attributeList();
-- 
GitLab