Skip to content
Snippets Groups Projects
Commit b0e00a34 authored by Edward Moyse's avatar Edward Moyse
Browse files

Adding demo package for the 2019 SW dev tutorial

parent 90c5c83c
No related merge requests found
Showing
with 415 additions and 0 deletions
atlas_subdir( DevTutorialWriteAlgAndTool )
atlas_depends_on_subdirs( PUBLIC
GaudiKernel
PRIVATE
Control/AthenaBaseComps
Event/xAOD/xAODTracking )
atlas_add_component( DevTutorialWriteAlgAndTool
src/*.cxx
src/components/*.cxx
LINK_LIBRARIES GaudiKernel AthenaBaseComps xAODTracking )
atlas_install_python_modules( python/*.py )
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MYNEWPACKAGE_IMYALGTOOL_H
#define MYNEWPACKAGE_IMYALGTOOL_H
#include "GaudiKernel/IAlgTool.h"
#include "xAODTracking/TrackParticle.h"
static const InterfaceID IID_IMyAlgTool("IMyAlgTool", 1, 0);
/** @class IMyAlgTool
@brief Interface to demonstrate how to make an interface which actually does something useful.
*/
class IMyAlgTool : virtual public IAlgTool {
public:
static const InterfaceID& interfaceID( );
virtual bool selectTrackParticle( const xAOD::TrackParticle& particle) const = 0 ;
};
inline const InterfaceID& IMyAlgTool::interfaceID()
{
return IID_IMyAlgTool;
}
#endif
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
from AthenaCommon.Constants import VERBOSE
from DevTutorialWriteAlgAndTool.DevTutorialWriteAlgAndToolConf import ExampleAlg
from TrkExTools.AtlasExtrapolatorConfig import AtlasExtrapolatorCfg
def ExampleAlgCfg(configFlags, **kwargs):
result=ComponentAccumulator()
alg = ExampleAlg(**kwargs )
result.addEventAlgo(alg)
return result
if __name__=="__main__":
from AthenaCommon.Configurable import Configurable
from AthenaCommon.Logging import log
from AthenaConfiguration.AllConfigFlags import ConfigFlags
from AthenaConfiguration.MainServicesConfig import MainServicesThreadedCfg
from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
Configurable.configurableRun3Behavior=1
from AthenaConfiguration.TestDefaults import defaultTestFiles
ConfigFlags.Input.Files = defaultTestFiles.ESD
ConfigFlags.Detector.GeometryPixel = True
ConfigFlags.Detector.GeometrySCT = True
ConfigFlags.Detector.GeometryTRT = True
ConfigFlags.Concurrency.NumThreads = 1
ConfigFlags.Concurrency.NumConcurrentEvents = 1
ConfigFlags.lock()
cfg=MainServicesThreadedCfg(ConfigFlags)
cfg.merge(PoolReadCfg(ConfigFlags))
from AthenaCommon.Constants import VERBOSE
acc=ExampleAlgCfg(ConfigFlags, OutputLevel=VERBOSE)
cfg.merge(acc)
cfg.run(10)
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
from AthenaCommon.Constants import VERBOSE
from DevTutorialWriteAlgAndTool.DevTutorialWriteAlgAndToolConf import ExampleAlg_step1 as ExampleAlg
from TrkExTools.AtlasExtrapolatorConfig import AtlasExtrapolatorCfg
def ExampleAlgCfg(configFlags, **kwargs):
result=ComponentAccumulator()
alg = ExampleAlg(**kwargs )
result.addEventAlgo(alg)
return result
if __name__=="__main__":
from AthenaCommon.Configurable import Configurable
from AthenaCommon.Logging import log
from AthenaConfiguration.AllConfigFlags import ConfigFlags
from AthenaConfiguration.MainServicesConfig import MainServicesThreadedCfg
from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
Configurable.configurableRun3Behavior=1
from AthenaConfiguration.TestDefaults import defaultTestFiles
ConfigFlags.Input.Files = defaultTestFiles.ESD
ConfigFlags.Detector.GeometryPixel = True
ConfigFlags.Detector.GeometrySCT = True
ConfigFlags.Detector.GeometryTRT = True
ConfigFlags.Concurrency.NumThreads = 8
ConfigFlags.Concurrency.NumConcurrentEvents = 8
ConfigFlags.lock()
cfg=MainServicesThreadedCfg(ConfigFlags)
cfg.merge(PoolReadCfg(ConfigFlags))
from AthenaCommon.Constants import VERBOSE
acc=ExampleAlgCfg(ConfigFlags, OutputLevel=VERBOSE)
cfg.merge(acc)
cfg.run(10)
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
from AthenaCommon.Constants import VERBOSE
from DevTutorialWriteAlgAndTool.DevTutorialWriteAlgAndToolConf import ExampleAlg_step4 as ExampleAlg
from TrkExTools.AtlasExtrapolatorConfig import AtlasExtrapolatorCfg
def ExampleAlgCfg(configFlags, **kwargs):
result=ComponentAccumulator()
alg = ExampleAlg(**kwargs )
result.addEventAlgo(alg)
return result
if __name__=="__main__":
from AthenaCommon.Configurable import Configurable
from AthenaCommon.Logging import log
from AthenaConfiguration.AllConfigFlags import ConfigFlags
from AthenaConfiguration.MainServicesConfig import MainServicesThreadedCfg
from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
Configurable.configurableRun3Behavior=1
from AthenaConfiguration.TestDefaults import defaultTestFiles
ConfigFlags.Input.Files = defaultTestFiles.ESD
ConfigFlags.Detector.GeometryPixel = True
ConfigFlags.Detector.GeometrySCT = True
ConfigFlags.Detector.GeometryTRT = True
ConfigFlags.Concurrency.NumThreads = 8
ConfigFlags.Concurrency.NumConcurrentEvents = 8
ConfigFlags.lock()
cfg=MainServicesThreadedCfg(ConfigFlags)
cfg.merge(PoolReadCfg(ConfigFlags))
from AthenaCommon.Constants import VERBOSE
acc=ExampleAlgCfg(ConfigFlags, OutputLevel=VERBOSE)
cfg.merge(acc)
cfg.run(10)
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "ExampleAlg.h"
ExampleAlg::ExampleAlg (const std::string& name, ISvcLocator* svcLocator)
: AthReentrantAlgorithm (name, svcLocator)
{ }
StatusCode ExampleAlg::initialize()
{
ATH_CHECK( m_trackParticleKey.initialize());
ATH_CHECK( m_algTool.retrieve() );
return StatusCode::SUCCESS;
}
StatusCode ExampleAlg::execute(const EventContext& ctx) const
{
SG::ReadHandle<xAOD::TrackParticleContainer> handle(m_trackParticleKey, ctx);
ATH_MSG_VERBOSE(ctx<< " Got back "<<handle->size()<<" trackparticles");
unsigned int count=0;
for (auto tp : *handle) {
if ( m_algTool->selectTrackParticle( *tp ) ) count++;
}
ATH_MSG_VERBOSE(ctx << " " << count << " pass selection");
return StatusCode::SUCCESS;
}
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MYNEWPACKAGE_EXAMPLEALG_H
#define MYNEWPACKAGE_EXAMPLEALG_H
#include "AthenaBaseComps/AthReentrantAlgorithm.h"
#include "xAODTracking/TrackParticleContainer.h"
#include "DevTutorialWriteAlgAndTool/IMyAlgTool.h"
/** An example algorithm that reads and writes objects from the event store
using handles.*/
class ExampleAlg
: public AthReentrantAlgorithm
{
public:
ExampleAlg (const std::string& name, ISvcLocator* svcLocator);
virtual StatusCode initialize() override;
virtual StatusCode execute (const EventContext& ctx) const override;
private:
SG::ReadHandleKey<xAOD::TrackParticleContainer> m_trackParticleKey
{ this, "TrackParticleContainerKey", "InDetTrackParticles", "Key for TrackParticle Containers" };
ToolHandle<IMyAlgTool> m_algTool {this, "SelectionTool", "MyAlgTool", "The selection tool"};
};
#endif
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "ExampleAlg_step1.h"
ExampleAlg_step1::ExampleAlg_step1 (const std::string& name, ISvcLocator* svcLocator)
: AthReentrantAlgorithm (name, svcLocator)
{ }
StatusCode ExampleAlg_step1::initialize()
{
return StatusCode::SUCCESS;
}
StatusCode ExampleAlg_step1::execute(const EventContext& ctx) const
{
ATH_MSG_VERBOSE("Events processed: "<<ctx.evt());
return StatusCode::SUCCESS;
}
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MYNEWPACKAGE_EXAMPLEALG_STEP1_H
#define MYNEWPACKAGE_EXAMPLEALG_STEP1_H
#include "AthenaBaseComps/AthReentrantAlgorithm.h"
/** An example algorithm that reads and writes objects from the event store
using handles.*/
class ExampleAlg_step1
: public AthReentrantAlgorithm
{
public:
ExampleAlg_step1 (const std::string& name, ISvcLocator* svcLocator);
virtual StatusCode initialize() override;
virtual StatusCode execute (const EventContext& ctx) const override;
private:
};
#endif
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "ExampleAlg_step3.h"
ExampleAlg_step3::ExampleAlg_step3 (const std::string& name, ISvcLocator* svcLocator)
: AthReentrantAlgorithm (name, svcLocator)
{ }
StatusCode ExampleAlg_step3::initialize()
{
ATH_CHECK( m_trackParticleKey.initialize());
return StatusCode::SUCCESS;
}
StatusCode ExampleAlg_step3::execute(const EventContext& ctx) const
{
ATH_MSG_VERBOSE("Events processed: "<<ctx.evt());
SG::ReadHandle<xAOD::TrackParticleContainer> handle(m_trackParticleKey, ctx);
ATH_MSG_VERBOSE("Got back "<<handle->size());
return StatusCode::SUCCESS;
}
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MYNEWPACKAGE_ExampleAlg_STEP3_H
#define MYNEWPACKAGE_ExampleAlg_STEP3_H
#include "AthenaBaseComps/AthReentrantAlgorithm.h"
#include "xAODTracking/TrackParticleContainer.h"
/** An example algorithm that reads and writes objects from the event store
using handles.*/
class ExampleAlg_step3
: public AthReentrantAlgorithm
{
public:
ExampleAlg_step3 (const std::string& name, ISvcLocator* svcLocator);
virtual StatusCode initialize() override;
virtual StatusCode execute (const EventContext& ctx) const override;
private:
///
SG::ReadHandleKey<xAOD::TrackParticleContainer> m_trackParticleKey
{ this, "TrackParticleContainerKey", "InDetTrackParticles", "Key for TrackParticle Containers" };
};
#endif
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "ExampleAlg_step4.h"
ExampleAlg_step4::ExampleAlg_step4 (const std::string& name, ISvcLocator* svcLocator)
: AthReentrantAlgorithm (name, svcLocator)
{ }
StatusCode ExampleAlg_step4::initialize()
{
ATH_CHECK( m_trackParticleKey.initialize());
ATH_CHECK( m_algTool.retrieve() );
return StatusCode::SUCCESS;
}
StatusCode ExampleAlg_step4::execute(const EventContext& ctx) const
{
ATH_MSG_VERBOSE("Event slot: "<<ctx.evt());
SG::ReadHandle<xAOD::TrackParticleContainer> handle(m_trackParticleKey, ctx);
ATH_MSG_VERBOSE("Got back "<<handle->size()<<" trackparticles");
return StatusCode::SUCCESS;
}
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MYNEWPACKAGE_EXAMPLEALG_STEP4_H
#define MYNEWPACKAGE_EXAMPLEALG_STEP4_H
#include "AthenaBaseComps/AthReentrantAlgorithm.h"
#include "xAODTracking/TrackParticleContainer.h"
#include "DevTutorialWriteAlgAndTool/IMyAlgTool.h"
/** An example algorithm that reads and writes objects from the event store
using handles.*/
class ExampleAlg_step4
: public AthReentrantAlgorithm
{
public:
ExampleAlg_step4 (const std::string& name, ISvcLocator* svcLocator);
virtual StatusCode initialize() override;
virtual StatusCode execute (const EventContext& ctx) const override;
private:
SG::ReadHandleKey<xAOD::TrackParticleContainer> m_trackParticleKey
{ this, "TrackParticleContainerKey", "InDetTrackParticles", "Key for TrackParticle Containers" };
ToolHandle<IMyAlgTool> m_algTool {this, "SelectionTool", "MyAlgTool", "The selection tool"};
};
#endif
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "MyAlgTool.h"
MyAlgTool::MyAlgTool(const std::string& t, const std::string& n, const IInterface* p ) :
AthAlgTool(t,n,p)
{
declareInterface<IMyAlgTool>(this);
}
bool MyAlgTool::selectTrackParticle( const xAOD::TrackParticle& particle) const {
return particle.pt()>2.0;
}
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MYNEWPACKAGE_MYALGTOOL_H
#define MYNEWPACKAGE_MYALGTOOL_H
#include "AthenaBaseComps/AthAlgTool.h"
#include "DevTutorialWriteAlgAndTool/IMyAlgTool.h"
class MyAlgTool : public AthAlgTool, virtual public IMyAlgTool {
public:
MyAlgTool(const std::string&,const std::string&,const IInterface*);
MyAlgTool& operator= (const MyAlgTool& ) = delete;
bool selectTrackParticle( const xAOD::TrackParticle& particle) const override;
};
#endif
#include "../ExampleAlg.h"
#include "../ExampleAlg_step1.h"
#include "../ExampleAlg_step3.h"
#include "../ExampleAlg_step4.h"
#include "../MyAlgTool.h"
DECLARE_COMPONENT( ExampleAlg )
DECLARE_COMPONENT( ExampleAlg_step1 )
DECLARE_COMPONENT( ExampleAlg_step3 )
DECLARE_COMPONENT( ExampleAlg_step4 )
DECLARE_COMPONENT( MyAlgTool )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment