ATLAS Offline Software
Loading...
Searching...
No Matches
TBXMLEventWriterTool.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
8#include "TBXMLWriter.h"
9
10#include <fstream>
11#include <iomanip>
12#include <iostream>
13#include <sstream>
14
15#include <vector>
16
18 const std::string& name,
19 const IInterface* parent)
20 : TBXMLWriterToolBase(type,name,parent)
21{
22}
23
26
27StatusCode
28TBXMLEventWriterTool::writeEvent(std::ostream& outStream, std::string_view entryTag)
29{
30
31 MsgStream log(msgSvc(),name());
32
33 log << MSG::DEBUG << "EntryTag: "<< entryTag <<endmsg;
34
35 // access some data
36 const EventContext& ctx = Gaudi::Hive::currentContext();
37 unsigned int theRun = ctx.eventID().run_number();
38 unsigned int theEvent = ctx.eventID().event_number();
39 unsigned int theType = 0;
40
42 // Write XML Dictionary //
44
45 // Document type
46 std::vector<std::string> theEventElements;
47 theEventElements.push_back("EventHeader");
48 theEventElements.push_back("(CaloCellContainer*)?");
49 theEventElements.push_back("(BeamWireChambers*)?");
50 theEventElements.push_back("(BeamProfileChambers*)?");
51 theEventElements.push_back("(BeamScintillators*)?");
52 theEventElements.push_back("(TailCatcher*)?");
53 theEventElements.push_back("(PatternUnit*)?");
54 this->openDictionary(outStream,"CTB_EC2Event",theEventElements);
55 std::vector<std::string> theEventAttr;
56 theEventAttr.push_back("name CDATA #REQUIRED");
57 this->addAttributes(outStream,"CTB_EC2Event",theEventAttr);
58
59 // EventHeader
60 std::vector<std::string> theHeaderElements;
61 // theHeaderElements.push_back("TriggerWord?");
62 // theHeaderElements.push_back("TriggerPattern?");
63 this->addDictElement(outStream,"EventHeader",theHeaderElements);
64 std::vector<std::string> theHeaderAttr;
65 theHeaderAttr.push_back("name CDATA #REQUIRED");
66 theHeaderAttr.push_back("run CDATA #REQUIRED");
67 theHeaderAttr.push_back("event CDATA #REQUIRED");
68 theHeaderAttr.push_back("type CDATA #REQUIRED");
69 this->addAttributes(outStream,"EventHeader",theHeaderAttr);
70
71 // Trigger etc
72 // std::vector<std::string> anyData;
73 // anyData.push_back("ANY");
74 // this->addDictElement(outStream,"TriggerWord",anyData);
75 // this->addDictElement(outStream,"TriggerPattern",anyData);
76
77 // CaloCellContainer
78 std::vector<std::string> anyData;
79 anyData.push_back("ANY");
80 this->addDictElement(outStream,"CaloCellContainer",anyData);
81 std::vector<std::string> theCaloAttr;
82 theCaloAttr.push_back("name CDATA #REQUIRED");
83 theCaloAttr.push_back("ncols CDATA #REQUIRED");
84 theCaloAttr.push_back("nrows CDATA #REQUIRED");
85 theCaloAttr.push_back("idtype ( uint | int | short | ushort ) #REQUIRED");
86 theCaloAttr.push_back("etype ( float | double ) #REQUIRED");
87 this->addAttributes(outStream,"CaloCellContainer",theCaloAttr);
88
89 // BPC Container
90 this->addDictElement(outStream,"BeamProfileChambers",anyData);
91 std::vector<std::string> theBPCAttr;
92 theBPCAttr.push_back("name CDATA #REQUIRED");
93 theBPCAttr.push_back("cols CDATA #REQUIRED");
94 theBPCAttr.push_back("idtype ( uint | int | short | ushort ) #REQUIRED");
95 theBPCAttr.push_back("xtype ( float | double ) #REQUIRED");
96 theBPCAttr.push_back("ytype ( float | double ) #REQUIRED");
97
98 // MWPC Container
99 this->addDictElement(outStream,"BeamWireChambers",anyData);
100 std::vector<std::string> theMWPCAttr;
101 theMWPCAttr.push_back("name CDATA #REQUIRED");
102 theMWPCAttr.push_back("cols CDATA #REQUIRED");
103 theMWPCAttr.push_back("idtype ( uint | int | short | ushort ) #REQUIRED");
104 theMWPCAttr.push_back("xtype ( float | double ) #REQUIRED");
105 theMWPCAttr.push_back("ytype ( float | double ) #REQUIRED");
106
107 // Scintillator Container
108 this->addDictElement(outStream,"BeamScinitllators",anyData);
109 std::vector<std::string> theScintAttr;
110 theScintAttr.push_back("name CDATA #REQUIRED");
111 theScintAttr.push_back("cols CDATA #REQUIRED");
112 theScintAttr.push_back("idtype ( uint | int | short | ushort ) #REQUIRED");
113 theScintAttr.push_back("signal ( float | double ) #REQUIRED");
114
115 // close dictionary
116 this->closeDictionary(outStream);
117
119 // Write Event //
121
122 std::vector<std::string> theEventValues(theEventAttr.size());
123 for ( unsigned int i=0; i<theEventAttr.size(); i++ )
124 {
125 if ( (theEventAttr[i]).find("name") != std::string::npos )
126 {
127 theEventValues[i] = "EventInfo";
128 }
129 theEventAttr[i] =
130 theEventAttr[i].substr(0,theEventAttr[i].find_first_of(" "));
131 }
132 this->openElement(outStream,"EventInfo",theEventAttr,theEventValues);
133
135 // Write EventHeader //
137
138 std::vector<std::string> theHeaderValues(theHeaderAttr.size());
139 for ( unsigned int i=0; i<theHeaderAttr.size(); i++ )
140 {
141 if ( (theHeaderAttr[i]).find("name") != std::string::npos )
142 {
143 theHeaderValues[i] = "EventInfo";
144 }
145 else if ( (theHeaderAttr[i]).find("run") != std::string::npos )
146 {
147 std::ostringstream theValue; theValue << theRun << std::ends;
148 theHeaderValues[i] = theValue.str();
149 }
150 else if ( (theHeaderAttr[i]).find("event") != std::string::npos )
151 {
152 std::ostringstream theValue; theValue << theEvent << std::ends;
153 theHeaderValues[i] = theValue.str();
154 }
155 else if ( (theHeaderAttr[i]).find("type") != std::string::npos )
156 {
157 std::ostringstream theValue; theValue << theType << std::ends;
158 theHeaderValues[i] = theValue.str();
159 }
160 else
161 {
162 theHeaderValues[i] = "unknown";
163 }
164 theHeaderAttr[i] =
165 theHeaderAttr[i].substr(0,theHeaderAttr[i].find_first_of(" "));
166 }
167 // -------------------------- EventHeader
168 this->openElement(outStream,"EventHeader",
169 theHeaderAttr,theHeaderValues);
170 // ----------------------------- TriggerWord
171 // std::vector<std::string> emptyStr;
172 // this->openElement(outStream,"TriggerWord",
173 // emptyStr,emptyStr);
174 // unsigned short theTriggerWord =
175 // (unsigned short) (m_data->getTriggerWord() & 0xffff);
176 // outStream << " 0x"<< setw(4) << setfill(48) << hex << theTriggerWord
177 // << dec << std::endl;
178 // this->closeElement(outStream);
179 // ----------------------------- TriggerPattern
180 // this->openElement(outStream,"TriggerPattern",emptyStr,emptyStr);
181 // outStream << " ";
182 // std::map<std::string,unsigned int>::const_iterator
183 // first = m_triggerBitMap.begin();
184 // std::map<std::string,unsigned int>::const_iterator
185 // last = m_triggerBitMap.end();
186 // for ( ; first != last; first++ )
187 // {
188 // if ( ( theTriggerWord & (*first).second ) == (*first).second )
189 // {
190 // outStream << "\042" << (*first).first << "\042 ";
191 // }
192 // }
193 outStream << std::endl;
194 this->closeElement(outStream);
195
196 // this->closeElement(outStream,"EventHeader");
197 return StatusCode::SUCCESS;
198}
199
200StatusCode
201TBXMLEventWriterTool::writeRunFiles(const std::string& /* fileDir */,
202 unsigned int /* runNumber */ )
203{
204 return StatusCode::SUCCESS;
205}
#define endmsg
TBXMLEventWriterTool(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode writeEvent(std::ostream &outFile, std::string_view entryTag) override
virtual StatusCode writeRunFiles(const std::string &, unsigned int) override
virtual void openDictionary(std::ostream &outStream, const std::string &dictName, const std::vector< std::string > &listOfElements)
TBXMLWriterToolBase(const std::string &type, const std::string &name, const IInterface *parent)
virtual void closeElement(std::ostream &outStream, const std::string &theElement)
virtual void addDictElement(std::ostream &outStream, const std::string &theElement, const std::vector< std::string > &listOfElements)
virtual void closeDictionary(std::ostream &outStream)
virtual void openElement(std::ostream &outStream, std::string_view theElement, const std::vector< std::string > &listOfAttr, const std::vector< std::string > &listOfValues)
virtual void addAttributes(std::ostream &outStream, const std::string &theElement, const std::vector< std::string > &listOfAttributes)
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140