From fea8979daa92f27675c6f93e21dfc564c8e53c0e Mon Sep 17 00:00:00 2001
From: cranshaw <Jack.Cranshaw@cern.ch>
Date: Mon, 13 Nov 2017 15:24:32 -0600
Subject: [PATCH] Add BookkeeperDumper that dumps the contents of the
 CutBookkeeperContainers to the EventCount options.

Former-commit-id: 21af162ea007be7b163df66970a3e5416a074962
---
 .../AthenaPOOL/AthenaPoolTools/CMakeLists.txt |   1 +
 .../share/EventCount_jobOptions.py            |   3 +
 .../AthenaPoolTools/src/BookkeeperDumper.cxx  | 109 ++++++++++++++++++
 .../AthenaPoolTools/src/BookkeeperDumper.h    |  43 +++++++
 .../components/AthenaPoolTools_entries.cxx    |   2 +
 5 files changed, 158 insertions(+)
 create mode 100755 Database/AthenaPOOL/AthenaPoolTools/src/BookkeeperDumper.cxx
 create mode 100755 Database/AthenaPOOL/AthenaPoolTools/src/BookkeeperDumper.h

diff --git a/Database/AthenaPOOL/AthenaPoolTools/CMakeLists.txt b/Database/AthenaPOOL/AthenaPoolTools/CMakeLists.txt
index 1281d1a5608..1a7ac3f5f2f 100644
--- a/Database/AthenaPOOL/AthenaPoolTools/CMakeLists.txt
+++ b/Database/AthenaPOOL/AthenaPoolTools/CMakeLists.txt
@@ -21,6 +21,7 @@ atlas_depends_on_subdirs( PRIVATE
 atlas_add_component( AthenaPoolTools
                      src/EventCount.cxx
                      src/MetadataTest.cxx
+                     src/BookkeeperDumper.cxx
                      src/RequireUniqueEvent.cxx
                      src/components/*.cxx
                      LINK_LIBRARIES AthenaBaseComps AthenaKernel StoreGateLib SGtests PersistentDataModel EventInfo xAODEventInfo GaudiKernel xAODCutFlow)
diff --git a/Database/AthenaPOOL/AthenaPoolTools/share/EventCount_jobOptions.py b/Database/AthenaPOOL/AthenaPoolTools/share/EventCount_jobOptions.py
index 691abe88929..f9dd47ccb01 100755
--- a/Database/AthenaPOOL/AthenaPoolTools/share/EventCount_jobOptions.py
+++ b/Database/AthenaPOOL/AthenaPoolTools/share/EventCount_jobOptions.py
@@ -21,6 +21,9 @@ alg = xAODMaker__EventInfoCnvAlg()
 alg.xAODKey = ""
 topSequence += alg
 
+#from AthenaPoolTools.AthenaPoolToolsConf import BookkeeperDumper
+#topSequence += BookkeeperDumper( OutputLevel = INFO)
+
 from AthenaPoolTools.AthenaPoolToolsConf import EventCount
 topSequence += EventCount( OutputLevel = INFO,
                            Dump        = True )
diff --git a/Database/AthenaPOOL/AthenaPoolTools/src/BookkeeperDumper.cxx b/Database/AthenaPOOL/AthenaPoolTools/src/BookkeeperDumper.cxx
new file mode 100755
index 00000000000..adc4c7d20e7
--- /dev/null
+++ b/Database/AthenaPOOL/AthenaPoolTools/src/BookkeeperDumper.cxx
@@ -0,0 +1,109 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/**
+ * @file BookkeeperDumper.cxx
+ * @brief Implementation of class BookkeeperDumper
+ */
+ 
+#include "BookkeeperDumper.h"
+
+#include "GaudiKernel/MsgStream.h"
+#include "GaudiKernel/AlgFactory.h"
+
+#include "PersistentDataModel/Token.h"
+#include "PersistentDataModel/DataHeader.h"
+#include "GaudiKernel/IIncidentSvc.h"
+#include "GaudiKernel/FileIncident.h"
+
+#include "StoreGate/StoreGateSvc.h"
+#include "AthenaKernel/IClassIDSvc.h"
+
+#include "xAODCutFlow/CutBookkeeperContainer.h"
+
+
+//___________________________________________________________________________
+BookkeeperDumper::BookkeeperDumper(const std::string& name, ISvcLocator* pSvcLocator) : 
+   AthAlgorithm(name, pSvcLocator) 
+{
+}
+
+BookkeeperDumper::~BookkeeperDumper()
+{}
+
+StatusCode BookkeeperDumper::initialize() 
+{
+   // clear containers
+   ATH_MSG_INFO ( "in initialize()" );
+
+   ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", this->name());
+   ATH_CHECK( incSvc.retrieve() );
+   incSvc->addListener(this, "BeginInputFile", 100); 
+
+   return StatusCode::SUCCESS;
+}
+
+void BookkeeperDumper::handle(const Incident& inc)
+{
+  
+  ATH_MSG_INFO("handle() " << inc.type());
+
+  // Need to get input file name for event comparison
+  if (inc.type()=="BeginInputFile") {
+    //const FileIncident* fileInc  = dynamic_cast<const FileIncident*>(&inc);
+    ServiceHandle<StoreGateSvc> mdstore("StoreGateSvc/InputMetaDataStore", name());
+    if (mdstore.retrieve().isSuccess()) {
+      const DataHandle<xAOD::CutBookkeeperContainer> compBook(NULL);
+      if (mdstore->retrieve(compBook, "CutBookkeepers").isSuccess()) {
+        ATH_MSG_INFO("CBK size = " << compBook->size());
+        for (auto it = compBook->begin(); it != compBook->end(); ++it) {
+          ATH_MSG_INFO("CBK name= " << (*it)->name() << " stream=" << (*it)->inputStream() << " N=" << (*it)->nAcceptedEvents() << " W=" << (*it)->sumOfEventWeights());
+        }
+      } else {
+        ATH_MSG_INFO("CBK No CutBookkeepers " << mdstore->dump());
+      }
+      const DataHandle<xAOD::CutBookkeeperContainer> fileBook(NULL);
+      if (mdstore->retrieve(fileBook, "FileBookkeepers").isSuccess()) {
+        ATH_MSG_INFO("FBK size = " << fileBook->size());
+        for (auto it = fileBook->begin(); it != fileBook->end(); ++it) {
+          ATH_MSG_INFO("FBK name= " << (*it)->name() << " stream=" << (*it)->inputStream() << " N=" << (*it)->nAcceptedEvents() << " W=" << (*it)->sumOfEventWeights());
+        }
+      } else {
+        ATH_MSG_INFO("FBK No FileBookkeepers " << mdstore->dump());
+      }
+      const DataHandle<xAOD::CutBookkeeperContainer> incompBook(NULL);
+      if (mdstore->retrieve(incompBook, "IncompleteCutBookkeepers").isSuccess()) {
+        ATH_MSG_INFO("ICBK size = " << incompBook->size());
+        for (auto it = incompBook->begin(); it != incompBook->end(); ++it) {
+          ATH_MSG_INFO("ICBK name= " << (*it)->name() << " stream=" << (*it)->inputStream() << " N=" << (*it)->nAcceptedEvents() << " W=" << (*it)->sumOfEventWeights());
+        }
+      } else {
+        ATH_MSG_INFO("ICBK No CutBookkeepers " << mdstore->dump());
+      }
+      const DataHandle<xAOD::CutBookkeeperContainer> infileBook(NULL);
+      if (mdstore->retrieve(infileBook, "IncompleteFileBookkeepers").isSuccess()) {
+        ATH_MSG_INFO("IFBK size = " << infileBook->size());
+        for (auto it = infileBook->begin(); it != infileBook->end(); ++it) {
+          ATH_MSG_INFO("IFBK name= " << (*it)->name() << " stream=" << (*it)->inputStream() << " N=" << (*it)->nAcceptedEvents() << " W=" << (*it)->sumOfEventWeights());
+        }
+      } else {
+        ATH_MSG_INFO("IFBK No FileBookkeepers " << mdstore->dump());
+      }
+    }
+  }
+}
+
+StatusCode BookkeeperDumper::execute() 
+{
+   ATH_MSG_DEBUG ( "in execute()" );
+
+   return(StatusCode::SUCCESS);
+}
+
+StatusCode BookkeeperDumper::finalize() 
+{
+   ATH_MSG_DEBUG ( "in m_finalize()" );
+   
+   return(StatusCode::SUCCESS);
+}
diff --git a/Database/AthenaPOOL/AthenaPoolTools/src/BookkeeperDumper.h b/Database/AthenaPOOL/AthenaPoolTools/src/BookkeeperDumper.h
new file mode 100755
index 00000000000..bb17cdeac22
--- /dev/null
+++ b/Database/AthenaPOOL/AthenaPoolTools/src/BookkeeperDumper.h
@@ -0,0 +1,43 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+// BookkeeperDumper.h
+
+#ifndef ATHENAPOOLTOOLS_BOOKKEEPERDUMPER_H
+#define ATHENAPOOLTOOLS_BOOKKEEPERDUMPER_H
+/**
+ * @file BookkeeperDumper.h
+ * @brief class definition for BookkeeperDumper
+ */
+ 
+/**
+ * @class BookkeeperDumper
+ * @author Jack Cranshaw (Jack.Cranshaw@cern.ch)
+ * Created October 2017
+ */
+             
+                                                                                
+#include <string>
+#include <vector>
+#include "AthenaBaseComps/AthAlgorithm.h"
+#include "GaudiKernel/ServiceHandle.h"
+#include "GaudiKernel/IIncidentListener.h"
+
+class IClassIDSvc;
+
+class BookkeeperDumper : public AthAlgorithm, virtual public IIncidentListener {
+public:
+	  
+  BookkeeperDumper(const std::string& name, ISvcLocator* pSvcLocator);
+  virtual ~BookkeeperDumper();
+  
+  StatusCode initialize(); /// Algorithm interface. Cannot re-initialize with this
+  StatusCode execute();    /// Algorithm interface.
+  StatusCode finalize();   /// Algorithm interface.
+
+  void handle(const Incident& inc);
+  
+private:
+};
+#endif
diff --git a/Database/AthenaPOOL/AthenaPoolTools/src/components/AthenaPoolTools_entries.cxx b/Database/AthenaPOOL/AthenaPoolTools/src/components/AthenaPoolTools_entries.cxx
index 7d52ed1c536..e2f9bc79794 100644
--- a/Database/AthenaPOOL/AthenaPoolTools/src/components/AthenaPoolTools_entries.cxx
+++ b/Database/AthenaPOOL/AthenaPoolTools/src/components/AthenaPoolTools_entries.cxx
@@ -1,8 +1,10 @@
 #include "../EventCount.h"
 #include "../MetadataTest.h"
+#include "../BookkeeperDumper.h"
 #include "../RequireUniqueEvent.h"
 
 DECLARE_COMPONENT( EventCount )
 DECLARE_COMPONENT( MetadataTest )
+DECLARE_COMPONENT( BookkeeperDumper )
 DECLARE_COMPONENT( RequireUniqueEvent )
 
-- 
GitLab