ATLAS Offline Software
Loading...
Searching...
No Matches
TPIntVectorCnv_p1.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ATHENAPOOLCNVSVC_T_ATHENAPOOLTPVECTORCNV_H
6#define ATHENAPOOLCNVSVC_T_ATHENAPOOLTPVECTORCNV_H
7
8#include "AthenaPoolUtilities/TPIntegerVector.h"
9#include "TPConverter.h"
10
11
12template< class TRANS_BASE, class TRANS >
13class TPAbstractPolyCnvBase < TRANS_BASE, TRANS, TPIntegerVector_p1 > : public ITPConverterFor< TRANS_BASE >
14{
15public:
16 typedef TRANS Trans_t;
18
20
22
23
24 // conversion methods - to be implemented in the concrete converter
25 // -------------------------------------------
26
34 virtual void persToTrans(const PERS* persObj, TRANS* transObj, MsgStream &log) = 0;
35
43 virtual void transToPers(const TRANS* transObj, PERS* persObj, MsgStream &log) = 0;
44
46 virtual void persToTransUntyped(const void* pers, void* trans,MsgStream& log){
47 persToTrans (reinterpret_cast<const PERS*> (pers),
48 reinterpret_cast<TRANS*> (trans),
49 log);
50 }
51
53 virtual void transToPersUntyped(const void* trans, void* pers, MsgStream& log){
54 transToPers (reinterpret_cast<const TRANS*> (trans),
55 reinterpret_cast<PERS*> (pers),
56 log);
57 }
58
59 // Default implementations (usually no need to overwrite)
60 // ------------------------------------------------------
61
68// virtual PERS* createPersistent(const TRANS* transObj, MsgStream &log);
69
77 TPObjRef toPersistent_impl( const TRANS *trans, MsgStream &log );
78
79
81 virtual const std::type_info& transientTInfo() const { return typeid(TRANS); }
82
83//protected:
84 // various virtual "redirector" methods
85
93 virtual void pstoreToTrans( unsigned index, TRANS_BASE *trans, MsgStream &log ) {
94 assert (index < m_pStorage->size());
95 PERS pers = (*m_pStorage)[index];
96 persToTrans( &pers, dynamic_cast<TRANS*>(trans), log );
97 }
98
103 virtual TPObjRef virt_toPersistent( const TRANS_BASE *trans, MsgStream &log ) {
104 return toPersistent_impl( dynamic_cast<const TRANS*>(trans), log);
105 }
106
111 virtual TRANS* virt_createTransFromPStore( unsigned, MsgStream& ) {
112 throw std::runtime_error(
113 std::string("virt_createTransFromPStore() mothod not supported in TP converter for an abstract class: ")
114 + typeid(*this).name() );
115 return 0;
116 }
117
118public:
124 m_pStorage = storage;
125 m_curRecLevel = 0;
126 }
127
129 virtual void reservePStorage( size_t size ) {
130 m_pStorage->reserve( size );
131 }
132
133protected:
136
139
142};
143
144
145
146// --------------------------------------------------------------
147
148// Base converter template for polymorphic types
149
150// Converters for objects in the same inheritance tree must share the same
151// base class type: TRANS_BASE
152
166
167template< class TRANS_BASE, class TRANS >
168class TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 > : public TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >
169{
170public:
172 virtual ~TPPolyCnvBase() {}
173
175
176 // Default implementations (usually no need to overwrite)
177 // ------------------------------------------------------
178
185 virtual TRANS* createTransient(const PERS* persObj, MsgStream &log) {
186 std::unique_ptr<TRANS> trans(new TRANS());
187 persToTrans(persObj, trans.get(), log);
188 return(trans.release());
189 }
190
197 virtual TRANS* virt_createTransFromPStore( unsigned index, MsgStream &log ) {
198 assert (index < this->m_pStorage->size());
199 PERS pers = (*this->m_pStorage)[index];
200 return createTransient( &pers, log );
201 }
202};
203
204
205
211template< class TRANS >
213 : public TPPolyCnvBase< TRANS, TRANS, TPIntegerVector_p1 >
214{
215public:
217 virtual ~TPCnvBase() {}
218
220
221 // implement these methods without dynamic cast to TRANS
222
224 virtual TPObjRef virt_toPersistent( const TRANS *trans, MsgStream &log ) {
225 return toPersistent_impl( trans, log );
226 }
227
229 virtual void pstoreToTrans( unsigned index, TRANS *trans, MsgStream &log ) {
230 assert (index < this->m_pStorage->size());
231 PERS pers = (*this->m_pStorage)[index];
232 persToTrans( &pers, trans, log );
233 }
234
235};
236
237
238
239
240template< class TRANS_BASE, class TRANS >
243toPersistent_impl( const TRANS *trans, MsgStream &log ){
244 // make sure there is a storage object
245// if( !this->topConverter()->hasTLPersObject() ) {
246// this->topConverter()->createTLPersObject();
247// }
248 // make a new space in the storage vector
249 m_pStorage->grow();
250
251 if( m_curRecLevel > 0 ) {
252 throw std::runtime_error(
253 std::string("T/P converter: ") + typeid(*this).name()
254 + " recursive usage not supported! " );
255 }
257 PERS pers = m_pStorage->back();
258 transToPers( trans, &pers, log);
260
261 return TPObjRef( this->m_pStorageTID, m_pStorage->size()-1 );
262}
263
264
265#endif
266
267
268
This file contains template definitions for Transient/Persistent converters.
virtual void transToPersUntyped(const void *trans, void *pers, MsgStream &log)
Convert transient object representation to persistent.
void setPStorage(TPIntegerVectorStorage_p1 *storage)
Tell this converter which storage vector it should use to store or retrieve persistent representation...
virtual void pstoreToTrans(unsigned index, TRANS_BASE *trans, MsgStream &log)
Convert persistent representation stored in the storage vector of the top-level object to transient.
virtual const std::type_info & transientTInfo() const
return C++ type id of the transient class this converter is for
virtual TRANS * virt_createTransFromPStore(unsigned, MsgStream &)
This method implements a pure virtual base class method, but should never be called,...
virtual void persToTrans(const PERS *persObj, TRANS *transObj, MsgStream &log)=0
Convert persistent representation to transient one.
bool m_recursive
if true, work in recursion-safe way (slower)
int m_curRecLevel
count recursive invocations, to detect recursion
TPIntegerVectorStorage_p1 * m_pStorage
the address of the storage vector for persistent representations
virtual void reservePStorage(size_t size)
Reserve 'size' elements for persistent storage - not much sense in this clas.
virtual TPObjRef virt_toPersistent(const TRANS_BASE *trans, MsgStream &log)
Internal interface method that is used to invoke the real conversion method (toPersistent_impl) in th...
TPObjRef toPersistent_impl(const TRANS *trans, MsgStream &log)
Create persistent representation of a transient object.
virtual void persToTransUntyped(const void *pers, void *trans, MsgStream &log)
Convert persistent object representation to transient.
virtual void transToPers(const TRANS *transObj, PERS *persObj, MsgStream &log)=0
Convert transient representation to persistent one.
virtual void persToTrans(const PERS *persObj, TRANS *transObj, MsgStream &log)=0
Convert persistent representation to transient one.
virtual void transToPers(const TRANS *transObj, PERS *persObj, MsgStream &log)=0
Convert transient representation to persistent one.
std::vector< TPIntegerVector_p1 > * m_pStorage
virtual TPObjRef virt_toPersistent(const TRANS *trans, MsgStream &log)
Internal interface method that is used to invoke the real conversion method (toPersistent_impl) in th...
virtual void pstoreToTrans(unsigned index, TRANS *trans, MsgStream &log)
Convert persistent representation stored in the storage vector of the top-level object to transient.
This class is an object reference used in Athena persistent data model.
Definition TPObjRef.h:20
virtual TRANS * createTransient(const PERS *persObj, MsgStream &log)
Create transient representation of a persistent object.
virtual TRANS * virt_createTransFromPStore(unsigned index, MsgStream &log)
Internal interface method that is used to invoke the real conversion method (createTransient)
virtual TRANS * createTransient(const PERS *persObj, MsgStream &log)
Create transient representation of a persistent object.
Definition index.py:1