ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaConverterTLPExtension.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
10
15
16#include <stdexcept>
17#include <sstream>
18#include <iostream>
19using namespace std;
20
21
22unsigned short
26
27
29{
30 // check if all converter IDs are unique
31 int extendingTPLCnvID = extending_converter->getTPCnvID();
32 if( extendingTPLCnvID == this->getTPCnvID()
33 || m_extendingConverters.find( extendingTPLCnvID ) != m_extendingConverters.end() ) {
34 ostringstream error;
35 error << "Conflicting TP converter IDs when registering extending Athena Converter. ID=" << extendingTPLCnvID;
36 throw runtime_error( error.str() );
37 }
38 AthenaConverterTLPExtension *cloned_converter;
39 if( ! extending_converter->needsCloning() ) {
40 cloned_converter = extending_converter;
41 // cout << " TPCNVINFO: TP converter not cloned CLID=" << cnv->name() << endl;
42 } else {
43 // get a private converter copy
44 cloned_converter = extending_converter->clone();
45 if( !cloned_converter ) {
46 ostringstream error;
47 error << "Extending TP converter neeeds to define clone() method. Converter: " << extending_converter->name();
48 throw runtime_error( error.str() );
49 }
50 //cout << " TPCNVINFO: Cloned extending TP converter " << " Converter CLID=" << extending_converter->name() << endl;
51 m_clonedExtendingCnvs.push_back( cloned_converter );
52 }
53 cloned_converter->wasClonedFrom( extending_converter );
54 m_extendingConverters[ extendingTPLCnvID ] = cloned_converter;
55 return true;
56}
57
58
60{
61 usingTPCnvForReading( *reinterpret_cast<TopLevelTPCnvBase*>( cnv ) );
62}
63
64
66{
67 m_TLCnvForReading = &baseTLPcnv;
68
70 // we are reading an old class version
71 if( m_extendingConverters.size()
72 && m_extCnvMapMap.find( m_TLCnvForReading ) == m_extCnvMapMap.end() ) {
73 // it is first time we use this TLP converter (for the old version)
74 extCnvMap_t *newCnvMap = new extCnvMap_t;
75 m_extCnvMapMap[ m_TLCnvForReading ] = newCnvMap;
76
77 // copy clones of all extending converters to a new converter map
78 for( extCnvMap_t::const_iterator cnvI = m_extendingConverters.begin();
79 cnvI != m_extendingConverters.end(); ++cnvI ) {
80 AthenaConverterTLPExtension *cloned_converter = cnvI->second->clone();
81 if( !cloned_converter ) {
82 // basically panicking, this is not a runtime exception but an incomplete converter implementation
83 ostringstream error;
84 error << " TPCNVINFO: ERROR! This extending TP converter does not define clone() method. "
85 << " Converter: " << cnvI->second->name();
86 cerr << error.str() << endl;
87 throw runtime_error( error.str() );
88 }
89 m_clonedExtendingCnvs.push_back( cloned_converter );
90 cloned_converter->wasClonedFrom( cnvI->second );
91 (*newCnvMap)[ cloned_converter->getTPCnvID() ] = cloned_converter;
92 // this would be only necessary for writing, but we don't write old versions
93 //cloned_converter->getTopLevelTPCnv()->addTPConvertersTo( this->getTopLevelTPCnv() );
94 }
95 }
96 }
97}
98
100{
101 // m_TLCnvForReading may be 0 if reading pre-TP object
102 if( m_TLCnvForReading ) {
103 TPCnvTokenList_p1 *tokens = m_TLCnvForReading->getTokenListVarFrom( baseObj );
104 if( tokens && tokens->size() ) {
105 // find which extending converter "set" to use
106 extCnvMap_t *extendingConverters;
108 // use the newest TP converters
109 extendingConverters = &m_extendingConverters;
110 } else {
111 extCnvMapMap_t::const_iterator extCnvMapIter = m_extCnvMapMap.find(m_TLCnvForReading);
112 if( extCnvMapIter == m_extCnvMapMap.end() ) {
113 throw std::runtime_error("Extending TP converter not available");
114 }
115 extendingConverters = extCnvMapIter->second;
116 }
117 // load the remaining "pieces" of this object
118 for( TPCnvTokenList_p1::const_iterator it = tokens->begin(); it != tokens->end(); ++it ) {
119 if( it->token().size() < 36 ) {
120 ostringstream err;
121 err << "Corrupted Token in the list of extensions. Token='" << it->token() << "'"
122 << " CnvID=" << it->converterID() << ", Token list size=" << tokens->size();
123 throw std::runtime_error(err.str());
124 }
125 extCnvMap_t::const_iterator cnv = extendingConverters->find( it->converterID() );
126 if( cnv == extendingConverters->end() ) {
127 ostringstream err;
128 err << "Extending TP converter not loaded! "
129 << "missing ExtCnvID=" << it->converterID()
130 << " corresponding POOL token: " << it->token();
131 throw std::runtime_error(err.str());
132 }
133// std::cout << "--->>--- readExtendingObjects: "
134// << " converter ID=" << it->converterID()
135// << " token=" << it->token() << ", AP converter=" << cnv->second << std::endl;
136
137 cnv->second->readObject( it->token() );
138 TopLevelTPCnvBase *extTPCnv = cnv->second->getTopLevelTPCnvForReading();
140 }
141 }
142 }
143}
144
145
146
147
149{
150 for( extCnvMap_t::const_iterator cnv = m_extendingConverters.begin();
151 cnv != m_extendingConverters.end(); ++cnv ) {
152 cnv->second->deletePersistentObjects();
153 }
154 for( size_t c = 0; c < m_clonedExtendingCnvs.size(); c++ )
156
158 // Can not do that - sometimes the converter is an automatic variable that is gone already
159 //if( m_TLCnvForReading ) m_TLCnvForReading->deleteTLPersObject();
160}
161
162
163
165{
166 // cout << "Deleting " << m_clonedExtendingCnvs.size() << " extending converters" << endl;
167 for( size_t c = 0; c < m_clonedExtendingCnvs.size(); c++ )
168 delete m_clonedExtendingCnvs[c];
169 for( extCnvMapMap_t::const_iterator mmiter = m_extCnvMapMap.begin();
170 mmiter != m_extCnvMapMap.end(); ++mmiter ) {
171 delete mmiter->second;
172 }
173
174}
Extensions to AthenaConverters used to implement TP separation.
This file contains the class definition for the Token class (migrated from POOL).
Defines the base class for top-level TP converters.
virtual const std::string name() const
Get name of this converter (anything that identifies it)
virtual void readExtendingObjects(void *baseObj)
Read all component persistent objects.
std::vector< AthenaConverterTLPExtension * > m_clonedExtendingCnvs
list of duplicated converters to delete at the end held in the original converter
virtual AthenaConverterTLPExtension * clone()
Clone this Athena Converter.
virtual void wasClonedFrom(AthenaConverterTLPExtension *)
Remember the original converter that this one was cloned from.
void usingTPCnvForReading(TopLevelTPCnvBase &cnv)
Sets top-level TP converter to be used for reading the next object.
virtual TopLevelTPCnvBase * getTopLevelTPCnv()=0
returns the main top-level TP converter
virtual bool registerExtendingCnv(AthenaConverterTLPExtension *cnv)
Register extending converter (that is, another converter that will extent this converter) and all his...
TopLevelTPCnvBase * m_TLCnvForReading
additional Top Level TP converter used only for reading tells which converter is used in case of read...
extCnvMap_t m_extendingConverters
map of Athena converters extending this one
virtual void deletePersistentObjects()
Delete persistent objects held by attached extending converters (used mainly in case of abort)
virtual bool needsCloning() const
Find out if this converter needs to be cloned Returns true if this converter was already registered o...
unsigned short getTPCnvID()
Returns the ID of the main top-level TP converter.
std::map< unsigned, AthenaConverterTLPExtension * > extCnvMap_t
vector of TPCnvToken_p1 Each top-level persistent object that has extentions needs a data member of t...
Base class for top-level TP converters.
virtual void addTPConvertersForReadingTo(TopLevelTPCnvBase *dest)
copy all extending converters from this top level converter to "dest" top level converter - for readi...
virtual unsigned short getConverterID()=0
virtual void deleteTLPersObject()=0
Delete the persistent object owned by the converter.
STL namespace.