Skip to content
Snippets Groups Projects
Commit 1fe06401 authored by Markus Frank's avatar Markus Frank
Browse files

Fix extensions in Geant4Event and Geant4Run using common destructor in ObjectExtensions

parent 031911ed
No related branches found
No related tags found
No related merge requests found
......@@ -154,8 +154,8 @@ namespace DD4hep {
}
/// Access extension element by the type
template <class T> T* extension() const {
return (T*) i_extension(typeid(T));
template <typename IFACE> IFACE* extension() const {
return (IFACE*) i_extension(typeid(IFACE));
}
};
......@@ -302,12 +302,10 @@ namespace DD4hep {
CallbackSequence::checkTypes(typeid(IFACE), typeid(CONCRETE), dynamic_cast<IFACE*>(c));
return (IFACE*) i_addExtension(dynamic_cast<IFACE*>(c), typeid(IFACE), _copy<CONCRETE>, _delete<IFACE>);
}
/// Access extension element by the type
template <class T> T* extension() const {
return (T*) i_extension(typeid(T));
template <typename IFACE> IFACE* extension() const {
return (IFACE*) i_extension(typeid(IFACE));
}
/// Extend the detector element with an arbitrary callback
template <typename Q, typename T>
void callAtUpdate(unsigned int type, Q* pointer,
......
......@@ -49,7 +49,11 @@ namespace DD4hep {
/// Function to be passed as dtor if object should NOT be deleted!
static void _noDelete(void*) {}
/// If the object SHOULD be deleted, use DD4hep::deletePtr<TYPE>!
/// Templated destructor function
template <typename T> static void _delete(void* ptr) {
delete (T*) (ptr);
}
public:
/// Default constructor
......
......@@ -70,6 +70,8 @@ namespace DD4hep {
class Geant4Run : public ObjectExtensions {
/// Reference to the original Geant4 run object
const G4Run* m_run;
protected:
public:
/// Intializing constructor
Geant4Run(const G4Run* run);
......@@ -87,8 +89,8 @@ namespace DD4hep {
return ObjectExtensions::addExtension(ptr,info,dtor);
}
/// Add user extension object. Ownership is transferred!
template <typename T> T* addExtension(T* ptr) {
return (T*)ObjectExtensions::addExtension(ptr,typeid(T),deletePtr<T>);
template <typename T> T* addExtension(T* ptr, bool take_ownership=true) {
return (T*)ObjectExtensions::addExtension(ptr,typeid(T),take_ownership ? _delete<T> : 0);
}
/// Access to type safe extension object. Exception is thrown if the object is invalid
template <typename T> T* extension(bool alert=true) {
......@@ -132,8 +134,8 @@ namespace DD4hep {
return ObjectExtensions::addExtension(ptr,info,dtor);
}
/// Add user extension object. Ownership is transferred and object deleted at the end of the event.
template <typename T> T* addExtension(T* ptr) {
return (T*)ObjectExtensions::addExtension(ptr,typeid(T),deletePtr<T>);
template <typename T> T* addExtension(T* ptr, bool take_ownership=true) {
return (T*)ObjectExtensions::addExtension(ptr,typeid(T),take_ownership ? _delete<T> : 0);
}
/// Access to type safe extension object. Exception is thrown if the object is invalid
template <typename T> T* extension(bool alert=true) {
......
......@@ -82,6 +82,7 @@ namespace DD4hep {
#include "DD4hep/InstanceCount.h"
#include "DDG4/Geant4HitCollection.h"
#include "DDG4/Geant4DataConversion.h"
#include "DDG4/Geant4Context.h"
//#include "DDG4/Geant4Output2LCIO.h"
#include "G4Event.hh"
......@@ -158,7 +159,8 @@ void Geant4Output2LCIO::begin(const G4Event* event){
//fg: fixme: should be this call (deleting the pointer in the end) but that does not compile ...
// context()->event().addExtension<lcio::LCEventImpl>( e );
context()->event().addExtension( e , typeid( lcio::LCEventImpl ), 0);
context()->event().addExtension<lcio::LCEventImpl>( e );
//context()->event().addExtension( e , typeid( lcio::LCEventImpl ), 0);
// std::cout << " ########### Geant4Output2LCIO::begin add new LCIO event event context " << std::endl ;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment