ATLAS Offline Software
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 
12 template< class TRANS_BASE, class TRANS >
13 class TPAbstractPolyCnvBase < TRANS_BASE, TRANS, TPIntegerVector_p1 > : public ITPConverterFor< TRANS_BASE >
14 {
15 public:
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 
118 public:
124  m_pStorage = storage;
125  m_curRecLevel = 0;
126  }
127 
129  virtual void reservePStorage( size_t size ) {
130  m_pStorage->reserve( size );
131  }
132 
133 protected:
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 
167 template< class TRANS_BASE, class TRANS >
168 class TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 > : public TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >
169 {
170 public:
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 
211 template< class TRANS >
213  : public TPPolyCnvBase< TRANS, TRANS, TPIntegerVector_p1 >
214 {
215 public:
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 
240 template< class TRANS_BASE, class TRANS >
241 TPObjRef
243 toPersistent_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  }
256  m_curRecLevel++;
257  PERS pers = m_pStorage->back();
258  transToPers( trans, &pers, log);
259  m_curRecLevel--;
260 
261  return TPObjRef( this->m_pStorageTID, m_pStorage->size()-1 );
262 }
263 
264 
265 #endif
266 
267 
268 
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::pstoreToTrans
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.
Definition: TPIntVectorCnv_p1.h:93
TPConverter.h
This file contains template definitions for Transient/Persistent converters.
TPAbstractPolyCnvBase::m_pStorage
std::vector< PERS > * m_pStorage
the address of the storage vector for persistent representations
Definition: TPConverter.h:579
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::PERS
TPIntegerVector_p1 PERS
Definition: TPIntVectorCnv_p1.h:17
ITPConverterFor
Definition: TPConverter.h:37
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::persToTransUntyped
virtual void persToTransUntyped(const void *pers, void *trans, MsgStream &log)
Convert persistent object representation to transient.
Definition: TPIntVectorCnv_p1.h:46
index
Definition: index.py:1
TPPolyCnvBase::createTransient
virtual TRANS * createTransient(const PERS *persObj, MsgStream &log)
Create transient representation of a persistent object.
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::transToPers
virtual void transToPers(const TRANS *transObj, PERS *persObj, MsgStream &log)=0
Convert transient representation to persistent one.
TPCnvBase< TRANS, TPIntegerVector_p1 >::PERS
TPIntegerVector_p1 PERS
Definition: TPIntVectorCnv_p1.h:219
TPCnvBase
TPIntegerVectorStorage_p1
Definition: TPIntegerVector_p1.h:71
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::transToPersUntyped
virtual void transToPersUntyped(const void *trans, void *pers, MsgStream &log)
Convert transient object representation to persistent.
Definition: TPIntVectorCnv_p1.h:53
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::transientTInfo
virtual const std::type_info & transientTInfo() const
return C++ type id of the transient class this converter is for
Definition: TPIntVectorCnv_p1.h:81
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::Trans_t
TRANS Trans_t
Definition: TPIntVectorCnv_p1.h:16
TPObjRef
Definition: TPObjRef.h:20
TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::~TPPolyCnvBase
virtual ~TPPolyCnvBase()
Definition: TPIntVectorCnv_p1.h:172
TPAbstractPolyCnvBase::transToPers
virtual void transToPers(const TRANS *transObj, PERS *persObj, MsgStream &log)=0
Convert transient representation to persistent one.
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::persToTrans
virtual void persToTrans(const PERS *persObj, TRANS *transObj, MsgStream &log)=0
Convert persistent representation to transient one.
TPPolyCnvBase
Definition: TPConverter.h:674
TPCnvBase< TRANS, TPIntegerVector_p1 >::virt_toPersistent
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...
Definition: TPIntVectorCnv_p1.h:224
TPAbstractPolyCnvBase
Definition: TPConverter.h:332
ITPConverterFor< TRANS_BASE >::m_pStorageTID
TPObjRef::typeID_t m_pStorageTID
TP Ref typeID for the persistent objects this converter is creating.
Definition: TPConverter.h:292
TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::TPPolyCnvBase
TPPolyCnvBase()
Definition: TPIntVectorCnv_p1.h:171
TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::createTransient
virtual TRANS * createTransient(const PERS *persObj, MsgStream &log)
Create transient representation of a persistent object.
Definition: TPIntVectorCnv_p1.h:185
TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::PERS
TPIntegerVector_p1 PERS
Definition: TPIntVectorCnv_p1.h:174
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::m_curRecLevel
int m_curRecLevel
count recursive invocations, to detect recursion
Definition: TPIntVectorCnv_p1.h:138
TPCnvBase< TRANS, TPIntegerVector_p1 >::TPCnvBase
TPCnvBase()
Definition: TPIntVectorCnv_p1.h:216
TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::virt_createTransFromPStore
virtual TRANS * virt_createTransFromPStore(unsigned index, MsgStream &log)
Internal interface method that is used to invoke the real conversion method (createTransient)
Definition: TPIntVectorCnv_p1.h:197
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::setPStorage
void setPStorage(TPIntegerVectorStorage_p1 *storage)
Tell this converter which storage vector it should use to store or retrieve persistent representation...
Definition: TPIntVectorCnv_p1.h:123
TPIntegerVector_p1
Definition: TPIntegerVector_p1.h:26
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::~TPAbstractPolyCnvBase
virtual ~TPAbstractPolyCnvBase()
Definition: TPIntVectorCnv_p1.h:21
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::virt_toPersistent
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...
Definition: TPIntVectorCnv_p1.h:103
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::reservePStorage
virtual void reservePStorage(size_t size)
Reserve 'size' elements for persistent storage - not much sense in this clas.
Definition: TPIntVectorCnv_p1.h:129
DeMoScan.index
string index
Definition: DeMoScan.py:362
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::virt_createTransFromPStore
virtual TRANS * virt_createTransFromPStore(unsigned, MsgStream &)
This method implements a pure virtual base class method, but should never be called,...
Definition: TPIntVectorCnv_p1.h:111
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::m_recursive
bool m_recursive
if true, work in recursion-safe way (slower)
Definition: TPIntVectorCnv_p1.h:141
TPAbstractPolyCnvBase::persToTrans
virtual void persToTrans(const PERS *persObj, TRANS *transObj, MsgStream &log)=0
Convert persistent representation to transient one.
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TPCnvBase< TRANS, TPIntegerVector_p1 >::~TPCnvBase
virtual ~TPCnvBase()
Definition: TPIntVectorCnv_p1.h:217
TPCnvBase< TRANS, TPIntegerVector_p1 >::pstoreToTrans
virtual void pstoreToTrans(unsigned index, TRANS *trans, MsgStream &log)
Convert persistent representation stored in the storage vector of the top-level object to transient.
Definition: TPIntVectorCnv_p1.h:229
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::TPAbstractPolyCnvBase
TPAbstractPolyCnvBase()
Definition: TPIntVectorCnv_p1.h:19
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p1 >::m_pStorage
TPIntegerVectorStorage_p1 * m_pStorage
the address of the storage vector for persistent representations
Definition: TPIntVectorCnv_p1.h:135
TPAbstractPolyCnvBase::m_curRecLevel
int m_curRecLevel
count recursive invocations, to detect recursion
Definition: TPConverter.h:582