Skip to content
Snippets Groups Projects
Commit 1b83d173 authored by Arthur Marius Hennequin's avatar Arthur Marius Hennequin
Browse files

Add debug jsonDump to SOACollections, add missing mask in copy_back from proxy

parent 0fbc3359
No related branches found
No related tags found
1 merge request!3907SOACollection particlev2
Pipeline #5239711 passed
......@@ -130,11 +130,7 @@ namespace LHCb::Event {
template <SIMDWrapper::InstructionSet simd, typename ProxyType>
[[gnu::always_inline]] inline void copy_back( ProxyType const& from ) {
using simd_t = typename SIMDWrapper::type_map_t<simd>;
reserve_exponential( m_size + simd_t::size );
m_data_tree->template copy_back<simd_t>( m_size, *from.container()->m_data_tree, from.offset(),
std::true_type{} );
m_size += simd_t::size;
copy_back<simd>( from, from.loop_mask() );
}
template <SIMDWrapper::InstructionSet simd, typename ProxyType>
......@@ -384,6 +380,16 @@ namespace LHCb::Event {
return SOAPackStruct<Tags...>::checkEqual( *static_cast<const Derived*>( this ), other );
}
void jsonDump( std::ostream& os ) const {
os << "[" << std::endl;
for ( std::size_t i = 0; i < size(); i++ ) {
SOAPackStruct<Tags...>::jsonDump( os, i, *this );
if ( i < size() - 1 ) os << ",";
os << std::endl;
}
os << "]" << std::endl;
}
uint32_t version() const { return m_version; }
void setVersion( uint32_t version ) { m_version = version; }
......
......@@ -61,6 +61,10 @@ namespace LHCb::Event {
}
return true;
}
template <typename Collection, typename Path>
static void jsonDump( std::ostream& os, std::size_t at, const Collection& collection, Path path ) {
os << collection.data( path )[at];
}
};
template <typename T, typename scale = std::ratio<1, 1>>
......@@ -113,6 +117,10 @@ namespace LHCb::Event {
}
return true;
}
template <typename Collection, typename Path>
static void jsonDump( std::ostream& os, std::size_t at, const Collection& collection, Path path ) {
os << collection.data( path )[at];
}
};
struct SOADontPack {
......@@ -124,6 +132,10 @@ namespace LHCb::Event {
static bool checkEqual( const Collection&, const Collection&, Path ) {
return true;
}
template <typename Collection, typename Path>
static void jsonDump( std::ostream& os, std::size_t, const Collection&, Path ) {
os << "\"NOT_PACKED\"";
}
};
template <std::size_t version, typename trueType, typename falseType = SOADontPack>
......@@ -149,6 +161,14 @@ namespace LHCb::Event {
if ( A.version() >= version ) { return trueType::checkEqual( A, B, path ); }
return falseType::checkEqual( A, B, path );
}
template <typename Collection, typename Path>
static void jsonDump( std::ostream& os, std::size_t at, const Collection& collection, Path path ) {
if ( collection.version() >= version ) {
trueType::jsonDump( os, at, collection, path );
} else {
falseType::jsonDump( os, at, collection, path );
}
}
};
template <typename T, typename SizeTag>
......@@ -190,6 +210,16 @@ namespace LHCb::Event {
}
return true;
}
template <typename Collection, typename Path>
static void jsonDump( std::ostream& os, std::size_t at, const Collection& collection, Path path ) {
os << "[";
std::size_t size = collection.data( path.template append<std::true_type>() )->sizes().data()[at];
for ( std::size_t i = 0; i < size; i++ ) {
T::jsonDump( os, at, collection, path.append( i ) );
if ( i < size - 1 ) os << ",";
}
os << "]";
}
};
template <typename T, std::size_t... Ns>
......@@ -211,6 +241,15 @@ namespace LHCb::Event {
}
return true;
}
template <typename Collection, typename Path>
static void jsonDump( std::ostream& os, std::size_t at, const Collection& collection, Path path ) {
os << "[";
for ( std::size_t i = 0; i < ( 1 * ... * Ns ); i++ ) { // TODO: true Nd array
T::jsonDump( os, at, collection, path.append( i ) );
if ( i < ( 1 * ... * Ns ) - 1 ) os << ",";
}
os << "]";
}
};
template <typename T, std::size_t N>
......@@ -232,6 +271,15 @@ namespace LHCb::Event {
}
return true;
}
template <typename Collection, typename Path>
static void jsonDump( std::ostream& os, std::size_t at, const Collection& collection, Path path ) {
os << "[";
for ( std::size_t i = 0; i < N; i++ ) {
T::jsonDump( os, at, collection, path.append( i ) );
if ( i < N - 1 ) os << ",";
}
os << "]";
}
};
template <typename... Tags>
......@@ -296,5 +344,33 @@ namespace LHCb::Event {
static bool checkEqual( const Collection& A, const Collection& B ) {
return ( checkEqual_debug<Tags>( A, B, SOAPath<Tags>{std::make_tuple( Tags{} )} ) && ... );
}
template <typename Tag>
static std::string tagName() {
auto n = System::typeinfoName( typeid( Tag ) );
return n.substr( n.find_last_of( ':' ) + 1 );
}
template <typename Collection, typename Path>
static void jsonDump( std::ostream& os, std::size_t at, const Collection& collection, Path path ) {
os << "{";
std::size_t i{0};
( ( os << "\"" << tagName<Tags>() << "\":",
Tags::packer_t::jsonDump( os, at, collection, path.template append<Tags>() ),
os << ( ++i != sizeof...( Tags ) ? "," : "" ) ),
... );
os << "}";
}
template <typename Collection>
static void jsonDump( std::ostream& os, std::size_t at, const Collection& collection ) {
os << "{";
std::size_t i{0};
( ( os << "\"" << tagName<Tags>() << "\":",
Tags::packer_t::jsonDump( os, at, collection, SOAPath<Tags>{std::make_tuple( Tags{} )} ),
os << ( ++i != sizeof...( Tags ) ? "," : "" ) ),
... );
os << "}";
}
};
} // namespace LHCb::Event
......@@ -83,4 +83,25 @@ BOOST_AUTO_TEST_CASE( test_packer ) {
// Check collections are different
BOOST_CHECK( !test.checkEqual( test_unpacked ) );
}
BOOST_AUTO_TEST_CASE( test_jsondump ) {
std::size_t n = 20;
TrackLike test{};
for ( std::size_t i = 0; i < n; i++ ) {
auto proxy = test.emplace_back<SIMDWrapper::InstructionSet::Scalar>();
proxy.field<A>().set( i );
proxy.field<B>().set( 0.5f * i );
proxy.field<E>().set( 100.f * i );
auto v = proxy.field<V>();
v.resize( i );
for ( std::size_t j = 0; j < i; j++ ) { v[j].set( j ); }
auto vempty = proxy.field<Vempty>();
vempty.resize( 19 - i );
for ( std::size_t j = 0; j < 19 - i; j++ ) {
vempty[j].template field<LHCbID>().set( SIMDWrapper::scalar::int_v{static_cast<int>( j )} );
}
}
test.jsonDump( std::cout );
}
\ No newline at end of file
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