From 1663f7cc5673c53beb12b9077e8032b371da3583 Mon Sep 17 00:00:00 2001
From: Frank Berghaus <frank.berghaus@cern.ch>
Date: Thu, 14 May 2020 15:25:16 +0000
Subject: [PATCH] Beautify the code in ByteStreamEVentInputSvc

Three things are combined into this commit: style, adoption of recent
C++ components, and some code de-duplication. The style updates
unfortunately makes this look like a full rewrite. Indentation was set
to use two spaces. The range based for loop was adopted where suitable.
Dynamically allocated memory was migrated to be managed using unique_ptr
were possible. The clearing of existing content in the Storegate was
abstrcted into a function.
---
 .../AthenaPoolTools/src/MetadataTest.cxx      |   8 +-
 .../AthenaPoolTools/src/MetadataTest.h        |   4 +-
 .../ByteStreamCnvSvc/ByteStreamInputSvc.h     |   4 +-
 .../share/BSEventSelector.ref                 |  22 +-
 .../share/TBEventSelector_jobOptions.py       |   2 +-
 .../src/ByteStreamEventStorageInputSvc.cxx    | 821 +++++++++---------
 .../src/ByteStreamEventStorageInputSvc.h      | 155 ++--
 .../src/ByteStreamEventStorageOutputSvc.cxx   | 684 ++++++++-------
 .../src/ByteStreamEventStorageOutputSvc.h     |  97 ++-
 .../src/ByteStreamMetadataTool.cxx            | 263 +++---
 .../src/ByteStreamMetadataTool.h              |  58 +-
 .../src/EventSelectorByteStream.cxx           |  35 -
 .../share/testROBDataProviderSvcMT.py         |   1 -
 .../ByteStreamData/ByteStreamMetadata.h       | 156 ++--
 .../ByteStreamMetadataContainer.h             |  11 +-
 Event/ByteStreamData/CMakeLists.txt           |   2 +-
 .../ByteStreamData/src/ByteStreamMetadata.cxx | 317 ++++---
 Event/ByteStreamTest/share/BadEvents.py       |   2 +-
 .../share/ByteStreamTestBadEvents.ref         | 591 -------------
 .../share/LArBadChannelReadTest.py            |   1 -
 .../share/LArDigits2Ntuple_jobOptions.py      |   2 +-
 .../share/LArCalib_DelayXtalk_jobOptions.py   |   2 +-
 .../LArCalib_Delay_OFC_Cali_jobOptions.py     |   2 +-
 .../LArCalib_Delay_OFC_splitter_jobOptions.py |   4 +-
 .../share/LArCalib_Delay_jobOptions.py        |   2 +-
 .../LArCalib_Delay_splitter_jobOptions.py     |   2 +-
 .../LArCalib_PedestalAutoCorr_jobOptions.py   |   2 +-
 .../share/LArCalib_Ramp_jobOptions.py         |   2 +-
 .../LArCalib_Ramp_splitter_jobOptions.py      |   2 +-
 .../LArMonTools/share/LArMonByteStream.py     |   2 +-
 .../LArCalibTest/share/DumpCaloBadChannels.py |   3 +-
 .../RecExCommission/share/skipBadEvents.py    |   2 +-
 .../RecExCommon/share/BSRead_config.py        |   1 -
 .../RecExTB_SCTMuonTile_2003_jobOptions.py    |   3 +-
 .../share/jobOptions_LaserTiming.py           |   3 +-
 .../share/jobOptions_NoiseCalib.py            |   2 +-
 .../TileTBRec/share/jobOptions_TileTB_CIS.py  |   2 +-
 37 files changed, 1430 insertions(+), 1842 deletions(-)

diff --git a/Database/AthenaPOOL/AthenaPoolTools/src/MetadataTest.cxx b/Database/AthenaPOOL/AthenaPoolTools/src/MetadataTest.cxx
index 02b31ef6a85..72d5a86c2a8 100755
--- a/Database/AthenaPOOL/AthenaPoolTools/src/MetadataTest.cxx
+++ b/Database/AthenaPOOL/AthenaPoolTools/src/MetadataTest.cxx
@@ -21,7 +21,7 @@ MetadataTest::MetadataTest(const std::string& name, ISvcLocator* pSvcLocator) :
    m_hkey("CutBookkeepers","MetaDataStore"),
    m_hinckey("IncompleteCutBookkeepers","MetaDataStore"),
    m_eihkey("StreamAOD","MetaDataStore"),
-   m_bshkey("ByteStreamMetadata","MetaDataStore"),
+   m_metadataStore("StoreGateSvc/MetaDataStore", name),
    m_esidone(false),
    m_inputstream("StreamAOD")
 {
@@ -40,7 +40,7 @@ StatusCode MetadataTest::start()
    ATH_CHECK( m_hkey.initialize() );  
    ATH_CHECK( m_hinckey.initialize() );  
    ATH_CHECK( m_eihkey.initialize() );
-   ATH_CHECK( m_bshkey.initialize() );
+   ATH_CHECK( m_metadataStore.retrieve() );
    m_esidone = false;
    return StatusCode::SUCCESS;
 }
@@ -85,8 +85,8 @@ StatusCode MetadataTest::execute()
 
      ATH_MSG_INFO("== BYTESTREAMMETADATACONTAINER CHECKS ==");
      // create handle, get pointer to object
