Commit 90b99d50 authored by John Derek Chapman's avatar John Derek Chapman Committed by Graeme Stewart
Browse files

cmt/requirements - add use statement for AthenaBaseComps, drop use statement...

cmt/requirements - add use statement for AthenaBaseComps, drop use statement for StoreGate. MCTruthAlgs/TrackRecordFilter.h, src/TrackRecordFilter.cxx - update to AthAlgorithm and initialize m_particleTablemember variable to fix Coverity defect #14703. Tagging as MCTruthAlgs-00-03-09 (MCTruthAlgs-00-03-09)

	* cmt/requirements - add use statement for AthenaBaseComps, drop
	use statement for StoreGate.
	* MCTruthAlgs/TrackRecordFilter.h, src/TrackRecordFilter.cxx -
	update to AthAlgorithm and initialize m_particleTablemember
	variable to fix Coverity defect #14703.
	* tagging as MCTruthAlgs-00-03-09
parent 1c8ae8c1
......@@ -5,8 +5,7 @@
#ifndef MCTRUTHALGS_TRACKRECORDFILTER_H
#define MCTRUTHALGS_TRACKRECORDFILTER_H
#include "GaudiKernel/Algorithm.h"
#include "GaudiKernel/MsgStream.h"
#include "AthenaBaseComps/AthAlgorithm.h"
// particle table
#include "HepPDT/ParticleDataTable.hh"
......@@ -15,24 +14,22 @@
#include <string>
class StoreGateSvc;
class TrackRecordFilter : public Algorithm {
class TrackRecordFilter : public AthAlgorithm {
public:
TrackRecordFilter (const std::string& name, ISvcLocator* pSvcLocator);
virtual ~TrackRecordFilter(){};
TrackRecordFilter (const std::string& name, ISvcLocator* pSvcLocator);
virtual ~TrackRecordFilter(){};
StatusCode initialize();
StatusCode finalize();
StatusCode execute();
StatusCode initialize();
StatusCode finalize();
StatusCode execute();
private:
std::string m_inputName;
std::string m_outputName;
double m_cutOff;
StoreGateSvc* m_storeGate;
const HepPDT::ParticleDataTable* m_pParticleTable;
std::string m_inputName;
std::string m_outputName;
double m_cutOff;
const HepPDT::ParticleDataTable* m_pParticleTable;
};
#endif
......@@ -2,14 +2,14 @@ package MCTruthAlgs
author Davide Costanzo
use AtlasPolicy AtlasPolicy-*
use GaudiInterface GaudiInterface-* External
use HepPDT v* LCG_Interfaces
use AthenaBaseComps AthenaBaseComps-* Control
use GaudiInterface GaudiInterface-* External
use HepPDT v* LCG_Interfaces
private
use AtlasCLHEP AtlasCLHEP-* External
use StoreGate StoreGate-* Control
use TrackRecord TrackRecord-* Simulation/G4Sim
use AtlasCLHEP AtlasCLHEP-* External
use TrackRecord TrackRecord-* Simulation/G4Sim
end_private
......
......@@ -9,17 +9,15 @@
#include "TrackRecord/TrackRecordCollection.h"
// particle prop service
#include "GaudiKernel/IPartPropSvc.h"
#include "GaudiKernel/IPartPropSvc.h"
// Particle data table
#include "HepPDT/ParticleData.hh"
#include "CLHEP/Units/SystemOfUnits.h"
//StoreGate
#include "StoreGate/StoreGateSvc.h"
TrackRecordFilter::TrackRecordFilter(const std::string& name,
ISvcLocator* pSvcLocator): Algorithm(name, pSvcLocator)
ISvcLocator* pSvcLocator):
AthAlgorithm(name, pSvcLocator), m_pParticleTable(0)
{
declareProperty("inputName", m_inputName="MuonEntryLayer");
declareProperty("outputName",m_outputName="MuonEntryLayerFilter");
......@@ -29,84 +27,74 @@ TrackRecordFilter::TrackRecordFilter(const std::string& name,
StatusCode TrackRecordFilter::initialize() {
MsgStream log(msgSvc(), name());
// Get StoreGate service
StatusCode sc = service("StoreGateSvc", m_storeGate);
if (sc.isFailure()) {
log << MSG::FATAL << "StoreGate service not found!" << endreq;
return StatusCode::FAILURE;
}
//FIXME Old syntax
// Get the Particle Properties Service
IPartPropSvc* p_PartPropSvc = 0;
static const bool CREATEIFNOTTHERE(true);
StatusCode PartPropStatus = service("PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
log << MSG::ERROR << " Could not initialize Particle Properties Service" << endreq;
ATH_MSG_ERROR ( " Could not initialize Particle Properties Service" );
return PartPropStatus;
}
}
m_pParticleTable = p_PartPropSvc->PDT();
return StatusCode::SUCCESS;
return StatusCode::SUCCESS;
}
StatusCode TrackRecordFilter::execute() {
// Get message service
MsgStream log(msgSvc(), name());
log << MSG::DEBUG << "TrackRecordFilter::execute()" << endreq;
// Get message service
ATH_MSG_DEBUG ( "TrackRecordFilter::execute()" );
// retrieve the collection
// retrieve the collection
const TrackRecordCollection* trackCollection(0);
if (m_storeGate->contains<TrackRecordCollection>(m_inputName)) {
if (StatusCode::SUCCESS != m_storeGate->retrieve(trackCollection, m_inputName) ) {
log << MSG::ERROR << "Could not retrieve TrackRecord collection!" << endreq;
if (evtStore()->contains<TrackRecordCollection>(m_inputName)) {
if (StatusCode::SUCCESS != evtStore()->retrieve(trackCollection, m_inputName) ) {
ATH_MSG_ERROR ( "Could not retrieve TrackRecord collection!" );
return StatusCode::SUCCESS;
}
}
else {
log << MSG::DEBUG << "Could not find TrackRecord collection" << endreq;
ATH_MSG_DEBUG ( "Could not find TrackRecord collection" );
return StatusCode::SUCCESS;
}
log << MSG::DEBUG << "There are " << trackCollection->size() << "tracks in this container " << endreq;
ATH_MSG_DEBUG ( "There are " << trackCollection->size() << "tracks in this container " );
// create and record a new collection
TrackRecordCollection* filterCollection = new TrackRecordCollection();
if (StatusCode::SUCCESS != m_storeGate->record(filterCollection, m_outputName) ) {
log << MSG::ERROR << "can not record collection!" << endreq;
TrackRecordCollection* filterCollection = new TrackRecordCollection();
if (StatusCode::SUCCESS != evtStore()->record(filterCollection, m_outputName) ) {
ATH_MSG_ERROR ( "can not record collection!" );
return StatusCode::SUCCESS;
}
// iterate over the collection
for (TrackRecordCollection::const_iterator trkit=trackCollection->begin(); trkit != trackCollection->end() ; ++trkit) {
int pdgId((*trkit)->GetPDGCode());
log << MSG::VERBOSE << "Track found with pdg id= " << (*trkit)->GetPDGCode() << " with energy "<< (*trkit)->GetEnergy() << endreq;
if(pdgId) { //Geant makes particle with pdgid=0...
// get rid of neutral particles
const HepPDT::ParticleData* particle =
m_pParticleTable->particle(HepPDT::ParticleID(abs(pdgId)));
if(particle){
if(fabs(particle->charge() ) >0.5 && (*trkit)->GetEnergy() > m_cutOff)
filterCollection->push_back(new TrackRecord(**trkit));
}
}
int pdgId((*trkit)->GetPDGCode());
ATH_MSG_VERBOSE ( "Track found with pdg id= " << (*trkit)->GetPDGCode() << " with energy "<< (*trkit)->GetEnergy() );
if(pdgId) { //Geant makes particle with pdgid=0...
// get rid of neutral particles
const HepPDT::ParticleData* particle =
m_pParticleTable->particle(HepPDT::ParticleID(abs(pdgId)));
if(particle){
if(fabs(particle->charge() ) >0.5 && (*trkit)->GetEnergy() > m_cutOff)
filterCollection->push_back(new TrackRecord(**trkit));
}
}
}
//lock the collection
StatusCode sc = m_storeGate->setConst(filterCollection);
if (sc.isFailure()) {
log << MSG::FATAL << "Cannot set collection to const" << endreq;
if (evtStore()->setConst(filterCollection).isFailure()) {
ATH_MSG_FATAL ( "Cannot set collection to const" );
return StatusCode::FAILURE;
}
log << MSG::DEBUG << "There are " << filterCollection->size() << "that satisfy the filter " << endreq;
ATH_MSG_DEBUG ( "There are " << filterCollection->size() << "that satisfy the filter " );
return StatusCode::SUCCESS;
}
StatusCode TrackRecordFilter::finalize() {
return StatusCode::SUCCESS;
return StatusCode::SUCCESS;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment