ATLAS Offline Software
MySelectionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
12 #include "CLHEP/Units/SystemOfUnits.h"
13 
15 
16 
17 using CLHEP::GeV;
18 using namespace AthPyEx;
19 
20 
21 MySelectionAlg::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() );
79  ATH_MSG_INFO ( "after - MyObj: " << obj->getA() );
80  delete obj;
81 
82  // retrive ElectronContainer
83  ATH_MSG_DEBUG ( "retrive ElectronContainer" );
84  const ElectronContainer *eCon = nullptr;
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ElectronContainer.h
AthPyEx::MyTool::getA
int getA() const
accessor
Definition: MyTool.cxx:52
AthPyEx
Definition: MyCutClass.h:13
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AthPyEx::MySelectionAlg::m_NewKey
std::string m_NewKey
Definition: MySelectionAlg.h:27
skel.it
it
Definition: skel.GENtoEVGEN.py:396
AthPyEx::MySelectionAlg::initialize
StatusCode initialize()
Definition: MySelectionAlg.cxx:35
MyDetObj.h
AthPyEx::MySelectionAlg::m_cut
MyCutClass * m_cut
Definition: MySelectionAlg.h:30
AthPyEx::MyDetObj
Definition: MyDetObj.h:15
AthPyEx::MySelectionAlg::MySelectionAlg
MySelectionAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MySelectionAlg.cxx:21
TruthTest.itE
itE
Definition: TruthTest.py:25
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthPyEx::MyObj
Definition: MyObj.h:17
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
AthPyEx::MySelectionAlg::m_myTool
AthPyEx::MyTool * m_myTool
Definition: MySelectionAlg.h:31
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MyObj.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthPyEx::MyCutClass
Definition: MyCutClass.h:16
AthAlgorithm
Definition: AthAlgorithm.h:47
MySelectionAlg.h
MyCutClass.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AthPyEx::MySelectionAlg::m_ContainerKey
std::string m_ContainerKey
Definition: MySelectionAlg.h:28
AthPyEx::MyTool::setA
void setA(int a)
Definition: MyTool.cxx:57
AthPyEx::MyTool
Definition: MyTool.h:23
MyTool.h
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
AthPyEx::MyTool::execute
StatusCode execute(MyObj *obj)
Definition: MyTool.cxx:20
AthPyEx::MyCutClass::isAccepted
bool isAccepted(const Analysis::Electron &e)
Definition: MyCutClass.h:21
ElectronContainer
Definition: Reconstruction/egamma/egammaEvent/egammaEvent/ElectronContainer.h:32
AthPyEx::MySelectionAlg::execute
StatusCode execute()
Definition: MySelectionAlg.cxx:70
AthPyEx::MySelectionAlg::m_ThrPT
double m_ThrPT
Definition: MySelectionAlg.h:26
AthPyEx::MySelectionAlg::finalize
StatusCode finalize()
Definition: MySelectionAlg.cxx:62
python.PyAthena.obj
obj
Definition: PyAthena.py:132
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.