From a59d66a7c7db1f1e0958683bbfd2c38ca33a1676 Mon Sep 17 00:00:00 2001
From: cranshaw <Jack.Cranshaw@cern.ch>
Date: Fri, 15 Jun 2018 11:48:55 -0500
Subject: [PATCH] Changes to BookkeeperTool to support MetaCont use (first
 iteration) BookkeeperTool   - At BeginInputFile     - MetaCont created at and
 put in output store     - Input containers put in MetaCont (incomplete and
 tmp)   - At EndInputFile     - source id is recorded in vector m_completes  
 - At MDS     - all incomplete are merged and container is put in output store
     - all tmp in MetaCont with source id in m_completes merged and      
 container put in output store     - all tmp in MetaCont _without source id in
 m_completes merged into       incomplete container AthenaOutputStream   -
 stop method added   - MetaDataSvc->prepareOutput called at stop   -
 MetaDataSvc->prepareOutput called at transitionMetadataFile

---
 .../AthenaServices/src/AthenaOutputStream.cxx |  41 +++-
 .../AthenaServices/src/AthenaOutputStream.h   |   5 +
 Control/AthenaServices/src/MetaDataSvc.cxx    |   1 +
 .../EventBookkeeperTools/BookkeeperTool.h     |   7 +-
 .../Root/BookkeeperTool.cxx                   | 204 +++++++-----------
 5 files changed, 130 insertions(+), 128 deletions(-)

diff --git a/Control/AthenaServices/src/AthenaOutputStream.cxx b/Control/AthenaServices/src/AthenaOutputStream.cxx
index 449a575211ad..f99e4a7f72ea 100644
--- a/Control/AthenaServices/src/AthenaOutputStream.cxx
+++ b/Control/AthenaServices/src/AthenaOutputStream.cxx
@@ -144,18 +144,20 @@ AthenaOutputStream::AthenaOutputStream(const string& name, ISvcLocator* pSvcLoca
         m_dataStore("StoreGateSvc", name),
         m_metadataStore("MetaDataStore", name),
         m_currentStore(&m_dataStore),
-                m_itemSvc("ItemListSvc", name),
+        m_itemSvc("ItemListSvc", name),
 	m_outputAttributes(),
-          m_pCLIDSvc("ClassIDSvc", name),
-          m_outSeqSvc("OutputStreamSequencerSvc", name),
+        m_pCLIDSvc("ClassIDSvc", name),
+        m_outSeqSvc("OutputStreamSequencerSvc", name),
         m_p2BWritten(string("SG::Folder/") + name + string("_TopFolder"), this),
         m_decoder(string("SG::Folder/") + name + string("_excluded"), this),
-                m_events(0),
+        m_transient(string("SG::Folder/") + name + string("_transient"), this),
+        m_events(0),
         m_streamer(string("AthenaOutputStreamTool/") + name + string("Tool"), this),
    m_helperTools(this) {
    assert(pSvcLocator);
    declareProperty("ItemList",               m_itemList);
    declareProperty("MetadataItemList",       m_metadataItemList);
+   declareProperty("TransientItems",         m_transientItems);
    declareProperty("OutputFile",             m_outputName="DidNotNameOutput.root");
    declareProperty("EvtConversionSvc",       m_persName="EventPersistencySvc");
    declareProperty("WritingTool",            m_streamer);
@@ -280,6 +282,35 @@ StatusCode AthenaOutputStream::initialize() {
       ATH_MSG_FATAL("Could re-init I/O component");
       return(status);
    }
+
+   // Add an explicit input dependency for everything in our item list
+   // that we know from the configuration is in the transient store.
+   // We don't want to add everything on the list, because configurations
+   // often initialize this with a maximal static list of everything
+   // that could possibly be written.
+   {
+     ATH_CHECK( m_transient.retrieve() );
+     IProperty *pAsIProp = dynamic_cast<IProperty*> (&*m_transient);
+     if (!pAsIProp) {
+       ATH_MSG_FATAL ("Bad folder interface");
+       return StatusCode::FAILURE;
+     }
+     ATH_CHECK (pAsIProp->setProperty("ItemList", m_transientItems.toString()));
+
+     for (const SG::FolderItem& item : *m_p2BWritten) {
+       const std::string& k = item.key();
+       if (k.find('*') != std::string::npos) continue;
+       if (k.find('.') != std::string::npos) continue;
+       for (const SG::FolderItem& titem : *m_transient) {
+         if (titem.id() == item.id() && titem.key() == k) {
+           DataObjID id (item.id(), m_dataStore.name() + "+" + k);
+           this->addDependency (id, Gaudi::DataHandle::Reader);
+           break;
+         }
+       }
+     }
+   }
+
    ATH_MSG_DEBUG("End initialize");
    if (baseStatus == StatusCode::FAILURE) return StatusCode::FAILURE;
    return(status);
@@ -300,7 +331,7 @@ StatusCode AthenaOutputStream::stop()
          }
          ATH_MSG_INFO("Records written: " << m_events);
       }
-      FileIncident fileInc(name(),"MetaDataStop","","");
+      FileIncident fileInc(name(),"MetaDataStop","","Serial");
       ServiceHandle<MetaDataSvc> mdsvc("MetaDataSvc", name());
       if (mdsvc.retrieve().isFailure()) {
          ATH_MSG_ERROR("Could not retrieve MetaDataSvc for stop actions");
diff --git a/Control/AthenaServices/src/AthenaOutputStream.h b/Control/AthenaServices/src/AthenaOutputStream.h
index 8f08c8080006..b578976339b5 100644
--- a/Control/AthenaServices/src/AthenaOutputStream.h
+++ b/Control/AthenaServices/src/AthenaOutputStream.h
@@ -80,10 +80,15 @@ protected:
    StringArrayProperty      m_metadataItemList;
    /// Vector of item names
    StringArrayProperty      m_excludeList;
+   /// List of items that are known to be present in the transient store
+   /// (and hence we can make input dependencies on them).
+   StringArrayProperty      m_transientItems;
    /// the top-level folder with items to be written
    ToolHandle<SG::IFolder>  m_p2BWritten;
    /// the top-level folder with items to be written
    ToolHandle<SG::IFolder>  m_decoder;
+   /// Decoded list of transient ids.
+   ToolHandle<SG::IFolder>  m_transient;
    /// map of (clid,key) pairs to be excluded (comes from m_excludeList)
    std::multimap<CLID,std::string> m_CLIDKeyPairs;
    /// Collection of objects being selected
diff --git a/Control/AthenaServices/src/MetaDataSvc.cxx b/Control/AthenaServices/src/MetaDataSvc.cxx
index 2d3ee4e81dd9..9f295ab5e76e 100644
--- a/Control/AthenaServices/src/MetaDataSvc.cxx
+++ b/Control/AthenaServices/src/MetaDataSvc.cxx
@@ -327,6 +327,7 @@ StatusCode MetaDataSvc::prepareOutput(const Incident& inc)
       return StatusCode::FAILURE;
    }
    const std::string guid = fileInc->fileGuid();
