ATLAS Offline Software
SelectionWriteAccessorSys.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  SelectionWriteAccessorSys (const std::string& val_selectionName)
25  : m_selectionName (val_selectionName)
26  {}
27 
28 
29 
31  setBits (const SG::AuxElement& element,
33  const CP::SystematicSet *sys) const
34  {
35  if (sys == nullptr)
36  throw std::logic_error ("trying to write systematics accessor without systematic");
37  auto iter = m_dataCache.find (*sys);
38  if (iter == m_dataCache.end())
39  throw std::logic_error ("unknown systematic: " + sys->name());
40  return std::get<1>(iter->second)->setBits (element, selection, sys);
41  }
42 
43 
44 
46  setBool (const SG::AuxElement& element,
47  bool selection,
48  const CP::SystematicSet *sys) const
49  {
50  if (sys == nullptr)
51  throw std::logic_error ("trying to write systematics accessor without systematic");
52  auto iter = m_dataCache.find (*sys);
53  if (iter == m_dataCache.end())
54  throw std::logic_error ("unknown systematic: " + sys->name());
55  return std::get<1>(iter->second)->setBool (element, selection, sys);
56  }
57 
58 
59 
61  label () const
62  {
63  return m_selectionName;
64  }
65 
66 
67 
70  const CP::SystematicSet& fullAffecting,
71  const std::vector<CP::SystematicSet>& sysList,
72  const std::string& objectName)
73  {
74  using namespace msgSelectionHelpers;
75 
76  std::string baseName = m_selectionName;
77  std::string suffix;
78  if (auto split = baseName.find (',');
79  split != std::string::npos)
80  {
81  suffix = baseName.substr (split);
82  baseName.resize (split);
83  }
84 
85  for (auto& sys : sysList)
86  {
87  std::string decorName;
88  ANA_CHECK (svc.makeSystematicsName (decorName, baseName, sys));
89  ANA_MSG_DEBUG ("SelectionWriteAccessorSys: " << decorName << " (" << sys.name() << ")");
90  std::unique_ptr<ISelectionWriteAccessor> accessor;
92  m_dataCache.emplace (sys, std::make_tuple (decorName, std::move (accessor)));
93  }
94  ANA_CHECK (svc.setDecorSystematics (objectName, baseName, fullAffecting));
95  return StatusCode::SUCCESS;
96  }
97 }
CP::SelectionWriteAccessorSys::m_selectionName
std::string m_selectionName
the selectionName for this accessor
Definition: SelectionWriteAccessorSys.h:63
hotSpotInTAG.suffix
string suffix
Definition: hotSpotInTAG.py:186
CP::ISystematicsSvc
the interface for the central systematics service
Definition: ISystematicsSvc.h:25
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
CP::makeSelectionWriteAccessor
StatusCode makeSelectionWriteAccessor(const std::string &name, std::unique_ptr< ISelectionWriteAccessor > &accessor, bool defaultToChar)
Produces a simple ISelectionWriteAccessor accessing the given decoration.
Definition: ISelectionAccessor.cxx:170
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
SelectionWriteAccessorSys.h
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
ISystematicsSvc.h
CP::SelectionWriteAccessorSys::fillSystematics
virtual StatusCode fillSystematics(const ISystematicsSvc &svc, const CP::SystematicSet &fullAffecting, const std::vector< CP::SystematicSet > &sysList, const std::string &objectName) override
fill the systematic variations
Definition: SelectionWriteAccessorSys.cxx:69
CP::SelectionWriteAccessorSys::setBits
virtual void setBits(const SG::AuxElement &element, SelectionType selection, const CP::SystematicSet *sys) const override
set the selection decoration
Definition: SelectionWriteAccessorSys.cxx:31
CP::SelectionWriteAccessorSys::SelectionWriteAccessorSys
SelectionWriteAccessorSys(const std::string &val_selectionName)
Definition: SelectionWriteAccessorSys.cxx:24
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::SelectionWriteAccessorSys::setBool
virtual void setBool(const SG::AuxElement &element, bool selection, const CP::SystematicSet *sys) const override
set the selection decoration
Definition: SelectionWriteAccessorSys.cxx:46
MessageCheck.h
macros for messaging and checking status codes
CP::SelectionWriteAccessorSys::label
virtual std::string label() const override
get the label of the accessor
Definition: SelectionWriteAccessorSys.cxx:61
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
selection
std::string selection
Definition: fbtTestBasics.cxx:73
CP::SelectionWriteAccessorSys::m_dataCache
std::unordered_map< CP::SystematicSet, std::tuple< std::string, std::unique_ptr< ISelectionWriteAccessor > > > m_dataCache
the map of accessor we use
Definition: SelectionWriteAccessorSys.h:59
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288