ATLAS Offline Software
Loading...
Searching...
No Matches
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
17
18//
19// method implementations
20//
21
22namespace CP
23{
24 SelectionWriteAccessorSys ::
25 SelectionWriteAccessorSys (const std::string& val_selectionName)
26 : m_selectionName (val_selectionName)
27 {}
28
29
30
31 void SelectionWriteAccessorSys ::
32 setBits (const SG::AuxElement& element,
34 const CP::SystematicSet *sys) const
35 {
36 if (sys == nullptr)
37 throw std::logic_error ("trying to write systematics accessor without systematic");
38 auto iter = m_dataCache.find (*sys);
39 if (iter == m_dataCache.end())
40 throw std::logic_error ("unknown systematic: " + sys->name());
41 return std::get<1>(iter->second)->setBits (element, selection, sys);
42 }
43
44
45
46 void SelectionWriteAccessorSys ::
47 setBool (const SG::AuxElement& element,
48 bool selection,
49 const CP::SystematicSet *sys) const
50 {
51 if (sys == nullptr)
52 throw std::logic_error ("trying to write systematics accessor without systematic");
53 auto iter = m_dataCache.find (*sys);
54 if (iter == m_dataCache.end())
55 throw std::logic_error ("unknown systematic: " + sys->name());
56 return std::get<1>(iter->second)->setBool (element, selection, sys);
57 }
58
59
60
61 std::string SelectionWriteAccessorSys ::
62 label () const
63 {
64 return m_selectionName;
65 }
66
67
68
69 StatusCode SelectionWriteAccessorSys ::
70 fillSystematics (const ISystematicsSvc& svc,
71 const CP::SystematicSet& fullAffecting,
72 const std::vector<CP::SystematicSet>& sysList,
73 ISysObjectHandleBase& objectHandle)
74 {
75 using namespace msgSelectionHelpers;
76
77 std::string baseName = m_selectionName;
78 std::string suffix;
79 if (auto split = baseName.find (',');
80 split != std::string::npos)
81 {
82 suffix = baseName.substr (split);
83 baseName.resize (split);
84 }
85
86 for (auto& sys : sysList)
87 {
88 std::string decorName;
89 ANA_CHECK (svc.makeSystematicsName (decorName, baseName, sys));
90 ANA_MSG_DEBUG ("SelectionWriteAccessorSys: " << decorName << " (" << sys.name() << ")");
91 std::unique_ptr<ISelectionWriteAccessor> accessor;
92 ANA_CHECK (makeSelectionWriteAccessor (decorName + suffix, accessor));
93 m_dataCache.emplace (sys, std::make_tuple (decorName, std::move (accessor)));
94 }
95 ANA_CHECK (svc.setDecorSystematics (objectHandle.getNamePattern(), baseName, fullAffecting));
96 ANA_CHECK (objectHandle.addDecorationDependency (svc, baseName, true));
97 return StatusCode::SUCCESS;
98 }
99}
macros for messaging and checking status codes
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
a ISysHandleBase for a handle to a specific object/container
virtual StatusCode addDecorationDependency(const ISystematicsSvc &svc, const std::string &decoName, bool decoWrite)=0
add dependency information for the given decoration
virtual std::string getNamePattern() const =0
get the name pattern before substitution
the interface for the central systematics service
std::unordered_map< CP::SystematicSet, std::tuple< std::string, std::unique_ptr< ISelectionWriteAccessor > > > m_dataCache
the map of accessor we use
std::string m_selectionName
the selectionName for this accessor
Class to wrap a set of SystematicVariations.
Base class for elements of a container that can have aux data.
Definition AuxElement.h:484
const std::string selection
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
Select isolated Photons, Electrons and Muons.
StatusCode makeSelectionWriteAccessor(const std::string &name, std::unique_ptr< ISelectionWriteAccessor > &accessor, bool defaultToChar)
Produces a simple ISelectionWriteAccessor accessing the given decoration.
uint32_t SelectionType
the type for selection decorations that are meant to hold a asg::AcceptData