+   ATH_MSG_INFO("BLARG guid=" << guid);
    StatusCode rc(StatusCode::SUCCESS);
    for (auto it = m_metaDataTools.begin(); it != m_metaDataTools.end(); ++it) {
       ATH_MSG_DEBUG(" calling metaDataStop for " << (*it)->name());
diff --git a/Event/EventBookkeeperTools/EventBookkeeperTools/BookkeeperTool.h b/Event/EventBookkeeperTools/EventBookkeeperTools/BookkeeperTool.h
index 5ea882025174..8c9e08a5a470 100644
--- a/Event/EventBookkeeperTools/EventBookkeeperTools/BookkeeperTool.h
+++ b/Event/EventBookkeeperTools/EventBookkeeperTools/BookkeeperTool.h
@@ -47,7 +47,7 @@ public: // Constructor and Destructor
 public:
    //void handle(const Incident& incident);
    virtual StatusCode metaDataStop();
-   virtual StatusCode metaDataStop(const SG::SourceID& sid = "Serial");
+   virtual StatusCode metaDataStop(const SG::SourceID&);
    virtual StatusCode beginInputFile();
    virtual StatusCode beginInputFile(const SG::SourceID& sid = "Serial");
    virtual StatusCode endInputFile();
@@ -63,7 +63,7 @@ private:
 
   StatusCode copyContainerToOutput(const SG::SourceID& sid = "Serial", const std::string& outname = "");
 
-  StatusCode initOutputContainer(const std::string& sgkey, const SG::SourceID& sid);
+  StatusCode initOutputContainer(const std::string& sgkey);
 
   /// Fill Cutflow information
   StatusCode addCutFlow();
@@ -80,6 +80,9 @@ private:
   /// The name of the CutFlowSvc CutBookkeeperContainer
   std::string m_cutflowCollName;
 
+  /// List of source ids which have reached end file
+  std::set<SG::SourceID> m_completes;
+
   bool m_cutflowTaken;
 
 };
