ATLAS Offline Software
Loading...
Searching...
No Matches
XMLFormatTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7namespace JiveXML {
8
13 XMLFormatTool::XMLFormatTool( const std::string& type , const std::string& name, const IInterface* p):
14 AthAlgTool(type,name,p){
15
16 //Provide interface
17 declareInterface<IFormatTool>(this);
18
19 //Intialize data members
20 m_EventBuffer = 0;
21 }
22
27
28 return StatusCode::SUCCESS;
29 }
30
35
36 //Clear the event buffer if it exists
37 if (m_EventBuffer) delete m_EventBuffer;
38 return StatusCode::SUCCESS;
39 }
40
45 StatusCode XMLFormatTool::SetTag ( const TagType tag ){
46
47 //Store this as release string
48 m_release = tag.second;
49 //Format properly
50 std::replace(m_release.begin(), m_release.end(), '/', '_');
51 return StatusCode::SUCCESS;
52 }
53
60 StatusCode XMLFormatTool::StartEvent( const unsigned long EventNumber, const unsigned int RunNumber,
61 const std::string& dateTime,
62 const unsigned int lumiBlock,
63 const std::string& eventProperty,
64 const std::string& geometryVersion ){
65
66
67 //Recreate the event buffer if it does not exists
68 if (!m_EventBuffer)
69 m_EventBuffer = new std::ostringstream();
70
71 //Clear the event buffer
72 m_EventBuffer->str("");
73
74 //Print general XML header information
75 (*m_EventBuffer) << "<?xml version=\"1.0\"?>" << std::endl
76 << "<?xml-stylesheet type=\"text/xsl\" href=\"JiveXML_event.xsl\"?>" << std::endl
77 << "<?ATLAS Release: \"" << m_release << "\"?>" << std::endl
78 << "<!DOCTYPE Event SYSTEM \"event.dtd\">"
79 << std::endl << std::endl << std::endl;
80
81 //Print event open tag
82 (*m_EventBuffer) << "<Event version=\"" << m_release << "\""
83 << " runNumber=\"" << RunNumber << "\""
84 << " eventNumber=\"" << EventNumber << "\""
85 << " lumiBlock=\"" << lumiBlock << "\""
86 << " dateTime=\"" << dateTime << "\""
87 << " geometryVersion=\"" << geometryVersion << "\""
88 << " eventProperty=\"" << eventProperty << "\""
89 << ">" << std::endl << std::endl << std::endl;
90
91 return StatusCode::SUCCESS;
92 }
93
98
99 //Print event close tag
100 (*m_EventBuffer) << "</Event>\n";
101
102 return StatusCode::SUCCESS;
103 }
104
105
112 StatusCode XMLFormatTool::AddToEvent(const std::string& component,
113 const std::string& key,
114 const DataMap * aMap) {
115
116 DataMap::const_iterator itr;
117
118 //check to see if any data is contained in the map before any formatting takes place
119 bool map_is_empty = true;
120 for(itr=aMap->begin(); itr!=aMap->end(); ++itr) {
121 if (itr->second.size()) {
122 map_is_empty = false;
123 break;
124 }
125 }
126
127 //return in case of empty map
128 if(map_is_empty) return StatusCode::SUCCESS;
129
130 //Open a new tag
131 (*m_EventBuffer) << "<" << component ;
132
133 //Write number of entries taken from first non-multiple collection
134 for (itr=aMap->begin(); itr!=aMap->end(); ++itr) {
135 if ((itr->first.find("multiple"))==std::string::npos) {
136 //Write out multiplicty and key
137 (*m_EventBuffer) <<" count=\""<< itr->second.size()<< "\""
138 <<" storeGateKey=\""<< key<< "\"";
139 break ;
140 }
141 }
142
143 //Close the opening tag
144 (*m_EventBuffer) << ">" << std::endl << std::endl;
145
146 //Now start writing event information
147 for(itr=aMap->begin(); itr!=aMap->end() ;++itr) {
148
149 // Write first key from map
150 (*m_EventBuffer) << "<" << (*itr).first <<">\n";
151
152 // Write the elements in groups of 10 per line
153 int ii=0;
154 for (DataVect::const_iterator itr2 = (*itr).second.begin(); itr2!=(*itr).second.end(); ++itr2){
155 ++ii;
156 (*m_EventBuffer) << (*itr2);
157 if ((*itr).first == "identifier"){
158 (*m_EventBuffer) <<"\n";
159 }
160 else if(ii>=10){
161 (*m_EventBuffer) <<"\n";
162 ii=0;
163 } else {
164 (*m_EventBuffer) << " ";
165 }
166 }
167
168 // I don't understand this bit
169 int i = (*itr).first.find(' ');
170 if (i != int(std::string::npos))
171 (*m_EventBuffer) << "\n</" << (*itr).first.substr(0,i) <<">\n";
172 else
173 (*m_EventBuffer) << "\n</" << (*itr).first <<">\n";
174 }
175
177 (*m_EventBuffer) << "</" << component << ">\n\n";
178
179 return StatusCode::SUCCESS;
180 }
181
183 const std::ostringstream* XMLFormatTool::getFormattedEvent() const {
184 return m_EventBuffer;
185 }
186
187
188} //namespace
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
virtual StatusCode EndEvent() override
Finialize this event.
virtual const std::ostringstream * getFormattedEvent() const override
Return the formated stringstream.
std::string m_release
the release tag
virtual StatusCode initialize() override
Initialize.
XMLFormatTool(const std::string &, const std::string &, const IInterface *)
Constructor.
std::ostringstream * m_EventBuffer
the string buffer that will hold the complete event
virtual StatusCode AddToEvent(const std::string &component, const std::string &key, const DataMap *aMap) override
Append a formatted version of one event component.
virtual StatusCode SetTag(const TagType tag) override
Set additional tags.
virtual StatusCode StartEvent(const unsigned long EventNumber, const unsigned int RunNumber, const std::string &DateTime, const unsigned int lumiBlock, const std::string &eventProperty, const std::string &geometryVersion) override
Start a new event.
virtual StatusCode finalize() override
Finalize.
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
std::map< std::string, DataVect > DataMap
Definition DataType.h:59
std::pair< std::string, std::string > TagType
Defines a tag as a pair of strings.
Definition DataType.h:62