Skip to content
Snippets Groups Projects
Commit 5ffbee85 authored by Michel De Cian's avatar Michel De Cian Committed by Rosen Matev
Browse files

Add templated mergers

parent cec9b7ca
No related branches found
No related tags found
1 merge request!3665Add templated mergers
/*****************************************************************************\
* (c) Copyright 2000-2022 CERN for the benefit of the LHCb Collaboration *
* *
* This software is distributed under the terms of the GNU General Public *
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
* *
* In applying this licence, CERN does not waive the privileges and immunities *
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
\*****************************************************************************/
/** @class SOACollectionMerger.h SOACollectionMerger
*
* Merge SOACollections into one. Template to work with all containers based on SOACollection.
*
* @author Michel De Cian
* @date 05/07/2022
*/
#include "Event/SOACollection.h"
#include "LHCbAlgs/MergingTransformer.h"
#include <string>
namespace LHCb {
template <typename Type>
struct SOACollectionMerger final
: Algorithm::MergingTransformer<Type( const Gaudi::Functional::vector_of_const_<Type>& )> {
SOACollectionMerger( const std::string& name, ISvcLocator* pSvcLocator )
: Algorithm::MergingTransformer<Type( const Gaudi::Functional::vector_of_const_<Type>& )>{
name, pSvcLocator, {"InputLocations", {}}, {"OutputLocation", {}}} {}
Type operator()( const Gaudi::Functional::vector_of_const_<Type>& lists ) const override {
if ( lists.size() == 0 ) return {};
Type out( lists[0].zipIdentifier(), lists[0].get_allocator() );
std::size_t overallSize = 0;
for ( const auto& list : lists ) overallSize += list.size();
out.reserve( overallSize );
m_nbObjectsCounter += overallSize;
for ( const auto& list : lists ) {
if ( list.empty() ) continue;
for ( const auto& obj : list.simd() ) {
out.template copy_back<SIMDWrapper::best::types>( list, obj.offset(), obj.loop_mask() );
}
}
return out;
}
private:
mutable Gaudi::Accumulators::SummingCounter<> m_nbObjectsCounter{this, "Nb of Merged Objects"};
};
} // namespace LHCb
/*****************************************************************************\
* (c) Copyright 2000-2022 CERN for the benefit of the LHCb Collaboration *
* *
* This software is distributed under the terms of the GNU General Public *
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
* *
* In applying this licence, CERN does not waive the privileges and immunities *
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
\*****************************************************************************/
/** @class SOACollectionMerger.h SOACollectionMerger
*
* Merge several std::vector<Type> into one. Template to work with all std::vector<Type>
*
* @author Michel De Cian
* @date 24/08/2022
*/
#include "LHCbAlgs/MergingTransformer.h"
#include <string>
namespace LHCb {
template <typename Type, typename Container = std::vector<Type>>
struct VectorOfObjectsMerger final
: Algorithm::MergingTransformer<Container( const Gaudi::Functional::vector_of_const_<Container>& )> {
VectorOfObjectsMerger( const std::string& name, ISvcLocator* pSvcLocator )
: Algorithm::MergingTransformer<Container( const Gaudi::Functional::vector_of_const_<Container>& )>{
name, pSvcLocator, {"InputLocations", {}}, {"OutputLocation", {}}} {}
Container operator()( const Gaudi::Functional::vector_of_const_<Container>& lists ) const override {
if ( lists.size() == 0 ) return {};
Container out;
std::size_t overallSize = 0;
for ( const auto& list : lists ) overallSize += list.size();
out.reserve( overallSize );
m_nbObjectsCounter += overallSize;
for ( const auto& list : lists ) {
if ( list.empty() ) continue;
out.insert( out.end(), list.begin(), list.end() );
}
return out;
}
private:
mutable Gaudi::Accumulators::SummingCounter<> m_nbObjectsCounter{this, "Nb of Merged Objects"};
};
} // namespace LHCb
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