ATLAS Offline Software
SelectionAccessorReadSys.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 //
9 // includes
10 //
11 
13 
16 
17 //
18 // method implementations
19 //
20 
21 namespace CP
22 {
24  SelectionAccessorReadSys (const std::string& val_selectionName)
25  : m_selectionName (val_selectionName)
26  {}
27 
28 
29 
31  getBits (const SG::AuxElement& element,
32  const CP::SystematicSet *sys) const
33  {
34  if (sys == nullptr)
35  throw std::logic_error ("trying to read systematics accessor without systematic");
36  auto iter = m_dataCache.find (*sys);
37  if (iter == m_dataCache.end())
38  throw std::logic_error ("unknown systematic: " + sys->name());
39  return std::get<1>(iter->second)->getBits (element, sys);
40  }
41 
42 
43 
45  getBool (const SG::AuxElement& element,
46  const CP::SystematicSet *sys) const
47  {
48  if (sys == nullptr)
49  throw std::logic_error ("trying to read systematics accessor without systematic");
50  auto iter = m_dataCache.find (*sys);
51  if (iter == m_dataCache.end())
52  throw std::logic_error ("unknown systematic: " + sys->name());
53  return std::get<1>(iter->second)->getBool (element, sys);
54  }
55 
56 
58  label () const
59  {
60  return m_selectionName;
61  }
62 
63 
64 
66  isBool () const
67  {
68  for (auto& item : m_dataCache)
69  if (!std::get<1>(item.second)->isBool())
70  return false;
71  return true;
72  }
73 
74 
75 
78  const std::string& objectName) const
79  {
80  std::string baseName = m_selectionName;
81  if (auto split = baseName.find (',');
82  split != std::string::npos)
83  baseName.resize (split);
84  return svc.getDecorSystematics (objectName, baseName);
85  }
86 
87 
88 
91  const std::vector<CP::SystematicSet>& sysList,
92  const std::string& objectName)
93  {
94  using namespace msgSelectionHelpers;
95 
96  std::string baseName = m_selectionName;
97  std::string suffix;
98  if (auto split = baseName.find (',');
99  split != std::string::npos)
100  {
101  suffix = baseName.substr (split);
102  baseName.resize (split);
103  }
104 
105  const CP::SystematicSet affecting
106  = svc.getDecorSystematics (objectName, baseName);
107  for (auto& sys : sysList)
108  {
109  CP::SystematicSet inputSys;
111  std::string decorName;
112  ANA_CHECK (svc.makeSystematicsName (decorName, baseName, inputSys));
113  ANA_MSG_DEBUG ("SysReadDecorHandle: " << decorName << " (" << sys.name() << ")");
114  std::unique_ptr<ISelectionReadAccessor> accessor;
116  m_dataCache.emplace (sys, std::make_tuple (decorName, std::move (accessor)));
117  }
118  return StatusCode::SUCCESS;
119  }
120 }
CP::SelectionAccessorReadSys::m_dataCache
std::unordered_map< CP::SystematicSet, std::tuple< std::string, std::unique_ptr< ISelectionReadAccessor > > > m_dataCache
the map of accessor we use
Definition: SelectionAccessorReadSys.h:65
hotSpotInTAG.suffix
string suffix
Definition: hotSpotInTAG.py:186
CP::ISystematicsSvc
the interface for the central systematics service
Definition: ISystematicsSvc.h:25
CP::SelectionAccessorReadSys::isBool
virtual bool isBool() const override
whether this accessor returns a simple boolean
Definition: SelectionAccessorReadSys.cxx:66
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:446
CP::SelectionType
uint32_t SelectionType
the type for selection decorations that are meant to hold a asg::AcceptData
Definition: SelectionHelpers.h:26
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
ISystematicsSvc.h
CP::SelectionAccessorReadSys::getBool
virtual bool getBool(const SG::AuxElement &element, const CP::SystematicSet *sys) const override
get the selection decoration
Definition: SelectionAccessorReadSys.cxx:45
CP::SelectionAccessorReadSys::getBits
virtual SelectionType getBits(const SG::AuxElement &element, const CP::SystematicSet *sys) const override
get the selection decoration
Definition: SelectionAccessorReadSys.cxx:31
CP::SelectionAccessorReadSys::m_selectionName
std::string m_selectionName
the selectionName for this accessor
Definition: SelectionAccessorReadSys.h:69
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::SelectionAccessorReadSys::fillSystematics
virtual StatusCode fillSystematics(const ISystematicsSvc &svc, const std::vector< CP::SystematicSet > &sysList, const std::string &objectName) override
fill the systematic variations
Definition: SelectionAccessorReadSys.cxx:90
MessageCheck.h
macros for messaging and checking status codes
SelectionAccessorReadSys.h
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
CP::SelectionAccessorReadSys::getInputAffecting
virtual CP::SystematicSet getInputAffecting(const ISystematicsSvc &svc, const std::string &objectName) const override
get the systematics when reading from the decoration
Definition: SelectionAccessorReadSys.cxx:77
CP::SelectionAccessorReadSys::label
virtual std::string label() const override
get the label of the accessor
Definition: SelectionAccessorReadSys.cxx:58
CP::makeSelectionReadAccessor
StatusCode makeSelectionReadAccessor(const std::string &expr, std::unique_ptr< ISelectionReadAccessor > &accessor, bool defaultToChar)
make the ISelectionReadAccessor for the given name
Definition: ISelectionAccessor.cxx:54
item
Definition: ItemListSvc.h:43
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
CP::SelectionAccessorReadSys::SelectionAccessorReadSys
SelectionAccessorReadSys(const std::string &val_selectionName)
Definition: SelectionAccessorReadSys.cxx:24
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
CP::SystematicSet::filterForAffectingSystematics
static StatusCode filterForAffectingSystematics(const SystematicSet &systConfig, const SystematicSet &affectingSystematics, SystematicSet &filteredSystematics)
description: filter the systematics for the affected systematics returns: success guarantee: strong f...
Definition: SystematicSet.cxx:213
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288