ATLAS Offline Software
Loading...
Searching...
No Matches
InputFileIncidentGuard.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11#ifndef ATHENAKERNEL_INPUTFILEINCIDENTGUARD_H
12#define ATHENAKERNEL_INPUTFILEINCIDENTGUARD_H
13
66
67#include "GaudiKernel/IIncidentSvc.h"
68#include "GaudiKernel/FileIncident.h"
69
70#include <optional>
71#include <string>
72#include <string_view>
73#include <utility>
74
76public:
92 [[nodiscard("End incident will not fire if the guard is discarded")]]
93 static InputFileIncidentGuard begin(IIncidentSvc& incSvc,
94 std::string_view source,
95 std::string_view beginFileName,
96 std::string_view guid,
97 std::string_view endFileName = {},
98 std::string_view beginType = IncidentType::BeginInputFile,
99 std::string_view endType = IncidentType::EndInputFile) {
100 return InputFileIncidentGuard(incSvc, source, beginFileName, guid,
101 endFileName.empty() ? "FID:" + std::string(guid)
102 : std::string(endFileName),
103 beginType, endType);
104 }
105
117 static void transition(std::optional<InputFileIncidentGuard>& guard,
118 IIncidentSvc& incSvc,
119 std::string_view source,
120 std::string_view beginFileName,
121 std::string_view guid,
122 std::string_view endFileName = {},
123 std::string_view beginType = IncidentType::BeginInputFile,
124 std::string_view endType = IncidentType::EndInputFile) {
125 guard.reset();
126 guard = begin(incSvc, source, beginFileName, guid,
127 endFileName, beginType, endType);
128 }
129
133 if (m_incSvc) {
134 m_incSvc->fireIncident(
135 FileIncident(m_source, m_endType,
137 }
138 }
139
142 : m_incSvc(std::exchange(other.m_incSvc, nullptr))
143 , m_source(std::move(other.m_source))
144 , m_guid(std::move(other.m_guid))
145 , m_endFileName(std::move(other.m_endFileName))
146 , m_endType(std::move(other.m_endType))
147 {}
148
152 if (this != &other) {
153 if (m_incSvc) {
154 m_incSvc->fireIncident(
155 FileIncident(m_source, m_endType,
157 }
158 m_incSvc = std::exchange(other.m_incSvc, nullptr);
159 m_source = std::move(other.m_source);
160 m_guid = std::move(other.m_guid);
161 m_endFileName = std::move(other.m_endFileName);
162 m_endType = std::move(other.m_endType);
163 }
164 return *this;
165 }
166
171
172private:
174 InputFileIncidentGuard(IIncidentSvc& incSvc,
175 std::string_view source,
176 std::string_view beginFileName,
177 std::string_view guid,
178 std::string endFileName,
179 std::string_view beginType,
180 std::string_view endType)
181 : m_incSvc(&incSvc)
182 , m_source(source)
183 , m_guid(guid)
184 , m_endFileName(std::move(endFileName))
185 , m_endType(endType)
186 {
187 m_incSvc->fireIncident(
188 FileIncident(m_source, std::string(beginType),
189 std::string(beginFileName), m_guid));
190 }
191
193 IIncidentSvc* m_incSvc;
195 std::string m_source;
197 std::string m_guid;
199 std::string m_endFileName;
201 std::string m_endType;
202};
203
204#endif // ATHENAKERNEL_INPUTFILEINCIDENTGUARD_H
static InputFileIncidentGuard begin(IIncidentSvc &incSvc, std::string_view source, std::string_view beginFileName, std::string_view guid, std::string_view endFileName={}, std::string_view beginType=IncidentType::BeginInputFile, std::string_view endType=IncidentType::EndInputFile)
Factory: fire the begin incident and return a guard whose destructor fires the matching end incident.
std::string m_endFileName
fileName used for the end incident.
InputFileIncidentGuard & operator=(const InputFileIncidentGuard &)=delete
Copy assignment is not allowed.
std::string m_guid
File GUID passed to the FileIncident.
~InputFileIncidentGuard()
Destructor: fires the end incident unless the guard has been moved from (disarmed).
std::string m_source
Source name for both begin and end incidents.
static void transition(std::optional< InputFileIncidentGuard > &guard, IIncidentSvc &incSvc, std::string_view source, std::string_view beginFileName, std::string_view guid, std::string_view endFileName={}, std::string_view beginType=IncidentType::BeginInputFile, std::string_view endType=IncidentType::EndInputFile)
Replace the guard in an optional, with strict End-before-Begin ordering.
InputFileIncidentGuard(const InputFileIncidentGuard &)=delete
Copy is not allowed.
InputFileIncidentGuard(InputFileIncidentGuard &&other) noexcept
Move constructor: takes ownership; the source is disarmed.
InputFileIncidentGuard & operator=(InputFileIncidentGuard &&other) noexcept
Move assignment: fires the end incident for the file being replaced (if any), then takes ownership of...
InputFileIncidentGuard(IIncidentSvc &incSvc, std::string_view source, std::string_view beginFileName, std::string_view guid, std::string endFileName, std::string_view beginType, std::string_view endType)
Private constructor used by begin().
IIncidentSvc * m_incSvc
Incident service pointer; nullptr if disarmed (moved-from).
std::string m_endType
Incident type string for the end incident (e.g. "EndInputFile").
STL namespace.