yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
WriterAIDA.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of YODA -- Yet more Objects for Data Analysis
4 // Copyright (C) 2008-2017 The YODA collaboration (see AUTHORS for details)
5 //
6 #include "YODA/WriterAIDA.h"
8 
9 #include <iostream>
10 #include <iomanip>
11 
12 using namespace std;
13 
14 namespace YODA {
15 
17  Writer& WriterAIDA::create() {
18  static WriterAIDA _instance;
19  _instance.setPrecision(6);
20  return _instance;
21  }
22 
23 
24  void WriterAIDA::writeHead(std::ostream& stream) {
25  stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
26  stream << "<!DOCTYPE aida SYSTEM \"http://aida.freehep.org/schemas/3.0/aida.dtd\">\n";
27  stream << "<aida>\n";
28  stream << " <implementation version=\"1.0\" package=\"YODA\"/>\n";
29  }
30 
31 
32  void WriterAIDA::writeFoot(std::ostream& stream) {
33  stream << "</aida>\n" << flush;
34  }
35 
36 
37  void WriterAIDA::writeCounter(std::ostream& os, const Counter&) {
38  os << endl << "<!-- COUNTER WRITING TO AIDA IS CURRENTLY UNSUPPORTED! -->" << endl << endl;
39  }
40 
41 
42  void WriterAIDA::writeHisto1D(std::ostream& os, const Histo1D& h) {
43  Scatter2D tmp = mkScatter(h);
44  tmp.setAnnotation("Type", "Histo1D");
45  writeScatter2D(os, tmp);
46  }
47 
48 
49  void WriterAIDA::writeHisto2D(std::ostream& os, const Histo2D&) {
50  os << endl << "<!-- HISTO2D WRITING TO AIDA IS CURRENTLY UNSUPPORTED! -->" << endl << endl;
51  // Scatter3D tmp = mkScatter(h);
52  // tmp.setAnnotation("Type", "Histo2D");
53  // writeScatter3D(os, tmp);
54  }
55 
56 
57  void WriterAIDA::writeProfile1D(std::ostream& os, const Profile1D& p) {
58  Scatter2D tmp = mkScatter(p);
59  tmp.setAnnotation("Type", "Profile1D");
60  writeScatter2D(os, tmp);
61  }
62 
63 
64  void WriterAIDA::writeProfile2D(std::ostream& os, const Profile2D& p) {
65  os << endl << "<!-- PROFILE2D WRITING TO AIDA IS CURRENTLY UNSUPPORTED! -->" << endl << endl;
66  // Scatter3D tmp = mkScatter(p);
67  // tmp.setAnnotation("Type", "Profile2D");
68  // writeScatter3D(os, tmp);
69  }
70 
71 
72  void WriterAIDA::writeScatter1D(std::ostream& os, const Scatter1D& s) {
73  os << endl << "<!-- SCATTER1D WRITING TO AIDA IS CURRENTLY UNSUPPORTED! -->" << endl << endl;
74  }
75 
76 
77  void WriterAIDA::writeScatter2D(std::ostream& os, const Scatter2D& s) {
78  ios_base::fmtflags oldflags = os.flags();
79  // const int precision = 8;
80  os << scientific << showpoint << setprecision(_precision);
81 
82  string name = "";
83  string path = "/";
84  const size_t slashpos = s.path().rfind("/");
85  if (slashpos != string::npos) {
86  name = s.path().substr(slashpos+1, s.path().length() - slashpos - 1);
87  if (slashpos > 0) path = s.path().substr(0, slashpos);
88  }
89  os << " <dataPointSet name=\"" << Utils::encodeForXML(name) << "\"\n"
90  << " title=\"" << Utils::encodeForXML(s.title()) << "\""
91  << " path=\"" << Utils::encodeForXML(path) << "\" dimension=\"2\">\n";
92  os << " <dimension dim=\"0\" title=\"\" />\n";
93  os << " <dimension dim=\"1\" title=\"\" />\n";
94  os << " <annotation>\n";
95  for (const string& a : s.annotations()) {
96  if (a.empty()) continue;
97  os << " <item key=\"" << Utils::encodeForXML(a)
98  << "\" value=\"" << Utils::encodeForXML(s.annotation(a)) << "\" />\n";
99  }
100  if (!s.hasAnnotation("Type")) {
101  os << " <item key=\"Type\" value=\"Scatter2D\" />\n";
102  }
103  os << " </annotation>\n";
104  for (const Point2D& pt : s.points()) {
105  os << " <dataPoint>\n";
106  os << " <measurement value=\"" << pt.x()
107  << "\" errorPlus=\"" << pt.xErrPlus()
108  << "\" errorMinus=\"" << pt.xErrMinus()
109  << "\"/>\n";
110  os << " <measurement value=\"" << pt.y()
111  << "\" errorPlus=\"" << pt.yErrPlus()
112  << "\" errorMinus=\"" << pt.yErrMinus()
113  << "\"/>\n";
114  os << " </dataPoint>\n";
115  }
116  os << " </dataPointSet>\n";
117  os << flush;
118 
119  os.flags(oldflags);
120  }
121 
122 
123  void WriterAIDA::writeScatter3D(std::ostream& os, const Scatter3D& s) {
124  os << endl << "<!-- SCATTER3D WRITING TO AIDA IS CURRENTLY UNSUPPORTED! -->" << endl << endl;
125  }
126 
127 
128 }
const std::string path() const
Get the AO path.
A very generic data type which is just a collection of 2D data points with errors.
Definition: Scatter2D.h:24
STL namespace.
A weighted counter.
Definition: Counter.h:23
A one-dimensional histogram.
Definition: Histo1D.h:26
A two-dimensional profile histogram.
Definition: Profile2D.h:31
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:9
Pure virtual base class for various output writers.
Definition: Writer.h:28
const std::string title() const
Get the AO title.
void setPrecision(int precision)
Set precision of numerical quantities in this writer&#39;s output.
Definition: Writer.h:154
A very generic data type which is just a collection of 3D data points with errors.
Definition: Scatter3D.h:24
Persistency writer for AIDA XML format.
Definition: WriterAIDA.h:16
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.
A very generic data type which is just a collection of 1D data points with errors.
Definition: Scatter1D.h:23
A two-dimensional histogram.
Definition: Histo2D.h:31
A one-dimensional profile histogram.
Definition: Profile1D.h:33
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.
std::vector< std::string > annotations() const
Points & points()
Get the collection of points (non-const)
Definition: Scatter2D.h:185
A 2D data point to be contained in a Scatter2D.
Definition: Point2D.h:18