ATLAS Offline Software
AsgShallowCopyAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 //
10 // includes
11 //
12 
14 
15 #include <CxxUtils/fpcompare.h>
19 #include <xAODJet/JetContainer.h>
20 #include <xAODMuon/MuonContainer.h>
27 
28 //
29 // method implementations
30 //
31 
32 namespace CP
33 {
34  template<typename Type> StatusCode AsgShallowCopyAlg ::
36  {
37  const Type *input = nullptr;
39 
40  const auto& name = m_outputHandle.getName(sys);
41  [[maybe_unused]] Type *output = nullptr;
43  (msg(), *evtStore(), output, input,
44  name, name + "Aux."));
45 
46  return StatusCode::SUCCESS;
47  }
48 
49  // Specialization for MissingETContainer
50  template<> StatusCode AsgShallowCopyAlg ::
51  executeTemplate<xAOD::MissingETContainer> (const CP::SystematicSet& sys)
52  {
53  const xAOD::MissingETContainer *input = nullptr;
54  ANA_CHECK (evtStore()->retrieve (input, m_inputHandle.getName (sys)));
55 
56  auto name = m_outputHandle.getName(sys);
57  auto output = std::make_unique<xAOD::MissingETContainer>();
58  auto auxOutput = std::make_unique<xAOD::AuxContainerBase>();
59 
60  output->setStore(auxOutput.get());
61  for (const auto* met : *input)
62  {
64  out->makePrivateStore(*met);
65  output->push_back(out);
66  }
67 
68  ANA_CHECK(evtStore()->record(std::move(output), name));
69  ANA_CHECK(evtStore()->record(std::move(auxOutput), name + "Aux."));
70 
71  return StatusCode::SUCCESS;
72  }
73 
74 
77  {
78  const xAOD::IParticleContainer *input = nullptr;
79  if (evtStore()->contains<xAOD::IParticleContainer>(m_inputHandle.getName(sys)))
80  {
81  ANA_CHECK (m_inputHandle.retrieve (input, sys));
82  }
83 
84  if (dynamic_cast<const xAOD::ElectronContainer*> (input))
85  {
86  m_function =
87  &AsgShallowCopyAlg::executeTemplate<xAOD::ElectronContainer>;
88  }
89  else if (dynamic_cast<const xAOD::PhotonContainer*> (input))
90  {
91  m_function =
92  &AsgShallowCopyAlg::executeTemplate<xAOD::PhotonContainer>;
93  }
94  else if (dynamic_cast<const xAOD::JetContainer*> (input))
95  {
96  m_function =
97  &AsgShallowCopyAlg::executeTemplate<xAOD::JetContainer>;
98  }
99  else if (dynamic_cast<const xAOD::MuonContainer*> (input)) {
100  m_function =
101  &AsgShallowCopyAlg::executeTemplate<xAOD::MuonContainer>;
102  }
103  else if (dynamic_cast<const xAOD::TauJetContainer*> (input))
104  {
105  m_function =
106  &AsgShallowCopyAlg::executeTemplate<xAOD::TauJetContainer>;
107  }
108  else if (dynamic_cast<const xAOD::DiTauJetContainer*> (input))
109  {
110  m_function =
111  &AsgShallowCopyAlg::executeTemplate<xAOD::DiTauJetContainer>;
112  }
113  else if (dynamic_cast<const xAOD::TrackParticleContainer*> (input))
114  {
115  m_function =
116  &AsgShallowCopyAlg::executeTemplate<xAOD::TrackParticleContainer>;
117  }
118  else if (dynamic_cast<const xAOD::TruthParticleContainer*> (input))
119  {
120  m_function =
121  &AsgShallowCopyAlg::executeTemplate<xAOD::TruthParticleContainer>;
122  }
123  else if (evtStore()->contains<xAOD::MissingETContainer>(m_inputHandle.getName(sys)))
124  {
125  m_function =
126  &AsgShallowCopyAlg::executeTemplate<xAOD::MissingETContainer>;
127  }
128  else
129  {
130  ANA_MSG_ERROR ("unknown type contained in AsgShallowCopyAlg, please extend it");
131  return StatusCode::FAILURE;
132  }
133 
134  return (this->*m_function) (sys);
135  }
136 
137 
138 
140  AsgShallowCopyAlg (const std::string& name,
141  ISvcLocator* pSvcLocator)
142  : AnaAlgorithm (name, pSvcLocator)
143  {
144  }
145 
146 
147 
149  initialize ()
150  {
151  ANA_CHECK (m_systematicsList.service().registerCopy (m_inputHandle.getNamePattern(), m_outputHandle.getNamePattern()));
155 
156  return StatusCode::SUCCESS;
157  }
158 
159 
160 
162  execute ()
163  {
164  for (const auto& sys : m_systematicsList.systematicsVector())
165  {
166  ANA_CHECK ((this->*m_function) (sys));
167  }
168  return StatusCode::SUCCESS;
169  }
170 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CP::AsgShallowCopyAlg::execute
StatusCode execute() override
Definition: AsgShallowCopyAlg.cxx:162
TruthParticleContainer.h
CP::AsgShallowCopyAlg::executeTemplate
StatusCode executeTemplate(const CP::SystematicSet &sys)
the templated version of execute for a single systematic
Definition: AsgShallowCopyAlg.cxx:35
AuxContainerBase.h
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
xAOD::MissingET
MissingET_v1 MissingET
Version control by type defintion.
Definition: Event/xAOD/xAODMissingET/xAODMissingET/MissingET.h:15
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
DiTauJetContainer.h
CP::SysListHandle::systematicsVector
const std::vector< CP::SystematicSet > & systematicsVector() const
the list of systematics to loop over
Definition: SysListHandle.cxx:96
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::detail::ShallowCopy
a helper class to create shallow copies and register them in the event store
Definition: SystematicsHandles/SystematicsHandles/CopyHelpers.h:61
CP::AsgShallowCopyAlg::m_outputHandle
SysWriteHandle< xAOD::IParticleContainer > m_outputHandle
the output view container we produce
Definition: AsgShallowCopyAlg.h:54
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
CP::AsgShallowCopyAlg::m_function
StatusCode(AsgShallowCopyAlg::* m_function)(const CP::SystematicSet &sys)
Definition: AsgShallowCopyAlg.h:67
CP::AsgShallowCopyAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: AsgShallowCopyAlg.h:45
met
Definition: IMETSignificance.h:24
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
ElectronContainer.h
CP::ISystematicsSvc::registerCopy
virtual StatusCode registerCopy(const std::string &fromName, const std::string &toName) const =0
register a (shallow) copy from one object to the next
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::AsgShallowCopyAlg::AsgShallowCopyAlg
AsgShallowCopyAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
Definition: AsgShallowCopyAlg.cxx:140
fpcompare.h
Workaround x86 precision issues for FP inequality comparisons.
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
CP::AsgShallowCopyAlg::initialize
StatusCode initialize() override
Definition: AsgShallowCopyAlg.cxx:149
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
TauJetContainer.h
xAODType
Definition: ObjectType.h:13
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
merge.output
output
Definition: merge.py:17
AsgShallowCopyAlg.h
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MuonContainer.h
CopyHelpers.h
JetContainer.h
CP::AsgShallowCopyAlg::executeFindType
StatusCode executeFindType(const CP::SystematicSet &sys)
the version of execute to find the type
Definition: AsgShallowCopyAlg.cxx:76
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
CP::AsgShallowCopyAlg::m_inputHandle
SysReadHandle< xAOD::IParticleContainer > m_inputHandle
the input collection we run on
Definition: AsgShallowCopyAlg.h:49
PhotonContainer.h
MissingETContainer.h
CP::SysListHandle::service
const ISystematicsSvc & service() const
the service we use
TrackParticleContainer.h