From 0245026b2bc113edbf710ef2402f4b6cbed78ad7 Mon Sep 17 00:00:00 2001
From: Marco Clemencic <marco.clemencic@cern.ch>
Date: Thu, 20 Jul 2023 16:58:15 +0200
Subject: [PATCH] Fire ContextIncident 'CONNECTED_NTUPLE_OUTPUT' when opening a
 ntuple file in RFileCnv

---
 RootHistCnv/src/RFileCnv.cpp | 11 ++++++++++-
 RootHistCnv/src/RFileCnv.h   |  6 ++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/RootHistCnv/src/RFileCnv.cpp b/RootHistCnv/src/RFileCnv.cpp
index 489a7cb1d6..3bc81fa779 100644
--- a/RootHistCnv/src/RFileCnv.cpp
+++ b/RootHistCnv/src/RFileCnv.cpp
@@ -10,6 +10,7 @@
 \***********************************************************************************/
 // Include files
 #include "GaudiKernel/Bootstrap.h"
+#include "GaudiKernel/DataIncident.h"
 #include "GaudiKernel/IOpaqueAddress.h"
 #include "GaudiKernel/IRegistry.h"
 #include "GaudiKernel/ISvcLocator.h"
@@ -44,7 +45,14 @@ StatusCode RootHistCnv::RFileCnv::initialize() {
     if ( !sc ) return sc;
   }
   // initialise base class
-  return RDirectoryCnv::initialize();
+  return RDirectoryCnv::initialize().andThen( [&]() {
+    m_incSvc = service( "IncidentSvc" );
+    if ( !m_incSvc ) {
+      MsgStream( msgSvc() ) << MSG::ERROR << "Cannot access IncidentSvc" << endmsg;
+      return StatusCode::FAILURE;
+    }
+    return StatusCode::SUCCESS;
+  } );
 }
 //------------------------------------------------------------------------------
 
@@ -126,6 +134,7 @@ StatusCode RootHistCnv::RFileCnv::createObj( IOpaqueAddress* pAddress, DataObjec
     regTFile( ooname, rfile ).ignore();
 
     log << MSG::DEBUG << "creating ROOT file " << fname << endmsg;
+    m_incSvc->fireIncident( ContextIncident<TFile*>( fname, "CONNECTED_NTUPLE_OUTPUT", rfile ) );
 
     ipar[0]             = (unsigned long)rfile;
     NTuple::File* pFile = new NTuple::File( objType(), fname, oname );
diff --git a/RootHistCnv/src/RFileCnv.h b/RootHistCnv/src/RFileCnv.h
index 6fea5447bf..23305f5fc6 100644
--- a/RootHistCnv/src/RFileCnv.h
+++ b/RootHistCnv/src/RFileCnv.h
@@ -12,6 +12,7 @@
 #define ROOTHISTCNV_RFILECNV_H 1
 
 // Include files
+#include "GaudiKernel/IIncidentSvc.h"
 #include "GaudiKernel/NTuple.h"
 #include "RDirectoryCnv.h"
 
@@ -51,8 +52,9 @@ namespace RootHistCnv {
     RFileCnv( ISvcLocator* svc );
 
   protected:
-    TFile*      rfile{ nullptr }; ///< Pointer to ROOT file
-    std::string m_compLevel;      ///< Compression setting, property RFileCnv.GlobalCompression
+    TFile*                rfile{ nullptr }; ///< Pointer to ROOT file
+    std::string           m_compLevel;      ///< Compression setting, property RFileCnv.GlobalCompression
+    SmartIF<IIncidentSvc> m_incSvc;
   };
 } // namespace RootHistCnv
 #endif // RootHistCnv_RFileCNV_H
-- 
GitLab