ATLAS Offline Software
Loading...
Searching...
No Matches
OutputStreamSequencerSvc Class Reference

This class provides configuration properties to enable OutputStream file sequences. More...

#include <OutputStreamSequencerSvc.h>

Inheritance diagram for OutputStreamSequencerSvc:
Collaboration diagram for OutputStreamSequencerSvc:

Public Types

typedef std::pair< std::string, std::string > RangeReport_t
typedef std::unique_ptr< RangeReport_t > RangeReport_ptr

Public Member Functions

 OutputStreamSequencerSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Standard Service Constructor.
virtual ~OutputStreamSequencerSvc ()
 Destructor.
virtual StatusCode initialize () override final
 Required of all Gaudi services:
virtual StatusCode finalize () override final
 Required of all Gaudi services:
virtual void handle (const Incident &) override final
 Incident service handle.
std::string buildSequenceFileName (const EventContext &ctx, const std::string &)
 Returns sequenced file name for output stream.
void publishRangeReport (const std::string &outputFile)
RangeReport_ptr getRangeReport ()
std::string incidentName () const
 The name of the incident that starts a new event sequence.
std::string currentRangeID (const EventContext &ctx) const
 The current Event Range ID (only one range is returned).
std::string setRangeID (const EventContext &ctx, const std::string &rangeID)
 set the RangeID (possibly temporarily) so the right Range Filename may be generated
bool inUse () const
 Is the service in active use? (true after the first range incident is handled).
const std::string & lastIncident ()
 Last incident type that was handled.

Static Public Member Functions

static bool inConcurrentEventsMode ()
 Are there concurrent events? (threads>1).

Private Attributes

ServiceHandle< MetaDataSvc > m_metaDataSvc
int m_fileSequenceNumber {}
 The event sequence number.
std::string m_currentRangeID
 Current EventRange ID constructed on the last NextRange incident.
std::string m_lastFileName
 Recently constructed full file name (useful in single threaded processing).
std::string m_lastIncident
 Last incident type that was handled.
SG::SlotSpecificObj< std::string, SG::InvalidSlot::Enabled > m_rangeIDinSlot
 EventRange ID for all slots.
StringProperty m_incidentName
 SequenceIncidentName, incident name for triggering file sequencing.
BooleanProperty m_reportingOn
 Flag to switch on storage of reporting info in fnToRangeId.
