diff --git a/DDCore/include/DD4hep/OpaqueData.h b/DDCore/include/DD4hep/OpaqueData.h index 1f8b89121e7a24447d894c3a4bc6338413ac41d0..dfcede3c52f59192750ac2907f6ba62387ae6d0b 100644 --- a/DDCore/include/DD4hep/OpaqueData.h +++ b/DDCore/include/DD4hep/OpaqueData.h @@ -90,15 +90,9 @@ namespace dd4hep { BOUND_DATA = 1<<3 }; - - /// Data buffer: plain data are allocated directly on this buffer /** Internal data buffer is sufficient to store any vector */ unsigned char data[sizeof(std::vector<void*>)]; - /// Destructor function -- only set if the object is valid - //void (*destruct)(void*); - /// Constructor function -- only set if the object is valid - //void (*copy)(void*,const void*); public: /// Data buffer type: Must be a bitmap! @@ -114,14 +108,9 @@ namespace dd4hep { /// Move the data content: 'from' will be reset to NULL bool move(OpaqueDataBlock& from); /// Bind data value - bool bind(const BasicGrammar* grammar, - void (*ctor)(void*,const void*), - void (*dtor)(void*)); + bool bind(const BasicGrammar* grammar); /// Bind data value in place - bool bind(void* ptr, size_t len, - const BasicGrammar* grammar, - void (*ctor)(void*,const void*), - void (*dtor)(void*)); + bool bind(void* ptr, size_t len, const BasicGrammar* grammar); /// Bind data value template <typename T> T& bind(); /// Bind data value diff --git a/DDCore/include/DD4hep/detail/BasicGrammar_inl.h b/DDCore/include/DD4hep/detail/BasicGrammar_inl.h index 4046b8edaafbc15afc05c058a4a2d965097dcafa..d3c10f91df48ad6d37aaf5656a3f79fa164fdaee 100644 --- a/DDCore/include/DD4hep/detail/BasicGrammar_inl.h +++ b/DDCore/include/DD4hep/detail/BasicGrammar_inl.h @@ -66,6 +66,8 @@ namespace dd4hep { Grammar(); /// Default destructor virtual ~Grammar(); + + /** Base class overrides */ /// PropertyGrammar overload: Access to the type information virtual const std::type_info& type() const override; /// Access to the type information name @@ -76,12 +78,14 @@ namespace dd4hep { virtual std::string str(const void* ptr) const override; /// PropertyGrammar overload: Retrieve value from string virtual bool fromString(void* ptr, const std::string& value) const override; - /// Evaluate string value if possible before calling boost::spirit - virtual int evaluate(void* ptr, const std::string& value) const; /// Opaque object destructor - virtual void destruct(void* pointer) const; + virtual void destruct(void* pointer) const override; /// Opaque object copy construction. Memory must be allocated externally - virtual void copy(void* to, const void* from) const; + virtual void copy(void* to, const void* from) const override; + + /** Class member function */ + /// Evaluate string value if possible before calling boost::spirit + virtual int evaluate(void* ptr, const std::string& value) const; }; /// Standarsd constructor diff --git a/DDCore/include/DD4hep/detail/OpaqueData_inl.h b/DDCore/include/DD4hep/detail/OpaqueData_inl.h index 79bffd96d267fbbb912f942731073abced80d3e9..c63b4f3e7d1f1aae1816768295f0c7cc11fc1490 100644 --- a/DDCore/include/DD4hep/detail/OpaqueData_inl.h +++ b/DDCore/include/DD4hep/detail/OpaqueData_inl.h @@ -29,16 +29,6 @@ /// Namespace for the AIDA detector description toolkit namespace dd4hep { - namespace { - template <typename T> static void opaqueCopyObject(void* t, const void* s) { - new(t) T(*(const T*)s); - } - template <typename T> static void opaqueDestructObject(void* p) { - T* t = (T*)p; - t->~T(); - } - } - /// Generic getter. Specify the exact type, not a polymorph type template <typename T> T& OpaqueData::get() { if (!grammar || (grammar->type() != typeid(T))) { throw std::bad_cast(); } @@ -53,13 +43,13 @@ namespace dd4hep { /// Bind data value template <typename T> T& OpaqueDataBlock::bind() { - this->bind(&BasicGrammar::instance<T>(),opaqueCopyObject<T>,opaqueDestructObject<T>); + this->bind(&BasicGrammar::instance<T>()); return *(new(this->pointer) T()); } /// Bind data value template <typename T> T& OpaqueDataBlock::bind(void* ptr, size_t len) { - this->bind(ptr,len,&BasicGrammar::instance<T>(),opaqueCopyObject<T>,opaqueDestructObject<T>); + this->bind(ptr,len,&BasicGrammar::instance<T>()); return *(new(this->pointer) T()); } diff --git a/DDCore/src/OpaqueData.cpp b/DDCore/src/OpaqueData.cpp index 5057469da262e316c7e78bdaf7e582477131b218..ad93d449b148bb89b5e34e5186f9c27c68883ac5 100644 --- a/DDCore/src/OpaqueData.cpp +++ b/DDCore/src/OpaqueData.cpp @@ -63,21 +63,20 @@ OpaqueDataBlock::OpaqueDataBlock() : OpaqueData(), /*destruct(0), copy(0),*/ typ /// Copy constructor OpaqueDataBlock::OpaqueDataBlock(const OpaqueDataBlock& c) - : OpaqueData(c), /*destruct(c.destruct), copy(c.copy), */type(c.type) { + : OpaqueData(c), type(c.type) { grammar = 0; pointer = 0; - this->bind(c.grammar,0,0/*c.copy,c.destruct*/); + this->bind(c.grammar); this->grammar->copy(pointer,c.pointer); InstanceCount::increment(this); } /// Standard Destructor OpaqueDataBlock::~OpaqueDataBlock() { - //if ( destruct ) { - //(*destruct)(pointer); - grammar->destruct(pointer); + if ( pointer ) { + grammar->destruct(pointer); if ( (type&ALLOC_DATA) == ALLOC_DATA ) ::operator delete(pointer); - //} + } pointer = 0; grammar = 0; InstanceCount::decrement(this); @@ -88,13 +87,9 @@ bool OpaqueDataBlock::move(OpaqueDataBlock& from) { pointer = from.pointer; grammar = from.grammar; ::memcpy(data,from.data,sizeof(data)); - //destruct = from.destruct; - //copy = from.copy; type = from.type; ::memset(from.data,0,sizeof(data)); from.type = PLAIN_DATA; - //from.destruct = 0; - //from.copy = 0; from.pointer = 0; from.grammar = 0; return true; @@ -104,21 +99,18 @@ bool OpaqueDataBlock::move(OpaqueDataBlock& from) { OpaqueDataBlock& OpaqueDataBlock::operator=(const OpaqueDataBlock& c) { if ( this != &c ) { if ( this->grammar == c.grammar ) { - //if ( destruct ) { - //(*destruct)(pointer); - grammar->destruct(pointer); + if ( pointer ) { + grammar->destruct(pointer); if ( (type&ALLOC_DATA) == ALLOC_DATA ) ::operator delete(pointer); } pointer = 0; grammar = 0; - //} + } if ( this->grammar == 0 ) { this->OpaqueData::operator=(c); - //this->destruct = c.destruct; - //this->copy = c.copy; this->type = c.type; this->grammar = 0; - this->bind(c.grammar,0,0/*c.copy,c.destruct*/); + this->bind(c.grammar); this->grammar->copy(pointer,c.pointer); return *this; } @@ -128,12 +120,10 @@ OpaqueDataBlock& OpaqueDataBlock::operator=(const OpaqueDataBlock& c) { } /// Set data value -bool OpaqueDataBlock::bind(const BasicGrammar* g, void (*ctor)(void*,const void*), void (*dtor)(void*)) { +bool OpaqueDataBlock::bind(const BasicGrammar* g) { if ( !grammar ) { size_t len = g->sizeOf(); grammar = g; - //destruct = dtor; - //copy = ctor; (len > sizeof(data)) ? (pointer=::operator new(len),type=ALLOC_DATA) : (pointer=data,type=PLAIN_DATA); @@ -149,12 +139,10 @@ bool OpaqueDataBlock::bind(const BasicGrammar* g, void (*ctor)(void*,const void* } /// Set data value -bool OpaqueDataBlock::bind(void* ptr, size_t size, const BasicGrammar* g, void (*ctor)(void*,const void*), void (*dtor)(void*)) { +bool OpaqueDataBlock::bind(void* ptr, size_t size, const BasicGrammar* g) { if ( !grammar ) { size_t len = g->sizeOf(); - grammar = g; - //destruct = dtor; - //copy = ctor; + grammar = g; if ( len <= size ) pointer=ptr, type=STACK_DATA; else if ( len <= sizeof(data) ) diff --git a/DDCore/src/plugins/VolumeMgrTest.cpp b/DDCore/src/plugins/VolumeMgrTest.cpp index 8e01c1e65c73c740e0fda90198359bafdf29f189..66ea311afada72241c9d9dffab5539f50d3a74b0 100644 --- a/DDCore/src/plugins/VolumeMgrTest.cpp +++ b/DDCore/src/plugins/VolumeMgrTest.cpp @@ -213,10 +213,21 @@ void VolIDTest::checkVolume(DetElement detector, PlacedVolume pv, const VolIDs& ::printf("VolumeMgr Trafo: %s [%s]\t\t",det_elem.path().c_str(),volumeID(vid).c_str()); m_mgr.worldTransformation(m_mapping,vid).Print(); } + + /// Check volume manager context if ( 0 == mgr_ctxt ) { printout(ERROR,m_det.name(),"VOLUME_MANAGER FAILED: Could not find entry for vid:%s.", volumeID(vid).c_str()); + ++m_errors; } + + /// Check nominal and DetElement trafos for pointer equality: + if ( &det_elem.nominal().worldTransformation() != &m_mgr.worldTransformation(m_mapping,det_elem.volumeID()) ) + { + printout(ERROR,m_det.name(),"DETELEMENT_PERSISTENCY FAILED: World transformation have DIFFERET pointer!"); + ++m_errors; + } + if ( pv.ptr() == det_elem.placement().ptr() ) { // The computed transformation 'trafo' MUST be equal to: // m_mgr.worldTransformation(vid) AND det_elem.nominal().worldTransformation()