00001
00002
00003 #ifndef XAODCORE_SHALLOWCOPY_H
00004 #define XAODCORE_SHALLOWCOPY_H
00005
00006
00007 #include <map>
00008 #include <iostream>
00009
00010
00011 #include "CxxUtils/make_unique.h"
00012
00013
00014 #include "AthLinks/DataLink.h"
00015 #include "AthContainersInterfaces/IConstAuxStore.h"
00016
00017
00018 #include "xAODCore/ShallowAuxContainer.h"
00019 #include "xAODCore/ShallowAuxInfo.h"
00020
00021 namespace xAOD {
00022
00032
00033 template< class T >
00034 std::unique_ptr<T> prepareElementForShallowCopy(const T* ) {
00035 return CxxUtils::make_unique<T>();
00036 }
00037
00038
00049 template< class T >
00050 std::pair< T*, ShallowAuxContainer* > shallowCopyContainer( const T& cont ) {
00051
00052
00053 DataLink< SG::IConstAuxStore > link( cont.getConstStore() );
00054 if( ! link.cptr() ) {
00055
00056
00057
00058 std::cout << "xAOD::shallowCopyContainer ERROR Couldn't set up "
00059 << "DataLink to the original container's auxiliary store"
00060 << std::endl;
00061 std::cout << "xAOD::shallowCopyContainer ERROR Are you using the "
00062 << "xAOD::TEvent::kBranchAccess access mode?"
00063 << std::endl;
00064 std::pair< T*, ShallowAuxContainer* > dummy;
00065 return dummy;
00066 }
00067
00068
00069 T* newCont = new T();
00070
00071
00072 newCont->reserve( cont.size() );
00073 for( size_t i = 0; i < cont.size(); ++i ) {
00074 newCont->push_back(prepareElementForShallowCopy(cont[i]));
00075 }
00076
00077
00078 ShallowAuxContainer* aux = new ShallowAuxContainer( link );
00079
00080
00081 newCont->setStore( aux );
00082
00083
00084 return std::make_pair( newCont, aux );
00085 }
00086
00098 template< class T >
00099 std::pair< T*, ShallowAuxInfo* > shallowCopyObject( const T& obj ) {
00100
00101
00102 DataLink< SG::IConstAuxStore > link( obj.getConstStore() );
00103 if( ! link.cptr() ) {
00104
00105
00106
00107 std::cout << "xAOD::shallowCopyObject ERROR Couldn't set up "
00108 << "DataLink to the original object's auxiliary store"
00109 << std::endl;
00110 std::cout << "xAOD::shallowCopyObject ERROR Are you using the "
00111 << "xAOD::TEvent::kBranchAccess access mode?"
00112 << std::endl;
00113 std::pair< T*, ShallowAuxInfo* > dummy;
00114 return dummy;
00115 }
00116
00117
00118 T* newObj = new T();
00119
00120
00121 ShallowAuxInfo* aux = new ShallowAuxInfo( link );
00122
00123
00124 newObj->setStore( aux );
00125
00126
00127 return std::make_pair( newObj, aux );
00128 }
00129
00130 }
00131
00132 #endif // XAODCORE_SHALLOWCOPY_H