Skip to content
Snippets Groups Projects
Commit 58937fd7 authored by Abhijit Mathad's avatar Abhijit Mathad Committed by Patrick Koppenburg
Browse files

Add multiple candidate info with a switch

parent dc445a9b
No related branches found
No related tags found
1 merge request!980Add multiple candidate info with a switch
......@@ -222,6 +222,10 @@ protected:
// function for filling void functors
void fill_void_func_output( const Tuples::Tuple& ntuple ) const;
// function for filling multiple candidate info
void fill_multiple_cand_info( const Tuples::Tuple& ntuple, const std::size_t totcand,
const unsigned int icand ) const;
// function for filling loki functors
void fill_loki_func_output( const typename LHCb::InputTypeSignature<T>::LoKiItemType& cand,
const unsigned int& nfield, const Tuples::Tuple& ntuple ) const;
......@@ -267,6 +271,10 @@ private:
Gaudi::Property<std::vector<std::string>> m_preamble_def_loki{this, "loki_preamble", {}, "List of preamble strings"};
std::string m_preamble_loki;
/// boolean to store multiple candidate information (default: false)
Gaudi::Property<bool> m_store_multiple_cand_info{this, "store_multiple_cand_info", false,
"Store the candidate index and the total number of candidates"};
//// Loki functor factory
ToolHandle<typename LHCb::InputTypeSignature<T>::LoKiFactory> m_factory_loki = {
LHCb::InputTypeSignature<T>::LoKiFactoryString, this};
......@@ -694,12 +702,18 @@ void FunTupleBase<T>::write_tuple( const LHCb::FTuple::retype<T>& vector_of_cand
if ( this->msgLevel( MSG::DEBUG ) ) { debug << "write_tuple: Candidates found booking their info" << endmsg; }
Tuples::Tuple ntuple = this->nTuple( m_ntupleTname );
for ( unsigned int ncand = 0; ncand < vector_of_cands[0].size(); ncand++ ) { // number of cands (write tuple)
// total number of candidates
std::size_t totcand{vector_of_cands[0].size()};
for ( unsigned int icand = 0; icand < vector_of_cands[0].size(); icand++ ) { // number of cands (write tuple)
// if requested store the total number of candidates and the candidate index
if ( m_store_multiple_cand_info ) fill_multiple_cand_info( ntuple, totcand, icand );
// fill void functors
fill_void_func_output( ntuple );
for ( unsigned int nfield = 0; nfield < vector_of_cands.size();
nfield++ ) { // number of fields i.e decay descriptors
// get the particle
const auto cand = vector_of_cands[nfield][ncand];
const auto cand = vector_of_cands[nfield][icand];
// fill loki functors
if ( !m_all_empty_lokifuncs ) fill_loki_func_output( *cand, nfield, ntuple );
// fill thor functors
......@@ -733,7 +747,14 @@ void FunTupleBase<T>::write_tuple( const LHCb::FTuple::retype<T>& vector_of_cand
// Hard code "nfield" to zero ie head of the decay here
unsigned int nfield{0};
auto const iterable = LHCb::Event::make_zip<SIMDWrapper::Scalar>( vector_of_cands );
// total number of candidates
std::size_t totcand{vector_of_cands.size()};
unsigned int icand{0};
for ( auto const& cand : iterable ) { // number of cands (write tuple)
// if requested store the total number of candidates and the candidate index
if ( m_store_multiple_cand_info ) fill_multiple_cand_info( ntuple, totcand, icand );
// fill void functors
fill_void_func_output( ntuple );
// fill thor functors
if ( !m_all_empty_thorfuncs ) fill_thor_func_output( cand, nfield, ntuple );
......@@ -741,6 +762,9 @@ void FunTupleBase<T>::write_tuple( const LHCb::FTuple::retype<T>& vector_of_cand
if ( this->msgLevel( MSG::DEBUG ) ) { debug << "write_tuple: Writing tuple after booking" << endmsg; }
StatusCode sc_write = ntuple->write();
if ( sc_write.isFailure() ) { this->err() << "Unable to write the tuple" << endmsg; }
// increment counter
++icand;
}
}
......@@ -771,6 +795,23 @@ void FunTupleBase<T>::fill_void_func_output( const Tuples::Tuple& ntuple ) const
}
}
template <class T>
void FunTupleBase<T>::fill_multiple_cand_info( const Tuples::Tuple& ntuple, const std::size_t totcand,
const unsigned int icand ) const {
// A warning is raised by GaudiTupleAlg about "'unsigned long' has different sizes on 32/64 bit systems, casting
// 'totCandidates' to 'unsigned long long'". To avoid this warning thrown after event loop, we cast the size_t to
// unsigned long long here itself.
// See also issue: https://gitlab.cern.ch/lhcb/DaVinci/-/issues/48
StatusCode sc_totcand = ntuple->column( "totCandidates", static_cast<unsigned long long>( totcand ) );
if ( sc_totcand.isFailure() )
throw GaudiException( "Error booking the total number of candidates (totCandidates)", "write_tuple",
StatusCode::FAILURE );
StatusCode sc_ncand = ntuple->column( "nCandidate", icand );
if ( sc_ncand.isFailure() )
throw GaudiException( "Error booking the candidate number (nCandidate)", "write_tuple", StatusCode::FAILURE );
}
template <class T>
void FunTupleBase<T>::fill_loki_func_output( const typename LHCb::InputTypeSignature<T>::LoKiItemType& cand,
const unsigned int& nfield, const Tuples::Tuple& ntuple ) const {
......
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