Skip to content
Snippets Groups Projects

Modernize AddressKillerAlg

Merged Gerhard Raven requested to merge modernize-addresskiller into master
@@ -15,14 +15,11 @@
// Author : Markus Frank
//
// ====================================================================
#include "GaudiKernel/Algorithm.h"
#include "Gaudi/Algorithm.h"
#include "GaudiKernel/IDataManagerSvc.h"
#include "GaudiKernel/IDataProviderSvc.h"
#include "GaudiKernel/IOpaqueAddress.h"
#include "GaudiKernel/IRegistry.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/SmartDataPtr.h"
#include "GaudiKernel/SmartIF.h"
/**@class AddressKillerAlg
*
@@ -32,76 +29,35 @@
* @author: M.Frank
* @version: 1.0
*/
class AddressKillerAlg : public Algorithm {
class AddressKillerAlg : public Gaudi::Algorithm {
private:
/// Reference to data provider service
IDataProviderSvc* m_dataSvc = nullptr;
/// Name of the data provider service
Gaudi::Property<std::string> m_dataSvcName{this, "DataSvc", "EventDataSvc"};
/// Name of the root leaf (obtained at initialize)
std::string m_rootName;
ServiceHandle<IDataProviderSvc> m_dataSvc{this, "DataSvc", "EventDataSvc"};
public:
/// Standard algorithm constructor
AddressKillerAlg( const std::string& name, ISvcLocator* pSvcLocator ) : Algorithm( name, pSvcLocator ) {}
using Algorithm::Algorithm;
/// Initialize
StatusCode initialize() override {
m_rootName.clear();
return Algorithm::initialize()
.andThen( [&] {
return service( m_dataSvcName, m_dataSvc, true ).orElse( [&] {
error() << "Failed to access service " << std::quoted( m_dataSvcName.value() ) << '.' << endmsg;
} );
} )
.andThen( [&]() -> StatusCode {
SmartIF<IDataManagerSvc> mgr( m_dataSvc );
if ( !mgr ) {
error() << "Failed to retrieve IDataManagerSvc interface." << endmsg;
return StatusCode::FAILURE;
}
m_rootName = mgr->rootName();
return StatusCode::SUCCESS;
} );
return Algorithm::initialize().andThen( [&] { return m_dataSvc.retrieve(); } );
}
/// Finalize
StatusCode finalize() override {
if ( m_dataSvc ) m_dataSvc->release();
m_dataSvc = nullptr;
return Algorithm::finalize();
return m_dataSvc.release().andThen( [&] { return Algorithm::finalize(); } );
}
/// Execute procedure
StatusCode execute() override {
SmartDataPtr<DataObject> root( m_dataSvc, m_rootName );
if ( !root ) return StatusCode::FAILURE;
explore( root->registry() );
return StatusCode::SUCCESS;
}
private:
void explore( IRegistry* pObj, const unsigned int depth = 0 ) {
if ( depth > 9999999 ) return; // infinite recursion protection..
SmartIF<IDataManagerSvc> mgr( m_dataSvc );
if ( mgr && pObj ) {
std::vector<IRegistry*> leaves;
const IOpaqueAddress* addr = pObj->address();
if ( addr ) {
StatusCode execute( const EventContext& ) const override {
SmartIF<IDataManagerSvc> mgr( m_dataSvc.get() );
return mgr->traverseTree( [&, id = mgr->rootName()]( IRegistry* reg, int depth ) {
if ( const IOpaqueAddress* addr = reg->address(); addr ) {
// NOT for MDF top level address!!!!
if ( !( addr->svcType() == RAWDATA_StorageType && pObj->identifier() == m_rootName ) ) {
MsgStream log( msgSvc(), name() );
log << MSG::DEBUG << "Remove store address \"" << pObj->identifier() << "\"." << endmsg;
pObj->setAddress( 0 );
if ( !( addr->svcType() == RAWDATA_StorageType && reg->identifier() == id ) ) {
debug() << "Remove store address \"" << reg->identifier() << "\"." << endmsg;
reg->setAddress( nullptr );
}
}
const StatusCode sc = mgr->objectLeaves( pObj, leaves );
if ( sc.isSuccess() ) {
for ( IRegistry* leaf : leaves ) { explore( leaf, depth + 1 ); }
}
}
return depth < 9999999; // infinite recursion protection..
} );
}
};
Loading