ATLAS Offline Software
TopLevelTPCnvBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 
8 #include <stdexcept>
9 
10 
12 {
13  addTPConverterForWriting( converter );
14  addTPConverterForReading( converter );
15 }
16 
17 
18 
20 {
21  // for reading, converters are selected based on their typeID value
22  // which comes from the Ref
23  // Ref contains top level converter ID + local type ID
25  m_convIdMap[ full_typeID.value() ] = converter;
26 
27 // std::cout << " **addTPConverter - adding converter for " << converter->transientTInfo().name() << " CnvID=" << full_typeID.value() << std::endl;
28  converter->setTopConverter( this, full_typeID );
29 }
30 
31 
32 
34 {
35  // add converter to the map keyed by type_info
36  // this map is used to find a converter when writing
37  const std::type_info &info( converter->transientTInfo() );
39  // adding a second converter for the same type will mess up things
40  const std::string error("Duplicate TP converter for class ");
41  throw std::runtime_error( error + info.name() );
42  }
43  m_converters.addConverter( converter, info );
44 }
45 
46 
48 {
49  // for reading, converters are selected based on our own typeID value
50  // which comes from the Ref
51  // Ref contains top level converter ID + local type ID
52  m_convIdMap[ converter->typeID().value() ] = converter;
53 
54 // std::cout << " **addExtTPConverterForReading - adding converter for " << converter->transientTInfo().name() << " CnvID=" << converter->typeID().value() << std::endl;
55  converter->setRuntimeTopConverter( this );
56 }
57 
58 
61 {
62  // loop over all registered converters
63  for( convIdMap_t::const_iterator itr = m_convIdMap.begin();
64  itr != m_convIdMap.end(); ++itr ) {
65  // check if the converter is in the list of R/W converters
66  if( m_converters.findConverter( itr->second->transientTInfo() ) == itr->second ) {
67  // this is a R/W converter, add it for writing too
68  cnv->addTPConverterForWriting( itr->second );
69  }
70  // add the convterter for reading
71  cnv->addExtTPConverterForReading( itr->second );
72  }
73  // prevent adding of the same converter again
74  cnv->rememberConverter( this );
75 }
76 
77 
79 {
80  // check if we have done this already, and if so then exit
81  if( cnv->hasConvertersFrom( this ) ) {
82  return;
83  }
84  // copy all TP converters to another topLevel conveter
85  for( convIdMap_t::const_iterator itr = m_convIdMap.begin();
86  itr != m_convIdMap.end(); ++itr ) {
87  cnv->addExtTPConverterForReading( itr->second );
88  }
89  // prevent attempts to add the same converters again
90  cnv->rememberConverter( this );
91 }
92 
93 
grepfile.info
info
Definition: grepfile.py:38
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.
TopLevelTPCnvBase::addExtTPConverterForReading
virtual void addExtTPConverterForReading(ITPConverter *cnv)
add extending TP converter to this top level converter - to the list consulted when reading only.
Definition: TopLevelTPCnvBase.cxx:47
TopLevelTPCnvBase::getConverterID
virtual unsigned short getConverterID()=0
TopLevelTPCnvBase::addTPConvertersForReadingTo
virtual void addTPConvertersForReadingTo(TopLevelTPCnvBase *dest)
copy all extending converters from this top level converter to "dest" top level converter - for readi...
Definition: TopLevelTPCnvBase.cxx:78
TPObjRef::typeID_t::value
unsigned value() const
Returns the type ID as an integer.
Definition: TPObjRef.h:46
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...
TopLevelTPCnvBase::hasConvertersFrom
bool hasConvertersFrom(TopLevelTPCnvBase *cnv)
Check if TP converters from a given top-level converter were already registered in this converter.
Definition: TopLevelTPCnvBase.h:166
TopLevelTPCnvBase::rememberConverter
void rememberConverter(TopLevelTPCnvBase *cnv)
Remember that elemental TP converters from the given top-level converter are already registered.
Definition: TopLevelTPCnvBase.h:156
ITPCnvBase::transientTInfo
virtual const std::type_info & transientTInfo() const =0
return C++ type id of the transient class this converter is for
TopLevelTPCnvBase::addTPConverter
virtual void addTPConverter(ITPConverter *cnv)
Add a TP converter to this top level converter.
Definition: TopLevelTPCnvBase.cxx:11
TopLevelTPCnvBase::addTPConverterForReading
virtual void addTPConverterForReading(ITPConverter *cnv)
Add a TP converter to this top level converter but only for reading.
Definition: TopLevelTPCnvBase.cxx:19
TopLevelTPCnvBase::m_typeIDCount
unsigned m_typeIDCount
Counter used to create typed IDs used in the transient Ref.
Definition: TopLevelTPCnvBase.h:187
TopLevelTPCnvBase::addTPConvertersTo
virtual void addTPConvertersTo(TopLevelTPCnvBase *dest)
copy all extending converters from this top level converter to "dest" top level converter
Definition: TopLevelTPCnvBase.cxx:60
TopLevelTPCnvBase::m_converters
TPConverterTypeMap< ITPConverter > m_converters
Map of elemental TP converters indexed by transient typeid - used for writing.
Definition: TopLevelTPCnvBase.h:180
TopLevelTPCnvBase
Base class for top-level TP converters.
Definition: TopLevelTPCnvBase.h:32
TopLevelTPCnvBase::m_convIdMap
convIdMap_t m_convIdMap
Map of elemental TP converters indexed by their ID - used for reading.
Definition: TopLevelTPCnvBase.h:177
TopLevelTPCnvBase::addTPConverterForWriting
virtual void addTPConverterForWriting(ITPConverter *cnv)
add TP converter to the list of converters consulted when writing - internal method.
Definition: TopLevelTPCnvBase.cxx:33
TopLevelTPCnvBase.h
Defines the base class for top-level TP converters.
TPObjRef::typeID_t
Definition: TPObjRef.h:31
ITPConverter
Definition: TPTools/TPTools/ITPConverter.h:32
get_generator_info.error
error
Definition: get_generator_info.py:40
error
Definition: IImpactPoint3dEstimator.h:70
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
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...