ATLAS Offline Software
Loading...
Searching...
No Matches
TopLevelTPConverter.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 TOPLEVELTPCONVERTER_H
6#define TOPLEVELTPCONVERTER_H
7
12
13#include "TopLevelTPCnvBaseP.h"
14#include "TPConverter.h"
16
17
30
31template< class MAIN_CNV, class TL_PERS >
33 : public TopLevelTPCnvBaseP< TL_PERS >
34 , public ITPCnvBase
35{
36public:
37 typedef typename MAIN_CNV::Trans_t TRANS;
38 typedef TL_PERS PERS;
39
40 // ---- Methods to be implement in the derived converter:
41
42 // this declaration is repeated here for clarity
44 virtual void setPStorage( TL_PERS* persObj) override = 0;
45
51
52
53 // ----- default implementations
54
62 TRANS* createTransient( MsgStream &log ) {
63 // 0 is the index of the main and only one top level object
64 TRANS *transObj = m_mainConverter.virt_createTransFromPStore( 0, log );
65 this->deleteTLPersObject();
66 return transObj;
67 }
68
69
78 TRANS* createTransientWithKey( const std::string& key,
79 MsgStream &log )
80 {
81 // 0 is the index of the main and only one top level object
82 TRANS *transObj = m_mainConverter.virt_createTransFromPStoreWithKey( 0, key, log );
83 this->deleteTLPersObject();
84 return transObj;
85 }
86
87
96 virtual TRANS* createTransient(const TL_PERS* persObj, MsgStream &log) {
97 // FIXME: TPConverter uses the same non-const member m_pStorage
98 // for both reading and writing, but we want it to be const
99 // in the former case.
100 TL_PERS* pers_nc ATLAS_THREAD_SAFE = const_cast<TL_PERS*>(persObj);
101 setPStorage( pers_nc );
102 return createTransient( log );
103 }
104
110 virtual TL_PERS* createPersistent(const TRANS* transObj, MsgStream &log)
111 {
112 // create a new persistent object (empty)
113 this->createTLPersObject();
114 // do transToPers conversion, fill in the persistent object
115 m_mainConverter.virt_toPersistent(transObj, log);
116 // take the persistent object away from the TL converter
117 TL_PERS *ret = this->getTLPersObject();
118 // important to clear so createTransient() will not try to delete it (and crash)
119 this->clearTLPersObject();
120 return ret;
121 }
122
129 virtual TL_PERS* createPersistentWithKey(const TRANS* transObj,
130 const std::string& key,
131 MsgStream &log)
132 {
133 // create a new persistent object (empty)
134 this->createTLPersObject();
135 // do transToPers conversion, fill in the persistent object
136 m_mainConverter.virt_toPersistentWithKey(transObj, key, log);
137 // take the persistent object away from the TL converter
138 TL_PERS *ret = this->getTLPersObject();
139 // important to clear so createTransient() will not try to delete it (and crash)
140 this->clearTLPersObject();
141 return ret;
142 }
143
147
149 // moved to a template to accomodate TPIntegerVectorStorage_pN classes
150 // without whole class specialization
151 template< typename STORAGE >
152 void setMainCnvPStorage( STORAGE* storage ) {
153 m_mainConverter.setPStorage( storage );
154 }
155
159 virtual unsigned short getConverterID() override { return 0; }
160
161
162 //- --------------------------------------------------------------------------
163 // implementation of ITPCnvBase interface
164
166 virtual const std::type_info& transientTInfo() const override { return typeid(TRANS); }
167
169 virtual const std::type_info& persistentTInfo() const override { return typeid(PERS); }
170
171
173 virtual void persToTransUntyped(const void* pers, void* trans, MsgStream& log) override {
174 persToTrans( reinterpret_cast<const PERS*>(pers), reinterpret_cast<TRANS*>(trans), log );
175 }
176
178 virtual void transToPersUntyped(const void* trans, void* pers, MsgStream& log) override {
179 transToPers( reinterpret_cast<const TRANS*>(trans), reinterpret_cast<PERS*>(pers), log );
180 }
181
183 virtual void persToTransWithKeyUntyped(const void* pers,
184 void* trans,
185 const std::string& /*key*/,
186 MsgStream& log) override
187 {
188 persToTrans( reinterpret_cast<const PERS*>(pers), reinterpret_cast<TRANS*>(trans), log );
189 }
190
192 virtual void transToPersWithKeyUntyped(const void* trans,
193 void* pers,
194 const std::string& /*key*/,
195 MsgStream& log) override
196 {
197 transToPers( reinterpret_cast<const TRANS*>(trans), reinterpret_cast<PERS*>(pers), log );
198 }
199
200 // ---------------------- methods used by T_TPCnv<> converters
201 virtual void persToTrans (const PERS* pers, TRANS* trans, MsgStream& msg) {
202 // FIXME: TPConverter uses the same non-const member m_pStorage
203 // for both reading and writing, but we want it to be const
204 // in the former case.
205 TL_PERS* pers_nc ATLAS_THREAD_SAFE = const_cast<TL_PERS*>(pers);
206 setPStorage( pers_nc );
207 m_mainConverter.pstoreToTrans (0, trans, msg);
208 }
209
210 virtual void transToPers(const TRANS* trans, PERS* pers, MsgStream& msg) {
211 this->setTLPersObject( pers );
212 m_mainConverter.virt_toPersistent(trans, msg);
213 this->clearTLPersObject();
214 }
215
216protected:
218
219};
220
221#endif
222
This file contains template definitions for Transient/Persistent converters.
Base class template for Top-Level TP converters, specialized with persistent type.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
virtual void clearTLPersObject() override
Discard the persistent object.
virtual void deleteTLPersObject() override
Delete the persistent object owned by the converter.
virtual void createTLPersObject() override
Create persistent object - the converter keeps it.
virtual void setTLPersObject(void *persObj) override
Take ownership of the persistent object.
virtual void addTPConverter(ITPConverter *cnv)
Add a TP converter to this top level converter.
TRANS * createTransient(MsgStream &log)
Create transient representation of the persistent object known to this converter.
virtual TRANS * createTransient(const TL_PERS *persObj, MsgStream &log)
Create transient representation of persObj.
virtual const std::type_info & persistentTInfo() const override
return C++ type id of the persistent class this converter is for
TRANS * createTransientWithKey(const std::string &key, MsgStream &log)
Create transient representation of the persistent object known to this converter.
virtual void persToTrans(const PERS *pers, TRANS *trans, MsgStream &msg)
virtual const std::type_info & transientTInfo() const override
return C++ type id of the transient class this converter is for
virtual TL_PERS * createPersistent(const TRANS *transObj, MsgStream &log)
Create persistent representation of transObj.
TopLevelTPConverter()
Constructor.
virtual void persToTransWithKeyUntyped(const void *pers, void *trans, const std::string &, MsgStream &log) override
Convert persistent object representation to transient.
virtual void transToPers(const TRANS *trans, PERS *pers, MsgStream &msg)
void setMainCnvPStorage(STORAGE *storage)
Set the persistent storage space for the main TP converter.
virtual void transToPersUntyped(const void *trans, void *pers, MsgStream &log) override
Convert transient object representation to persistent.
MAIN_CNV::Trans_t TRANS
virtual void persToTransUntyped(const void *pers, void *trans, MsgStream &log) override
Convert persistent object representation to transient.
void addMainTPConverter()
Add the main TP converter to the internal list - should be called from user-defined constructor.
virtual void transToPersWithKeyUntyped(const void *trans, void *pers, const std::string &, MsgStream &log) override
Convert transient object representation to persistent.
virtual unsigned short getConverterID() override
Returns this converter's ID.
virtual TL_PERS * createPersistentWithKey(const TRANS *transObj, const std::string &key, MsgStream &log)
Create persistent representation of transObj.
virtual void setPStorage(TL_PERS *persObj) override=0
A stub for a method that should be provided by the converter creator.
MsgStream & msg
Definition testRead.cxx:32