ATLAS Offline Software
Loading...
Searching...
No Matches
TPConverter.h
Go to the documentation of this file.
1// dear emacs, this is -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef TPCONVERTER_H
8#define TPCONVERTER_H 1
9
15
19#include "ITPConverter.h"
20#include "TopLevelTPCnvBase.h"
21
22#include "GaudiKernel/MsgStream.h"
23
24#include <vector>
25#include <stdexcept>
26#include <cassert>
27
28
35template< class TRANS >
37{
38public:
39 typedef TRANS TransBase_t;
42
47
48 virtual ~ITPConverterFor() = default;
49
56 template < class CNV >
57 CNV *
58 converterForType( CNV *cnv, const std::type_info& t_info, MsgStream& log ) const {
59 ITPConverter *c = m_topConverterRuntime->converterForType( t_info );
60 cnv = dynamic_cast< CNV* >( c );
61 if( !cnv )
62 this->converterNotFound( typeid(CNV), c, t_info.name(), log );
63 return cnv;
64 }
65
72 template < class CNV >
73 CNV *
74 converterForRef( CNV *cnv, const TPObjRef& ref, MsgStream& log ) const {
75 ITPConverter *c = m_topConverterRuntime->converterForRef( ref );
76 cnv = dynamic_cast<CNV*>(c);
77 if( !cnv )
78 this->converterNotFound( ref.typeID(), c, typeid(CNV).name(), log );
79 return cnv;
80 }
81
95 template < class CNV >
97 baseToPersistent( CNV **cnv, const typename CNV::Trans_t* transObj, MsgStream& log) const {
98 if( !*cnv || (*cnv)->wasUsedForReading() ) {
99 // don't trust the converter if it was used for reading, find again
100 *cnv = converterForType( *cnv, typeid(typename CNV::Trans_t), log );
101 if( !*cnv ) return TPObjRef();
102 (*cnv)->clearReadingFlag();
103 }
104// return (**cnv).toPersistent_impl(transObj, log);
105 return (**cnv).virt_toPersistent(transObj, log);
106 }
107
118 template < class CNV >
119 TPObjRef toPersistent( CNV **cnv, const typename CNV::TransBase_t* transObj, MsgStream& log) const {
120 if( !transObj ) return TPObjRef();
121 CNV *temp_cnv_p = 0;
122 if( !cnv ) cnv = &temp_cnv_p;
123 if( !*cnv || (*cnv)->wasUsedForReading() ) {
124 // don't trust the converter if it was used for reading, find again
125 *cnv = converterForType( *cnv, typeid(*transObj), log );
126 if( !*cnv ) return TPObjRef();
127 (*cnv)->clearReadingFlag();
128 }
129 return (**cnv).virt_toPersistent(transObj, log);
130 }
131
144 template < class CNV, class TRANS_T >
145 void fillTransFromPStore( CNV **cnv, const TPObjRef& ref, TRANS_T *trans, MsgStream &log ) const {
146 if( ref.isNull() ) return;
147 CNV *temp_cnv_p = 0;
148 if( !cnv ) cnv = &temp_cnv_p;
149 // see if we already have a converter and if it is the right one
150 if( !*cnv || (*cnv)->typeID().value() != ref.typeID() ) {
151 // we don't - find the right converter for ref.typeID()
152 *cnv = converterForRef( *cnv, ref, log );
153 if( !*cnv ) return;
154 (*cnv)->setReadingFlag();
155 }
156 (**cnv).pstoreToTrans( ref.index(), trans, log );
157 }
158
170 template < class CNV >
171 typename CNV::Trans_t*
172 createTransFromPStore( CNV **cnv, const TPObjRef& ref, MsgStream& log) const {
173 if( ref.isNull() ) return 0;
174 CNV *temp_cnv_p = 0;
175 if( !cnv ) cnv = &temp_cnv_p;
176 // see if we already have a converter and if it is the right one
177 if( !*cnv || (*cnv)->typeID().value() != ref.typeID() ) {
178 // we don't - find the right converter for ref.typeID()
179 *cnv = converterForRef( *cnv, ref, log );
180 if( !*cnv ) return 0;
181 (*cnv)->setReadingFlag();
182 }
183 return (**cnv).virt_createTransFromPStore( ref.index(), log );
184 }
185
186 // hook to initialize private converters
188
189
192 return m_topConverter;
193 }
194
196 virtual const TopLevelTPCnvBase* topConverter() const {
197 return m_topConverter;
198 }
199
201 virtual const std::type_info& transientTInfo() const { return typeid(TRANS); }
202
205 const std::type_info& transBaseTInfo() const { return typeid(TRANS); }
206
208 virtual const TPObjRef::typeID_t& typeID() const { return m_pStorageTID; }
209
211 unsigned typeIDvalue() const { return m_pStorageTIDvalue; }
212
213
219
229
230
231 /* Internal accessor methods for the Read Flag
232 Need to be public
233 */
237
238
239//protected:
240 // ------ methods operating on the persistent store of the top level object
241
249 virtual TPObjRef virt_toPersistent( const TransBase_t* trans, MsgStream& log) = 0;
250
260 const std::string& key,
261 MsgStream& log) = 0;
262
269 virtual TRANS* virt_createTransFromPStore( unsigned index, MsgStream &log ) = 0;
270
278 virtual TRANS* virt_createTransFromPStoreWithKey( unsigned index,
279 const std::string& key,
280 MsgStream &log ) = 0;
281
288 virtual void pstoreToTrans( unsigned index, TransBase_t* transObj, MsgStream& log) = 0;
289
290protected:
293
296
300
303
307};
308
309
310
311
312// --------------------------------------------------------------
313
328
329template< class TRANS_BASE, class TRANS, class PERS >
331 : public ITPConverterFor< TRANS_BASE >
332{
333public:
334 typedef TRANS Trans_t;
335 typedef PERS Pers_t;
336 typedef PERS PersBase_t; // Obsolete, for backward compat
337
339 m_pStorage(0),
340 m_curRecLevel(0),
341 m_recursive(false),
342 m_ignoreRecursion(false)
343 {}
344
345 virtual ~TPAbstractPolyCnvBase() = default;
346
347
348 // conversion methods - to be implemented in the concrete converter
349 // -------------------------------------------
350
358 virtual void persToTrans(const PERS* persObj, TRANS* transObj, MsgStream &log) = 0;
359
367 virtual void transToPers(const TRANS* transObj, PERS* persObj, MsgStream &log) = 0;
368
376 virtual void persToTransWithKey(const PERS* persObj, TRANS* transObj,
377 const std::string& /*key*/,
378 MsgStream &log)
379 {
380 return persToTrans (persObj, transObj, log);
381 }
382
383
392 virtual void transToPersWithKey(const TRANS* transObj, PERS* persObj,
393 const std::string& /*key*/,
394 MsgStream &log)
395 {
396 return transToPers (transObj, persObj, log);
397 }
398
400 virtual void persToTransUntyped(const void* pers,
401 void* trans,
402 MsgStream& log)
403 {
404 persToTrans (reinterpret_cast<const PERS*> (pers),
405 reinterpret_cast<TRANS*> (trans),
406 log);
407 }
408
410 virtual void transToPersUntyped(const void* trans,
411 void* pers,
412 MsgStream& log)
413 {
414 transToPers (reinterpret_cast<const TRANS*> (trans),
415 reinterpret_cast<PERS*> (pers),
416 log);
417 }
418
420 virtual void persToTransWithKeyUntyped(const void* pers,
421 void* trans,
422 const std::string& key,
423 MsgStream& log)
424 {
425 persToTransWithKey (reinterpret_cast<const PERS*> (pers),
426 reinterpret_cast<TRANS*> (trans),
427 key,
428 log);
429 }
430
432 virtual void transToPersWithKeyUntyped(const void* trans,
433 void* pers,
434 const std::string& key,
435 MsgStream& log)
436 {
437 transToPersWithKey (reinterpret_cast<const TRANS*> (trans),
438 reinterpret_cast<PERS*> (pers),
439 key,
440 log);
441 }
442
443 // Default implementations (usually no need to overwrite)
444 // ------------------------------------------------------
445
452 virtual PERS* createPersistent(const TRANS* transObj, MsgStream &log);
453
461 virtual PERS* createPersistentWithKey(const TRANS* transObj,
462 const std::string& key,
463 MsgStream &log);
464
474 const std::string& key,
475 MsgStream &log );
476
477
479 virtual const std::type_info& transientTInfo() const { return typeid(TRANS); }
480
482 virtual const std::type_info& persistentTInfo() const { return typeid(PERS); }
483
484//protected:
485 // various virtual "redirector" methods
486
494 virtual void pstoreToTrans( unsigned index, TRANS_BASE *trans, MsgStream &log ) {
495 assert (index < m_pStorage->size());
496 TRANS* trans_der = dynamic_cast<TRANS*>(trans);
497 if (!trans_der) std::abort();
498 this->persToTrans( &(*m_pStorage)[index], trans_der, log );
499 }
500
505 virtual TPObjRef virt_toPersistent( const TRANS_BASE *trans, MsgStream &log ) {
506 const TRANS* trans_der = dynamic_cast<const TRANS*>(trans);
507 if (!trans_der) std::abort();
508 return toPersistentWithKey_impl( trans_der, "", log);
509 }
510
515 virtual TPObjRef virt_toPersistentWithKey( const TRANS_BASE *trans,
516 const std::string& key,
517 MsgStream &log )
518 {
519 const TRANS* trans_der = dynamic_cast<const TRANS*>(trans);
520 if (!trans_der) std::abort();
521 return toPersistentWithKey_impl( trans_der, key, log);
522 }
523
528 virtual TRANS* virt_createTransFromPStore( unsigned, MsgStream& ) {
529 throw std::runtime_error(
530 std::string("virt_createTransFromPStore() mothod not supported in TP converter for an abstract class: ")
531 + typeid(*this).name() );
532 return 0;
533 }
534
539 virtual TRANS* virt_createTransFromPStoreWithKey( unsigned, const std::string&, MsgStream& ) {
540 throw std::runtime_error(
541 std::string("virt_createTransFromPStore() method not supported in TP converter for an abstract class: ")
542 + typeid(*this).name() );
543 return 0;
544 }
545
546public:
551 void setPStorage( std::vector< PERS > *storage ) {
552 m_pStorage = storage;
553 m_curRecLevel = 0;
554 }
555
559 void setRecursive( bool flag=true ) {
560 m_recursive = flag;
561 }
562
568 void ignoreRecursion( bool flag=false ) {
569 m_ignoreRecursion = flag;
570 }
571
573 virtual void reservePStorage( size_t size ) {
574 m_pStorage->reserve( size );
575 }
576
577protected:
579 std::vector< PERS > *m_pStorage;
580
583
586
589};
590
591
592
597template< class TRANS_BASE, class TRANS, class PERS >
599 : public TPAbstractPolyCnvBase<TRANS_BASE, TRANS, PERS>
600{
601public:
602 // To shorten using declarations in derived classes.
604
605
613 virtual void persToTrans (const PERS* persObj,
614 TRANS* transObj,
615 MsgStream &log) const = 0;
616
617
625 virtual void transToPers (const TRANS* transObj,
626 PERS* persObj,
627 MsgStream &log) const = 0;
628
629
630 // These call through to the const implementations.
631 virtual void persToTrans(const PERS* persObj,
632 TRANS* transObj,
633 MsgStream &log) override final
634 {
635 return const_cast<const TPAbstractPolyCnvConstBase*>(this)->persToTrans (persObj, transObj, log);
636 }
637
638
639 virtual void transToPers(const TRANS* transObj,
640 PERS* persObj,
641 MsgStream &log) override final
642 {
643 return const_cast<const TPAbstractPolyCnvConstBase*>(this)->transToPers (transObj, persObj, log);
644 }
645};
646
647
648
649// --------------------------------------------------------------
650
651
652// Base converter template for polymorphic types
653
654// Converters for objects in the same inheritance tree must share the same
655// base class type: TRANS_BASE
656
670
671template< class TRANS_BASE, class TRANS, class PERS >
673 : public TPAbstractPolyCnvBase< TRANS_BASE, TRANS, PERS >
674{
675public:
677 virtual ~TPPolyCnvBase() = default;
678
679
680 // Default implementations (usually no need to overwrite)
681 // ------------------------------------------------------
682
689 virtual TRANS* createTransient(const PERS* persObj, MsgStream &log);
690
698 virtual TRANS* createTransientWithKey(const PERS* persObj, const std::string& key, MsgStream &log);
699
706 virtual TRANS* virt_createTransFromPStore( unsigned index, MsgStream &log ) {
707 assert (index < this->m_pStorage->size());
708 return createTransient( &(*this->m_pStorage)[index], log );
709 }
710
718 virtual TRANS* virt_createTransFromPStoreWithKey( unsigned index,
719 const std::string& key,
720 MsgStream &log )
721 {
722 assert (index < this->m_pStorage->size());
723 return createTransientWithKey( &(*this->m_pStorage)[index], key, log );
724 }
725
726};
727
728
729
735template< class TRANS, class PERS >
737 : public TPPolyCnvBase< TRANS, TRANS, PERS >
738{
739public:
741 virtual ~TPConverterBase() = default;
742
743
744 // implement these methods without dynamic cast to TRANS
745
747 virtual TPObjRef virt_toPersistent( const TRANS *trans, MsgStream &log ) {
748 return this->toPersistentWithKey_impl( trans, "", log);
749 }
750
752 virtual TPObjRef virt_toPersistentWithKey( const TRANS *trans,
753 const std::string& key,
754 MsgStream &log )
755 {
756 return this->toPersistentWithKey_impl( trans, key, log);
757 }
758
760 virtual void pstoreToTrans( unsigned index, TRANS *trans, MsgStream &log ) {
761 assert (index < this->m_pStorage->size());
762 this->persToTrans( &(*this->m_pStorage)[index], trans, log );
763 }
764
765};
766
767
773template< class TRANS, class PERS >
775 : public TPConverterBase< TRANS, PERS >
776{
777public:
778 // To shorten using declarations in derived classes.
780
781
789 virtual void persToTrans (const PERS* persObj,
790 TRANS* transObj,
791 MsgStream &log) const = 0;
792
793
801 virtual void transToPers (const TRANS* transObj,
802 PERS* persObj,
803 MsgStream &log) const = 0;
804
805
806 // These call through to the const implementations.
807 virtual void persToTrans(const PERS* persObj,
808 TRANS* transObj,
809 MsgStream &log) override final
810 {
811 return const_cast<const TPConverterConstBase*>(this)->persToTrans (persObj, transObj, log);
812 }
813
814
815 virtual void transToPers(const TRANS* transObj,
816 PERS* persObj,
817 MsgStream &log) override final
818 {
819 return const_cast<const TPConverterConstBase*>(this)->transToPers (transObj, persObj, log);
820 }
821
822
823 virtual TRANS* createTransientConst (const PERS* persObj, MsgStream& log) const;
824 virtual PERS* createPersistentConst(const TRANS* transObj, MsgStream &log) const;
825};
826
827
832template< class TRANS, class PERS >
834 : public TPConverterConstBase< TRANS, PERS >
835{
836public:
839
840 // To shorten using declarations in derived classes.
842
843
852 virtual void persToTransWithKey (const PERS* persObj,
853 TRANS* transObj,
854 const std::string& key,
855 MsgStream &log) const = 0;
856
857
866 virtual void transToPersWithKey (const TRANS* transObj,
867 PERS* persObj,
868 const std::string& key,
869 MsgStream &log) const = 0;
870
871
872 // These call through to the const implementations.
873 virtual void persToTransWithKey (const PERS* persObj,
874 TRANS* transObj,
875 const std::string& key,
876 MsgStream &log) override final
877 {
878 return const_cast<const TPConverterWithKeyBase*>(this)->persToTransWithKey (persObj, transObj, key, log);
879 }
880
881
882 virtual void transToPersWithKey (const TRANS* transObj,
883 PERS* persObj,
884 const std::string& key,
885 MsgStream &log) override final
886 {
887 return const_cast<const TPConverterWithKeyBase*>(this)->transToPersWithKey (transObj, persObj, key, log);
888 }
889
890
891 // It's an error if the non-key versions get called.
892 virtual void persToTrans(const PERS* /*persObj*/,
893 TRANS* /*transObj*/,
894 MsgStream& /*log*/) const override final
895 {
896 throw std::runtime_error ("persToTrans called where persToTransWithKey required.");
897 }
898
899
900 virtual void transToPers(const TRANS* /*transObj*/,
901 PERS* /*persObj*/,
902 MsgStream& /*log*/) const override final
903 {
904 throw std::runtime_error ("transToPers called where transToPersWithKey required.");
905 }
906};
907
908
909// --------------------------------------------------------------
910
918template<class TRANS, class PERS, class CONV>
919class TPPtrVectorCnv : public TPConverterBase<TRANS, PERS> {
920public:
922
929 virtual void persToTrans(const PERS* persVect, TRANS* transVect, MsgStream &log) {
930 transVect->clear();
931 transVect->reserve( persVect->size() );
932 // convert vector entries one by one
933 for( typename PERS::const_iterator
934 it = persVect->begin(),
935 iEnd = persVect->end();
936 it != iEnd; ++it ) {
937 transVect->push_back( this->createTransFromPStore( &m_elementCnv, *it, log ) );
938 }
939 }
940
941
948 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log) {
949 persVect->clear();
950 persVect->reserve( transVect->size() );
951 // convert vector entries one by one
952 for( typename TRANS::const_iterator
953 it = transVect->begin(),
954 iEnd = transVect->end();
955 it != iEnd;
956 ++it ) {
957 persVect->push_back( this->toPersistent( &m_elementCnv, *it, log ) );
958 }
959 }
960
961protected:
964};
965
966
967
968// --------------------------------------------------------------
969
978template<class TRANS, class PERS, class CONV>
979class TPPtrVectorCnvConst : public TPConverterConstBase<TRANS, PERS> {
980public:
983
984
986
993 virtual void persToTrans(const PERS* persVect, TRANS* transVect, MsgStream &log) const override {
994 transVect->clear();
995 transVect->reserve( persVect->size() );
996 // convert vector entries one by one
997 CONV* cnv = nullptr;
998 for( typename PERS::const_iterator
999 it = persVect->begin(),
1000 iEnd = persVect->end();
1001 it != iEnd; ++it ) {
1002 transVect->push_back( this->createTransFromPStore( &cnv,
1003 *it, log ) );
1004 }
1005 }
1006
1007
1014 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log) const override
1015 {
1016 persVect->clear();
1017 persVect->reserve( transVect->size() );
1018 // convert vector entries one by one
1019 CONV* cnv = nullptr;
1020 for( typename TRANS::const_iterator
1021 it = transVect->begin(),
1022 iEnd = transVect->end();
1023 it != iEnd; ++it ) {
1024 persVect->push_back( this->toPersistent( &cnv, *it, log ) );
1025 }
1026 }
1027};
1028
1029
1030
1031// --------------------------------------------------------------
1032
1041template<class TRANS, class PERS, class CONV>
1043public:
1046
1047
1049
1057 virtual void persToTransWithKey (const PERS* persVect,
1058 TRANS* transVect,
1059 const std::string& /*key*/,
1060 MsgStream &log) const override
1061 {
1062 transVect->clear();
1063 transVect->reserve( persVect->size() );
1064 // convert vector entries one by one
1065 CONV* cnv = nullptr;
1066 for( typename PERS::const_iterator
1067 it = persVect->begin(),
1068 iEnd = persVect->end();
1069 it != iEnd; ++it ) {
1070 transVect->push_back( this->createTransFromPStore( &cnv,
1071 *it, log ) );
1072 }
1073 }
1074
1075
1083 virtual void transToPersWithKey (const TRANS* transVect,
1084 PERS* persVect,
1085 const std::string& key,
1086 MsgStream &log) const override
1087 {
1089 persVect->clear();
1090 persVect->reserve( transVect->size() );
1091 // convert vector entries one by one
1092 CONV* cnv = nullptr;
1093 size_t ipos = 0;
1094 for( typename TRANS::const_iterator
1095 it = transVect->begin(),
1096 iEnd = transVect->end();
1097 it != iEnd; ++it, ++ipos )
1098 {
1099 if (!dec || !dec->thinned (ipos)) {
1100 persVect->push_back( this->toPersistent( &cnv, *it, log ) );
1101 }
1102 }
1103 }
1104};
1105
1106
1107
1108// --------------------------------------------------------------
1117template<class TRANS, class PERS, class CONV>
1118class TPPolyVectorCnv : public TPPtrVectorCnv<TRANS, PERS, CONV> {
1119public:
1122 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log) {
1123 persVect->clear();
1124 persVect->reserve( transVect->size() );
1125 // convert vector entries one by one
1126 for( typename TRANS::const_iterator
1127 it = transVect->begin(),
1128 iEnd = transVect->end();
1129 it != iEnd; ++it ) {
1130 persVect->push_back( this->toPersistent( (CONV**)0, *it, log ) );
1131 }
1132 }
1133};
1134
1135
1145template<class TRANS, class PERS, class CONV>
1146class TPPolyVectorCnvConst : public TPPtrVectorCnvConst<TRANS, PERS, CONV> {
1147public:
1148 using TPPtrVectorCnvConst<TRANS, PERS, CONV>::transToPers;
1149 using TPPtrVectorCnvConst<TRANS, PERS, CONV>::persToTrans;
1150
1151
1154 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log) const {
1155 persVect->clear();
1156 persVect->reserve( transVect->size() );
1157 // convert vector entries one by one
1158 for( typename TRANS::const_iterator
1159 it = transVect->begin(),
1160 iEnd = transVect->end();
1161 it != iEnd; ++it ) {
1162 persVect->push_back( this->toPersistent( (CONV**)0, *it, log ) );
1163 }
1164 }
1165};
1166
1167
1168/*
1169 Converter between
1170 transient vector<T> (by value) and persistent vector<TPObjRef>
1171*/
1172
1173template<class TRANS, class PERS, class CONV>
1174class TPValVectorCnv : public TPConverterBase<TRANS, PERS> {
1175public:
1177
1179 virtual void persToTrans(const PERS* persVect, TRANS* transVect, MsgStream &log) {
1180 transVect->clear();
1181 transVect->reserve( persVect->size() );
1182 // convert vector entries one by one
1183 typename TRANS::iterator ti = transVect->begin();
1184 typename PERS::const_iterator pi = persVect->begin(), iEnd = persVect->end();
1185 for( ; pi != iEnd; ++pi, ++ti ) {
1186 fillTransFromPStore( &m_elementCnv, *pi, &*ti, log );
1187 }
1188 }
1189
1191 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log) {
1192 persVect->clear();
1193 persVect->reserve( transVect->size() );
1194 // convert vector entries one by one
1195 for( typename TRANS::const_iterator
1196 it = transVect->begin(), iEnd = transVect->end();
1197 it != iEnd; ++it ) {
1198 persVect->push_back( toPersistent( &m_elementCnv, &*it, log ) );
1199 }
1200 }
1201
1202protected:
1205};
1206
1207
1208
1209// --------------------------------------------------------------
1210/*
1211 Converter between
1212 transient AthenaHistVector of T* and persistent vector<T>
1213*/
1214
1215template<class TRANS, class PERS, class CONV>
1216class T_AthenaHitsVectorCnv : public TPConverterBase<TRANS, PERS> {
1217public:
1219
1221 virtual void persToTrans(const PERS* persCont, TRANS* transCont, MsgStream &log);
1223 virtual void transToPers(const TRANS* transCont, PERS* persCont, MsgStream &log);
1224};
1225
1226
1227// --------------------------------------------------------------
1228/*
1229 Converter between
1230 transient AtlasHitsVector of T* and persistent vector<T>
1231*/
1232
1233template<class TRANS, class PERS, class CONV>
1234class T_AtlasHitsVectorCnv : public TPConverterBase<TRANS, PERS> {
1235public:
1237
1239 virtual void persToTrans(const PERS* persCont, TRANS* transCont, MsgStream &log);
1241 virtual void transToPers(const TRANS* transCont, PERS* persCont, MsgStream &log);
1242};
1243
1244
1245// -------------------------------
1246// OLD STYLE vector TP converters
1247// TP conversion in-place, not involving top-level objects or TPRefs
1248// -------------------------------------------------------------------
1249/*
1250 Converter between
1251 transient vector of T* (like DataVector<T>)
1252 and persistent vector<T>
1253*/
1254
1255template<class TRANS, class PERS, class CONV>
1256class TPCnvVector : public TPConverterBase<TRANS, PERS> {
1257public:
1259
1261 virtual void persToTrans(const PERS* persVect, TRANS* transVect, MsgStream &log);
1263 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log);
1264
1267};
1268
1269
1270template<class TRANS, class PERS, class CONV>
1271class TPCnvVectorConst : public TPConverterConstBase<TRANS, PERS> {
1272public:
1274
1277
1279 virtual void persToTrans(const PERS* persVect, TRANS* transVect, MsgStream &log) const override;
1281 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log) const override;
1282};
1283
1284
1285/*
1286 Converter between
1287 transient vector of T and persistent vector<T>
1288*/
1289
1290template<class TRANS, class PERS, class CONV>
1291class TPCnvStdVector : public TPConverterBase<TRANS, PERS> {
1292public:
1294
1296 virtual void persToTrans(const PERS* persVect, TRANS* transVect, MsgStream &log) ;
1298 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log) ;
1299};
1300
1301
1306template<class TRANS, class PERS, class CONV>
1308{
1309public:
1312
1313
1315 virtual void persToTrans(const PERS* persVect,
1316 TRANS* transVect,
1317 MsgStream &log) const override;
1318
1320 virtual void transToPers(const TRANS* transVect,
1321 PERS* persVect,
1322 MsgStream &log) const override;
1323};
1324
1325
1326//---------------------------------------------------------------------------------
1327/*
1328 Converter between
1329 transient IdentifiableContainer<T> and persistent std::vector<T>
1330 Used by Muon RDO containers
1331 This version assumes RDO collection returns an identifier as a unsigned int.
1332*/
1333
1334template<class TRANS, class PERS, class CONV>
1335class TPCnvIDCont : public TPConverterBase<TRANS, PERS> {
1336public:
1338
1340 virtual void persToTrans(const PERS* persVect, TRANS* transVect, MsgStream &log) ;
1341
1343 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log) ;
1344
1345 typedef typename TRANS::IDENTIFIABLE COLLECTION_t;
1346
1349};
1350
1351//---------------------------------------------------------------------------------
1352/*
1353 Converter between
1354 transient IdentifiableContainer<T> and persistent std::vector<T>
1355 Used by Muon RDO containers
1356 This version assumes RDO collection returns an identifier as an Identifier
1357*/
1358
1359template<class TRANS, class PERS, class CONV>
1360class TPCnvIDContFromIdentifier : public TPConverterBase<TRANS, PERS> {
1361public:
1363
1365 virtual void persToTrans(const PERS* persVect, TRANS* transVect, MsgStream &log) ;
1366
1368 virtual void transToPers(const TRANS* transVect, PERS* persVect, MsgStream &log) ;
1369
1370 typedef typename TRANS::IDENTIFIABLE COLLECTION_t;
1371
1374};
1375
1376
1377
1378#include "TPConverter.icc"
1379#endif
const boost::regex ref(r_ef)
RpcSectorLogicContainer_p1 PERS
Defines the base ITPConverter class interface for all TP converters.
Hold thinning decisions for one container.
#define pi
Defines the base class for top-level TP converters.
virtual void initPrivateConverters(TopLevelTPCnvBase *)
virtual void setRuntimeTopConverter(TopLevelTPCnvBase *topConverter)
Set runtime top-level converter - usually it is the owning TL converter, but in case of extended obje...
CNV * converterForRef(CNV *cnv, const TPObjRef &ref, MsgStream &log) const
Find converter for a TP type ID (passed in a TP Ref), that is or ihnerits from CNV type.
Definition TPConverter.h:74
TopLevelTPCnvBase * m_topConverterRuntime
virtual ~ITPConverterFor()=default
TPObjRef baseToPersistent(CNV **cnv, const typename CNV::Trans_t *transObj, MsgStream &log) const
Persistify bass class of a given object and store the persistent represenation in the storage vector ...
Definition TPConverter.h:97
virtual void setTopConverter(TopLevelTPCnvBase *topConverter, const TPObjRef::typeID_t &TPtypeID)
Set which top-level converter owns this elemental converter, and what TPtypeID was assigned to the pe...
void setReadingFlag()
TransBase_t Trans_t
Definition TPConverter.h:40
void clearReadingFlag()
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...
virtual TopLevelTPCnvBase * topConverter()
return the top-level converter for this elemental TP converter
unsigned typeIDvalue() const
inlined non-virtual version to get the typeID value fast
void fillTransFromPStore(CNV **cnv, const TPObjRef &ref, TRANS_T *trans, MsgStream &log) const
Convert persistent object, stored in the the top-level persistent object and referenced by the TP Ref...
virtual TPObjRef virt_toPersistent(const TransBase_t *trans, MsgStream &log)=0
Internal interface method that is used to invoke the real conversion method (toPersistent_impl) in th...
const std::type_info & transBaseTInfo() const
return C++ type id of the common base transient type for all converters for a group of polymorphic ty...
virtual TRANS * virt_createTransFromPStore(unsigned index, MsgStream &log)=0
Internal interface method that is used to invoke the real conversion method (createTransient) in the ...
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...
virtual void pstoreToTrans(unsigned index, TransBase_t *transObj, MsgStream &log)=0
Internal interface method that is used to invoke the real conversion method (persToTrans) in the deri...
virtual const TPObjRef::typeID_t & typeID() const
Return TP typeID for persistent objects produced by this converter.
virtual const TopLevelTPCnvBase * topConverter() const
return the top-level converter for this elemental TP converter
virtual TRANS * virt_createTransFromPStoreWithKey(unsigned index, const std::string &key, MsgStream &log)=0
Internal interface method that is used to invoke the real conversion method (createTransient) in the ...
virtual const std::type_info & transientTInfo() const
return C++ type id of the transient class this converter is for
CNV * converterForType(CNV *cnv, const std::type_info &t_info, MsgStream &log) const
Find converter for a given C++ type ID, that is or ihnerits from CNV type.
Definition TPConverter.h:58
virtual TPObjRef virt_toPersistentWithKey(const TransBase_t *trans, const std::string &key, MsgStream &log)=0
Internal interface method that is used to invoke the real conversion method (toPersistent_impl) in th...
ITPConverterFor< TRANS > PolyCnvBase_t
Definition TPConverter.h:41
bool wasUsedForReading()
virtual void converterNotFound(const std::type_info &converterType, ITPConverter *c, const std::string &typeName, MsgStream &log) const
method called when the right TP converter was not found during writing
Hold thinning decisions for one container.
bool thinned(size_t ndx) const
Return true if element ndx should be thinned.
virtual PERS * createPersistent(const TRANS *transObj, MsgStream &log)
Create persistent representation of a transient object.
virtual TRANS * virt_createTransFromPStore(unsigned, MsgStream &)
This method implements a pure virtual base class method, but should never be called,...
void ignoreRecursion(bool flag=false)
Tell the converter to ignore recursion (do not throw errors) even when recurion is detected.
virtual PERS * createPersistentWithKey(const TRANS *transObj, const std::string &key, MsgStream &log)
Create persistent representation of a transient object, with SG key.
virtual void persToTransWithKeyUntyped(const void *pers, void *trans, const std::string &key, MsgStream &log)
Convert persistent object representation to transient.
virtual void transToPersWithKeyUntyped(const void *trans, void *pers, const std::string &key, MsgStream &log)
Convert transient object representation to persistent.
virtual void persToTrans(const PERS *persObj, TRANS *transObj, MsgStream &log)=0
Convert persistent representation to transient one.
bool m_ignoreRecursion
if true, do not throw errors in case of recursion.
virtual void transToPers(const TRANS *transObj, PERS *persObj, MsgStream &log)=0
Convert transient representation to persistent one.
void setPStorage(std::vector< PERS > *storage)
Tell this converter which storage vector it should use to store or retrieve persistent representation...
virtual void transToPersUntyped(const void *trans, void *pers, MsgStream &log)
Convert transient object representation to persistent.
std::vector< PERS > * m_pStorage
the address of the storage vector for persistent representations
virtual const std::type_info & transientTInfo() const
return C++ type id of the transient class this converter is for
bool m_recursive
if true, work in recursion-safe way (slower)
virtual const std::type_info & persistentTInfo() const
return C++ type id of the persistent class this converter is for
virtual TRANS * virt_createTransFromPStoreWithKey(unsigned, const std::string &, MsgStream &)
This method implements a pure virtual base class method, but should never be called,...
virtual void transToPersWithKey(const TRANS *transObj, PERS *persObj, const std::string &, MsgStream &log)
Convert transient representation to persistent one.
int m_curRecLevel
count recursive invocations, to detect recursion
virtual void persToTransUntyped(const void *pers, void *trans, MsgStream &log)
Convert persistent object representation to transient.
void setRecursive(bool flag=true)
Tell the converter if it should work in recursive mode slower but it can safely handle recursion.
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 reservePStorage(size_t size)
Reserve 'size' elements for persistent storage.
virtual TPObjRef virt_toPersistentWithKey(const TRANS_BASE *trans, const std::string &key, MsgStream &log)
Internal interface method that is used to invoke the real conversion method (toPersistent_impl) in th...
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 void persToTransWithKey(const PERS *persObj, TRANS *transObj, const std::string &, MsgStream &log)
Convert persistent representation to transient one.
TPObjRef toPersistentWithKey_impl(const TRANS *trans, const std::string &key, MsgStream &log)
Convert transient object to persistent representation.
virtual ~TPAbstractPolyCnvBase()=default
In contrast to TPAbstractPolyCnvBase, this calls const methods to do the conversion.
virtual void transToPers(const TRANS *transObj, PERS *persObj, MsgStream &log) override final
Convert transient representation to persistent one.
virtual void persToTrans(const PERS *persObj, TRANS *transObj, MsgStream &log) override final
Convert persistent representation to transient one.
virtual void persToTrans(const PERS *persObj, TRANS *transObj, MsgStream &log) const =0
Convert persistent representation to transient one.
TPAbstractPolyCnvConstBase base_class
virtual void transToPers(const TRANS *transObj, PERS *persObj, MsgStream &log) const =0
Convert transient representation to persistent one.
TRANS::IDENTIFIABLE COLLECTION_t
CONV m_elementCnv
the TP converter used for vector elements
virtual void persToTrans(const PERS *persVect, TRANS *transVect, MsgStream &log)
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
virtual void persToTrans(const PERS *persVect, TRANS *transVect, MsgStream &log)
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
TRANS::IDENTIFIABLE COLLECTION_t
Const version of TPCnvStdVector.
virtual void persToTrans(const PERS *persVect, TRANS *transVect, MsgStream &log) const override
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log) const override
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
virtual void persToTrans(const PERS *persVect, TRANS *transVect, MsgStream &log)
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log) const override
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
virtual void persToTrans(const PERS *persVect, TRANS *transVect, MsgStream &log) const override
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
virtual void persToTrans(const PERS *persVect, TRANS *transVect, MsgStream &log)
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
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...
virtual TPObjRef virt_toPersistentWithKey(const TRANS *trans, const std::string &key, MsgStream &log)
Internal interface method that is used to invoke the real conversion method (toPersistent_impl) in th...
virtual ~TPConverterBase()=default
TP Converter template for a "regular" type.
virtual void persToTrans(const PERS *persObj, TRANS *transObj, MsgStream &log) override final
Convert persistent representation to transient one.
virtual PERS * createPersistentConst(const TRANS *transObj, MsgStream &log) const
TPConverterConstBase base_class
virtual void transToPers(const TRANS *transObj, PERS *persObj, MsgStream &log) const =0
Convert transient representation to persistent one.
virtual void transToPers(const TRANS *transObj, PERS *persObj, MsgStream &log) override final
Convert transient representation to persistent one.
virtual TRANS * createTransientConst(const PERS *persObj, MsgStream &log) const
virtual void persToTrans(const PERS *persObj, TRANS *transObj, MsgStream &log) const =0
Convert persistent representation to transient one.
TP Converter template for a "regular" type.
virtual void persToTrans(const PERS *, TRANS *, MsgStream &) const override final
Convert persistent representation to transient one.
virtual void transToPersWithKey(const TRANS *transObj, PERS *persObj, const std::string &key, MsgStream &log) const =0
Convert transient representation to persistent one.
virtual void transToPers(const TRANS *, PERS *, MsgStream &) const override final
Convert transient representation to persistent one.
virtual void persToTransWithKey(const PERS *persObj, TRANS *transObj, const std::string &key, MsgStream &log) override final
Convert persistent representation to transient one.
virtual void persToTransWithKey(const PERS *persObj, TRANS *transObj, const std::string &key, MsgStream &log) const =0
Convert persistent representation to transient one.
TPConverterWithKeyBase base_class
virtual void transToPersWithKey(const TRANS *transObj, PERS *persObj, const std::string &key, MsgStream &log) override final
Convert transient representation to persistent one.
This class is an object reference used in Athena persistent data model.
Definition TPObjRef.h:20
unsigned typeID() const
returns the type ID (as integer) of the referenced object
Definition TPObjRef.h:71
virtual TRANS * virt_createTransFromPStoreWithKey(unsigned index, const std::string &key, MsgStream &log)
Internal interface method that is used to invoke the real conversion method (createTransient)
virtual TRANS * createTransientWithKey(const PERS *persObj, const std::string &key, MsgStream &log)
Create transient representation of a persistent object, with SG key.
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.
virtual ~TPPolyCnvBase()=default
Converter between: transient vector of T* (like DataVector<T>) and persistent vector<T> Uses converte...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log) const
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...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log) const override
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
virtual void persToTrans(const PERS *persVect, TRANS *transVect, MsgStream &log) const override
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
virtual void persToTrans(const PERS *persVect, TRANS *transVect, MsgStream &log)
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
virtual void transToPersWithKey(const TRANS *transVect, PERS *persVect, const std::string &key, MsgStream &log) const override
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
virtual void persToTransWithKey(const PERS *persVect, TRANS *transVect, const std::string &, MsgStream &log) const override
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
virtual void persToTrans(const PERS *persVect, TRANS *transVect, MsgStream &log)
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
CONV * m_elementCnv
pointer to the TP converter used for vector elements
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
transToPers
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
persToTrans
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
transToPers
Base class for top-level TP converters.
Helpers to retrieve the current thinning cache from the event context.
const SG::ThinningDecisionBase * getThinningDecision(const EventContext &ctx, const std::string &key)
Retrieve the current thinning decision for key.
Definition index.py:1
This structure holds an ID of a persistent type.
Definition TPObjRef.h:31
unsigned value() const
Returns the type ID as an integer.
Definition TPObjRef.h:46