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