ATLAS Offline Software
Loading...
Searching...
No Matches
MySelectionAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
10
12#include "CLHEP/Units/SystemOfUnits.h"
13
15
16
17using CLHEP::GeV;
18using namespace AthPyEx;
19
20
21MySelectionAlg::MySelectionAlg (const std::string& name, ISvcLocator* pSvcLocator)
22 : AthAlgorithm(name, pSvcLocator),
23 m_ThrPT(10*GeV),
24 m_NewKey("MyNewContainer"),
25 m_ContainerKey("ElectronCollection"),
26 m_cut(0),
27 m_myTool(0)
28{
29 declareProperty("ThrPT", m_ThrPT);
30 declareProperty("NewKey", m_NewKey);
31 declareProperty("ContainerKey", m_ContainerKey);
32}
33
34// Initialize
36{
37 ATH_MSG_INFO ( "initialize" );
38
39 // instantiate cut class
40 m_cut = new MyCutClass (m_ThrPT);
41
42 // record an object in DetectorStore
43 MyDetObj *detObj = new MyDetObj ("MyDetObj0");
44 ATH_CHECK( detStore()->record(detObj, "myDetObj", false) );
45
46 IAlgTool *tmp_myTool = nullptr;
47 ATH_CHECK( toolSvc()->retrieveTool("AthPyEx::MyTool",tmp_myTool) );
48 m_myTool=dynamic_cast<AthPyEx::MyTool *>(tmp_myTool);
49 if (!m_myTool)
50 {
51 ATH_MSG_ERROR ( "Can't get handle on analysis tools" );
52 return StatusCode::FAILURE;
53 }
54
55 m_myTool->setA(100);
56
57 return StatusCode::SUCCESS;
58}
59
60
61// finalize
63{
64 delete m_cut;
65 return StatusCode::SUCCESS;
66}
67
68
69// execute
71{
72 ATH_MSG_DEBUG ( "execute" );
73 ATH_MSG_INFO ( "MyTool: " << m_myTool->getA() );
74
75 MyObj *obj = new MyObj("aaa");
76 obj->setA(123);
77 ATH_MSG_INFO ( "before - MyObj: " << obj->getA() );
78 ATH_CHECK( m_myTool->execute(obj) );
79 ATH_MSG_INFO ( "after - MyObj: " << obj->getA() );
80 delete obj;
81
82 // retrieve ElectronContainer
83 ATH_MSG_DEBUG ( "retrieve ElectronContainer" );
84 const ElectronContainer *eCon = nullptr;
85 ATH_CHECK( evtStore()->retrieve(eCon, m_ContainerKey) );
86
87 auto newCon = std::make_unique<ConstDataVector<ElectronContainer> >(SG::VIEW_ELEMENTS);
88
91 for (; it!=itE; ++it)
92 if (m_cut->isAccepted(**it)) newCon->push_back(*it);
93
94 ATH_MSG_DEBUG ( "record new ElectronContainer : size=" << newCon->size() );
95 ATH_CHECK( evtStore()->record(std::move(newCon), m_NewKey, false) );
96 return StatusCode::SUCCESS;
97}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
DataVector adapter that acts like it holds const pointers.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MySelectionAlg(const std::string &name, ISvcLocator *pSvcLocator)
AthPyEx::MyTool * m_myTool
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts