ATLAS Offline Software
graphics
JiveXML
src
StreamToFileTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include <
JiveXML/StreamToFileTool.h
>
6
7
#include <fstream>
8
#include <iomanip>
9
10
namespace
JiveXML
{
11
17
StreamToFileTool::StreamToFileTool
(
const
std::string&
type
,
const
std::string&
name
,
const
IInterface*
p
):
18
AthAlgTool
(
type
,
name
,
p
){
19
20
//Provide interface
21
declareInterface<IStreamTool>(
this
);
22
24
declareProperty
(
"FileNamePrefix"
,
m_FileNamePrefix
=
"JiveXML"
);
26
declareProperty
(
"FileNameSuffix"
,
m_FileNameSuffix
=
".xml"
);
27
28
}
29
33
StatusCode
StreamToFileTool::initialize
(){
34
if
(
m_isOnline
){
35
if
(
m_onlineEDsvc
.retrieve().isFailure()){
36
ATH_MSG_ERROR
(
"Could not locate the online event displays service"
);
37
return
StatusCode::FAILURE;
38
}
39
}
40
return
StatusCode::SUCCESS;
41
}
42
46
StatusCode
StreamToFileTool::finalize
(){
47
return
StatusCode::SUCCESS;
48
}
49
56
StatusCode
StreamToFileTool::StreamEvent
(
const
unsigned
long
EventNumber
,
const
unsigned
int
RunNumber
,
const
std::ostringstream* EventBuffer ) {
57
if
(
m_isOnline
){
58
m_FileNamePrefix
=
m_onlineEDsvc
->getFileNamePrefix();
59
ATH_MSG_DEBUG
(
"m_FileNamePrefix: "
<<
m_FileNamePrefix
<<
" EventNumber: "
<<
EventNumber
);
60
}
62
std::ofstream*
outFile
;
63
StatusCode
sc
=
NewFile
(
EventNumber
,
RunNumber
,
outFile
);
64
if
(
sc
.isFailure()){
65
ATH_MSG_WARNING
(
"Could not open file for event "
<<
EventNumber
<<
" from run "
<<
RunNumber
);
66
return
sc
;
67
}
69
(*outFile) << EventBuffer->str();
70
outFile
->flush();
72
if
(!
outFile
->good()){
73
ATH_MSG_WARNING
(
"Could not open file for event "
<<
EventNumber
<<
" from run "
<<
RunNumber
);
74
return
StatusCode::FAILURE;
75
}
76
78
sc
=
CloseFile
(
outFile
);
79
return
sc
;
80
81
}
82
88
std::string
StreamToFileTool::MakeFileName
(
const
unsigned
long
EventNumber
,
const
unsigned
int
RunNumber
)
const
{
89
90
//Generate a the return string with file prefix
91
std::ostringstream
name
;
92
93
//Assemble file name
94
name
<<
m_FileNamePrefix
<< std::setfill(
'0'
);
95
name
<<
"_"
<< std::setw(5) <<
RunNumber
;
96
name
<<
"_"
<< std::setw(5) <<
EventNumber
;
97
name
<<
m_FileNameSuffix
;
98
return
name
.str();
99
}
100
104
StatusCode
StreamToFileTool::NewFile
(
const
unsigned
long
EventNumber
,
const
unsigned
int
RunNumber
, std::ofstream *&
outputFile
)
const
{
105
106
// Generate the file name
107
std::string
filename
=
MakeFileName
(
EventNumber
,
RunNumber
);
108
109
// create a new output stream
110
outputFile
=
new
std::ofstream(
filename
.c_str());
111
ATH_MSG_DEBUG
(
"outputFile "
<<
filename
);
112
// check if it worked
113
if
( !(
outputFile
->good()) ){
114
ATH_MSG_WARNING
(
"Unable to create output file with name "
<<
filename
);
115
return
StatusCode::FAILURE;
116
}
117
118
return
StatusCode::SUCCESS;
119
}
120
124
StatusCode
StreamToFileTool::CloseFile
( std::ofstream *&
outputFile
)
const
{
125
126
//Try to close the file
127
outputFile
->close();
128
129
//See if it worked
130
if
(!
outputFile
->good()){
131
ATH_MSG_WARNING
(
"Unable to close file"
);
132
}
133
134
//In any case delete object
135
delete
outputFile
;
136
137
return
StatusCode::SUCCESS;
138
}
139
140
}
//namespace
JiveXML::StreamToFileTool::finalize
virtual StatusCode finalize()
Finalize.
Definition:
StreamToFileTool.cxx:46
JiveXML::StreamToFileTool::NewFile
StatusCode NewFile(const unsigned long EventNumber, const unsigned int RunNumber, std::ofstream *&outFile) const
Creates a new output stream to write XML to.
Definition:
StreamToFileTool.cxx:104
JiveXML::StreamToFileTool::m_FileNamePrefix
std::string m_FileNamePrefix
Prefix put in front of JiveXML file name.
Definition:
StreamToFileTool.h:45
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition:
AthCommonDataStore.h:145
JiveXML::StreamToFileTool::m_onlineEDsvc
ServiceHandle< IOnlineEventDisplaysSvc > m_onlineEDsvc
Definition:
StreamToFileTool.h:40
sct_calib_tf.EventNumber
int EventNumber
Definition:
sct_calib_tf.py:29
JiveXML::StreamToFileTool::m_FileNameSuffix
std::string m_FileNameSuffix
Suffix put at the end of the file name (including type)
Definition:
StreamToFileTool.h:48
AthenaPoolTestRead.sc
sc
Definition:
AthenaPoolTestRead.py:27
StreamToFileTool.h
compareGeometries.outputFile
string outputFile
Definition:
compareGeometries.py:25
python.utils.AtlRunQueryDQUtils.p
p
Definition:
AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition:
AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition:
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition:
AthMsgStreamMacros.h:29
JiveXML::StreamToFileTool::MakeFileName
std::string MakeFileName(const unsigned long EventNumber, const unsigned int RunNumber) const
Generate a file name.
Definition:
StreamToFileTool.cxx:88
JiveXML::StreamToFileTool::StreamToFileTool
StreamToFileTool(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition:
StreamToFileTool.cxx:17
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition:
BadLArRetriever.cxx:22
DQPostProcessTest.outFile
outFile
Comment Out Those You do not wish to run.
Definition:
DQPostProcessTest.py:37
EventInfoWrite.RunNumber
RunNumber
Definition:
EventInfoWrite.py:50
name
std::string name
Definition:
Control/AthContainers/Root/debug.cxx:228
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition:
AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition:
CaloScaleNoiseConfig.py:78
JiveXML::StreamToFileTool::m_isOnline
Gaudi::Property< bool > m_isOnline
Definition:
StreamToFileTool.h:42
CaloCellTimeCorrFiller.filename
filename
Definition:
CaloCellTimeCorrFiller.py:24
JiveXML::StreamToFileTool::StreamEvent
virtual StatusCode StreamEvent(const unsigned long EventNumber, const unsigned int RunNumber, const std::ostringstream *EventBuffer)
Stream one event.
Definition:
StreamToFileTool.cxx:56
JiveXML::StreamToFileTool::initialize
virtual StatusCode initialize()
Initialize.
Definition:
StreamToFileTool.cxx:33
JiveXML::StreamToFileTool::CloseFile
StatusCode CloseFile(std::ofstream *&outFile) const
Closes output stream.
Definition:
StreamToFileTool.cxx:124
AthAlgTool
Definition:
AthAlgTool.h:26
Generated on Sun Dec 22 2024 21:18:36 for ATLAS Offline Software by
1.8.18