ATLAS Offline Software
SysListHandle.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 //
9 // includes
10 //
11 
13 
19 #include <regex>
20 #include <unordered_set>
21 
22 //
23 // method implementations
24 //
25 
26 namespace CP
27 {
29  addHandle (ISysHandleBase& handle)
30  {
31  if (isInitialized())
32  {
33  ANA_MSG_ERROR ("trying to add/initialize data handle after initializing SysListHandle");
34  return StatusCode::FAILURE;
35  }
36  if (handle.empty())
37  {
38  ANA_MSG_ERROR ("trying to add/initialize empty data handle");
39  return StatusCode::FAILURE;
40  }
41  m_sysHandles.push_back (&handle);
42  return StatusCode::SUCCESS;
43  }
44 
45 
46 
48  addSystematics (const CP::SystematicSet& recommended,
49  const CP::SystematicSet& affecting)
50  {
51  assert (!isInitialized());
52  ANA_CHECK (m_systematicsService->addSystematics (recommended, affecting));
53  m_affecting.insert (affecting);
54  return StatusCode::SUCCESS;
55  }
56 
57 
58 
61  {
62  return addSystematics (tool.recommendedSystematics(),
63  tool.affectingSystematics());
64  }
65 
66 
67 
69  initialize ()
70  {
71  for (ISysHandleBase *handle : m_sysHandles)
72  m_affecting.insert (handle->getInputAffecting (*m_systematicsService));
73  if (!m_affectingFilter.empty())
74  {
76  auto affecting = std::move (m_affecting);
77  m_affecting.clear ();
78  for (auto& sys : affecting)
79  {
80  if (!std::regex_match (sys.basename(), filter))
81  {
83  }
84  }
85  }
87  for (ISysHandleBase *handle : m_sysHandles)
88  ANA_CHECK (handle->fillSystematics (*m_systematicsService, m_affecting, m_systematicsVector));
89  m_isInitialized = true;
90  return StatusCode::SUCCESS;
91  }
92 
93 
94 
95  const std::vector<CP::SystematicSet>& SysListHandle ::
96  systematicsVector () const
97  {
98  assert (isInitialized());
99  return m_systematicsVector;
100  }
101 
102 
103 
106  {
107  assert (m_systematicsVector.empty());
108 
109  std::unordered_set<CP::SystematicSet> knownSys;
110 
111  for (const auto& sys : m_systematicsService->makeSystematicsVector())
112  {
113  CP::SystematicSet filtered;
115  if (knownSys.find (filtered) == knownSys.end())
116  {
117  m_systematicsVector.push_back (filtered);
118  knownSys.insert (filtered);
119  }
120  }
121  return StatusCode::SUCCESS;
122  }
123 
124 
125 
127  foreach (const std::function<StatusCode(const CP::SystematicSet&)>& func) const
128  {
129  assert (isInitialized());
130 
131  for (const CP::SystematicSet& sys : systematicsVector())
132  {
133  if (func (sys).isFailure())
134  {
135  ANA_MSG_ERROR ("failed to evaluate algorithm for systematic " << sys.name());
136  return StatusCode::FAILURE;
137  }
138  }
139  return StatusCode::SUCCESS;
140  }
141 }
CP::SysListHandle::addHandle
StatusCode addHandle(ISysHandleBase &handle)
register an input handle we are using
Definition: SysListHandle.cxx:29
CP::SysListHandle::m_isInitialized
bool m_isInitialized
the value of isInitialized
Definition: SysListHandle.h:163
SysListHandle.h
SystematicSet.h
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
CP::SysListHandle::addSystematics
StatusCode addSystematics(const CP::SystematicSet &recommended, const CP::SystematicSet &affecting)
register a set of affecting variables for the current algorithm (usually obtained from an CP::ISystem...
Definition: SysListHandle.cxx:48
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
CP::SysListHandle::systematicsVector
const std::vector< CP::SystematicSet > & systematicsVector() const
the list of systematics to loop over
Definition: SysListHandle.cxx:96
CP::SysListHandle::isInitialized
bool isInitialized() const noexcept
whether initialize has been called successfully
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
covarianceTool.filter
filter
Definition: covarianceTool.py:514
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
CP::SysListHandle::m_systematicsVector
std::vector< CP::SystematicSet > m_systematicsVector
the value of systematicsVector
Definition: SysListHandle.h:159
CP::ISysHandleBase
a basic interface for all systematics handles
Definition: ISysHandleBase.h:28
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MessageCheck.h
macros for messaging and checking status codes
StatusCode.h
IReentrantSystematicsTool.h
CP::SysListHandle::m_systematicsService
ServiceHandle< ISystematicsSvc > m_systematicsService
the handle for the systematics service
Definition: SysListHandle.h:143
CP::SysListHandle::m_affecting
CP::SystematicSet m_affecting
this set of affecting systematics
Definition: SysListHandle.h:155
CP::SysListHandle::m_affectingFilter
std::string m_affectingFilter
an (optional) filter to remove affecting systematics
Definition: SysListHandle.h:147
CP::SystematicSet::insert
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Definition: SystematicSet.cxx:88
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
ISysHandleBase.h
CP::SystematicSet::clear
void clear()
description: clear the set
Definition: SystematicSet.cxx:119
CP::IReentrantSystematicsTool
interface for all CP tools supporting systematic variations within a reentrant algorithm
Definition: IReentrantSystematicsTool.h:58
CP::SysListHandle::fillSystematicsVector
StatusCode fillSystematicsVector()
Definition: SysListHandle.cxx:105
CP::SysListHandle::m_sysHandles
std::vector< ISysHandleBase * > m_sysHandles
the list of systematics handles we have
Definition: SysListHandle.h:151
CP::ISysHandleBase::empty
virtual bool empty() const noexcept=0
whether this is an empty handle
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
CP::SysListHandle::foreach
StatusCode foreach(const std::function< StatusCode(const CP::SystematicSet &)> &func) const
run the function for each systematic
Definition: SysListHandle.cxx:127