Skip to content
Snippets Groups Projects
Commit e11fe12a authored by Emily Anne Thompson's avatar Emily Anne Thompson
Browse files

Migrate RpvMuonD0Tool to use DataHandles

parent 5cb48d35
No related branches found
No related tags found
6 merge requests!58791DataQualityConfigurations: Modify L1Calo config for web display,!46784MuonCondInterface: Enable thread-safety checking.,!46776Updated LArMonitoring config file for WD to match new files produced using MT,!45405updated ART test cron job,!42417Draft: DIRE and VINCIA Base Fragments for Pythia 8.3,!39666Migrate LongLivedParticleDPDMaker to R22
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
// DerivationFramework includes // DerivationFramework includes
#include "DerivationFrameworkInterfaces/IAugmentationTool.h" #include "DerivationFrameworkInterfaces/IAugmentationTool.h"
#include "xAODMuon/MuonContainer.h"
#include "StoreGate/ReadHandleKey.h"
namespace DerivationFramework { namespace DerivationFramework {
...@@ -43,7 +45,7 @@ namespace DerivationFramework { ...@@ -43,7 +45,7 @@ namespace DerivationFramework {
virtual StatusCode addBranches() const; virtual StatusCode addBranches() const;
private: private:
std::string m_collName; SG::ReadHandleKey<xAOD::MuonContainer> m_collName { this, "MuonContainerKey", "Muons", ""};
std::string m_sgPrefix; std::string m_sgPrefix;
}; };
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
// Writes result to SG for later selection by string parser // Writes result to SG for later selection by string parser
#include "LongLivedParticleDPDMaker/RpvMuonD0Tool.h" #include "LongLivedParticleDPDMaker/RpvMuonD0Tool.h"
#include "xAODMuon/MuonContainer.h"
#include <vector> #include <vector>
#include <string> #include <string>
...@@ -19,11 +18,9 @@ DerivationFramework::RpvMuonD0Tool::RpvMuonD0Tool( const std::string& t, ...@@ -19,11 +18,9 @@ DerivationFramework::RpvMuonD0Tool::RpvMuonD0Tool( const std::string& t,
const std::string& n, const std::string& n,
const IInterface* p ) : const IInterface* p ) :
AthAlgTool(t,n,p), AthAlgTool(t,n,p),
m_collName("Muons"),
m_sgPrefix("") m_sgPrefix("")
{ {
declareInterface<DerivationFramework::IAugmentationTool>(this); declareInterface<DerivationFramework::IAugmentationTool>(this);
declareProperty("CollectionName", m_collName);
declareProperty("SGPrefix", m_sgPrefix); declareProperty("SGPrefix", m_sgPrefix);
} }
...@@ -35,6 +32,7 @@ DerivationFramework::RpvMuonD0Tool::~RpvMuonD0Tool() { ...@@ -35,6 +32,7 @@ DerivationFramework::RpvMuonD0Tool::~RpvMuonD0Tool() {
StatusCode DerivationFramework::RpvMuonD0Tool::initialize() StatusCode DerivationFramework::RpvMuonD0Tool::initialize()
{ {
ATH_MSG_VERBOSE("initialize() ..."); ATH_MSG_VERBOSE("initialize() ...");
ATH_CHECK(m_collName.initialize());
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
StatusCode DerivationFramework::RpvMuonD0Tool::finalize() StatusCode DerivationFramework::RpvMuonD0Tool::finalize()
...@@ -48,15 +46,22 @@ StatusCode DerivationFramework::RpvMuonD0Tool::addBranches() const ...@@ -48,15 +46,22 @@ StatusCode DerivationFramework::RpvMuonD0Tool::addBranches() const
{ {
// Retrieve data // Retrieve data
const xAOD::MuonContainer* muons = evtStore()->retrieve< const xAOD::MuonContainer >( m_collName ); SG::ReadHandle<xAOD::MuonContainer> muons(m_collName);
if( ! muons ) { if( !muons.isValid() ) {
ATH_MSG_ERROR("Couldn't retrieve muon container with key: " << m_collName); ATH_MSG_ERROR("Couldn't retrieve muon container with key: " << m_collName);
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
// Make a vector for the cut results // Make a vector for the cut results
std::vector<float>* d0vec = new std::vector<float>(); // Write decision to SG for access by downstream algs
std::vector<int>* isCombinedVec = new std::vector<int>(); std::string sgKeyd0(m_sgPrefix+"D0");
SG::WriteHandle< std::vector<float> > d0vec(sgKeyd0);
ATH_CHECK(d0vec.record(std::make_unique< std::vector<float> >()));
std::string sgKeycomb(m_sgPrefix+"isCombined");
SG::WriteHandle< std::vector<int> > isCombinedVec(sgKeycomb);
ATH_CHECK(isCombinedVec.record(std::make_unique< std::vector<int> >()));
// Loop over muons, set decisions // Loop over muons, set decisions
for (xAOD::MuonContainer::const_iterator muIt = muons->begin(); muIt!=muons->end(); ++muIt) { for (xAOD::MuonContainer::const_iterator muIt = muons->begin(); muIt!=muons->end(); ++muIt) {
...@@ -86,27 +91,6 @@ StatusCode DerivationFramework::RpvMuonD0Tool::addBranches() const ...@@ -86,27 +91,6 @@ StatusCode DerivationFramework::RpvMuonD0Tool::addBranches() const
} }
} }
// Write decision to SG for access by downstream algs
std::string sgKey(m_sgPrefix+"D0");
if (evtStore()->contains<std::vector<float> >(sgKey)) {
ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << sgKey << " which already exists. Please use a different key");
// avoid mem leak
delete d0vec;
delete isCombinedVec;
return StatusCode::FAILURE;
}
CHECK(evtStore()->record(d0vec, sgKey));
sgKey = m_sgPrefix+"isCombined";
if (evtStore()->contains<std::vector<int> >(sgKey)) {
ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << sgKey << " which already exists. Please use a different key");
delete isCombinedVec; // avoid mem leak
return StatusCode::FAILURE;
}
CHECK(evtStore()->record(isCombinedVec, sgKey));
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment