Skip to content
Snippets Groups Projects
Commit ff6f4516 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'add-test-void-record' into 'master'

DataBucket implementation suitable for inserting void* into the store

See merge request atlas/athena!15743
parents d4fc4b72 b19fcb02
No related branches found
No related tags found
No related merge requests found
......@@ -37,3 +37,12 @@ atlas_add_library( TrigOutputHandlingLib
atlas_add_component( TrigOutputHandling
src/components/*.cxx
LINK_LIBRARIES TrigOutputHandlingLib )
atlas_add_test( void_record_test
SOURCES test/void_record_test.cxx
INCLUDE_DIRS ${Boost_INCLUDE_DIRS}
LINK_LIBRARIES ${Boost_LIBRARIES} xAODTrigger
AthLinks AthenaKernel StoreGateLib GaudiKernel TestTools xAODCore
ENVIRONMENT "JOBOPTSEARCHPATH=${CMAKE_CURRENT_SOURCE_DIR}/share"
POST_EXEC_SCRIPT nopost.sh
)
StoreGateSvc.OutputLevel=0;
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TrigOutputHandling_BareDataBucket_h
#define TrigOutputHandling_BareDataBucket_h
#include "AthenaKernel/DataBucketBase.h"
#include "DataModelRoot/RootType.h"
/**
* @class Allows to insert void* returned from serialisation into the store
**/
class BareDataBucket: public DataBucketBase {
public:
BareDataBucket() = delete;
BareDataBucket( void * data, size_t sz, CLID clid, const RootType& type )
: m_data(data), m_size(sz), m_clid(clid), m_type( type ){}
virtual ~BareDataBucket() {
if ( m_own )
m_type.Destruct( m_data );
}
// DataObject overrides
virtual const CLID& clID() const override {
return m_clid;
}
// DataBuckedBase overrides
virtual void* object() override {
return m_data;
}
virtual const std::type_info& tinfo() const override {
return m_type.TypeInfo();
};
virtual void* cast (CLID clid,
SG::IRegisterTransient* ,
bool isConst = true) override {
return ( m_clid == clid and isConst ) ? m_data : nullptr;
}
virtual void* cast (const std::type_info& tinfo,
SG::IRegisterTransient* ,
bool isConst = true) override {
return ( tinfo == m_type.TypeInfo() and isConst ) ? m_data : nullptr;
}
virtual DataBucketBase* clone() const override {
return nullptr;
}
virtual void relinquish() override {
m_own = false;
};
virtual void lock() override { /*not lockable I think */ };
private:
void* m_data = 0;
size_t m_size = 0;
CLID m_clid = 0;
RootType m_type;
bool m_own = false;
};
#endif
#include <iostream>
#include "TestTools/expect.h"
#include "TestTools/initGaudi.h"
#include "AthenaKernel/getMessageSvc.h"
#include "GaudiKernel/MsgStream.h"
#include "StoreGate/StoreGate.h"
#include "StoreGate/StoreGateSvc.h"
#include "../src/BareDataBucket.h"
#include "xAODTrigger/TrigCompositeContainer.h"
#include "xAODTrigger/TrigCompositeAuxContainer.h"
int main() {
using namespace std;
ISvcLocator* pSvcLoc;
if (!Athena_test::initGaudi("test.txt", pSvcLoc)) {
cerr << "ERROR This test can not be run" << endl;
return 0;
}
assert(pSvcLoc);
MsgStream log(Athena::getMessageSvc(), "void_record_test");
StoreGateSvc* pStore = 0;
if( pSvcLoc->service("StoreGateSvc", pStore, true).isSuccess() ) {
log << MSG::INFO << "SG pointer: " << pStore << endmsg;
} else {
log << MSG::ERROR << "can't obtain SG ptr" << endmsg;
return -1;
}
xAOD::TrigCompositeContainer* testContainer = new xAOD::TrigCompositeContainer();
xAOD::TrigCompositeAuxContainer* aux = new xAOD::TrigCompositeAuxContainer();
testContainer->setStore( aux );
testContainer->push_back( new xAOD::TrigComposite() );
testContainer->push_back( new xAOD::TrigComposite() );
testContainer->at(0)->setDetail( "idetail", 7 );
testContainer->at(1)->setDetail( "fdetail", 2.5f );
void * rawContainerPtr = static_cast<void*>( testContainer );
void * rawStorePtr = static_cast<void*>( aux );
SG::BaseInfo<xAOD::TrigCompositeContainer>::baseinfo(); // this is problematic because client code does not know about templates, will have to see in athena if the problem persists
RootType contaierRT = RootType::ByName( "xAOD::TrigCompositeContainer_v1" );
log << MSG::INFO << contaierRT.Name() << endmsg;
BareDataBucket containerDataBucket( rawContainerPtr, 1, ClassID_traits<xAOD::TrigCompositeContainer>::ID(), contaierRT ); // size (second arg == 1) is ficticious in this test
RootType storeRT = RootType::ByName( "xAOD::TrigCompositeAuxContainer_v1" );
log << MSG::INFO << storeRT.Name() << endmsg;
BareDataBucket storeDataBucket( rawStorePtr, 1, ClassID_traits<xAOD::TrigCompositeAuxContainer>::ID(), storeRT );
pStore->recordObject( SG::DataObjectSharedPtr<BareDataBucket>( &containerDataBucket ), "test", false, false );
pStore->recordObject( SG::DataObjectSharedPtr<BareDataBucket>( &storeDataBucket ), "testAux.", false, false );
log << MSG::INFO << "recordObject done" << endmsg;
VALUE( pStore->accessData( ClassID_traits<xAOD::TrigCompositeContainer>::ID(), "test" ) ) NOT_EXPECTED ( nullptr );
VALUE( pStore->accessData( ClassID_traits<xAOD::TrigCompositeAuxContainer>::ID(), "testAux." ) ) NOT_EXPECTED ( nullptr );
log << MSG::INFO << "objects in store, trying to read them back via rertieve" << endmsg;
const xAOD::TrigCompositeContainer* containerBack = 0;
pStore->retrieve( containerBack, "test" );
VALUE ( containerBack ) NOT_EXPECTED ( nullptr );
VALUE( containerBack->size() ) EXPECTED ( 2 );
VALUE( containerBack->at(0)->getDetail<int32_t>( "idetail" ) ) EXPECTED ( 7 );
VALUE( containerBack->at(1)->getDetail<float>( "fdetail" ) ) EXPECTED ( 2.5f );
log << MSG::INFO << "Container red back is identical" << endmsg;
return 0;
}
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