From 14e84e4838818b6d1171d13c4db34ee1c0af1cf2 Mon Sep 17 00:00:00 2001
From: cranshaw <Jack.Cranshaw@cern.ch>
Date: Tue, 14 Nov 2017 16:41:35 -0600
Subject: [PATCH] Replace CutFlowSvc with FileCutFlowSvc Remove some code
 duplication in BookkeeperTool

Former-commit-id: 4aba486ff5cd7217c6bcaf4eea57928a660958d7
---
 .../src/AthFilterAlgorithm.cxx                |   2 +-
 .../EventBookkeeperTools/BookkeeperTool.h     |   2 +
 .../Root/BookkeeperTool.cxx                   |  78 +-
 .../python/CutFlowHelpers.py                  |   8 +-
 Event/EventBookkeeperTools/src/CutFlowSvc.cxx | 808 ++++--------------
 Event/EventBookkeeperTools/src/CutFlowSvc.h   |  68 +-
 .../src/FileCutFlowSvc.cxx                    | 536 ------------
 .../EventBookkeeperTools/src/FileCutFlowSvc.h | 201 -----
 .../EventBookkeeperTools_entries.cxx          |   4 +-
 9 files changed, 228 insertions(+), 1479 deletions(-)
 delete mode 100644 Event/EventBookkeeperTools/src/FileCutFlowSvc.cxx
 delete mode 100644 Event/EventBookkeeperTools/src/FileCutFlowSvc.h

diff --git a/Control/AthenaBaseComps/src/AthFilterAlgorithm.cxx b/Control/AthenaBaseComps/src/AthFilterAlgorithm.cxx
index 7b3bc0f84bd..312403758b8 100644
--- a/Control/AthenaBaseComps/src/AthFilterAlgorithm.cxx
+++ b/Control/AthenaBaseComps/src/AthFilterAlgorithm.cxx
@@ -28,7 +28,7 @@ AthFilterAlgorithm::AthFilterAlgorithm( const std::string& name,
                                         ISvcLocator* pSvcLocator ) :
   ::AthAlgorithm( name, pSvcLocator ),
   m_cutID ( 0 ),