-     SG::ReadMetaHandle<ByteStreamMetadataContainer> bskey(m_bshkey,this->getContext());
-     const ByteStreamMetadataContainer* bsmc(*bskey);
+     const ByteStreamMetadataContainer* bsmc = 
+       m_metadataStore->tryConstRetrieve<ByteStreamMetadataContainer>("ByteStreamMetadata");
      if (bsmc!=nullptr) {
        ATH_MSG_INFO("ByteStreamMetadataContainer size " << bsmc->size());
        for (auto it = bsmc->begin(); it != bsmc->end(); ++it) {
diff --git a/Database/AthenaPOOL/AthenaPoolTools/src/MetadataTest.h b/Database/AthenaPOOL/AthenaPoolTools/src/MetadataTest.h
index 536ce36a6bf..17aa2dd9497 100755
--- a/Database/AthenaPOOL/AthenaPoolTools/src/MetadataTest.h
+++ b/Database/AthenaPOOL/AthenaPoolTools/src/MetadataTest.h
@@ -27,6 +27,8 @@
 #include "xAODCutFlow/CutBookkeeperContainer.h"
 #include "EventInfo/EventStreamInfo.h"
 #include "ByteStreamData/ByteStreamMetadataContainer.h"
+#include "StoreGate/StoreGateSvc.h"
+#include "GaudiKernel/ServiceHandle.h"
 
 class MetadataTest : public AthAlgorithm {
 public:
@@ -43,7 +45,7 @@ private:
   SG::ReadMetaHandleKey<xAOD::CutBookkeeperContainer> m_hkey;
   SG::ReadMetaHandleKey<xAOD::CutBookkeeperContainer> m_hinckey;
   SG::ReadMetaHandleKey<EventStreamInfo> m_eihkey;
-  SG::ReadMetaHandleKey<ByteStreamMetadataContainer> m_bshkey;
+  ServiceHandle<StoreGateSvc> m_metadataStore;
 
   bool m_esidone;
   std::string m_inputstream;
diff --git a/Event/ByteStreamCnvSvc/ByteStreamCnvSvc/ByteStreamInputSvc.h b/Event/ByteStreamCnvSvc/ByteStreamCnvSvc/ByteStreamInputSvc.h
index 377473a07b9..fb7498dd310 100644
--- a/Event/ByteStreamCnvSvc/ByteStreamCnvSvc/ByteStreamInputSvc.h
+++ b/Event/ByteStreamCnvSvc/ByteStreamCnvSvc/ByteStreamInputSvc.h
@@ -40,7 +40,7 @@ public:
   virtual unsigned int currentEventStatus() const;
   virtual std::pair<long,std::string> getBlockIterator(const std::string /* file */);
   virtual void closeBlockIterator(bool);
-  virtual bool ready();
+  virtual bool ready() const;
   virtual StatusCode generateDataHeader(); 
   virtual long positionInBlock();
   virtual void validateEvent();
@@ -59,7 +59,7 @@ inline unsigned int ByteStreamInputSvc::currentEventStatus() const {
 // Virtual methods needed for file input
 inline std::pair<long,std::string> ByteStreamInputSvc::getBlockIterator(const std::string /* file */) {return std::make_pair(-1,"GUID");}
 inline void ByteStreamInputSvc::closeBlockIterator(bool) {}
-inline bool ByteStreamInputSvc::ready() {return false;}
+inline bool ByteStreamInputSvc::ready() const {return false;}
 inline StatusCode ByteStreamInputSvc::generateDataHeader() {return StatusCode::SUCCESS;}
 inline long ByteStreamInputSvc::positionInBlock() {return -1;} 
 inline void ByteStreamInputSvc::validateEvent() {}
diff --git a/Event/ByteStreamCnvSvc/share/BSEventSelector.ref b/Event/ByteStreamCnvSvc/share/BSEventSelector.ref
index a090d5ba63b..9a5cc37a2b3 100644
--- a/Event/ByteStreamCnvSvc/share/BSEventSelector.ref
+++ b/Event/ByteStreamCnvSvc/share/BSEventSelector.ref
@@ -1,21 +1,29 @@
-ByteStreamInputSvc  DEBUG Recorded ByteStreamMetadata in InputMetadataStore
-ByteStreamInputSvc  DEBUG  run parameters  =  
-ByteStreamInputSvc  DEBUG Number of Free meta data strings: 0
+ByteStreamAddre...   INFO Initializing ByteStreamAddressProviderSvc - package version ByteStreamCnvSvcBase-00-00-00
+ToolSvc.ByteStr...   INFO Initializing ToolSvc.ByteStreamMetadataTool - package version ByteStreamCnvSvc-00-00-00
+ByteStreamInputSvc  DEBUG Property update for OutputLevel : new value = 2
+ByteStreamInputSvc   INFO Initializing ByteStreamInputSvc - package version ByteStreamCnvSvc-00-00-00
+ByteStreamInputSvc  DEBUG Service base class initialized successfully
+ROBDataProviderSvc   INFO Initializing ROBDataProviderSvc - package version ByteStreamCnvSvcBase-00-00-00
+ByteStreamInputSvc  DEBUG ByteStreamMetadata:
+ByteStreamInputSvc  DEBUG Recorded ByteStreamMetadata in InputMetaDataStore
 ByteStreamInputSvc   INFO Picked valid file: /cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/TrigP1Test/data17_13TeV.00327265.physics_EnhancedBias.merge.RAW._lb0100._SFO-1._0001.1
 ByteStreamInputSvc  DEBUG nextEvent _above_ high water mark
 ByteStreamInputSvc  DEBUG Event Size 1038508
 ByteStreamInputSvc  DEBUG First word of the fragment aa1234aa
-ByteStreamInputSvc  DEBUG Format version 500
+ByteStreamInputSvc  DEBUG Format version500
+ByteStreamInputSvc  DEBUG Made an FullEventFragment from ES 0x15bd2000
 ByteStreamInputSvc  DEBUG switched to next event in slot INVALID
-ByteStreamInputSvc  DEBUG ByteStream File GUID:1C43C4AA-2555-E711-BB1F-02163E01794D
+ByteStreamInputSvc  DEBUG ByteStream File GUID:              1C43C4AA-2555-E711-BB1F-02163E01794D
 ByteStreamInputSvc  DEBUG ByteStream Event Position in File: 1324
+ByteStreamCnvSvc    DEBUG Property update for OutputLevel : new value = 2
 EventPersistenc...   INFO Added successfully Conversion service:ByteStreamCnvSvc
 ByteStreamInputSvc  DEBUG nextEvent _above_ high water mark
 ByteStreamInputSvc  DEBUG Event Size 1000648
 ByteStreamInputSvc  DEBUG First word of the fragment aa1234aa
-ByteStreamInputSvc  DEBUG Format version 500
+ByteStreamInputSvc  DEBUG Format version500
+ByteStreamInputSvc  DEBUG Made an FullEventFragment from ES 0x15cd0000
 ByteStreamInputSvc  DEBUG switched to next event in slot s: 0  e: 0
-ByteStreamInputSvc  DEBUG ByteStream File GUID:1C43C4AA-2555-E711-BB1F-02163E01794D
+ByteStreamInputSvc  DEBUG ByteStream File GUID:              1C43C4AA-2555-E711-BB1F-02163E01794D
 ByteStreamInputSvc  DEBUG ByteStream Event Position in File: 1039848
 ByteStreamInputSvc  DEBUG Calling ByteStreamInputSvc::stop()
 ByteStreamCnvSvc    DEBUG releasing all workers
diff --git a/Event/ByteStreamCnvSvc/share/TBEventSelector_jobOptions.py b/Event/ByteStreamCnvSvc/share/TBEventSelector_jobOptions.py
index af634cd1f0a..571741ecfed 100644
--- a/Event/ByteStreamCnvSvc/share/TBEventSelector_jobOptions.py
+++ b/Event/ByteStreamCnvSvc/share/TBEventSelector_jobOptions.py
@@ -21,7 +21,7 @@ svcMgr += ByteStreamCnvSvc()
 
 # Properties 
 EventSelector = svcMgr.EventSelector
-EventSelector.ByteStreamInputSvc     = "ByteStreamInputSvc"; 
+EventSelector.ByteStreamInputSvc = "ByteStreamInputSvc"; 
 EventPersistencySvc = svcMgr.EventPersistencySvc
 EventPersistencySvc.CnvServices += [ "ByteStreamCnvSvc" ]
 
diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx
index c96dc1fd64c..1b3dd397191 100644
--- a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx
+++ b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx
@@ -8,6 +8,7 @@
 #include "ByteStreamData/ByteStreamMetadataContainer.h"
 #include "ByteStreamCnvSvcBase/ByteStreamAddress.h"
 #include "EventStorage/pickDataReader.h"
+#include "EventStorage/DataReader.h"
 
 #include "GaudiKernel/IJobOptionsSvc.h"
 #include "GaudiKernel/Property.h"
@@ -32,140 +33,106 @@
 #include <unistd.h>
 
 
+/******************************************************************************/
 // Constructor.
-ByteStreamEventStorageInputSvc::ByteStreamEventStorageInputSvc(const std::string& name,
-		ISvcLocator* svcloc) : ByteStreamInputSvc(name, svcloc),
-	//m_totalEventCounter(0),
-	m_reader(0),
-        m_evtInFile(0),
-	m_sgSvc("StoreGateSvc", name),
-	m_mdSvc("StoreGateSvc/InputMetaDataStore", name),
-        m_robProvider("ROBDataProviderSvc", name),
-	m_sequential(false),
-	m_fileCount(0) {
-   declareProperty("FullFileName", m_vExplicitFile);
-   declareProperty("EnableSequential", m_sequential);
-   declareProperty("DumpFlag", m_dump = false);
-   declareProperty("WaitSecs", m_wait = 0);
-   declareProperty("ValidateEvent", m_valEvent = true);
-   declareProperty("ProcessBadEvent", m_procBadEvent = false); // Defunct property, backward compatibility only
-   declareProperty("MaxBadEvents", m_maxBadEvts = -1); // Defunct property, backward compatibility only
-
-   declareProperty("EventStore", m_sgSvc);
-   declareProperty("MetaDataStore", m_mdSvc);
-}
-//------------------------------------------------------------------------------
-ByteStreamEventStorageInputSvc::~ByteStreamEventStorageInputSvc() {
-  
-  delete m_reader; m_reader = 0;
+ByteStreamEventStorageInputSvc::ByteStreamEventStorageInputSvc(
+    const std::string& name, ISvcLocator* pSvcLocator)
+  : ByteStreamInputSvc(name, pSvcLocator)
+  , m_readerMutex()
+  , m_eventsCache()
+  , m_reader()
+  , m_evtOffsets()
+  , m_evtInFile(0)
+  , m_evtFileOffset(0)
+  , m_fileGUID("")
+  , m_storeGate    ("StoreGateSvc", name)
+  , m_inputMetadata("StoreGateSvc/InputMetaDataStore", name)
+  , m_robProvider  ("ROBDataProviderSvc", name)
+  , m_vExplicitFile(this, "FullFileName",          {}, "")
+  , m_sequential   (this, "EnableSequential",   false, "")
+  , m_dump         (this, "DumpFlag",           false, "Dump fragments")
+  , m_wait         (this, "WaitSecs",              0., "Seconds to wait if input is in wait state")
+  , m_valEvent     (this, "ValidateEvent",       true, "switch on check_tree when reading events")
+  , m_eventInfoKey (this, "EventInfoKey", "EventInfo", "Key of EventInfo in metadata store")
+{
+  assert(pSvcLocator != nullptr);
+
+  declareProperty("EventStore",    m_storeGate);
+  declareProperty("MetaDataStore", m_inputMetadata);
 }
-//------------------------------------------------------------------------------
-StatusCode ByteStreamEventStorageInputSvc::initialize() {
-   ATH_MSG_INFO("Initializing " << name() << " - package version " << PACKAGE_VERSION);
-   if (!ByteStreamInputSvc::initialize().isSuccess()) {
-      ATH_MSG_FATAL("Cannot initialize ByteStreamInputSvc base class.");
-      return(StatusCode::FAILURE);
-   }
-
-   // Retrieve InputMetaDataStore
-   if (!m_mdSvc.retrieve().isSuccess()) {
-      ATH_MSG_FATAL("Cannot get InputMetaDataStore.");
-      return(StatusCode::FAILURE);
-   }
-   if (!m_robProvider.retrieve().isSuccess()) {
-      ATH_MSG_FATAL("Cannot get rob data provider");
-      return(StatusCode::FAILURE);
-   }
-
-   // Check if defunct properties set, and give instructions
-   if (m_procBadEvent != false) ATH_MSG_WARNING("ProcessBadEvent property has been moved to EventSelector, please use svgMgr.EventSelector.ProcessBadEvent instead");
-   if (m_maxBadEvts != -1) ATH_MSG_WARNING("MaxBadEvents property has been moved to EventSelector, please use svgMgr.EventSelector.MaxBadEvents instead");
-
-   // Retrieve StoreGateSvc
-   if (!m_sgSvc.retrieve().isSuccess()) {
-      ATH_MSG_FATAL("Cannot get StoreGateSvc.");
-      return(StatusCode::FAILURE);
-   }
-
-   return(StatusCode::SUCCESS);
+
+
+/******************************************************************************/
+ByteStreamEventStorageInputSvc::~ByteStreamEventStorageInputSvc()
+{}
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageInputSvc::initialize()
+{
+  ATH_MSG_INFO("Initializing " << name() << " - package version " << PACKAGE_VERSION);
+
+  ATH_CHECK(ByteStreamInputSvc::initialize());
+  ATH_CHECK(m_inputMetadata.retrieve());
+  ATH_CHECK(m_storeGate.retrieve());
+  ATH_CHECK(m_robProvider.retrieve());
+
+  return(StatusCode::SUCCESS);
 }
-//________________________________________________________________________________
-StatusCode ByteStreamEventStorageInputSvc::stop() {
-   ATH_MSG_DEBUG("Calling ByteStreamInputSvc::stop()");
-   // close moved to EventSelector for explicit coupling with incident
-   //if (m_reader != 0) closeBlockIterator(false);
-   return(StatusCode::SUCCESS);
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageInputSvc::stop()
+{
+  ATH_MSG_DEBUG("Calling ByteStreamInputSvc::stop()");
+  // close moved to EventSelector for explicit coupling with incident
+  //if (m_reader != 0) closeBlockIterator(false);
+  return(StatusCode::SUCCESS);
 }
-//------------------------------------------------------------------------------
-StatusCode ByteStreamEventStorageInputSvc::finalize() {
-   // delete the old event
-  //   releaseCurrentEvent(); // destruction of service obj will clear it
-  
-   if (!m_sgSvc.release().isSuccess()) {
-      ATH_MSG_WARNING("Cannot release StoreGateSvc");
-   }
-   if (!m_robProvider.release().isSuccess()) {
-      ATH_MSG_WARNING("Cannot release rob data provider");
-   }
-   if (!m_mdSvc.release().isSuccess()) {
-      ATH_MSG_WARNING("Cannot release InputMetaDataStore");
-   }
-   return(ByteStreamInputSvc::finalize());
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageInputSvc::finalize() {
+
+  ATH_CHECK(m_storeGate.release());
+  ATH_CHECK(m_robProvider.release()); 
+  ATH_CHECK(m_inputMetadata.release());
+
+  return(ByteStreamInputSvc::finalize());
 }
-//------------------------------------------------------------------------------
-long ByteStreamEventStorageInputSvc::positionInBlock()
+
+
+/******************************************************************************/
+// Can't inline this because it is called via pointer to the base class
+long
+ByteStreamEventStorageInputSvc::positionInBlock()
 {
   return m_evtOffsets.size();
 }
-//------------------------------------------------------------------------------
-// Load freemetadata into store
-bool ByteStreamEventStorageInputSvc::loadMetadata()
-{
-  bool good = true;
 
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageInputSvc::loadMetadata()
+{
   // default goes into ByteStreamMetadata
-  std::bitset<64> word1;
-  std::bitset<64> word2;
-  for (unsigned int i=0; i<64; ++i) {
-     word1[i] = m_reader->detectorMask()[i];
-     word2[i] = m_reader->detectorMask()[i+64];
-  }
-  ByteStreamMetadata* metadata = new ByteStreamMetadata(m_reader->runNumber(), m_reader->eventsInFile(),
-	  m_reader->maxEvents(), m_reader->recEnable(), m_reader->triggerType(), word1.to_ulong(), word2.to_ulong(),
-	  m_reader->beamType(), m_reader->beamEnergy(), m_reader->GUID(), m_reader->stream(),
-	  m_reader->projectTag(), m_reader->lumiblockNumber(), m_reader->freeMetaDataStrings());
-  ByteStreamMetadataContainer* bsmdc = new ByteStreamMetadataContainer;
-  bsmdc->push_back(metadata);
-  StatusCode status = m_mdSvc->record(bsmdc, "ByteStreamMetadata");
-  if (!status.isSuccess()) {
-     delete metadata; metadata = 0;
-     ATH_MSG_WARNING("Unable to record Input MetaData for ByteStream");
-     good = false;
-  }
-  else ATH_MSG_DEBUG("Recorded ByteStreamMetadata in InputMetadataStore");
-
-  ATH_MSG_DEBUG(" run parameters  =  \n "
-     << " run number  " << m_reader->runNumber() << "\n"
-     << " max events  " << m_reader->maxEvents() << "\n"
-     << " rec enable  " << m_reader->recEnable() << "\n"
-     << " trigger_type " << m_reader->triggerType() << "\n"
-     << " detector mask  " << m_reader->detectorMask() << "\n"
-     << " beam type " << m_reader->beamType() << "\n"
-     << " beam energy " << m_reader->beamEnergy());
-
-  std::vector<std::string> vMetaData = m_reader->freeMetaDataStrings();
-  ATH_MSG_DEBUG("Number of Free meta data strings: " << vMetaData.size());
-  for (unsigned int i = 0; i < vMetaData.size(); ++i) {
-    ATH_MSG_DEBUG("MetaData[" << i << "]:" << vMetaData[i]);
-  }
+  auto bsmdc = std::make_unique<ByteStreamMetadataContainer>();
+  bsmdc->push_back(std::make_unique<ByteStreamMetadata>(*m_reader));
+  ATH_MSG_DEBUG("ByteStreamMetadata:\n" << *(bsmdc->front()));
 
-  return good;
+  return m_inputMetadata->record(std::move(bsmdc), "ByteStreamMetadata");
 }
 
-const RawEvent* ByteStreamEventStorageInputSvc::previousEvent() {
 
-  std::lock_guard<std::mutex> lock( m_readerMutex );
-  const EventContext context{ Gaudi::Hive::currentContext() };
+/******************************************************************************/
+const RawEvent*
+ByteStreamEventStorageInputSvc::previousEvent()
+{
+  std::lock_guard<std::mutex> lock(m_readerMutex);
+  const EventContext context{Gaudi::Hive::currentContext()};
 
   // Load data buffer from file
   char *buf;
@@ -174,19 +141,20 @@ const RawEvent* ByteStreamEventStorageInputSvc::previousEvent() {
     //get current event position (cast to long long until native tdaq implementation)
     m_evtInFile--;
     m_evtFileOffset = m_evtOffsets.at(m_evtInFile);
-    DRError ecode = m_reader->getData(eventSize,&buf,m_evtOffsets.at(m_evtInFile -1));
+    DRError ecode = m_reader->getData(eventSize, &buf, m_evtOffsets.at(m_evtInFile - 1));
+
     if (DRWAIT == ecode && m_wait > 0) {
       do {
         // wait for n seconds
         ATH_MSG_DEBUG("Waiting for input:  " << m_wait << " seconds");
-        int result = usleep((int)(m_wait*1000000));
+        int result = usleep(static_cast<int>(m_wait * 1e6));
         if (result != 0) {
           ATH_MSG_ERROR("System Error while running sleep");
-          return 0;
+          return nullptr;
         }
-      } while(m_reader->getData(eventSize,&buf,m_evtFileOffset) == DRWAIT);
+      } while(m_reader->getData(eventSize, &buf, m_evtFileOffset) == DRWAIT);
     } else if (DROK != ecode) {
-      ATH_MSG_ERROR("Error reading next event");
+      ATH_MSG_ERROR("Error reading previous event");
       throw ByteStreamExceptions::readError();
     }
     ATH_MSG_DEBUG("Event Size " << eventSize);
@@ -198,37 +166,39 @@ const RawEvent* ByteStreamEventStorageInputSvc::previousEvent() {
 
   EventCache* cache = m_eventsCache.get(context);
   // initialize before building RawEvent
-  releaseEvent( cache );
- 
+  cache->releaseEvent();
+
   // Use buffer to build FullEventFragment
   try {
-    buildFragment( cache, buf, eventSize, true);
+    buildFragment(cache, buf, eventSize, true);
   }
   catch (...) {
     // rethrow any exceptions
     throw;
   }
 
-  if ( cache->rawEvent == 0 ) {
+  if (cache->rawEvent == nullptr) {
     ATH_MSG_ERROR("Failure to build fragment");
-    return 0;
+    return nullptr;
   }
 
   // Set it for the data provider
-  m_robProvider->setNextEvent(context, cache->rawEvent);
+  m_robProvider->setNextEvent(context, cache->rawEvent.get());
   m_robProvider->setEventStatus(context, cache->eventStatus);
 
   // dump
   if (m_dump) {
-    DumpFrags::dump( cache->rawEvent );
+    DumpFrags::dump(cache->rawEvent.get());
   }
-  ATH_MSG_DEBUG( "switched to previous event in slot " << context );
-  return( cache->rawEvent );
-  
+  ATH_MSG_DEBUG( "switched to previous event in slot " << context);
+  return(cache->rawEvent.get());
 }
-//------------------------------------------------------------------------------
+
+
+/******************************************************************************/
 // Read the next event.
-const RawEvent* ByteStreamEventStorageInputSvc::nextEvent() {
+const RawEvent*
+ByteStreamEventStorageInputSvc::nextEvent() {
 
   std::lock_guard<std::mutex> lock( m_readerMutex );
   const EventContext context{ Gaudi::Hive::currentContext() };
@@ -239,418 +209,481 @@ const RawEvent* ByteStreamEventStorageInputSvc::nextEvent() {
   if (readerReady()) {
     DRError ecode;
     // Check if have moved back from high water mark
-    m_evtInFile ++; // increment iterator
+    m_evtInFile++; // increment iterator
     if (m_evtInFile+1 > m_evtOffsets.size()) { 
       //get current event position (cast to long long until native tdaq implementation)
       ATH_MSG_DEBUG("nextEvent _above_ high water mark");
-      m_evtFileOffset = (long long)m_reader->getPosition();
+      m_evtFileOffset = static_cast<long long>(m_reader->getPosition());
       m_evtOffsets.push_back(m_evtFileOffset);
-      ecode = m_reader->getData(eventSize,&buf);
-    }
-
-    else {
+      ecode = m_reader->getData(eventSize, &buf);
+    } else {
       // Load from previous offset
       ATH_MSG_DEBUG("nextEvent below high water mark");
-      m_evtFileOffset = m_evtOffsets.at( m_evtInFile-1 );
-      ecode = m_reader->getData( eventSize, &buf, m_evtFileOffset );
+      m_evtFileOffset = m_evtOffsets.at(m_evtInFile - 1);
+      ecode = m_reader->getData(eventSize, &buf, m_evtFileOffset);
     }
 
     if (DRWAIT == ecode && m_wait > 0) {
       do {
         // wait for n seconds
         ATH_MSG_DEBUG("Waiting for input:  " << m_wait << " seconds");
-        int result = usleep((int)(m_wait*1000000));
+        int result = usleep(static_cast<int>(m_wait * 1e6));
         if (result != 0) {
           ATH_MSG_ERROR("System Error while running sleep");
           return 0;
         }
-      } while(m_reader->getData( eventSize, &buf ) == DRWAIT);
+      } while(m_reader->getData(eventSize, &buf) == DRWAIT);
     } else if (DROK != ecode) {
       ATH_MSG_ERROR("Error reading next event");
       throw ByteStreamExceptions::readError();
     }
     ATH_MSG_DEBUG("Event Size " << eventSize);
-  }
-  else {
+
+  } else {
     ATH_MSG_ERROR("DataReader not ready. Need to getBlockIterator first");
     return 0;
   }
+
   EventCache* cache = m_eventsCache.get(context);
 
   // initialize before building RawEvent
-  releaseEvent( cache );
- 
+  cache->releaseEvent();
+
   // Use buffer to build FullEventFragment
   try {
-    buildFragment( cache,  buf, eventSize, true );
+    buildFragment(cache, buf, eventSize, true);
   }
   catch (...) {
     // rethrow any exceptions
     throw;
   }
 
-  if ( cache->rawEvent == 0 ) {
+  if (cache->rawEvent == nullptr) {
     ATH_MSG_ERROR("Failure to build fragment");
-    return 0;
+    return nullptr;
   }
 
-  
   // Set it for the data provider
-  m_robProvider->setNextEvent( context, cache->rawEvent );
-  m_robProvider->setEventStatus( context, cache->eventStatus );
+  m_robProvider->setNextEvent(context, cache->rawEvent.get());
+  m_robProvider->setEventStatus(context, cache->eventStatus);
 
   //++m_totalEventCounter;
 
   // dump
   if (m_dump) {
-    DumpFrags::dump( cache->rawEvent );
+    DumpFrags::dump(cache->rawEvent.get());
   }
-  ATH_MSG_DEBUG( "switched to next event in slot " << context );
-  return( cache->rawEvent );
+  ATH_MSG_DEBUG("switched to next event in slot " << context);
+  return(cache->rawEvent.get());
 }
 
-void ByteStreamEventStorageInputSvc::validateEvent() {
-  const EventContext context{ Gaudi::Hive::currentContext() };
-  m_eventsCache.get(context)->eventStatus = validateEvent( m_eventsCache.get(context)->rawEvent );
+
+/******************************************************************************/
+void
+ByteStreamEventStorageInputSvc::validateEvent()
+{
+  const EventContext& context{Gaudi::Hive::currentContext()};
+  const RawEvent* const event = m_eventsCache.get(context)->rawEvent.get();
+  m_eventsCache.get(context)->eventStatus = validateEvent(event);
 }
 
-unsigned ByteStreamEventStorageInputSvc::validateEvent( const RawEvent* rawEvent ) const
+
+/******************************************************************************/
+unsigned
+ByteStreamEventStorageInputSvc::validateEvent(const RawEvent* const rawEvent) const
 {
   unsigned int status = 0;
   if (m_valEvent) {
     // check validity
-    std::vector<eformat::FragmentProblem> p;
-    rawEvent->problems(p);
-    if (!p.empty()) {
+    std::vector<eformat::FragmentProblem> problems;
+    rawEvent->problems(problems);
+
+    if(!problems.empty()) {
       status += 0x01000000;
+
       // bad event
       ATH_MSG_WARNING("Failed to create FullEventFragment");
-      for (std::vector<eformat::FragmentProblem>::const_iterator i = p.begin(), iEnd = p.end();
-	        i != iEnd; i++) {
-        ATH_MSG_WARNING(eformat::helper::FragmentProblemDictionary.string(*i));
-      }
-      //      releaseCurrentEvent();
+      for(const auto& problem : problems)
+        ATH_MSG_WARNING(eformat::helper::FragmentProblemDictionary.string(problem));
+
       throw ByteStreamExceptions::badFragmentData();
     }
-    if ( !ROBFragmentCheck( rawEvent ) ) {
+
+    if(!ROBFragmentCheck(rawEvent)) {
       status += 0x02000000;
+
       // bad event
-      //      releaseCurrentEvent();
       ATH_MSG_ERROR("Skipping bad event");
       throw ByteStreamExceptions::badFragmentData();
     }
-  } 
-  else {
+  } else {
     ATH_MSG_DEBUG("Processing event without validating.");
   }
   return status;
 }
 
-void ByteStreamEventStorageInputSvc::buildFragment(EventCache* cache, void* data, uint32_t eventSize, bool validate) const
+
+/******************************************************************************/
+void
+ByteStreamEventStorageInputSvc::buildFragment(
+    EventCache* cache, char* data, uint32_t eventSize,
+    bool validate) const
 {
-  OFFLINE_FRAGMENTS_NAMESPACE::DataType* fragment = reinterpret_cast<OFFLINE_FRAGMENTS_NAMESPACE::DataType*>(data);
+  using OFFLINE_FRAGMENTS_NAMESPACE::DataType;
+  using OFFLINE_FRAGMENTS_NAMESPACE::PointerType;
+  DataType* fragment = reinterpret_cast<DataType*>(data);
+
   if (validate) {
     // check fragment type
-    const uint32_t headWord = fragment[0];
+    const DataType headWord = fragment[0];
     ATH_MSG_DEBUG("First word of the fragment " << MSG::hex << headWord << MSG::dec);
     // format version
-    const uint32_t formatVersion = eformat::helper::Version(fragment[3]).major_version();
-    ATH_MSG_DEBUG("Format version " << MSG::hex << formatVersion << MSG::dec);
+    const DataType formatVersion = eformat::helper::Version(fragment[3]).major_version();
+    ATH_MSG_DEBUG("Format version" << MSG::hex << formatVersion << MSG::dec);
     // error message
-    if ((formatVersion != eformat::MAJOR_DEFAULT_VERSION) && 
-        (formatVersion != eformat::MAJOR_V24_VERSION) && 
-        (formatVersion != eformat::MAJOR_V30_VERSION) && 
-        (formatVersion != eformat::MAJOR_V40_VERSION) && 
-        (formatVersion != eformat::MAJOR_V31_VERSION) ) {
-      ATH_MSG_ERROR("unsupported Format Version : " << MSG::hex << formatVersion << MSG::dec);
+    if((formatVersion != eformat::MAJOR_DEFAULT_VERSION) && 
+       (formatVersion != eformat::MAJOR_V24_VERSION) && 
+       (formatVersion != eformat::MAJOR_V30_VERSION) && 
+       (formatVersion != eformat::MAJOR_V40_VERSION) && 
+       (formatVersion != eformat::MAJOR_V31_VERSION) ) {
+      ATH_MSG_ERROR("unsupported Format Version : "
+          << MSG::hex << formatVersion << MSG::dec);
     }
 
-    if (eformat::FULL_EVENT == headWord || 0xcc1234cc == headWord) { // ROS = 0xcc1234cc
+    if(eformat::FULL_EVENT == headWord || 0xcc1234cc == headWord) { // ROS = 0xcc1234cc
       try {
         // convert old fragment
-        if (formatVersion != eformat::MAJOR_DEFAULT_VERSION) {
+        if(formatVersion != eformat::MAJOR_DEFAULT_VERSION) {
           // 100 for increase of data-size due to header conversion
-          uint32_t newEventSize = eventSize + 1000;
-          OFFLINE_FRAGMENTS_NAMESPACE::DataType* newFragment = new OFFLINE_FRAGMENTS_NAMESPACE::DataType[newEventSize];
+          DataType  newEventSize = eventSize + 1000;
+          DataType* newFragment  = new DataType[newEventSize];
           eformat::old::convert(fragment, newFragment, newEventSize);
+
           // delete old fragment
-          delete [] fragment; fragment = 0;
+          delete [] fragment; fragment = nullptr;
+
           // set new pointer
           fragment = newFragment;
         }
-      } catch (eformat::Issue& ex) {
+      } catch (const eformat::Issue& ex) {
         // bad event
         ATH_MSG_WARNING(ex.what());
-	//        releaseCurrentEvent();
         ATH_MSG_ERROR("Skipping bad event");
         throw ByteStreamExceptions::badFragment();
       }
-    }
-    else {
+    } else {
       // Unknown fragment
       ATH_MSG_FATAL("Unknown Header work in input fragment " << MSG::hex << headWord);
       throw ByteStreamExceptions::badFragment();
     }
-  } 
+  }
+
   // This is a FullEventFragment
   // make a new FEFrag in memory from it
   cache->eventStatus = 0;
-  if (fragment[5] > 0) {
+  if(fragment[5] > 0) {
     cache->eventStatus += eformat::helper::Status(fragment[6]).specific();
     cache->eventStatus += (eformat::helper::Status(fragment[6]).generic() & 0x000000ff) << 16;
   }
 
   // This is a FullEventFragment
   // make a new RawEvent in memory from it
-  cache->rawEvent = new RawEvent(fragment);
+  cache->rawEvent = std::make_unique<RawEvent>(fragment);
   ATH_MSG_DEBUG("Made an FullEventFragment from ES " << fragment);
-
 }
 
-//__________________________________________________________________________
-StatusCode ByteStreamEventStorageInputSvc::generateDataHeader()
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageInputSvc::generateDataHeader()
 {
   // get file GUID
   m_fileGUID = m_reader->GUID();
+
   // reader returns -1 when end of the file is reached
-  if (m_evtFileOffset != -1) {
-    ATH_MSG_DEBUG("ByteStream File GUID:" << m_fileGUID);
+  if(m_evtFileOffset != -1) {
+    ATH_MSG_DEBUG("ByteStream File GUID:              " << m_fileGUID);
     ATH_MSG_DEBUG("ByteStream Event Position in File: " << m_evtFileOffset);
-    // Created data header element with BS provenance information
-    Token* token = new Token();
-    token->setDb(m_fileGUID);
-    token->setTechnology(0x00001000);
-    token->setOid(Token::OID_t(0LL, m_evtFileOffset));
-    DataHeaderElement Dhe(ClassID_traits<DataHeader>::ID(), "StreamRAW", token);
-    // Create data header itself
-    DataHeader* Dh = new DataHeader();
+
     // To accomodate for skipEvents option in EventSelector
     // While skipping BS event Selector does not return SUCCESS code,
     // just advances silently through events. So SG content is not refreshed
     // Lets do refresh of the event header here
-    if (m_sgSvc->contains<DataHeader>("ByteStreamDataHeader")) {
-      // Temporary event header pointer for retrieval of the old one , if exists
-      DataHeader* Dh_temp;
-      Dh_temp = m_sgSvc->retrieve<DataHeader>("ByteStreamDataHeader");
-      StatusCode sc = m_sgSvc->remove<DataHeader>(Dh_temp);
-      if (!sc.isSuccess()) {
-        ATH_MSG_ERROR("Failed to remove DataHeader ByteStreamDataHeader");
-      }
-    }
+    std::string key = "ByteStreamDataHeader";
+    ATH_CHECK(deleteEntry<DataHeader>(key));
+
+    // Created data header element with BS provenance information
+    std::unique_ptr<DataHeaderElement> dataHeaderElement = makeBSProvenance();
+    // Create data header itself
+    std::unique_ptr<DataHeader> dataHeader = std::make_unique<DataHeader>();
     // Declare header primary
-    Dh->setStatus(DataHeader::Input);
-    //add the Dhe self reference to the object vector
-    Dh->insert(Dhe);
-
-    // Cleanup EventInfo from the previous event, if exists
-    if (m_sgSvc->contains<xAOD::EventInfo>(m_eventInfoKey.value())) {
-      // Temporary event info pointer for retrieval of the old one
-      const xAOD::EventInfo* Ei_temp{nullptr};
-      if (m_sgSvc->retrieve(Ei_temp, m_eventInfoKey.value()).isSuccess()) {
-        StatusCode sc = m_sgSvc->remove(Ei_temp);
-        if (!sc.isSuccess()) {
-          ATH_MSG_ERROR("Failed to remove EventInfo");
-        }
-      }
-    }
-    if (m_sgSvc->contains<xAOD::EventAuxInfo>(m_eventInfoKey.value() + "Aux.")) {
-      // Temporary event info Aux store pointer for retrieval of the old one
-      const xAOD::EventAuxInfo* EiAux_temp{nullptr};
-      if (m_sgSvc->retrieve(EiAux_temp, m_eventInfoKey.value() + "Aux.").isSuccess()) {
-        StatusCode sc = m_sgSvc->remove(EiAux_temp);
-        if (!sc.isSuccess()) {
-          ATH_MSG_ERROR("Failed to remove EventAuxInfo");
-        }
-      }
-    }
+    dataHeader->setStatus(DataHeader::Input);
+    //add the data header elenebt self reference to the object vector
+    dataHeader->insert(*std::move(dataHeaderElement));
 
+    // Clean up EventInfo from the previous event
+    key = m_eventInfoKey.value();
+    ATH_CHECK(deleteEntry<xAOD::EventInfo>(key));
     // Now add ref to xAOD::EventInfo
-    IOpaqueAddress* iopx = new ByteStreamAddress(ClassID_traits<xAOD::EventInfo>::ID(), m_eventInfoKey.value(), "");
-    StatusCode iocx = m_sgSvc->recordAddress(m_eventInfoKey.value(), iopx);
-    if (iocx.isSuccess()) {
-      const SG::DataProxy* ptmpx = m_sgSvc->transientProxy(ClassID_traits<xAOD::EventInfo>::ID(), m_eventInfoKey.value());
-      if (ptmpx !=0) {
-        DataHeaderElement DheEIx(ptmpx, 0, m_eventInfoKey.value());
-        Dh->insert(DheEIx);
-      }
+    std::unique_ptr<IOpaqueAddress> iopx = std::make_unique<ByteStreamAddress>(
+        ClassID_traits<xAOD::EventInfo>::ID(), key, "");
+    ATH_CHECK(m_storeGate->recordAddress(key, iopx.release()));
+    const SG::DataProxy* ptmpx = m_storeGate->transientProxy(
+        ClassID_traits<xAOD::EventInfo>::ID(), key);
+    if (ptmpx != nullptr) {
+      DataHeaderElement element(ptmpx, 0, key);
+      dataHeader->insert(element);
     }
 
+    // Clean up auxiliary EventInfo from the previous event
+    key = m_eventInfoKey.value() + "Aux.";
+    ATH_CHECK(deleteEntry<xAOD::EventAuxInfo>(key));
     // Now add ref to xAOD::EventAuxInfo
-    IOpaqueAddress* iopaux = new ByteStreamAddress(ClassID_traits<xAOD::EventAuxInfo>::ID(), m_eventInfoKey.value() + "Aux.", "");
-    StatusCode iocaux = m_sgSvc->recordAddress(m_eventInfoKey.value() + "Aux.", iopaux);
-    if (iocaux.isSuccess()) {
-      const SG::DataProxy* ptmpaux = m_sgSvc->transientProxy(ClassID_traits<xAOD::EventAuxInfo>::ID(), m_eventInfoKey.value() + "Aux.");
-      if (ptmpaux !=0) {
-        DataHeaderElement DheEIAux(ptmpaux, 0, m_eventInfoKey.value() + "Aux.");
-        Dh->insert(DheEIAux);
-      }
+    std::unique_ptr<IOpaqueAddress> iopaux = std::make_unique<ByteStreamAddress>(
+        ClassID_traits<xAOD::EventAuxInfo>::ID(), key, "");
+    ATH_CHECK(m_storeGate->recordAddress(key, iopaux.release()));
+    const SG::DataProxy* ptmpaux = m_storeGate->transientProxy(
+        ClassID_traits<xAOD::EventAuxInfo>::ID(), key);
+    if (ptmpaux !=0) {
+      DataHeaderElement element(ptmpaux, 0, key);
+      dataHeader->insert(element);
     }
 
     // Record new data header.Boolean flags will allow it's deletionin case
     // of skipped events.
-    return m_sgSvc->record<DataHeader>(Dh, "ByteStreamDataHeader", true, false, true);
+    ATH_CHECK(m_storeGate->record<DataHeader>(dataHeader.release(),
+          "ByteStreamDataHeader", true, false, true));
   }
-  return StatusCode::FAILURE;
+  return StatusCode::SUCCESS;
 }
 
-//__________________________________________________________________________
-void ByteStreamEventStorageInputSvc::releaseEvent( EventCache* cache)
+
+/******************************************************************************/
+void
+ByteStreamEventStorageInputSvc::EventCache::releaseEvent()
 {
-   // cleanup parts of previous event and re-init them
-   if ( cache->rawEvent ) {
-      OFFLINE_FRAGMENTS_NAMESPACE::PointerType fragment = 0;
-      cache->rawEvent->start(fragment);
-      delete [] fragment; fragment = 0;
-      delete cache->rawEvent; cache->rawEvent = 0;
-      cache->eventStatus = 0;
-   }
+  // cleanup parts of previous event and re-init them
+  if(rawEvent) {
+    OFFLINE_FRAGMENTS_NAMESPACE::PointerType fragment = 0;
+    rawEvent->start(fragment);
+    delete [] fragment; fragment = 0;
+    rawEvent.reset(nullptr);
+    eventStatus = 0;
+  }
 }
 
-//__________________________________________________________________________
-void ByteStreamEventStorageInputSvc::closeBlockIterator(bool clearMetadata)
+
+/******************************************************************************/
+void
+ByteStreamEventStorageInputSvc::closeBlockIterator(bool clearMetadata)
 {
-    if (clearMetadata) {
-       ATH_MSG_WARNING("Clearing input metadata store");
-       StatusCode status = m_mdSvc->clearStore();
-       if (!status.isSuccess()) {
-          ATH_MSG_WARNING("Unable to clear Input MetaData Proxies");
-       }
+  if (clearMetadata) {
+    ATH_MSG_WARNING("Clearing input metadata store");
+    StatusCode status = m_inputMetadata->clearStore();
+    if (!status.isSuccess()) {
+      ATH_MSG_WARNING("Unable to clear Input MetaData Proxies");
     }
-    if (!readerReady()) {
-       ATH_MSG_INFO("No more events in this run, high water mark for this file = " << m_evtOffsets.size()-1);
-    }
-    delete m_reader; m_reader = 0;
+  }
+
+  if (!readerReady()) {
+    ATH_MSG_INFO("No more events in this run, high water mark for this file = "
+        << m_evtOffsets.size()-1);
+  }
+
+  m_reader.reset();
 }
 
-//__________________________________________________________________________
-bool ByteStreamEventStorageInputSvc::setSequentialRead()
+
+/******************************************************************************/
+bool
+ByteStreamEventStorageInputSvc::setSequentialRead()
 {
-    // enable SequenceReading
-    m_reader->enableSequenceReading();
-    return true;
+  // enable SequenceReading
+  m_reader->enableSequenceReading();
+  return true;
 }
 
-bool ByteStreamEventStorageInputSvc::ready()
+
+/******************************************************************************/
+bool
+ByteStreamEventStorageInputSvc::ready() const
 {
-   return readerReady();
+  return readerReady();
 }
 
-//__________________________________________________________________________
-std::pair<long,std::string> ByteStreamEventStorageInputSvc::getBlockIterator(const std::string fileName)
+
+/******************************************************************************/
+std::pair<long,std::string>
+ByteStreamEventStorageInputSvc::getBlockIterator(const std::string fileName)
 {
-   m_fullFile = fileName;
-
-   // open the file
-   if (m_reader != 0) closeBlockIterator();
-   m_reader = pickDataReader(fileName);
-   if (!m_reader) {
-      ATH_MSG_ERROR("Failed to open file " << fileName);
-      closeBlockIterator();
-      return std::make_pair(-1,"END"); 
-   }
-   // Initilaize offset vector
-   m_evtOffsets.resize(m_reader->eventsInFile(), -1);
-   m_evtOffsets.clear();
-   // Get ByteStream Metadata into Input MetaData Store (include begin Input File Incident)
-   loadMetadata();
-
-   m_evtInFile = 0;
-   ++m_fileCount;
-
-   // enable sequentialReading if multiple files
-   if (m_sequential) {
-      bool test = setSequentialRead();
-      if (!test) return std::make_pair(-1,"SEQ");
-   }
-   ATH_MSG_INFO("Picked valid file: " << m_reader->fileName());
-   // initialize offsets and counters
-   m_evtOffsets.push_back((long long)m_reader->getPosition());
-   return std::make_pair(m_reader->eventsInFile(),m_reader->GUID());;
+  // open the file
+  if(m_reader != 0) closeBlockIterator();
+
+  m_reader = std::move(std::unique_ptr<EventStorage::DataReader>(pickDataReader(fileName)));
+
+  if(m_reader == nullptr) {
+    ATH_MSG_ERROR("Failed to open file " << fileName);
+    closeBlockIterator();
+    return std::make_pair(-1,"END"); 
+  }
+
+  // Initilaize offset vector
+  m_evtOffsets.resize(m_reader->eventsInFile(), -1);
+  m_evtOffsets.clear();
+
+  // Get ByteStream Metadata into Input MetaData Store
+  // (include begin Input File Incident)
+  if (loadMetadata().isSuccess()) {
+    ATH_MSG_DEBUG("Recorded ByteStreamMetadata in InputMetaDataStore");
+  } else {
+    ATH_MSG_ERROR("Unable to record ByteStreamMetadata in InputMetaDataStore");
+    return std::make_pair(-1, "FAIL");
+  }
+
+  m_evtInFile = 0;
+
+  // enable sequentialReading if multiple files
+  if(m_sequential) {
+    bool test = setSequentialRead();
+    if (!test) return std::make_pair(-1,"SEQ");
+  }
+
+  ATH_MSG_INFO("Picked valid file: " << m_reader->fileName());
+  // initialize offsets and counters
+  m_evtOffsets.push_back(static_cast<long long>(m_reader->getPosition()));
+  return std::make_pair(m_reader->eventsInFile(), m_reader->GUID());
 }
 
-//__________________________________________________________________________
-bool ByteStreamEventStorageInputSvc::readerReady()
+
+/******************************************************************************/
+bool
+ByteStreamEventStorageInputSvc::readerReady() const
 {
-   bool eofFlag(false);
-   if (m_reader!=0) eofFlag = m_reader->endOfFile();
-   else {
-      ATH_MSG_INFO("eformat reader object not initialized");
-      return false;
-   }
-   bool moreEvent = m_reader->good();
-
-   return (!eofFlag)&&moreEvent;
+  bool eofFlag(false);
+
+  if (m_reader) eofFlag = m_reader->endOfFile();
+  else {
+    ATH_MSG_INFO("eformat reader object not initialized");
+    return false;
+  }
+
+  bool moreEvent = m_reader->good();
+
+  return (!eofFlag) && moreEvent;
 }
-//__________________________________________________________________________
-bool ByteStreamEventStorageInputSvc::ROBFragmentCheck( const RawEvent* re ) const
+
+
+/******************************************************************************/
+bool
+ByteStreamEventStorageInputSvc::ROBFragmentCheck(const RawEvent* re) const
 {
-   bool allOK = true;
-   uint32_t total = re->nchildren(), lastId = 0;
-   std::vector<eformat::FragmentProblem> p;
-   for (size_t i = 0; i<total; ++i) {
-     OFFLINE_FRAGMENTS_NAMESPACE::PointerType fp;
-     re->child(fp, i);
-     OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment f(fp);
-     lastId = f.source_id();
-     p.clear();
-     f.problems(p);
-     if (!p.empty()) {
-       allOK = false;
-       for (std::vector<eformat::FragmentProblem>::const_iterator i = p.begin(), iEnd = p.end();
-	          i != iEnd; i++) {
-         ATH_MSG_WARNING("Failed to create ROBFragment id = " << lastId << ", " << eformat::helper::SourceIdentifier(lastId).human()  << " : " << eformat::helper::FragmentProblemDictionary.string(*i));
-       }
-     }
-   }
-   return allOK;
+  bool     allOK  = true;
+  uint32_t total  = re->nchildren();
+  uint32_t lastId = 0;
+  std::vector<eformat::FragmentProblem> problems;
+
+  for (size_t i = 0; i<total; ++i) {
+    OFFLINE_FRAGMENTS_NAMESPACE::PointerType fp;
+    re->child(fp, i);
+
+    OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment f(fp);
+    lastId = f.source_id();
+
+    problems.clear();
+    f.problems(problems);
+    if(!problems.empty()) {
+      allOK = false;
+      for(const auto& problem : problems) {
+        ATH_MSG_WARNING("Failed to create ROBFragment id = " << lastId << ", "
+            << eformat::helper::SourceIdentifier(lastId).human()  << " : "
+            << eformat::helper::FragmentProblemDictionary.string(problem));
+      }
+    }
+  }
+
+  return allOK;
 }
-//__________________________________________________________________________
-void ByteStreamEventStorageInputSvc::setEvent(void* data, unsigned int eventStatus) {
-  const EventContext context{ Gaudi::Hive::currentContext() };
-  return setEvent( context, data, eventStatus );
+
+
+/******************************************************************************/
+void
+ByteStreamEventStorageInputSvc::setEvent(void* data, unsigned int eventStatus)
+{
+  const EventContext context{Gaudi::Hive::currentContext()};
+  return setEvent(context, data, eventStatus);
 }
 
-void ByteStreamEventStorageInputSvc::setEvent( const EventContext& context, void* data, unsigned int eventStatus )
+
+/******************************************************************************/
+void
+ByteStreamEventStorageInputSvc::setEvent(const EventContext& context,
+    void* data, unsigned int eventStatus)
 {
-  EventCache* cache = m_eventsCache.get( context );
-  releaseEvent( cache );
-   OFFLINE_FRAGMENTS_NAMESPACE::DataType* fragment = reinterpret_cast<OFFLINE_FRAGMENTS_NAMESPACE::DataType*>(data);
-   cache->rawEvent = new RawEvent(fragment);
-   cache->eventStatus = eventStatus;
-   // Set it for the data provider
-   m_robProvider->setNextEvent(context, cache->rawEvent );
-   m_robProvider->setEventStatus(context, cache->eventStatus );
-
-   // Build a DH for use by other components
-   StatusCode rec_sg = generateDataHeader();
-   if (rec_sg != StatusCode::SUCCESS) {
-      ATH_MSG_ERROR("Fail to record BS DataHeader in StoreGate. Skipping events?! " << rec_sg);
-   }
+  using OFFLINE_FRAGMENTS_NAMESPACE::DataType;
+  EventCache* cache = m_eventsCache.get(context);
+  cache->releaseEvent();
+
+  DataType* fragment = reinterpret_cast<DataType*>(data);
+  cache->rawEvent = std::make_unique<RawEvent>(fragment);
+  cache->eventStatus = eventStatus;
+
+  // Set it for the data provider
+  m_robProvider->setNextEvent(context, cache->rawEvent.get());
+  m_robProvider->setEventStatus(context, cache->eventStatus);
+
+  // Build a DH for use by other components
+  StatusCode rec_sg = generateDataHeader();
+  if (rec_sg != StatusCode::SUCCESS) {
+    ATH_MSG_ERROR("Fail to record BS DataHeader in StoreGate. Skipping events?! "
+        << rec_sg);
+  }
 }
-//__________________________________________________________________________
-const RawEvent* ByteStreamEventStorageInputSvc::currentEvent() const {
-  const EventContext context{ Gaudi::Hive::currentContext() };
-  return m_eventsCache.get(context)->rawEvent;
+
+
+/******************************************************************************/
+const
+RawEvent* ByteStreamEventStorageInputSvc::currentEvent() const
+{
+  const EventContext context{Gaudi::Hive::currentContext()};
+  return m_eventsCache.get(context)->rawEvent.get();
 }
-//__________________________________________________________________________
-unsigned int ByteStreamEventStorageInputSvc::currentEventStatus() const {
-  const EventContext context{ Gaudi::Hive::currentContext() };
+
+
+/******************************************************************************/
+unsigned int
+ByteStreamEventStorageInputSvc::currentEventStatus() const
+{
+  const EventContext context{Gaudi::Hive::currentContext()};
   return m_eventsCache.get(context)->eventStatus;
 }
-//________________________________________________________________________________
-StatusCode ByteStreamEventStorageInputSvc::queryInterface(const InterfaceID& riid, void** ppvInterface) {
-   if (ByteStreamInputSvc::interfaceID().versionMatch(riid)) {
-      *ppvInterface = dynamic_cast<ByteStreamInputSvc*>(this);
-   } else {
-     // Interface is not directly available: try out a base class
-     return(::AthService::queryInterface(riid, ppvInterface));
-   }
-   addRef();
-   return(StatusCode::SUCCESS);
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageInputSvc::queryInterface(const InterfaceID& riid,
+    void** ppvInterface)
+{
+  if(ByteStreamInputSvc::interfaceID().versionMatch(riid))
+    *ppvInterface = dynamic_cast<ByteStreamInputSvc*>(this);
+  else // Interface is not directly available: try out a base class
+    return(::AthService::queryInterface(riid, ppvInterface));
+ 
+  addRef();
+  return(StatusCode::SUCCESS);
 }
 
-ByteStreamEventStorageInputSvc::EventCache::~EventCache() {
-  delete rawEvent;
-  rawEvent = 0;
+
+/******************************************************************************/
+std::unique_ptr<DataHeaderElement>
+ByteStreamEventStorageInputSvc::makeBSProvenance() const
+{
+    std::unique_ptr<Token> token = std::make_unique<Token>();
+    token->setDb(m_fileGUID);
+    token->setTechnology(0x00001000);
+    token->setOid(Token::OID_t(0LL, m_evtFileOffset));
+
+    // note: passing ownership of token to DataHeaderElement
+    return std::make_unique<DataHeaderElement>(ClassID_traits<DataHeader>::ID(),
+        "StreamRAW", token.release());
 }
 
diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.h b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.h
index f4465f69221..df0ef8311d5 100644
--- a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.h
+++ b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.h
@@ -8,6 +8,7 @@
 /** @file ByteStreamEventStorageInputSvc.h
  *  @brief This file contains the class definition for the ByteStreamEventStorageInputSvc class.
  *  @author Peter van Gemmeren <gemmeren@anl.gov>
+ *  @author Frank Berghaus <fberghaus@anl.gov>
  **/
 
 // Include files.
@@ -15,111 +16,115 @@
 #include "ByteStreamCnvSvcBase/IROBDataProviderSvc.h"
 #include "ByteStreamData/RawEvent.h"
 #include "AthenaKernel/SlotSpecificObj.h"
-#include "EventStorage/DataReader.h"
 
 // FrameWork includes
 #include "GaudiKernel/ServiceHandle.h"
 
+namespace EventStorage
+{
+  class DataReader;
+}
 class StoreGateSvc;
+class DataHeaderElement;
+
 
 /** @class ByteStreamEventStorageInputSvc
  *  @brief This class is the ByteStreamInputSvc for reading events written by EventStorage.
  **/
-class ByteStreamEventStorageInputSvc :
-	public ByteStreamInputSvc {
+class ByteStreamEventStorageInputSvc
+: public ByteStreamInputSvc
+{
 public:
-   /// Constructors:
-   ByteStreamEventStorageInputSvc(const std::string& name, ISvcLocator* svcloc);
-
-   /// Destructor.
-   virtual ~ByteStreamEventStorageInputSvc();
+  /// Constructors:
+  ByteStreamEventStorageInputSvc(const std::string& name,
+      ISvcLocator* pSvcLocator);
 
-   /// Required of all Gaudi Services
-   virtual StatusCode initialize();
-   virtual StatusCode stop();
-   /// Required of all Gaudi Services
-   virtual StatusCode finalize();
+  /// Destructor.
+  virtual ~ByteStreamEventStorageInputSvc();
 
-   /// Required of all Gaudi services:  see Gaudi documentation for details
-   StatusCode queryInterface(const InterfaceID& riid, void** ppvInterface);
+  /// Required of all Gaudi Services
+  virtual StatusCode initialize();
+  virtual StatusCode stop      ();
+  virtual StatusCode finalize  ();
 
-   /// Implementation of the ByteStreamInputSvc interface methods.
-   virtual const RawEvent* currentEvent() const;
-   virtual const RawEvent* nextEvent();            //!< ++, new
-   virtual const RawEvent* previousEvent();        //!< --, old
-   virtual       void setEvent(void* data, unsigned int eventStatus);
+  /// Required of all Gaudi services:  see Gaudi documentation for details
+  StatusCode queryInterface(const InterfaceID& riid, void** ppvInterface);
 
-   /// Return the current event status
-   virtual unsigned int currentEventStatus() const;
-   virtual void validateEvent(); 
+  /// Implementation of the ByteStreamInputSvc interface methods.
+  virtual const RawEvent* currentEvent () const;
+  virtual const RawEvent* nextEvent    (); //!< ++, new
+  virtual const RawEvent* previousEvent(); //!< --, old
+  virtual void            setEvent     (void* data, unsigned int eventStatus);
 
+  /// Return the current event status
+  virtual unsigned int currentEventStatus() const;
+  virtual void         validateEvent     (); 
 
-   virtual long positionInBlock();
-   virtual std::pair<long,std::string> getBlockIterator(const std::string fileName);
-   void         closeBlockIterator(bool clearMetadata=true);
-   bool         setSequentialRead();
-   bool         ready();
-   StatusCode   generateDataHeader();
+  virtual long positionInBlock   ();
+  virtual std::pair<long,std::string> getBlockIterator(const std::string fileName);
+  void         closeBlockIterator(bool clearMetadata=true);
+  bool         setSequentialRead ();
+  bool         ready             () const;
+  StatusCode   generateDataHeader();
 
-private: // internal member functions
-   bool loadMetadata();
 
 private: // data
-   std::mutex m_readerMutex;
+  std::mutex m_readerMutex;
 
-   struct EventCache {
-     ~EventCache();
-     RawEvent*          rawEvent = 0;            //!< current event
-     unsigned int       eventStatus = 0;   //!< check_tree() status of the current event
-     long long int      eventOffset = 0;   //!< event offset within a file, can be -1          
-   };
+  struct EventCache {
+    std::unique_ptr<RawEvent> rawEvent    = nullptr; //!< current event
+    unsigned int              eventStatus = 0;       //!< check_tree() status of the current event
+    long long int             eventOffset = 0;       //!< event offset within a file, can be -1
+    void                      releaseEvent();
+  };
 
-   SG::SlotSpecificObj<EventCache> m_eventsCache;
+  SG::SlotSpecificObj<EventCache> m_eventsCache;
 
-   //int                m_totalEventCounter; //!< event Counter
-   DataReader*        m_reader;        //!< DataReader from EventStorage
+  std::unique_ptr<EventStorage::DataReader>  m_reader; //!< DataReader from EventStorage
 
-   mutable std::vector<int>     m_numEvt;    //!< number of events in that file
-   mutable std::vector<int>     m_firstEvt;  //!< event number of first event in that file
-   mutable std::vector<long long int> m_evtOffsets;  //!< offset for event i in that file
-   unsigned int                 m_evtInFile;
-   long long int      m_evtFileOffset = 0;   //!< last read in event offset within a file, can be -1     
-   // Event back navigation info
-   std::string        m_fileGUID;      //!< current file GUID
+  mutable std::vector<long long int> m_evtOffsets;  //!< offset for event i in that file
+  unsigned int       m_evtInFile;
+  long long int      m_evtFileOffset;   //!< last read in event offset within a file, can be -1     
+  // Event back navigation info
+  std::string        m_fileGUID;      //!< current file GUID
 
 
-   /// Pointer to StoreGate
-   ServiceHandle<StoreGateSvc> m_sgSvc; //!< StoreGateSvc
-   ServiceHandle<StoreGateSvc> m_mdSvc; //!< StoreGateSvc
-   ServiceHandle<IROBDataProviderSvc> m_robProvider;
 
 private: // properties
-   std::vector<std::string>	m_vExplicitFile;  //!< prefix of the file names
-
-   std::vector<std::string>::const_iterator m_itFullFile; //!< iter  for full filename
-
-   bool               m_sequential;    //!< enable sequential reading.
-   int                m_fileCount;     //!< number of files to process.
-   std::string        m_fullFile;      //!< current full file name
+  /// Pointer to StoreGate
+  ServiceHandle<StoreGateSvc>                m_storeGate;     //!< StoreGateSvc
+  ServiceHandle<StoreGateSvc>                m_inputMetadata; //!< StoreGateSvc
+  ServiceHandle<IROBDataProviderSvc>         m_robProvider;
+  Gaudi::Property<std::vector<std::string> > m_vExplicitFile;
+  Gaudi::Property<bool>                      m_sequential;    //!< enable sequential reading.
+  Gaudi::Property<bool>                      m_dump;
+  Gaudi::Property<float>                     m_wait;
+  Gaudi::Property<bool>                      m_valEvent;
+  Gaudi::Property<std::string>               m_eventInfoKey;
 
-   Gaudi::Property<bool>    m_dump;          //!< flag for Dump fragments
-   Gaudi::Property<float>      m_wait;          //!< Number of seconds to wait if the input is in the wait state.
-   Gaudi::Property<bool>    m_valEvent;      //!< switch on check_tree() call when reading events.
-   Gaudi::Property<bool>    m_procBadEvent;  //!< DEFUNCT process bad events, which fail check_tree().
-   Gaudi::Property<int>    m_maxBadEvts;    //!< DEFUNCT number of bad events allowed before quitting.
-   Gaudi::Property<std::string> m_eventInfoKey{this, "EventInfoKey", "EventInfo", ""};
 
 private: // internal helper functions
+  StatusCode loadMetadata    ();
+  void       buildFragment   (EventCache* cache, char* data, uint32_t eventSize, bool validate) const;
+  bool       readerReady     () const;
+  bool       ROBFragmentCheck(const RawEvent*) const;
+  unsigned   validateEvent   (const RawEvent* const rawEvent) const;
+  void       setEvent        (const EventContext& context, void* data, unsigned int eventStatus);
+
+  enum Advance{ PREVIOUS = -1, NEXT = 1 };
+  const RawEvent* getEvent( Advance step );
+  std::unique_ptr<DataHeaderElement> makeBSProvenance() const;
+
+  template<typename T>
+  StatusCode deleteEntry(const std::string& key)
+  {
+    if (m_storeGate->contains<T>(key)) {
+      const T* tmp = m_storeGate->tryConstRetrieve<T>(key);
+      if (tmp != nullptr) ATH_CHECK(m_storeGate->remove<T>(tmp));
+    }
+    return StatusCode::SUCCESS;
+  }
 
-   void buildFragment( EventCache* cache, void* data, uint32_t eventSize, bool validate ) const;
-   void releaseEvent( EventCache* );
-   bool readerReady();
-   bool ROBFragmentCheck( const RawEvent* ) const;
-   unsigned validateEvent( const RawEvent* rawEvent ) const;
-   void setEvent( const EventContext& context, void* data, unsigned int eventStatus );
-   
-   enum Advance{ PREVIOUS = -1, NEXT = 1 };
-   const RawEvent* getEvent( Advance step );
 };
 
-#endif
+#endif // BYTESTREAMEVENTSTORAGEINPUTSVC_H
diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.cxx b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.cxx
index 5f7097f20a0..1ce60ee24ce 100644
--- a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.cxx
+++ b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.cxx
@@ -28,356 +28,382 @@
 #include <boost/shared_ptr.hpp>
 #include <stdlib.h>
 
-// Constructor.
-ByteStreamEventStorageOutputSvc::ByteStreamEventStorageOutputSvc(const std::string& name, ISvcLocator* svcloc) :
-		ByteStreamOutputSvc(name,svcloc),
-	m_totalEventCounter(0)
+
+/******************************************************************************/
+ByteStreamEventStorageOutputSvc::ByteStreamEventStorageOutputSvc(
+    const std::string& name, ISvcLocator* pSvcLocator)
+  : ByteStreamOutputSvc(name, pSvcLocator)
+  , m_totalEventCounter  (0)
+  , m_inputDir           (this,     "OutputDirectory",        "", "directory for the data files")
+  , m_projectTag         (this,          "ProjectTag",        "", "part of filename")
+  , m_appName            (this,             "AppName",        "", "part of filename")
+  , m_fileTag            (this,             "FileTag",        "", "part of filename")
+  , m_streamType         (this,          "StreamType",  "Single", "part of filename")
+  , m_streamName         (this,          "StreamName",  "Stream", "part of filename")
+  , m_lumiBlockNumber    (this,     "LumiBlockNumber",         0, "part of filename")
+  , m_run                (this,           "RunNumber",         0, "part of filename")
+  , m_dump               (this,            "DumpFlag",     false, "dump fragments")
+  , m_writeEventless     (this, "WriteEventlessFiles",      true, "")
+  , m_compressEvents     (this,      "CompressEvents",     false, "")
+  , m_maxFileMB          (this,           "MaxFileMB",     10000, "MB per file")
+  , m_maxFileNE          (this,           "MaxFileNE",    100000, "evens per file")
+  , m_eformatVersion     (this,      "EformatVersion", "current",
+      "Version of the event format data, use \"v40\" or \"run1\" "
+      "for run1, \"current\" for most current version (default).")
+  , m_eventStorageVersion(this, "EventStorageVersion", "current",
+      "Version of the ByteStream file data, use \"v5\" or \"run1\" "
+      "for run1, \"current\" for most current version (default).")
+  , m_bsOutputStreamName (this,  "BSOutputStreamName",      name, "stream name for muliple output")
+  , m_simpleFileName     (this,      "SimpleFileName",        "", "for filename not from AgreedFileName")
 {
-   declareProperty("OutputDirectory", m_inputDir);
-   // a set of fields for making up filename
-   declareProperty("ProjectTag",      m_projectTag);
-   declareProperty("AppName",         m_appName);
-   declareProperty("FileTag",         m_fileTag);
-   declareProperty("StreamType",      m_streamType = "Single");
-   declareProperty("StreamName",      m_streamName = "Stream");
-   declareProperty("LumiBlockNumber", m_lumiBlockNumber = 0);
-   declareProperty("RunNumber",       m_run = 0);
-
-   // This is used by ByteStreamCnvSvc when multiple streams are written out.
-   declareProperty("BSOutputStreamName", m_bsOutputStreamName = name);
-   // or just give a simple filename
-   // this will be the filename if it is non-empty
-   declareProperty("SimpleFileName",  m_simpleFileName);
-
-   // flag for dumping all fragments to logfile
-   declareProperty("DumpFlag", m_dump = false);
-
-   // flag for writing eventless files
-   declareProperty("WriteEventlessFiles", m_writeEventless = true);
-
-   // flag for compressing events
-   declareProperty("CompressEvents", m_compressEvents = false);
-
-   declareProperty("MaxFileMB", m_maxFileMB = 10000);
-   declareProperty("MaxFileNE", m_maxFileNE = 100000);
-
-   declareProperty("EformatVersion", m_eformatVersion = "current",
-                   "Version of the event format data, use \"v40\" or \"run1\" "
-                   "for run1, \"current\" for most current version (default).");
-   declareProperty("EventStorageVersion", m_eventStorageVersion = "current",
-                   "Version of the ByteStream file data, use \"v5\" or \"run1\" "
-                   "for run1, \"current\" for most current version (default).");
-}
-//__________________________________________________________________________
-ByteStreamEventStorageOutputSvc::~ByteStreamEventStorageOutputSvc() {
+  assert(pSvcLocator != nullptr);
 }
-//__________________________________________________________________________
-StatusCode ByteStreamEventStorageOutputSvc::initialize() {
-   ATH_MSG_INFO("Initializing " << name() << " - package version " << PACKAGE_VERSION);
-   if (!ByteStreamOutputSvc::initialize().isSuccess()) {
-      ATH_MSG_FATAL("Cannot initialize ByteStreamOutputSvc base class.");
-      return(StatusCode::FAILURE);
-   }
 
-   // register this service for 'I/O' events
-   ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", name());
-   if (!iomgr.retrieve().isSuccess()) {
-      ATH_MSG_FATAL("Could not retrieve IoComponentMgr !");
-      return(StatusCode::FAILURE);
-   }
-   if (!iomgr->io_register(this).isSuccess()) {
-      ATH_MSG_FATAL("Could not register myself with the IoComponentMgr !");
+
+/******************************************************************************/
+ByteStreamEventStorageOutputSvc::~ByteStreamEventStorageOutputSvc()
+{}
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageOutputSvc::initialize()
+{
+  ATH_MSG_INFO("Initializing " << name() << " - package version " << PACKAGE_VERSION);
+  if (!ByteStreamOutputSvc::initialize().isSuccess()) {
+    ATH_MSG_FATAL("Cannot initialize ByteStreamOutputSvc base class.");
+    return(StatusCode::FAILURE);
+  }
+
+  // register this service for 'I/O' events
+  ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", name());
+  if (!iomgr.retrieve().isSuccess()) {
+    ATH_MSG_FATAL("Could not retrieve IoComponentMgr !");
+    return(StatusCode::FAILURE);
+  }
+  if (!iomgr->io_register(this).isSuccess()) {
+    ATH_MSG_FATAL("Could not register myself with the IoComponentMgr !");
+    return(StatusCode::FAILURE);
+  }
+
+  // Register output file's name with the I/O manager
+  if (!m_simpleFileName.value().empty()) {
+    if (!iomgr->io_register(this, IIoComponentMgr::IoMode::WRITE, m_simpleFileName.value()).isSuccess()) {
+      ATH_MSG_FATAL("could not register [" << m_simpleFileName.value() << "] for output !");
       return(StatusCode::FAILURE);
-   }
-
-   // Register output file's name with the I/O manager
-   if (!m_simpleFileName.value().empty()) {
-      if (!iomgr->io_register(this, IIoComponentMgr::IoMode::WRITE, m_simpleFileName.value()).isSuccess()) {
-         ATH_MSG_FATAL("could not register [" << m_simpleFileName.value() << "] for output !");
-         return(StatusCode::FAILURE);
-      } else {
-         ATH_MSG_VERBOSE("io_register[" << this->name() << "](" << m_simpleFileName.value() << ") [ok]");
-      }
-   }
-
-   // validate m_eformatVersion and m_eventStorageVersion
-   const char* choices_ef[] = {"current", "v40", "run1"};
-   if (std::find(std::begin(choices_ef), std::end(choices_ef), m_eformatVersion.value()) == std::end(choices_ef)) {
-       ATH_MSG_FATAL("Unexpected value for EformatVersion property: " << m_eformatVersion);
-       return(StatusCode::FAILURE);
-   }
-   const char* choices_es[] = {"current", "v5", "run1"};
-   if (std::find(std::begin(choices_es), std::end(choices_es), m_eventStorageVersion.value()) == std::end(choices_es)) {
-       ATH_MSG_FATAL("Unexpected value for EventStorageVersion property: " << m_eventStorageVersion);
-       return(StatusCode::FAILURE);
-   }
-   ATH_MSG_INFO("eformat version to use: \"" << m_eformatVersion.value() << "\"");
-   ATH_MSG_INFO("event storage (BS) version to use: \"" << m_eventStorageVersion.value() << "\"");
-
-   return(this->reinit());
+    } else {
+      ATH_MSG_VERBOSE("io_register[" << this->name() << "](" << m_simpleFileName.value() << ") [ok]");
+    }
+  }
+
+  // validate m_eformatVersion and m_eventStorageVersion
+  const char* choices_ef[] = {"current", "v40", "run1"};
+  if (std::find(std::begin(choices_ef), std::end(choices_ef), m_eformatVersion.value()) == std::end(choices_ef)) {
+    ATH_MSG_FATAL("Unexpected value for EformatVersion property: " << m_eformatVersion);
+    return(StatusCode::FAILURE);
+  }
+  const char* choices_es[] = {"current", "v5", "run1"};
+  if (std::find(std::begin(choices_es), std::end(choices_es), m_eventStorageVersion.value()) == std::end(choices_es)) {
+    ATH_MSG_FATAL("Unexpected value for EventStorageVersion property: " << m_eventStorageVersion);
+    return(StatusCode::FAILURE);
+  }
+  ATH_MSG_INFO("eformat version to use: \"" << m_eformatVersion.value() << "\"");
+  ATH_MSG_INFO("event storage (BS) version to use: \"" << m_eventStorageVersion.value() << "\"");
+
+  return(this->reinit());
 
 }
-//__________________________________________________________________________
-StatusCode ByteStreamEventStorageOutputSvc::reinit() {
-   ATH_MSG_INFO("Reinitialization...");
-   return(StatusCode::SUCCESS);
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageOutputSvc::reinit()
+{
+  ATH_MSG_INFO("Reinitialization...");
+  return(StatusCode::SUCCESS);
 }
-//__________________________________________________________________________
-StatusCode ByteStreamEventStorageOutputSvc::stop() {
-   // Check whether anything has been written && whether the user wants metadata only files
-   bool dWok = false; 
-   if (m_dataWriter == 0 && m_writeEventless) {
-      const ByteStreamMetadataContainer* metaDataCont = 0;
-      const ByteStreamMetadata* metaData = 0;
-      ServiceHandle<StoreGateSvc> mds("MetaDataStore", name());
-      StatusCode status = mds.retrieve();
-      if (!status.isFailure()) {
-         StatusCode stat = mds->retrieve(metaDataCont);
-         if (stat.isSuccess()) metaData = *(metaDataCont->begin());
-      }
-      // Try to write metadata to file
-      dWok = initDataWriterContents(0, metaData);
-      if (!dWok) ATH_MSG_WARNING("Could not write Metadata for eventless file");
-   }
-   return(StatusCode::SUCCESS);
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageOutputSvc::stop()
+{
+  // Check whether anything has been written && whether the user wants metadata only files
+  bool dWok = false; 
+  if (m_dataWriter == 0 && m_writeEventless) {
+    const ByteStreamMetadataContainer* metaDataCont = 0;
+    const ByteStreamMetadata* metaData = 0;
+    ServiceHandle<StoreGateSvc> mds("StoreGateSvc/MetaDataStore", name());
+    StatusCode status = mds.retrieve();
+    if (!status.isFailure()) {
+      StatusCode stat = mds->retrieve(metaDataCont, "ByteStreamMetadata");
+      if (stat.isSuccess()) metaData = *(metaDataCont->begin());
+    }
+    // Try to write metadata to file
+    dWok = initDataWriterContents(0, metaData);
+    if (!dWok) ATH_MSG_WARNING("Could not write Metadata for eventless file");
+  }
+  return(StatusCode::SUCCESS);
 }
-//__________________________________________________________________________
-StatusCode ByteStreamEventStorageOutputSvc::finalize() {
-   // clean up
-   ATH_MSG_DEBUG("deleting DataWriter");
-   m_dataWriter.reset();
-   ATH_MSG_INFO("number of events written: " << m_totalEventCounter);
-   return(StatusCode::SUCCESS);
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageOutputSvc::finalize()
+{
+  // clean up
+  ATH_MSG_DEBUG("deleting DataWriter");
+  m_dataWriter.reset();
+  ATH_MSG_INFO("number of events written: " << m_totalEventCounter);
+  return(StatusCode::SUCCESS);
 }
-//__________________________________________________________________________
+
+
+/******************************************************************************/
 // Open the first input file and read the first event.
-bool ByteStreamEventStorageOutputSvc::initDataWriter() {
-   // Retrieve EventInfo to get run number, detector mask and event type
-   const EventInfo* evtInfo = 0;
-   ServiceHandle<StoreGateSvc> sg("StoreGateSvc", name());
-   if (sg.retrieve().isFailure()) {
-      ATH_MSG_ERROR("Cannot get StoreGateSvc");
-      return(false);
-   }
-   if (sg->retrieve(evtInfo).isFailure() || evtInfo == 0) {
-      ATH_MSG_ERROR("Cannot retrieve EventInfo");
-      return(false);
-   }
-   // Now try to write metadata to file
-   return initDataWriterContents(evtInfo, 0);
+bool
+ByteStreamEventStorageOutputSvc::initDataWriter()
+{
+  // Retrieve EventInfo to get run number, detector mask and event type
+  const EventInfo* evtInfo = 0;
+  ServiceHandle<StoreGateSvc> sg("StoreGateSvc", name());
+  if (sg.retrieve().isFailure()) {
+    ATH_MSG_ERROR("Cannot get StoreGateSvc");
+    return(false);
+  }
+  if (sg->retrieve(evtInfo).isFailure() || evtInfo == 0) {
+    ATH_MSG_ERROR("Cannot retrieve EventInfo");
+    return(false);
+  }
+  // Now try to write metadata to file
+  return initDataWriterContents(evtInfo, 0);
 }
-//__________________________________________________________________________
+
+
+/******************************************************************************/
 // Open the first input file and read the first event.
-bool ByteStreamEventStorageOutputSvc::initDataWriterContents(const EventInfo* evtInfo, 
-                                                             const ByteStreamMetadata* metaData)
+bool
+ByteStreamEventStorageOutputSvc::initDataWriterContents(
+    const EventInfo* evtInfo, const ByteStreamMetadata* metaData)
 {
-   // Initialize parameters
-   EventStorage::run_parameters_record runPara = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-   EventStorage::freeMetaDataStrings freeMetaDataStrings;
-   runPara.detector_mask_LS=0xFFFFFFFFFFFFFFFFULL;
-   runPara.detector_mask_MS=0xFFFFFFFFFFFFFFFFULL;
-   int run = 0;
-   int lumiNum = 0;
-   // The heirarchy of run/lumiblock number, GNARR
-   // 1) User override
-   // 2) Event data
-   // 3) File metadata
-   // 4) default = unknown = 0
-   if (m_run != 0) {
-      run = m_run;
-   } else if (evtInfo != 0) {
-      run = evtInfo->event_ID()->run_number();
-   } else if (metaData != 0) {
-      run = metaData->getRunNumber();
-   } 
-   runPara.run_number = run;
-
-   if (m_lumiBlockNumber != 0) {
-      lumiNum = m_lumiBlockNumber;
-   } else if (evtInfo != 0) {
-      lumiNum = evtInfo->event_ID()->lumi_block();
-   } else if (metaData != 0) {
-      lumiNum = metaData->getLumiBlock();
-   }
-
-   if (evtInfo != 0) {   
-      uint64_t result = evtInfo->event_ID()->detector_mask1();
-      result = result << 32;
-      result |= evtInfo->event_ID()->detector_mask0();
-      runPara.detector_mask_LS = result;
-      result = evtInfo->event_ID()->detector_mask3();
-      result = result << 32;
-      result |= evtInfo->event_ID()->detector_mask2();
-      runPara.detector_mask_MS = result;
-      
-      freeMetaDataStrings.push_back(evtInfo->event_type()->EventType::typeToString());
-   } else {
-      runPara.detector_mask_LS=0xFFFFFFFFFFFFFFFFULL;
-      runPara.detector_mask_MS=0xFFFFFFFFFFFFFFFFULL;
-   }
-   if (metaData != 0) {
-      runPara.max_events   = metaData->getMaxEvents();
-      runPara.rec_enable   = metaData->getRecEnable();
-      runPara.trigger_type = metaData->getTriggerType();
-      runPara.beam_type    = metaData->getBeamType();
-      runPara.beam_energy  = metaData->getBeamEnergy();
-      for (EventStorage::freeMetaDataStrings::const_iterator iter = metaData->getFreeMetaDataStrings().begin(),
-		      iterEnd = metaData->getFreeMetaDataStrings().end(); iter != iterEnd; iter++) {
-         if((*iter).find("Compression=") == std::string::npos) {
-            freeMetaDataStrings.push_back(*iter);
-         }
+  // Initialize parameters
+  EventStorage::run_parameters_record runPara = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  EventStorage::freeMetaDataStrings freeMetaDataStrings;
+  runPara.detector_mask_LS=0xFFFFFFFFFFFFFFFFULL;
+  runPara.detector_mask_MS=0xFFFFFFFFFFFFFFFFULL;
+  int run = 0;
+  int lumiNum = 0;
+  // The heirarchy of run/lumiblock number, GNARR
+  // 1) User override
+  // 2) Event data
+  // 3) File metadata
+  // 4) default = unknown = 0
+  if (m_run != 0) {
+    run = m_run;
+  } else if (evtInfo != 0) {
+    run = evtInfo->event_ID()->run_number();
+  } else if (metaData != 0) {
+    run = metaData->getRunNumber();
+  } 
+  runPara.run_number = run;
+
+  if (m_lumiBlockNumber != 0) {
+    lumiNum = m_lumiBlockNumber;
+  } else if (evtInfo != 0) {
+    lumiNum = evtInfo->event_ID()->lumi_block();
+  } else if (metaData != 0) {
+    lumiNum = metaData->getLumiBlock();
+  }
+
+  if (evtInfo != 0) {   
+    uint64_t result = evtInfo->event_ID()->detector_mask1();
+    result = result << 32;
+    result |= evtInfo->event_ID()->detector_mask0();
+    runPara.detector_mask_LS = result;
+    result = evtInfo->event_ID()->detector_mask3();
+    result = result << 32;
+    result |= evtInfo->event_ID()->detector_mask2();
+    runPara.detector_mask_MS = result;
+
+    freeMetaDataStrings.push_back(evtInfo->event_type()->EventType::typeToString());
+  } else {
+    runPara.detector_mask_LS=0xFFFFFFFFFFFFFFFFULL;
+    runPara.detector_mask_MS=0xFFFFFFFFFFFFFFFFULL;
+  }
+  if (metaData != 0) {
+    runPara.max_events   = metaData->getMaxEvents();
+    runPara.rec_enable   = metaData->getRecEnable();
+    runPara.trigger_type = metaData->getTriggerType();
+    runPara.beam_type    = metaData->getBeamType();
+    runPara.beam_energy  = metaData->getBeamEnergy();
+    for (EventStorage::freeMetaDataStrings::const_iterator iter = metaData->getFreeMetaDataStrings().begin(),
+        iterEnd = metaData->getFreeMetaDataStrings().end(); iter != iterEnd; iter++) {
+      if((*iter).find("Compression=") == std::string::npos) {
+        freeMetaDataStrings.push_back(*iter);
       }
-   } else {
-      ATH_MSG_DEBUG("Cannot retrieve MetaData");
-      metaData = 0;
-      runPara.max_events = 0;
-      runPara.rec_enable = 0;
-      runPara.trigger_type = 0;
-      runPara.beam_type = 0;
-      runPara.beam_energy = 0;
-   }
-   const TagInfo* tagInfo = 0;
-   ServiceHandle<StoreGateSvc> ds("DetectorStore", name());
-   if (ds.retrieve().isSuccess()) {
-      if (ds->retrieve(tagInfo).isFailure() || tagInfo == 0) {
-         ATH_MSG_DEBUG("Cannot retrieve TagInfo");
-      } else {
-         std::string tagName, tagValue;
-         if (metaData == 0) { // FIXME: Set TriggerType, BeamType?
-            tagName = "beam_energy";
-            tagInfo->findTag(tagName, tagValue);
-            runPara.beam_type = atof(tagValue.c_str());
-         }
-         tagName = "GeoAtlas";
-         tagInfo->findTag(tagName, tagValue);
-         freeMetaDataStrings.push_back(tagName + ": " + tagValue);
-         tagName = "IOVDbGlobalTag";
-         tagInfo->findTag(tagName, tagValue);
-         freeMetaDataStrings.push_back(tagName + ": " + tagValue);
+    }
+  } else {
+    ATH_MSG_DEBUG("Cannot retrieve MetaData");
+    metaData = 0;
+    runPara.max_events = 0;
+    runPara.rec_enable = 0;
+    runPara.trigger_type = 0;
+    runPara.beam_type = 0;
+    runPara.beam_energy = 0;
+  }
+  const TagInfo* tagInfo = 0;
+  ServiceHandle<StoreGateSvc> ds("DetectorStore", name());
+  if (ds.retrieve().isSuccess()) {
+    if (ds->retrieve(tagInfo).isFailure() || tagInfo == 0) {
+      ATH_MSG_DEBUG("Cannot retrieve TagInfo");
+    } else {
+      std::string tagName, tagValue;
+      if (metaData == 0) { // FIXME: Set TriggerType, BeamType?
+        tagName = "beam_energy";
+        tagInfo->findTag(tagName, tagValue);
+        runPara.beam_type = atof(tagValue.c_str());
       }
-   }
-
-   std::string fileNameCore;
-   EventStorage::CompressionType compression = m_compressEvents ? EventStorage::ZLIB : EventStorage::NONE;
-   int eventStorageVersion = 0;
-   if (m_eventStorageVersion.value() == "v5" || m_eventStorageVersion.value() == "run1") {
-       eventStorageVersion = 5;
-   }
-   if (!m_simpleFileName.value().empty()) {
-      fileNameCore = m_simpleFileName.value();
-      boost::shared_ptr<EventStorage::SimpleFileName> sfn(new EventStorage::SimpleFileName(m_simpleFileName.value()));
-      m_dataWriter = ByteStreamDataWriter::makeWriter(eventStorageVersion,
-                         m_inputDir.value(), sfn, runPara, m_projectTag.value(),
-                         m_streamType.value(), m_streamName.value(),
-                         m_streamType.value() + "_" + m_streamName.value(),
-                         lumiNum, m_appName.value(), freeMetaDataStrings,
-                         m_maxFileNE.value(), m_maxFileMB.value(), compression);
-   } else {
-      // construct file name
-      daq::RawFileName fileNameObj(m_projectTag.value(), run, m_streamType.value(), m_streamName.value(), lumiNum, m_appName.value());
-      fileNameCore = fileNameObj.fileNameCore();
-      m_dataWriter = ByteStreamDataWriter::makeWriter(eventStorageVersion,
-                         m_inputDir.value(), fileNameCore, runPara, freeMetaDataStrings,
-                         m_maxFileNE.value(), m_maxFileMB.value(), compression);
-   }
-   if (!m_dataWriter->good()) {
-      ATH_MSG_ERROR("Unable to initialize file");
-      return(false);
-   } else {
-      ATH_MSG_DEBUG("initialized file for with name " << fileNameCore);
-   }
-   return(true);
+      tagName = "GeoAtlas";
+      tagInfo->findTag(tagName, tagValue);
+      freeMetaDataStrings.push_back(tagName + ": " + tagValue);
+      tagName = "IOVDbGlobalTag";
+      tagInfo->findTag(tagName, tagValue);
+      freeMetaDataStrings.push_back(tagName + ": " + tagValue);
+    }
+  }
+
+  std::string fileNameCore;
+  EventStorage::CompressionType compression = m_compressEvents ? EventStorage::ZLIB : EventStorage::NONE;
+  int eventStorageVersion = 0;
+  if (m_eventStorageVersion.value() == "v5" || m_eventStorageVersion.value() == "run1") {
+    eventStorageVersion = 5;
+  }
+  if (!m_simpleFileName.value().empty()) {
+    fileNameCore = m_simpleFileName.value();
+    boost::shared_ptr<EventStorage::SimpleFileName> sfn(new EventStorage::SimpleFileName(m_simpleFileName.value()));
+    m_dataWriter = ByteStreamDataWriter::makeWriter(eventStorageVersion,
+        m_inputDir.value(), sfn, runPara, m_projectTag.value(),
+        m_streamType.value(), m_streamName.value(),
+        m_streamType.value() + "_" + m_streamName.value(),
+        lumiNum, m_appName.value(), freeMetaDataStrings,
+        m_maxFileNE.value(), m_maxFileMB.value(), compression);
+  } else {
+    // construct file name
+    daq::RawFileName fileNameObj(m_projectTag.value(), run, m_streamType.value(), m_streamName.value(), lumiNum, m_appName.value());
+    fileNameCore = fileNameObj.fileNameCore();
+    m_dataWriter = ByteStreamDataWriter::makeWriter(eventStorageVersion,
+        m_inputDir.value(), fileNameCore, runPara, freeMetaDataStrings,
+        m_maxFileNE.value(), m_maxFileMB.value(), compression);
+  }
+  if (!m_dataWriter->good()) {
+    ATH_MSG_ERROR("Unable to initialize file");
+    return(false);
+  } else {
+    ATH_MSG_DEBUG("initialized file for with name " << fileNameCore);
+  }
+  return(true);
 }
 
-//__________________________________________________________________________
+/******************************************************************************/
 // Read the next event.
-bool ByteStreamEventStorageOutputSvc::putEvent(RawEvent* re) {
-   if (!m_dataWriter) {
-      if (!initDataWriter()) {
-         ATH_MSG_ERROR("Failed to initialize DataWriter");
-         return(false);
-      }
-   }
-   uint32_t size = re->fragment_size_word();
-   // write
-   OFFLINE_FRAGMENTS_NAMESPACE::PointerType st;
-   re->start(st);
-   ATH_MSG_DEBUG("event size =  " << size << "  start = " << st);
-
-   // convert to different version
-   bool deleteBuffer = false;
-   if (m_eformatVersion.value() == "v40" or m_eformatVersion.value() == "run1") {
-       // allocate some extra space just in case
-       uint32_t bufSize = size + 128;
-       auto buf = new OFFLINE_FRAGMENTS_NAMESPACE::DataType[bufSize];
-
-       // This builds no-checksum headers, should use the same
-       // checksum type as original event
-       size = offline_eformat::old::convert_to_40(st, buf, bufSize);
-       if (size == 0) {
-           // not enough space in buffer
-           ATH_MSG_ERROR("Failed to convert event, buffer is too small");
-           delete [] buf;
-           return false;
-       }
-
-       st = buf;
-       deleteBuffer = true;
-       ATH_MSG_DEBUG("event size after conversion =  " << size << "  version = " << st[3]);
-   }
-
-   if (m_dataWriter->putData(sizeof(OFFLINE_FRAGMENTS_NAMESPACE::DataType) * size,
-	   reinterpret_cast<void*>(const_cast<OFFLINE_FRAGMENTS_NAMESPACE::DataType*>(st))) != EventStorage::DWOK) {
-      ATH_MSG_ERROR("Failed to write event to DataWriter");
-      if (deleteBuffer) delete [] st;
+bool
+ByteStreamEventStorageOutputSvc::putEvent(RawEvent* re)
+{
+  if (!m_dataWriter) {
+    if (!initDataWriter()) {
+      ATH_MSG_ERROR("Failed to initialize DataWriter");
       return(false);
-   }
-   ++m_totalEventCounter;
-   if (deleteBuffer) delete [] st;
-   return(true);
+    }
+  }
+  uint32_t size = re->fragment_size_word();
+  // write
+  OFFLINE_FRAGMENTS_NAMESPACE::PointerType st;
+  re->start(st);
+  ATH_MSG_DEBUG("event size =  " << size << "  start = " << st);
+
+  // convert to different version
+  bool deleteBuffer = false;
+  if (m_eformatVersion.value() == "v40" or m_eformatVersion.value() == "run1") {
+    // allocate some extra space just in case
+    uint32_t bufSize = size + 128;
+    auto buf = new OFFLINE_FRAGMENTS_NAMESPACE::DataType[bufSize];
+
+    // This builds no-checksum headers, should use the same
+    // checksum type as original event
+    size = offline_eformat::old::convert_to_40(st, buf, bufSize);
+    if (size == 0) {
+      // not enough space in buffer
+      ATH_MSG_ERROR("Failed to convert event, buffer is too small");
+      delete [] buf;
+      return false;
+    }
+
+    st = buf;
+    deleteBuffer = true;
+    ATH_MSG_DEBUG("event size after conversion =  " << size << "  version = " << st[3]);
+  }
+
+  if (m_dataWriter->putData(sizeof(OFFLINE_FRAGMENTS_NAMESPACE::DataType) * size,
+        reinterpret_cast<void*>(const_cast<OFFLINE_FRAGMENTS_NAMESPACE::DataType*>(st))) != EventStorage::DWOK) {
+    ATH_MSG_ERROR("Failed to write event to DataWriter");
+    if (deleteBuffer) delete [] st;
+    return(false);
+  }
+  ++m_totalEventCounter;
+  if (deleteBuffer) delete [] st;
+  return(true);
 }
-//__________________________________________________________________________
-StatusCode ByteStreamEventStorageOutputSvc::queryInterface(const InterfaceID& riid, void** ppvInterface) {
-   if (ByteStreamOutputSvc::interfaceID().versionMatch(riid)) {
-      *ppvInterface = dynamic_cast<ByteStreamOutputSvc*>(this);
-   } else {
-      // Interface is not directly available: try out a base class
-      return(::AthService::queryInterface(riid, ppvInterface));
-   }
-   addRef();
-   return(StatusCode::SUCCESS);
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageOutputSvc::queryInterface(
+    const InterfaceID& riid, void** ppvInterface)
+{
+  if (ByteStreamOutputSvc::interfaceID().versionMatch(riid)) {
+    *ppvInterface = dynamic_cast<ByteStreamOutputSvc*>(this);
+  } else {
+    // Interface is not directly available: try out a base class
+    return(::AthService::queryInterface(riid, ppvInterface));
+  }
+  addRef();
+  return(StatusCode::SUCCESS);
 }
-//__________________________________________________________________________
-StatusCode ByteStreamEventStorageOutputSvc::io_reinit() {
-   ATH_MSG_INFO("I/O reinitialization...");
-   ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", name());
-   if (!iomgr.retrieve().isSuccess()) {
-      ATH_MSG_FATAL("Could not retrieve IoComponentMgr !");
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamEventStorageOutputSvc::io_reinit()
+{
+  ATH_MSG_INFO("I/O reinitialization...");
+  ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", name());
+  if (!iomgr.retrieve().isSuccess()) {
+    ATH_MSG_FATAL("Could not retrieve IoComponentMgr !");
+    return(StatusCode::FAILURE);
+  }
+  if (!iomgr->io_hasitem(this)) {
+    ATH_MSG_FATAL("IoComponentMgr does not know about myself !");
+    return(StatusCode::FAILURE);
+  }
+  if (!m_simpleFileName.value().empty()) {
+    std::string outputFile = m_simpleFileName.value();
+    ATH_MSG_INFO("I/O reinitialization, file = "  << outputFile);
+    std::string &fname = outputFile;
+    if (!iomgr->io_contains(this, fname)) {
+      ATH_MSG_ERROR("IoComponentMgr does not know about [" << fname << "] !");
       return(StatusCode::FAILURE);
-   }
-   if (!iomgr->io_hasitem(this)) {
-      ATH_MSG_FATAL("IoComponentMgr does not know about myself !");
+    }
+    if (!iomgr->io_retrieve(this, fname).isSuccess()) {
+      ATH_MSG_FATAL("Could not retrieve new value for [" << fname << "] !");
       return(StatusCode::FAILURE);
-   }
-   if (!m_simpleFileName.value().empty()) {
-      std::string outputFile = m_simpleFileName.value();
-      ATH_MSG_INFO("I/O reinitialization, file = "  << outputFile);
-      std::string &fname = outputFile;
-      if (!iomgr->io_contains(this, fname)) {
-         ATH_MSG_ERROR("IoComponentMgr does not know about [" << fname << "] !");
-         return(StatusCode::FAILURE);
-      }
-      if (!iomgr->io_retrieve(this, fname).isSuccess()) {
-         ATH_MSG_FATAL("Could not retrieve new value for [" << fname << "] !");
-         return(StatusCode::FAILURE);
-      }
-      // all good... copy over.
-      // modify directory
-      m_inputDir.setValue(outputFile.substr(0, outputFile.find_last_of("/")));
-      // FIXME: modify file name, not done for now because of IoUtils.update_io_registry vs. merge conflict.
-      //m_simpleFileName.setValue(outputFile.substr(outputFile.find_last_of("/") + 1));
-   }
-   ATH_MSG_DEBUG("Deleting DataWriter");
-   m_dataWriter.reset();
-   return(this->reinit());
+    }
+    // all good... copy over.
+    // modify directory
+    m_inputDir.setValue(outputFile.substr(0, outputFile.find_last_of("/")));
+    // FIXME: modify file name, not done for now because of IoUtils.update_io_registry vs. merge conflict.
+    //m_simpleFileName.setValue(outputFile.substr(outputFile.find_last_of("/") + 1));
+  }
+  ATH_MSG_DEBUG("Deleting DataWriter");
+  m_dataWriter.reset();
+  return(this->reinit());
 }
diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.h b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.h
index d469adca666..9bf035bf44f 100644
--- a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.h
+++ b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageOutputSvc.h
@@ -1,6 +1,6 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
-*/
+   Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+   */
 
 #ifndef BYTESTREAMEVENTSTORAGEOUTPUTSVC_H
 #define BYTESTREAMEVENTSTORAGEOUTPUTSVC_H
@@ -21,71 +21,74 @@
 #include "GaudiKernel/IIoComponent.h"
 #include "GaudiKernel/ServiceHandle.h"
 
+
 class EventInfo;
 class ByteStreamMetadata;
 
+
 /** @class ByteStreamEventStorageOutputSvc
  *  @brief This class provides the services for writing FullEventFragment into file.
  *  This class implements the interface ByteStreamOutputSvc for the conversion service to write the output.
  **/
-class ByteStreamEventStorageOutputSvc : public ByteStreamOutputSvc, virtual public IIoComponent {
+class ByteStreamEventStorageOutputSvc
+:         public ByteStreamOutputSvc
+, virtual public IIoComponent
+{
 public:
-   /// Constructors:
-   ByteStreamEventStorageOutputSvc(const std::string& name, ISvcLocator* svcloc);
+  /// Constructors:
+  ByteStreamEventStorageOutputSvc(const std::string& name, ISvcLocator* pSvcLocator);
+
+  /// Destructor.
+  virtual ~ByteStreamEventStorageOutputSvc();
 
-   /// Destructor.
-   virtual ~ByteStreamEventStorageOutputSvc();
+  /// Required of all Gaudi Services
+  virtual StatusCode initialize();
+  virtual StatusCode stop      ();
+  virtual StatusCode finalize  ();
 
-   /// Required of all Gaudi Services
-   virtual StatusCode initialize();
-   /// Required of all Gaudi Services
-   virtual StatusCode stop();
-   virtual StatusCode finalize();
+  /// Required of all Gaudi services:  see Gaudi documentation for details
+  StatusCode queryInterface(const InterfaceID& riid, void** ppvInterface);
 
-   /// Required of all Gaudi services:  see Gaudi documentation for details
-   StatusCode queryInterface(const InterfaceID& riid, void** ppvInterface);
+  /// Implementation of the ByteStreamOutputSvc interface method putEvent.
+  virtual bool putEvent(RawEvent* re);
 
-   /// Implementation of the ByteStreamOutputSvc interface method putEvent.
-   virtual bool putEvent(RawEvent* re);
+  // Callback method to reinitialize the internal state of the component
+  // for I/O purposes (e.g. upon @c fork(2))
+  virtual StatusCode io_reinit();
 
-   /// Callback method to reinitialize the internal state of the component for I/O purposes (e.g. upon @c fork(2))
-   virtual StatusCode io_reinit();
 
 private: // internal member functions
-   /// reinitialize the service when a @c fork() occured/was-issued
-   StatusCode reinit();
-   void checkForUserMetadata(EventStorage::freeMetaDataStrings& freeMetaDataStrings);
+  /// reinitialize the service when a @c fork() occured/was-issued
+  StatusCode reinit();
+  void checkForUserMetadata(EventStorage::freeMetaDataStrings& freeMetaDataStrings);
 
 private: // data
-   int                m_totalEventCounter; //!< number of event counter
-   std::unique_ptr<ByteStreamDataWriter> m_dataWriter; //!< pointer to DataWriter
+  int                                   m_totalEventCounter; //!< number of event counter
+  std::unique_ptr<ByteStreamDataWriter> m_dataWriter;        //!< pointer to DataWriter
 
 private: // properties
-   Gaudi::Property<std::string>        m_inputDir;       //!< directory for the data files
-   Gaudi::Property<std::string>        m_projectTag;     //!< Project Tag
-   Gaudi::Property<std::string>        m_appName;        //!< Application Name
-   Gaudi::Property<std::string>        m_fileTag;        //!< File Tag
-   Gaudi::Property<std::string>        m_streamType;     //!< stream type
-   Gaudi::Property<std::string>        m_streamName;     //!< stream name
-   Gaudi::Property<int>       m_lumiBlockNumber;//!< luminosity block number
-   Gaudi::Property<int>       m_run;	           //!< run number
-
-   Gaudi::Property<bool>       m_dump;	   //!< Dump fragments
-   Gaudi::Property<bool>       m_writeEventless; //!< Write eventless files
-   Gaudi::Property<bool>       m_compressEvents; //!< Compress events
-
-   Gaudi::Property<unsigned int> m_maxFileMB;    //!< number of MB per file
-   Gaudi::Property<unsigned int> m_maxFileNE;    //!< number of events per file
-
-   Gaudi::Property<std::string>     m_eformatVersion;    //!< eformat event version to produce, "v40" for run1, or "current"
-   Gaudi::Property<std::string>     m_eventStorageVersion;  //!< EventStorage BS version to produce, "v5" for run1, or "current"
-   Gaudi::Property<std::string>     m_bsOutputStreamName;//!< stream name for multiple output
-   Gaudi::Property<std::string>     m_simpleFileName;    //!< use this string for filename, not from the "AgreedFileName"
+  Gaudi::Property<std::string>  m_inputDir;       //!< directory for the data files
+  Gaudi::Property<std::string>  m_projectTag;     //!< Project Tag
+  Gaudi::Property<std::string>  m_appName;        //!< Application Name
+  Gaudi::Property<std::string>  m_fileTag;        //!< File Tag
+  Gaudi::Property<std::string>  m_streamType;     //!< stream type
+  Gaudi::Property<std::string>  m_streamName;     //!< stream name
+  Gaudi::Property<int>          m_lumiBlockNumber;//!< luminosity block number
+  Gaudi::Property<int>          m_run;	          //!< run number
+  Gaudi::Property<bool>         m_dump;	          //!< Dump fragments
+  Gaudi::Property<bool>         m_writeEventless; //!< Write eventless files
+  Gaudi::Property<bool>         m_compressEvents; //!< Compress events
+  Gaudi::Property<unsigned int> m_maxFileMB;      //!< number of MB per file
+  Gaudi::Property<unsigned int> m_maxFileNE;      //!< number of events per file
+  Gaudi::Property<std::string>  m_eformatVersion; //!< eformat event version to produce, "v40" for run1, or "current"
+  Gaudi::Property<std::string>  m_eventStorageVersion;  //!< EventStorage BS version to produce, "v5" for run1, or "current"
+  Gaudi::Property<std::string>  m_bsOutputStreamName;//!< stream name for multiple output
+  Gaudi::Property<std::string>  m_simpleFileName; //!< use this string for filename, not from the "AgreedFileName"
 
 private: // internal helper functions
-   /// initialize EventStorage's DataWriter
-   bool initDataWriter();
-   bool initDataWriterContents(const EventInfo*, const ByteStreamMetadata* );
+  /// initialize EventStorage's DataWriter
+  bool initDataWriter();
+  bool initDataWriterContents(const EventInfo*, const ByteStreamMetadata* );
 };
 
-#endif
+#endif // BYTESTREAMEVENTSTORAGEOUTPUTSVC_H
diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.cxx b/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.cxx
index d9e65ca8e7c..b7d77ae6934 100644
--- a/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.cxx
+++ b/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.cxx
@@ -1,6 +1,6 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
-*/
+   Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+   */
 
 /** @file ByteStreamMetadataTool.cxx
  *  @brief This file contains the implementation for the ByteStreamMetadataTool class.
@@ -13,155 +13,168 @@
 #include "ByteStreamData/ByteStreamMetadataContainer.h"
 #include "StoreGate/StoreGateSvc.h"
 
-//___________________________________________________________________________
-ByteStreamMetadataTool::ByteStreamMetadataTool(const std::string& type,
-	const std::string& name,
-	const IInterface* parent) : AthAlgTool(type, name, parent), 
-		m_pMetaDataStore("StoreGateSvc/MetaDataStore", name), 
-		m_pInputStore("StoreGateSvc/InputMetaDataStore", name) {
-   declareInterface<IMetaDataTool>(this);
-}
 
-//___________________________________________________________________________
-ByteStreamMetadataTool::~ByteStreamMetadataTool() {
+/******************************************************************************/
+ByteStreamMetadataTool::ByteStreamMetadataTool(
+    const std::string& type,
+    const std::string& name,
+    const IInterface* parent)
+  : AthAlgTool(type, name, parent)
+  , m_metadataStore("StoreGateSvc/MetaDataStore", name)
+  , m_inputStore   ("StoreGateSvc/InputMetaDataStore", name)
+{
+  declareInterface<IMetaDataTool>(this);
 }
 
-//___________________________________________________________________________
-StatusCode ByteStreamMetadataTool::initialize() {
-   ATH_MSG_INFO("Initializing " << name() << " - package version " << PACKAGE_VERSION);
-   if (!::AthAlgTool::initialize().isSuccess()) {
-      ATH_MSG_FATAL("Cannot initialize AthService base class.");
-      return(StatusCode::FAILURE);
-   }
-
-   // locate the DetectorStore and initialize our local ptr
-   StatusCode status = m_pMetaDataStore.retrieve();
-   if (!status.isSuccess() || 0 == m_pMetaDataStore) {
-      ATH_MSG_ERROR("Could not find MetaDataStore");
-      return(status);
-   }
-   status = m_pInputStore.retrieve();
-   if (!status.isSuccess() || 0 == m_pInputStore) {
-      ATH_MSG_ERROR("Could not find InputMetaDataStore");
-      return(status);
-   }
-   return(StatusCode::SUCCESS);
+
+/******************************************************************************/
+ByteStreamMetadataTool::~ByteStreamMetadataTool()
+{}
+
+
+/******************************************************************************/
+StatusCode
+ByteStreamMetadataTool::initialize()
+{
+  ATH_MSG_INFO("Initializing " << name() << " - package version " << PACKAGE_VERSION);
+
+  ATH_CHECK(::AthAlgTool::initialize());
+  ATH_CHECK(m_metadataStore.retrieve());
+  ATH_CHECK(m_inputStore.retrieve());
+
+  return(StatusCode::SUCCESS);
 }
 
-//___________________________________________________________________________
-StatusCode ByteStreamMetadataTool::finalize() {
-   ATH_MSG_INFO("in finalize()");
-   return(::AthAlgTool::finalize());
+
+/******************************************************************************/
+StatusCode
+ByteStreamMetadataTool::finalize()
+{
+  ATH_MSG_INFO("in finalize()");
+  return(::AthAlgTool::finalize());
 }
 
 
-StatusCode ByteStreamMetadataTool::beginInputFile(const SG::SourceID&)
+/******************************************************************************/
+StatusCode
+ByteStreamMetadataTool::beginInputFile(const SG::SourceID&)
 {
-   return this->beginInputFile();
+  return this->beginInputFile();
 }
 
-StatusCode ByteStreamMetadataTool::beginInputFile()
+
+/******************************************************************************/
+StatusCode
+ByteStreamMetadataTool::beginInputFile()
 {
-   std::vector<std::string> vKeys;
-   std::set<std::string> keys;
-   m_pInputStore->keys<ByteStreamMetadata>(vKeys);
-   keys.insert(vKeys.begin(), vKeys.end());
-   m_pInputStore->keys<ByteStreamMetadataContainer>(vKeys);
-   keys.insert(vKeys.begin(), vKeys.end());
-
-   std::vector<ByteStreamMetadata*> copy;
-   std::set<std::string> transGuids;
-   for (std::set<std::string>::const_iterator keyIter = keys.begin(), keyEnd = keys.end();
-	      keyIter != keyEnd; keyIter++) {
-      ATH_MSG_DEBUG("Processing Input ByteStreamMetadata, key = " << *keyIter);
-      copy.clear();
-      if (m_pInputStore->contains<ByteStreamMetadata>(*keyIter)) {
-         std::list<SG::ObjectWithVersion<ByteStreamMetadata> > allVersions;
-         StatusCode status = m_pInputStore->retrieveAllVersions(allVersions, *keyIter);
-         if (!status.isSuccess()) {
-            ATH_MSG_ERROR("Could not find Input ByteStreamMetadata");
-            return StatusCode::FAILURE;
-         } else {
-            ATH_MSG_DEBUG("Found Input ByteStreamMetadata");
-         }
-         for (SG::ObjectWithVersion<ByteStreamMetadata>& obj : allVersions) {
-            copy.push_back(new ByteStreamMetadata(*obj.dataObject));
-         }
-      }
-      if (m_pInputStore->contains<ByteStreamMetadataContainer>(*keyIter)) {
-         std::list<SG::ObjectWithVersion<ByteStreamMetadataContainer> > allVersions;
-         StatusCode status = m_pInputStore->retrieveAllVersions(allVersions, *keyIter);
-         if (!status.isSuccess()) {
-            ATH_MSG_ERROR("Could not find Input ByteStreamMetadataContainer");
-            return StatusCode::FAILURE;
-         } else {
-            ATH_MSG_DEBUG("Found Input ByteStreamMetadataContainer");
-         }
-         for (SG::ObjectWithVersion<ByteStreamMetadataContainer>& obj : allVersions) {
-            const ByteStreamMetadataContainer& bsmdc = *obj.dataObject;
-            for (const ByteStreamMetadata* md : bsmdc) {
-              copy.push_back(new ByteStreamMetadata(*md));
-            }
-         }
+  std::set<std::string> keys = keysFromInput();
+
+  std::vector<std::unique_ptr<ByteStreamMetadata> > copy;
+  std::set<std::string> transGuids;
+
+
+  for(const auto& key : keys) {
+    ATH_MSG_DEBUG("Processing Input ByteStreamMetadata, key = " << key);
+    copy.clear();
+
+    if(m_inputStore->contains<ByteStreamMetadata>(key)) {
+
+      std::list<SG::ObjectWithVersion<ByteStreamMetadata> > allVersions;
+      ATH_CHECK(m_inputStore->retrieveAllVersions(allVersions, key));
+
+      for(SG::ObjectWithVersion<ByteStreamMetadata>& obj : allVersions)
+        copy.push_back(std::make_unique<ByteStreamMetadata>(*obj.dataObject));
+
+    }
+
+
+    if(m_inputStore->contains<ByteStreamMetadataContainer>(key)) {
+
+      std::list<SG::ObjectWithVersion<ByteStreamMetadataContainer> > allVersions;
+      ATH_CHECK(m_inputStore->retrieveAllVersions(allVersions, key));
+
+      for(SG::ObjectWithVersion<ByteStreamMetadataContainer>& obj : allVersions)
+        for(const ByteStreamMetadata* md : *obj.dataObject)
+          copy.push_back(std::make_unique<ByteStreamMetadata>(*md));
+    }
+
+
+    if(!copy.empty()) {
+
+      transGuids.clear();
+      // Check for existing container
+      ByteStreamMetadataContainer* bsmdc = 0;
+
+      if (m_metadataStore->contains<ByteStreamMetadataContainer>(key)) {
+
+        ATH_MSG_DEBUG("Pre-existing ByteStreamMetadataContainer found");
+        ATH_CHECK(m_metadataStore->retrieve(bsmdc, key));
+
+        for (const auto& bsmd : *bsmdc)
+          transGuids.insert(bsmd->getGuid());
+
+      } else {
+
+        bsmdc = new ByteStreamMetadataContainer;
+        ATH_CHECK(m_metadataStore->record(bsmdc, key));
+
       }
-      if (!copy.empty()) {
-         transGuids.clear();
-         // Check for existing container
-         ByteStreamMetadataContainer* bsmdc = 0;
-         if (m_pMetaDataStore->contains<ByteStreamMetadataContainer>(*keyIter)) {
-            ATH_MSG_DEBUG("Pre-existing ByteStreamMetadataContainer found");
-            StatusCode status = m_pMetaDataStore->retrieve(bsmdc, *keyIter);
-            if (!status.isSuccess()) {
-               ATH_MSG_ERROR("Could not retrieve " << *keyIter << " ByteStreamMetadataContainer");
-               return StatusCode::FAILURE;
-            }
-            for (ByteStreamMetadataContainer::const_iterator iter = bsmdc->begin(), iterEnd = bsmdc->end();
-	               iter != iterEnd; iter++) {
-               transGuids.insert((*iter)->getGuid());
-            }
-         } else {
-            bsmdc = new ByteStreamMetadataContainer;
-            StatusCode status = m_pMetaDataStore->record(bsmdc, *keyIter);
-            if (!status.isSuccess()) {
-               ATH_MSG_ERROR("Could not store ByteStreamMetadata in Metadata store");
-               return StatusCode::FAILURE;
-            } else {
-               ATH_MSG_DEBUG("ByteStreamMetadata copied to MetaDataStore");
-            }
-         }
-         for (std::vector<ByteStreamMetadata*>::iterator iter = copy.begin(), iterEnd = copy.end();
-	            iter != iterEnd; iter++) {
-            // Only insert new metadata records (with GUID not yet in container)
-            if (transGuids.insert((*iter)->getGuid()).second) {
-               bsmdc->push_back(*iter);
-               *iter = 0;
-            } else {
-               delete *iter; *iter = 0;
-            }
-         }
+
+      for(auto& pBSMD : copy) {
+        // Only insert new metadata records (with GUID not yet in container)
+        if(transGuids.insert(pBSMD->getGuid()).second)
+          bsmdc->push_back(std::move(pBSMD));
       }
-   }
-   return StatusCode::SUCCESS;
+    }
+  }
+
+  return StatusCode::SUCCESS;
 }
 
 
-StatusCode ByteStreamMetadataTool::endInputFile(const SG::SourceID&)
+
+/******************************************************************************/
+inline
+std::set<std::string>
+ByteStreamMetadataTool::keysFromInput() const
 {
-   return StatusCode::SUCCESS;
+  std::vector<std::string> vKeys;
+  std::set<std::string> keys;
+
+  m_inputStore->keys<ByteStreamMetadata>(vKeys);
+  keys.insert(vKeys.begin(), vKeys.end());
+
+  m_inputStore->keys<ByteStreamMetadataContainer>(vKeys);
+  keys.insert(vKeys.begin(), vKeys.end());
+
+  return keys;
 }
 
-StatusCode ByteStreamMetadataTool::endInputFile()
+
+/******************************************************************************/
+StatusCode
+ByteStreamMetadataTool::endInputFile(const SG::SourceID&)
 {
-   return StatusCode::SUCCESS;
+  return StatusCode::SUCCESS;
 }
 
-StatusCode ByteStreamMetadataTool::metaDataStop(const SG::SourceID&)
+
+StatusCode
+ByteStreamMetadataTool::endInputFile()
 {
-   return StatusCode::SUCCESS;
+  return StatusCode::SUCCESS;
 }
 
-StatusCode ByteStreamMetadataTool::metaDataStop()
+
+StatusCode
+ByteStreamMetadataTool::metaDataStop(const SG::SourceID&)
 {
-   return StatusCode::SUCCESS;
+  return StatusCode::SUCCESS;
 }
 
+
+StatusCode
+ByteStreamMetadataTool::metaDataStop()
+{
+  return StatusCode::SUCCESS;
+}
diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.h b/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.h
index 6a2ff656b36..98379a57ba4 100644
--- a/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.h
+++ b/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.h
@@ -8,6 +8,7 @@
 /** @file ByteStreamMetadataTool.h
  *  @brief This file contains the class definition for the ByteStreamMetadataTool class.
  *  @author Peter van Gemmeren <gemmeren@anl.gov>
+ *  @author Frank Berghaus <fberghaus@anl.gov>
  *  $Id: $
  **/
 
@@ -17,37 +18,48 @@
 #include "AthenaKernel/IMetaDataTool.h"
 
 #include <string>
+#include <set>
 
 class StoreGateSvc;
 
+
 /** @class ByteStreamMetadataTool
  *  @brief This class provides the MetaDataTool for ByteStreamMetadata objects
  **/
-class ByteStreamMetadataTool : public ::AthAlgTool,
-	virtual public IMetaDataTool {
+class ByteStreamMetadataTool
+:         public ::AthAlgTool,
+  virtual public IMetaDataTool
+{
 public: 
-   /// Standard Service Constructor
-   ByteStreamMetadataTool(const std::string& type, const std::string& name, const IInterface* parent);
-   /// Destructor
-   virtual ~ByteStreamMetadataTool();
-
-   /// Gaudi Service Interface method implementations:
-   StatusCode initialize();
-   StatusCode finalize();
-
-   /// Incident service handle listening for BeginInputFile and EndInputFile.
-   virtual StatusCode beginInputFile();
-   virtual StatusCode endInputFile();
-   virtual StatusCode metaDataStop(const SG::SourceID&);
-   virtual StatusCode beginInputFile(const SG::SourceID&);
-   virtual StatusCode endInputFile(const SG::SourceID&);
-   virtual StatusCode metaDataStop();
+  /// Standard Service Constructor
+  ByteStreamMetadataTool(const std::string& type, const std::string& name,
+      const IInterface* parent);
+
+
+  /// Destructor
+  virtual ~ByteStreamMetadataTool();
+
+
+  /// Gaudi Service Interface method implementations:
+  StatusCode initialize();
+  StatusCode finalize  ();
+
+
+  /// Incident service handle listening for BeginInputFile and EndInputFile.
+  virtual StatusCode beginInputFile();
+  virtual StatusCode beginInputFile(const SG::SourceID&);
+  virtual StatusCode metaDataStop  ();
+  virtual StatusCode metaDataStop  (const SG::SourceID&);
+  virtual StatusCode endInputFile  ();
+  virtual StatusCode endInputFile  (const SG::SourceID&);
+
 
 private:
-   typedef ServiceHandle<StoreGateSvc> StoreGateSvc_t;
-   StoreGateSvc_t m_pMetaDataStore;
-   StoreGateSvc_t m_pInputStore;
-};
+  typedef ServiceHandle<StoreGateSvc> StoreGateSvc_t;
+  StoreGateSvc_t m_metadataStore;
+  StoreGateSvc_t m_inputStore;
 
-#endif
+  std::set<std::string> keysFromInput() const;
+};
 
+#endif // BYTESTREAMMETADATATOOL_H
diff --git a/Event/ByteStreamCnvSvc/src/EventSelectorByteStream.cxx b/Event/ByteStreamCnvSvc/src/EventSelectorByteStream.cxx
index aeaa3f9091a..f4bf2ee6b2d 100644
--- a/Event/ByteStreamCnvSvc/src/EventSelectorByteStream.cxx
+++ b/Event/ByteStreamCnvSvc/src/EventSelectorByteStream.cxx
@@ -181,41 +181,6 @@ StatusCode EventSelectorByteStream::initialize() {
       return(StatusCode::FAILURE);
    }
 
-   // For backward compatibility, check InputSvc properties for bad events
-   ServiceHandle<IJobOptionsSvc> joSvc("JobOptionsSvc", name());
-   if (!joSvc.retrieve().isSuccess()) {
-      ATH_MSG_FATAL("Cannot get JobOptionsSvc.");
-      return(StatusCode::FAILURE);
-   }
-   typedef std::vector<const Property*> Properties_t;
-   const Properties_t* esProps = joSvc->getProperties("ByteStreamInputSvc");
-   if (esProps != 0) {
-      std::vector<const Property*>::const_iterator ii = esProps->begin();
-      while (ii != esProps->end()) {
-         IntegerProperty temp;
-         if ((*ii)->name() == "MaxBadEvents") {     // find it
-            if ((*ii)->load(temp)) {                // load it
-               if (temp.value() != -1) {            // check if it is set
-                  m_maxBadEvts = temp.value();
-                  ATH_MSG_INFO("Retrieved MaxBadEvents=" << m_maxBadEvts << " from ByteStreamInputSvc");
-               }
-            }
-         }
-         BooleanProperty temp2;
-         if ((*ii)->name() == "ProcessBadEvents") {     // find it
-            if ((*ii)->load(temp)) {                // load it
-               if (temp.value()) {            // check if it is set
-                  m_procBadEvent = temp.value();
-                  ATH_MSG_INFO("Retrieved ProcessBadEvents=" << m_procBadEvent << " from ByteStreamInputSvc");
-               }
-            }
-         }
-         ++ii;
-      }
-   } else {
-      ATH_MSG_WARNING("Did not find ByteStreamInputSvc jobOptions properties");
-   }
-   
    // Must happen before trying to open a file
    StatusCode risc = this->reinit();
 
diff --git a/Event/ByteStreamCnvSvcBase/share/testROBDataProviderSvcMT.py b/Event/ByteStreamCnvSvcBase/share/testROBDataProviderSvcMT.py
index db960851af8..80020fc7647 100644
--- a/Event/ByteStreamCnvSvcBase/share/testROBDataProviderSvcMT.py
+++ b/Event/ByteStreamCnvSvcBase/share/testROBDataProviderSvcMT.py
@@ -9,7 +9,6 @@ svcMgr.ByteStreamInputSvc.FullFileName = [ "/cvmfs/atlas-nightlies.cern.ch/repo/
 #svcMgr.ByteStreamInputSvc.FullFileName = [ "/afs/cern.ch/atlas/offline/test/daq.m4_combined.0020720.extract.L1TT-b00000010._0001.data" ]
 #svcMgr.ByteStreamInputSvc.FullFileName += [ "/afs/cern.ch/atlas/offline/test/daq.m4_combined.0020720.extract.L1TT-b00000010._0001.data" ]
 #svcMgr.EventSelector.InputCollections = [ "/afs/cern.ch/atlas/offline/test/daq.m4_combined.0020720.extract.L1TT-b00000010._0001.data" ]
-#svcMgr.ByteStreamInputSvc.MaxBadEvents = 1
 #svcMgr.ByteStreamInputSvc.ValidateEvent = False
 
 #from AthenaCommon.AppMgr import theApp
diff --git a/Event/ByteStreamData/ByteStreamData/ByteStreamMetadata.h b/Event/ByteStreamData/ByteStreamData/ByteStreamMetadata.h
index 15f6a5d43a2..83066ab18be 100644
--- a/Event/ByteStreamData/ByteStreamData/ByteStreamMetadata.h
+++ b/Event/ByteStreamData/ByteStreamData/ByteStreamMetadata.h
@@ -8,82 +8,116 @@
 /** @file ByteStreamMetadata.h
  *  @brief This file contains the class definition for the ByteStreamMetadata class.
  *  @author Peter van Gemmeren <gemmeren@anl.gov>
+ *  @author Frank Berghaus <fberghaus@anl.gov>
  *  $Id: ByteStreamMetadata.h,v 1.2 2009-04-02 14:47:40 gemmeren Exp $
  **/
 
 #include <vector>
 #include <string>
 #include <stdint.h>
+#include <iostream>
+
+namespace EventStorage { class DataReader; }
 
 /** @class ByteStreamMetadata 
  *  @brief This class is the StoreGate data object for bytestream metadata. 
  **/
 class ByteStreamMetadata {
-public: // Constructor and Destructor
-   ByteStreamMetadata();
-   // 64 bit det mask constructor
-   ByteStreamMetadata(unsigned int runNumber,
-	   unsigned int numEvents,
-	   unsigned int maxEvents,
-	   unsigned int recEnable,
-	   unsigned int triggerType,
-	   uint64_t detectorMask,
-	   unsigned int beamType,
-	   unsigned int beamEnergy,
-	   const std::string& guid,
-	   const std::string& stream,
-	   const std::string& project,
-	   unsigned int lumiBlock,
-	   const std::vector<std::string>& freeMetaDataStrings);
-   // 128 bit det mask constructor
-   ByteStreamMetadata(unsigned int runNumber,
-	   unsigned int numEvents,
-	   unsigned int maxEvents,
-	   unsigned int recEnable,
-	   unsigned int triggerType,
-	   uint64_t detectorMask,
-	   uint64_t detectorMask2,
-	   unsigned int beamType,
-	   unsigned int beamEnergy,
-	   const std::string& guid,
-	   const std::string& stream,
-	   const std::string& project,
-	   unsigned int lumiBlock,
-	   const std::vector<std::string>& freeMetaDataStrings);
-   virtual ~ByteStreamMetadata();
-
-   unsigned int getRunNumber() const;
-   unsigned int getNumEvents() const;
-   unsigned int getMaxEvents() const;
-   unsigned int getRecEnable() const;
-   unsigned int getTriggerType() const;
-   uint64_t getDetectorMask() const;
-   uint64_t getDetectorMask2() const;
-   unsigned int getBeamType() const;
-   unsigned int getBeamEnergy() const;
-   const std::string& getGuid() const;
-   const std::string& getStream() const;
-   const std::string& getProject() const;
-   unsigned int getLumiBlock() const;
-   const std::vector<std::string>& getFreeMetaDataStrings() const;
+public:
+
+
+  ByteStreamMetadata();
+
+
+  /**
+   * Constructure for 64 bit det mask constructor
+   */
+  ByteStreamMetadata(
+      unsigned int       runNumber,
+      unsigned int       numEvents,
+      unsigned int       maxEvents,
+      unsigned int       recEnable,
+      unsigned int       triggerType,
+      uint64_t           detectorMask,
+      unsigned int       beamType,
+      unsigned int       beamEnergy,
+      const std::string& guid,
+      const std::string& stream,
+      const std::string& project,
+      unsigned int       lumiBlock,
+      const std::vector<std::string>& freeMetaDataStrings);
+
+
+  /**
+   * Constructor using 128 bit det mask
+   */
+  ByteStreamMetadata(
+      unsigned int       runNumber,
+      unsigned int       numEvents,
+      unsigned int       maxEvents,
+      unsigned int       recEnable,
+      unsigned int       triggerType,
+      uint64_t           detectorMask,
+      uint64_t           detectorMask2,
+      unsigned int       beamType,
+      unsigned int       beamEnergy,
+      const std::string& guid,
+      const std::string& stream,
+      const std::string& project,
+      unsigned int       lumiBlock,
+      const std::vector<std::string>& freeMetaDataStrings);
+
+  /**
+   * Construct bytestream metadata directly from data reader provided by online
+   * EventStorage
+   */
+  ByteStreamMetadata(EventStorage::DataReader& reader);
+
+
+  virtual ~ByteStreamMetadata();
+
+
+  unsigned int       getRunNumber() const;
+  unsigned int       getNumEvents() const;
+  unsigned int       getMaxEvents() const;
+  unsigned int       getRecEnable() const;
+  unsigned int       getTriggerType() const;
+  uint64_t           getDetectorMask() const;
+  uint64_t           getDetectorMask2() const;
+  unsigned int       getBeamType() const;
+  unsigned int       getBeamEnergy() const;
+  const std::string& getGuid() const;
+  const std::string& getStream() const;
+  const std::string& getProject() const;
+  unsigned int       getLumiBlock() const;
+  const std::vector<std::string>& getFreeMetaDataStrings() const;
+
+
+  /**
+   * pretty print bytestream metadata content
+   */
+  friend std::ostream& operator<<(std::ostream& os,
+      const ByteStreamMetadata& bsmd);
+
 
 private:
-   unsigned int m_runNumber;
-   unsigned int m_numEvents;
-   unsigned int m_maxEvents;
-   unsigned int m_recEnable;
-   unsigned int m_triggerType;
-   uint64_t m_detectorMask;
-   uint64_t m_detectorMask2;
-   unsigned int m_beamType;
-   unsigned int m_beamEnergy;
-   std::string m_guid;
-   std::string m_stream;
-   std::string m_project;
-   unsigned int m_lumiBlock;
-   std::vector<std::string> m_freeMetaDataStrings;
+  unsigned int m_runNumber;
+  unsigned int m_numEvents;
+  unsigned int m_maxEvents;
+  unsigned int m_recEnable;
+  unsigned int m_triggerType;
+  uint64_t     m_detectorMask;
+  uint64_t     m_detectorMask2;
+  unsigned int m_beamType;
+  unsigned int m_beamEnergy;
+  std::string  m_guid;
+  std::string  m_stream;
+  std::string  m_project;
+  unsigned int m_lumiBlock;
+  std::vector<std::string> m_freeMetaDataStrings;
 };
 
+
 #include "AthenaKernel/CLASS_DEF.h"
 CLASS_DEF(ByteStreamMetadata, 170625359, 1)
 #endif
diff --git a/Event/ByteStreamData/ByteStreamData/ByteStreamMetadataContainer.h b/Event/ByteStreamData/ByteStreamData/ByteStreamMetadataContainer.h
index 70f4c3064c4..19451f3a070 100644
--- a/Event/ByteStreamData/ByteStreamData/ByteStreamMetadataContainer.h
+++ b/Event/ByteStreamData/ByteStreamData/ByteStreamMetadataContainer.h
@@ -17,16 +17,11 @@
 /** @class ByteStreamMetadataContainer 
  *  @brief This class is the StoreGate data object for bytestream metadata. 
  **/
-class ByteStreamMetadataContainer : public DataVector<ByteStreamMetadata> {
-};
+class ByteStreamMetadataContainer
+  : public DataVector<ByteStreamMetadata>
+{};
 
 #include "AthenaKernel/CLASS_DEF.h"
 CLASS_DEF(ByteStreamMetadataContainer, 1076128893, 1)
-#ifndef XAOD_STANDALONE
-#include "AthenaKernel/MetaCont.h"
-CLASS_DEF( MetaCont<ByteStreamMetadataContainer> , 1174128703 , 1 )
-#include "AthenaKernel/BaseInfo.h"
-SG_BASE( MetaCont<ByteStreamMetadataContainer>, MetaContBase );
-#endif // not XAOD_STANDALONE
 
 #endif
diff --git a/Event/ByteStreamData/CMakeLists.txt b/Event/ByteStreamData/CMakeLists.txt
index 04342fcf2d5..4b0fb94f8f2 100644
--- a/Event/ByteStreamData/CMakeLists.txt
+++ b/Event/ByteStreamData/CMakeLists.txt
@@ -13,7 +13,7 @@ atlas_depends_on_subdirs(
    Control/AthContainers )
 
 # External dependencies:
-find_package( tdaq-common )
+find_package( tdaq-common COMPONENTS DataReader )
 
 # Treat tdaq-common as an optional dependency:
 set( extra_inc )
diff --git a/Event/ByteStreamData/src/ByteStreamMetadata.cxx b/Event/ByteStreamData/src/ByteStreamMetadata.cxx
index 6a9c2d1c500..360ca2bc667 100644
--- a/Event/ByteStreamData/src/ByteStreamMetadata.cxx
+++ b/Event/ByteStreamData/src/ByteStreamMetadata.cxx
@@ -10,122 +10,207 @@
 
 #include "ByteStreamData/ByteStreamMetadata.h"
 
-//______________________________________________________________________________
-ByteStreamMetadata::ByteStreamMetadata() : m_runNumber(0U),
-	m_numEvents(0U),
-	m_maxEvents(0U),
-	m_recEnable(0U),
-	m_triggerType(0U),
-	m_detectorMask(0L),
-	m_detectorMask2(0L),
-	m_beamType(0U),
-	m_beamEnergy(0U),
-	m_guid(),
-	m_stream(),
-	m_project(),
-	m_lumiBlock(0U),
-	m_freeMetaDataStrings() {
-}
-//______________________________________________________________________________
-ByteStreamMetadata::ByteStreamMetadata(unsigned int runNumber,
-	unsigned int numEvents,
-	unsigned int maxEvents,
-	unsigned int recEnable,
-	unsigned int triggerType,
-	uint64_t detectorMask,
-	unsigned int beamType,
-	unsigned int beamEnergy,
-	const std::string& guid,
-	const std::string& stream,
-	const std::string& project,
-	unsigned int lumiBlock,
-	const std::vector<std::string>& freeMetaDataStrings) : m_runNumber(runNumber),
-		m_numEvents(numEvents),
-		m_maxEvents(maxEvents),
-		m_recEnable(recEnable),
-		m_triggerType(triggerType),
-		m_detectorMask(detectorMask),
-		m_detectorMask2(0),
-		m_beamType(beamType),
-		m_beamEnergy(beamEnergy),
-		m_guid(guid),
-		m_stream(stream),
-		m_project(project),
-		m_lumiBlock(lumiBlock),
-		m_freeMetaDataStrings(freeMetaDataStrings) {
-}
-//______________________________________________________________________________
+#include "EventStorage/DataReader.h"
+
+#include <bitset>
+
+/******************************************************************************/
+ByteStreamMetadata::ByteStreamMetadata()
+  : m_runNumber(0U)
+  , m_numEvents(0U)
+  , m_maxEvents(0U)
+  , m_recEnable(0U)
+  , m_triggerType(0U)
+  , m_detectorMask(0L)
+  , m_detectorMask2(0L)
+  , m_beamType(0U)
+  , m_beamEnergy(0U)
+  , m_guid()
+  , m_stream()
+  , m_project()
+  , m_lumiBlock(0U)
+  , m_freeMetaDataStrings()
+{}
+
+
+/******************************************************************************/
 ByteStreamMetadata::ByteStreamMetadata(unsigned int runNumber,
-	unsigned int numEvents,
-	unsigned int maxEvents,
-	unsigned int recEnable,
-	unsigned int triggerType,
-	uint64_t detectorMask,
-        uint64_t detectorMask2,
-	unsigned int beamType,
-	unsigned int beamEnergy,
-	const std::string& guid,
-	const std::string& stream,
-	const std::string& project,
-	unsigned int lumiBlock,
-	const std::vector<std::string>& freeMetaDataStrings) : m_runNumber(runNumber),
-		m_numEvents(numEvents),
-		m_maxEvents(maxEvents),
-		m_recEnable(recEnable),
-		m_triggerType(triggerType),
-		m_detectorMask(detectorMask),
-		m_detectorMask2(detectorMask2),
-		m_beamType(beamType),
-		m_beamEnergy(beamEnergy),
-		m_guid(guid),
-		m_stream(stream),
-		m_project(project),
-		m_lumiBlock(lumiBlock),
-		m_freeMetaDataStrings(freeMetaDataStrings) {
-}
-//______________________________________________________________________________
-ByteStreamMetadata::~ByteStreamMetadata() {
-}
-unsigned int ByteStreamMetadata::getRunNumber() const {
-   return(m_runNumber);
-}
-unsigned int ByteStreamMetadata::getNumEvents() const {
-   return(m_numEvents);
-}
-unsigned int ByteStreamMetadata::getMaxEvents() const {
-   return(m_maxEvents);
-}
-unsigned int ByteStreamMetadata::getRecEnable() const {
-   return(m_recEnable);
-}
-unsigned int ByteStreamMetadata::getTriggerType() const {
-   return(m_triggerType);
-}
-uint64_t ByteStreamMetadata::getDetectorMask() const {
-   return(m_detectorMask);
-}
-uint64_t ByteStreamMetadata::getDetectorMask2() const {
-   return(m_detectorMask2);
-}
-unsigned int ByteStreamMetadata::getBeamType() const {
-   return(m_beamType);
-}
-unsigned int ByteStreamMetadata::getBeamEnergy() const {
-   return(m_beamEnergy);
-}
-const std::string& ByteStreamMetadata::getGuid() const {
-   return(m_guid);
-}
-const std::string& ByteStreamMetadata::getStream() const {
-   return(m_stream);
-}
-const std::string& ByteStreamMetadata::getProject() const {
-   return(m_project);
-}
-unsigned int ByteStreamMetadata::getLumiBlock() const {
-   return(m_lumiBlock);
+    unsigned int numEvents,
+    unsigned int maxEvents,
+    unsigned int recEnable,
+    unsigned int triggerType,
+    uint64_t detectorMask,
+    unsigned int beamType,
+    unsigned int beamEnergy,
+    const std::string& guid,
+    const std::string& stream,
+    const std::string& project,
+    unsigned int lumiBlock,
+    const std::vector<std::string>& freeMetaDataStrings)
+  : m_runNumber(runNumber)
+  , m_numEvents(numEvents)
+  , m_maxEvents(maxEvents)
+  , m_recEnable(recEnable)
+  , m_triggerType(triggerType)
+  , m_detectorMask(detectorMask)
+  , m_detectorMask2(0)
+  , m_beamType(beamType)
+  , m_beamEnergy(beamEnergy)
+  , m_guid(guid)
+  , m_stream(stream)
+  , m_project(project)
+  , m_lumiBlock(lumiBlock)
+  , m_freeMetaDataStrings(freeMetaDataStrings)
+{}
+
+
+/******************************************************************************/
+ByteStreamMetadata::ByteStreamMetadata(
+    unsigned int runNumber,
+    unsigned int numEvents,
+    unsigned int maxEvents,
+    unsigned int recEnable,
+    unsigned int triggerType,
+    uint64_t detectorMask,
+    uint64_t detectorMask2,
+    unsigned int beamType,
+    unsigned int beamEnergy,
+    const std::string& guid,
+    const std::string& stream,
+    const std::string& project,
+    unsigned int lumiBlock,
+    const std::vector<std::string>& freeMetaDataStrings)
+  : m_runNumber(runNumber)
+  , m_numEvents(numEvents)
+  , m_maxEvents(maxEvents)
+  , m_recEnable(recEnable)
+  , m_triggerType(triggerType)
+  , m_detectorMask(detectorMask)
+  , m_detectorMask2(detectorMask2)
+  , m_beamType(beamType)
+  , m_beamEnergy(beamEnergy)
+  , m_guid(guid)
+  , m_stream(stream)
+  , m_project(project)
+  , m_lumiBlock(lumiBlock)
+  , m_freeMetaDataStrings(freeMetaDataStrings)
+{}
+
+
+/******************************************************************************/
+ByteStreamMetadata::ByteStreamMetadata(EventStorage::DataReader& reader)
+  : m_runNumber          (reader.runNumber())
+  , m_numEvents          (reader.eventsInFile())
+  , m_maxEvents          (reader.maxEvents())
+  , m_recEnable          (reader.recEnable())
+  , m_triggerType        (reader.triggerType())
+  , m_detectorMask       (0)
+  , m_detectorMask2      (0)
+  , m_beamType           (reader.beamType())
+  , m_beamEnergy         (reader.beamEnergy())
+  , m_guid               (reader.GUID())
+  , m_stream             (reader.stream())
+  , m_project            (reader.projectTag())
+  , m_lumiBlock          (reader.lumiblockNumber())
+  , m_freeMetaDataStrings(reader.freeMetaDataStrings())
+{
+  // default goes into ByteStreamMetadata
+  std::bitset<64> word1;
+  std::bitset<64> word2;
+  for (unsigned int i=0; i<64; ++i) {
+    word1[i] = reader.detectorMask()[i];
+    word2[i] = reader.detectorMask()[i+64];
+  }
+  m_detectorMask  = word1.to_ulong();
+  m_detectorMask2 = word2.to_ulong();
 }
-const std::vector<std::string>& ByteStreamMetadata::getFreeMetaDataStrings() const {
-   return(m_freeMetaDataStrings);
+
+
+/******************************************************************************/
+ByteStreamMetadata::~ByteStreamMetadata() {}
+
+
+/******************************************************************************/
+// TODO: inline these getters
+unsigned int
+ByteStreamMetadata::getRunNumber() const
+{return(m_runNumber);}
+
+unsigned int
+ByteStreamMetadata::getNumEvents() const
+{return(m_numEvents);}
+
+unsigned int
+ByteStreamMetadata::getMaxEvents() const
+{return(m_maxEvents);}
+
+unsigned int
+ByteStreamMetadata::getRecEnable() const
+{return(m_recEnable);}
+
+unsigned int
+ByteStreamMetadata::getTriggerType() const
+{return(m_triggerType);}
+
+uint64_t
+ByteStreamMetadata::getDetectorMask() const
+{return(m_detectorMask);}
+
+uint64_t
+ByteStreamMetadata::getDetectorMask2() const
+{return(m_detectorMask2);}
+
+unsigned int
+ByteStreamMetadata::getBeamType() const
+{return(m_beamType);}
+
+unsigned int
+ByteStreamMetadata::getBeamEnergy() const
+{return(m_beamEnergy);}
+
+const std::string&
+ByteStreamMetadata::getGuid() const
+{return(m_guid);}
+
+const std::string&
+ByteStreamMetadata::getStream() const
+{return(m_stream);}
+
+const std::string&
+ByteStreamMetadata::getProject() const
+{return(m_project);}
+
+unsigned int
+ByteStreamMetadata::getLumiBlock() const
+{return(m_lumiBlock);}
+
+const std::vector<std::string>&
+ByteStreamMetadata::getFreeMetaDataStrings() const
+{return(m_freeMetaDataStrings);}
+
+
+/******************************************************************************/
+std::ostream& operator<<(std::ostream& os, const ByteStreamMetadata& bsmd) {
+  std::bitset<64> word1(bsmd.getDetectorMask());
+  std::bitset<64> word2(bsmd.getDetectorMask2());
+
+  os << "  runNumber:           " << bsmd.getRunNumber()   << '\n'
+     << "  numEvents:           " << bsmd.getNumEvents()   << '\n'
+     << "  m_maxEvents:         " << bsmd.getMaxEvents()   << '\n'
+     << "  recEnable:           " << bsmd.getRecEnable()   << '\n'
+     << "  triggerType:         " << bsmd.getTriggerType() << '\n'
+     << "  detectorMask:        " << word1                 << '\n'
+     << "  detectorMask2:       " << word2                 << '\n'
+     << "  beamType:            " << bsmd.getBeamType()    << '\n'
+     << "  beamEnergy:          " << bsmd.getBeamEnergy()  << '\n'
+     << "  guid:                " << bsmd.getGuid()        << '\n'
+     << "  stream:              " << bsmd.getStream()      << '\n'
+     << "  project:             " << bsmd.getProject()     << '\n'
+     << "  lumiBlock:           " << bsmd.getLumiBlock()   << '\n';
+
+  os << "  freeMetaDataStrings: ";
+  for (const std::string& key : bsmd.getFreeMetaDataStrings())
+    os <<  key << "  ";
+
+  return os;
 }
-//______________________________________________________________________________
diff --git a/Event/ByteStreamTest/share/BadEvents.py b/Event/ByteStreamTest/share/BadEvents.py
index 759d2456f7e..7e3bc8967b1 100755
--- a/Event/ByteStreamTest/share/BadEvents.py
+++ b/Event/ByteStreamTest/share/BadEvents.py
@@ -12,7 +12,7 @@ svcMgr = theApp.serviceMgr()
 theApp.EvtMax = 500
 
 svcMgr.EventSelector.Input += ["/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/TrigP1Test/data17_13TeV.00327265.physics_EnhancedBias.merge.RAW._lb0100._SFO-1._0001.1"]
-svcMgr.ByteStreamInputSvc.MaxBadEvents = 10
+svcMgr.EventSelector.MaxBadEvents = 10
 
 #MessageSvc.OutputLevel = DEBUG
 svcMgr.EventSelector.OutputLevel = DEBUG
diff --git a/Event/ByteStreamTest/share/ByteStreamTestBadEvents.ref b/Event/ByteStreamTest/share/ByteStreamTestBadEvents.ref
index fe1a6fd577e..5fcb078c79f 100644
--- a/Event/ByteStreamTest/share/ByteStreamTestBadEvents.ref
+++ b/Event/ByteStreamTest/share/ByteStreamTestBadEvents.ref
@@ -1,599 +1,8 @@
-Fri Jan 24 17:44:11 CET 2020
-Preloading tcmalloc_minimal.so
-Py:Athena            INFO including file "AthenaCommon/Preparation.py"
-Py:Athena            INFO using release [WorkDir-22.0.9] [x86_64-centos7-gcc8-opt] [atlas-work3g/b1aa4d492c9] -- built on [2020-01-24T1658]
-Py:Athena            INFO including file "AthenaCommon/Atlas.UnixStandardJob.py"
-Py:Athena            INFO executing ROOT6Setup
-Py:Athena            INFO including file "AthenaCommon/Execution.py"
-Py:Athena            INFO including file "ByteStreamTest/BadEvents.py"
-Py:ConfigurableDb    INFO Read module info for 5625 configurables from 37 genConfDb files
-Py:ConfigurableDb    INFO No duplicates have been found: that's good !
-Py:Athena            INFO including file "AthenaCommon/runbatch.py"
-Warning in <TInterpreter::ReadRootmapFile>: class  CP::IMuonCalibrationAndSmearingTool found in libMuonMomentumCorrectionsDict.so  is already in libMuonAnalysisInterfacesDict.so 
-Warning in <TInterpreter::ReadRootmapFile>: class  CP::IMuonSelectionTool found in libMuonSelectorToolsDict.so  is already in libMuonAnalysisInterfacesDict.so 
-ApplicationMgr       INFO Updating Gaudi::PluginService::SetDebug(level) to level= 'PluginDebugLevel':0
-ApplicationMgr       INFO Updating Gaudi::PluginService::SetDebug(level) to level= 'PluginDebugLevel':0
-ApplicationMgr    SUCCESS 
-====================================================================================================================================
-                                                   Welcome to ApplicationMgr (GaudiCoreSvc v33r0)
-                                          running on lxplus730.cern.ch on Fri Jan 24 17:44:20 2020
-====================================================================================================================================
-ApplicationMgr       INFO Application Manager Configured successfully
-ApplicationMgr       INFO Updating Gaudi::PluginService::SetDebug(level) to level= 'PluginDebugLevel':0
-StatusCodeSvc        INFO initialize
-AthDictLoaderSvc     INFO in initialize...
-AthDictLoaderSvc     INFO acquired Dso-registry
-ClassIDSvc           INFO  getRegistryEntries: read 3459 CLIDRegistry entries for module ALL
-CoreDumpSvc          INFO install f-a-t-a-l handler... (flag = -1)
-CoreDumpSvc          INFO Handling signals: 11(Segmentation fault) 7(Bus error) 4(Illegal instruction) 8(Floating point exception) 
-AthenaEventLoopMgr   INFO Initializing AthenaEventLoopMgr - package version AthenaServices-00-00-00
-ByteStreamAddre...  DEBUG Property update for OutputLevel : new value = 2
-ByteStreamAddre...   INFO Initializing ByteStreamAddressProviderSvc - package version ByteStreamCnvSvcBase-00-00-00
-ByteStreamAddre...  DEBUG Service base class initialized successfully
-ByteStreamAddre...   INFO initialized 
-ByteStreamAddre...   INFO -- Will fill Store with id =  0
-MetaDataSvc          INFO Initializing MetaDataSvc - package version AthenaServices-00-00-00
-AthenaPoolCnvSvc     INFO Initializing AthenaPoolCnvSvc - package version AthenaPoolCnvSvc-00-00-00
-PoolSvc              INFO io_register[PoolSvc](xmlcatalog_file:PoolFileCatalog.xml) [ok]
-PoolSvc              INFO Set connectionsvc retry/timeout/IDLE timeout to  'ConnectionRetrialPeriod':300/ 'ConnectionRetrialTimeOut':3600/ 'ConnectionTimeOut':5 seconds with connection cleanup disabled
-PoolSvc              INFO Frontier compression level set to 5
-DBReplicaSvc         INFO Frontier server at (serverurl=http://atlasfrontier-local.cern.ch:8000/atlr)(serverurl=http://atlasfrontier-ai.cern.ch:8000/atlr)(serverurl=http://ccfrontier.in2p3.fr:23128/ccin2p3-AtlasFrontier)(proxyurl=http://ca-proxy-atlas.cern.ch:3128)(proxyurl=http://ca-proxy-meyrin.cern.ch:3128)(proxyurl=http://ca-proxy.cern.ch:3128)(proxyurl=http://atlasbpfrontier.cern.ch:3127)(proxyurl=http://atlasbpfrontier.fnal.gov:3127) will be considered for COOL data
-DBReplicaSvc         INFO Read replica configuration from /cvmfs/atlas-nightlies.cern.ch/repo/sw/master--py3/2020-01-23T2132/Athena/22.0.9/InstallArea/x86_64-centos7-gcc8-opt/share/dbreplica.config
-DBReplicaSvc         INFO Total of 10 servers found for host lxplus730.cern.ch [ATLF ATLAS_COOLPROD atlas_dd ATLAS_CONFIG INT8R INTR ATONR_COOL ATONR_CONF DEVDB11 ATLF ]
-PoolSvc              INFO Successfully setup replica sorting algorithm
-PoolSvc              INFO Setting up APR FileCatalog and Streams
-PoolSvc              INFO POOL WriteCatalog is xmlcatalog_file:PoolFileCatalog.xml
-DbSession            INFO     Open     DbSession    
-Domain[ROOT_All]     INFO >   Access   DbDomain     READ      [ROOT_All] 
-ToolSvc.ByteStr...   INFO Initializing ToolSvc.ByteStreamMetadataTool - package version ByteStreamCnvSvc-00-00-00
-MetaDataSvc          INFO Found MetaDataTools = PublicToolHandleArray(['IOVDbMetaDataTool','ByteStreamMetadataTool'])
-ByteStreamAddre...  DEBUG in preLoadAddress
-ByteStreamAddre...  DEBUG StoreID = 3 does not match required id (0) skip
-ByteStreamAddre...  DEBUG in preLoadAddress
-ByteStreamAddre...  DEBUG StoreID = 3 does not match required id (0) skip
-ByteStreamAddre...  DEBUG in preLoadAddress
 EventSelector       DEBUG Property update for OutputLevel : new value = 2
 EventSelector       DEBUG Initializing EventSelector
 EventSelector       DEBUG Service base class initialized successfully
 ByteStreamInputSvc   INFO Initializing ByteStreamInputSvc - package version ByteStreamCnvSvc-00-00-00
-ROBDataProviderSvc   INFO Initializing ROBDataProviderSvc - package version ByteStreamCnvSvcBase-00-00-00
-ROBDataProviderSvc   INFO  ---> Filter out empty ROB fragments                               =  'filterEmptyROB':False
-ROBDataProviderSvc   INFO  ---> Filter out specific ROBs by Status Code: # ROBs = 0
-ROBDataProviderSvc   INFO  ---> Filter out Sub Detector ROBs by Status Code: # Sub Detectors = 0
-ByteStreamInputSvcWARNING MaxBadEvents property has been moved to EventSelector, please use svgMgr.EventSelector.MaxBadEvents instead
-EventSelector        INFO Retrieved MaxBadEvents= 'MaxBadEvents':10 from ByteStreamInputSvc
 EventSelector        INFO reinitialization...
 AthenaEventLoopMgr   INFO Setup EventSelector service EventSelector
-ApplicationMgr       INFO Application Manager Initialized successfully
 EventSelector       DEBUG Calling EventSelectorByteStream::start()
-ClassIDSvc           INFO  getRegistryEntries: read 3112 CLIDRegistry entries for module ALL
-ByteStreamInputSvc   INFO Picked valid file: /cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/TrigP1Test/data17_13TeV.00327265.physics_EnhancedBias.merge.RAW._lb0100._SFO-1._0001.1
-EventSelector       DEBUG Opened block/file /cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/TrigP1Test/data17_13TeV.00327265.physics_EnhancedBias.merge.RAW._lb0100._SFO-1._0001.1
-ApplicationMgr       INFO Application Manager Started successfully
-ByteStreamCnvSvc    DEBUG Property update for OutputLevel : new value = 2
-EventPersistenc...   INFO Added successfully Conversion service:ByteStreamCnvSvc
-EventInfoByteSt...   INFO IsSimulation : 0
-EventInfoByteSt...   INFO IsTestbeam : 0
-EventInfoByteSt...   INFO IsCalibration : 0
-AthenaEventLoopMgr   INFO   ===>>>  start of run 327265    <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186525031, run #327265 0 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186525031, run #327265 1 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186524665, run #327265 1 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186524665, run #327265 2 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186542447, run #327265 2 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186542447, run #327265 3 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186543405, run #327265 3 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186543405, run #327265 4 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186548387, run #327265 4 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186548387, run #327265 5 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186515186, run #327265 5 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186515186, run #327265 6 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186556019, run #327265 6 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186556019, run #327265 7 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186542866, run #327265 7 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186542866, run #327265 8 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186537901, run #327265 8 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186537901, run #327265 9 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186517811, run #327265 9 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186517811, run #327265 10 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186534221, run #327265 10 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186534221, run #327265 11 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186540986, run #327265 11 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186540986, run #327265 12 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186535104, run #327265 12 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186535104, run #327265 13 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186539903, run #327265 13 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186539903, run #327265 14 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186552713, run #327265 14 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186552713, run #327265 15 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186524730, run #327265 15 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186524730, run #327265 16 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186547632, run #327265 16 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186547632, run #327265 17 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186555621, run #327265 17 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186555621, run #327265 18 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186568452, run #327265 18 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186568452, run #327265 19 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186580451, run #327265 19 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186580451, run #327265 20 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186535608, run #327265 20 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186535608, run #327265 21 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186583753, run #327265 21 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186583753, run #327265 22 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186553141, run #327265 22 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186553141, run #327265 23 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186582746, run #327265 23 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186582746, run #327265 24 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186583174, run #327265 24 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186583174, run #327265 25 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186590851, run #327265 25 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186590851, run #327265 26 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186585306, run #327265 26 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186585306, run #327265 27 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186575285, run #327265 27 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186575285, run #327265 28 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186585984, run #327265 28 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186585984, run #327265 29 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186539710, run #327265 29 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186539710, run #327265 30 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186591032, run #327265 30 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186591032, run #327265 31 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186588956, run #327265 31 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186588956, run #327265 32 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186576768, run #327265 32 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186576768, run #327265 33 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186601222, run #327265 33 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186601222, run #327265 34 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186572663, run #327265 34 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186572663, run #327265 35 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186577411, run #327265 35 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186577411, run #327265 36 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186599854, run #327265 36 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186599854, run #327265 37 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186604353, run #327265 37 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186604353, run #327265 38 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186612782, run #327265 38 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186612782, run #327265 39 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186591907, run #327265 39 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186591907, run #327265 40 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186570839, run #327265 40 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186570839, run #327265 41 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186601132, run #327265 41 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186601132, run #327265 42 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186597670, run #327265 42 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186597670, run #327265 43 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186607522, run #327265 43 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186607522, run #327265 44 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186526080, run #327265 44 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186526080, run #327265 45 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186602200, run #327265 45 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186602200, run #327265 46 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186560321, run #327265 46 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186560321, run #327265 47 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186624442, run #327265 47 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186624442, run #327265 48 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186608781, run #327265 48 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186608781, run #327265 49 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186550866, run #327265 49 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186550866, run #327265 50 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186628839, run #327265 50 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186628839, run #327265 51 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186623350, run #327265 51 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186623350, run #327265 52 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186632949, run #327265 52 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186632949, run #327265 53 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186571041, run #327265 53 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186571041, run #327265 54 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186626376, run #327265 54 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186626376, run #327265 55 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186617693, run #327265 55 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186617693, run #327265 56 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186564608, run #327265 56 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186564608, run #327265 57 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186555851, run #327265 57 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186555851, run #327265 58 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186643444, run #327265 58 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186643444, run #327265 59 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186632654, run #327265 59 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186632654, run #327265 60 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186636034, run #327265 60 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186636034, run #327265 61 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186542869, run #327265 61 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186542869, run #327265 62 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186517781, run #327265 62 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186517781, run #327265 63 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186559285, run #327265 63 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186559285, run #327265 64 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186643065, run #327265 64 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186643065, run #327265 65 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186658559, run #327265 65 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186658559, run #327265 66 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186655355, run #327265 66 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186655355, run #327265 67 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186601977, run #327265 67 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186601977, run #327265 68 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186584562, run #327265 68 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186584562, run #327265 69 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186593754, run #327265 69 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186593754, run #327265 70 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186613131, run #327265 70 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186613131, run #327265 71 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186668507, run #327265 71 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186668507, run #327265 72 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186605769, run #327265 72 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186605769, run #327265 73 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186675279, run #327265 73 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186675279, run #327265 74 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186648601, run #327265 74 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186648601, run #327265 75 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186586172, run #327265 75 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186586172, run #327265 76 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186594108, run #327265 76 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186594108, run #327265 77 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186587808, run #327265 77 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186587808, run #327265 78 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186559989, run #327265 78 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186559989, run #327265 79 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186694427, run #327265 79 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186694427, run #327265 80 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186560463, run #327265 80 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186560463, run #327265 81 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186656654, run #327265 81 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186656654, run #327265 82 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186669690, run #327265 82 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186669690, run #327265 83 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186661885, run #327265 83 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186661885, run #327265 84 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186696271, run #327265 84 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186696271, run #327265 85 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186679566, run #327265 85 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186679566, run #327265 86 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186698691, run #327265 86 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186698691, run #327265 87 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186690050, run #327265 87 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186690050, run #327265 88 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186652514, run #327265 88 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186652514, run #327265 89 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186681251, run #327265 89 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186681251, run #327265 90 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186702451, run #327265 90 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186702451, run #327265 91 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186604733, run #327265 91 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186604733, run #327265 92 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186701849, run #327265 92 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186701849, run #327265 93 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186711201, run #327265 93 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186711201, run #327265 94 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186707463, run #327265 94 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186707463, run #327265 95 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186689265, run #327265 95 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186689265, run #327265 96 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186712432, run #327265 96 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186712432, run #327265 97 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186719092, run #327265 97 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186719092, run #327265 98 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186705874, run #327265 98 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186705874, run #327265 99 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186712152, run #327265 99 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186712152, run #327265 100 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186709416, run #327265 100 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186709416, run #327265 101 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186648363, run #327265 101 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186648363, run #327265 102 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186672590, run #327265 102 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186672590, run #327265 103 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186735944, run #327265 103 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186735944, run #327265 104 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186656866, run #327265 104 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186656866, run #327265 105 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186719941, run #327265 105 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186719941, run #327265 106 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186725877, run #327265 106 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186725877, run #327265 107 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186710147, run #327265 107 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186710147, run #327265 108 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186729622, run #327265 108 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186729622, run #327265 109 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186719439, run #327265 109 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186719439, run #327265 110 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186662104, run #327265 110 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186662104, run #327265 111 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186718858, run #327265 111 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186718858, run #327265 112 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186696696, run #327265 112 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186696696, run #327265 113 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186723374, run #327265 113 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186723374, run #327265 114 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186676771, run #327265 114 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186676771, run #327265 115 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186714379, run #327265 115 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186714379, run #327265 116 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186753188, run #327265 116 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186753188, run #327265 117 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186768110, run #327265 117 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186768110, run #327265 118 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186715681, run #327265 118 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186715681, run #327265 119 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186694508, run #327265 119 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186694508, run #327265 120 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186749947, run #327265 120 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186749947, run #327265 121 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186702141, run #327265 121 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186702141, run #327265 122 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186742388, run #327265 122 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186742388, run #327265 123 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186763234, run #327265 123 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186763234, run #327265 124 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186672468, run #327265 124 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186672468, run #327265 125 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186764005, run #327265 125 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186764005, run #327265 126 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186746683, run #327265 126 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186746683, run #327265 127 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186659212, run #327265 127 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186659212, run #327265 128 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186785946, run #327265 128 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186785946, run #327265 129 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186702220, run #327265 129 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186702220, run #327265 130 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186616169, run #327265 130 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186616169, run #327265 131 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186701524, run #327265 131 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186701524, run #327265 132 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186758085, run #327265 132 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186758085, run #327265 133 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186726977, run #327265 133 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186726977, run #327265 134 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186740235, run #327265 134 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186740235, run #327265 135 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186788124, run #327265 135 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186788124, run #327265 136 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186708778, run #327265 136 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186708778, run #327265 137 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186795239, run #327265 137 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186795239, run #327265 138 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186723887, run #327265 138 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186723887, run #327265 139 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186775492, run #327265 139 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186775492, run #327265 140 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186682091, run #327265 140 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186682091, run #327265 141 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186753997, run #327265 141 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186753997, run #327265 142 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186764460, run #327265 142 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186764460, run #327265 143 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186745693, run #327265 143 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186745693, run #327265 144 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186710688, run #327265 144 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186710688, run #327265 145 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186802326, run #327265 145 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186802326, run #327265 146 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186797801, run #327265 146 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186797801, run #327265 147 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186778551, run #327265 147 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186778551, run #327265 148 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186813147, run #327265 148 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186813147, run #327265 149 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186785797, run #327265 149 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186785797, run #327265 150 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186685966, run #327265 150 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186685966, run #327265 151 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186811385, run #327265 151 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186811385, run #327265 152 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186814497, run #327265 152 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186814497, run #327265 153 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186756848, run #327265 153 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186756848, run #327265 154 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186818234, run #327265 154 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186818234, run #327265 155 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186836460, run #327265 155 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186836460, run #327265 156 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186840455, run #327265 156 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186840455, run #327265 157 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186837707, run #327265 157 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186837707, run #327265 158 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186824767, run #327265 158 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186824767, run #327265 159 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186809298, run #327265 159 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186809298, run #327265 160 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186838388, run #327265 160 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186838388, run #327265 161 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186781049, run #327265 161 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186781049, run #327265 162 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186830888, run #327265 162 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186830888, run #327265 163 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186838981, run #327265 163 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186838981, run #327265 164 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186847210, run #327265 164 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186847210, run #327265 165 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186836465, run #327265 165 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186836465, run #327265 166 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186831188, run #327265 166 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186831188, run #327265 167 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186848540, run #327265 167 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186848540, run #327265 168 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186792811, run #327265 168 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186792811, run #327265 169 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186853421, run #327265 169 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186853421, run #327265 170 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186846289, run #327265 170 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186846289, run #327265 171 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186816237, run #327265 171 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186816237, run #327265 172 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186829848, run #327265 172 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186829848, run #327265 173 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186864525, run #327265 173 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186864525, run #327265 174 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186840237, run #327265 174 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186840237, run #327265 175 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186837137, run #327265 175 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186837137, run #327265 176 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186780407, run #327265 176 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186780407, run #327265 177 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186788595, run #327265 177 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186788595, run #327265 178 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186799596, run #327265 178 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186799596, run #327265 179 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186860115, run #327265 179 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186860115, run #327265 180 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186871617, run #327265 180 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186871617, run #327265 181 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186866190, run #327265 181 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186866190, run #327265 182 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186770048, run #327265 182 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186770048, run #327265 183 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186884605, run #327265 183 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186884605, run #327265 184 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186887133, run #327265 184 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186887133, run #327265 185 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186744842, run #327265 185 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186744842, run #327265 186 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186858735, run #327265 186 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186858735, run #327265 187 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186895282, run #327265 187 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186895282, run #327265 188 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186868084, run #327265 188 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186868084, run #327265 189 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186875877, run #327265 189 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186875877, run #327265 190 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186778521, run #327265 190 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186778521, run #327265 191 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186825494, run #327265 191 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186825494, run #327265 192 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186907029, run #327265 192 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186907029, run #327265 193 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186892099, run #327265 193 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186892099, run #327265 194 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186921290, run #327265 194 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186921290, run #327265 195 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186919780, run #327265 195 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186919780, run #327265 196 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186917083, run #327265 196 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186917083, run #327265 197 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186848118, run #327265 197 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186848118, run #327265 198 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186866322, run #327265 198 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186866322, run #327265 199 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186896738, run #327265 199 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186896738, run #327265 200 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186920902, run #327265 200 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186920902, run #327265 201 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186860164, run #327265 201 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186860164, run #327265 202 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186915572, run #327265 202 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186915572, run #327265 203 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186894279, run #327265 203 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186894279, run #327265 204 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186739247, run #327265 204 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186739247, run #327265 205 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186935750, run #327265 205 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186935750, run #327265 206 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186863475, run #327265 206 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186863475, run #327265 207 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186852555, run #327265 207 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186852555, run #327265 208 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186882810, run #327265 208 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186882810, run #327265 209 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186935468, run #327265 209 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186935468, run #327265 210 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186711649, run #327265 210 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186711649, run #327265 211 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186910160, run #327265 211 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186910160, run #327265 212 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186944545, run #327265 212 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186944545, run #327265 213 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186952911, run #327265 213 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186952911, run #327265 214 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186924618, run #327265 214 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186924618, run #327265 215 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186916578, run #327265 215 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186916578, run #327265 216 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186959341, run #327265 216 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186959341, run #327265 217 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186912302, run #327265 217 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186912302, run #327265 218 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186963661, run #327265 218 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186963661, run #327265 219 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186905553, run #327265 219 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186905553, run #327265 220 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186900745, run #327265 220 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186900745, run #327265 221 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186938008, run #327265 221 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186938008, run #327265 222 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186864200, run #327265 222 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186864200, run #327265 223 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186967525, run #327265 223 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186967525, run #327265 224 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186937177, run #327265 224 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186937177, run #327265 225 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186957692, run #327265 225 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186957692, run #327265 226 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186945772, run #327265 226 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186945772, run #327265 227 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186989883, run #327265 227 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186989883, run #327265 228 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186926295, run #327265 228 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186926295, run #327265 229 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186954552, run #327265 229 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186954552, run #327265 230 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186890872, run #327265 230 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186890872, run #327265 231 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186920732, run #327265 231 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186920732, run #327265 232 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186961898, run #327265 232 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186961898, run #327265 233 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186965145, run #327265 233 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186965145, run #327265 234 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186996129, run #327265 234 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186996129, run #327265 235 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186986130, run #327265 235 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186986130, run #327265 236 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186993826, run #327265 236 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186993826, run #327265 237 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186988901, run #327265 237 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186988901, run #327265 238 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186902269, run #327265 238 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186902269, run #327265 239 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186938613, run #327265 239 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186938613, run #327265 240 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186973357, run #327265 240 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186973357, run #327265 241 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #187008237, run #327265 241 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #187008237, run #327265 242 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186863906, run #327265 242 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186863906, run #327265 243 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186951585, run #327265 243 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186951585, run #327265 244 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186982294, run #327265 244 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186982294, run #327265 245 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #187008101, run #327265 245 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #187008101, run #327265 246 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186850748, run #327265 246 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186850748, run #327265 247 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  start processing event #186997627, run #327265 247 events processed so far  <<<===
-AthenaEventLoopMgr   INFO   ===>>>  done processing event #186997627, run #327265 248 events processed so far  <<<===
-AthenaEventLoopMgrWARNING INFO message limit (500) reached for AthenaEventLoopMgr. Suppressing further output.
 EventSelector       DEBUG Calling EventSelectorByteStream::stop()
-Domain[ROOT_All]     INFO >   Deaccess DbDomain     READ      [ROOT_All] 
-ApplicationMgr       INFO Application Manager Stopped successfully
-IncidentProcAlg1     INFO Finalize
-IncidentProcAlg2     INFO Finalize
-ByteStreamCnvSvc    DEBUG releasing all workers
-AthDictLoaderSvc     INFO in finalize...
-ToolSvc              INFO Removing all tools created by ToolSvc
-ToolSvc.ByteStr...   INFO in finalize()
-*****Chrono*****     INFO ****************************************************************************************************
-*****Chrono*****     INFO  The Final CPU consumption ( Chrono ) Table (ordered)
-*****Chrono*****     INFO ****************************************************************************************************
-ChronoStatSvc        INFO Time User   : Tot= 6.01  [s]                                             #=  1
-*****Chrono*****     INFO ****************************************************************************************************
-ChronoStatSvc.f...   INFO  Service finalized successfully 
-ApplicationMgr       INFO Application Manager Finalized successfully
-ApplicationMgr       INFO Application Manager Terminated successfully
-Py:Athena            INFO leaving with code 0: "successful run"
-Listing sources of suppressed message: 
-=====================================================
- Message Source              |   Level |    Count
------------------------------+---------+-------------
- AthenaEventLoopMgr          |    INFO |     1003
-=====================================================
diff --git a/LArCalorimeter/LArBadChannelTool/share/LArBadChannelReadTest.py b/LArCalorimeter/LArBadChannelTool/share/LArBadChannelReadTest.py
index 23c47a9fe93..2bd22534b25 100644
--- a/LArCalorimeter/LArBadChannelTool/share/LArBadChannelReadTest.py
+++ b/LArCalorimeter/LArBadChannelTool/share/LArBadChannelReadTest.py
@@ -61,7 +61,6 @@ theApp.EvtMax=1
 ## theByteStreamInputSvc=svcMgr.ByteStreamInputSvc
 ## theByteStreamInputSvc.FullFileName=["/home/wlampl/LArOFIter/ramp/inputs/daq.Ramp.0029146.No.Streaming.LB0000.EB-EMBA._0001.data"]
    
-## theByteStreamInputSvc.MaxBadEvents=0
 
 
 #That's the dumper, keep for now
diff --git a/LArCalorimeter/LArCalibTools/share/LArDigits2Ntuple_jobOptions.py b/LArCalorimeter/LArCalibTools/share/LArDigits2Ntuple_jobOptions.py
index 96c3471e2d6..add93e7a5c1 100755
--- a/LArCalorimeter/LArCalibTools/share/LArDigits2Ntuple_jobOptions.py
+++ b/LArCalorimeter/LArCalibTools/share/LArDigits2Ntuple_jobOptions.py
@@ -139,7 +139,7 @@ if not 'FullFileName' in dir():
 else :   
    theByteStreamInputSvc.FullFileName=FullFileName
    
-theByteStreamInputSvc.MaxBadEvents=0
+scvMgr.EventSelector.MaxBadEvents = 0
 svcMgr.ByteStreamCnvSvc.InitCnvs += [ "EventInfo"]
 
 theByteStreamAddressProviderSvc =svcMgr.ByteStreamAddressProviderSvc
diff --git a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_DelayXtalk_jobOptions.py b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_DelayXtalk_jobOptions.py
index ebca655d996..82a87d4bb1c 100644
--- a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_DelayXtalk_jobOptions.py
+++ b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_DelayXtalk_jobOptions.py
@@ -265,7 +265,7 @@ if not 'FullFileName' in dir():
 else :   
    theByteStreamInputSvc.FullFileName=FullFileName
    
-theByteStreamInputSvc.MaxBadEvents=0
+svcMgr.EventSelector.MaxBadEvents = 0
 
 theByteStreamAddressProviderSvc =svcMgr.ByteStreamAddressProviderSvc
 theByteStreamAddressProviderSvc.TypeNames += ["LArFebHeaderContainer/LArFebHeader"]
diff --git a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_OFC_Cali_jobOptions.py b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_OFC_Cali_jobOptions.py
index 36b4e78a101..1fc6e113ac4 100644
--- a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_OFC_Cali_jobOptions.py
+++ b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_OFC_Cali_jobOptions.py
@@ -454,7 +454,7 @@ else :
    #theByteStreamInputSvc.FullFileName=FullFileName
    svcMgr.EventSelector.Input = FullFileName
    
-theByteStreamInputSvc.MaxBadEvents=0
+scvMgr.EventSelector.MaxBadEvents = 0
 
 ##############################################################################################
 #                                                                                            #
diff --git a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_OFC_splitter_jobOptions.py b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_OFC_splitter_jobOptions.py
index 00ddca51be4..d318758a2df 100644
--- a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_OFC_splitter_jobOptions.py
+++ b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_OFC_splitter_jobOptions.py
@@ -451,8 +451,8 @@ if not 'FullFileName' in dir():
    theApp.exit(-1)
 else :   
    theByteStreamInputSvc.FullFileName=FullFileName
-   
-theByteStreamInputSvc.MaxBadEvents=0
+  
+svcMgr.EventSelector.MaxBadEvents = 0
 
 ##############################################################################################
 #                                                                                            #
diff --git a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_jobOptions.py b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_jobOptions.py
index 55e57ea4d29..d6bde46597b 100644
--- a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_jobOptions.py
+++ b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_jobOptions.py
@@ -270,7 +270,7 @@ if not 'FullFileName' in dir():
 else :   
    theByteStreamInputSvc.FullFileName=FullFileName
    
-theByteStreamInputSvc.MaxBadEvents=0
+scvMgr.EventSelector.MaxBadEvents = 0
 
 ##############################################################################################
 #                                                                                            #
diff --git a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_splitter_jobOptions.py b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_splitter_jobOptions.py
index 2169546e746..f4798504b7d 100644
--- a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_splitter_jobOptions.py
+++ b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Delay_splitter_jobOptions.py
@@ -298,7 +298,7 @@ if not 'FullFileName' in dir():
 else :   
    theByteStreamInputSvc.FullFileName=FullFileName
    
-theByteStreamInputSvc.MaxBadEvents=0
+scvMgr.EventSelector.MaxBadEvents = 0
 
 ##############################################################################################
 #                                                                                            #
diff --git a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_PedestalAutoCorr_jobOptions.py b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_PedestalAutoCorr_jobOptions.py
index 0dffa8fcc19..7e8acce4373 100644
--- a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_PedestalAutoCorr_jobOptions.py
+++ b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_PedestalAutoCorr_jobOptions.py
@@ -285,7 +285,7 @@ if not 'FullFileName' in dir():
 else :   
    theByteStreamInputSvc.FullFileName=FullFileName
    
-theByteStreamInputSvc.MaxBadEvents=0
+scvMgr.EventSelector.MaxBadEvents = 0
 
 ##############################################################################################
 #                                                                                            #
diff --git a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Ramp_jobOptions.py b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Ramp_jobOptions.py
index 88a3f8f6efb..42b97e04306 100644
--- a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Ramp_jobOptions.py
+++ b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Ramp_jobOptions.py
@@ -346,7 +346,7 @@ if not 'FullFileName' in dir():
 else :   
    theByteStreamInputSvc.FullFileName=FullFileName
    
-theByteStreamInputSvc.MaxBadEvents=0
+scvMgr.EventSelector.MaxBadEvents = 0
 
 ##############################################################################################
 #                                                                                            #
diff --git a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Ramp_splitter_jobOptions.py b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Ramp_splitter_jobOptions.py
index 9f5566aac26..c4a990f607f 100644
--- a/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Ramp_splitter_jobOptions.py
+++ b/LArCalorimeter/LArExample/LArCalibProcessing/share/LArCalib_Ramp_splitter_jobOptions.py
@@ -322,7 +322,7 @@ if not 'FullFileName' in dir():
 else :   
    theByteStreamInputSvc.FullFileName=FullFileName
    
-theByteStreamInputSvc.MaxBadEvents=0
+scvMgr.EventSelector.MaxBadEvents = 0
 
 ##############################################################################################
 #                                                                                            #
diff --git a/LArCalorimeter/LArMonTools/share/LArMonByteStream.py b/LArCalorimeter/LArMonTools/share/LArMonByteStream.py
index 843471ffe9d..3e29cdf1a47 100755
--- a/LArCalorimeter/LArMonTools/share/LArMonByteStream.py
+++ b/LArCalorimeter/LArMonTools/share/LArMonByteStream.py
@@ -5,7 +5,7 @@
 if not online:
     theByteStreamInputSvc = svcMgr.ByteStreamInputSvc
     theByteStreamInputSvc.FullFileName = FullFileName
-    theByteStreamInputSvc.MaxBadEvents=0
+    svcMgr.EventSelector.MaxBadEvents = 0
 else:
     theApp.CreateSvc += ["ByteStreamCnvSvc"]
 
diff --git a/LArCalorimeter/LArTest/LArCalibTest/share/DumpCaloBadChannels.py b/LArCalorimeter/LArTest/LArCalibTest/share/DumpCaloBadChannels.py
index 43e07cbb34b..de2eefef723 100644
--- a/LArCalorimeter/LArTest/LArCalibTest/share/DumpCaloBadChannels.py
+++ b/LArCalorimeter/LArTest/LArCalibTest/share/DumpCaloBadChannels.py
@@ -38,6 +38,7 @@ svcMgr.EventSelector.RunNumber         = 1
 svcMgr.EventSelector.FirstEvent        = 1
 #svcMgr.EventSelector.InitialTimeStamp  = 0
 #svcMgr.EventSelector.TimeStampInterval = 5
+# svcMgr.EventSelector.MaxBadEvents      = 0
 
 #
 # Provides ByteStreamInputSvc name of the data file to process in the offline context
@@ -55,8 +56,6 @@ theApp.EvtMax=1
 ## theByteStreamInputSvc=svcMgr.ByteStreamInputSvc
 ## theByteStreamInputSvc.FullFileName=["/home/wlampl/LArOFIter/ramp/inputs/daq.Ramp.0029146.No.Streaming.LB0000.EB-EMBA._0001.data"]
    
-## theByteStreamInputSvc.MaxBadEvents=0
-
 
 
 from LArCalibTest.LArCalibTestConf import DumpCaloBadChannels
diff --git a/Reconstruction/RecExample/RecExCommission/share/skipBadEvents.py b/Reconstruction/RecExample/RecExCommission/share/skipBadEvents.py
index 5f805084d2c..8a076004401 100644
--- a/Reconstruction/RecExample/RecExCommission/share/skipBadEvents.py
+++ b/Reconstruction/RecExample/RecExCommission/share/skipBadEvents.py
@@ -1,3 +1,3 @@
 from AthenaCommon.AppMgr import ServiceMgr
 if (rec.doWriteESD):
-    ServiceMgr.ByteStreamInputSvc.MaxBadEvents=1000
+    ServiceMgr.EventSelector.MaxBadEvents=1000
diff --git a/Reconstruction/RecExample/RecExCommon/share/BSRead_config.py b/Reconstruction/RecExample/RecExCommon/share/BSRead_config.py
index aa384c3616d..3fdb561d971 100644
--- a/Reconstruction/RecExample/RecExCommon/share/BSRead_config.py
+++ b/Reconstruction/RecExample/RecExCommon/share/BSRead_config.py
@@ -17,7 +17,6 @@ if not hasattr( svcMgr, "ByteStreamAddressProviderSvc" ):
 
 if not athenaCommonFlags.isOnline() and not rec.readTAG():
     try:
-        #svcMgr.ByteStreamInputSvc.ProcessBadEvent=True
         svcMgr.EventSelector.ProcessBadEvent=True
     except Exception:
         treatException ("could not set svcMgr.EventSelector.ProcessBadEvent=True")
diff --git a/Reconstruction/RecExample/RecExTB/share/RecExTB_SCTMuonTile_2003_jobOptions.py b/Reconstruction/RecExample/RecExTB/share/RecExTB_SCTMuonTile_2003_jobOptions.py
index ae1f3dc8885..413eec870f2 100755
--- a/Reconstruction/RecExample/RecExTB/share/RecExTB_SCTMuonTile_2003_jobOptions.py
+++ b/Reconstruction/RecExample/RecExTB/share/RecExTB_SCTMuonTile_2003_jobOptions.py
@@ -19,11 +19,12 @@ ByteStreamInputSvc.InputDirectory = ["/castor/cern.ch/atlas/testbeam/combined/20
 ByteStreamInputSvc.FilePrefix = ["daq_SFO-1_combined"] ; 
 # Run number 
 ByteStreamInputSvc.RunNumber = [1222] ; 
-ByteStreamInputSvc.MaxBadEvents=200
 # Reader type "Castor" or "Simple" 
 ByteStreamEventStorageInputSvc = Service( "ByteStreamEventStorageInputSvc" )
 ByteStreamEventStorageInputSvc.ReaderType = "Castor";
 
+theApp.serviceMgr().EventSelector.MaxBadEvents = 200
+
 # This does not work for some unknown reason. That means that the SCT
 # reconstruction needs to be commented (even if what we try to say here
 # is to ignore the SCT ROS
diff --git a/TileCalorimeter/TileCalib/TileCalibAlgs/share/jobOptions_LaserTiming.py b/TileCalorimeter/TileCalib/TileCalibAlgs/share/jobOptions_LaserTiming.py
index 6fd96085726..1ff37a2cda9 100755
--- a/TileCalorimeter/TileCalib/TileCalibAlgs/share/jobOptions_LaserTiming.py
+++ b/TileCalorimeter/TileCalib/TileCalibAlgs/share/jobOptions_LaserTiming.py
@@ -383,7 +383,7 @@ topCalibAlg.TileCalibTools += [ToolSvc.oTileLaserTimingTool];
 theAuditorSvc = svcMgr.AuditorSvc
 theAuditorSvc.Auditors =  [ "ChronoAuditor" ] 
 
-ByteStreamInputSvc.MaxBadEvents = 10000
+
 # ByteStreamInputSvc.DumpFlag = TRUE
 # from AthenaCommon.AppMgr import ToolSvc
 # ToolSvc.TileROD_Decoder.VerboseOutput = TRUE
@@ -391,5 +391,6 @@ ByteStreamInputSvc.MaxBadEvents = 10000
 print topSequence
 
 EventSelector.SkipEvents = EvtMin
+EventSelector.MaxBadEvents = 10000
 theApp.EvtMax=EvtMax
 
diff --git a/TileCalorimeter/TileCalib/TileCalibAlgs/share/jobOptions_NoiseCalib.py b/TileCalorimeter/TileCalib/TileCalibAlgs/share/jobOptions_NoiseCalib.py
index a9edf10fe67..73667cff0c8 100755
--- a/TileCalorimeter/TileCalib/TileCalibAlgs/share/jobOptions_NoiseCalib.py
+++ b/TileCalorimeter/TileCalib/TileCalibAlgs/share/jobOptions_NoiseCalib.py
@@ -399,7 +399,6 @@ if 'doPerfMon' in dir():
         jobproperties.PerfMonFlags.doFastMon = False
         include( "PerfMonComps/PerfMonSvc_jobOptions.py" )
 
-ByteStreamInputSvc.MaxBadEvents = 10000
 # ByteStreamInputSvc.DumpFlag = TRUE
 # from AthenaCommon.AppMgr import ToolSvc
 # ToolSvc.TileROD_Decoder.VerboseOutput = TRUE
@@ -416,5 +415,6 @@ svcMgr.MessageSvc.useColors = False
 print topSequence
 
 EventSelector.SkipEvents = EvtMin
+EventSelector.MaxBadEvents = 10000
 theApp.EvtMax=EvtMax
 
diff --git a/TileCalorimeter/TileTBRec/share/jobOptions_TileTB_CIS.py b/TileCalorimeter/TileTBRec/share/jobOptions_TileTB_CIS.py
index fc2920e49a9..539d9ea71bc 100755
--- a/TileCalorimeter/TileTBRec/share/jobOptions_TileTB_CIS.py
+++ b/TileCalorimeter/TileTBRec/share/jobOptions_TileTB_CIS.py
@@ -85,7 +85,7 @@ theApp.Dlls += [ "GaudiAud" ]
 theAuditorSvc = AuditorSvc()
 theAuditorSvc.Auditors =  [ "ChronoAuditor" ] 
 
-ByteStreamInputSvc.MaxBadEvents = 10000
+theApp.serviceMgr().EventSelector.MaxBadEvents = 10000
 # ByteStreamInputSvc.DumpFlag = TRUE
 # TileROD_Decoder = Algorithm( "TileROD_Decoder" )
 # TileROD_Decoder.VerboseOutput = TRUE
-- 
GitLab