ATLAS Offline Software
Loading...
Searching...
No Matches
PseudoJetMerger.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <numeric> // for std::accumulate
6
10
12 ATH_MSG_DEBUG("Initializing...");
13
14 if(m_inputPJC.empty() || m_outcoll.key().empty()) {
15 if(m_inputPJC.empty() ) { ATH_MSG_ERROR("Input container array is empty! "<< m_inputPJC.size() );}
16 else {ATH_MSG_ERROR("OutputContainer container array is empty! "<< m_outcoll.key() );}
17 return StatusCode::FAILURE;
18 }
19
20 // Ugly check but no other good way of testing at initialisation
21 auto add_if_ghost = [](unsigned int sum_ghosts, const SG::ReadHandleKey<PseudoJetContainer>& pjckey) {
22 return sum_ghosts + (pjckey.key().find("Ghost")!=std::string::npos);
23 };
24 unsigned int N_ghosts = std::accumulate(m_inputPJC.begin(), m_inputPJC.end(), 0, add_if_ghost);
25 if(m_inputPJC.size()-N_ghosts!=1) {
26 ATH_MSG_ERROR("List of input pseudojet containers to be merged must have exactly one non-ghost collection!");
27 return StatusCode::FAILURE;
28 }
29
30 ATH_CHECK( m_inputPJC.initialize() );
31 ATH_CHECK( m_outcoll.initialize() );
32
33 return StatusCode::SUCCESS;
34}
35
36
37StatusCode PseudoJetMerger::execute(const EventContext& ctx) const {
38
39 auto allPseudoJets = std::make_unique<PseudoJetContainer>();
40
41 for (const auto& pjcKey : m_inputPJC) {
42 SG::ReadHandle<PseudoJetContainer> pjcHandle( pjcKey, ctx );
43 if(!pjcHandle.isValid()){
44 ATH_MSG_ERROR("Can't retrieve PseudoJetContainer "<< pjcKey.key() ); return StatusCode::FAILURE;
45 }
46 allPseudoJets->append( pjcHandle.get() );
47 }
48
50 ATH_MSG_DEBUG("Merged PseudoJetContainer \"" << m_outcoll.key() << "\" has size " << allPseudoJets->size());
51 ATH_CHECK( outHandle.record(std::move(allPseudoJets)) );
52
53 return StatusCode::SUCCESS;
54}
55
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
SG::ReadHandleKeyArray< PseudoJetContainer > m_inputPJC
virtual StatusCode execute(const EventContext &ctx) const override final
virtual StatusCode initialize() override
Initialization.
SG::WriteHandleKey< PseudoJetContainer > m_outcoll
Output collection name.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138