From 3d04b01702c127de0e9ba9a6fa16b4be92201047 Mon Sep 17 00:00:00 2001 From: Rosen Matev <rosen.matev@cern.ch> Date: Wed, 24 Aug 2016 11:14:12 +0200 Subject: [PATCH] Use boost::optional to simplify VxCreator - instead of keeping a seperate bool to flag the presence of a 'dummy' trivial value, use boost::optional instead, which avoids having to create a 'dummy', and which avoids the corresponding bookkeeping. This fixes the longstanding warning about hiding virtual functions, as the instance which caused the warning isn't instantiated anymore... - replace a deprecated std::auto_ptr with std::unique_ptr - See merge request !156 (cherry picked from commit 22fc39471b34609693db859748fb4fb9fab3d116) 2c54a7d4 Use boost::optional to simplify VxCreator --- Phys/LoKiTrigger/LoKi/VxCreator.h | 22 +-- Phys/LoKiTrigger/src/VxCreator.cpp | 237 ++++++++++++----------------- 2 files changed, 101 insertions(+), 158 deletions(-) diff --git a/Phys/LoKiTrigger/LoKi/VxCreator.h b/Phys/LoKiTrigger/LoKi/VxCreator.h index adad99403..7d5c9e857 100755 --- a/Phys/LoKiTrigger/LoKi/VxCreator.h +++ b/Phys/LoKiTrigger/LoKi/VxCreator.h @@ -6,6 +6,7 @@ // Include files // ============================================================================ // TrackEvent/RecEvent +#include "boost/optional.hpp" // ============================================================================ #include "Event/RecVertex.h" // ============================================================================ @@ -70,8 +71,6 @@ namespace LoKi VxCreator ( const LoKi::Types::RVCuts& cust4rv ) ; /// default contructor, no cuts VxCreator () ; - /// MANDATORY: virtual destructor - virtual ~VxCreator() {} // ====================================================================== /// nice printout // ====================================================================== @@ -90,27 +89,18 @@ namespace LoKi const LHCb::Track::ConstVector& tracks2 , std::vector<LHCb::RecVertex*>& vertices ) const ; // ====================================================================== - /// alkl cuts are trivial? + /// all cuts are trivial? bool trivial() const - { return m_cut_trivial && m_cut2tr_trivial && m_cut4rv_trivial ; } - // ====================================================================== - private: - // ====================================================================== - const LoKi::Types::TrCuts& cuts () const { return m_cut ; } - const LoKi::Types::TTrCuts& cuts2tr () const { return m_cut2tr ; } - const LoKi::Types::RVCuts& cuts4rv () const { return m_cut4rv ; } + { return !m_cut && !m_cut2tr && !m_cut4rv ; } // ====================================================================== private: // ====================================================================== /// cuts to be applied for each track - LoKi::Types::TrCut m_cut ; - bool m_cut_trivial ; // trivial? + boost::optional<LoKi::Types::TrCut> m_cut ; /// cuts to be applied for two track-combination - LoKi::Types::TTrCut m_cut2tr ; // cut on 2-track - bool m_cut2tr_trivial ; // trivial? + boost::optional<LoKi::Types::TTrCut> m_cut2tr ; // cut on 2-track /// cuts to be applied for the recontructed vertex - LoKi::Types::RVCut m_cut4rv ; // cut on RV - bool m_cut4rv_trivial ; // trivial? + boost::optional<LoKi::Types::RVCut> m_cut4rv ; // cut on RV // ====================================================================== } ; // ======================================================================== diff --git a/Phys/LoKiTrigger/src/VxCreator.cpp b/Phys/LoKiTrigger/src/VxCreator.cpp index 8ac3bd66b..bd993be01 100755 --- a/Phys/LoKiTrigger/src/VxCreator.cpp +++ b/Phys/LoKiTrigger/src/VxCreator.cpp @@ -1,13 +1,13 @@ // $Id$ // ============================================================================ -// Include files +// Include files // ============================================================================ #ifdef __INTEL_COMPILER #pragma warning(disable:1572) // non-pointer conversion ... may lose significant bits #pragma warning(push) #endif // ============================================================================ -// HltBase +// HltBase // ============================================================================ #include "HltBase/HltUtils.h" // ============================================================================ @@ -16,7 +16,7 @@ #include "LoKi/VxCreator.h" #include "LoKi/Combiner.h" // ============================================================================ -// local +// local // ============================================================================ #include "LTTools.h" // ============================================================================ @@ -24,222 +24,175 @@ #pragma warning(pop) #endif // ============================================================================ -/** @file +/** @file * Implementation file for class LoKi::Hlt1::VxCreator - * @date 2008-11-14 + * @date 2008-11-14 * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl */ // ============================================================================ -// constructor from the cuts +// constructor from the cuts // ============================================================================ LoKi::Hlt1::VxCreator::VxCreator -( const LoKi::Types::TrCuts& cuts , +( const LoKi::Types::TrCuts& cuts , const LoKi::Types::TTrCuts& cuts2tr , - const LoKi::Types::RVCuts& cuts4rv ) - : LoKi::AuxFunBase ( std::tie ( cuts , cuts2tr , cuts4rv ) ) + const LoKi::Types::RVCuts& cuts4rv ) + : LoKi::AuxFunBase ( std::tie ( cuts , cuts2tr , cuts4rv ) ) // - , m_cut ( cuts ) - , m_cut_trivial ( false ) - , m_cut2tr ( cuts2tr ) - , m_cut2tr_trivial ( false ) - , m_cut4rv ( cuts4rv ) - , m_cut4rv_trivial ( false ) + , m_cut ( cuts ) + , m_cut2tr ( cuts2tr ) + , m_cut4rv ( cuts4rv ) {} // ============================================================================ -// constructor from the cuts +// constructor from the cuts // ============================================================================ LoKi::Hlt1::VxCreator::VxCreator ( const LoKi::Types::TTrCuts& cuts2tr , - const LoKi::Types::RVCuts& cuts4rv ) - : LoKi::AuxFunBase ( std::tie ( cuts2tr , cuts4rv ) ) + const LoKi::Types::RVCuts& cuts4rv ) + : LoKi::AuxFunBase ( std::tie ( cuts2tr , cuts4rv ) ) // - , m_cut ( LoKi::Constant<const LHCb::Track*,bool>( true ) ) - , m_cut_trivial ( true ) - , m_cut2tr ( cuts2tr ) - , m_cut2tr_trivial ( false ) - , m_cut4rv ( cuts4rv ) - , m_cut4rv_trivial ( false ) + , m_cut2tr ( cuts2tr ) + , m_cut4rv ( cuts4rv ) {} // ============================================================================ -// constructor from the cuts +// constructor from the cuts // ============================================================================ LoKi::Hlt1::VxCreator::VxCreator ( const LoKi::Types::TrCuts& cuts , - const LoKi::Types::RVCuts& cuts4rv ) - : LoKi::AuxFunBase ( std::tie ( cuts , cuts4rv ) ) - // - , m_cut ( cuts ) - , m_cut_trivial ( false ) - , m_cut2tr ( LoKi::Constant<LoKi::TrackTypes::TrackPair,bool>( true ) ) - , m_cut2tr_trivial ( true ) - , m_cut4rv ( cuts4rv ) - , m_cut4rv_trivial ( false ) + const LoKi::Types::RVCuts& cuts4rv ) + : LoKi::AuxFunBase ( std::tie ( cuts , cuts4rv ) ) + , m_cut ( cuts ) + , m_cut4rv ( cuts4rv ) {} // ============================================================================ -// constructor from the cuts +// constructor from the cuts // ============================================================================ LoKi::Hlt1::VxCreator::VxCreator ( const LoKi::Types::TrCuts& cuts , - const LoKi::Types::TTrCuts& cuts2tr ) - : LoKi::AuxFunBase ( std::tie ( cuts , cuts2tr ) ) + const LoKi::Types::TTrCuts& cuts2tr ) + : LoKi::AuxFunBase ( std::tie ( cuts , cuts2tr ) ) // - , m_cut ( cuts ) - , m_cut_trivial ( false ) - , m_cut2tr ( cuts2tr ) - , m_cut2tr_trivial ( false ) - , m_cut4rv ( LoKi::Constant<LHCb::RecVertex,bool>( true ) ) - , m_cut4rv_trivial ( true ) + , m_cut ( cuts ) + , m_cut2tr ( cuts2tr ) {} // ============================================================================ -// constructor from the cuts +// constructor from the cuts // ============================================================================ LoKi::Hlt1::VxCreator::VxCreator -( const LoKi::Types::TrCuts& cuts ) - : LoKi::AuxFunBase ( std::tie ( cuts ) ) - // - , m_cut ( cuts ) - , m_cut_trivial ( false ) - , m_cut2tr ( LoKi::Constant<LoKi::TrackTypes::TrackPair,bool>( true ) ) - , m_cut2tr_trivial ( true ) - , m_cut4rv ( LoKi::Constant<LHCb::RecVertex,bool>( true ) ) - , m_cut4rv_trivial ( true ) +( const LoKi::Types::TrCuts& cuts ) + : LoKi::AuxFunBase ( std::tie ( cuts ) ) + , m_cut ( cuts ) {} // ============================================================================ -// constructor from the cuts +// constructor from the cuts // ============================================================================ LoKi::Hlt1::VxCreator::VxCreator -( const LoKi::Types::TTrCuts& cuts2tr ) - : LoKi::AuxFunBase ( std::tie ( cuts2tr ) ) -// - , m_cut ( LoKi::Constant<const LHCb::Track*,bool>( true ) ) - , m_cut_trivial ( true ) - , m_cut2tr ( cuts2tr ) - , m_cut2tr_trivial ( false ) - , m_cut4rv ( LoKi::Constant<LHCb::RecVertex,bool>( true ) ) - , m_cut4rv_trivial ( true ) +( const LoKi::Types::TTrCuts& cuts2tr ) + : LoKi::AuxFunBase ( std::tie ( cuts2tr ) ) + , m_cut2tr ( cuts2tr ) {} // ============================================================================ -// constructor from the cuts +// constructor from the cuts // ============================================================================ LoKi::Hlt1::VxCreator::VxCreator -( const LoKi::Types::RVCuts& cuts4rv ) - : LoKi::AuxFunBase ( std::tie ( cuts4rv ) ) - // - , m_cut ( LoKi::Constant<const LHCb::Track*,bool>( true ) ) - , m_cut_trivial ( true ) - , m_cut2tr ( LoKi::Constant<LoKi::TrackTypes::TrackPair,bool>( true ) ) - , m_cut2tr_trivial ( true ) - , m_cut4rv ( cuts4rv ) - , m_cut4rv_trivial ( false ) +( const LoKi::Types::RVCuts& cuts4rv ) + : LoKi::AuxFunBase ( std::tie ( cuts4rv ) ) + , m_cut4rv ( cuts4rv ) {} // ============================================================================ -// constructor from the cuts +// constructor from the cuts // ============================================================================ -LoKi::Hlt1::VxCreator::VxCreator () - : LoKi::AuxFunBase () - // - , m_cut ( LoKi::Constant<const LHCb::Track*,bool>( true ) ) - , m_cut_trivial ( true ) - , m_cut2tr ( LoKi::Constant<LoKi::TrackTypes::TrackPair,bool>( true ) ) - , m_cut2tr_trivial ( true ) - , m_cut4rv ( LoKi::Constant<LHCb::RecVertex,bool>( true ) ) - , m_cut4rv_trivial ( true ) +LoKi::Hlt1::VxCreator::VxCreator () + : LoKi::AuxFunBase { std::tie() } {} // ============================================================================ -// nice printout +// nice printout // ============================================================================ -std::ostream& LoKi::Hlt1::VxCreator::fillStream ( std::ostream& s ) const +std::ostream& LoKi::Hlt1::VxCreator::fillStream ( std::ostream& s ) const { + std::vector<std::string> out ; + if ( !m_cut ) { out.push_back( m_cut -> printOut () ) ; } + if ( !m_cut2tr ) { out.push_back( m_cut2tr -> printOut () ) ; } + if ( !m_cut4rv ) { out.push_back( m_cut4rv -> printOut () ) ; } s << "LoKi.Hlt1.VxCreator(" ; - // - typedef std::vector<std::string> Strings ; - Strings out ; - // - if ( !m_cut_trivial ) { out.push_back( cuts () . printOut () ) ; } - if ( !m_cut2tr_trivial ) { out.push_back( cuts2tr () . printOut () ) ; } - if ( !m_cut4rv_trivial ) { out.push_back( cuts4rv () . printOut () ) ; } - // - for ( Strings::const_iterator iout = out.begin() ; out.end() != iout ; ++iout ) - { + for ( auto iout = out.begin() ; out.end() != iout ; ++iout ) { if ( out.begin () !=iout ) { s << "," ; } - s << ( *iout ) ; + s << *iout ; } - // return s << ")" ; } // ============================================================================ // make the vertices // ============================================================================ -size_t LoKi::Hlt1::VxCreator::make -( const LHCb::Track::ConstVector& tracks1 , - const LHCb::Track::ConstVector& tracks2 , - std::vector<LHCb::RecVertex*>& vertices ) const +size_t LoKi::Hlt1::VxCreator::make +( const LHCb::Track::ConstVector& tracks1 , + const LHCb::Track::ConstVector& tracks2 , + std::vector<LHCb::RecVertex*>& vertices ) const { if ( tracks1.empty() || tracks2.empty() ) { return 0 ; } - - const bool same = + + const bool same = ( &tracks1 == &tracks2 ) || ( tracks1 == tracks2 ) ; - + const size_t n1 = tracks1.size() ; const size_t n2 = tracks2.size() ; - - vertices.reserve ( same ? - vertices.size() + n1*(n1-1)/2 : + + vertices.reserve ( same ? + vertices.size() + n1*(n1-1)/2 : vertices.size() + n1*n2 ) ; - + typedef LHCb::Track::ConstVector Tracks ; typedef LoKi::Combiner_<Tracks> Combiner ; - + const Hlt::VertexCreator creator ; const LoKi::Hlt1::Utils::CmpTrack compare = LoKi::Hlt1::Utils::CmpTrack() ; - + const size_t size = vertices.size() ; - - /// create the combiner & fill it with data + + /// create the combiner & fill it with data Combiner loop ; loop.add ( { tracks1 } ) ; loop.add ( { tracks2 } ) ; - - // make the combinations - for ( ; loop.valid() ; loop.next() ) + + // make the combinations + for ( ; loop.valid() ; loop.next() ) { - // get the current combination + // get the current combination Tracks tracks ( 2 ) ; loop.current ( tracks.begin() ) ; - + const LHCb::Track* first = tracks[0] ; const LHCb::Track* second = tracks[1] ; - - // skip invalid - if ( 0 == first || 0 == second ) { continue ; } // CONTINUE - // skip the same - if ( first == second ) { continue ; } // CONTINUE + + // skip invalid + if ( !first || !second ) { continue ; } // CONTINUE + // skip the same + if ( first == second ) { continue ; } // CONTINUE // reduce the double count : if ( same && !compare ( first , second ) ) { continue ; } // CONTINUE - - // chech the overrlap - if ( HltUtils::matchIDs ( *first , *second ) ) { continue ; } // CONTINUE - + + // chech the overrlap + if ( HltUtils::matchIDs ( *first , *second ) ) { continue ; } // CONTINUE + // apply the cuts on the combination of two tracks: - if ( !m_cut2tr_trivial && !m_cut2tr ( *first , *second ) ) { continue ; } - - // create the vertex - std::auto_ptr<LHCb::RecVertex> vertex ( new LHCb::RecVertex() ) ; - - /// fill it with some information + if ( m_cut2tr && !(*m_cut2tr)( *first , *second ) ) { continue ; } + + // create the vertex + auto vertex = std::make_unique<LHCb::RecVertex>(); + + /// fill it with some information creator ( *first , *second , *vertex ) ; - - // apply cuts on the vertex - if ( !m_cut4rv_trivial && !m_cut4rv ( *vertex ) ) { continue ; } // CONTINUE - - // good vertex! add it to the outptu container + + // apply cuts on the vertex + if ( m_cut4rv && !(*m_cut4rv)( *vertex ) ) { continue ; } // CONTINUE + + // good vertex! add it to the outptu container vertices.push_back ( vertex.release() ) ; // "vertex is not valid anymore - - } // end of loop over all combinations + + } // end of loop over all combinations // - // return number of created vertcies - return vertices.size() - size ; // RETURN + // return number of created vertcies + return vertices.size() - size ; // RETURN } // ============================================================================ -// The END +// The END // ============================================================================ -- GitLab