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
99{
100 const EventContext& ctx = Gaudi::Hive::currentContext();
101
103 // Check Tools //
105
107 // Output Frequency Control //
109
112 {
113 return StatusCode::SUCCESS;
114 }
115
117 // XML Files //
119
120 // run info
121 // if ( m_geomWriter > 0 && thisRun != m_oldRun )
122 // {
123 // m_oldRun = thisRun;
124 // this->writeRunInfo();
125 // }
126
127 // construct directory and file name
128 std::ostringstream thisFileName;
129 thisFileName << m_topDirectory << "/evnt."
130 << std::setw(6) << std::setfill('0')
131 << ctx.eventID().run_number() << "." << std::setfill('0')
132 << std::setw(6)
133 << ctx.eventID().event_number() << ".xml" << std::ends;
134
135 std::ofstream thisFileStream((thisFileName.str()).c_str());
136
138 // Loop Tools //
140
142 {
143 StatusCode checkOut = tool->writeOut(thisFileStream);
144 m_toolInvoke[tool->name()]++;
145 if ( checkOut.isFailure() )
146 {
147 m_toolReject[tool->name()]++;
148 }
149 else
150 {
151 m_toolAccept[tool->name()]++;
152 }
153 }
154
155 // finalize the stream
156 ATH_CHECK((*(m_writerTools.begin()))->finalize(thisFileStream));
157 thisFileStream.close();
158
159 return StatusCode::SUCCESS;
160}
161
162
164{
165 return StatusCode::SUCCESS;
166}
167
168
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
base class for XML writer tools for 2004 event display
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
virtual StatusCode execute() override
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