ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
TestBeam
TBRec
src
TBXMLWriterToolBase.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
#include "
TBXMLWriterToolBase.h
"
7
8
#include <iostream>
9
11
// XML writer implementation //
13
14
const
std::string
TBXMLWriterToolBase::m_doubleQuote
=
"\042"
;
15
16
// dictionary
17
void
18
TBXMLWriterToolBase::openDictionary
(std::ostream& outStream,
19
const
std::string& dictName,
20
const
std::vector<std::string>&
21
listOfElements)
22
{
23
// clean up
24
m_elementList
.clear();
25
m_dictionary
= dictName;
26
27
// write header
28
outStream <<
"<?XML version="
<<
m_doubleQuote
29
<<
"1"
<<
m_doubleQuote
<<
"?>"
<< std::endl;
30
31
// write begin of dictionary
32
outStream <<
"<!DOCTYPE "
<< dictName
33
<<
" ["
<< std::endl;
34
35
// add doctype as element
36
this->
addDictElement
(outStream,dictName,listOfElements);
37
}
38
39
// template <typename DATA>
40
void
41
TBXMLWriterToolBase::openDictionary
(std::ostream& outStream,
42
const
std::string& dictName)
43
{
44
std::vector<std::string> emptyList;
45
this->
openDictionary
(outStream,dictName, emptyList);
46
}
47
48
// template <typename DATA>
49
void
50
TBXMLWriterToolBase::closeDictionary
(std::ostream& outStream)
51
{
52
outStream <<
"]>"
<< std::endl;
53
}
54
55
//template <typename DATA>
56
void
57
TBXMLWriterToolBase::addDictElement
(std::ostream& outStream,
58
const
std::string& theElement,
59
const
std::vector<std::string>&
60
listOfElements)
61
{
62
outStream <<
"<!ELEMENT "
<< theElement;
63
// add document as element
64
if
( listOfElements.size() == 0 )
65
{
66
outStream <<
">"
<< std::endl;
67
}
68
else
69
{
70
// store elements
71
if
( listOfElements[0] ==
"ANY"
||
72
listOfElements[0] ==
"EMPTY"
||
73
listOfElements[0] ==
"ALL"
)
74
{
75
outStream <<
" "
<< listOfElements[0] <<
" >"
<< std::endl;
76
}
77
else
78
{
79
outStream <<
" ("
<< listOfElements[0];
80
for
(
unsigned
int
i=1; i<listOfElements.size(); i++ )
81
{
82
outStream <<
","
<< listOfElements[i];
83
}
84
outStream <<
") >"
<< std::endl;
85
}
86
}
87
}
88
89
// template <typename DATA>
90
void
91
TBXMLWriterToolBase::addAttributes
(std::ostream& outStream,
92
const
std::string& theElement,
93
const
std::vector<std::string>&
94
listOfAttr)
95
{
96
outStream <<
" <!ATTLIST "
<< theElement << std::endl;
97
for
(
unsigned
int
i=0; i<listOfAttr.size(); i++ )
98
{
99
outStream <<
" "
<< listOfAttr[i] << std::endl;
100
}
101
outStream <<
">"
<< std::endl;
102
}
103
104
// template <typename DATA>
105
void
106
TBXMLWriterToolBase::openElement
(std::ostream& outStream,
107
std::string_view theElement,
108
const
std::vector<std::string>&
109
listOfAttr,
110
const
std::vector<std::string>&
111
listOfValues)
112
{
113
m_elementList
.emplace_back(theElement);
114
outStream <<
"<"
<< theElement;
115
if
( listOfAttr.size() > 0 && listOfValues.size() == listOfAttr.size() )
116
{
117
for
(
unsigned
int
i=0; i<listOfAttr.size(); i++ )
118
{
119
outStream <<
" "
<< listOfAttr[i] <<
"="
120
<<
m_doubleQuote
121
<< listOfValues[i]
122
<<
m_doubleQuote
;
123
}
124
}
125
outStream <<
">"
<< std::endl;
126
}
127
128
// template <typename DATA>
129
void
130
TBXMLWriterToolBase::closeElement
(std::ostream& outStream)
131
{
132
unsigned
int
thisSize =
m_elementList
.size() - 1;
133
outStream <<
"</"
<<
m_elementList
[thisSize] <<
">"
<< std::endl;
134
m_elementList
.resize(thisSize);
135
}
136
137
// template <typename DATA>
138
void
139
TBXMLWriterToolBase::closeElement
(std::ostream& outStream,
140
const
std::string& theElement)
141
{
142
std::vector<std::string>::iterator inVec =
143
find
(
m_elementList
.begin(),
m_elementList
.end(), theElement);
144
if
( inVec !=
m_elementList
.end() )
145
{
146
outStream <<
"</"
<< (*inVec) <<
">"
<< std::endl;
147
m_elementList
.erase(inVec);
148
}
149
else
150
{
151
outStream <<
"<!-- XML Structural Problem! \n\n"
152
<<
" cannot find an element "
<< theElement <<
"!\n\n"
153
<<
"-->"
<< std::endl;
154
}
155
}
156
157
// template <typename DATA>
158
void
159
TBXMLWriterToolBase::closeAllElements
(std::ostream& outStream)
160
{
161
for
(
int
i=
m_elementList
.size()-1; i>=0; i-- )
162
{
163
outStream <<
"</"
<<
m_elementList
[i] <<
">"
<< std::endl;
164
}
165
m_elementList
.clear();
166
}
167
TBXMLWriterToolBase.h
TBXMLWriterToolBase::closeAllElements
virtual void closeAllElements(std::ostream &outStream)
Definition
TBXMLWriterToolBase.cxx:159
TBXMLWriterToolBase::openDictionary
virtual void openDictionary(std::ostream &outStream, const std::string &dictName, const std::vector< std::string > &listOfElements)
Definition
TBXMLWriterToolBase.cxx:18
TBXMLWriterToolBase::m_dictionary
std::string m_dictionary
Definition
TBXMLWriterToolBase.h:108
TBXMLWriterToolBase::m_elementList
std::vector< std::string > m_elementList
Definition
TBXMLWriterToolBase.h:107
TBXMLWriterToolBase::closeElement
virtual void closeElement(std::ostream &outStream, const std::string &theElement)
Definition
TBXMLWriterToolBase.cxx:139
TBXMLWriterToolBase::addDictElement
virtual void addDictElement(std::ostream &outStream, const std::string &theElement, const std::vector< std::string > &listOfElements)
Definition
TBXMLWriterToolBase.cxx:57
TBXMLWriterToolBase::closeDictionary
virtual void closeDictionary(std::ostream &outStream)
Definition
TBXMLWriterToolBase.cxx:50
TBXMLWriterToolBase::openElement
virtual void openElement(std::ostream &outStream, std::string_view theElement, const std::vector< std::string > &listOfAttr, const std::vector< std::string > &listOfValues)
Definition
TBXMLWriterToolBase.cxx:106
TBXMLWriterToolBase::m_doubleQuote
static const std::string m_doubleQuote
Definition
TBXMLWriterToolBase.h:110
TBXMLWriterToolBase::addAttributes
virtual void addAttributes(std::ostream &outStream, const std::string &theElement, const std::vector< std::string > &listOfAttributes)
Definition
TBXMLWriterToolBase.cxx:91
find
std::string find(const std::string &s)
return a remapped string
Definition
hcg.cxx:140
Generated on
for ATLAS Offline Software by
1.17.0