| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

SequentialOutputStream.cpp
Go to the documentation of this file.
1 // standard headers
2 #include <limits>
3
4 // boost
5 #include <boost/filesystem.hpp>
6
7 // Framework include files
8 #include "GaudiKernel/IRegistry.h"
9 #include "GaudiKernel/IDataManagerSvc.h"
10 #include "GaudiKernel/IDataProviderSvc.h"
11 #include "GaudiKernel/IOpaqueAddress.h"
12 #include "GaudiKernel/DataStoreItem.h"
13 #include "GaudiKernel/DataObject.h"
14 #include "GaudiKernel/MsgStream.h"
15 #include "SequentialOutputStream.h"
16
17 // Define the algorithm factory for the standard output data writer
18 DECLARE_COMPONENT( SequentialOutputStream )
19
20 using namespace std;
21 namespace bf = boost::filesystem;
22
23 //=============================================================================
24 StatusCode SequentialOutputStream::writeObjects()
25 {
26 try {
27 makeFilename();
28 } catch ( const GaudiException& except ) {
29 error() << except.message() << endmsg;
30 return StatusCode::FAILURE;
31 }
32 return OutputStream::writeObjects();
33 }
34
35 //=============================================================================
36 StatusCode SequentialOutputStream::execute()
37 {
38 // Clear any previously existing item list
39 clearSelection();
40 // Test whether this event should be output
41 if ( isEventAccepted() ) {
42 StatusCode sc = writeObjects();
43 clearSelection();
44 ++m_events;
45 return sc;
46 }
47 return StatusCode::SUCCESS;
48 }
49
50 //=============================================================================
51 void SequentialOutputStream::makeFilename()
52 {
53 if ( m_events % m_eventsPerFile != 0 ) return;
54
55 bf::path outputPath( m_outputName );
56 string filename = outputPath.filename().string();
57 bf::path dir = outputPath.parent_path();
58 string stem = outputPath.stem().string();
59 string extension = outputPath.extension().string();
60
61 if ( !dir.empty() ) {
62 if ( !bf::exists( dir ) ) {
63 stringstream stream;
64 stream << "Directory " << dir << " does not exist.";
65 throw GaudiException( stream.str(), "error", StatusCode::FAILURE );
66 }
67 }
68
69 if ( m_numericFilename ) {
70 if ( m_events == 0 ) {
71 try {
72 m_iFile = std::stoul( stem );
73 } catch( const std::invalid_argument& /* cast */ ) {
74 string msg = "Filename " + filename
75 + " is not a number, which was needed.";
76 throw GaudiException( msg, "error", StatusCode::FAILURE );
77 }
78 }
79 string iFile = std::to_string(m_iFile);
80 unsigned int length = 0;
81
82 if ( stem.length() > iFile.length() ) {
83 length = stem.length() - iFile.length();
84 }
85
86 stringstream name;
87 if ( !dir.empty() ) name << dir << "/";
88 for ( unsigned int i = 0; i < length; ++i ) {
89 name << "0";
90 }
91 name << iFile << extension;
92 m_outputName = name.str();
93 } else {
94 if ( m_iFile != 1 ) {
95 size_t pos = stem.rfind( "_" );
96 stem = stem.substr( 0, pos );
97 }
98
99 string iFile = std::to_string(m_iFile);
100
101 unsigned int length = 0;
102 if ( m_nNumbersAdded > iFile.length() ) {
103 length = m_nNumbersAdded - iFile.length();
104 }
105
106 stringstream name;
107 name << dir << "/" << stem;
108 for ( unsigned int i = 0; i < length; ++i ) {
109 if ( i == 0 ) name << "_";
110 name << "0";
111 }
112 name << iFile << extension;
113 m_outputName = name.str();
114 }
115 ++m_iFile;
116 }
OutputStream::isEventAccepted
bool isEventAccepted() const
Test whether this event should be output.
Definition: OutputStream.cpp:533
GaudiException::message
virtual const std::string & message() const
error message to be printed
Definition: GaudiException.h:111
StatusCode::SUCCESS
Definition: StatusCode.h:30
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:132
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
SequentialOutputStream::makeFilename
void makeFilename()
Definition: SequentialOutputStream.cpp:51
SequentialOutputStream::m_events
unsigned int m_events
Definition: SequentialOutputStream.h:35
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:715
boost
The namespace threadpool contains a thread pool and related utility classes.
Definition: iter_pos.hpp:13
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:772
SequentialOutputStream::writeObjects
StatusCode writeObjects() override
OutputStream override: Select the different objects and write them to file.
Definition: SequentialOutputStream.cpp:24
StatusCode::FAILURE
Definition: StatusCode.h:29
MsgStream.h
std::string::rfind
T rfind(T...args)
OutputStream::m_outputName
Gaudi::Property< std::string > m_outputName
Definition: OutputStream.h:52
std::to_string
T to_string(T...args)
std
STL namespace.
SequentialOutputStream::m_numericFilename
Gaudi::Property< bool > m_numericFilename
Definition: SequentialOutputStream.h:31
graphanalysis.filename
string filename
Definition: graphanalysis.py:109
SequentialOutputStream.h
std::stringstream
STL class.
std::stoul
T stoul(T...args)
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
std::string::string
T string(T...args)
OutputStream::writeObjects
virtual StatusCode writeObjects()
Select the different objects and write them to file.
Definition: OutputStream.cpp:162
DataStoreItem.h
IDataManagerSvc.h
IDataProviderSvc.h
SequentialOutputStream::execute
StatusCode execute() override
Definition: SequentialOutputStream.cpp:36
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::stringstream::str
T str(T...args)
IRegistry.h
OutputStream::clearSelection
void clearSelection()
Clear list of selected objects.
Definition: OutputStream.cpp:309
SequentialOutputStream::m_iFile
unsigned int m_iFile
Definition: SequentialOutputStream.h:36
IOpaqueAddress.h
std::string::length
T length(T...args)
SequentialOutputStream::m_eventsPerFile
Gaudi::Property< unsigned int > m_eventsPerFile
Definition: SequentialOutputStream.h:30
SequentialOutputStream
Extension of OutputStream to write run records after last event.
Definition: SequentialOutputStream.h:14
std::string::substr
T substr(T...args)
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SequentialOutputStream::m_nNumbersAdded
Gaudi::Property< unsigned int > m_nNumbersAdded
Definition: SequentialOutputStream.h:32
std::invalid_argument
STL class.
DataObject.h