diff --git a/Event/EventBookkeeperTools/Root/BookkeeperTool.cxx b/Event/EventBookkeeperTools/Root/BookkeeperTool.cxx
index 5eeaeb6cf8b9..5a7d4175d06c 100644
--- a/Event/EventBookkeeperTools/Root/BookkeeperTool.cxx
+++ b/Event/EventBookkeeperTools/Root/BookkeeperTool.cxx
@@ -161,7 +161,6 @@ StatusCode BookkeeperTool::beginInputFile()
 #ifdef ASGTOOL_ATHENA
 StatusCode BookkeeperTool::beginInputFile(const SG::SourceID& sid)
 {
-  ATH_MSG_INFO("BLARG 2 " << sid);
   //OPENING NEW INPUT FILE
   //Things to do:
   // 1) note that a file is currently opened
@@ -169,103 +168,52 @@ StatusCode BookkeeperTool::beginInputFile(const SG::SourceID& sid)
   //    2a) if incomplete from input, directly propagate to output
   //    2b) if complete from input, wait for EndInputFile to decide what to do in output
 
-  //  Now make sure the output containers are in the output store
+  std::string tmp_name = m_outputCollName+"tmp";
+  std::string inc_name = "Incomplete"+m_outputCollName; 
+  //  IF NO METACONT IN OUTPUT STORE YET
+  //     Initialize MetaCont for incomplete and tmp containers in output store
   //
-  //  Make sure complete container exists in output
   if( !(outputMetaStore()->contains<MetaCont<xAOD::CutBookkeeperContainer> >(m_outputCollName)) ) {
-    ATH_CHECK(this->initOutputContainer(m_outputCollName,sid));
-/*
-      // Now create the complete container
-    xAOD::CutBookkeeperContainer* inc = new xAOD::CutBookkeeperContainer();
-    xAOD::CutBookkeeperAuxContainer* auxinc = new xAOD::CutBookkeeperAuxContainer();
-    inc->setStore(auxinc);
-    MetaCont<xAOD::CutBookkeeperContainer>* mcont = new MetaCont<xAOD::CutBookkeeperContainer>(DataObjID("xAOD::CutBookkeeperContainer",m_outputCollName));
-    if(!mcont->insert(sid,inc)) {
-      ATH_MSG_ERROR("Unable to insert into MetaCont");
-    }
-    ATH_CHECK(outputMetaStore()->record(std::move(mcont),m_outputCollName));
-    std::string auxkey(m_outputCollName+"Aux.");
-    MetaCont<xAOD::CutBookkeeperAuxContainer>* acont = new MetaCont<xAOD::CutBookkeeperAuxContainer>(DataObjID("xAOD::CutBookkeeperAuxContainer",auxkey));
-    //MetaCont<SG::IConstAuxStore>* acont = new MetaCont<SG::IConstAuxStore>(DataObjID("xAOD::CutBookkeeperAuxContainer",auxkey));
-    ATH_CHECK(outputMetaStore()->record(std::move(acont),auxkey));
-    ATH_CHECK(outputMetaStore()->symLink
-            (
-              ClassID_traits<MetaCont<xAOD::CutBookkeeperAuxContainer> >::ID(),
-              auxkey,
-              ClassID_traits<xAOD::CutBookkeeperAuxContainer>::ID()
-            ));
-*/
-/*
-    ATH_CHECK(outputMetaStore()->symLink
-            (
-              ClassID_traits<MetaCont<SG::IConstAuxStore> >::ID(),
-              auxkey,
-              ClassID_traits<SG::IConstAuxStore>::ID()
-            ));
-*/
-    // Below to be deprecated
-    //ATH_CHECK(outputMetaStore()->record(inc,m_outputCollName));
-    //ATH_CHECK(outputMetaStore()->record(auxinc,m_outputCollName+"Aux."));
+    ATH_CHECK(this->initOutputContainer(tmp_name));
   }
   else {
     ATH_MSG_WARNING("complete collection already exists");
   }
-  //  Make sure incomplete container exists in output
-  std::string inc_name = "Incomplete"+m_outputCollName;
   if( !(outputMetaStore()->contains<MetaCont<xAOD::CutBookkeeperContainer> >(inc_name)) ) {
-    ATH_CHECK(this->initOutputContainer(inc_name,sid));
-/*
-      // Now create the complete container
-    xAOD::CutBookkeeperContainer* coll = new xAOD::CutBookkeeperContainer();
-    xAOD::CutBookkeeperAuxContainer* auxcoll = new xAOD::CutBookkeeperAuxContainer();
-    coll->setStore(auxcoll);
-    MetaCont<xAOD::CutBookkeeperContainer>* mcont = new MetaCont<xAOD::CutBookkeeperContainer>(DataObjID("xAOD::CutBookkeeperContainer",inc_name));
-    if(!mcont->insert(sid,coll)) {
-      ATH_MSG_ERROR("Unable to insert into MetaCont");
-    }
-    ATH_CHECK(outputMetaStore()->record(std::move(mcont),inc_name));
-    std::string auxkey(inc_name+"Aux.");
-    MetaCont<xAOD::CutBookkeeperAuxContainer>* acont = new MetaCont<xAOD::CutBookkeeperAuxContainer>(DataObjID("xAOD::CutBookkeeperAuxContainer",auxkey));
-    ATH_CHECK(outputMetaStore()->record(std::move(acont),auxkey));
-    ATH_CHECK(outputMetaStore()->symLink
-            (
-              ClassID_traits<MetaCont<xAOD::CutBookkeeperAuxContainer> >::ID(),
-              auxkey,
-              ClassID_traits<xAOD::CutBookkeeperAuxContainer>::ID()
-            ));
-*/
-    //ATH_CHECK(outputMetaStore()->record(coll,inc_name));
-    //ATH_CHECK(outputMetaStore()->record(auxcoll,inc_name+"Aux."));
+    ATH_CHECK(this->initOutputContainer(inc_name));
   }
   else {
     ATH_MSG_WARNING("incomplete collection already exists");
   }
 
+  // Now retrieve pointers for the MetaConts
+  MetaCont<xAOD::CutBookkeeperContainer>* tmp;
+  MetaCont<xAOD::CutBookkeeperContainer>* inc;
+  ATH_CHECK(outputMetaStore()->retrieve(tmp,tmp_name));
+  ATH_CHECK(outputMetaStore()->retrieve(inc,inc_name));
+
+  // Make sure sid does not already exist in container
+  if (std::find(tmp->sources().begin(),tmp->sources().end(),sid)!=tmp->sources().end() ||  
+      std::find(inc->sources().begin(),inc->sources().end(),sid)!=inc->sources().end() ) {
+    ATH_MSG_ERROR("Metadata already exists for sid " << sid);
+    return StatusCode::FAILURE;
+  }
+
   // reset cutflow taken marker
   m_cutflowTaken = false;
 
+  // NOW GET NEW INFORMATION FROM INPUT STORE
+  //
   // Get the incomplete bookkeeper collection of the input metadata store
-  const xAOD::CutBookkeeperContainer* input_inc = 0;
-  // Construct input and output incomplete names
   std::string inCollName = "Incomplete" + m_inputCollName;
-  std::string outCollName = "Incomplete" + m_outputCollName;
+  xAOD::CutBookkeeperContainer* input_inc = 0;
   if (inputMetaStore()->contains<xAOD::CutBookkeeperContainer>(inCollName) ) {
     StatusCode ssc = inputMetaStore()->retrieve( input_inc, inCollName );
     if (ssc.isSuccess()) {
       // retrieve the incomplete output container
-      xAOD::CutBookkeeperContainer* incompleteBook(NULL);
-      ATH_CHECK(outputMetaStore()->retrieve( incompleteBook, outCollName));
-      // update incomplete output with any incomplete input
-      ATH_CHECK(this->updateContainer(incompleteBook,input_inc));
-      // Find output in MetaCont
-      MetaCont<xAOD::CutBookkeeperContainer>* inc_cont;
-      ATH_CHECK(outputMetaStore()->retrieve(inc_cont,outCollName));
-      // update incomplete output with any incomplete input
-      xAOD::CutBookkeeperContainer* incompleteContBook(NULL);
-      if (inc_cont->find(sid,incompleteContBook)) {
-        ATH_CHECK(this->updateContainer(incompleteContBook,input_inc));
+      if ( !inc->insert(sid,input_inc) ) {
+        ATH_MSG_ERROR("Unable to insert " << inCollName << " for " << sid << " with key " << inc_name);
       }
-      ATH_MSG_DEBUG("Successfully merged input incomplete bookkeepers with output");
     }
   }
   else {
@@ -273,25 +221,13 @@ StatusCode BookkeeperTool::beginInputFile(const SG::SourceID& sid)
   }
 
   // Get the complete bookkeeper collection of the input metadata store
-  const xAOD::CutBookkeeperContainer* input_com = 0;
   inCollName = m_inputCollName;
-  outCollName = m_outputCollName;
+  xAOD::CutBookkeeperContainer* input_com = 0;
   if (inputMetaStore()->contains<xAOD::CutBookkeeperContainer>(inCollName) ) {
     if ( (inputMetaStore()->retrieve( input_com, inCollName )).isSuccess() ) {
-      // Check if a tmp is there. IT SHOULD NOT BE
-      //xAOD::CutBookkeeperContainer* incompleteBook(NULL);
-      if( !(outputMetaStore()->contains<xAOD::CutBookkeeperContainer>(outCollName+"tmp")) ) {
-        // Now create the tmp container
-        xAOD::CutBookkeeperContainer* tmp = new xAOD::CutBookkeeperContainer();
-        xAOD::CutBookkeeperAuxContainer* auxtmp = new xAOD::CutBookkeeperAuxContainer();
-        tmp->setStore(auxtmp);
-        if (updateContainer(tmp,input_com).isSuccess()) {
-          ATH_CHECK(outputMetaStore()->record(tmp,outCollName+"tmp"));
-          ATH_CHECK(outputMetaStore()->record(auxtmp,outCollName+"tmpAux."));
-        }
-        else {
-          ATH_MSG_WARNING("Could not update tmp container from input complete conatiner");
-        }
+      // retrieve the incomplete output container
+      if ( !tmp->insert(sid,input_com) ) {
+        ATH_MSG_ERROR("Unable to insert " << inCollName << " for " << sid << "with key " << tmp_name);
       }
     }
     else {
@@ -325,26 +261,68 @@ StatusCode BookkeeperTool::endInputFile()
 }
 
 
-#ifdef ASGTOOL_ATHENA
-StatusCode BookkeeperTool::endInputFile(const SG::SourceID&)
+//#ifdef ASGTOOL_ATHENA
+StatusCode BookkeeperTool::endInputFile(const SG::SourceID& sid)
 {
+  // Add the sid to the list of complete sids
+  m_completes.insert(sid);
+
   return StatusCode::SUCCESS;
 }
 
-StatusCode BookkeeperTool::metaDataStop(const SG::SourceID& sid)
+StatusCode BookkeeperTool::metaDataStop(const SG::SourceID&)
 {
   //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
-  //  Make sure incomplete container exists in output
-  std::string inc_name = "Incomplete"+m_outputCollName;
-  ATH_MSG_INFO(this->name() << " BLARG Stop 1");
-  if (copyContainerToOutput(sid,inc_name).isFailure()) return StatusCode::FAILURE;
+  // Now retrieve pointers for the MetaConts
+  std::string tmp_name = m_outputCollName+"tmp";
+  std::string inc_name = "Incomplete"+m_outputCollName; 
+  MetaCont<xAOD::CutBookkeeperContainer>* tmp;
+  MetaCont<xAOD::CutBookkeeperContainer>* inc;
+  ATH_CHECK(outputMetaStore()->retrieve(tmp,tmp_name));
+  ATH_CHECK(outputMetaStore()->retrieve(inc,inc_name));
+
+  // Output containers
+  xAOD::CutBookkeeperContainer* outcom = new xAOD::CutBookkeeperContainer();
+  xAOD::CutBookkeeperContainer* outinc = new xAOD::CutBookkeeperContainer();
+  // Incomplete can just be merged
+  auto sids_inc = inc->sources();
+  xAOD::CutBookkeeperContainer* contptr(nullptr);
+  for (auto it = sids_inc.begin(); it != sids_inc.end(); ++it) {
+    if (!inc->find(*it,contptr)) {
+      ATH_MSG_ERROR("Container sid list did not match contents");
+    } else {
+      ATH_CHECK(updateContainer(outinc,contptr));
+    }
+    contptr = nullptr; 
+  }
+  //for (auto it = inc->begin(); it != inc->end(); ++it) {
+  //  ATH_CHECK(updateContainer(outinc,it->second));
+  //}
+  // Loop over containers and mark complete/incomplete based on end files seen
+  auto sids_tmp = tmp->sources();
+  contptr = nullptr;
+  for (auto it = sids_tmp.begin(); it != sids_tmp.end(); ++it) {
+    if (!inc->find(*it,contptr)) {
+      ATH_MSG_ERROR("Container sid list did not match contents");
+    } else {
+      if (std::find(m_completes.begin(), 
+                    m_completes.end(),
+                    *it) == m_completes.end()) {
+        ATH_CHECK(updateContainer(outinc,contptr));
+      } else {
+        ATH_CHECK(updateContainer(outcom,contptr));
+      }
+    }
+  }
+  // Record container objects directly in store for output
+  ATH_CHECK(outputMetaStore()->record(outinc,"Incomplete"+m_outputCollName));
+  ATH_CHECK(outputMetaStore()->record(outcom,m_outputCollName));
 
 
-  ATH_MSG_INFO(this->name() << " BLARG Stop 2");
   if (!m_cutflowTaken) {
     if (addCutFlow().isFailure()) {
       ATH_MSG_ERROR("Could not add CutFlow information");
@@ -353,14 +331,13 @@ StatusCode BookkeeperTool::metaDataStop(const SG::SourceID& sid)
   else {
     ATH_MSG_DEBUG("Cutflow information written into container before metaDataStop");
   }
-  ATH_MSG_INFO(this->name() << " BLARG Stop 3");
 
   // Reset after metadata stop
   m_cutflowTaken = false;
   
   return StatusCode::SUCCESS;
 }
-#endif
+//#endif
 
 StatusCode BookkeeperTool::metaDataStop()
 {
@@ -371,11 +348,9 @@ StatusCode BookkeeperTool::metaDataStop()
   // 3) Write root file if requested
   //  Make sure incomplete container exists in output
   std::string inc_name = "Incomplete"+m_outputCollName;
-  ATH_MSG_INFO(this->name() << " BLARG Stop 1");
   if (copyContainerToOutput(inc_name).isFailure()) return StatusCode::FAILURE;
 
 
-  ATH_MSG_INFO(this->name() << " BLARG Stop 2");
   if (!m_cutflowTaken) {
     if (addCutFlow().isFailure()) {
       ATH_MSG_ERROR("Could not add CutFlow information");
@@ -384,7 +359,6 @@ StatusCode BookkeeperTool::metaDataStop()
   else {
     ATH_MSG_DEBUG("Cutflow information written into container before metaDataStop");
   }
-  ATH_MSG_INFO(this->name() << " BLARG Stop 3");
 
   // Reset after metadata stop
   m_cutflowTaken = false;
@@ -401,8 +375,7 @@ BookkeeperTool::finalize()
 }
 
 
-StatusCode BookkeeperTool::initOutputContainer( const std::string& sgkey, 
-                                                const SG::SourceID& sid )
+StatusCode BookkeeperTool::initOutputContainer( const std::string& sgkey)
 {
   // Now create the primary container
   xAOD::CutBookkeeperContainer* coll = new xAOD::CutBookkeeperContainer();
@@ -410,21 +383,10 @@ StatusCode BookkeeperTool::initOutputContainer( const std::string& sgkey,
   coll->setStore(auxcoll);
   // Put it in a MetaCont
   MetaCont<xAOD::CutBookkeeperContainer>* mcont = new MetaCont<xAOD::CutBookkeeperContainer>(DataObjID("xAOD::CutBookkeeperContainer",sgkey));
-  if(!mcont->insert(sid,coll)) {
-    ATH_MSG_ERROR("Unable to insert primary into MetaCont for " << sgkey);
-    return StatusCode::FAILURE;
-  }
-  ATH_MSG_INFO("Prefind test");
-  bool ss = mcont->valid(sid);
-  ATH_MSG_INFO("Postfind test " << ss);
-  ATH_CHECK(outputMetaStore()->record(std::move(mcont),sgkey));
   // Do the same for the auxiliary container
   std::string auxkey(sgkey+"Aux.");
   MetaCont<xAOD::CutBookkeeperAuxContainer>* acont = new MetaCont<xAOD::CutBookkeeperAuxContainer>(DataObjID("xAOD::CutBookkeeperAuxContainer",auxkey));
-  if(!acont->insert(sid,auxcoll)) {
-    ATH_MSG_ERROR("Unable to insert auxiliary into MetaCont for " << auxkey);
-    return StatusCode::FAILURE;
-  }
+  ATH_CHECK(outputMetaStore()->record(std::move(mcont),sgkey));
   ATH_CHECK(outputMetaStore()->record(std::move(acont),auxkey));
   ATH_CHECK(outputMetaStore()->symLink
           (
@@ -619,12 +581,12 @@ StatusCode BookkeeperTool::copyContainerToOutput(const SG::SourceID& sid,
       return StatusCode::FAILURE;
     }
     if (!contBookCont->find(sid,contBook)) {
-      ATH_MSG_ERROR( "Could not get " << outname << " CutBookkeepers from MetaCont" );
+      ATH_MSG_ERROR( "Could not get " << outname << " CutBookkeepers from MetaCont for sid=" << sid );
       return StatusCode::FAILURE;
     }
   }
   else {
-    xAOD::CutBookkeeperContainer* contBook(nullptr); 
+    //xAOD::CutBookkeeperContainer* contBook(nullptr); 
     if( !(outputMetaStore()->retrieve( contBook, outname) ).isSuccess() ) {
       ATH_MSG_ERROR( "Could not get " << outname << " CutBookkeepers from output MetaDataStore" );
       ATH_MSG_INFO(outputMetaStore()->dump());
-- 
GitLab