diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/CMakeLists.txt b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..23dc8378faeeecc959b0d0681b40b0dbaaaf0c9d --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/CMakeLists.txt @@ -0,0 +1,14 @@ +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 ) diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/DevTutorialWriteAlgAndTool/IMyAlgTool.h b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/DevTutorialWriteAlgAndTool/IMyAlgTool.h new file mode 100644 index 0000000000000000000000000000000000000000..db3679106c286ef7d922507b7f98fbf8108f059a --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/DevTutorialWriteAlgAndTool/IMyAlgTool.h @@ -0,0 +1,28 @@ +/* + 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 + diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/python/ExampleAlgConfig.py b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/python/ExampleAlgConfig.py new file mode 100644 index 0000000000000000000000000000000000000000..e6a2f1ded57fad3414ee0652705e3a0c34f7a5d4 --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/python/ExampleAlgConfig.py @@ -0,0 +1,45 @@ +# 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) + + + diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/python/ExampleAlgConfig_step2.py b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/python/ExampleAlgConfig_step2.py new file mode 100644 index 0000000000000000000000000000000000000000..393702abe9be51a367a5b4824242396cbdcf6e2c --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/python/ExampleAlgConfig_step2.py @@ -0,0 +1,46 @@ +# 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) + + + diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/python/ExampleAlgConfig_step4.py b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/python/ExampleAlgConfig_step4.py new file mode 100644 index 0000000000000000000000000000000000000000..08467fdc0d13ad5058f940e790dd77506d13aa38 --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/python/ExampleAlgConfig_step4.py @@ -0,0 +1,46 @@ +# 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) + + + diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg.cxx b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e5e87c46dfbc40e87bfb1291714e6c9482e9bbb3 --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg.cxx @@ -0,0 +1,29 @@ +/* + 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; +} diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg.h b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..c4f55b1edb15686118dfedbbdffcaa3fe6404ceb --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg.h @@ -0,0 +1,26 @@ +/* + 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 diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step1.cxx b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step1.cxx new file mode 100644 index 0000000000000000000000000000000000000000..73c447a64d6d5045dd7b597af5fdd3da305fb5fa --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step1.cxx @@ -0,0 +1,20 @@ +/* + 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; +} diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step1.h b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step1.h new file mode 100644 index 0000000000000000000000000000000000000000..49289bf185532d97feaebf20b69dd9bd89db9f9a --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step1.h @@ -0,0 +1,20 @@ +/* + 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 diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step3.cxx b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step3.cxx new file mode 100644 index 0000000000000000000000000000000000000000..52a333974fb41e5fddb76cc85ecde3850f4963ad --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step3.cxx @@ -0,0 +1,23 @@ +/* + 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; +} diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step3.h b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step3.h new file mode 100644 index 0000000000000000000000000000000000000000..b49d70362729ba1a8c904adf14b67a64fa0220fa --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step3.h @@ -0,0 +1,24 @@ +/* + 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 diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step4.cxx b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step4.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7d1c32c60589d30b58e0fc34fab59b9342d6a96b --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step4.cxx @@ -0,0 +1,24 @@ +/* + 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; +} diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step4.h b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step4.h new file mode 100644 index 0000000000000000000000000000000000000000..8082d4bb3ce7f4a4502e1750cac85b49c888ab59 --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/ExampleAlg_step4.h @@ -0,0 +1,26 @@ +/* + 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 diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/MyAlgTool.cxx b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/MyAlgTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..280aa22e2d7a430ea95054775cc083fcca5cb5c0 --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/MyAlgTool.cxx @@ -0,0 +1,15 @@ +/* + 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; +} diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/MyAlgTool.h b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/MyAlgTool.h new file mode 100644 index 0000000000000000000000000000000000000000..bb83336086b8fc89a5b4275312ae605655aa98a8 --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/MyAlgTool.h @@ -0,0 +1,19 @@ +/* + 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 diff --git a/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/components/MyNewPackage_entries.cxx b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/components/MyNewPackage_entries.cxx new file mode 100644 index 0000000000000000000000000000000000000000..20aacc1fd916af37a6bbfb4ff4437617d2932ddf --- /dev/null +++ b/Control/AthenaExamples/DevTutorialWriteAlgAndTool/src/components/MyNewPackage_entries.cxx @@ -0,0 +1,10 @@ +#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 )