Skip to content
Snippets Groups Projects
Commit 6aaaeec9 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Merge branch 'strong-enum-tagresult' into 'master'

Strong enum for Tagger::TagResult, used in FlavourTag and Tagger

See merge request !4423
parents cf83ae5e 0a2d7aa1
No related branches found
No related tags found
1 merge request!4423Strong enum for Tagger::TagResult, used in FlavourTag and Tagger
Pipeline #6802773 passed
......@@ -22,11 +22,11 @@ void FlavourTagPacker::pack( const Data& ft, PackedData& pft, PackedDataVector&
pft.key = ft.key();
// Decision
pft.decision = ft.decision();
pft.decision = to_underlying( ft.decision() );
pft.omega = StandardPacker::fraction( ft.omega() );
// OS decision
pft.decisionOS = ft.decisionOS();
pft.decisionOS = to_underlying( ft.decisionOS() );
pft.omegaOS = StandardPacker::fraction( ft.omegaOS() );
// tagging particle
......@@ -41,7 +41,7 @@ void FlavourTagPacker::pack( const Data& ft, PackedData& pft, PackedDataVector&
// save data members
ptagger.type = T.type();
ptagger.decision = T.decision();
ptagger.decision = to_underlying( T.decision() );
ptagger.omega = StandardPacker::fraction( T.omega() );
// tagging particles
......@@ -72,11 +72,11 @@ StatusCode FlavourTagPacker::unpack( const PackedData& pft, Data& ft, const Pack
return StatusCode::FAILURE; // TODO: move to component, and define a dedicated error code
// Decision
ft.setDecision( pft.decision );
ft.setDecision( FlavourTag::TagResult{pft.decision} );
ft.setOmega( StandardPacker::fraction( pft.omega ) );
// OS Decision
ft.setDecisionOS( pft.decisionOS );
ft.setDecisionOS( FlavourTag::TagResult{pft.decisionOS} );
ft.setOmegaOS( StandardPacker::fraction( pft.omegaOS ) );
// Tagging B
......@@ -100,7 +100,7 @@ StatusCode FlavourTagPacker::unpack( const PackedData& pft, Data& ft, const Pack
// set the tagger members
tagger.setType( ptagger.type );
tagger.setDecision( ptagger.decision );
tagger.setDecision( Tagger::TagResult{ptagger.decision} );
tagger.setOmega( StandardPacker::fraction( ptagger.omega ) );
// tagging particles
......
......@@ -55,29 +55,17 @@ namespace LHCb {
typedef Gaudi::NamedRange_<ConstVector> Range;
/// Possible result of the tagging algorithm
enum TagResult { b = -1, bbar = 1, none = 0 };
friend std::ostream& operator<<( std::ostream& s, LHCb::FlavourTag::TagResult e ) {
switch ( e ) {
case LHCb::FlavourTag::b:
return s << "b";
case LHCb::FlavourTag::bbar:
return s << "bbar";
case LHCb::FlavourTag::none:
return s << "none";
default:
return s << "ERROR wrong value " << int( e ) << " for enum LHCb::FlavourTag::TagResult";
}
}
using TagResult = Tagger::TagResult;
/// Copy Constructor
FlavourTag( const FlavourTag& c )
: KeyedObject<int>()
, m_decision( c.decision() )
, m_omega( c.omega() )
, m_taggers( c.taggers() )
, m_decisionOS( c.decisionOS() )
, m_omegaOS( c.omegaOS() )
, m_taggedB( c.taggedB() ) {}
, m_decision( c.m_decision )
, m_omega( c.m_omega )
, m_taggers( c.m_taggers )
, m_decisionOS( c.m_decisionOS )
, m_omegaOS( c.m_omegaOS )
, m_taggedB( c.m_taggedB ) {}
/// Default Constructor
FlavourTag() = default;
......@@ -115,11 +103,11 @@ namespace LHCb {
}
/// Retrieve const The result of the tagging algorithm
[[nodiscard]] short int decision() const { return m_decision; }
[[nodiscard]] TagResult decision() const { return TagResult{m_decision}; }
/// Update The result of the tagging algorithm
FlavourTag& setDecision( short int value ) {
m_decision = value;
FlavourTag& setDecision( TagResult value ) {
m_decision = to_underlying( value );
return *this;
}
......@@ -145,11 +133,11 @@ namespace LHCb {
}
/// Retrieve const decision of opposite side taggers only
[[nodiscard]] short int decisionOS() const { return m_decisionOS; }
[[nodiscard]] TagResult decisionOS() const { return TagResult{m_decisionOS}; }
/// Update decision of opposite side taggers only
FlavourTag& setDecisionOS( short int value ) {
m_decisionOS = value;
FlavourTag& setDecisionOS( TagResult value ) {
m_decisionOS = to_underlying( value );
return *this;
}
......
......@@ -86,6 +86,12 @@ namespace LHCb {
SSLambdaDev = 20499
};
friend std::ostream& operator<<( std::ostream& s, TaggerType e );
enum struct TagResult : short int { b = -1, bbar = 1, none = 0 };
friend std::ostream& operator<<( std::ostream& s, TagResult e );
[[nodiscard]] friend std::underlying_type_t<TagResult> to_underlying( TagResult tr ) {
return static_cast<std::underlying_type_t<TagResult>>( tr );
} // FIXME: C++23: use std::to_underlying...
[[nodiscard]] friend TagResult reversed( TagResult tr ) { return static_cast<TagResult>( -to_underlying( tr ) ); }
/// Default Constructor
Tagger() = default;
......@@ -113,11 +119,11 @@ namespace LHCb {
}
/// Retrieve const decision of tagger
[[nodiscard]] short int decision() const { return m_decision; }
[[nodiscard]] TagResult decision() const { return TagResult{m_decision}; }
/// Update decision of tagger
Tagger& setDecision( short int value ) {
m_decision = value;
Tagger& setDecision( TagResult value ) {
m_decision = to_underlying( value );
return *this;
}
......
......@@ -70,6 +70,17 @@ namespace {
} // namespace
namespace LHCb {
std::ostream& operator<<( std::ostream& s, LHCb::Tagger::TagResult e ) {
switch ( e ) {
case Tagger::TagResult::b:
return s << "b";
case Tagger::TagResult::bbar:
return s << "bbar";
case Tagger::TagResult::none:
return s << "none";
}
return s << "ERROR wrong value " << int( e ) << " for enum LHCb::FlavourTag::TagResult";
}
std::ostream& operator<<( std::ostream& s, LHCb::Tagger::TaggerType e ) {
switch ( e ) {
case Tagger::none:
......
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