ATLAS Offline Software
Loading...
Searching...
No Matches
TPIntVectorCnv_p2.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 T_ATHENAPOOLTPINTVECTORCNV_H
6#define T_ATHENAPOOLTPINTVECTORCNV_H
7
13
14#include "TPConverter.h"
16
17#include <stdexcept>
18
19
20template< class TRANS_BASE, class TRANS >
21class TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >
22 : public ITPConverterFor< TRANS_BASE >
23{
24public:
25 typedef TRANS Trans_t;
27
30
32
33
34 // conversion methods - to be implemented in the concrete converter
35 // -------------------------------------------
36
44 virtual void persToTrans(const Pers_t* persObj, TRANS* transObj, MsgStream &log) = 0;
45
53 virtual void transToPers(const TRANS* transObj, Pers_t* persObj, MsgStream &log) = 0;
54
56 virtual void persToTransUntyped(const void* pers,
57 void* trans,
58 MsgStream& log)
59 {
60 persToTrans (reinterpret_cast<const Pers_t*> (pers),
61 reinterpret_cast<TRANS*> (trans),
62 log);
63 }
64
66 virtual void transToPersUntyped(const void* trans,
67 void* pers,
68 MsgStream& log)
69 {
70 transToPers (reinterpret_cast<const TRANS*> (trans),
71 reinterpret_cast<Pers_t*> (pers),
72 log);
73 }
74
75 // Default implementations (usually no need to overwrite)
76 // ------------------------------------------------------
77
85 TPObjRef toPersistent_impl( const TRANS *trans, MsgStream &log );
86
87
89 virtual const std::type_info& transientTInfo() const { return typeid(TRANS); }
90
91//protected:
92 // various virtual "redirector" methods
93
101 virtual void pstoreToTrans( unsigned index, TRANS_BASE *trans, MsgStream &log ) {
102 assert (index < m_pStorage->size());
103 Pers_t pers = (*m_pStorage)[index];
104 persToTrans( &pers, dynamic_cast<TRANS*>(trans), log );
105 }
106
111 virtual TPObjRef virt_toPersistent( const TRANS_BASE *trans, MsgStream &log ) {
112 return toPersistent_impl( dynamic_cast<const TRANS*>(trans), log);
113 }
114
119 virtual TRANS* virt_createTransFromPStore( unsigned, MsgStream& ) {
120 throw std::runtime_error(
121 std::string("virt_createTransFromPStore() mothod not supported in TP converter for an abstract class: ")
122 + typeid(*this).name() );
123 return 0;
124 }
125
126public:
132 m_pStorage = storage;
133 }
134
136 virtual void reservePStorage( size_t size ) {
137 m_pStorage->reserve( size );
138 }
139
140protected:
143};
144
145
146
147// --------------------------------------------------------------
148
149// Base converter template for polymorphic types
150
151// Converters for objects in the same inheritance tree must share the same
152// base class type: TRANS_BASE
153
167
168template< class TRANS_BASE, class TRANS >
169class TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >
170 : public TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >
171{
172public:
174 virtual ~TPPolyCnvBase() {}
175
177
178 // Default implementations (usually no need to overwrite)
179 // ------------------------------------------------------
180
187 virtual TRANS* createTransient(const Pers_t* persObj, MsgStream &log) {
188 std::unique_ptr<TRANS> trans(new TRANS());
189 persToTrans(persObj, trans.get(), log);
190 return(trans.release());
191 }
192
199 virtual TRANS* virt_createTransFromPStore( unsigned index, MsgStream &log ) {
200 assert (index < this->m_pStorage->size());
201 Pers_t pers = (*this->m_pStorage)[index];
202 return createTransient( &pers, log );
203 }
204};
205
206
207
213template< class TRANS >
215 : public TPPolyCnvBase< TRANS, TRANS, TPIntegerVector_p2 >
216{
217public:
219 virtual ~TPCnvBase() {}
220
222
223 // implement these methods without dynamic cast to TRANS
224
226 virtual TPObjRef virt_toPersistent( const TRANS *trans, MsgStream &log ) {
227 return toPersistent_impl( trans, log );
228 }
229
231 virtual void pstoreToTrans( unsigned index, TRANS *trans, MsgStream &log ) {
232 assert (index < this->m_pStorage->size());
233 Pers_t pers = (*this->m_pStorage)[index];
234 persToTrans( &pers, trans, log );
235 }
236
237};
238
239
240
241template< class TRANS_BASE, class TRANS >
244toPersistent_impl( const TRANS *trans, MsgStream &log )
245{
246 // make sure there is a storage object
247 if( !this->topConverter()->hasTLPersObject() ) {
248 this->topConverter()->createTLPersObject();
249 }
250
251 unsigned pos = m_pStorage->size();
252 // make a new space in the storage vector
253 m_pStorage->grow();
254
255 Pers_t pers = m_pStorage->back();
256 transToPers( trans, &pers, log);
257
258 return TPObjRef( this->m_pStorageTID, pos );
259}
260
261
262
263
264
265
266
267// --------------------------------------------------------------
268
276template<class TRANS, class CONV>
278 : public TPCnvBase<TRANS, TPIntegerVector_p2 > {
279public:
281
288 virtual void persToTrans(const TPIntegerVector_p2 * persVect, TRANS* transVect, MsgStream &log) {
289 TPIntegerVector_p2::const_iterator piter = persVect->begin();
290 size_t pers_size = persVect->next(piter);
291 transVect->clear();
292 transVect->reserve( pers_size );
293 // convert vector entries one by one
294 while( pers_size-- ) {
295 transVect->push_back( createTransFromPStore( &m_elementCnv, persVect->next_TPObjRef(piter), log ) );
296 }
297 }
298
305 virtual void transToPers(const TRANS* transVect, TPIntegerVector_p2* persVect, MsgStream &log) {
306 persVect->reserve( 1 + transVect->size()*2 );
307 persVect->push_back( transVect->size() );
308 // convert vector entries one by one
309 for( typename TRANS::const_iterator
310 it = transVect->begin(),
311 iEnd = transVect->end();
312 it != iEnd;
313 ++it ) {
314 persVect->push_TPObjRef( toPersistent( &m_elementCnv, *it, log ) );
315 }
316 }
317
318protected:
321};
322
323
324
325// --------------------------------------------------------------
334template<class TRANS, class CONV>
336 : public TPPtrVectorCnv<TRANS, TPIntegerVector_p2, CONV> {
337public:
340 virtual void transToPers(const TRANS* transVect, TPIntegerVector_p2* persVect, MsgStream &log)
341 {
342 persVect->reserve( 1 + transVect->size()*2 );
343 persVect->push_back( transVect->size() );
344 // convert vector entries one by one
345 for( typename TRANS::const_iterator
346 it = transVect->begin(),
347 iEnd = transVect->end();
348 it != iEnd;
349 ++it ) {
350 persVect->push_TPObjRef( toPersistent( (CONV**)0, *it, log ) );
351 }
352 }
353};
354
355
356/*
357 Converter between
358 transient vector<T> (by value) and persistent vector<TPObjRef>
359*/
360/*
361template<class TRANS, class PERS, class CONV>
362class TPValVectorCnv : public TPCnvBase<TRANS, PERS> {
363public:
364 TPValVectorCnv() : m_elementCnv(0) {}
365
367 virtual void persToTrans(const PERS* persVect, TRANS* transVect, MsgStream &log) {
368 transVect->clear();
369 transVect->reserve( persVect->size() );
370 // convert vector entries one by one
371 typename TRANS::iterator ti = transVect->begin();
372 typename PERS::const_iterator pi = persVect->begin(), iEnd = persVect->end();
373 for( ; pi != iEnd; ++pi, ++ti ) {
374 fillTransFromPStore( &m_elementCnv, *pi, &*ti, log );
375 }
376 }
377
379 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log) {
380 persVect->clear();
381 persVect->reserve( transVect->size() );
382 // convert vector entries one by one
383 for( typename TRANS::const_iterator
384 it = transVect->begin(), iEnd = transVect->end();
385 it != iEnd; ++it ) {
386 persVect->push_back( toPersistent( &m_elementCnv, &*it, log ) );
387 }
388 }
389
390protected:
392 CONV *m_elementCnv;
393};
394
395*/
396
397#endif
This file contains template definitions for Transient/Persistent converters.
This file contains definition of TPIntegerVectorStorage_p2, which is a storage class used in top-leve...
CNV::Trans_t * createTransFromPStore(CNV **cnv, const TPObjRef &ref, MsgStream &log) const
TPObjRef toPersistent(CNV **cnv, const typename CNV::TransBase_t *transObj, MsgStream &log) const
virtual const std::type_info & transientTInfo() const
return C++ type id of the transient class this converter is for
TPObjRef toPersistent_impl(const TRANS *trans, MsgStream &log)
Convert transient object to persistent representation.
virtual void persToTrans(const Pers_t *persObj, TRANS *transObj, MsgStream &log)=0
Convert persistent representation to transient one.
virtual void persToTransUntyped(const void *pers, void *trans, MsgStream &log)
Convert persistent object representation to transient.
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.
TPIntegerVectorStorage_p2 * m_pStorage
the address of the storage vector for persistent representations
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...
virtual void transToPersUntyped(const void *trans, void *pers, MsgStream &log)
Convert transient object representation to persistent.
void setPStorage(TPIntegerVectorStorage_p2 *storage)
Tell this converter which storage vector it should use to store or retrieve persistent representation...
virtual TRANS * virt_createTransFromPStore(unsigned, MsgStream &)
This method implements a pure virtual base class method, but should never be called,...
virtual void transToPers(const TRANS *transObj, Pers_t *persObj, MsgStream &log)=0
Convert transient representation to persistent one.
virtual void reservePStorage(size_t size)
Reserve 'size' elements for persistent storage - not much sense in this clas.
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_p2 > * m_pStorage
virtual void pstoreToTrans(unsigned index, TRANS *trans, MsgStream &log)
Convert persistent representation stored in the storage vector of the top-level object to transient.
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...
Storage implementation for TP converters producing TP representation as series of ints.
const value_type & next(const_iterator &iter) const
TPObjRef next_TPObjRef(const_iterator &iter) const
void push_back(const value_type &val)
void push_TPObjRef(const TPObjRef &val)
void reserve(size_t new_size)
const value_type * const_iterator
This class is an object reference used in Athena persistent data model.
Definition TPObjRef.h:20
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_t *persObj, MsgStream &log)
Create transient representation of a persistent object.
virtual TRANS * createTransient(const PERS *persObj, MsgStream &log)
Create transient representation of a persistent object.
virtual void transToPers(const TRANS *transVect, TPIntegerVector_p2 *persVect, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
Converter between: transient vector of T* (like DataVector<T>) and persistent vector<T> Uses converte...
CONV * m_elementCnv
pointer to the TP converter used for vector elements
virtual void transToPers(const TRANS *transVect, TPIntegerVector_p2 *persVect, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of Pers_t::value_type objects,...
virtual void persToTrans(const TPIntegerVector_p2 *persVect, TRANS *transVect, MsgStream &log)
Converts vector of Pers_t::value_type objects to vector of TRANS::value_type objects,...
Definition index.py:1