ATLAS Offline Software
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 
14 #include "TPConverter.h"
16 
17 #include <stdexcept>
18 
19 
20 template< class TRANS_BASE, class TRANS >
21 class TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >
22  : public ITPConverterFor< TRANS_BASE >
23 {
24 public:
25  typedef TRANS Trans_t;
27 
29  {}
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 
126 public:
132  m_pStorage = storage;
133  }
134 
136  virtual void reservePStorage( size_t size ) {
137  m_pStorage->reserve( size );
138  }
139 
140 protected:
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 
168 template< class TRANS_BASE, class TRANS >
169 class TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >
170  : public TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >
171 {
172 public:
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 
213 template< class TRANS >
215  : public TPPolyCnvBase< TRANS, TRANS, TPIntegerVector_p2 >
216 {
217 public:
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 
241 template< class TRANS_BASE, class TRANS >
242 TPObjRef
244 toPersistent_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 
276 template<class TRANS, class CONV>
277 class TPPtrVectorCnv<TRANS, TPIntegerVector_p2, CONV >
278  : public TPCnvBase<TRANS, TPIntegerVector_p2 > {
279 public:
281 
288  virtual void persToTrans(const TPIntegerVector_p2 * persVect, TRANS* transVect, MsgStream &log) {
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 
318 protected:
320  CONV *m_elementCnv;
321 };
322 
323 
324 
325 // --------------------------------------------------------------
334 template<class TRANS, class CONV>
336  : public TPPtrVectorCnv<TRANS, TPIntegerVector_p2, CONV> {
337 public:
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 /*
361 template<class TRANS, class PERS, class CONV>
362 class TPValVectorCnv : public TPCnvBase<TRANS, PERS> {
363 public:
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 
390 protected:
392  CONV *m_elementCnv;
393 };
394 
395 */
396 
397 #endif
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
ITPConverterFor
Definition: TPConverter.h:37
TopLevelTPCnvBase::createTLPersObject
virtual void createTLPersObject()=0
Create persistent object - the converter keeps it.
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::transientTInfo
virtual const std::type_info & transientTInfo() const
return C++ type id of the transient class this converter is for
Definition: TPIntVectorCnv_p2.h:89
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::virt_createTransFromPStore
virtual TRANS * virt_createTransFromPStore(unsigned, MsgStream &)
This method implements a pure virtual base class method, but should never be called,...
Definition: TPIntVectorCnv_p2.h:119
TPIntegerVector_p2::begin
iterator begin()
Definition: TPIntegerVector_p2.h:92
TPCnvBase< TRANS, TPIntegerVector_p2 >::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_p2.h:226
index
Definition: index.py:1
TPPtrVectorCnv< TRANS, TPIntegerVector_p2, CONV >::transToPers
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,...
Definition: TPIntVectorCnv_p2.h:305
TPPolyCnvBase::createTransient
virtual TRANS * createTransient(const PERS *persObj, MsgStream &log)
Create transient representation of a persistent object.
TPIntegerVector_p2::next_TPObjRef
TPObjRef next_TPObjRef(const_iterator &iter) const
TPIntegerVector_p2::reserve
void reserve(size_t new_size)
TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::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_p2.h:199
TPIntegerVector_p2.h
This file contains definition of TPIntegerVectorStorage_p2, which is a storage class used in top-leve...
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::Pers_t
TPIntegerVector_p2 Pers_t
Definition: TPIntVectorCnv_p2.h:26
TPCnvBase
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TPCnvBase< TRANS, TPIntegerVector_p2 >::TPCnvBase
TPCnvBase()
Definition: TPIntVectorCnv_p2.h:218
TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::Pers_t
TPIntegerVector_p2 Pers_t
Definition: TPIntVectorCnv_p2.h:176
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::TPAbstractPolyCnvBase
TPAbstractPolyCnvBase()
Definition: TPIntVectorCnv_p2.h:28
ITPConverterFor< TRANS_BASE >::topConverter
virtual TopLevelTPCnvBase * topConverter()
return the top-level converter for this elemental TP converter
Definition: TPConverter.h:191
TPObjRef
Definition: TPObjRef.h:20
TPAbstractPolyCnvBase::transToPers
virtual void transToPers(const TRANS *transObj, PERS *persObj, MsgStream &log)=0
Convert transient representation to persistent one.
TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::~TPPolyCnvBase
virtual ~TPPolyCnvBase()
Definition: TPIntVectorCnv_p2.h:174
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TPPolyCnvBase
Definition: TPConverter.h:674
TPCnvBase< TRANS, TPIntegerVector_p2 >::~TPCnvBase
virtual ~TPCnvBase()
Definition: TPIntVectorCnv_p2.h:219
TPAbstractPolyCnvBase
Definition: TPConverter.h:332
TPIntegerVector_p2
Definition: TPIntegerVector_p2.h:22
TPIntegerVectorStorage_p2
Storage implementation for TP converters producing TP representation as series of ints.
Definition: TPIntegerVector_p2.h:121
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
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::transToPersUntyped
virtual void transToPersUntyped(const void *trans, void *pers, MsgStream &log)
Convert transient object representation to persistent.
Definition: TPIntVectorCnv_p2.h:66
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::persToTransUntyped
virtual void persToTransUntyped(const void *pers, void *trans, MsgStream &log)
Convert persistent object representation to transient.
Definition: TPIntVectorCnv_p2.h:56
TPPtrVectorCnv< TRANS, TPIntegerVector_p2, CONV >::TPPtrVectorCnv
TPPtrVectorCnv()
Definition: TPIntVectorCnv_p2.h:280
TPPtrVectorCnv< TRANS, TPIntegerVector_p2, CONV >::persToTrans
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: TPIntVectorCnv_p2.h:288
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::Trans_t
TRANS Trans_t
Definition: TPIntVectorCnv_p2.h:25
ITPConverterFor::toPersistent
TPObjRef toPersistent(CNV **cnv, const typename CNV::TransBase_t *transObj, MsgStream &log) const
Persistify an object and store the persistent represenation in the storage vector of the top-level pe...
Definition: TPConverter.h:119
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::reservePStorage
virtual void reservePStorage(size_t size)
Reserve 'size' elements for persistent storage - not much sense in this clas.
Definition: TPIntVectorCnv_p2.h:136
TPCnvBase< TRANS, TPIntegerVector_p2 >::Pers_t
TPIntegerVector_p2 Pers_t
Definition: TPIntVectorCnv_p2.h:221
TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::TPPolyCnvBase
TPPolyCnvBase()
Definition: TPIntVectorCnv_p2.h:173
TPIntegerVector_p2::const_iterator
const value_type * const_iterator
Definition: TPIntegerVector_p2.h:26
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::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_p2.h:111
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::m_pStorage
TPIntegerVectorStorage_p2 * m_pStorage
the address of the storage vector for persistent representations
Definition: TPIntVectorCnv_p2.h:142
DeMoScan.index
string index
Definition: DeMoScan.py:364
TPIntegerVector_p2::push_back
void push_back(const value_type &val)
TPPolyVectorCnv< TRANS, TPIntegerVector_p2, CONV >::transToPers
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,...
Definition: TPIntVectorCnv_p2.h:340
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
TPPolyVectorCnv
Definition: TPConverter.h:1118
TPPtrVectorCnv::m_elementCnv
CONV * m_elementCnv
pointer to the TP converter used for vector elements
Definition: TPConverter.h:963
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::~TPAbstractPolyCnvBase
virtual ~TPAbstractPolyCnvBase()
Definition: TPIntVectorCnv_p2.h:31
TPPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::createTransient
virtual TRANS * createTransient(const Pers_t *persObj, MsgStream &log)
Create transient representation of a persistent object.
Definition: TPIntVectorCnv_p2.h:187
TPPtrVectorCnv< TRANS, TPIntegerVector_p2, CONV >::m_elementCnv
CONV * m_elementCnv
pointer to the TP converter used for vector elements
Definition: TPIntVectorCnv_p2.h:320
TPIntegerVector_p2::push_TPObjRef
void push_TPObjRef(const TPObjRef &val)
TPPtrVectorCnv
Definition: TPConverter.h:919
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::setPStorage
void setPStorage(TPIntegerVectorStorage_p2 *storage)
Tell this converter which storage vector it should use to store or retrieve persistent representation...
Definition: TPIntVectorCnv_p2.h:131
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::persToTrans
virtual void persToTrans(const Pers_t *persObj, TRANS *transObj, MsgStream &log)=0
Convert persistent representation to transient one.
TPIntegerVector_p2::next
const value_type & next(const_iterator &iter) const
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::transToPers
virtual void transToPers(const TRANS *transObj, Pers_t *persObj, MsgStream &log)=0
Convert transient representation to persistent one.
TPCnvBase< TRANS, TPIntegerVector_p2 >::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_p2.h:231
TPAbstractPolyCnvBase< TRANS_BASE, TRANS, TPIntegerVector_p2 >::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_p2.h:101
python.MpUtils.piter
def piter(iterable, eoi=None)
Definition: MpUtils.py:69
ITPConverterFor::createTransFromPStore
CNV::Trans_t * createTransFromPStore(CNV **cnv, const TPObjRef &ref, MsgStream &log) const
Create transient representation of a persistent object, stored in the the top-level persistent object...
Definition: TPConverter.h:172