The Gaudi Framework  master (34daa81a)
Loading...
Searching...
No Matches
SequentialOutputStream.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11// standard headers
12#include <limits>
13
14// boost
15#include <boost/filesystem.hpp>
16
17// Framework include files
26
27// Define the algorithm factory for the standard output data writer
29
30namespace bf = boost::filesystem;
31
32//=============================================================================
34 try {
36 } catch ( const GaudiException& except ) {
37 error() << except.message() << endmsg;
39 }
41}
42
43//=============================================================================
45 // Clear any previously existing item list
47 // Test whether this event should be output
48 if ( isEventAccepted() ) {
51 ++m_events;
52 return sc;
53 }
55}
56
57//=============================================================================
59 if ( m_events % m_eventsPerFile != 0 ) return;
60
61 bf::path outputPath( m_outputName.value() );
62 std::string filename = outputPath.filename().string();
63 bf::path dir = outputPath.parent_path();
64 std::string stem = outputPath.stem().string();
65 std::string extension = outputPath.extension().string();
66
67 if ( !dir.empty() ) {
68 if ( !bf::exists( dir ) ) {
69 std::stringstream stream;
70 stream << "Directory " << dir << " does not exist.";
71 throw GaudiException( stream.str(), "error", StatusCode::FAILURE );
72 }
73 }
74
75 if ( m_numericFilename ) {
76 if ( m_events == 0 ) {
77 try {
78 m_iFile = std::stoul( stem );
79 } catch ( const std::invalid_argument& /* cast */ ) {
80 std::string msg = "Filename " + filename + " is not a number, which was needed.";
81 throw GaudiException( msg, "error", StatusCode::FAILURE );
82 }
83 }
84 std::string iFile = std::to_string( m_iFile );
85 unsigned int length = 0;
86
87 if ( stem.length() > iFile.length() ) { length = stem.length() - iFile.length(); }
88
89 std::stringstream name;
90 if ( !dir.empty() ) name << dir << "/";
91 for ( unsigned int i = 0; i < length; ++i ) { name << "0"; }
92 name << iFile << extension;
93 m_outputName = name.str();
94 } else {
95 if ( m_iFile != 1 ) {
96 size_t pos = stem.rfind( "_" );
97 stem.resize( pos );
98 }
99
100 std::string iFile = std::to_string( m_iFile );
101
102 unsigned int length = 0;
103 if ( m_nNumbersAdded > iFile.length() ) { length = m_nNumbersAdded - iFile.length(); }
104
105 std::stringstream name;
106 name << dir << "/" << stem;
107 for ( unsigned int i = 0; i < length; ++i ) {
108 if ( i == 0 ) name << "_";
109 name << "0";
110 }
111 name << iFile << extension;
112 m_outputName = name.str();
113 }
114 ++m_iFile;
115}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
const std::string & name() const override
The identifying name of the algorithm object.
Define general base for Gaudi exception.
virtual const std::string & message() const
error message to be printed
void clearSelection()
Clear list of selected objects.
Gaudi::Property< std::string > m_outputName
virtual StatusCode writeObjects()
Select the different objects and write them to file.
bool isEventAccepted() const
Test whether this event should be output.
Extension of OutputStream to write run records after last event.
StatusCode execute() override
Working entry point.
Gaudi::Property< unsigned int > m_eventsPerFile
Gaudi::Property< unsigned int > m_nNumbersAdded
StatusCode writeObjects() override
OutputStream override: Select the different objects and write them to file.
Gaudi::Property< bool > m_numericFilename
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100