13#include "GaudiKernel/IIncidentSvc.h"
14#include "GaudiKernel/FileIncident.h"
15#include "GaudiKernel/ConcurrencyFlags.h"
25 : base_class(name, pSvcLocator),
40 if (!incsvc.retrieve().isSuccess()) {
42 return(StatusCode::FAILURE);
46 incsvc->addListener(
this, IncidentType::BeginProcessing, 100);
52 return StatusCode::FAILURE;
64 return(StatusCode::SUCCESS);
72 return(StatusCode::SUCCESS);
77 return Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents() > 1;
82 std::lock_guard lockg(
m_mutex );
89 const EventContext& ctx = inc.context();
95 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
96 if (fileInc !=
nullptr) {
97 rangeID = fileInc->fileName();
99 if (inc.type() == IncidentType::BeginInputFile) {
103 "Requested (through incident) Next Event Range filename extension: "
107 if( rangeID ==
"dummy" ) {
113 bool disconnect {
true };
114 std::lock_guard lockg(
m_mutex );
116 throw GaudiException(
"Cannot transition MetaData", name(), StatusCode::FAILURE);
124 std::lock_guard lockg(
m_mutex );
126 if( rangeID.empty() ) {
127 std::ostringstream n;
130 ATH_MSG_DEBUG(
"Default next event range filename extension: " << rangeID);
132 else if (rangeID ==
"INFILE") {
145 bool disconnect {
false };
147 if( !
m_metaDataSvc->transitionMetaDataFile(
"" , disconnect ).isSuccess() ) {
148 throw GaudiException(
"Cannot transition MetaData", name(), StatusCode::FAILURE);
152 else if( inc.type() == IncidentType::BeginProcessing ) {
154 std::lock_guard lockg(
m_mutex );
168 std::lock_guard lockg(
m_mutex );
171 std::string fileNameCore = orgFileName, fileNameExt;
172 std::size_t sepPos = orgFileName.find(
'[');
173 if (sepPos != std::string::npos) {
174 fileNameCore = orgFileName.substr(0, sepPos);
175 fileNameExt = orgFileName.substr(sepPos);
177 std::ostringstream n;
178 n << fileNameCore <<
"." << rangeID << fileNameExt;
181 std::string_view origFileNameView = orgFileName;
182 std::size_t open = origFileNameView.find(
'[');
183 std::size_t close = origFileNameView.find(
']');
186 if (open == std::string_view::npos || close == std::string_view::npos) {
191 std::vector<std::string_view> elems{};
192 std::size_t pos = open + 1;
193 for (std::size_t comma = origFileNameView.find(
',', pos);
195 comma = origFileNameView.find(
',', pos)) {
196 std::string_view item = origFileNameView.substr(pos, comma - pos);
197 ATH_MSG_DEBUG(
"(start) pos = " << pos <<
", (end) comma = " << comma <<
", item = " << item);
198 elems.push_back(item);
201 std::string_view last_item = origFileNameView.substr(pos, close - pos);
202 ATH_MSG_DEBUG(
"(start) pos = " << pos <<
", (end) close = " << close <<
", item = " << last_item);
203 elems.push_back(last_item);
205 std::size_t rangeIdx{};
206 auto rangeIdxParseRes = std::from_chars(
207 rangeID.data(), rangeID.data() + rangeID.size(), rangeIdx);
208 if (rangeIdxParseRes.ec != std::errc()) {
210 "Error parsing rangeID to integer. Replacing [] list with "
213 std::format(
"{}{}{}", origFileNameView.substr(0, open), rangeID,
214 origFileNameView.substr(close + 1));
215 }
else if (rangeIdx >= elems.size()) {
217 "Number of elements in [] list <= rangeID. Replacing [] list with "
220 std::format(
"{}{}{}", origFileNameView.substr(0, open), rangeID,
221 origFileNameView.substr(close + 1));
224 "{}{}{}", origFileNameView.substr(0, open), elems.at(rangeIdx),
225 origFileNameView.substr(close + 1));
241 if( !
inUse() )
return "";
249 const std::string oldrange = *rangeid;
257 std::lock_guard lockg(
m_mutex );
267 std::lock_guard lockg(
m_mutex );
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
This file contains the class definition for the OutputStreamSequencerSvc class.
static const Attributes_t empty
void publishRangeReport(const std::string &outputFile)
SG::SlotSpecificObj< std::string, SG::InvalidSlot::Enabled > m_rangeIDinSlot
EventRange ID for all slots.
bool inUse() const
Is the service in active use? (true after the first range incident is handled).
OutputStreamSequencerSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
std::string buildSequenceFileName(const EventContext &ctx, const std::string &)
Returns sequenced file name for output stream.
virtual void handle(const Incident &) override final
Incident service handle.
RangeReport_ptr getRangeReport()
std::string m_lastFileName
Recently constructed full file name (useful in single threaded processing).
std::string currentRangeID(const EventContext &ctx) const
The current Event Range ID (only one range is returned).
ServiceHandle< MetaDataSvc > m_metaDataSvc
int m_fileSequenceNumber
The event sequence number.
BooleanProperty m_replaceRangeMode
Flag to put in ReplaceRangeMode (i.e.
virtual StatusCode finalize() override final
Required of all Gaudi services:
std::string incidentName() const
The name of the incident that starts a new event sequence.
std::string m_currentRangeID
Current EventRange ID constructed on the last NextRange incident.
virtual ~OutputStreamSequencerSvc()
Destructor.
BooleanProperty m_reportingOn
Flag to switch on storage of reporting info in fnToRangeId.
static bool inConcurrentEventsMode()
Are there concurrent events? (threads>1).
std::string m_lastIncident
Last incident type that was handled.
std::string setRangeID(const EventContext &ctx, const std::string &rangeID)
set the RangeID (possibly temporarily) so the right Range Filename may be generated
std::unique_ptr< RangeReport_t > RangeReport_ptr
std::map< std::string, std::string >::iterator m_finishedRange
virtual StatusCode initialize() override final
Required of all Gaudi services:
std::map< std::string, std::string > m_fnToRangeId