The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
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
18
#include "
SequentialOutputStream.h
"
19
#include <
GaudiKernel/DataObject.h
>
20
#include <
GaudiKernel/DataStoreItem.h
>
21
#include <
GaudiKernel/IDataManagerSvc.h
>
22
#include <
GaudiKernel/IDataProviderSvc.h
>
23
#include <
GaudiKernel/IOpaqueAddress.h
>
24
#include <
GaudiKernel/IRegistry.h
>
25
#include <
GaudiKernel/MsgStream.h
>
26
27
// Define the algorithm factory for the standard output data writer
28
DECLARE_COMPONENT
(
SequentialOutputStream
)
29
30
namespace
bf = boost::filesystem;
31
32
//=============================================================================
33
StatusCode
SequentialOutputStream::writeObjects
() {
34
try
{
35
makeFilename
();
36
}
catch
(
const
GaudiException
& except ) {
37
error
() << except.
message
() <<
endmsg
;
38
return
StatusCode::FAILURE
;
39
}
40
return
OutputStream::writeObjects
();
41
}
42
43
//=============================================================================
44
StatusCode
SequentialOutputStream::execute
() {
45
// Clear any previously existing item list
46
clearSelection
();
47
// Test whether this event should be output
48
if
(
isEventAccepted
() ) {
49
StatusCode
sc =
writeObjects
();
50
clearSelection
();
51
++
m_events
;
52
return
sc;
53
}
54
return
StatusCode::SUCCESS
;
55
}
56
57
//=============================================================================
58
void
SequentialOutputStream::makeFilename
() {
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
}
DataObject.h
DataStoreItem.h
IDataManagerSvc.h
IDataProviderSvc.h
IOpaqueAddress.h
IRegistry.h
MsgStream.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
SequentialOutputStream.h
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition
CommonMessaging.h:109
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:124
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition
Algorithm.cpp:518
GaudiException
Define general base for Gaudi exception.
Definition
GaudiException.h:29
GaudiException::message
virtual const std::string & message() const
error message to be printed
Definition
GaudiException.h:66
OutputStream::clearSelection
void clearSelection()
Clear list of selected objects.
Definition
OutputStream.cpp:323
OutputStream::m_outputName
Gaudi::Property< std::string > m_outputName
Definition
OutputStream.h:63
OutputStream::writeObjects
virtual StatusCode writeObjects()
Select the different objects and write them to file.
Definition
OutputStream.cpp:181
OutputStream::isEventAccepted
bool isEventAccepted() const
Test whether this event should be output.
Definition
OutputStream.cpp:489
SequentialOutputStream
Extension of OutputStream to write run records after last event.
Definition
SequentialOutputStream.h:23
SequentialOutputStream::execute
StatusCode execute() override
Working entry point.
Definition
SequentialOutputStream.cpp:44
SequentialOutputStream::m_eventsPerFile
Gaudi::Property< unsigned int > m_eventsPerFile
Definition
SequentialOutputStream.h:35
SequentialOutputStream::m_nNumbersAdded
Gaudi::Property< unsigned int > m_nNumbersAdded
Definition
SequentialOutputStream.h:37
SequentialOutputStream::writeObjects
StatusCode writeObjects() override
OutputStream override: Select the different objects and write them to file.
Definition
SequentialOutputStream.cpp:33
SequentialOutputStream::m_numericFilename
Gaudi::Property< bool > m_numericFilename
Definition
SequentialOutputStream.h:36
SequentialOutputStream::makeFilename
void makeFilename()
Definition
SequentialOutputStream.cpp:58
SequentialOutputStream::m_events
unsigned int m_events
Definition
SequentialOutputStream.h:40
SequentialOutputStream::m_iFile
unsigned int m_iFile
Definition
SequentialOutputStream.h:41
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
GaudiCommonSvc
src
PersistencySvc
SequentialOutputStream.cpp
Generated on
for The Gaudi Framework by
1.17.0