BooleanProperty m_replaceRangeMode
 Flag to put in ReplaceRangeMode (i.e.
std::map< std::string, std::string > m_fnToRangeId
std::map< std::string, std::string >::iterator m_finishedRange {}
std::mutex m_mutex

Detailed Description

This class provides configuration properties to enable OutputStream file sequences.

Definition at line 30 of file OutputStreamSequencerSvc.h.

Member Typedef Documentation

◆ RangeReport_ptr

Definition at line 36 of file OutputStreamSequencerSvc.h.

◆ RangeReport_t

typedef std::pair<std::string,std::string> OutputStreamSequencerSvc::RangeReport_t

Definition at line 35 of file OutputStreamSequencerSvc.h.

Constructor & Destructor Documentation

◆ OutputStreamSequencerSvc()

OutputStreamSequencerSvc::OutputStreamSequencerSvc ( const std::string & name,
ISvcLocator * pSvcLocator )

Standard Service Constructor.

Definition at line 25 of file OutputStreamSequencerSvc.cxx.

26 : base_class(name, pSvcLocator),
27 m_metaDataSvc("MetaDataSvc", name),
29{
30}
ServiceHandle< MetaDataSvc > m_metaDataSvc
int m_fileSequenceNumber
The event sequence number.

◆ ~OutputStreamSequencerSvc()

OutputStreamSequencerSvc::~OutputStreamSequencerSvc ( )
virtual

Destructor.

Definition at line 33 of file OutputStreamSequencerSvc.cxx.

33 {
34}

Member Function Documentation

◆ buildSequenceFileName()

std::string OutputStreamSequencerSvc::buildSequenceFileName ( const EventContext & ctx,
const std::string & orgFileName )

Returns sequenced file name for output stream.

Definition at line 163 of file OutputStreamSequencerSvc.cxx.

164{
165 if( !inUse() ) {
166 // Event sequences not in use, just return the original filename
167 return orgFileName;
168 }
169 std::string rangeID = currentRangeID(ctx);
170 std::lock_guard lockg( m_mutex );
171 if (!m_replaceRangeMode) {
172 // build the full output file name for this event range
173 std::string fileNameCore = orgFileName, fileNameExt;
174 std::size_t sepPos = orgFileName.find('[');
175 if (sepPos != std::string::npos) {
176 fileNameCore = orgFileName.substr(0, sepPos);
177 fileNameExt = orgFileName.substr(sepPos);
178 }
179 m_lastFileName = fileNameCore + "." + rangeID + fileNameExt;
180 } else {
181 std::string_view origFileNameView = orgFileName;
182 std::size_t open = origFileNameView.find('[');
183 std::size_t close = origFileNameView.find(']');
184 // If we don't find a [ ] enclosed section, just append the rangeID to the
185 // end
186 if (open == std::string_view::npos || close == std::string_view::npos) {
187 m_lastFileName = std::format("{}.{}", origFileNameView, rangeID);
188 } else {
189 // build list of elems to substitute from
190 ATH_MSG_DEBUG("Building element list");
191 std::vector<std::string_view> elems{};
192 std::size_t pos = open + 1;
193 for (std::size_t comma = origFileNameView.find(',', pos);
194 comma < close;
195 comma = origFileNameView.find(',', pos)) {
196 std::string_view item = origFileNameView.substr(pos, comma - pos);
197 ATH_MSG_DEBUG("(start) pos = {}, (end) comma = comma, item = {}",
198 pos, comma, item);
199 elems.push_back(item);
200 pos = comma + 1;
201 }
202 std::string_view last_item = origFileNameView.substr(pos, close - pos);
203 ATH_MSG_DEBUG("(start) pos = {}, (end) close = {}, item = {}",
204 pos, close, last_item);
205 elems.push_back(last_item);
206 // substitute
207 std::size_t rangeIdx{};
208 auto rangeIdxParseRes = std::from_chars(
209 rangeID.data(), rangeID.data() + rangeID.size(), rangeIdx);
210 if (rangeIdxParseRes.ec != std::errc()) {
212 "Error parsing rangeID to integer. Replacing [] list with "
213 "rangeID.");
215 std::format("{}{}{}", origFileNameView.substr(0, open), rangeID,
216 origFileNameView.substr(close + 1));
217 } else if (rangeIdx >= elems.size()) {
219 "Number of elements in [] list <= rangeID. Replacing [] list with "
220 "rangeID.");
222 std::format("{}{}{}", origFileNameView.substr(0, open), rangeID,
223 origFileNameView.substr(close + 1));
224 } else {
225 m_lastFileName = std::format(
226 "{}{}{}", origFileNameView.substr(0, open), elems.at(rangeIdx),
227 origFileNameView.substr(close + 1));
228 ATH_MSG_DEBUG("Output file: {}", m_lastFileName);
229 }
230 }
231 }
232
233 if( m_reportingOn.value() ) {
234 m_fnToRangeId.insert( std::pair(m_lastFileName, rangeID) );
235 }
236
237 return m_lastFileName;
238}
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
bool inUse() const
Is the service in active use? (true after the first range incident is handled).
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).
BooleanProperty m_replaceRangeMode
Flag to put in ReplaceRangeMode (i.e.
BooleanProperty m_reportingOn
Flag to switch on storage of reporting info in fnToRangeId.
std::map< std::string, std::string > m_fnToRangeId
@ open
Definition BinningType.h:40

◆ currentRangeID()

std::string OutputStreamSequencerSvc::currentRangeID ( const EventContext & ctx) const

The current Event Range ID (only one range is returned).

Definition at line 241 of file OutputStreamSequencerSvc.cxx.

242{
243 if( !inUse() ) return "";
244 return *m_rangeIDinSlot.get(ctx);
245}
SG::SlotSpecificObj< std::string, SG::InvalidSlot::Enabled > m_rangeIDinSlot
EventRange ID for all slots.

◆ finalize()

StatusCode OutputStreamSequencerSvc::finalize ( )
finaloverridevirtual

Required of all Gaudi services:

Definition at line 68 of file OutputStreamSequencerSvc.cxx.

68 {
69 // Release MetaDataSvc
70 if (!m_metaDataSvc.release().isSuccess()) {
71 ATH_MSG_WARNING("Cannot release MetaDataSvc.");
72 }
73 return(StatusCode::SUCCESS);
74}

◆ getRangeReport()

OutputStreamSequencerSvc::RangeReport_ptr OutputStreamSequencerSvc::getRangeReport ( )

Definition at line 263 of file OutputStreamSequencerSvc.cxx.

264{
266 if( !m_reportingOn.value() ) {
267 ATH_MSG_WARNING("Reporting not turned on - set {} to True",
268 m_reportingOn.name());
269 } else {
270 std::lock_guard lockg( m_mutex );
271 if(m_finishedRange!=m_fnToRangeId.end()) {
272 report = std::make_unique<RangeReport_t>(m_finishedRange->second,m_finishedRange->first);
275 }
276 }
277 return report;
278}
std::unique_ptr< RangeReport_t > RangeReport_ptr
std::map< std::string, std::string >::iterator m_finishedRange
list report
Definition checkTP.py:125

◆ handle()

void OutputStreamSequencerSvc::handle ( const Incident & inc)
finaloverridevirtual

Incident service handle.

Definition at line 88 of file OutputStreamSequencerSvc.cxx.

89{
90 const EventContext& ctx = inc.context();
91 m_lastIncident = inc.type();
92 ATH_MSG_INFO("Handling incident of type " << m_lastIncident << " for " << ctx);
93
94 if( inc.type() == incidentName() ) { // NextEventRange
95 std::string rangeID;
96 const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
97 if (fileInc != nullptr) {
98 rangeID = fileInc->fileName();
99 // Handle BeginInputFile
100 if (inc.type() == IncidentType::BeginInputFile) {
101 rangeID = "INFILE";
102 }
104 "Requested (through incident) Next Event Range filename extension: {}",
105 rangeID);
106 }
107
108 if( rangeID == "dummy" ) {
109 if( not inConcurrentEventsMode() ) {
110 // finish the previous Range here only in SEQUENTIAL (threads<2) event processing
111 // Write metadata on the incident finishing a Range (filename=="dummy") in ES MP
112 ATH_MSG_DEBUG("MetaData transition");
113 // immediate write and disconnect for ES, otherwise do it after Event write is done
114 bool disconnect { true };
115 std::lock_guard lockg( m_mutex );
116 if( !m_metaDataSvc->transitionMetaDataFile( m_lastFileName, disconnect ).isSuccess() ) {
117 throw GaudiException("Cannot transition MetaData", name(), StatusCode::FAILURE);
118 }
119 }
120 // exit now, wait for the next (real) incident that will start the next range
121 return;
122 }
123 {
124 // start a new range
125 std::lock_guard lockg( m_mutex );
127 if( rangeID.empty() ) {
128 std::ostringstream n;
129 std::print (n, "_{:04}", m_fileSequenceNumber);
130 rangeID = n.str();
131 ATH_MSG_DEBUG("Default next event range filename extension: {}", rangeID);
132 }
133 else if (rangeID == "INFILE") {
134 rangeID = std::to_string(m_fileSequenceNumber);
135 }
136 // from now on new events will use the new rangeID
137 m_currentRangeID = rangeID;
138 // for ESMT these incidents are asynchronous, so wait for BeginProcessing to update the range map
139 if( not inConcurrentEventsMode() or ctx.valid() ) {
140 *m_rangeIDinSlot.get(ctx) = std::move(rangeID);
141 }
142 }
143 if( not inConcurrentEventsMode() and not fileInc ) {
144 // non-file incident case (filename=="") in regular SP LoopMgr
145 ATH_MSG_DEBUG("MetaData transition");
146 bool disconnect { false };
147 // MN: may not know the full filename yet, but that is only needed for disconnect==true
148 if( !m_metaDataSvc->transitionMetaDataFile( "" /*m_lastFileName*/, disconnect ).isSuccess() ) {
149 throw GaudiException("Cannot transition MetaData", name(), StatusCode::FAILURE);
150 }
151 }
152 }
153 else if( inc.type() == IncidentType::BeginProcessing ) {
154 // new event start - assing current rangeId to its slot
155 std::lock_guard lockg( m_mutex );
156 ATH_MSG_DEBUG("Assigning rangeID = {} to slot {}",
157 m_currentRangeID, ctx.slot());
159 }
160}
#define ATH_MSG_INFO(x,...)
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.
static bool inConcurrentEventsMode()
Are there concurrent events? (threads>1).
std::string m_lastIncident
Last incident type that was handled.

