ATLAS Offline Software
SysListHandle.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 }
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:134
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:130
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:114
CP::SysListHandle::m_affecting
CP::SystematicSet m_affecting
this set of affecting systematics
Definition: SysListHandle.h:126
CP::SysListHandle::m_affectingFilter
std::string m_affectingFilter
an (optional) filter to remove affecting systematics
Definition: SysListHandle.h:118
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:122
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