ATLAS Offline Software
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() );
32 
33  return StatusCode::SUCCESS;
34 }
35 
36 
37 StatusCode 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 
WriteHandle.h
Handle class for recording to StoreGate.
PseudoJetMerger::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: PseudoJetMerger.cxx:37
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::ReadHandleKey< PseudoJetContainer >
PseudoJetMerger.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PseudoJetMerger::m_inputPJC
SG::ReadHandleKeyArray< PseudoJetContainer > m_inputPJC
Definition: PseudoJetMerger.h:55
PseudoJetMerger::m_outcoll
SG::WriteHandleKey< PseudoJetContainer > m_outcoll
Output collection name.
Definition: PseudoJetMerger.h:58
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ReadHandle.h
Handle class for reading from StoreGate.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
PseudoJetMerger::initialize
virtual StatusCode initialize() override
Initialization.
Definition: PseudoJetMerger.cxx:11