Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:07:03

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #pragma once
0012 
0013 #include "details.h"
0014 #include "utilities.h"
0015 #include <GaudiKernel/FunctionalFilterDecision.h>
0016 #include <type_traits>
0017 #include <utility>
0018 
0019 namespace Gaudi::Functional {
0020 
0021   namespace details {
0022 
0023     template <typename T, typename Traits_, bool isLegacy>
0024     struct FilterPredicate;
0025 
0026     template <typename... In, typename Traits_>
0027     struct FilterPredicate<bool( const In&... ), Traits_, true>
0028         : DataHandleMixin<std::tuple<>, filter_evtcontext<In...>, Traits_> {
0029       using DataHandleMixin<std::tuple<>, filter_evtcontext<In...>, Traits_>::DataHandleMixin;
0030 
0031       // derived classes are NOT allowed to implement execute ...
0032       StatusCode execute() override final {
0033         try {
0034           return filter_evtcontext_t<In...>::apply( *this, this->m_inputs ) ? FilterDecision::PASSED
0035                                                                             : FilterDecision::FAILED;
0036         } catch ( GaudiException& e ) {
0037           if ( e.code().isFailure() ) this->error() << e.tag() << " : " << e.message() << endmsg;
0038           return e.code();
0039         }
0040       }
0041 
0042       // ... instead, they must implement the following operator
0043       virtual bool operator()( const In&... ) const = 0;
0044     };
0045 
0046     template <typename... In, typename Traits_>
0047     struct FilterPredicate<bool( const In&... ), Traits_, false>
0048         : DataHandleMixin<std::tuple<>, filter_evtcontext<In...>, Traits_> {
0049       using DataHandleMixin<std::tuple<>, filter_evtcontext<In...>, Traits_>::DataHandleMixin;
0050 
0051       // derived classes are NOT allowed to implement execute ...
0052       StatusCode execute( const EventContext& ctx ) const override final {
0053         try {
0054           return filter_evtcontext_t<In...>::apply( *this, ctx, this->m_inputs ) ? FilterDecision::PASSED
0055                                                                                  : FilterDecision::FAILED;
0056         } catch ( GaudiException& e ) {
0057           if ( e.code().isFailure() ) this->error() << e.tag() << " : " << e.message() << endmsg;
0058           return e.code();
0059         }
0060       }
0061 
0062       // ... instead, they must implement the following operator
0063       virtual bool operator()( const In&... ) const = 0;
0064     };
0065 
0066   } // namespace details
0067 
0068   template <typename Signature, typename Traits_ = Traits::useDefaults>
0069   using FilterPredicate = details::FilterPredicate<Signature, Traits_, details::isLegacy<Traits_>>;
0070 
0071 } // namespace Gaudi::Functional