diff --git a/Reconstruction/tauRec/src/TauRunnerAlg.cxx b/Reconstruction/tauRec/src/TauRunnerAlg.cxx index a737a50596da04f61758d41ba2196ac8f3e3dbf8..f19d80896b05d529c46d7aba1add9be2fdbb8ffe 100644 --- a/Reconstruction/tauRec/src/TauRunnerAlg.cxx +++ b/Reconstruction/tauRec/src/TauRunnerAlg.cxx @@ -64,7 +64,6 @@ StatusCode TauRunnerAlg::initialize() { ATH_CHECK( m_hadronicPFOOutputContainer.initialize() ); ATH_CHECK( m_vertexOutputContainer.initialize() ); ATH_CHECK( m_chargedPFOOutputContainer.initialize() ); - ATH_CHECK( m_pi0Container.initialize() ); //------------------------------------------------------------------------- // Allocate tools @@ -169,14 +168,6 @@ StatusCode TauRunnerAlg::execute() { SG::WriteHandle<xAOD::PFOContainer> chargedPFOHandle( m_chargedPFOOutputContainer ); ATH_MSG_DEBUG(" write: " << chargedPFOHandle.key() << " = " << "..." ); ATH_CHECK(chargedPFOHandle.record(std::unique_ptr<xAOD::PFOContainer>{chargedPFOContainer}, std::unique_ptr<xAOD::PFOAuxContainer>{chargedPFOAuxStore})); - - // write pi0 container - xAOD::ParticleContainer* pi0Container = new xAOD::ParticleContainer(); - xAOD::ParticleAuxContainer* pi0AuxStore = new xAOD::ParticleAuxContainer(); - pi0Container->setStore(pi0AuxStore); - SG::WriteHandle<xAOD::ParticleContainer> pi0Handle( m_pi0Container ); - ATH_MSG_DEBUG(" write: " << pi0Handle.key() << " = " << "..." ); - ATH_CHECK(pi0Handle.record(std::unique_ptr<xAOD::ParticleContainer>{pi0Container}, std::unique_ptr<xAOD::ParticleAuxContainer>{pi0AuxStore})); //------------------------------------------------------------------------- // Initialize tools for this event @@ -200,16 +191,20 @@ StatusCode TauRunnerAlg::execute() { } pTauContainer = tauInputHandle.cptr(); - // create shallow copy, write that - std::pair< xAOD::TauJetContainer*, xAOD::ShallowAuxContainer* > taus_shallowCopy = xAOD::shallowCopyContainer( *pTauContainer ); - + // Make new container which is deep copy of that + xAOD::TauJetContainer* newTauCon = 0; + xAOD::TauJetAuxContainer* newTauAuxCon = 0; + xAOD::TauJet* tau(0); + // See function in header file + ATH_CHECK(deepCopy(newTauCon, newTauAuxCon, tau, pTauContainer)); + // Write final taujets container SG::WriteHandle<xAOD::TauJetContainer> outputTauHandle(m_tauOutputContainer); - ATH_CHECK( outputTauHandle.record(std::unique_ptr<xAOD::TauJetContainer>(taus_shallowCopy.first), - std::unique_ptr<xAOD::ShallowAuxContainer>(taus_shallowCopy.second)) ); + ATH_CHECK( outputTauHandle.record(std::unique_ptr<xAOD::TauJetContainer>(newTauCon), + std::unique_ptr<xAOD::TauJetAuxContainer>(newTauAuxCon)) ); - // iterate over the shallow copy - xAOD::TauJetContainer::iterator itTau = (taus_shallowCopy.first)->begin(); - xAOD::TauJetContainer::iterator itTauE = (taus_shallowCopy.first)->end(); + // iterate over the copy + xAOD::TauJetContainer::iterator itTau = newTauCon->begin(); + xAOD::TauJetContainer::iterator itTauE = newTauCon->end(); for (; itTau != itTauE; ++itTau) { xAOD::TauJet* pTau = (*itTau); diff --git a/Reconstruction/tauRec/tauRec/TauRunnerAlg.h b/Reconstruction/tauRec/tauRec/TauRunnerAlg.h index 6633f69ccaac93824c89aacd7c1f58f42bda2d9a..b9b05983fc5194a59cf46e71e29a6eb4bc1d5375 100644 --- a/Reconstruction/tauRec/tauRec/TauRunnerAlg.h +++ b/Reconstruction/tauRec/tauRec/TauRunnerAlg.h @@ -24,9 +24,6 @@ #include "xAODTracking/VertexContainer.h" #include "xAODTracking/VertexAuxContainer.h" -#include "xAODParticleEvent/ParticleContainer.h" -#include "xAODParticleEvent/ParticleAuxContainer.h" - /** * @brief Main class for tau candidate processing. */ @@ -48,7 +45,10 @@ class TauRunnerAlg: public AthAlgorithm virtual StatusCode execute(); virtual StatusCode finalize(); - private: + // template for deep copy function + template<class T, class U, class V> StatusCode deepCopy(T*& containerOut, U*& containerStoreOut, const V* dummyContainerType, + const T*& oldContainer); + private: ToolHandleArray<ITauToolBase> m_tools; @@ -63,9 +63,33 @@ class TauRunnerAlg: public AthAlgorithm SG::WriteHandleKey<xAOD::PFOContainer> m_hadronicPFOOutputContainer{this,"Key_hadronicPFOOutputContainer", "TauHadronicParticleFlowObjects", "tau hadronic pfo out key"}; SG::WriteHandleKey<xAOD::VertexContainer> m_vertexOutputContainer{this,"Key_vertexOutputContainer", "TauSecondaryVertices", "input vertex container key"}; SG::WriteHandleKey<xAOD::PFOContainer> m_chargedPFOOutputContainer{this,"Key_chargedPFOOutputContainer", "TauChargedParticleFlowObjects", "tau charged pfo out key"}; - SG::WriteHandleKey<xAOD::ParticleContainer> m_pi0Container{this,"Key_pi0Container", "finalTauPi0s", "tau final pi0s output"}; }; +// Function to perform deep copy on container +template<class T, class U, class V> StatusCode TauRunnerAlg::deepCopy(T*& container, U*& containerStore, const V* /*dummyContainerElementType*/, + const T*& oldContainer){ + + // The new container should be null, check here + if(container==0 && containerStore==0){ + container = new T(); + containerStore = new U(); + container->setStore(containerStore); + } + else{ + ATH_MSG_FATAL("Proviced non-null containters, not initializing please provide null containers: "); + return StatusCode::FAILURE; + } + for( const V* v : *oldContainer ){ + V* newV = new V(); + // Put objects into new container + container->push_back(newV); + // Copy across aux store + *newV = *v; + } + + return StatusCode::SUCCESS; +} + #endif // TAUREC_TAURUNNERALG_H