◆ incidentName()

std::string OutputStreamSequencerSvc::incidentName ( ) const
inline

The name of the incident that starts a new event sequence.

Definition at line 60 of file OutputStreamSequencerSvc.h.

60{ return m_incidentName.value(); }
StringProperty m_incidentName
SequenceIncidentName, incident name for triggering file sequencing.

◆ inConcurrentEventsMode()

bool OutputStreamSequencerSvc::inConcurrentEventsMode ( )
static

Are there concurrent events? (threads>1).

Definition at line 77 of file OutputStreamSequencerSvc.cxx.

77 {
78 return Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents() > 1;
79}

◆ initialize()

StatusCode OutputStreamSequencerSvc::initialize ( )
finaloverridevirtual

Required of all Gaudi services:

Definition at line 36 of file OutputStreamSequencerSvc.cxx.

36 {
37 ATH_MSG_DEBUG("Initializing {}", name());
38
39 // Set to be listener for end of event
40 ServiceHandle<IIncidentSvc> incsvc("IncidentSvc", this->name());
41 if (!incsvc.retrieve().isSuccess()) {
42 ATH_MSG_FATAL("Cannot get IncidentSvc.");
43 return(StatusCode::FAILURE);
44 }
45 if( !incidentName().empty() ) {
46 incsvc->addListener(this, incidentName(), 100);
47 incsvc->addListener(this, IncidentType::BeginProcessing, 100);
48 ATH_MSG_DEBUG("Listening to {} incidents", incidentName() );
49 ATH_MSG_DEBUG("Reporting is {}", (m_reportingOn.value()? "ON" : "OFF") );
50 // Retrieve MetaDataSvc
51 if( !m_metaDataSvc.isValid() and !m_metaDataSvc.retrieve().isSuccess() ) {
52 ATH_MSG_ERROR("Cannot get MetaDataSvc");
53 return StatusCode::FAILURE;
54 }
55 }
56
58 ATH_MSG_DEBUG("Concurrent events mode");
59 } else {
60 ATH_MSG_VERBOSE("Sequential events mode");
61 }
62
64
65 return(StatusCode::SUCCESS);
66}
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_FATAL(x,...)
static const Attributes_t empty

