ATLAS Offline Software
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 
15 
16 #include <stdexcept>
17 #include <sstream>
18 #include <iostream>
19 using namespace std;
20 
21 
22 unsigned short
24  return getTopLevelTPCnv()->getConverterID();
25 }
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 
69  if( getTopLevelTPCnv() != m_TLCnvForReading ) {
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;
107  if( getTopLevelTPCnv() == m_TLCnvForReading ) {
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();
139  extTPCnv->addTPConvertersForReadingTo( m_TLCnvForReading );
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++ )
155  m_clonedExtendingCnvs[c]->deletePersistentObjects();
156 
157  getTopLevelTPCnv()->deleteTLPersObject();
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 }
TPCnvTokenList_p1
Definition: TPCnvTokenList_p1.h:55
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
skel.it
it
Definition: skel.GENtoEVGEN.py:423
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
AthenaConverterTLPExtension.h
Extensions to AthenaConverters used to implement TP separation.
AthenaConverterTLPExtension::needsCloning
virtual bool needsCloning() const
Find out if this converter needs to be cloned Returns true if this converter was already registered o...
Definition: AthenaConverterTLPExtension.h:80
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
AthenaConverterTLPExtension::readExtendingObjects
virtual void readExtendingObjects(void *baseObj)
Read all component persistent objects.
Definition: AthenaConverterTLPExtension.cxx:99
AthenaConverterTLPExtension
This class is used to add functionality to a standard AthenaConverter.
Definition: AthenaConverterTLPExtension.h:43
TopLevelTPCnvBase
Base class for top-level TP converters.
Definition: TopLevelTPCnvBase.h:32
AthenaConverterTLPExtension::extCnvMap_t
std::map< unsigned, AthenaConverterTLPExtension * > extCnvMap_t
Definition: AthenaConverterTLPExtension.h:133
AthenaConverterTLPExtension::name
virtual const std::string name() const
Get name of this converter (anything that identifies it)
Definition: AthenaConverterTLPExtension.h:85
AthenaConverterTLPExtension::clone
virtual AthenaConverterTLPExtension * clone()
Clone this Athena Converter.
Definition: AthenaConverterTLPExtension.h:70
AthenaConverterTLPExtension::~AthenaConverterTLPExtension
virtual ~AthenaConverterTLPExtension()
Destructor.
Definition: AthenaConverterTLPExtension.cxx:164
TopLevelTPCnvBase.h
Defines the base class for top-level TP converters.
AthenaConverterTLPExtension::wasClonedFrom
virtual void wasClonedFrom(AthenaConverterTLPExtension *)
Remember the original converter that this one was cloned from.
Definition: AthenaConverterTLPExtension.h:75
TPCnvTokenList_p1.h
AthenaConverterTLPExtension::getTPCnvID
unsigned short getTPCnvID()
Returns the ID of the main top-level TP converter.
Definition: AthenaConverterTLPExtension.cxx:23
AthenaConverterTLPExtension::deletePersistentObjects
virtual void deletePersistentObjects()
Delete persistent objects held by attached extending converters (used mainly in case of abort)
Definition: AthenaConverterTLPExtension.cxx:148
get_generator_info.error
error
Definition: get_generator_info.py:40
Token.h
This file contains the class definition for the Token class (migrated from POOL).
error
Definition: IImpactPoint3dEstimator.h:70
python.compressB64.c
def c
Definition: compressB64.py:93
AthenaConverterTLPExtension::usingTPCnvForReading
void usingTPCnvForReading(TopLevelTPCnvBase &cnv)
Sets top-level TP converter to be used for reading the next object.
Definition: AthenaConverterTLPExtension.cxx:65
AthenaConverterTLPExtension::registerExtendingCnv
virtual bool registerExtendingCnv(AthenaConverterTLPExtension *cnv)
Register extending converter (that is, another converter that will extent this converter) and all his...
Definition: AthenaConverterTLPExtension.cxx:28