ATLAS Offline Software
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 
7 namespace JiveXML {
8 
13  XMLFormatTool::XMLFormatTool( const std::string& type , const std::string& name, const IInterface* 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 
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 
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
jetMakeRefSamples.geometryVersion
string geometryVersion
Definition: jetMakeRefSamples.py:68
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
JiveXML::XMLFormatTool::XMLFormatTool
XMLFormatTool(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: XMLFormatTool.cxx:13
JiveXML::XMLFormatTool::m_release
std::string m_release
the release tag
Definition: XMLFormatTool.h:62
JiveXML::XMLFormatTool::initialize
virtual StatusCode initialize() override
Initialize.
Definition: XMLFormatTool.cxx:26
sct_calib_tf.EventNumber
int EventNumber
Definition: sct_calib_tf.py:29
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
JiveXML::XMLFormatTool::AddToEvent
virtual StatusCode AddToEvent(const std::string &component, const std::string &key, const DataMap *aMap) override
Append a formatted version of one event component.
Definition: XMLFormatTool.cxx:112
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
JiveXML::XMLFormatTool::StartEvent
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.
Definition: XMLFormatTool.cxx:60
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:21
SCT_Cabling::dateTime
std::string dateTime()
Definition: SCT_CablingXmlTags.h:55
JiveXML::XMLFormatTool::SetTag
virtual StatusCode SetTag(const TagType tag) override
Set additional tags.
Definition: XMLFormatTool.cxx:45
EventInfoWrite.RunNumber
RunNumber
Definition: EventInfoWrite.py:50
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
XMLFormatTool.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
JiveXML::XMLFormatTool::EndEvent
virtual StatusCode EndEvent() override
Finialize this event.
Definition: XMLFormatTool.cxx:97
JiveXML::TagType
std::pair< std::string, std::string > TagType
Defines a tag as a pair of strings.
Definition: DataType.h:62
JiveXML::XMLFormatTool::m_EventBuffer
std::ostringstream * m_EventBuffer
the string buffer that will hold the complete event
Definition: XMLFormatTool.h:59
JiveXML::XMLFormatTool::finalize
virtual StatusCode finalize() override
Finalize.
Definition: XMLFormatTool.cxx:34
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
AthAlgTool
Definition: AthAlgTool.h:26
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
JiveXML::XMLFormatTool::getFormattedEvent
virtual const std::ostringstream * getFormattedEvent() const override
Return the formated stringstream.
Definition: XMLFormatTool.cxx:183
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37