Skip to content
Snippets Groups Projects
Commit ccabfddc authored by Gerhard Raven's avatar Gerhard Raven
Browse files

adapt to use gaudi/Gaudi!1270

parent 675ce6dd
No related branches found
No related tags found
No related merge requests found
Pipeline #3168186 passed
......@@ -25,7 +25,7 @@
#include <string>
// Gaudi
#include "GaudiKernel/INamedInterface.h"
#include "GaudiKernel/IAlgTool.h"
// Event Model
namespace LHCb {
......@@ -40,7 +40,7 @@ namespace LHCb {
* @author Chris Jones Christopher.Rob.Jones@cern.ch
* @date 2004-04-28
*/
struct IMCReconstructible : extend_interfaces<INamedInterface> {
struct IMCReconstructible : extend_interfaces<IAlgTool> {
/// Reconstructability categories
enum RecCategory {
......
......@@ -24,7 +24,9 @@
#include "Event/MCTrackGeomCriteria.h"
#include "Event/MCTrackInfo.h"
#include "GaudiAlg/FunctionalDetails.h"
#include "GaudiAlg/FunctionalTool.h"
#include "GaudiAlg/GaudiTool.h"
#include "GaudiKernel/IBinder.h"
#include "GaudiKernel/VectorMap.h"
#include "LHCbMath/LHCbMath.h"
#include "MCInterfaces/IMCParticleSelector.h"
......@@ -49,67 +51,24 @@ namespace {
struct CaloAcc {
// misc CALO params. Hopefully to go into specific CALO reconstructibility tool
double zECAL = 12696.0 * Gaudi::Units::mm;
double xECALInn = 363.3 * Gaudi::Units::mm;
double yECALInn = 363.3 * Gaudi::Units::mm;
double xECALOut = 3757.2 * Gaudi::Units::mm;
double yECALOut = 3030.0 * Gaudi::Units::mm;
CaloAcc() = default;
static constexpr double zECAL = 12696.0 * Gaudi::Units::mm;
double xECALInn = 363.3 * Gaudi::Units::mm;
double yECALInn = 363.3 * Gaudi::Units::mm;
double xECALOut = 3757.2 * Gaudi::Units::mm;
double yECALOut = 3030.0 * Gaudi::Units::mm;
CaloAcc() = default;
CaloAcc( const DeCalorimeter& calo ) {
auto refOut = LHCb::CaloCellID{CaloCellCode::CaloIndex::EcalCalo, 0, 6, 0};
auto refInn = LHCb::CaloCellID{CaloCellCode::CaloIndex::EcalCalo, 2, 25, 23};
xECALInn = std::abs( calo.cellX( refInn ) );
yECALInn = std::abs( calo.cellY( refInn ) );
xECALOut = std::abs( calo.cellX( refOut ) );
yECALOut = std::abs( calo.cellY( refOut ) );
constexpr auto refOut = LHCb::CaloCellID{CaloCellCode::CaloIndex::EcalCalo, 0, 6, 0};
constexpr auto refInn = LHCb::CaloCellID{CaloCellCode::CaloIndex::EcalCalo, 2, 25, 23};
xECALInn = std::abs( calo.cellX( refInn ) );
yECALInn = std::abs( calo.cellY( refInn ) );
xECALOut = std::abs( calo.cellX( refOut ) );
yECALOut = std::abs( calo.cellY( refOut ) );
}
};
} // namespace
template <typename IUserVisibleIFace>
struct IBinder : extend_interfaces<IInterface> {
DeclareInterfaceID( IBinder<IUserVisibleIFace>, 1, 0 );
virtual std::unique_ptr<IUserVisibleIFace> operator()( EventContext const& ) const = 0;
};
template <typename Signature, typename Traits = void>
struct ToolBinder;
template <typename IRet, typename... Args, typename Traits>
class ToolBinder<std::unique_ptr<IRet>( Args const&... ), Traits>
: public extends<Gaudi::Functional::details::BaseClass_t<Traits>, IBinder<IRet>> {
constexpr static std::size_t N = sizeof...( Args );
template <typename IArgs, std::size_t... I>
ToolBinder( std::string type, std::string name, const IInterface* parent, IArgs&& args, std::index_sequence<I...> )
: extends<Gaudi::Functional::details::BaseClass_t<Traits>, IBinder<IRet>>{std::move( type ), std::move( name ),
parent}
, m_handles{std::tuple_cat( std::forward_as_tuple( this ), std::get<I>( args ) )...} {}
std::tuple<Gaudi::Functional::details::InputHandle_t<Traits, Args>...> m_handles;
public:
using KeyValue = std::pair<std::string, std::string>;
ToolBinder( std::string type, std::string name, const IInterface* parent,
Gaudi::Functional::details::RepeatValues_<KeyValue, N> const& inputs )
: ToolBinder{std::move( type ), std::move( name ), parent, inputs, std::index_sequence_for<Args...>{}} {}
// TODO: replace with the concrete implementation type to here, and just return it by value, avoiding bind()
// alltogether
virtual std::unique_ptr<IRet> bind( const Args&... ) const = 0;
std::unique_ptr<IRet> operator()( EventContext const& ctx ) const override final {
return std::apply(
[&]( auto&... arg ) {
using namespace Gaudi::Functional::details;
return this->bind( get( arg, *this, ctx )... );
},
m_handles );
}
};
// in Gaudi::Functional, when `IMCReconstructible` does _not_ inherit from IAlgTool,
// use a `ToolHandle<IBinder<IMCReconstructible>>` instead, eg. add
//
......@@ -127,8 +86,10 @@ public:
//
class MCReconstructible
: public ToolBinder<std::unique_ptr<IMCReconstructible>( DeCalorimeter const&, LHCb::MCProperty const& ),
LHCb::DetDesc::usesBaseAndConditions<AlgTool, DeCalorimeter>> {
: public Gaudi::Functional::ToolBinder<
Gaudi::Interface::BoxedInterface<IMCReconstructible>( const DeCalorimeter&, const LHCb::MCProperty& ),
LHCb::DetDesc::usesBaseAndConditions<LHCb::DetDesc::ConditionAccessorHolder<FixTESPath<AlgTool>>,
DeCalorimeter>> {
public:
/// Standard constructor
......@@ -138,10 +99,16 @@ public:
parent,
{{"DeCalo", DeCalorimeterLocation::Ecal}, {"MCTrackInfo", LHCb::MCPropertyLocation::TrackInfo}}} {}
// TODO: replace unique_ptr with a small-buffer-optimized handle type
// TODO: expose BoundInstance, and instantiate ToolBinder with as type
std::unique_ptr<IMCReconstructible> bind( DeCalorimeter const& calo, LHCb::MCProperty const& prop ) const override {
class BoundInstance : public IMCReconstructible {
// code to be called by BoundInstance
bool inAcceptance( const LHCb::MCParticle*, const MCTrackInfo&, const CaloAcc& ) const;
IMCReconstructible::RecCategory reconstructible( const LHCb::MCParticle*, const MCTrackInfo&, const CaloAcc& ) const;
bool isReconstructibleAs( const IMCReconstructible::RecCategory& category, const LHCb::MCParticle* mcPart,
const MCTrackInfo& mcTkInfo, const CaloAcc& ) const;
Gaudi::Interface::BoxedInterface<IMCReconstructible> bind( const DeCalorimeter& calo,
const LHCb::MCProperty& prop ) const override {
class BoundInstance final : public Gaudi::Interface::Stub<IMCReconstructible> {
const MCReconstructible* m_parent;
const CaloAcc acc;
const MCTrackInfo info;
......@@ -158,28 +125,15 @@ public:
bool inAcceptance( const LHCb::MCParticle* mcPart ) const override {
return m_parent->inAcceptance( mcPart, info, acc );
}
/// Is the MCParticle reconstructible as given type
bool isReconstructibleAs( const IMCReconstructible::RecCategory& category,
const LHCb::MCParticle* mcPart ) const override {
return m_parent->isReconstructibleAs( category, mcPart, info, acc );
}
// IMCReconstructible extends INamedInterface...
unsigned long addRef() override { return 0; }
unsigned long release() override { return 0; }
StatusCode queryInterface( const InterfaceID&, void** ) override { return StatusCode::FAILURE; }
const std::string& name() const override { return m_parent->name(); }
};
return std::make_unique<BoundInstance>( this, calo, prop );
return {std::in_place_type<BoundInstance>, this, calo, prop};
}
// code to be called by BoundInstance
bool inAcceptance( const LHCb::MCParticle*, const MCTrackInfo&, const CaloAcc& ) const;
IMCReconstructible::RecCategory reconstructible( const LHCb::MCParticle*, const MCTrackInfo&, const CaloAcc& ) const;
bool isReconstructibleAs( const IMCReconstructible::RecCategory& category, const LHCb::MCParticle* mcPart,
const MCTrackInfo& mcTkInfo, const CaloAcc& ) const;
private:
/// Trest acceptance for charged particles
bool accept_charged( const LHCb::MCParticle*, const MCTrackInfo& ) const;
......
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