ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
22TBXMLWriter::TBXMLWriter(const std::string& name,
23 ISvcLocator* pSvcLocator)
24 : AthAlgorithm(name,pSvcLocator)
27{
28 declareProperty("OutputFrequency",m_outputFrequency);
30 declareProperty("FileTopDirectory",m_topDirectory);
31}
32
35
37// Initialize //
39
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 {
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
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
98StatusCode TBXMLWriter::execute(const EventContext& ctx)
99{
100
102 // Check Tools //
104
106 // Output Frequency Control //
108
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
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
163{
164 return StatusCode::SUCCESS;
165}
166
167
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
base class for XML writer tools for 2004 event display
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
std::map< std::string, unsigned int > m_toolReject
Definition TBXMLWriter.h:67
std::map< std::string, unsigned int > m_toolInvoke
Definition TBXMLWriter.h:68
std::vector< TBXMLWriterToolBase * > m_writerTools
Definition TBXMLWriter.h:60
TBXMLWriter(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm constructor.
virtual StatusCode finalize() override
std::map< std::string, unsigned int > m_toolAccept
Definition TBXMLWriter.h:66
std::vector< std::string > m_writerToolNames
Definition TBXMLWriter.h:56
std::string m_topDirectory
Definition TBXMLWriter.h:58
virtual StatusCode initialize() override
unsigned int m_outputFrequency
Definition TBXMLWriter.h:53
virtual ~TBXMLWriter()
unsigned int m_eventCounter
Definition TBXMLWriter.h:54