ATLAS Offline Software
TPTools/TPTools/ITPConverter.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef ATHENAPOOLCNVSVC_ITPConverter_H
8 #define ATHENAPOOLCNVSVC_ITPConverter_H 1
9 
19 
20 #include <typeinfo>
21 #include <typeindex>
22 #include <string>
23 
24 
25 class MsgStream;
26 class TopLevelTPCnvBase;
27 
31 class ITPConverter : public ITPCnvBase
32 {
33 protected:
35 public:
36  virtual ~ITPConverter() = default;
37 
45  const TPObjRef::typeID_t& TPtypeID ) = 0;
46 
53 
57  virtual TopLevelTPCnvBase* topConverter() { return 0; }
58  virtual const TopLevelTPCnvBase* topConverter() const { return 0; }
59 
63  virtual const TPObjRef::typeID_t& typeID() const = 0;
64 
69  virtual const std::type_info& transBaseTInfo() const = 0;
70 
72  virtual void reservePStorage( size_t size ) = 0;
73 
82  virtual void converterNotFound( const std::type_info& converterType,
83  ITPConverter *c,
84  const std::string& typeName,
85  MsgStream& log ) const;
86 
95  virtual void converterNotFound( unsigned typeID,
96  ITPConverter *c,
97  const std::string& typeName,
98  MsgStream& log ) const;
99 };
100 
101 
102 
103 
104 //-------------- TPConverterTypeMap<CONVERTER_BASE> -------------
105 #include <map>
106 
111 template<class CONVERTER_BASE>
113 public:
114  typedef std::map<const std::type_index, CONVERTER_BASE*> TId_Map_t;
115  typedef typename TId_Map_t::iterator iterator;
116 
118 
123  CONVERTER_BASE * findConverter(const std::type_info &objTypeInfo) const;
124 
129  void addConverter(CONVERTER_BASE *converter,
130  const std::type_info &objTypeInfo);
131 
133  iterator begin() { return m_cnvRegistry.begin(); }
134 
136  iterator end() { return m_cnvRegistry.end(); }
137 
138 protected:
140 };
141 
142 
143 
144 
145 
146 template<class CONVERTER_BASE>
147 inline
148 CONVERTER_BASE *
150 ::findConverter(const std::type_info &objTypeInfo) const
151 {
152  typename TId_Map_t::const_iterator iter = m_cnvRegistry.find( std::type_index(objTypeInfo) );
153  return (iter == m_cnvRegistry.end())?
154  0 : iter->second;
155 }
156 
157 
158 template<class CONVERTER_BASE>
159 inline
160 void
162 ::addConverter(CONVERTER_BASE *converter, const std::type_info &objTypeInfo)
163 {
164  m_cnvRegistry[std::type_index(objTypeInfo)] = converter;
165 }
166 
167 
168 
169 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TPConverterTypeMap::findConverter
CONVERTER_BASE * findConverter(const std::type_info &objTypeInfo) const
Find converter for a given C++ type info.
Definition: TPTools/TPTools/ITPConverter.h:150
ITPConverter::typeID
virtual const TPObjRef::typeID_t & typeID() const =0
Return TP typeID for persistent objects produced by this converter.
ITPConverter::transBaseTInfo
virtual const std::type_info & transBaseTInfo() const =0
return C++ type id of the common base transient type for all converters for a group of polymorphic ty...
TPConverterTypeMap::end
iterator end()
Definition: TPTools/TPTools/ITPConverter.h:136
ITPConverter::setRuntimeTopConverter
virtual void setRuntimeTopConverter(TopLevelTPCnvBase *topConverter)=0
Set runtime top-level converter - usually it is the owning TL converter, but in case of extended obje...
ITPConverter::reservePStorage
virtual void reservePStorage(size_t size)=0
Reserve 'size' elements for persistent storage.
ITPCnvBase.h
TPConverterTypeMap::begin
iterator begin()
Definition: TPTools/TPTools/ITPConverter.h:133
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ITPConverter::ITPConverter
ITPConverter()
Definition: TPTools/TPTools/ITPConverter.h:34
TPConverterTypeMap::TId_Map_t
std::map< const std::type_index, CONVERTER_BASE * > TId_Map_t
Definition: TPTools/TPTools/ITPConverter.h:114
ITPConverter::~ITPConverter
virtual ~ITPConverter()=default
ITPConverter::topConverter
virtual const TopLevelTPCnvBase * topConverter() const
Definition: TPTools/TPTools/ITPConverter.h:58
TPConverterTypeMap::m_cnvRegistry
TId_Map_t m_cnvRegistry
map of the converters, indexed by type_index
Definition: TPTools/TPTools/ITPConverter.h:139
TopLevelTPCnvBase
Base class for top-level TP converters.
Definition: TopLevelTPCnvBase.h:32
ITPCnvBase
Definition: ITPCnvBase.h:24
TPObjRef.h
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TPConverterTypeMap::iterator
TId_Map_t::iterator iterator
Definition: TPTools/TPTools/ITPConverter.h:115
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
TPObjRef::typeID_t
Definition: TPObjRef.h:31
ITPConverter
Definition: TPTools/TPTools/ITPConverter.h:32
ITPConverter::converterNotFound
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
Definition: ITPConverter.cxx:22
TPConverterTypeMap::TPConverterTypeMap
TPConverterTypeMap()
Definition: TPTools/TPTools/ITPConverter.h:117
TPConverterTypeMap::addConverter
void addConverter(CONVERTER_BASE *converter, const std::type_info &objTypeInfo)
Add a new converter to the map.
Definition: TPTools/TPTools/ITPConverter.h:162
python.compressB64.c
def c
Definition: compressB64.py:93
ITPConverter::topConverter
virtual TopLevelTPCnvBase * topConverter()
return the top-level converter for this elemental TP converter
Definition: TPTools/TPTools/ITPConverter.h:57
ITPConverter::setTopConverter
virtual void setTopConverter(TopLevelTPCnvBase *topConverter, const TPObjRef::typeID_t &TPtypeID)=0
Set which top-level converter owns this elemental converter, and what TPtypeID was assigned to the pe...
TPConverterTypeMap
class TPConverterTypeMap Converter registry template: a map from type_info to the appropriate convert...
Definition: TPTools/TPTools/ITPConverter.h:112