◆ inUse()

bool OutputStreamSequencerSvc::inUse ( ) const

Is the service in active use? (true after the first range incident is handled).

Definition at line 82 of file OutputStreamSequencerSvc.cxx.

82 {
83 std::lock_guard lockg( m_mutex );
84 return m_fileSequenceNumber >= 0;
85}

◆ lastIncident()

const std::string & OutputStreamSequencerSvc::lastIncident ( )
inline

Last incident type that was handled.

Definition at line 75 of file OutputStreamSequencerSvc.h.

75{ return m_lastIncident; }

◆ publishRangeReport()

void OutputStreamSequencerSvc::publishRangeReport ( const std::string & outputFile)

Definition at line 257 of file OutputStreamSequencerSvc.cxx.

258{
259 std::lock_guard lockg( m_mutex );
260 m_finishedRange = m_fnToRangeId.find(outputFile);
261}

◆ setRangeID()

std::string OutputStreamSequencerSvc::setRangeID ( const EventContext & ctx,
const std::string & rangeID )

set the RangeID (possibly temporarily) so the right Range Filename may be generated

Definition at line 248 of file OutputStreamSequencerSvc.cxx.

249{
250 std::string* rangeid = m_rangeIDinSlot.get(ctx);
251 const std::string oldrange = *rangeid;
252 *rangeid = rangeID;
253 return oldrange;
254}

