ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
TestBeam
TBRec
src
TBXMLWriter.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
6
#include "
TBXMLWriterToolBase.h
"
7
#include "
TBXMLWriter.h
"
8
9
10
// event
11
#include "GaudiKernel/TypeNameString.h"
12
13
#include <string>
14
#include <vector>
15
#include <map>
16
#include <iostream>
17
#include <fstream>
18
#include <sstream>
19
#include <ios>
20
#include <iomanip>
21
22
TBXMLWriter::TBXMLWriter
(
const
std::string& name,
23
ISvcLocator* pSvcLocator)
24
:
AthAlgorithm
(name,pSvcLocator)
25
,
m_outputFrequency
(1)
26
,
m_eventCounter
(0)
27
{
28
declareProperty
(
"OutputFrequency"
,
m_outputFrequency
);
29
declareProperty
(
"WriteTools"
,
m_writerToolNames
);
30
declareProperty
(
"FileTopDirectory"
,
m_topDirectory
);
31
}
32
33
TBXMLWriter::~TBXMLWriter
()
34
{ }
35
37
// Initialize //
39
40
StatusCode
TBXMLWriter::initialize
()
41
{
42
// loop all writers
43
for
(
const
std::string& toolName :
m_writerToolNames
)
44
{
45
IAlgTool* algToolPtr;
46
Gaudi::Utils::TypeNameString writerAlgoTool(toolName);
47
48
// pick up tool
49
StatusCode checkOut = toolSvc()->retrieveTool(writerAlgoTool.type(),
50
writerAlgoTool.name(),
51
algToolPtr,
52
this
);
53
// not found
54
if
( checkOut.isFailure() )
55
{
56
ATH_MSG_ERROR
57
(
"failed to pick up tool of type \042"
58
<< writerAlgoTool.type()
59
<<
"\042 with name <"
60
<< writerAlgoTool.name()
61
<<
">"
62
);
63
return
StatusCode::FAILURE;
64
}
65
66
// store pointer to tool if right type
67
TBXMLWriterToolBase
* thisTool =
68
dynamic_cast<
TBXMLWriterToolBase
*
>
(algToolPtr);
69
if
( thisTool != 0 )
70
{
71
m_writerTools
.push_back(thisTool);
72
}
73
74
}
75
76
// check tools
77
if
(
m_writerTools
.size() == 0 )
78
{
79
ATH_MSG_ERROR
(
"no tools found!"
);
80
return
StatusCode::FAILURE;
81
}
82
83
for
(
TBXMLWriterToolBase
* tool :
m_writerTools
)
84
{
85
// reset statistics
86
m_toolInvoke
[tool->name()] = 0;
87
m_toolReject
[tool->name()] = 0;
88
m_toolAccept
[tool->name()] = 0;
89
}
90
91
return
StatusCode::SUCCESS;
92
}
93
95
// Execute //
97
98
StatusCode
TBXMLWriter::execute
(
const
EventContext& ctx)
99
{
100
102
// Check Tools //
104
106
// Output Frequency Control //
108
109
m_eventCounter
++;
110
if
(
m_eventCounter
> 1 &&
m_eventCounter
%
m_outputFrequency
!= 0 )
111
{
112
return
StatusCode::SUCCESS;
113
}
114
116
// XML Files //
118
119
// run info
120
// if ( m_geomWriter > 0 && thisRun != m_oldRun )
121
// {
122
// m_oldRun = thisRun;
123
// this->writeRunInfo();
124
// }
125
126
// construct directory and file name
127
std::ostringstream thisFileName;
128
thisFileName <<
m_topDirectory
<<
"/evnt."
129
<< std::setw(6) << std::setfill(
'0'
)
130
<< ctx.eventID().run_number() <<
"."
<< std::setfill(
'0'
)
131
<< std::setw(6)
132
<< ctx.eventID().event_number() <<
".xml"
<< std::ends;
133
134
std::ofstream thisFileStream((thisFileName.str()).c_str());
135
137
// Loop Tools //
139
140
for
(
TBXMLWriterToolBase
* tool :
m_writerTools
)
141
{
142
StatusCode checkOut = tool->writeOut(thisFileStream);
143
m_toolInvoke
[tool->name()]++;
144
if
( checkOut.isFailure() )
145
{
146
m_toolReject
[tool->name()]++;
147
}
148
else
149
{
150
m_toolAccept
[tool->name()]++;
151
}
152
}
153
154
// finalize the stream
155
ATH_CHECK
((*(
m_writerTools
.begin()))->finalize(thisFileStream));
156
thisFileStream.close();
157
158
return
StatusCode::SUCCESS;
159
}
160
161
162
StatusCode
TBXMLWriter::finalize
()
163
{
164
return
StatusCode::SUCCESS;
165
}
166
167
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
TBXMLWriterToolBase.h
TBXMLWriter.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
TBXMLWriterToolBase
base class for XML writer tools for 2004 event display
Definition
TBXMLWriterToolBase.h:18
TBXMLWriter::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
TBXMLWriter.cxx:98
TBXMLWriter::m_toolReject
std::map< std::string, unsigned int > m_toolReject
Definition
TBXMLWriter.h:67
TBXMLWriter::m_toolInvoke
std::map< std::string, unsigned int > m_toolInvoke
Definition
TBXMLWriter.h:68
TBXMLWriter::m_writerTools
std::vector< TBXMLWriterToolBase * > m_writerTools
Definition
TBXMLWriter.h:60
TBXMLWriter::TBXMLWriter
TBXMLWriter(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm constructor.
Definition
TBXMLWriter.cxx:22
TBXMLWriter::finalize
virtual StatusCode finalize() override
Definition
TBXMLWriter.cxx:162
TBXMLWriter::m_toolAccept
std::map< std::string, unsigned int > m_toolAccept
Definition
TBXMLWriter.h:66
TBXMLWriter::m_writerToolNames
std::vector< std::string > m_writerToolNames
Definition
TBXMLWriter.h:56
TBXMLWriter::m_topDirectory
std::string m_topDirectory
Definition
TBXMLWriter.h:58
TBXMLWriter::initialize
virtual StatusCode initialize() override
Definition
TBXMLWriter.cxx:40
TBXMLWriter::m_outputFrequency
unsigned int m_outputFrequency
Definition
TBXMLWriter.h:53
TBXMLWriter::~TBXMLWriter
virtual ~TBXMLWriter()
Definition
TBXMLWriter.cxx:33
TBXMLWriter::m_eventCounter
unsigned int m_eventCounter
Definition
TBXMLWriter.h:54
Generated on
for ATLAS Offline Software by
1.17.0