ATLAS Offline Software
ViewMergeAlg.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 // AthExStoreGateExample includes
6 #include "ViewMergeAlg.h"
7 #include "AthViews/ViewHelper.h"
8 
9 // STL includes
10 
11 // FrameWork includes
12 #include "Gaudi/Property.h"
13 #include "StoreGate/ReadHandle.h"
14 #include "StoreGate/WriteHandle.h"
15 
16 namespace AthViews {
17 
19 // Public methods:
21 
22 // Constructors
24 ViewMergeAlg::ViewMergeAlg( const std::string& name,
25  ISvcLocator* pSvcLocator ) :
26  ::AthAlgorithm( name, pSvcLocator ),
27  m_r_ints( "dflow_ints" )
28 {
29 }
30 
31 // Destructor
34 {}
35 
36 // Athena Algorithm's Hooks
39 {
40  ATH_MSG_INFO ("Initializing " << name() << "...");
41 
45 
46  return StatusCode::SUCCESS;
47 }
48 
50 {
51  ATH_MSG_INFO ("Finalizing " << name() << "...");
52 
53  return StatusCode::SUCCESS;
54 }
55 
57 {
58  ATH_MSG_DEBUG ("Executing " << name() << "...");
59 
60  const EventContext& ctx = getContext();
61 
62  //Merge results
63  std::vector< int > outputVector;
64  SG::ReadHandle< ViewContainer > inputViews( m_r_views, ctx );
65  ViewHelper::ViewMerger merger( evtStore().get(), msg() );
66  CHECK( merger.mergeViewCollection( *inputViews, //Vector of views (inside ReadHandle)
67  m_r_ints, //ReadHandleKey to access the views
68  ctx, //The context of this algorithm
69  outputVector ) ); //Container to merge results into
70 
71  //Output the merged data
72  SG::WriteHandle< std::vector< int > > outputHandle( m_w_ints, ctx );
73  CHECK( outputHandle.record( std::make_unique< std::vector< int > >( outputVector ) ) );
74  if ( !outputHandle.isValid() )
75  {
76  ATH_MSG_INFO( "Unable to load main event store for output" );
77  }
78 
79  for ( int const test : outputVector )
80  {
81  ATH_MSG_INFO( test );
82  }
83 
84  return StatusCode::SUCCESS;
85 }
86 
87 } //> end namespace AthViews
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthViews::ViewMergeAlg::~ViewMergeAlg
virtual ~ViewMergeAlg()
Destructor:
Definition: ViewMergeAlg.cxx:33
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ViewMergeAlg.h
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:146
AthViews::ViewMergeAlg::m_r_ints
SG::ReadHandleKey< std::vector< int > > m_r_ints
Definition: ViewMergeAlg.h:50
ViewHelper.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
WriteHandle.h
Handle class for recording to StoreGate.
AthViews::ViewMergeAlg::finalize
virtual StatusCode finalize()
Definition: ViewMergeAlg.cxx:49
AthViews::ViewMergeAlg::execute
virtual StatusCode execute()
Definition: ViewMergeAlg.cxx:56
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AthViews
Definition: ViewDataVerifier.cxx:18
ViewHelper::ViewMerger::mergeViewCollection
StatusCode mergeViewCollection(ViewContainer const &viewVector, SG::ReadHandleKey< T > const &queryKey, EventContext const &sourceContext, T &outputData)
Definition: ViewHelper.h:143
AthViews::ViewMergeAlg::ViewMergeAlg
ViewMergeAlg()
Default constructor:
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.
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
ViewHelper::ViewMerger
Definition: ViewHelper.h:134
ReadHandle.h
Handle class for reading from StoreGate.
AthViews::ViewMergeAlg::m_r_views
SG::ReadHandleKey< ViewContainer > m_r_views
Definition: ViewMergeAlg.h:51
AthViews::ViewMergeAlg::m_w_ints
SG::WriteHandleKey< std::vector< int > > m_w_ints
Definition: ViewMergeAlg.h:49
AthViews::ViewMergeAlg::initialize
virtual StatusCode initialize()
Definition: ViewMergeAlg.cxx:38