Skip to content
Snippets Groups Projects
Commit b240cd62 authored by Scott Snyder's avatar Scott Snyder Committed by scott snyder
Browse files

Add some testing of read/write handle arrays to AthExStoreGateExample.

Add versions of makeHandles methods of arrays that take an EventContext.
parent 7462e01b
1 merge request!20779WIP: Migrate DataQualityTools to ToolHandles
This diff is collapsed.
......@@ -20,8 +20,8 @@ theApp.EvtMax = 3
from AthenaCommon.AlgSequence import AlgSequence
topSeq = AlgSequence()
topSeq += CfgMgr.WriteDataReentrant()
topSeq += CfgMgr.ReadDataReentrant()
topSeq += CfgMgr.WriteDataReentrant(DObjKeyArray = ['x1', 'x2', 'x3'])
topSeq += CfgMgr.ReadDataReentrant(DObjKeyArray = ['x1', 'x2', 'x3'])
# setup output level
from AthenaCommon.AppMgr import ServiceMgr as svcMgr
......
......@@ -48,7 +48,7 @@ ReadDataReentrant::ReadDataReentrant(const std::string& name, ISvcLocator* pSvcL
declareProperty ("PLinkListKey", m_pLinkListKey = std::string("WriteDataReentrant"));
declareProperty ("LinkVectorKey", m_linkVectorKey = std::string("linkvec"));
declareProperty ("TestObjectKey", m_testObjectKey = "testobj");
declareProperty ("DObjKeyArray", m_dobjKeyArray = {"dobj_a1", "dobj_a2"});
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
......@@ -66,6 +66,7 @@ StatusCode ReadDataReentrant::initialize()
ATH_CHECK( m_pLinkListKey.initialize() );
ATH_CHECK( m_linkVectorKey.initialize() );
ATH_CHECK( m_testObjectKey.initialize() );
ATH_CHECK( m_dobjKeyArray.initialize() );
return StatusCode::SUCCESS;
}
......@@ -120,6 +121,13 @@ StatusCode ReadDataReentrant::execute_r (const EventContext& ctx) const
SG::ReadHandle<TestDataObject> testobj (m_testObjectKey, ctx);
if (testobj->val() != 10) std::abort();
// Reading the array of handles.
std::vector<SG::ReadHandle<MyDataObj> > vh = m_dobjKeyArray.makeHandles (ctx);
for (size_t i = 0; i < vh.size(); i++) {
assert (vh[i]->val() == static_cast<int> (100+i));
++i;
}
#if 0
/////////////////////////////////////////////////////////////////////
......
......@@ -42,6 +42,7 @@ private:
SG::ReadHandleKey<std::list<ElementLink<std::vector<float> > > > m_pLinkListKey;
SG::ReadHandleKey<std::vector<ElementLink<MapStringFloat> > > m_linkVectorKey;
SG::ReadHandleKey<TestDataObject> m_testObjectKey;
SG::ReadHandleKeyArray<MyDataObj> m_dobjKeyArray;
};
......
......@@ -49,6 +49,7 @@ WriteDataReentrant::WriteDataReentrant(const std::string& name,
declareProperty ("MKey", m_mKey = "mkey");
declareProperty ("LinkVectorKey", m_linkVectorKey = "linkvec");
declareProperty ("TestObjectKey", m_testObjectKey = "testobj");
declareProperty ("DObjKeyArray", m_dobjKeyArray = {"dobj_a1", "dobj_a2"});
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
......@@ -68,6 +69,7 @@ StatusCode WriteDataReentrant::initialize()
ATH_CHECK( m_mKey.initialize() );
ATH_CHECK( m_linkVectorKey.initialize() );
ATH_CHECK( m_testObjectKey.initialize() );
ATH_CHECK( m_dobjKeyArray.initialize() );
m_testObject =
SG::DataObjectSharedPtr<TestDataObject> (new TestDataObject(10));
......@@ -126,6 +128,14 @@ StatusCode WriteDataReentrant::execute_r (const EventContext& ctx) const
assert (pp == &*dobj4);
}
#endif
// Writing an array of objects.
size_t i = 0;
for (const SG::WriteHandleKey<MyDataObj>& k : m_dobjKeyArray) {
SG::WriteHandle<MyDataObj> h (k, ctx);
ATH_CHECK( h.record (std::make_unique<MyDataObj> (i+100)) );
++i;
}
///////////////////////////////////////////////////////////////////////
......
......@@ -22,6 +22,7 @@
#include "StoreGateExample_ClassDEF.h"
#include "AthenaBaseComps/AthReentrantAlgorithm.h"
#include "StoreGate/WriteHandleKey.h"
#include "StoreGate/WriteHandleKeyArray.h"
class WriteDataReentrant
......@@ -45,6 +46,8 @@ private:
SG::WriteHandleKey<std::vector<ElementLink<MapStringFloat> > > m_linkVectorKey;
SG::WriteHandleKey<TestDataObject> m_testObjectKey;
SG::WriteHandleKeyArray<MyDataObj> m_dobjKeyArray;
SG::DataObjectSharedPtr<TestDataObject> m_testObject;
StatusCode onError() const;
};
......
......@@ -83,6 +83,20 @@ namespace SG {
return ( std::move( hndl ) );
}
/**
* @brief create a vector of ReadHandles from the ReadHandleKeys
* in the array, with explicit EventContext.
*/
std::vector< ReadHandle<T> > makeHandles (const EventContext& ctx) const
{
std::vector< ReadHandle<T> > hndl;
typename std::vector<ReadHandleKey<T>>::const_iterator itr;
for (itr = this->begin(); itr != this->end(); ++itr) {
hndl.push_back ( ReadHandle<T>( *itr, ctx ) );
}
return ( std::move( hndl ) );
}
};
......
......@@ -83,6 +83,20 @@ namespace SG {
return ( std::move( hndl ) );
}
/**
* @brief create a vector of WriteHandles from the WriteHandleKeys
* in the array, with explicit EventContext.
*/
std::vector< WriteHandle<T> > makeHandles (const EventContext& ctx) const
{
std::vector< WriteHandle<T> > hndl;
typename std::vector<WriteHandleKey<T>>::const_iterator itr;
for (itr = this->begin(); itr != this->end(); ++itr) {
hndl.push_back ( WriteHandle<T>( *itr, ctx) );
}
return ( std::move( hndl ) );
}
};
......
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