13 #include "GaudiKernel/IIncidentSvc.h"
14 #include "GaudiKernel/FileIncident.h"
15 #include "GaudiKernel/ConcurrencyFlags.h"
19 #include <string_view>
25 : base_class(
name, pSvcLocator),
26 m_metaDataSvc(
"MetaDataSvc",
name),
27 m_fileSequenceNumber(-1)
40 if (!incsvc.retrieve().isSuccess()) {
42 return(StatusCode::FAILURE);
46 incsvc->addListener(
this, IncidentType::BeginProcessing, 100);
52 return StatusCode::FAILURE;
64 std::lock_guard lockg(
m_mutex );
67 return(StatusCode::SUCCESS);
75 return(StatusCode::SUCCESS);
80 return Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents() > 1;
85 std::lock_guard lockg(
m_mutex );
92 auto slot = Gaudi::Hive::currentContext().slot();
93 bool has_context = ( slot != EventContext::INVALID_CONTEXT_ID );
95 if( !has_context ) slot = 0;
98 << (!has_context?
" NO event context":
"") );
102 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
103 if (fileInc !=
nullptr) {
104 rangeID = fileInc->fileName();
106 if (inc.type() == IncidentType::BeginInputFile) {
110 "Requested (through incident) Next Event Range filename extension: "
114 if( rangeID ==
"dummy" ) {
120 bool disconnect {
true };
121 std::lock_guard lockg(
m_mutex );
123 throw GaudiException(
"Cannot transition MetaData",
name(), StatusCode::FAILURE);
131 std::lock_guard lockg(
m_mutex );
133 if( rangeID.empty() ) {
134 std::ostringstream
n;
137 ATH_MSG_DEBUG(
"Default next event range filename extension: " << rangeID);
139 else if (rangeID ==
"INFILE") {
156 bool disconnect {
false };
158 if( !
m_metaDataSvc->transitionMetaDataFile(
"" , disconnect ).isSuccess() ) {
159 throw GaudiException(
"Cannot transition MetaData",
name(), StatusCode::FAILURE);
163 else if( inc.type() == IncidentType::BeginProcessing ) {
165 std::lock_guard lockg(
m_mutex );
183 std::lock_guard lockg(
m_mutex );
186 std::string fileNameCore = orgFileName, fileNameExt;
187 std::size_t sepPos = orgFileName.find(
'[');
188 if (sepPos != std::string::npos) {
189 fileNameCore = orgFileName.substr(0, sepPos);
190 fileNameExt = orgFileName.substr(sepPos);
192 std::ostringstream
n;
193 n << fileNameCore <<
"." << rangeID << fileNameExt;
196 std::string_view origFileNameView = orgFileName;
197 std::size_t
open = origFileNameView.find(
'[');
198 std::size_t close = origFileNameView.find(
']');
201 if (
open == std::string_view::npos || close == std::string_view::npos) {
206 std::vector<std::string_view> elems{};
208 for (std::size_t comma = origFileNameView.find(
',',
pos);
210 comma = origFileNameView.find(
',',
pos)) {
211 std::string_view
item = origFileNameView.substr(
pos, comma -
pos);
213 elems.push_back(
item);
216 std::string_view last_item = origFileNameView.substr(
pos, close -
pos);
217 ATH_MSG_DEBUG(
"(start) pos = " <<
pos <<
", (end) close = " << close <<
", item = " << last_item);
218 elems.push_back(last_item);
220 std::size_t rangeIdx{};
221 auto rangeIdxParseRes = std::from_chars(
222 rangeID.data(), rangeID.data() + rangeID.size(), rangeIdx);
223 if (rangeIdxParseRes.ec != std::errc()) {
225 "Error parsing rangeID to integer. Replacing [] list with "
229 origFileNameView.substr(close + 1));
230 }
else if (rangeIdx >= elems.size()) {
232 "Number of elements in [] list <= rangeID. Replacing [] list with "
236 origFileNameView.substr(close + 1));
239 "{}{}{}", origFileNameView.substr(0,
open), elems.at(rangeIdx),
240 origFileNameView.substr(close + 1));
256 if( !
inUse() )
return "";
257 auto slot = Gaudi::Hive::currentContext().slot();
258 if( slot == EventContext::INVALID_CONTEXT_ID ) slot = 0;
259 std::lock_guard lockg(
m_mutex );
267 auto slot = Gaudi::Hive::currentContext().slot();
268 if( slot == EventContext::INVALID_CONTEXT_ID ) slot = 0;
269 std::lock_guard lockg(
m_mutex );
271 throw std::runtime_error(
"OutputStreamSequencer::setRangeID(): slot out of range");
281 std::lock_guard lockg(
m_mutex );
291 std::lock_guard lockg(
m_mutex );