diff --git a/Event/EventPacker/include/Event/PackedTrack.h b/Event/EventPacker/include/Event/PackedTrack.h index ea8943ef3f93dc44e1d43a50845201b435651230..27ad4863ab6dff3456d97e7602da07a985040d62 100644 --- a/Event/EventPacker/include/Event/PackedTrack.h +++ b/Event/EventPacker/include/Event/PackedTrack.h @@ -166,7 +166,7 @@ namespace LHCb { const std::vector<std::pair<std::int32_t, std::int32_t>>& extras() const { return m_extra; } /// Default Packing Version - static char defaultPackingVersion() { return 5; } + static char defaultPackingVersion() { return 6; } /// Set the packing version void setPackingVersion( const char ver ) { m_packingVersion = ver; } @@ -176,6 +176,7 @@ namespace LHCb { /// Describe serialization of object template <typename T> void save( T& buf ) const { + buf.save( static_cast<uint8_t>( packingVersion() ) ); buf.save( static_cast<uint8_t>( version() ) ); buf.save( m_vect ); buf.save( m_state ); @@ -186,14 +187,18 @@ namespace LHCb { /// Describe de-serialization of object template <typename T> void load( T& buf ) { - setVersion( buf.template load<uint8_t>() ); - if ( version() < 4 || version() > 5 ) { - throw std::runtime_error( "PackedTracks packing version is not supported: " + std::to_string( version() ) ); + m_packingVersion = buf.template load<uint8_t>(); + if ( packingVersion() < 4 || packingVersion() > PackedTracks::defaultPackingVersion() ) { + throw std::runtime_error( "PackedTracks packing version is not supported: " + + std::to_string( packingVersion() ) ); } - buf.load( m_vect, version() ); - buf.load( m_state, version() ); + // Both packing version and DataObject version only saved to buffer since packing version 6 + const auto ver = ( 6 <= packingVersion() ? buf.template load<uint8_t>() : packingVersion() ); + setVersion( ver ); + buf.load( m_vect, ver ); + buf.load( m_state, ver ); buf.load( m_ids ); - buf.load( m_extra, version() ); + buf.load( m_extra, ver ); } private: @@ -260,12 +265,12 @@ namespace LHCb { /// Safe divide ... template <typename TYPE> static auto safe_divide( const TYPE a, const TYPE b ) { - return ( b != TYPE( 0 ) ? a / b : 9e9 ); + return ( b != TYPE( 0 ) ? a / b : TYPE( 9e9 ) ); } /// Check if the given packing version is supported bool isSupportedVer( const char ver ) const { - const bool OK = ( 0 <= ver && ver <= 5 ); + const bool OK = ( 0 <= ver && ver <= PackedTracks::defaultPackingVersion() ); if ( !OK ) { throw GaudiException( fmt::format( "Unknown packed data version {}", (int)ver ), "TrackPacker", StatusCode::FAILURE ); diff --git a/Event/EventPacker/src/component/BufferPackerBaseAlg.h b/Event/EventPacker/src/component/BufferPackerBaseAlg.h index 53cf9d9e814637565ced2b1327100100b01909e7..ef31870f3a776245cda507229a0fc26e4bd20c88 100644 --- a/Event/EventPacker/src/component/BufferPackerBaseAlg.h +++ b/Event/EventPacker/src/component/BufferPackerBaseAlg.h @@ -149,9 +149,11 @@ namespace DataPacking::Buffer { } } - if ( checksum ) - for ( const auto& x : checksum->checksums() ) - this->info() << "Packed data checksum for '" << x.first << "' = " << x.second << endmsg; + if ( checksum ) { + for ( const auto& x : checksum->checksums() ) { + this->info() << "Packed data checksum for '" << x.first << "' = " << std::hex << x.second << endmsg; + } + } return bigBuffer; } diff --git a/Event/EventPacker/src/component/BufferRelationPackerBaseAlg.h b/Event/EventPacker/src/component/BufferRelationPackerBaseAlg.h index fa5fb5f82b1faa82e24f8c852d0b4362246ee7b9..0a78124ff86f77e96f217709d2f9d2c67ec05000 100644 --- a/Event/EventPacker/src/component/BufferRelationPackerBaseAlg.h +++ b/Event/EventPacker/src/component/BufferRelationPackerBaseAlg.h @@ -143,9 +143,11 @@ namespace DataPacking::Buffer { } } - if ( checksum ) - for ( const auto& x : checksum->checksums() ) - this->info() << "Packed data checksum for '" << x.first << "' = " << x.second << endmsg; + if ( checksum ) { + for ( const auto& x : checksum->checksums() ) { + this->info() << "Packed data checksum for '" << x.first << "' = " << std::hex << x.second << endmsg; + } + } return bigBuffer; } diff --git a/Event/EventPacker/src/lib/PackedTrack.cpp b/Event/EventPacker/src/lib/PackedTrack.cpp index c6d8ec458e59ee0970f3d2ee5966185949488bee..9560822a41e77008d1b9382da593295ac158e33f 100644 --- a/Event/EventPacker/src/lib/PackedTrack.cpp +++ b/Event/EventPacker/src/lib/PackedTrack.cpp @@ -14,12 +14,40 @@ using namespace LHCb; +namespace { + auto getUnPackingVersion( const TrackPacker::PackedDataVector& ptracks ) { + // Packing version + auto pver = ptracks.packingVersion(); + // Work around for old data that (ab)used the DataObject version for the packing version and + // does not have an explicit packingVersion saved in the data. In this case the ROOT schema + // evolution simply fills this member with the default value, which is defaultPackingVersion(). + // We attempt to detect this here and correct the packing version to the older value. + // This is only needed as long as we need support for older DataObject based persistency. + // Note since packing version 6 the packing and data object versions are force to be the same + // (see comment below in the pack method) so work around is skipped for ver >= 6. + const auto ver = ptracks.version(); + if ( pver == PackedTracks::defaultPackingVersion() && pver > ver && ver < 6 ) { pver = ver; } + return pver; + } +} // namespace + void TrackPacker::pack( const Data& track, PackedData& ptrack, PackedDataVector& ptracks ) const { - // check version - ptracks.setVersion( 5 ); - const auto ver = ptracks.version(); - if ( !isSupportedVer( ver ) ) return; + // check versions + const auto pver = ptracks.packingVersion(); + if ( !isSupportedVer( pver ) ) { return; } + + // work around for the fact in old data there was no explicit packing version and + // the DataObject version of the packed container was (ab)used for this. + // To handle this for the old DataObject based event model and packing ensure + // the two values are synchronised... + // This should not be done when we migrate to the packing for the new event model where + // DataObject should not be used anywhere... + ptracks.setVersion( pver ); + + if ( parent().msgLevel( MSG::DEBUG ) ) { + parent().debug() << "pack : PackingVer=" << (int)pver << " DataVer=" << (int)ptracks.version() << endmsg; + } ptrack.chi2PerDoF = StandardPacker::fltPacked( track.chi2PerDoF() ); ptrack.nDoF = track.nDoF(); @@ -51,10 +79,9 @@ void TrackPacker::pack( const Data& track, PackedData& ptrack, PackedDataVector& void TrackPacker::pack( const DataVector& tracks, PackedDataVector& ptracks ) const { // check version - ptracks.setVersion( 5 ); - const auto ver = ptracks.version(); - - if ( !isSupportedVer( ver ) ) return; + const auto pver = ptracks.packingVersion(); + if ( !isSupportedVer( pver ) ) { return; } + // pack ptracks.data().reserve( tracks.size() ); for ( const auto* track : tracks ) { if ( !track ) continue; @@ -81,12 +108,11 @@ void TrackPacker::convertState( const LHCb::State& state, PackedDataVector& ptra p = StandardPacker::energy( newState.p ); // convariance Matrix - std::vector<double> err; - err.push_back( safe_sqrt( state.errX2() ) ); - err.push_back( safe_sqrt( state.errY2() ) ); - err.push_back( safe_sqrt( state.errTx2() ) ); - err.push_back( safe_sqrt( state.errTy2() ) ); - err.push_back( safe_sqrt( state.errQOverP2() ) ); + const auto err = std::array{safe_sqrt( state.errX2() ), // + safe_sqrt( state.errY2() ), // + safe_sqrt( state.errTx2() ), // + safe_sqrt( state.errTy2() ), // + safe_sqrt( state.errQOverP2() )}; newState.cov_00 = StandardPacker::position( err[0] ); newState.cov_11 = StandardPacker::position( err[1] ); @@ -109,9 +135,13 @@ void TrackPacker::convertState( const LHCb::State& state, PackedDataVector& ptra void TrackPacker::unpack( const PackedData& ptrack, Data& track, const PackedDataVector& ptracks, DataVector& /* tracks */ ) const { - // Check version - const auto ver = ptracks.version(); - if ( !isSupportedVer( ver ) ) return; + // check packing version + const auto pver = getUnPackingVersion( ptracks ); + if ( !isSupportedVer( pver ) ) { return; } + + if ( parent().msgLevel( MSG::DEBUG ) ) { + parent().debug() << "unpack : PackingVer=" << (int)pver << " DataVer=" << (int)ptracks.version() << endmsg; + } // Try and detect changes that require the cached wrap IDs to be reset. // trigger a reset if a new packed container is detected, or if the @@ -125,17 +155,17 @@ void TrackPacker::unpack( const PackedData& ptrack, Data& track, const PackedDat track.setChi2PerDoF( StandardPacker::fltPacked( ptrack.chi2PerDoF ) ); track.setNDoF( ptrack.nDoF ); track.setFlags( ptrack.flags ); - if ( ver > 2 ) { + if ( pver > 2 ) { track.setLikelihood( StandardPacker::fltPacked( ptrack.likelihood ) ); track.setGhostProbability( StandardPacker::fltPacked( ptrack.ghostProba ) ); } // extract the first and last ID for the LHCbIDs - int firstId = ptrack.firstId; - int lastId = ptrack.lastId; + auto firstId = ptrack.firstId; + auto lastId = ptrack.lastId; // Apply protection for short int wrapping - if ( ver < 5 && ptracks.ids().size() > std::numeric_limits<uint8_t>::max() ) { + if ( pver < 5 && ptracks.ids().size() > std::numeric_limits<uint8_t>::max() ) { firstId = m_firstIdHigh + ptrack.firstId; lastId = m_lastIdHigh + ptrack.lastId; if ( lastId < firstId ) { // we wrapped in the track @@ -156,17 +186,43 @@ void TrackPacker::unpack( const PackedData& ptrack, Data& track, const PackedDat std::vector<LHCb::LHCbID> lhcbids; lhcbids.reserve( lastId - firstId ); std::transform( std::next( ptracks.ids().begin(), firstId ), std::next( ptracks.ids().begin(), lastId ), - std::back_inserter( lhcbids ), []( const int i ) { return LHCb::LHCbID( i ); } ); + std::back_inserter( lhcbids ), [&pver]( const auto i ) { + LHCb::LHCbID id( i ); + if ( pver < 6 ) { + // Fixup channelIDtype for old (<6) data + // Adapts to https://gitlab.cern.ch/lhcb/LHCb/-/merge_requests/3226 + enum class OLD_channelIDtype { Velo = 1, TT, IT, OT, Rich, Calo, Muon, VP, FT = 10, UT, HC }; + const auto dtype = (int)id.detectorType(); + if ( (int)OLD_channelIDtype::VP == dtype ) { + id.setDetectorType( LHCb::LHCbID::channelIDtype::VP ); + } else if ( (int)OLD_channelIDtype::UT == dtype ) { + id.setDetectorType( LHCb::LHCbID::channelIDtype::UT ); + } else if ( (int)OLD_channelIDtype::FT == dtype ) { + id.setDetectorType( LHCb::LHCbID::channelIDtype::FT ); + } else if ( (int)OLD_channelIDtype::Rich == dtype ) { + id.setDetectorType( LHCb::LHCbID::channelIDtype::Rich ); + } else if ( (int)OLD_channelIDtype::Calo == dtype ) { + id.setDetectorType( LHCb::LHCbID::channelIDtype::Calo ); + } else if ( (int)OLD_channelIDtype::Muon == dtype ) { + id.setDetectorType( LHCb::LHCbID::channelIDtype::Muon ); + } else { + // For sub-systems no longer defined .. + id.setDetectorType( LHCb::LHCbID::channelIDtype::UNDEFINED ); + } + } + return id; + } ); // schema change: sorting no longer needed when we write DSTs with sorted lhcbids - if ( ver <= 1 ) { std::sort( lhcbids.begin(), lhcbids.end() ); } + // Update: Always (re)sort after modifications above (i.e. pver < 6). + if ( pver < 6 ) { std::sort( lhcbids.begin(), lhcbids.end() ); } track.addSortedToLhcbIDs( lhcbids ); // extract the first and last indices for the states for this track - int firstState = ptrack.firstState; - int lastState = ptrack.lastState; + auto firstState = ptrack.firstState; + auto lastState = ptrack.lastState; // protection for short int wrapping - if ( ver < 5 && ptracks.states().size() > std::numeric_limits<uint8_t>::max() ) { + if ( pver < 5 && ptracks.states().size() > std::numeric_limits<uint8_t>::max() ) { firstState = m_firstStateHigh + ptrack.firstState; lastState = m_lastStateHigh + ptrack.lastState; if ( lastState < firstState ) { // we wrapped in the track @@ -189,11 +245,11 @@ void TrackPacker::unpack( const PackedData& ptrack, Data& track, const PackedDat { this->convertState( s, track ); } ); // extract the first and last extra info indices - int firstExtra = ptrack.firstExtra; - int lastExtra = ptrack.lastExtra; + auto firstExtra = ptrack.firstExtra; + auto lastExtra = ptrack.lastExtra; // protect against short int wrapping - if ( ver < 5 && ptracks.extras().size() > std::numeric_limits<uint8_t>::max() ) { + if ( pver < 5 && ptracks.extras().size() > std::numeric_limits<uint8_t>::max() ) { firstExtra = m_firstExtraHigh + ptrack.firstExtra; lastExtra = m_lastExtraHigh + ptrack.lastExtra; if ( lastExtra < firstExtra ) { // we wrapped in the track @@ -218,7 +274,7 @@ void TrackPacker::unpack( const PackedData& ptrack, Data& track, const PackedDat } ); //== Cleanup extraInfo and set likelihood/ghostProbability for old data - if ( ver <= 2 ) { + if ( pver <= 2 ) { track.eraseInfo( LHCb::Track::AdditionalInfo::PatQuality ); track.eraseInfo( LHCb::Track::AdditionalInfo::Cand1stQPat ); track.eraseInfo( LHCb::Track::AdditionalInfo::Cand2ndQPat ); @@ -233,9 +289,10 @@ void TrackPacker::unpack( const PackedData& ptrack, Data& track, const PackedDat } void TrackPacker::unpack( const PackedDataVector& ptracks, DataVector& tracks ) const { + // Check version - const auto ver = ptracks.version(); - if ( !isSupportedVer( ver ) ) return; + const auto pver = getUnPackingVersion( ptracks ); + if ( !isSupportedVer( pver ) ) { return; } // reserve the required size tracks.reserve( ptracks.data().size() ); diff --git a/Event/RecEvent/include/Event/RecVertex_v2.h b/Event/RecEvent/include/Event/RecVertex_v2.h index 03833dac6e79f603cc2e21cddcba4c3d3c7d6deb..e9738e6888e08c11a0eb46adaf977b4ce8b1059a 100644 --- a/Event/RecEvent/include/Event/RecVertex_v2.h +++ b/Event/RecEvent/include/Event/RecVertex_v2.h @@ -46,9 +46,9 @@ namespace LHCb::Event::v2 { /// helper class to bundle a Track and its weight struct WeightedTrack { using Track = LHCb::Event::v2::Track; - WeightedTrack( const Track* t, float w ) : track( t ), weight( w ){}; - const Track* track; - float weight; + WeightedTrack( const Track* t, float w ) : track( t ), weight( w ) {} + const Track* track = nullptr; + float weight = 0.0; }; /// Reconstructed Vertices class diff --git a/Kernel/LHCbKernel/include/Kernel/LHCbID.h b/Kernel/LHCbKernel/include/Kernel/LHCbID.h index aea797c2e1475770a35dbd72ca5866a2082818d1..ff96cb7a19793f83c8dfc32514fa2543ec226b6b 100644 --- a/Kernel/LHCbKernel/include/Kernel/LHCbID.h +++ b/Kernel/LHCbKernel/include/Kernel/LHCbID.h @@ -31,16 +31,17 @@ namespace LHCb { public: /// types of sub-detector channel ID enum class channelIDtype { - Plume = 1, - VP = 2, - UT, + UNDEFINED = 0, + Plume = 1, + VP = 2, + UT = 3, reserved_magnet_sidestations = 4, FT = 5, reserved_mighty_tracker = 6, reserved_torch = 7, Rich = 8, - Calo, - Muon + Calo = 9, + Muon = 10 }; /// Default Constructor