Member Data Documentation

◆ m_currentRangeID

std::string OutputStreamSequencerSvc::m_currentRangeID
private

Current EventRange ID constructed on the last NextRange incident.

Definition at line 84 of file OutputStreamSequencerSvc.h.

◆ m_fileSequenceNumber

int OutputStreamSequencerSvc::m_fileSequenceNumber {}
private

The event sequence number.

Definition at line 81 of file OutputStreamSequencerSvc.h.

81{};

◆ m_finishedRange

std::map<std::string,std::string>::iterator OutputStreamSequencerSvc::m_finishedRange {}
private

Definition at line 112 of file OutputStreamSequencerSvc.h.

112{};

◆ m_fnToRangeId

std::map<std::string,std::string> OutputStreamSequencerSvc::m_fnToRangeId
private

Definition at line 111 of file OutputStreamSequencerSvc.h.

◆ m_incidentName

StringProperty OutputStreamSequencerSvc::m_incidentName
private
Initial value:
{this, "SequenceIncidentName", "",
"Name of the incident that signals the next Event Range start" }

SequenceIncidentName, incident name for triggering file sequencing.

Definition at line 97 of file OutputStreamSequencerSvc.h.

97 {this, "SequenceIncidentName", "",
98 "Name of the incident that signals the next Event Range start" };

◆ m_lastFileName

std::string OutputStreamSequencerSvc::m_lastFileName
private

Recently constructed full file name (useful in single threaded processing).

Definition at line 87 of file OutputStreamSequencerSvc.h.

◆ m_lastIncident

std::string OutputStreamSequencerSvc::m_lastIncident
private

Last incident type that was handled.

Definition at line 90 of file OutputStreamSequencerSvc.h.

◆ m_metaDataSvc

ServiceHandle<MetaDataSvc> OutputStreamSequencerSvc::m_metaDataSvc
private

Definition at line 78 of file OutputStreamSequencerSvc.h.

◆ m_mutex

std::mutex OutputStreamSequencerSvc::m_mutex
mutableprivate

Definition at line 114 of file OutputStreamSequencerSvc.h.

◆ m_rangeIDinSlot

SG::SlotSpecificObj<std::string, SG::InvalidSlot::Enabled> OutputStreamSequencerSvc::m_rangeIDinSlot
private

EventRange ID for all slots.

Definition at line 93 of file OutputStreamSequencerSvc.h.

◆ m_replaceRangeMode

BooleanProperty OutputStreamSequencerSvc::m_replaceRangeMode
private
Initial value:
{
this, "ReplaceRangeMode", false,
"If True, everything between [ and ] in the output filename is treated "
"as a comma-separated list, and the range_idth element of the list is "
"selected"}

Flag to put in ReplaceRangeMode (i.e.

everything between [ and ] (inclusive) is replaced with the range_idth element of that list)

Definition at line 105 of file OutputStreamSequencerSvc.h.

105 {
106 this, "ReplaceRangeMode", false,
107 "If True, everything between [ and ] in the output filename is treated "
108 "as a comma-separated list, and the range_idth element of the list is "
109 "selected"};

◆ m_reportingOn

BooleanProperty OutputStreamSequencerSvc::m_reportingOn
private
Initial value:
{this, "ReportingOn", false,
"If True, keep info about Ranges for getRangeReport() calls"}

Flag to switch on storage of reporting info in fnToRangeId.

Definition at line 100 of file OutputStreamSequencerSvc.h.

100 {this, "ReportingOn", false,
101 "If True, keep info about Ranges for getRangeReport() calls"};

The documentation for this class was generated from the following files: