ATLAS Offline Software
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 
13 #include "TopLevelTPCnvBaseP.h"
14 #include "TPConverter.h"
16 
17 
31 template< class MAIN_CNV, class TL_PERS >
33  : public TopLevelTPCnvBaseP< TL_PERS >
34  , public ITPCnvBase
35 {
36 public:
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 
216 protected:
217  MAIN_CNV m_mainConverter;
218 
219 };
220 
221 #endif
222 
TopLevelTPConverter::setPStorage
virtual void setPStorage(TL_PERS *persObj) override=0
A stub for a method that should be provided by the converter creator.
TopLevelTPConverter::PERS
TL_PERS PERS
Definition: TopLevelTPConverter.h:38
TPConverter.h
This file contains template definitions for Transient/Persistent converters.
TopLevelTPConverter::persToTransWithKeyUntyped
virtual void persToTransWithKeyUntyped(const void *pers, void *trans, const std::string &, MsgStream &log) override
Convert persistent object representation to transient.
Definition: TopLevelTPConverter.h:183
TopLevelTPConverter::createTransientWithKey
TRANS * createTransientWithKey(const std::string &key, MsgStream &log)
Create transient representation of the persistent object known to this converter.
Definition: TopLevelTPConverter.h:78
TopLevelTPCnvBaseP
Definition: TopLevelTPCnvBaseP.h:27
TopLevelTPConverter::createPersistentWithKey
virtual TL_PERS * createPersistentWithKey(const TRANS *transObj, const std::string &key, MsgStream &log)
Create persistent representation of transObj.
Definition: TopLevelTPConverter.h:129
TopLevelTPConverter::addMainTPConverter
void addMainTPConverter()
Add the main TP converter to the internal list - should be called from user-defined constructor.
Definition: TopLevelTPConverter.h:146
TopLevelTPConverter::TRANS
MAIN_CNV::Trans_t TRANS
Definition: TopLevelTPConverter.h:37
TopLevelTPConverter::persToTransUntyped
virtual void persToTransUntyped(const void *pers, void *trans, MsgStream &log) override
Convert persistent object representation to transient.
Definition: TopLevelTPConverter.h:173
TopLevelTPCnvBaseP::getTLPersObject
TL_PERS * getTLPersObject()
Definition: TopLevelTPCnvBaseP.h:72
TopLevelTPCnvBase::addTPConverter
virtual void addTPConverter(ITPConverter *cnv)
Add a TP converter to this top level converter.
Definition: TopLevelTPCnvBase.cxx:11
TopLevelTPCnvBaseP.h
Base class template for Top-Level TP converters, specialized with persistent type.
TopLevelTPConverter::createTransient
TRANS * createTransient(MsgStream &log)
Create transient representation of the persistent object known to this converter.
Definition: TopLevelTPConverter.h:62
TopLevelTPCnvBaseP::deleteTLPersObject
virtual void deleteTLPersObject() override
Delete the persistent object owned by the converter.
Definition: TopLevelTPCnvBaseP.h:64
TopLevelTPCnvBaseP::clearTLPersObject
virtual void clearTLPersObject() override
Discard the persistent object.
Definition: TopLevelTPCnvBaseP.h:99
TopLevelTPConverter::m_mainConverter
MAIN_CNV m_mainConverter
Definition: TopLevelTPConverter.h:217
TopLevelTPConverter::persToTrans
virtual void persToTrans(const PERS *pers, TRANS *trans, MsgStream &msg)
Definition: TopLevelTPConverter.h:201
TopLevelTPConverter::getConverterID
virtual unsigned short getConverterID() override
Returns this converter's ID.
Definition: TopLevelTPConverter.h:159
TopLevelTPConverter::transToPersWithKeyUntyped
virtual void transToPersWithKeyUntyped(const void *trans, void *pers, const std::string &, MsgStream &log) override
Convert transient object representation to persistent.
Definition: TopLevelTPConverter.h:192
TopLevelTPConverter::createTransient
virtual TRANS * createTransient(const TL_PERS *persObj, MsgStream &log)
Create transient representation of persObj.
Definition: TopLevelTPConverter.h:96
TopLevelTPConverter::transientTInfo
virtual const std::type_info & transientTInfo() const override
return C++ type id of the transient class this converter is for
Definition: TopLevelTPConverter.h:166
TopLevelTPConverter::transToPersUntyped
virtual void transToPersUntyped(const void *trans, void *pers, MsgStream &log) override
Convert transient object representation to persistent.
Definition: TopLevelTPConverter.h:178
TopLevelTPConverter::TopLevelTPConverter
TopLevelTPConverter()
Constructor.
Definition: TopLevelTPConverter.h:50
TopLevelTPConverter::persistentTInfo
virtual const std::type_info & persistentTInfo() const override
return C++ type id of the persistent class this converter is for
Definition: TopLevelTPConverter.h:169
ITPCnvBase
Definition: ITPCnvBase.h:24
TopLevelTPCnvBaseP::setTLPersObject
virtual void setTLPersObject(void *persObj) override
Take ownership of the persistent object.
Definition: TopLevelTPCnvBaseP.h:104
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TopLevelTPConverter::createPersistent
virtual TL_PERS * createPersistent(const TRANS *transObj, MsgStream &log)
Create persistent representation of transObj.
Definition: TopLevelTPConverter.h:110
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
TopLevelTPConverter::transToPers
virtual void transToPers(const TRANS *trans, PERS *pers, MsgStream &msg)
Definition: TopLevelTPConverter.h:210
TopLevelTPConverter::setMainCnvPStorage
void setMainCnvPStorage(STORAGE *storage)
Set the persistent storage space for the main TP converter.
Definition: TopLevelTPConverter.h:152
checker_macros.h
Define macros for attributes used to control the static checker.
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TopLevelTPCnvBaseP::createTLPersObject
virtual void createTLPersObject() override
Create persistent object - the converter keeps it.
Definition: TopLevelTPCnvBaseP.h:57
TopLevelTPConverter
Definition: TopLevelTPConverter.h:35
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37