-  m_cutFlowSvc("FileCutFlowSvc/FileCutFlowSvc", name)
+  m_cutFlowSvc("CutFlowSvc/CutFlowSvc", name)
 {
   //
   // Property declaration
diff --git a/Event/EventBookkeeperTools/EventBookkeeperTools/BookkeeperTool.h b/Event/EventBookkeeperTools/EventBookkeeperTools/BookkeeperTool.h
index 3982b9a0e77..3ca75254cc5 100644
--- a/Event/EventBookkeeperTools/EventBookkeeperTools/BookkeeperTool.h
+++ b/Event/EventBookkeeperTools/EventBookkeeperTools/BookkeeperTool.h
@@ -58,6 +58,8 @@ private:
   StatusCode updateContainer( xAOD::CutBookkeeperContainer* contToUpdate,
                               const xAOD::CutBookkeeperContainer* otherCont );
 
+  StatusCode copyContainerToOutput(const std::string& outname);
+
   /// Fill Cutflow information
   StatusCode addCutFlow();
  
diff --git a/Event/EventBookkeeperTools/Root/BookkeeperTool.cxx b/Event/EventBookkeeperTools/Root/BookkeeperTool.cxx
index 61fda39f63e..279708809eb 100644
--- a/Event/EventBookkeeperTools/Root/BookkeeperTool.cxx
+++ b/Event/EventBookkeeperTools/Root/BookkeeperTool.cxx
@@ -164,31 +164,7 @@ StatusCode BookkeeperTool::beginInputFile()
 StatusCode BookkeeperTool::endInputFile()
 {
 
-  // Get the complete bookkeeper collection of the output meta-data store
-  xAOD::CutBookkeeperContainer* completeBook(NULL); 
-  if( !(outputMetaStore()->retrieve( completeBook, m_outputCollName) ).isSuccess() ) {
-    ATH_MSG_ERROR( "Could not get complete CutBookkeepers from output MetaDataStore" );
-    return StatusCode::FAILURE;
-  }
-
-  // Get the tmp bookkeeper from the input
-  const xAOD::CutBookkeeperContainer* tmpCompleteBook(NULL);
-  if ( outputMetaStore()->contains<xAOD::CutBookkeeperContainer>(m_outputCollName+"tmp") ) {
-    if( !(outputMetaStore()->retrieve( tmpCompleteBook, m_outputCollName+"tmp") ).isSuccess() ) {
-      ATH_MSG_WARNING( "Could not get tmp CutBookkeepers from output MetaDataStore" );
-    }
-    else {
-      // update the complete output with the complete input
-      ATH_CHECK(this->updateContainer(completeBook,tmpCompleteBook));
-      // remove the tmp container
-      const SG::IConstAuxStore* tmpCompleteBookAux = tmpCompleteBook->getConstStore();
-      ATH_CHECK(outputMetaStore()->removeDataAndProxy(tmpCompleteBook));
-      ATH_CHECK(outputMetaStore()->removeDataAndProxy(tmpCompleteBookAux));
-    }
-  }
-  else {
-    ATH_MSG_INFO("Found no tmp collection in output store " << outputMetaStore()->dump());
-  }
+  if (copyContainerToOutput(m_outputCollName).isFailure()) return StatusCode::FAILURE;
 
   if (!m_cutflowTaken) {
     if (addCutFlow().isFailure()) {
@@ -212,28 +188,8 @@ StatusCode BookkeeperTool::metaDataStop()
   // 3) Write root file if requested
   //  Make sure incomplete container exists in output
   std::string inc_name = "Incomplete"+m_outputCollName;
+  if (copyContainerToOutput(inc_name).isFailure()) return StatusCode::FAILURE;
 
-  // Get the complete bookkeeper collection of the output meta-data store
-  xAOD::CutBookkeeperContainer* incompleteBook(NULL); 
-  if( !(outputMetaStore()->retrieve( incompleteBook, inc_name) ).isSuccess() ) {
-    ATH_MSG_WARNING( "Could not get incomplete CutBookkeepers from output MetaDataStore" );
-  }
-
-  // Get the tmp bookkeeper from the input
-  const xAOD::CutBookkeeperContainer* tmpCompleteBook(NULL);
-  if ( outputMetaStore()->contains<xAOD::CutBookkeeperContainer>(m_outputCollName+"tmp") ) {
-    if( !(outputMetaStore()->retrieve( tmpCompleteBook, m_outputCollName+"tmp") ).isSuccess() ) {
-      ATH_MSG_WARNING( "Could not get tmp CutBookkeepers from output MetaDataStore for " << m_outputCollName+"tmp");
-    }
-    else {
-      // update the complete output with the complete input
-      ATH_CHECK(this->updateContainer(incompleteBook,tmpCompleteBook));
-      // remove the tmp container
-      const SG::IConstAuxStore* tmpCompleteBookAux = tmpCompleteBook->getConstStore();
-      ATH_CHECK(outputMetaStore()->removeDataAndProxy(tmpCompleteBook));
-      ATH_CHECK(outputMetaStore()->removeDataAndProxy(tmpCompleteBookAux));
-    }
-  }
 
   if (!m_cutflowTaken) {
     if (addCutFlow().isFailure()) {
@@ -425,3 +381,33 @@ BookkeeperTool::updateContainer( xAOD::CutBookkeeperContainer* contToUpdate,
   return StatusCode::SUCCESS;
 }
 
+
+StatusCode BookkeeperTool::copyContainerToOutput(const std::string& outname)
+{
+
+  // Get the complete bookkeeper collection of the output meta-data store
+  xAOD::CutBookkeeperContainer* contBook(NULL); 
+  if( !(outputMetaStore()->retrieve( contBook, outname) ).isSuccess() ) {
+    ATH_MSG_ERROR( "Could not get " << outname << " CutBookkeepers from output MetaDataStore" );
+    return StatusCode::FAILURE;
+  }
+
+  // Get the tmp bookkeeper from the input
+  const xAOD::CutBookkeeperContainer* tmpBook(NULL);
+  if ( outputMetaStore()->contains<xAOD::CutBookkeeperContainer>(outname+"tmp") ) {
+    if( !(outputMetaStore()->retrieve( tmpBook, outname+"tmp") ).isSuccess() ) {
+      ATH_MSG_WARNING( "Could not get tmp CutBookkeepers from output MetaDataStore" );
+    }
+    else {
+      // update the complete output with the complete input
+      ATH_CHECK(this->updateContainer(contBook,tmpBook));
+      // remove the tmp container
+      const SG::IConstAuxStore* tmpBookAux = tmpBook->getConstStore();
+      ATH_CHECK(outputMetaStore()->removeDataAndProxy(tmpBook));
+      ATH_CHECK(outputMetaStore()->removeDataAndProxy(tmpBookAux));
+    }
+  }
+    
+  return StatusCode::SUCCESS;
+}
+
diff --git a/Event/EventBookkeeperTools/python/CutFlowHelpers.py b/Event/EventBookkeeperTools/python/CutFlowHelpers.py
index af1d33cc527..7c947ee3729 100644
--- a/Event/EventBookkeeperTools/python/CutFlowHelpers.py
+++ b/Event/EventBookkeeperTools/python/CutFlowHelpers.py
@@ -63,8 +63,8 @@ def CreateCutFlowSvc( svcName="CutFlowSvc", athFile=None, seq=None, addAlgInPlac
     import AthenaCommon.CfgMgr as CfgMgr
     if not hasattr(svcMgr,"CutFlowSvc"): svcMgr += CfgMgr.CutFlowSvc()
     svcMgr.CutFlowSvc.InputStream   = inputStreamName
-    if not hasattr(svcMgr,"FileCutFlowSvc"): svcMgr += CfgMgr.FileCutFlowSvc()
-    svcMgr.FileCutFlowSvc.InputStream   = inputStreamName
+    #if not hasattr(svcMgr,"FileCutFlowSvc"): svcMgr += CfgMgr.FileCutFlowSvc()
+    #svcMgr.FileCutFlowSvc.InputStream   = inputStreamName
 
     # Make sure MetaDataSvc is ready
     if not hasattr(svcMgr,'MetaDataSvc'):
@@ -75,8 +75,8 @@ def CreateCutFlowSvc( svcName="CutFlowSvc", athFile=None, seq=None, addAlgInPlac
     from EventBookkeeperTools.EventBookkeeperToolsConf import BookkeeperTool
 
     # Standard event bookkeepers
-    inname = "FileBookkeepers"
-    outname = "FileBookkeepers"
+    inname = "CutBookkeepers"
+    outname = "CutBookkeepers"
     cutflowtool = BookkeeperTool(outname,
                                  InputCollName = inname,
                                  OutputCollName= outname) 
diff --git a/Event/EventBookkeeperTools/src/CutFlowSvc.cxx b/Event/EventBookkeeperTools/src/CutFlowSvc.cxx
index ae38cbfa581..31828c6991b 100644
--- a/Event/EventBookkeeperTools/src/CutFlowSvc.cxx
+++ b/Event/EventBookkeeperTools/src/CutFlowSvc.cxx
@@ -29,20 +29,7 @@
 #include "EventBookkeeperMetaData/EventBookkeeperCollection.h"
 #include "EventBookkeeperMetaData/EventBookkeeper.h"
 #include "xAODEventInfo/EventInfo.h"
-
-
-namespace {
-  const std::string&
-  getFileName(const Incident& inc)
-  {
-    static const std::string s_empty = "";
-    const FileIncident* fileInc  = dynamic_cast<const FileIncident*>(&inc);
-    return fileInc
-      ? fileInc->fileName()
-      : s_empty;
-  }
-}
-
+#include "EventInfo/EventStreamInfo.h"
 
 
 CutFlowSvc::CutFlowSvc(const std::string& name,
@@ -54,19 +41,14 @@ CutFlowSvc::CutFlowSvc(const std::string& name,
   m_completeCollName(""),
   m_incompleteCollName(""),
   m_skimmingCycle(0),
-  m_inputStream(""),
-  m_inputCompleteBookTmp(0),
-  m_inputCompleteBookAuxTmp(0),
-  m_fileCurrentlyOpened(false),
-  m_ebkMap(),
-  m_alreadyCopiedEventBookkeepers(false)
-  //m_alreadyDeterminedCycleNumber(false)
+  m_fileCollName("CutBookkeepersFile"),
+  m_inputStream("")
 {
   declareProperty("OutputCollName",           m_completeCollName="CutBookkeepers",
-    "The default name of the xAOD::CutBookkeeperContainer for fully processed files");
+    "DEFUNCT - handled by tool now");
   declareProperty("OutputIncompleteCollName", m_incompleteCollName = "IncompleteCutBookkeepers",
-    "The default name of the xAOD::CutBookkeeperContainer for partially processed files");
-  declareProperty("SkimmingCycle",            m_skimmingCycle = 0, "The processing step number");
+    "DEFUNCT - handled by tool now");
+  declareProperty("SkimmingCycle",            m_skimmingCycle = 0, "DEFUNCT - handled automatically");
   declareProperty("InputStream",              m_inputStream = "N/A", "The name of the input file stream");
   assert( pSvcLocator );
 }
@@ -91,124 +73,63 @@ CutFlowSvc::initialize()
   //Get Event StoreGate
   ATH_CHECK( m_eventStore.retrieve() );
 
+  // Align File name with complete name
+  m_fileCollName = m_completeCollName + "File";
 
   //Get IncidentSvc
   ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", this->name());
   ATH_CHECK( incSvc.retrieve() );
   incSvc->addListener(this, IncidentType::BeginInputFile, 60); // pri has to be < 100 to be after MetaDataSvc.
   incSvc->addListener(this, IncidentType::EndInputFile, 50); // pri has to be > 10 to be before MetaDataSvc.
-  incSvc->addListener(this, IncidentType::EndRun, 50);
-  incSvc->addListener(this, "StoreCleared", 50);
-
-
-  // Set up the container structure that we will write to the output file
-  xAOD::CutBookkeeperContainer* completeBook(NULL);
-  completeBook = new xAOD::CutBookkeeperContainer();
-  ATH_CHECK( recordCollection( completeBook, m_completeCollName) );
-
-  xAOD::CutBookkeeperContainer* incompleteBook(NULL);
-  incompleteBook = new xAOD::CutBookkeeperContainer();
-  ATH_CHECK( recordCollection( incompleteBook, m_incompleteCollName) );
-
-  delete m_inputCompleteBookTmp; m_inputCompleteBookTmp = NULL;
-  delete m_inputCompleteBookAuxTmp; m_inputCompleteBookAuxTmp = NULL;
-  //Note, do not sg->record inputCompleteTmp, this is internal
-  m_inputCompleteBookTmp = new xAOD::CutBookkeeperContainer();
-  // Take care of the peculiarities of the new xAOD EDM, i.e., create the needed AuxStore...
-  m_inputCompleteBookAuxTmp =  new xAOD::CutBookkeeperAuxContainer();
-  // ...and connect the two
-  m_inputCompleteBookTmp->setStore( m_inputCompleteBookAuxTmp );
-
-  m_fileCurrentlyOpened = false;
+  incSvc->addListener(this, "MetaDataStop", 50);
 
+  xAOD::CutBookkeeperContainer* fileBook(NULL);
+  fileBook = new xAOD::CutBookkeeperContainer();
+  ATH_CHECK( recordCollection( fileBook, m_fileCollName) );
+  if (m_outMetaDataStore->retrieve(m_completeBook,m_fileCollName).isFailure()) {
+    ATH_MSG_ERROR("Could not retrieve handle to cutflowsvc bookkeeper");
+    //return StatusCode::RECOVERABLE;
+  }
 
   // Determine the skimming cycle number that we should use now from the input file
   ATH_MSG_VERBOSE("Have currently the cycle number = " << m_skimmingCycle );
-  ATH_CHECK( this->determineCycleNumberFromOldInput("EventBookkeepers") );
-  ATH_CHECK( this->determineCycleNumberFromOldInput("IncompleteEventBookkeepers") );
   ATH_CHECK( this->determineCycleNumberFromInput(m_completeCollName) );
-  ATH_CHECK( this->determineCycleNumberFromInput(m_incompleteCollName) );
-  ATH_MSG_VERBOSE("Will use as currently cycle number = " << m_skimmingCycle );
+  ATH_MSG_VERBOSE("Will use cycle number = " << m_skimmingCycle );
 
   return StatusCode::SUCCESS;
 }
 
 
-
-
-StatusCode CutFlowSvc::determineCycleNumberFromInput( const std::string& collName )
+StatusCode
+CutFlowSvc::stop()
 {
-  ATH_MSG_DEBUG("calling determineCycleNumberFromInput('" << collName
-                  << "')... have currently cycle number = " << m_skimmingCycle );
-
-  // Try to get CutBookkeepers from the input file
-  if ( m_inMetaDataStore->contains<xAOD::CutBookkeeperContainer>(collName) ) {
-    ATH_MSG_VERBOSE("Found xAOD::CutBookkeeperContainer in input MetaStore with name: " << collName);
-
-    // There can always only be a single object in the input store. As the store
-    // is connected to just a single input file.
-    const xAOD::CutBookkeeperContainer* constColl = 0;
-    ATH_CHECK( m_inMetaDataStore->retrieve( constColl, collName ) );
-    xAOD::CutBookkeeperContainer* tmpColl = const_cast<xAOD::CutBookkeeperContainer*>(constColl);
-    if ( !(tmpColl->hasStore()) ) {
-      ATH_MSG_VERBOSE("Setting store of xAOD::CutBookkeeperContainer");
-      // Get also the auxilliary store
-      // const SG::IConstAuxStore* auxColl = 0;
-      const xAOD::CutBookkeeperAuxContainer* auxColl = 0;
-      ATH_CHECK( m_inMetaDataStore->retrieve(auxColl, collName+"Aux.") );
-      tmpColl->setConstStore( auxColl );
-    }
-    // Now, iterate over all CutBookkeepers and search for the highest cycle number
-    int maxCycle=0;
-    for ( std::size_t i=0; i<tmpColl->size(); ++i ) {
-      // Get the current old EBK
-      const xAOD::CutBookkeeper* cbk = tmpColl->at(i);
-      int inCycle = cbk->cycle();
-      if (inCycle > maxCycle) maxCycle = inCycle;
-    }
-    m_skimmingCycle = std::max(m_skimmingCycle,maxCycle+1);
-  }
-
-  ATH_MSG_DEBUG("done calling determineCycleNumberFromInput('" << collName
-                  << "')... have now cycle number = " << m_skimmingCycle );
   return StatusCode::SUCCESS;
 }
 
 
-StatusCode CutFlowSvc::determineCycleNumberFromOldInput( const std::string& collName )
+StatusCode
+CutFlowSvc::finalize()
 {
-  ATH_MSG_DEBUG("calling determineCycleNumberFromOldInput('" << collName
-                  << "')... have currently cycle number = " << m_skimmingCycle );
-  // Now check if there are old-style EventBookkeepers in the input file, using the old default name
-  if ( m_inMetaDataStore->contains< ::EventBookkeeperCollection >(collName) ) {
-    //get list of input metadata stores(!)
-    std::list<SG::ObjectWithVersion< ::EventBookkeeperCollection > > allVersions;
-    ATH_CHECK( m_inMetaDataStore->retrieveAllVersions(allVersions, collName) );
-
-    //now get all corresponding lists...
-    for ( std::list<SG::ObjectWithVersion< ::EventBookkeeperCollection> >::const_iterator
-          iter = allVersions.begin();
-          iter != allVersions.end();
-          ++iter ) {
-      //const DataHandle<xAOD::CutBookkeeperContainer> tmpColl = iter->dataObject;
-      const ::EventBookkeeperCollection* tmpColl = iter->dataObject;
-      // Now, iterate over all old-style EventBookkeepers and search for the highest cycle number
-      for ( std::size_t i=0; i<tmpColl->size(); ++i ) {
-        // Get the current old EBK
-        const ::EventBookkeeper* oldEBK = tmpColl->at(i);
-        int inCycle = oldEBK->getCycle();
-        if ( inCycle > m_skimmingCycle ){ m_skimmingCycle = inCycle + 1; }
-      }
-    }
-  }
-
-  ATH_MSG_DEBUG("done calling determineCycleNumberFromOldInput('" << collName
-                  << "')... have now cycle number = " << m_skimmingCycle );
+  ATH_MSG_DEBUG( "Finalizing " << name() << " - package version " << PACKAGE_VERSION );
   return StatusCode::SUCCESS;
 }
 
 
 
+StatusCode
+CutFlowSvc::queryInterface( const InterfaceID& riid, void** ppvi )
+{
+  // valid placeholder?
+  if ( 0 == ppvi ) { return StatusCode::FAILURE ; }  // RETURN
+  if ( ICutFlowSvc::interfaceID() == riid ) {
+    *ppvi = static_cast<ICutFlowSvc*>(this);
+    addRef(); // NB! : inrement the reference count!
+    return StatusCode::SUCCESS;                     // RETURN
+  }
+  // Interface is not directly availible: try out a base class
+  return AthService::queryInterface( riid, ppvi );
+}
+
 
 CutIdentifier CutFlowSvc::registerFilter( const std::string& name,
                                           const std::string& description )
@@ -222,16 +143,12 @@ CutIdentifier CutFlowSvc::registerFilter( const std::string& name,
   tmpEBK->setCycle(m_skimmingCycle);
   CutIdentifier cutID = tmpEBK->uniqueIdentifier();
 
-  // Get the complete bookkeeper collection of the meta-data store
-  xAOD::CutBookkeeperContainer* completeBook(NULL);
-  ATH_CHECK( m_outMetaDataStore->retrieve( completeBook, m_completeCollName) );
-
   // Let's see if an CutBookkeeper of this name already exists
   ATH_MSG_VERBOSE("in registerFilter(" << name << ", " << description << "): "
                   << "Going to search if this CutBookkeeper already exists" );
   bool existsAlready=false;
-  for ( std::size_t i=0; i<completeBook->size(); ++i ) {
-    xAOD::CutBookkeeper* ebk = completeBook->at(i);
+  for ( std::size_t i=0; i<m_completeBook->size(); ++i ) {
+    xAOD::CutBookkeeper* ebk = m_completeBook->at(i);
     if( tmpEBK->isEqualTo( ebk) ) {
       ATH_MSG_DEBUG("The CutBookkeeper with name " << name
                     << " and cutID " << cutID << " already exists... not adding!" );
@@ -254,10 +171,7 @@ CutIdentifier CutFlowSvc::registerFilter( const std::string& name,
   // If it is a new CutBookkeeper, add it to the container
   ATH_MSG_DEBUG( "You are DECLARING a new filter of name " << name
                  << " and cutID " << cutID );
-  completeBook->push_back(tmpEBK);
-
-  // Fill the map
-  m_ebkMap[cutID] = tmpEBK;
+  m_completeBook->push_back(tmpEBK);
 
   ATH_MSG_VERBOSE("done calling registerFilter(" << name << ", " << description << ")" );
   return cutID;
@@ -266,35 +180,6 @@ CutIdentifier CutFlowSvc::registerFilter( const std::string& name,
 
 
 
-// This method is probably only called by the DecionsSvc
-CutIdentifier CutFlowSvc::registerTopFilter( const std::string& name,
-                                             const std::string& description,
-                                             unsigned int logic,
-                                             const std::string& outputStream ) {
-  ATH_MSG_DEBUG("calling registerTopFilter(" << name << ", " << description
-                << ", " << logic << ", " << outputStream << ")" );
-  // Call the registerFilter method and get the correct CutBookkeeper
-  // from the returned cutID
-  CutIdentifier cutID = this->registerFilter( name, description );
-  xAOD::CutBookkeeper* ebk = this->getCutBookkeeper(cutID);
-  if ( !ebk ) {
-    ATH_MSG_ERROR( "(file: " __FILE__ << ", line: " << __LINE__ << ") "
-                   << "Couldn't find CutBookkeeper with cutID " << cutID );
-    return 0;
-  }
-
-  //Then set the logic and outputStream of the relevant CutBookkeeper
-  // toFind->setDescription(description);
-  ebk->setCutLogic(xAOD::CutBookkeeper::CutLogic(logic));
-  ebk->setTopFilter(true);
-  ebk->addOutputStreamForAllUsed(outputStream);
-
-  return cutID;
-}
-
-
-
-
 CutIdentifier CutFlowSvc::registerCut( const std::string& name,
                                        const std::string& description,
                                        CutIdentifier originCutID )
@@ -327,6 +212,35 @@ CutIdentifier CutFlowSvc::registerCut( const std::string& name,
 
 
 
+// This method is probably only called by the DecionsSvc
+CutIdentifier CutFlowSvc::registerTopFilter( const std::string& name,
+                                             const std::string& description,
+                                             unsigned int logic,
+                                             const std::string& outputStream ) 
+{
+  ATH_MSG_DEBUG("calling registerTopFilter(" << name << ", " << description
+                << ", " << logic << ", " << outputStream << ")" );
+  // Call the registerFilter method and get the correct CutBookkeeper
+  // from the returned cutID
+  CutIdentifier cutID = this->registerFilter( name, description );
+  xAOD::CutBookkeeper* ebk = this->getCutBookkeeper(cutID);
+  if ( !ebk ) {
+    ATH_MSG_ERROR( "(file: " __FILE__ << ", line: " << __LINE__ << ") "
+                   << "Couldn't find CutBookkeeper with cutID " << cutID );
+    return 0;
+  }
+
+  //Then set the logic and outputStream of the relevant CutBookkeeper
+  // toFind->setDescription(description);
+  ebk->setCutLogic(xAOD::CutBookkeeper::CutLogic(logic));
+  ebk->setTopFilter(true);
+  ebk->addOutputStreamForAllUsed(outputStream);
+
+  return cutID;
+}
+
+
+
 CutIdentifier CutFlowSvc::declareUsedOtherFilter( const std::string& name,
                                                   CutIdentifier originCutID )
 {
@@ -348,14 +262,10 @@ CutIdentifier CutFlowSvc::declareUsedOtherFilter( const std::string& name,
   tmpEBK->setCycle(m_skimmingCycle);
   CutIdentifier cutID = tmpEBK->uniqueIdentifier();
 
-  // Get the complete bookkeeper collection of the meta-data store
-  xAOD::CutBookkeeperContainer* completeBook(NULL);
-  ATH_CHECK( m_outMetaDataStore->retrieve( completeBook, m_completeCollName) );
-
   // See if the CutBookkeeper already exists or not
   bool existsAlready = false;
-  for ( std::size_t i=0; i<completeBook->size(); ++i ) {
-    xAOD::CutBookkeeper* ebk = completeBook->at(i);
+  for ( std::size_t i=0; i<m_completeBook->size(); ++i ) {
+    xAOD::CutBookkeeper* ebk = m_completeBook->at(i);
     if( tmpEBK->isEqualTo( ebk ) ) {
       originEBK->addUsedOther( ebk );
       cutID = ebk->uniqueIdentifier();
@@ -372,37 +282,35 @@ CutIdentifier CutFlowSvc::declareUsedOtherFilter( const std::string& name,
 
   // Otherwise, add the new one to the collection
   tmpEBK->setDescription( "Registered by origin filter" );
-  completeBook->push_back( tmpEBK );
   originEBK->addUsedOther( tmpEBK );
-
-  // Fill the map
-  m_ebkMap[cutID] = tmpEBK;
+  m_completeBook->push_back( tmpEBK );
 
   return cutID;
 }
 
 
 
+void
+CutFlowSvc::setFilterDescription( CutIdentifier cutID,
+                                  const std::string& descr )
+{
+  ATH_MSG_DEBUG("calling setFilterDescription(" << cutID << ", " << descr << ")" );
+
+  xAOD::CutBookkeeper* ebk = this->getCutBookkeeper(cutID);
+  ebk->setDescription(descr);
+  return;
+}
+
+
+
 
 void
 CutFlowSvc::addEvent( CutIdentifier cutID )
 {
-  ATH_MSG_VERBOSE("calling addEvent(" << cutID << ")" );
+  ATH_MSG_INFO("calling addEvent(" << cutID << ")" );
 
   double evtWeight=1.0;
 
-  const xAOD::EventInfo* evtInfo = 0;
-  StatusCode sc = m_eventStore->retrieve(evtInfo);
-  if ( sc.isFailure() || NULL == evtInfo ) {
-    ATH_MSG_WARNING("Could not retrieve EventInfo from StoreGate  ");
-    evtWeight=-1000.;
-  } else {
-    // Only try to access the mcEventWeight is we are running on Monte Carlo, duhhh!
-    if ( evtInfo->eventType(xAOD::EventInfo::IS_SIMULATION) ) {
-      evtWeight = evtInfo->mcEventWeight();
-    }
-  }
-
   addEvent(cutID,evtWeight);
 
   return;
@@ -413,40 +321,34 @@ CutFlowSvc::addEvent( CutIdentifier cutID )
 void
 CutFlowSvc::addEvent( CutIdentifier cutID, double weight)
 {
-  ATH_MSG_VERBOSE("calling addEvent(" << cutID << ", " << weight << ")" );
+  ATH_MSG_INFO("calling addEvent(" << cutID << ", " << weight << ")" );
 
   xAOD::CutBookkeeper* eb = this->getCutBookkeeper(cutID);
   if ( !eb ) {
-    // Get the complete bookkeeper collection of the output meta-data store
-    xAOD::CutBookkeeperContainer* completeBook(NULL);
-    if( !(m_outMetaDataStore->retrieve( completeBook, m_completeCollName)).isSuccess() ) {
-      ATH_MSG_ERROR( "Could not retrieve complete CutBookkeepers from output MetaDataStore." );
-      return;
-    }
-
+    ATH_MSG_INFO("Could not find eb");
 
     // Iterate over the complete bookkeepers and update the cutID-to-bookkeeper map
     ATH_MSG_DEBUG( "addEvent: Going to re-populate the map. Have "
-                   << completeBook->size() << " CutBookkeepers"
+                   << m_completeBook->size() << " CutBookkeepers"
                    << " and skimming cycle " << m_skimmingCycle
-                   << " and input Stream name " << m_inputStream.value() );
-    xAOD::CutBookkeeperContainer::iterator iter    = completeBook->begin();
-    xAOD::CutBookkeeperContainer::iterator iterEnd = completeBook->end();
+                   << " and input Stream name " << m_inputStream );
+    xAOD::CutBookkeeperContainer::iterator iter    = m_completeBook->begin();
+    xAOD::CutBookkeeperContainer::iterator iterEnd = m_completeBook->end();
     for ( ; iter != iterEnd; ++iter ) {
       xAOD::CutBookkeeper* ebk = *iter;
-      CutIdentifier cutID2 = ebk->uniqueIdentifier();
+      CutIdentifier cutID = ebk->uniqueIdentifier();
       ATH_MSG_VERBOSE( "addEvent: Have CutBookkeeper with"
                        << " skimming cycle " << ebk->cycle()
                        << " and input Stream name " << ebk->inputStream()
                        << " and logic " << ebk->cutLogic()
                        << " isTopFilter " << ebk->isTopFilter()
-                       << " and cutID " << cutID2
+                       << " and cutID " << cutID
                        << " and name " << ebk->name() );
       if ( m_skimmingCycle == ebk->cycle() ) {
-        if ( m_inputStream.value() == ebk->inputStream() ) {
-          CutIDMap_t::iterator mapIter = m_ebkMap.find(cutID2);
+        if ( m_inputStream == ebk->inputStream() ) {
+          CutIDMap_t::iterator mapIter = m_ebkMap.find(cutID);
           ATH_MSG_DEBUG( "BeginInputFile: Have CutBookkeeper with"
-                         << " cutID " << cutID2
+                         << " cutID " << cutID
                          <<  " and name " << ebk->name() );
           if ( mapIter != m_ebkMap.end() ) { // we found this CutBookkeeper in the existing map
             (*mapIter).second = ebk;
@@ -471,33 +373,10 @@ CutFlowSvc::addEvent( CutIdentifier cutID, double weight)
 
 
 
-
-
-
 //__________________________________________________________________________
 void CutFlowSvc::handle( const Incident& inc )
 {
-  ATH_MSG_VERBOSE( "Start incident " << inc.type() << ", fileOpened " << m_fileCurrentlyOpened );
-
-  //CLEARING METADATA STORE
-  //Things to do:
-  // 1) transer tmp complete CutBookkeepers from input to output, and clear the tmp list
-  if ( inc.type() == "StoreCleared" ) {
-    ATH_MSG_VERBOSE( "Start incident processing " << inc.type() << ", fileOpened " << m_fileCurrentlyOpened );
-    const StoreClearedIncident* sinc = dynamic_cast<const StoreClearedIncident*>(&inc);
-    if ( sinc != 0 && sinc->store() == &*m_outMetaDataStore ) {
-      ATH_MSG_DEBUG( "StoreCleared: Going to re-initialize the map" );
-      // Set all CutBookkeeper pointers in the internal map to zero
-      for ( CutIDMap_t::iterator mapIter = m_ebkMap.begin(),
-            mapIterEnd = m_ebkMap.end();
-            mapIter != mapIterEnd;
-            ++mapIter ) {
-        (*mapIter).second = 0;
-      }
-    }
-    return;
-  }
-
+  ATH_MSG_VERBOSE( "Start incident " << inc.type() );
 
   //OPENING NEW INPUT FILE
   //Things to do:
@@ -506,88 +385,67 @@ void CutFlowSvc::handle( const Incident& inc )
   //    2a) if incomplete from input, directly propagate to output
   //    2b) if complete from input, wait for EndInputFile to decide what to do in output
 
-  // Get the incomplete bookkeeper collection of the meta-data store
-  xAOD::CutBookkeeperContainer* incompleteBook(NULL);
-  if( !(m_outMetaDataStore->retrieve( incompleteBook, m_incompleteCollName)).isSuccess() ) {
-    ATH_MSG_ERROR( "Could not retrieve incomplete CutBookkeepers from output MetaDataStore" );
-    return;
-  }
-
   if ( inc.type() == IncidentType::BeginInputFile ) {
-    m_fileCurrentlyOpened = true;
-
-    // Copy the existing cut bookkeepers from the input file to the output
-    m_alreadyCopiedEventBookkeepers = false;
-    ATH_MSG_DEBUG( "Start incident processing " << inc.type() << ", fileOpened " << m_fileCurrentlyOpened );
-    if( !(updateCollFromInputStore(m_inputCompleteBookTmp, m_completeCollName) ).isSuccess() ) {
-      ATH_MSG_ERROR( "Could not update complete CutBookkeepers from input" );
-      return;
+    // Check the stream name
+    const EventStreamInfo* esi;
+    if (m_inMetaDataStore->retrieve(esi).isFailure()) {
+      ATH_MSG_WARNING("No EventStreamInfo taking stream from property InputStream");
     }
-    if( !(updateCollFromInputStore(incompleteBook,m_incompleteCollName) ).isSuccess() ) {
-      ATH_MSG_ERROR( "Could not update incomplete CutBookkeepers from input" );
-      return;
+    else {
+      std::string inputstream = *(esi->getProcessingTags().begin());
+      if (m_inputStream.empty()) {m_inputStream=inputstream;}
+      else if (m_inputStream!=inputstream) {
+        const FileIncident* finc = dynamic_cast<const FileIncident*>(&inc);
+        ATH_MSG_FATAL("File " << finc->fileName() 
+                              << " stream " << inputstream 
+                              << " does not match previous file " 
+                              << m_inputStream);
+        return;
+      }
     }
-  }
-
 
-  // Get the complete bookkeeper collection of the output meta-data store
-  xAOD::CutBookkeeperContainer* completeBook(NULL);
-  if( !(m_outMetaDataStore->retrieve( completeBook, m_completeCollName) ).isSuccess() ) {
-    ATH_MSG_ERROR( "Could not get complete CutBookkeepers from output MetaDataStore" );
-    return;
-  }
-
-  //CLOSING INPUT FILE
-  //Things to do:
-  // 1) note that no file is currently opened
-  if ( inc.type() == IncidentType::EndInputFile ) {
-    m_fileCurrentlyOpened = false;
-    ATH_MSG_DEBUG( "Start incident processing " << inc.type() << ", fileOpened " << m_fileCurrentlyOpened );
-    ATH_MSG_DEBUG("In EndInputFile: updating container with completeBook of size=" << completeBook->size()
-                  << ", and m_inputCompleteBookTmp with size=" << m_inputCompleteBookTmp->size() );
-    if( !(this->updateContainer( completeBook, m_inputCompleteBookTmp )).isSuccess() ) {
-      ATH_MSG_ERROR( "Could not update complete CutBookkeepers from input at EndInputFile" );
-      return;
+    // Clear the file bookkeeper
+    if (m_completeBook.isValid()) {
+      // Reset existing container
+      for (xAOD::CutBookkeeperContainer::iterator it = m_completeBook->begin();
+           it != m_completeBook->end(); ++it) {
+        (*it)->setNAcceptedEvents(0);
+        (*it)->setSumOfEventWeights(0);
+        (*it)->setSumOfEventWeightsSquared(0);
+      }
     }
-    ATH_MSG_DEBUG("Now clearing the inputCompleteBookTmp... currently, it has size=" << m_inputCompleteBookTmp->size() );
-    m_inputCompleteBookTmp->clear();
   }
 
-  //TERMINATING THE JOB (EndRun)
-  //Things to do:
-  // 1) Create new incomplete CutBookkeepers if relevant
-  // 2) Print cut flow summary
-  // 3) Write root file if requested
-  if ( inc.type() == IncidentType::EndRun ) {
-    ATH_MSG_DEBUG( "Start incident processing " << inc.type() << ", fileOpened " << m_fileCurrentlyOpened );
-    if ( m_fileCurrentlyOpened ) {
-      //Document which file caused the incompletion
-      std::string fileName = ::getFileName(inc);
-      std::string postfix = " (incomplete from " + fileName + ")";
-      ATH_MSG_DEBUG("In EndRun with open file: " << fileName);
-      ATH_MSG_VERBOSE("Have inputCompleteBookTmp container with size=" << m_inputCompleteBookTmp->size() );
-      for ( std::size_t i=0; i<m_inputCompleteBookTmp->size(); ++i ) {
-        std::string newDescrip = m_inputCompleteBookTmp->at(i)->description()
-                                 + postfix;
-        m_inputCompleteBookTmp->at(i)->setDescription( newDescrip );
+  // Clean up the bookkeeper before output
+  //if ( inc.type() == "MetaDataStop" || inc.type() == "EndInputFile") {
+  if ( inc.type() == "MetaDataStop" ) {
+    if (m_completeBook.isValid()) {
+      // Reset existing container
+      for (xAOD::CutBookkeeperContainer::iterator it = m_completeBook->begin();
+           it != m_completeBook->end(); ++it) {
       }
-      //Then update incompleteBook
-      if( !(this->updateContainer( incompleteBook, m_inputCompleteBookTmp ) ).isSuccess() ) {
-        ATH_MSG_ERROR( "Could not update incomplete CutBookkeepers from input at EndRun" );
-        return;
+    }
+    const xAOD::CutBookkeeperContainer* fileBook(NULL);
+    if( !(m_outMetaDataStore->retrieve(fileBook, m_fileCollName) ).isSuccess() ) {
+      ATH_MSG_WARNING( "Could not get " << m_fileCollName 
+                       << " CutBookkeepers from output MetaDataStore" );
+    }
+    else {
+      const SG::IConstAuxStore* fileBookAux = fileBook->getConstStore();
+      if (m_outMetaDataStore->removeDataAndProxy(fileBook).isFailure()) {
+        ATH_MSG_ERROR("Unable to remove " << m_fileCollName);
+      }
+      if (m_outMetaDataStore->removeDataAndProxy(fileBookAux).isFailure()) {
+        ATH_MSG_ERROR("Unable to remove " << m_fileCollName);
       }
     }
-
-    // Clear the internal map
-    m_ebkMap.clear();
   }
-  ATH_MSG_DEBUG( "End incident " << inc.type() << " fileOpened " << m_fileCurrentlyOpened );
+
+  ATH_MSG_DEBUG( "End incident " << inc.type() );
   return;
 }
 
 
-
-
 void
 CutFlowSvc::print()
 {
@@ -595,337 +453,41 @@ CutFlowSvc::print()
 }
 
 
-
-
-
-
-StatusCode
-CutFlowSvc::updateCollFromInputStore(xAOD::CutBookkeeperContainer* coll,
-                                     const std::string &collName)
+StatusCode CutFlowSvc::determineCycleNumberFromInput( const std::string& collName )
 {
-  ATH_MSG_DEBUG("calling updateCollFromInputStore(" << collName << ") with coll-size=" << coll->size() );
+  ATH_MSG_DEBUG("calling determineCycleNumberFromInput('" << collName
+                  << "')... have currently cycle number = " << m_skimmingCycle );
 
+  // Try to get CutBookkeepers from the input file
   if ( m_inMetaDataStore->contains<xAOD::CutBookkeeperContainer>(collName) ) {
-    ATH_MSG_VERBOSE("Input MetaData contains type xAOD::CutBookkeeperContainer with name" << collName);
+    ATH_MSG_VERBOSE("Found xAOD::CutBookkeeperContainer in input MetaStore with name: " << collName);
 
     // There can always only be a single object in the input store. As the store
     // is connected to just a single input file.
-    const xAOD::CutBookkeeperContainer* tmpColl = 0;
-    ATH_CHECK( m_inMetaDataStore->retrieve( tmpColl, collName ) );
-
-    // Check that we succeeded:
-    if( ! tmpColl->hasStore() ) {
-       ATH_MSG_FATAL( "Object doesn't have an auxiliary store" );
-       return StatusCode::FAILURE;
-    }
-
-    //...and update coll with each list.
-    ATH_CHECK( this->updateContainer(coll, tmpColl) );
-  }
-  // Now check if there are old-style EventBookkeepers in the input file
-  else if ( m_inMetaDataStore->contains< ::EventBookkeeperCollection >(collName) ) {
-    ATH_MSG_VERBOSE("Input MetaData contains type EventBookkeeperCollection with name" << collName);
-    //get list of input metadata stores(!)
-    std::list<SG::ObjectWithVersion< ::EventBookkeeperCollection > > allVersions;
-    ATH_CHECK( m_inMetaDataStore->retrieveAllVersions(allVersions, collName) );
-
-    //now get all corresponding lists...
-    for ( std::list<SG::ObjectWithVersion< ::EventBookkeeperCollection> >::const_iterator
-            iter = allVersions.begin();
-          iter != allVersions.end();
-          ++iter ) {
-      //const DataHandle<xAOD::CutBookkeeperContainer> tmpColl = iter->dataObject;
-      const ::EventBookkeeperCollection* tmpColl = iter->dataObject;
-      //...and update coll with each list.
-      ATH_CHECK( this->updateContainerFromOldEDM(coll, tmpColl) );
-    }
-  }
-  // Now check if there are old-style EventBookkeepers in the input file, using the old default name
-  else if ( m_inMetaDataStore->contains< ::EventBookkeeperCollection >("EventBookkeepers") ) {
-    if (!m_alreadyCopiedEventBookkeepers) {
-      ATH_MSG_VERBOSE("Input MetaData contains type EventBookkeeperCollection with name EventBookkeepers");
-      m_alreadyCopiedEventBookkeepers = true;
-      //get list of input metadata stores(!)
-      std::list<SG::ObjectWithVersion< ::EventBookkeeperCollection > > allVersions;
-      ATH_CHECK( m_inMetaDataStore->retrieveAllVersions(allVersions, "EventBookkeepers") );
-
-      //now get all corresponding lists...
-      for ( std::list<SG::ObjectWithVersion< ::EventBookkeeperCollection> >::const_iterator
-            iter = allVersions.begin();
-            iter != allVersions.end();
-            ++iter ) {
-        //const DataHandle<xAOD::CutBookkeeperContainer> tmpColl = iter->dataObject;
-        const ::EventBookkeeperCollection* tmpColl = iter->dataObject;
-        //...and update coll with each list.
-        ATH_CHECK( this->updateContainerFromOldEDM(coll, tmpColl) );
-      }
-    }
-    else {
-      ATH_MSG_VERBOSE("Already copied EventBookkeeperCollection with name EventBookkeepers for this input file");
-    }
-  }
-  else {
-    ATH_MSG_INFO( "Cannot find xAOD::CutBookkeeperContainer "
-                  << "or an old-style EventBookkeeperCollection "
-                  << "with name " << collName << " in the input file.");
-  }
-  return StatusCode::SUCCESS;
-}
-
-
-namespace {
-
-
-xAOD::CutBookkeeper*
-resolveLink (const xAOD::CutBookkeeper* old,
-             xAOD::CutBookkeeperContainer& contToUpdate,
-             const xAOD::CutBookkeeperContainer& otherCont,
-             const std::vector<size_t>& otherIndices)
-{
-  {
-    xAOD::CutBookkeeperContainer::iterator matchIter = 
-      std::find( contToUpdate.begin(),
-                 contToUpdate.end(),
-                 old );
-    if (matchIter != contToUpdate.end())
-      return *matchIter;
-  }
-
-  {
-    xAOD::CutBookkeeperContainer::const_iterator matchIter = 
-      std::find( otherCont.begin(),
-                 otherCont.end(),
-                 old );
-    if (matchIter != contToUpdate.end()) {
-      size_t pos = matchIter - otherCont.begin();
-      return contToUpdate[otherIndices[pos]];
-    }
-  }
-
-  // If we didn't find it, we need to add it
-  xAOD::CutBookkeeper* newEBK = new xAOD::CutBookkeeper();
-  if ( newEBK->usingPrivateStore() ) { newEBK->releasePrivateStore(); }
-  newEBK->makePrivateStore(old);
-  contToUpdate.push_back( newEBK );
-  return newEBK;
-}
-
-
-} // anonymous namespace
-
-
-StatusCode
-CutFlowSvc::updateContainer( xAOD::CutBookkeeperContainer* contToUpdate,
-                             const xAOD::CutBookkeeperContainer* otherCont ) {
-  ATH_MSG_DEBUG("calling updateContainer(...)" );
-  ATH_MSG_VERBOSE("Have container to update with size=" << contToUpdate->size()
-                  << ", and other container with size=" << otherCont->size() );
-
-  size_t origSize = contToUpdate->size();
-
-  // Vector of indices in contToUpdate of elements in otherCont.
-  std::vector< std::size_t > otherIndices (otherCont->size());
-  // Loop through otherCont.
-  // If element already in contToUpdate, update event counts, otherwise create new element
-  for ( std::size_t i=0; i<otherCont->size(); ++i ) {
-    const xAOD::CutBookkeeper* otherEBK = otherCont->at(i);
-    ATH_MSG_VERBOSE("Looping through otherCont at index " << i);
-    ATH_MSG_VERBOSE("Have otherEBK with: name=" << otherEBK->name()
-                    << ", cycle=" << otherEBK->cycle()
-                    << ", nAcceptedEvents=" << otherEBK->nAcceptedEvents()
-                    << ", inputStream=" << otherEBK->inputStream() );
-
-
-    // Loop through the container to be updated (contToUpdate) and see if we find a match
-    bool foundEBKToUpdate(false);
-    for ( std::size_t j=0; j<contToUpdate->size(); ++j ) {
-      xAOD::CutBookkeeper* ebkToUpdate = contToUpdate->at(j);
-      // Check if they are identical, if so, update; else add otherEBK
-      if ( otherEBK->isEqualTo(ebkToUpdate) ) {
-        ebkToUpdate->setPayload( ebkToUpdate->payload() + otherEBK->payload() );
-        otherIndices[i] = j;
-        foundEBKToUpdate = true;
-        break;
-      }
-    } // End: Inner loop over contToUpdate
-    if (!foundEBKToUpdate) {
-      xAOD::CutBookkeeper* newEBK = new xAOD::CutBookkeeper();
-      if ( newEBK->usingPrivateStore() ) { newEBK->releasePrivateStore(); }
-      newEBK->makePrivateStore(otherEBK);
-      contToUpdate->push_back( newEBK );
-      std::size_t ebIdx = newEBK->index();
-      otherIndices[i] = ebIdx;
-    }
-  } // End: Outer loop over contToUpdate
-
-  // Now, we still need to fix the cross-referencing of the newly added CutBookkkeepers
-  for ( std::size_t i=origSize; i<contToUpdate->size(); ++i ) {
-    xAOD::CutBookkeeper* ebkToModify = contToUpdate->at(i);
-
-    // Parent check
-    if ( ebkToModify->hasParent() ) {
-      const xAOD::CutBookkeeper* oldParent = ebkToModify->parent();
-      const xAOD::CutBookkeeper* newParent = resolveLink (oldParent,
-                                                          *contToUpdate,
-                                                          *otherCont,
-                                                          otherIndices);
-      ebkToModify->setParent (newParent);
-    } // Done fixing parent
-
-    // Children check
-    std::vector< xAOD::CutBookkeeper* > newChildren;
-    for ( std::size_t oldIdx=0; oldIdx<ebkToModify->nChildren(); ++oldIdx ) {
-      const xAOD::CutBookkeeper* oldEBK = ebkToModify->child(oldIdx);
-      newChildren.push_back (resolveLink (oldEBK,
-                                          *contToUpdate,
-                                          *otherCont,
-                                          otherIndices));
-    } // Done fixing children
-    ebkToModify->setChildren (newChildren);
-
-    // Used others check
-    std::vector< xAOD::CutBookkeeper* > newOthers;
-    for ( std::size_t oldIdx=0; oldIdx<ebkToModify->nUsedOthers(); ++oldIdx ) {
-      const xAOD::CutBookkeeper* oldEBK = ebkToModify->usedOther(oldIdx);
-      newOthers.push_back (resolveLink (oldEBK,
-                                        *contToUpdate,
-                                        *otherCont,
-                                        otherIndices));
-    } // Done fixing used others
-    ebkToModify->setUsedOthers (newOthers);
-
-    // Siblings check
-    std::vector< xAOD::CutBookkeeper* > newSiblings;
-    for ( std::size_t oldIdx=0; oldIdx<ebkToModify->nSiblings(); ++oldIdx ) {
-      const xAOD::CutBookkeeper* oldEBK = ebkToModify->sibling(oldIdx);
-      newSiblings.push_back (resolveLink (oldEBK,
-                                          *contToUpdate,
-                                          *otherCont,
-                                          otherIndices));
-    } // Done fixing siblings
-    ebkToModify->setSiblings (newSiblings);
-  } // Done fixing all cross references
-  return StatusCode::SUCCESS;
-}
-
-
-
-
-StatusCode CutFlowSvc::updateContainerFromOldEDM( xAOD::CutBookkeeperContainer* contToUpdate,
-                                                  const EventBookkeeperCollection* otherContOldEDM ) {
-  // Helper class to update a container with information from another one from the old EDM
-  ATH_MSG_DEBUG("calling updateContainerFromOldEDM(contToUpdate, otherContOldEDM)"
-                << " with sizes=(" << contToUpdate->size() << "," << otherContOldEDM->size() << ")");
-
-  // Create a new CutBookkeeperContainer to hold the transferred objects
-  // Note, do not sg->record, this is internal
-  xAOD::CutBookkeeperContainer otherCont;
-  // Take care of the peculiarities of the new xAOD EDM, i.e., create the needed AuxStore...
-  xAOD::CutBookkeeperAuxContainer otherAuxCont;
-  // ...and connect both
-  otherCont.setStore( &otherAuxCont );
-
-  // Now, iterate over all old-style EventBookkeepers and create new ones
-  for ( std::size_t i=0; i<otherContOldEDM->size(); ++i ) {
-    // Get the current old EBK
-    const ::EventBookkeeper* oldEBK = otherContOldEDM->at(i);
-
-    // Create a new CutBookkeeper
-    xAOD::CutBookkeeper* newEBK = new xAOD::CutBookkeeper();
-    otherCont.push_back( newEBK );
-
-    // Update the container
-    ATH_CHECK( this->updateContainerFromOldEDM( &otherCont, newEBK, oldEBK ) );
-  }
-
-  // Now, we can pass this one on to the standard merging method
-  ATH_CHECK( this->updateContainer( contToUpdate, &otherCont ) );
-  ATH_MSG_VERBOSE("Resulting size of contToUpdate=" << contToUpdate->size() << ", and of otherCont=" << otherCont.size() );
-
-  return StatusCode::SUCCESS;
-}
-
-
-
-
-StatusCode CutFlowSvc::updateContainerFromOldEDM( xAOD::CutBookkeeperContainer* contToUpdate,
-                                                  xAOD::CutBookkeeper* newEBK,
-                                                  const EventBookkeeper* oldEBK,
-                                                  const xAOD::CutBookkeeper* parentEBK ) {
-  // Helper class to update a container with information from another one from the old EDM
-  ATH_MSG_DEBUG("calling updateContainerFromOldEDM(contToUpdate, newEBK, oldEBK, parentEBK)" );
-  ATH_MSG_VERBOSE("Old EBK has: name=" << oldEBK->getName()
-                  << ", cycle=" << oldEBK->getCycle()
-                  << ", nAcceptedEvents=" << oldEBK->getNAcceptedEvents()
-                  << ", inputStream=" << oldEBK->getInputStream()
-                  << ", outputStream=" << oldEBK->getOutputStream() );
-
-  // Set all the properties of this new CutBookkeeper
-  newEBK->setName( oldEBK->getName() );
-  newEBK->setDescription( oldEBK->getDescription() );
-  newEBK->setInputStream( oldEBK->getInputStream() );
-  newEBK->addOutputStream( oldEBK->getOutputStream() );
-  newEBK->setCycle( oldEBK->getCycle() );
-  newEBK->setNAcceptedEvents( oldEBK->getNAcceptedEvents() );
-  newEBK->setSumOfEventWeights( oldEBK->getNWeightedAcceptedEvents() );
-  if ( parentEBK ) { newEBK->setParent( parentEBK ); }
-
-  // Deal with the translation of the logic
-  const std::string& oldLogic = oldEBK->getLogic();
-  if ( oldLogic == "Accept" ) { newEBK->setCutLogic( xAOD::CutBookkeeper::CutLogic::ACCEPT ); }
-  else if ( oldLogic == "Require" ) { newEBK->setCutLogic( xAOD::CutBookkeeper::CutLogic::REQUIRE ); }
-  else if ( oldLogic == "Veto" ) { newEBK->setCutLogic( xAOD::CutBookkeeper::CutLogic::VETO ); }
-  else if ( oldLogic == "Other" ) { newEBK->setCutLogic( xAOD::CutBookkeeper::CutLogic::OTHER ); }
-  else if ( oldLogic == "AllEvents" ) { newEBK->setCutLogic( xAOD::CutBookkeeper::CutLogic::ALLEVENTSPROCESSED ); }
-  else { newEBK->setCutLogic( xAOD::CutBookkeeper::CutLogic::UNKNOWN ); }
-
-  // Deal with the translation of the old children to the new used others
-  const std::vector<EventBookkeeper*>* oldChildren = oldEBK->getChildrenEventBookkeepers();
-  for ( std::size_t i=0; i<oldChildren->size(); ++i ) {
-    ATH_MSG_VERBOSE("Updating child number " << i);
-    // Get the current old child
-    const ::EventBookkeeper* oldChild = oldChildren->at(i);
-
-    // Create a new CutBookkeeper
-    xAOD::CutBookkeeper* newOther = new xAOD::CutBookkeeper();
-    contToUpdate->push_back( newOther );
-
-    // Add this new other to the existing CutBookkeeper
-    newEBK->addUsedOther( newOther );
-
-    // Do this iteratively
-    ATH_CHECK( this->updateContainerFromOldEDM( contToUpdate, newOther, oldChild, newEBK ) );
-  }
-  ATH_MSG_DEBUG("Done with calling updateContainerFromOldEDM(contToUpdate, newEBK, oldEBK, parentEBK)" );
-  return StatusCode::SUCCESS;
-}
-
-
-StatusCode
-CutFlowSvc::stop()
-{
-  const DataHandle<xAOD::CutBookkeeperContainer> coll;
-  std::string name = "CutBookkeepers";
-  if (m_outMetaDataStore->retrieve(coll,name).isSuccess()) {
-    for(xAOD::CutBookkeeperContainer::const_iterator it = coll->begin();
-                                          it != coll->end(); it++) {
-      ATH_MSG_INFO("CutBookkeeper " << name << " " << (*it)->inputStream() << " " << (*it)->name() << " Cyc=" << (*it)->cycle() << " N=" << (*it)->nAcceptedEvents() << " weight^2=" << (*it)->sumOfEventWeightsSquared());
+    const xAOD::CutBookkeeperContainer* constColl = 0;
+    ATH_CHECK( m_inMetaDataStore->retrieve( constColl, collName ) );
+    xAOD::CutBookkeeperContainer* tmpColl = const_cast<xAOD::CutBookkeeperContainer*>(constColl);
+    if ( !(tmpColl->hasStore()) ) {
+      ATH_MSG_VERBOSE("Setting store of xAOD::CutBookkeeperContainer");
+      // Get also the auxilliary store
+      // const SG::IConstAuxStore* auxColl = 0;
+      const xAOD::CutBookkeeperAuxContainer* auxColl = 0;
+      ATH_CHECK( m_inMetaDataStore->retrieve(auxColl, collName+"Aux.") );
+      tmpColl->setConstStore( auxColl );
     }
-  }
-  name = "IncompleteCutBookkeepers";
-  if (m_outMetaDataStore->retrieve(coll,name).isSuccess()) {
-    for(xAOD::CutBookkeeperContainer::const_iterator it = coll->begin();
-                                          it != coll->end(); it++) {
-      ATH_MSG_INFO("CutBookkeeper " << name << " " << (*it)->inputStream() << " " << (*it)->name() << " Cyc=" << (*it)->cycle() << " N=" << (*it)->nAcceptedEvents() << " weight^2=" << (*it)->sumOfEventWeightsSquared());
+    // Now, iterate over all CutBookkeepers and search for the highest cycle number
+    int maxCycle=0;
+    for ( std::size_t i=0; i<tmpColl->size(); ++i ) {
+      // Get the current old EBK
+      const xAOD::CutBookkeeper* cbk = tmpColl->at(i);
+      int inCycle = cbk->cycle();
+      if (inCycle > maxCycle) maxCycle = inCycle;
     }
+    m_skimmingCycle = std::max(m_skimmingCycle,maxCycle+1);
   }
-  return StatusCode::SUCCESS;
-}
 
-StatusCode
-CutFlowSvc::finalize()
-{
-  ATH_MSG_DEBUG( "Finalizing " << name() << " - package version " << PACKAGE_VERSION );
+  ATH_MSG_DEBUG("done calling determineCycleNumberFromInput('" << collName
+                  << "')... have now cycle number = " << m_skimmingCycle );
   return StatusCode::SUCCESS;
 }
 
@@ -961,30 +523,14 @@ CutFlowSvc::recordCollection( xAOD::CutBookkeeperContainer * coll,
 
 
 
-
-StatusCode
-CutFlowSvc::queryInterface( const InterfaceID& riid, void** ppvi )
-{
-  // valid placeholder?
-  if ( 0 == ppvi ) { return StatusCode::FAILURE ; }  // RETURN
-  if ( ICutFlowSvc::interfaceID() == riid ) {
-    *ppvi = static_cast<ICutFlowSvc*>(this);
-    addRef(); // NB! : inrement the reference count!
-    return StatusCode::SUCCESS;                     // RETURN
-  }
-  // Interface is not directly availible: try out a base class
-  return AthService::queryInterface( riid, ppvi );
+xAOD::CutBookkeeper*
+CutFlowSvc::getCutBookkeeper( const CutIdentifier cutID ) {
+  xAOD::CutBookkeeperContainer::iterator it = m_completeBook->begin();
+  xAOD::CutBookkeeperContainer::iterator ite = m_completeBook->end();
+  while (it != ite) {
+    if ((*it)->uniqueIdentifier()==cutID) return (*it);
+    ++it;
+  }
+  return 0;
 }
 
-
-
-void
-CutFlowSvc::setFilterDescription( CutIdentifier cutID,
-                                  const std::string& descr )
-{
-  ATH_MSG_DEBUG("calling setFilterDescription(" << cutID << ", " << descr << ")" );
-
-  xAOD::CutBookkeeper* ebk = this->getCutBookkeeper(cutID);
-  ebk->setDescription(descr);
-  return;
-}
diff --git a/Event/EventBookkeeperTools/src/CutFlowSvc.h b/Event/EventBookkeeperTools/src/CutFlowSvc.h
index 0601ec84e0c..062f3ec3ebb 100644
--- a/Event/EventBookkeeperTools/src/CutFlowSvc.h
+++ b/Event/EventBookkeeperTools/src/CutFlowSvc.h
@@ -27,6 +27,7 @@
 #include "GaudiKernel/ISvcLocator.h"
 #include "GaudiKernel/IIncidentListener.h"
 #include "GaudiKernel/ServiceHandle.h"
+#include "StoreGate/DataHandle.h"
 
 // Athena includes
 #include "AthenaBaseComps/AthService.h"
@@ -129,9 +130,6 @@ public:
   /// Get a CutBookkeeper given a CutID
   xAOD::CutBookkeeper* getCutBookkeeper( const CutIdentifier cutID );
 
-  // TTree* dumpCutFlowToTTree(const char* treeName="CutFlowTree");
-  // void loadCutFlowFromTTree(TTree*) override final;
-
   void print();
 
 private:
@@ -139,40 +137,11 @@ private:
   /// input meta-data store
   StatusCode determineCycleNumberFromInput( const std::string& collName );
 
-  /// Determine the cycle number from the old-style EventBookkeeper
-  StatusCode determineCycleNumberFromOldInput( const std::string& collName );
-
   /// Helper function to record the collection (and its aux store) to the
   /// output MetaData store
   StatusCode recordCollection( xAOD::CutBookkeeperContainer* coll,
                                const std::string &collName );
 
-  /// Update an existing (possibly empty) xAOD::CutBookkeeperContainer with
-  /// all the information from the container(s) form the input file
-  StatusCode updateCollFromInputStore( xAOD::CutBookkeeperContainer* coll,
-                                       const std::string &collName );
-
-  /// Helper class to update a container with information from another one
-  StatusCode updateContainer( xAOD::CutBookkeeperContainer* contToUpdate,
-                              const xAOD::CutBookkeeperContainer* otherCont );
-
-  /// Helper class to update a container with information from another one from the old EDM
-  StatusCode updateContainerFromOldEDM( xAOD::CutBookkeeperContainer* contToUpdate,
-                                        const EventBookkeeperCollection* otherContOldEDM );
-
-  /// Helper class to update a container with information from another one from the old EDM
-  StatusCode updateContainerFromOldEDM( xAOD::CutBookkeeperContainer* contToUpdate,
-                                        xAOD::CutBookkeeper* newEBK,
-                                        const EventBookkeeper* oldEBK,
-                                        const xAOD::CutBookkeeper* parentEBK=0 );
-
-  // bool inputStoreHasFlatTTree() const;
-  // void fillIncompleteCollectionFromInputStore(xAOD::CutBookkeeperContainer *coll);
-  // void fillCompleteCollectionFromInputStore(xAOD::CutBookkeeperContainer *coll);
-  // void fillCollectionFromInputStore(xAOD::CutBookkeeperContainer *coll, int wantIsComplete);
-
-
-
   /// Create a typedef
   typedef ServiceHandle<StoreGateSvc> StoreGateSvc_t;
 
@@ -185,26 +154,25 @@ private:
   /// The event store
   StoreGateSvc_t m_eventStore;
 
+  DataHandle<xAOD::CutBookkeeperContainer> m_completeBook;
+
   /// The name of the completed, i.e., fully processed, CutBookkeeperContainer
-  StringProperty m_completeCollName;
+  std::string m_completeCollName;
 
   /// The name of the incomplete, i.e., not fully processed (e.g. failed job), CutBookkeeperContainer
-  StringProperty m_incompleteCollName;
+  std::string m_incompleteCollName;
 
   /// The current skimming cycle, i.e., how many processing stages we already had
   int m_skimmingCycle;
 
-  /// The name of the currently used input file stream
-  StringProperty m_inputStream;
+  /// The name of the container in storegate with cutflow values for a file. 
+  std::string m_fileCollName;
 
-  /// Temporary container for frequent use
-  xAOD::CutBookkeeperContainer*  m_inputCompleteBookTmp;
-
-  /// Temporary auxiliary container for frequent use
-  xAOD::CutBookkeeperAuxContainer* m_inputCompleteBookAuxTmp;
+  /// The name of the currently used input file stream
+  std::string m_inputStream;
 
   /// A flag to say if the input file is currently open or not
-  bool m_fileCurrentlyOpened;
+  //bool m_fileCurrentlyOpened;
 
   /// Declare a simple typedef for the internal map
   typedef MAP_NS::unordered_map<CutIdentifier, xAOD::CutBookkeeper*> CutIDMap_t;
@@ -213,12 +181,6 @@ private:
   /// to the pointer of associated CutBookkeeper
   CutIDMap_t m_ebkMap;
 
-  /// Internal flag to track if the old-style EventBookkeepers from the input were already processed
-  bool m_alreadyCopiedEventBookkeepers;
-
-  /// Internal flag to track if we have already determined the cycle number from the first input file
-  //bool m_alreadyDeterminedCycleNumber;
-
 public:
 
   /// Publish the interface for this service
@@ -228,8 +190,6 @@ public:
 
 
 
-
-
 ///////////////////////////////////////////////////////////////////
 // Inline methods:
 ///////////////////////////////////////////////////////////////////
@@ -238,12 +198,4 @@ inline const InterfaceID& CutFlowSvc::interfaceID() {
   return ICutFlowSvc::interfaceID();
 }
 
-
-inline
-xAOD::CutBookkeeper*
-CutFlowSvc::getCutBookkeeper( const CutIdentifier cutID ) {
-  return m_ebkMap[cutID];
-}
-
-
 #endif //> !CUTFLOWSVC_H
diff --git a/Event/EventBookkeeperTools/src/FileCutFlowSvc.cxx b/Event/EventBookkeeperTools/src/FileCutFlowSvc.cxx
deleted file mode 100644
index 806c2575eb8..00000000000
--- a/Event/EventBookkeeperTools/src/FileCutFlowSvc.cxx
+++ /dev/null
@@ -1,536 +0,0 @@
-///////////////////////// -*- C++ -*- /////////////////////////////
-
-/*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
-*/
-
-// Implementation file for class FileCutFlowSvc
-// Authors: Joao Firmino da Costa <joao.costa@cern.ch> and David Cote <david.cote@cern.ch>
-///////////////////////////////////////////////////////////////////
-
-#include "FileCutFlowSvc.h"
-
-// STL include
-#include <algorithm>
-
-// #include "FillEBCFromFlat.h"
-
-#include "GaudiKernel/Incident.h"
-#include "GaudiKernel/FileIncident.h"
-#include "StoreGate/StoreClearedIncident.h"
-#include "GaudiKernel/IIncidentSvc.h"
-#include <TTree.h>
-#include <TFile.h>
-
-// EDM includes
-#include "xAODCutFlow/CutBookkeeper.h"
-#include "xAODCutFlow/CutBookkeeperContainer.h"
-#include "xAODCutFlow/CutBookkeeperAuxContainer.h"
-#include "EventBookkeeperMetaData/EventBookkeeperCollection.h"
-#include "EventBookkeeperMetaData/EventBookkeeper.h"
-#include "xAODEventInfo/EventInfo.h"
-#include "EventInfo/EventStreamInfo.h"
-
-
-FileCutFlowSvc::FileCutFlowSvc(const std::string& name,
-                       ISvcLocator* pSvcLocator ) :
-  AthService(name, pSvcLocator),
-  m_outMetaDataStore("StoreGateSvc/MetaDataStore", name),
-  m_inMetaDataStore("StoreGateSvc/InputMetaDataStore", name),
-  m_eventStore("StoreGateSvc", name),
-  m_completeCollName(""),
-  m_incompleteCollName(""),
-  m_skimmingCycle(0),
-  m_fileCollName("CutBookkeepersFile"),
-  m_inputStream("")
-{
-  declareProperty("OutputCollName",           m_completeCollName="CutBookkeepers",
-    "DEFUNCT - handled by tool now");
-  declareProperty("OutputIncompleteCollName", m_incompleteCollName = "IncompleteCutBookkeepers",
-    "DEFUNCT - handled by tool now");
-  declareProperty("SkimmingCycle",            m_skimmingCycle = 0, "DEFUNCT - handled automatically");
-  declareProperty("InputStream",              m_inputStream = "N/A", "The name of the input file stream");
-  assert( pSvcLocator );
-}
-
-
-
-FileCutFlowSvc::~FileCutFlowSvc()
-{
-}
-
-
-
-StatusCode
-FileCutFlowSvc::initialize()
-{
-  ATH_MSG_DEBUG( "Initializing " << name() << " - package version " << PACKAGE_VERSION );
-
-  //Get output MetaData StoreGate
-  ATH_CHECK( m_outMetaDataStore.retrieve() );
-  //Get input MetaData StoreGate
-  ATH_CHECK( m_inMetaDataStore.retrieve() );
-  //Get Event StoreGate
-  ATH_CHECK( m_eventStore.retrieve() );
-
-  // Align File name with complete name
-  m_fileCollName = m_completeCollName + "File";
-
-  //Get IncidentSvc
-  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", this->name());
-  ATH_CHECK( incSvc.retrieve() );
-  incSvc->addListener(this, IncidentType::BeginInputFile, 60); // pri has to be < 100 to be after MetaDataSvc.
-  incSvc->addListener(this, IncidentType::EndInputFile, 50); // pri has to be > 10 to be before MetaDataSvc.
-  incSvc->addListener(this, "MetaDataStop", 50);
-
-  xAOD::CutBookkeeperContainer* fileBook(NULL);
-  fileBook = new xAOD::CutBookkeeperContainer();
-  ATH_CHECK( recordCollection( fileBook, m_fileCollName) );
-  if (m_outMetaDataStore->retrieve(m_completeBook,m_fileCollName).isFailure()) {
-    ATH_MSG_ERROR("Could not retrieve handle to cutflowsvc bookkeeper");
-    //return StatusCode::RECOVERABLE;
-  }
-
-  // Determine the skimming cycle number that we should use now from the input file
-  ATH_MSG_VERBOSE("Have currently the cycle number = " << m_skimmingCycle );
-  ATH_CHECK( this->determineCycleNumberFromInput(m_completeCollName) );
-  ATH_MSG_VERBOSE("Will use cycle number = " << m_skimmingCycle );
-
-  return StatusCode::SUCCESS;
-}
-
-
-StatusCode
-FileCutFlowSvc::stop()
-{
-  return StatusCode::SUCCESS;
-}
-
-
-StatusCode
-FileCutFlowSvc::finalize()
-{
-  ATH_MSG_DEBUG( "Finalizing " << name() << " - package version " << PACKAGE_VERSION );
-  return StatusCode::SUCCESS;
-}
-
-
-
-StatusCode
-FileCutFlowSvc::queryInterface( const InterfaceID& riid, void** ppvi )
-{
-  // valid placeholder?
-  if ( 0 == ppvi ) { return StatusCode::FAILURE ; }  // RETURN
-  if ( ICutFlowSvc::interfaceID() == riid ) {
-    *ppvi = static_cast<ICutFlowSvc*>(this);
-    addRef(); // NB! : inrement the reference count!
-    return StatusCode::SUCCESS;                     // RETURN
-  }
-  // Interface is not directly availible: try out a base class
-  return AthService::queryInterface( riid, ppvi );
-}
-
-
-CutIdentifier FileCutFlowSvc::registerFilter( const std::string& name,
-                                          const std::string& description )
-{
-  ATH_MSG_DEBUG("calling registerFilter(" << name << ", " << description << ")" );
-
-  xAOD::CutBookkeeper* tmpEBK = new xAOD::CutBookkeeper();
-  tmpEBK->setName(name);
-  tmpEBK->setDescription(description);
-  tmpEBK->setInputStream(m_inputStream);
-  tmpEBK->setCycle(m_skimmingCycle);
-  CutIdentifier cutID = tmpEBK->uniqueIdentifier();
-
-  // Let's see if an CutBookkeeper of this name already exists
-  ATH_MSG_VERBOSE("in registerFilter(" << name << ", " << description << "): "
-                  << "Going to search if this CutBookkeeper already exists" );
-  bool existsAlready=false;
-  for ( std::size_t i=0; i<m_completeBook->size(); ++i ) {
-    xAOD::CutBookkeeper* ebk = m_completeBook->at(i);
-    if( tmpEBK->isEqualTo( ebk) ) {
-      ATH_MSG_DEBUG("The CutBookkeeper with name " << name
-                    << " and cutID " << cutID << " already exists... not adding!" );
-      existsAlready = true;
-      cutID = ebk->uniqueIdentifier();
-      break;
-    }
-  }
-
-  ATH_MSG_VERBOSE("in registerFilter(" << name << ", " << description << "): "
-                  << "Found it: " << existsAlready );
-
-  // If this CutBookkeeper already exists, delete the temporary
-  // and return the existing cutID
-  if ( existsAlready ) {
-    delete tmpEBK;
-    return cutID;
-  }
-
-  // If it is a new CutBookkeeper, add it to the container
-  ATH_MSG_DEBUG( "You are DECLARING a new filter of name " << name
-                 << " and cutID " << cutID );
-  m_completeBook->push_back(tmpEBK);
-
-  ATH_MSG_VERBOSE("done calling registerFilter(" << name << ", " << description << ")" );
-  return cutID;
-}
-
-
-
-
-CutIdentifier FileCutFlowSvc::registerCut( const std::string& name,
-                                       const std::string& description,
-                                       CutIdentifier originCutID )
-{
-  ATH_MSG_DEBUG("calling registerCut(" << name << ", " << description
-                << ", " << originCutID << ")" );
-
-  // Get the CutBookkeeper of the origin Filter Algorithm/Tool
-  xAOD::CutBookkeeper *originEBK = this->getCutBookkeeper(originCutID);
-  if ( !originEBK ) {
-    ATH_MSG_ERROR( "(file: " __FILE__ << ", line: " << __LINE__ << ") "
-                   << "Couldn't find CutBookkeeper with cutID " << originCutID );
-    return 0;
-  }
-
-  // Call the registerFilter method and get the correct CutBookkeeper
-  // from the returned cutID
-  CutIdentifier cutID = this->registerFilter( name, description );
-  xAOD::CutBookkeeper* ebk = this->getCutBookkeeper(cutID);
-  if ( !ebk ) {
-    ATH_MSG_ERROR( "(file: " __FILE__ << ", line: " << __LINE__ << ") "
-                   << "Couldn't find CutBookkeeper with cutID " << cutID );
-    return 0;
-  }
-  originEBK->addUsedOther( ebk );
-
-  return cutID;
-}
-
-
-
-
-// This method is probably only called by the DecionsSvc
-CutIdentifier FileCutFlowSvc::registerTopFilter( const std::string& name,
-                                             const std::string& description,
-                                             unsigned int logic,
-                                             const std::string& outputStream ) 
-{
-  ATH_MSG_DEBUG("calling registerTopFilter(" << name << ", " << description
-                << ", " << logic << ", " << outputStream << ")" );
-  // Call the registerFilter method and get the correct CutBookkeeper
-  // from the returned cutID
-  CutIdentifier cutID = this->registerFilter( name, description );
-  xAOD::CutBookkeeper* ebk = this->getCutBookkeeper(cutID);
-  if ( !ebk ) {
-    ATH_MSG_ERROR( "(file: " __FILE__ << ", line: " << __LINE__ << ") "
-                   << "Couldn't find CutBookkeeper with cutID " << cutID );
-    return 0;
-  }
-
-  //Then set the logic and outputStream of the relevant CutBookkeeper
-  // toFind->setDescription(description);
-  ebk->setCutLogic(xAOD::CutBookkeeper::CutLogic(logic));
-  ebk->setTopFilter(true);
-  ebk->addOutputStreamForAllUsed(outputStream);
-
-  return cutID;
-}
-
-
-
-CutIdentifier FileCutFlowSvc::declareUsedOtherFilter( const std::string& name,
-                                                  CutIdentifier originCutID )
-{
-  ATH_MSG_DEBUG("calling declareUsedOtherFilter(" << name << ", " << originCutID << ")" );
-
-  // Get the CutBookkeeper of the origin cut
-  xAOD::CutBookkeeper *originEBK = this->getCutBookkeeper(originCutID);
-  if ( !originEBK ) {
-    ATH_MSG_ERROR( "(file: " << __FILE__ << ", line: " << __LINE__ << ") "
-                   << "Couldn't find CutBookkeeper with cutID " << originCutID );
-    return 0;
-  }
-
-  // Create a temporary CutBookkeeper object
-  xAOD::CutBookkeeper* tmpEBK = new xAOD::CutBookkeeper();
-  // tmpEBK->makePrivateStore();
-  tmpEBK->setName(name);
-  tmpEBK->setInputStream(m_inputStream);
-  tmpEBK->setCycle(m_skimmingCycle);
-  CutIdentifier cutID = tmpEBK->uniqueIdentifier();
-
-  // See if the CutBookkeeper already exists or not
-  bool existsAlready = false;
-  for ( std::size_t i=0; i<m_completeBook->size(); ++i ) {
-    xAOD::CutBookkeeper* ebk = m_completeBook->at(i);
-    if( tmpEBK->isEqualTo( ebk ) ) {
-      originEBK->addUsedOther( ebk );
-      cutID = ebk->uniqueIdentifier();
-      existsAlready = true;
-    }
-  }
-
-  // If this CutBookkeeper already exists, delete the temporary
-  // and return the existing cutID
-  if ( existsAlready ) {
-    delete tmpEBK;
-    return cutID;
-  }
-
-  // Otherwise, add the new one to the collection
-  tmpEBK->setDescription( "Registered by origin filter" );
-  originEBK->addUsedOther( tmpEBK );
-  m_completeBook->push_back( tmpEBK );
-
-  return cutID;
-}
-
-
-
-void
-FileCutFlowSvc::setFilterDescription( CutIdentifier cutID,
-                                  const std::string& descr )
-{
-  ATH_MSG_DEBUG("calling setFilterDescription(" << cutID << ", " << descr << ")" );
-
-  xAOD::CutBookkeeper* ebk = this->getCutBookkeeper(cutID);
-  ebk->setDescription(descr);
-  return;
-}
-
-
-
-
-void
-FileCutFlowSvc::addEvent( CutIdentifier cutID )
-{
-  ATH_MSG_INFO("calling addEvent(" << cutID << ")" );
-
-  double evtWeight=1.0;
-
-  addEvent(cutID,evtWeight);
-
-  return;
-}
-
-
-
-void
-FileCutFlowSvc::addEvent( CutIdentifier cutID, double weight)
-{
-  ATH_MSG_INFO("calling addEvent(" << cutID << ", " << weight << ")" );
-
-  xAOD::CutBookkeeper* eb = this->getCutBookkeeper(cutID);
-  if ( !eb ) {
-    ATH_MSG_INFO("Could not find eb");
-
-    // Iterate over the complete bookkeepers and update the cutID-to-bookkeeper map
-    ATH_MSG_DEBUG( "addEvent: Going to re-populate the map. Have "
-                   << m_completeBook->size() << " CutBookkeepers"
-                   << " and skimming cycle " << m_skimmingCycle
-                   << " and input Stream name " << m_inputStream );
-    xAOD::CutBookkeeperContainer::iterator iter    = m_completeBook->begin();
-    xAOD::CutBookkeeperContainer::iterator iterEnd = m_completeBook->end();
-    for ( ; iter != iterEnd; ++iter ) {
-      xAOD::CutBookkeeper* ebk = *iter;
-      CutIdentifier cutID = ebk->uniqueIdentifier();
-      ATH_MSG_VERBOSE( "addEvent: Have CutBookkeeper with"
-                       << " skimming cycle " << ebk->cycle()
-                       << " and input Stream name " << ebk->inputStream()
-                       << " and logic " << ebk->cutLogic()
-                       << " isTopFilter " << ebk->isTopFilter()
-                       << " and cutID " << cutID
-                       << " and name " << ebk->name() );
-      if ( m_skimmingCycle == ebk->cycle() ) {
-        if ( m_inputStream == ebk->inputStream() ) {
-          CutIDMap_t::iterator mapIter = m_ebkMap.find(cutID);
-          ATH_MSG_DEBUG( "BeginInputFile: Have CutBookkeeper with"
-                         << " cutID " << cutID
-                         <<  " and name " << ebk->name() );
-          if ( mapIter != m_ebkMap.end() ) { // we found this CutBookkeeper in the existing map
-            (*mapIter).second = ebk;
-          }
-        }
-      }
-    } // End: Loop over all complete CutBookkeepers
-    eb = this->getCutBookkeeper(cutID);
-  }
-  if ( !eb ) {
-    ATH_MSG_ERROR ( "Got a zero pointer to an CutBookkeeper with cutID="
-                    << cutID << "! This should never happen..." );
-    return;
-  }
-  ATH_MSG_VERBOSE( "addEvent: have cutID " << cutID
-                   << " and CutBookkeeper name " << eb->name() );
-  eb->addNAcceptedEvents(1);
-  eb->addSumOfEventWeights(weight);
-  eb->addSumOfEventWeightsSquared(weight*weight);
-  return;
-}
-
-
-
-//__________________________________________________________________________
-void FileCutFlowSvc::handle( const Incident& inc )
-{
-  ATH_MSG_VERBOSE( "Start incident " << inc.type() );
-
-  //OPENING NEW INPUT FILE
-  //Things to do:
-  // 1) note that a file is currently opened
-  // 2) Load CutBookkeepers from input file
-  //    2a) if incomplete from input, directly propagate to output
-  //    2b) if complete from input, wait for EndInputFile to decide what to do in output
-
-  if ( inc.type() == IncidentType::BeginInputFile ) {
-    // Check the stream name
-    const EventStreamInfo* esi;
-    if (m_inMetaDataStore->retrieve(esi).isFailure()) {
-      ATH_MSG_WARNING("No EventStreamInfo taking stream from property InputStream");
-    }
-    else {
-      std::string inputstream = *(esi->getProcessingTags().begin());
-      if (m_inputStream.empty()) {m_inputStream=inputstream;}
-      else if (m_inputStream!=inputstream) {
-        const FileIncident* finc = dynamic_cast<const FileIncident*>(&inc);
-        ATH_MSG_FATAL("File " << finc->fileName() 
-                              << " stream " << inputstream 
-                              << " does not match previous file " 
-                              << m_inputStream);
-        return;
-      }
-    }
-
-    // Clear the file bookkeeper
-    if (m_completeBook.isValid()) {
-      // Reset existing container
-      for (xAOD::CutBookkeeperContainer::iterator it = m_completeBook->begin();
-           it != m_completeBook->end(); ++it) {
-        (*it)->setNAcceptedEvents(0);
-        (*it)->setSumOfEventWeights(0);
-        (*it)->setSumOfEventWeightsSquared(0);
-      }
-    }
-  }
-
-  // Clean up the bookkeeper before output
-  //if ( inc.type() == "MetaDataStop" || inc.type() == "EndInputFile") {
-  if ( inc.type() == "MetaDataStop" ) {
-    if (m_completeBook.isValid()) {
-      // Reset existing container
-      for (xAOD::CutBookkeeperContainer::iterator it = m_completeBook->begin();
-           it != m_completeBook->end(); ++it) {
-      }
-    }
-    const xAOD::CutBookkeeperContainer* fileBook(NULL);
-    if( !(m_outMetaDataStore->retrieve(fileBook, m_fileCollName) ).isSuccess() ) {
-      ATH_MSG_WARNING( "Could not get " << m_fileCollName 
-                       << " CutBookkeepers from output MetaDataStore" );
-    }
-    else {
-      const SG::IConstAuxStore* fileBookAux = fileBook->getConstStore();
-      if (m_outMetaDataStore->removeDataAndProxy(fileBook).isFailure()) {
-        ATH_MSG_ERROR("Unable to remove " << m_fileCollName);
-      }
-      if (m_outMetaDataStore->removeDataAndProxy(fileBookAux).isFailure()) {
-        ATH_MSG_ERROR("Unable to remove " << m_fileCollName);
-      }
-    }
-  }
-
-  ATH_MSG_DEBUG( "End incident " << inc.type() );
-  return;
-}
-
-
-void
-FileCutFlowSvc::print()
-{
-  return;
-}
-
-
-StatusCode FileCutFlowSvc::determineCycleNumberFromInput( const std::string& collName )
-{
-  ATH_MSG_DEBUG("calling determineCycleNumberFromInput('" << collName
-                  << "')... have currently cycle number = " << m_skimmingCycle );
-
-  // Try to get CutBookkeepers from the input file
-  if ( m_inMetaDataStore->contains<xAOD::CutBookkeeperContainer>(collName) ) {
-    ATH_MSG_VERBOSE("Found xAOD::CutBookkeeperContainer in input MetaStore with name: " << collName);
-
-    // There can always only be a single object in the input store. As the store
-    // is connected to just a single input file.
-    const xAOD::CutBookkeeperContainer* constColl = 0;
-    ATH_CHECK( m_inMetaDataStore->retrieve( constColl, collName ) );
-    xAOD::CutBookkeeperContainer* tmpColl = const_cast<xAOD::CutBookkeeperContainer*>(constColl);
-    if ( !(tmpColl->hasStore()) ) {
-      ATH_MSG_VERBOSE("Setting store of xAOD::CutBookkeeperContainer");
-      // Get also the auxilliary store
-      // const SG::IConstAuxStore* auxColl = 0;
-      const xAOD::CutBookkeeperAuxContainer* auxColl = 0;
-      ATH_CHECK( m_inMetaDataStore->retrieve(auxColl, collName+"Aux.") );
-      tmpColl->setConstStore( auxColl );
-    }
-    // Now, iterate over all CutBookkeepers and search for the highest cycle number
-    int maxCycle=0;
-    for ( std::size_t i=0; i<tmpColl->size(); ++i ) {
-      // Get the current old EBK
-      const xAOD::CutBookkeeper* cbk = tmpColl->at(i);
-      int inCycle = cbk->cycle();
-      if (inCycle > maxCycle) maxCycle = inCycle;
-    }
-    m_skimmingCycle = std::max(m_skimmingCycle,maxCycle+1);
-  }
-
-  ATH_MSG_DEBUG("done calling determineCycleNumberFromInput('" << collName
-                  << "')... have now cycle number = " << m_skimmingCycle );
-  return StatusCode::SUCCESS;
-}
-
-
-
-StatusCode
-FileCutFlowSvc::recordCollection( xAOD::CutBookkeeperContainer * coll,
-                              const std::string &collName) {
-  ATH_MSG_VERBOSE("calling recordCollection(..., " << collName << ")" );
-
-  //Expected that FileCutFlowSvc is the only one allowed to record *coll
-  if( m_outMetaDataStore->contains<xAOD::CutBookkeeperContainer>(collName) ) {
-    ATH_MSG_ERROR( "xAOD::CutBookkeeperContainer " << collName
-      << " already exists in output MetaData store. This is unexpected." );
-    return StatusCode::FAILURE;
-  }
-
-  // Record the container
-  ATH_CHECK( m_outMetaDataStore->record(coll, collName) );
-  ATH_MSG_VERBOSE("Recorded xAOD::CutBookkeeperContainer " << collName);
-
-
-  // Take care of the peculiarities of the new xAOD EDM, i.e., create the needed AuxStore
-  xAOD::CutBookkeeperAuxContainer* auxCont = new xAOD::CutBookkeeperAuxContainer;
-  coll->setStore( auxCont ); //gives it a new associated aux container
-
-  // Record the aux container
-  ATH_CHECK( m_outMetaDataStore->record( auxCont, collName+"Aux." ) );
-  ATH_MSG_VERBOSE( "Recorded xAOD::CutBookkeeperContainer " << collName << "Aux." );
-
-  return StatusCode::SUCCESS;
-}
-
-
-
-xAOD::CutBookkeeper*
-FileCutFlowSvc::getCutBookkeeper( const CutIdentifier cutID ) {
-  xAOD::CutBookkeeperContainer::iterator it = m_completeBook->begin();
-  xAOD::CutBookkeeperContainer::iterator ite = m_completeBook->end();
-  while (it != ite) {
-    if ((*it)->uniqueIdentifier()==cutID) return (*it);
-    ++it;
-  }
-  return 0;
-}
-
diff --git a/Event/EventBookkeeperTools/src/FileCutFlowSvc.h b/Event/EventBookkeeperTools/src/FileCutFlowSvc.h
deleted file mode 100644
index 5a7f8c66748..00000000000
--- a/Event/EventBookkeeperTools/src/FileCutFlowSvc.h
+++ /dev/null
@@ -1,201 +0,0 @@
-///////////////////////// -*- C++ -*- /////////////////////////////
-
-/*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
-*/
-
-// Header file for class FileCutFlowSvc
-// Authors: Joao Firmino da Costa <joao.costa@cern.ch> and David Cote <david.cote@cern.ch>
-
-///////////////////////////////////////////////////////////////////
-#ifndef FILECUTFLOWSVC_H
-#define FILECUTFLOWSVC_H
-
-/**
- * @class FileCutFlowSvc
- * @brief This implementes the methods for ICutFlowSvc
- */
-
-// for size_t
-#include <cassert>
-
-// STL includes
-#include <string>
-#include <vector>
-
-// FrameWork includes
-#include "GaudiKernel/ISvcLocator.h"
-#include "GaudiKernel/IIncidentListener.h"
-#include "GaudiKernel/ServiceHandle.h"
-#include "StoreGate/DataHandle.h"
-
-// Athena includes
-#include "AthenaBaseComps/AthService.h"
-#include "AthenaKernel/ICutFlowSvc.h"
-#include "StoreGate/StoreGateSvc.h"
-
-// EDM includes
-#include "xAODCutFlow/CutBookkeeper.h"
-#include "xAODCutFlow/CutBookkeeperContainer.h"
-#include "xAODCutFlow/CutBookkeeperAuxContainer.h"
-
-// STL include(s):
-#if __cplusplus < 201100
-#   include <tr1/unordered_map>
-namespace MAP_NS = std::tr1;
-#else
-#   include <unordered_map>
-namespace MAP_NS = std;
-#endif // C++
-
-// forward declarations
-class EventBookkeeperCollection;
-class EventBookkeeper;
-
-
-
-class FileCutFlowSvc :
-  virtual public ICutFlowSvc,
-  virtual public IIncidentListener,
-          public AthService
-{
-
-public:
-
-/// Constructor
-  FileCutFlowSvc(const std::string& name, ISvcLocator* pSvcLocator );
-
-  /// Destructor
-  virtual ~FileCutFlowSvc();
-
-  /// Gaudi Service Implementation
-  //@{
-  virtual StatusCode initialize() override;
-  virtual StatusCode stop() override;
-  virtual StatusCode finalize() override;
-  virtual StatusCode queryInterface( const InterfaceID& riid, void** ppvi ) override;
-  //@}
-
-
-  /// Incident service handle listening for BeginFile and EndFile.
-  virtual void handle(const Incident& incident) override;
-
-  ///////////////////////////////////////////////////////////////////
-  // Non-const methods:
-  ///////////////////////////////////////////////////////////////////
-
-public:
-
-  /// Register filter in the FileCutFlowSvc and returns the CutID of the
-  /// corresponding CutBookkeeper.
-  /// This method should be used by filters that register themselves.
-  CutIdentifier registerFilter( const std::string& name,
-                                const std::string& description ) override final;
-
-  /// Register cut as child of a filter in the FileCutFlowSvc and returns the CutID
-  /// of the corresponding CutBookkeeper. This method should be used by
-  /// filters to register their internal cuts that are not the Algs themselves.
-  CutIdentifier registerCut( const std::string& name,
-                             const std::string& description,
-                             CutIdentifier originCutID ) override final;
-
-  /// Tells FileCutFlowSvc that a filter is used directly by an outputStream with
-  /// a given logical context. The only foreseen client should the DecisionSvc,
-  /// with its Accept/Require/Veto.
-  CutIdentifier registerTopFilter( const std::string& name,
-                                   const std::string& description,
-                                   unsigned int logic,
-                                   const std::string& outputStream ) override final;
-
-  /// Tells FileCutFlowSvc that a filter should not be treated as as being used by
-  /// another filter. This should be used by filters that use other filter Algs
-  /// internally, e.g., like the LogicalFilterCombiner
-  CutIdentifier declareUsedOtherFilter( const std::string& name,
-                                        CutIdentifier originCutID ) override final;
-
-  /// Set the description of an existing CutBookkeeper
-  void setFilterDescription( CutIdentifier cutID,
-                             const std::string& descr ) override final;
-
-  /// Tells FileCutFlowSvc to update the event counter of a CutIdentifier cutID,
-  /// using the CutIdentifier returned by selfRegisterFilter or registerCut
-  /// Internally, the Monte Carlo event weight will be retrieved from the
-  /// xAOD::EventInfo object as evtWeight = evtInfo->mcEventWeight();
-  void addEvent( CutIdentifier cutID ) override final;
-
-  /// Tells FileCutFlowSvc to update the weighted event counter of a CutIdentifier cutID,
-  /// using CutIdentifier returned by selfRegisterFilter or registerCut
-  void addEvent( CutIdentifier cutID, double weight ) override final;
-
-  /// Get a CutBookkeeper given a CutID
-  xAOD::CutBookkeeper* getCutBookkeeper( const CutIdentifier cutID );
-
-  void print();
-
-private:
-  /// Helper function to determine the processing cycle number from the
-  /// input meta-data store
-  StatusCode determineCycleNumberFromInput( const std::string& collName );
-
-  /// Helper function to record the collection (and its aux store) to the
-  /// output MetaData store
-  StatusCode recordCollection( xAOD::CutBookkeeperContainer* coll,
-                               const std::string &collName );
-
-  /// Create a typedef
-  typedef ServiceHandle<StoreGateSvc> StoreGateSvc_t;
-
-  /// The output meta-data store
-  StoreGateSvc_t m_outMetaDataStore;
-
-  /// The input meta-data store
-  StoreGateSvc_t m_inMetaDataStore;
-
-  /// The event store
-  StoreGateSvc_t m_eventStore;
-
-  DataHandle<xAOD::CutBookkeeperContainer> m_completeBook;
-
-  /// The name of the completed, i.e., fully processed, CutBookkeeperContainer
-  std::string m_completeCollName;
-
-  /// The name of the incomplete, i.e., not fully processed (e.g. failed job), CutBookkeeperContainer
-  std::string m_incompleteCollName;
-
-  /// The current skimming cycle, i.e., how many processing stages we already had
-  int m_skimmingCycle;
-
-  /// The name of the container in storegate with cutflow values for a file. 
-  std::string m_fileCollName;
-
-  /// The name of the currently used input file stream
-  std::string m_inputStream;
-
-  /// A flag to say if the input file is currently open or not
-  //bool m_fileCurrentlyOpened;
-
-  /// Declare a simple typedef for the internal map
-  typedef MAP_NS::unordered_map<CutIdentifier, xAOD::CutBookkeeper*> CutIDMap_t;
-
-  /// This internal map keeps the association between the instance identifier of each algorithm
-  /// to the pointer of associated CutBookkeeper
-  CutIDMap_t m_ebkMap;
-
-public:
-
-  /// Publish the interface for this service
-  static const InterfaceID& interfaceID();
-
-};
-
-
-
-///////////////////////////////////////////////////////////////////
-// Inline methods:
-///////////////////////////////////////////////////////////////////
-
-inline const InterfaceID& FileCutFlowSvc::interfaceID() {
-  return ICutFlowSvc::interfaceID();
-}
-
-#endif //> !FILECUTFLOWSVC_H
diff --git a/Event/EventBookkeeperTools/src/components/EventBookkeeperTools_entries.cxx b/Event/EventBookkeeperTools/src/components/EventBookkeeperTools_entries.cxx
index 0dcc53404fa..0d68092771c 100644
--- a/Event/EventBookkeeperTools/src/components/EventBookkeeperTools_entries.cxx
+++ b/Event/EventBookkeeperTools/src/components/EventBookkeeperTools_entries.cxx
@@ -1,6 +1,6 @@
 #include "EventBookkeeperTools/myCppFilterTest.h"
 #include "../SkimDecisionMultiFilter.h"
-#include "../FileCutFlowSvc.h"
+//#include "../FileCutFlowSvc.h"
 #include "../CutFlowSvc.h"
 #include "EventBookkeeperTools/BookkeeperTool.h"
 #include "../EventCounterAlg.h"
@@ -10,5 +10,5 @@ DECLARE_COMPONENT( SkimDecisionMultiFilter )
 DECLARE_COMPONENT( EventCounterAlg )
 DECLARE_COMPONENT( BookkeeperTool )
 DECLARE_COMPONENT( CutFlowSvc )
-DECLARE_COMPONENT( FileCutFlowSvc )
+//DECLARE_COMPONENT( FileCutFlowSvc )
 
-- 
GitLab