yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.1.0

Legacy persistency writer for YODA1-style flat text format. More...

#include <WriterYODA1.h>

Inheritance diagram for YODA::WriterYODA1:
YODA::Writer

Static Public Member Functions

static Writercreate ()
 Singleton creation function.
 

Protected Member Functions

void writeAO (std::ostream &stream, const AnalysisObject &ao)
 
void writeCounter (std::ostream &stream, const Counter &c)
 
void writeHisto1D (std::ostream &stream, const Histo1D &h)
 
void writeHisto2D (std::ostream &stream, const Histo2D &h)
 
void writeProfile1D (std::ostream &stream, const Profile1D &p)
 
void writeProfile2D (std::ostream &stream, const Profile2D &p)
 
void writeScatter1D (std::ostream &stream, const Scatter1D &s)
 
void writeScatter2D (std::ostream &stream, const Scatter2D &s)
 
void writeScatter3D (std::ostream &stream, const Scatter3D &s)
 
- Protected Member Functions inherited from YODA::Writer
virtual void writeHead (std::ostream &)
 Write any opening boilerplate required by the format to stream.
 
virtual void writeBody (std::ostream &stream, const AnalysisObject *ao)
 Write the body elements corresponding to AnalysisObject ao to stream.
 
virtual void writeBody (std::ostream &stream, const AnalysisObject &ao)
 Write the body elements corresponding to AnalysisObject pointer ao to stream.
 
template<typename T >
std::enable_if_t< DerefableToAO< T >::value > writeBody (std::ostream &stream, const T &ao)
 Write the body elements corresponding to AnalysisObject ao to stream.
 
virtual void writeFoot (std::ostream &stream)
 Write any closing boilerplate required by the format to stream.
 

Additional Inherited Members

- Public Member Functions inherited from YODA::Writer
virtual ~Writer ()
 Virtual destructor.
 
void setPrecision (int precision)
 Set precision of numerical quantities in this writer's output.
 
void setAOPrecision (const bool needsDP=false)
 Set precision of numerical quantities for current AO in this writer's output.
 
void useCompression (const bool compress=true)
 Use libz compression?
 
void write (const std::string &filename, const AnalysisObject &ao)
 Write out object ao to file filename.
 
void write (std::ostream &stream, const AnalysisObject &ao)
 Write out object ao to output stream stream.
 
template<typename T >
std::enable_if_t< DerefableToAO< T >::value > write (std::ostream &stream, const T &ao)
 Write out pointer-like object ao to output stream stream.
 
template<typename T >
std::enable_if_t< DerefableToAO< T >::value > write (const std::string &filename, const T &ao)
 Write out pointer-like object ao to file filename.
 
void write (YODA_H5::File &file, const std::vector< const AnalysisObject * > &aos)
 
void write (std::ostream &stream, const std::vector< const AnalysisObject * > &aos, int precision=-1)
 
template<typename RANGE >
std::enable_if_t< CIterable< RANGE >::value > write (std::ostream &stream, const RANGE &aos)
 
template<typename RANGE >
std::enable_if_t< CIterable< RANGE >::value > write (const std::string &filename, const RANGE &aos)
 Write out a collection of objects objs to file filename.
 
template<typename AOITER >
void write (std::ostream &stream, const AOITER &begin, const AOITER &end, int precision=-1)
 
template<typename AOITER >
void write (const std::string &filename, const AOITER &begin, const AOITER &end)
 

Detailed Description

Legacy persistency writer for YODA1-style flat text format.

Definition at line 20 of file WriterYODA1.h.

Member Function Documentation

◆ create()

Writer & YODA::WriterYODA1::create ( )
static

Singleton creation function.

Definition at line 21 of file WriterYODA1.cc.

21 {
22 static WriterYODA1 _instance;
23 _instance.setPrecision(6);
24 return _instance;
25 }

References YODA::Writer::setPrecision().

◆ writeAO()

void YODA::WriterYODA1::writeAO ( std::ostream &  stream,
const AnalysisObject ao 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 43 of file WriterYODA1.cc.

43 {
44 const string aotype = ao.type();
45 if (aotype == "Counter") {
46 writeCounter(stream, dynamic_cast<const Counter&>(ao));
47 } else if (aotype == "Histo1D") {
48 writeHisto1D(stream, dynamic_cast<const Histo1D&>(ao));
49 } else if (aotype == "Histo2D") {
50 writeHisto2D(stream, dynamic_cast<const Histo2D&>(ao));
51 } else if (aotype == "Profile1D") {
52 writeProfile1D(stream, dynamic_cast<const Profile1D&>(ao));
53 } else if (aotype == "Profile2D") {
54 writeProfile2D(stream, dynamic_cast<const Profile2D&>(ao));
55 } else if (aotype == "Scatter1D") {
56 writeScatter1D(stream, dynamic_cast<const Scatter1D&>(ao));
57 } else if (aotype == "Scatter2D") {
58 writeScatter2D(stream, dynamic_cast<const Scatter2D&>(ao));
59 } else if (aotype == "Scatter3D") {
60 writeScatter3D(stream, dynamic_cast<const Scatter3D&>(ao));
61 } else {
62 stream << "# Type " << aotype << " not supported in the legacy writer.\n";
63 // Skip writing other AO types since they were not supported in YODA1.
64 }
65 }
void writeScatter1D(std::ostream &stream, const Scatter1D &s)
void writeCounter(std::ostream &stream, const Counter &c)
void writeScatter3D(std::ostream &stream, const Scatter3D &s)
void writeScatter2D(std::ostream &stream, const Scatter2D &s)
void writeHisto1D(std::ostream &stream, const Histo1D &h)
void writeProfile1D(std::ostream &stream, const Profile1D &p)
void writeProfile2D(std::ostream &stream, const Profile2D &p)
void writeHisto2D(std::ostream &stream, const Histo2D &h)
BinnedHisto< double, double > Histo2D
Definition Histo.h:355
ScatterND< 3 > Scatter3D
Definition Scatter.h:903
BinnedHisto< double > Histo1D
User-friendly familiar names (continuous axes only)
Definition Histo.h:354
BinnedProfile< double > Profile1D
User-friendly familiar names (continuous axes only)
Definition Profile.h:350
BinnedProfile< double, double > Profile2D
Definition Profile.h:351
ScatterND< 1 > Scatter1D
Definition Scatter.h:901
ScatterND< 2 > Scatter2D
Definition Scatter.h:902

References YODA::AnalysisObject::type(), writeCounter(), writeHisto1D(), writeHisto2D(), writeProfile1D(), writeProfile2D(), writeScatter1D(), writeScatter2D(), and writeScatter3D().

◆ writeCounter()

void YODA::WriterYODA1::writeCounter ( std::ostream &  stream,
const Counter c 
)
protected

Definition at line 68 of file WriterYODA1.cc.

68 {
69 ios_base::fmtflags oldflags = os.flags();
70 os << scientific << showpoint << setprecision(_aoprecision);
71
72 os << "BEGIN YODA_" << Utils::toUpper("COUNTER") << "_V2 " << c.path() << "\n";
73 _writeAnnotations(os, c);
74 os << "# sumW\t sumW2\t numEntries\n";
75 os << c.sumW() << "\t" << c.sumW2() << "\t" << c.numEntries() << "\n";
76 os << "END YODA_" << Utils::toUpper("COUNTER") << "_V2\n\n";
77
78 os.flags(oldflags);
79 }

References YODA::Counter::numEntries(), YODA::AnalysisObject::path(), YODA::Counter::sumW(), and YODA::Counter::sumW2().

Referenced by writeAO().

◆ writeHisto1D()

void YODA::WriterYODA1::writeHisto1D ( std::ostream &  stream,
const Histo1D h 
)
protected

Definition at line 82 of file WriterYODA1.cc.

82 {
83 ios_base::fmtflags oldflags = os.flags();
84 os << scientific << showpoint << setprecision(_aoprecision);
85
86 os << "BEGIN YODA_" << Utils::toUpper("HISTO1D") << "_V2 " << h.path() << "\n";
87 _writeAnnotations(os, h);
88 os << "# Mean: " << h.xMean() << "\n";
89 os << "# Area: " << h.integral() << "\n";
90 os << "# ID\t ID\t sumw\t sumw2\t sumwx\t sumwx2\t numEntries\n";
91 os << "Total \tTotal \t";
92 os << h.sumW() << "\t" << h.sumW2() << "\t";
93 os << h.sumWA(0) << "\t" << h.sumWA2(0) << "\t";
94 os << h.numEntries() << "\n";
95 os << "Underflow\tUnderflow\t";
96 os << h.bin(0).sumW() << "\t" << h.bin(0).sumW2() << "\t";
97 os << h.bin(0).sumWX() << "\t" << h.bin(0).sumWX2() << "\t";
98 os << h.bin(0).numEntries() << "\n";
99 os << "Overflow\tOverflow\t";
100 os << h.bin(h.numBins()+1).sumW() << "\t" << h.bin(h.numBins()+1).sumW2() << "\t";
101 os << h.bin(h.numBins()+1).sumWX() << "\t" << h.bin(h.numBins()+1).sumWX2() << "\t";
102 os << h.bin(h.numBins()+1).numEntries() << "\n";
103 os << "# xlow\t xhigh\t sumw\t sumw2\t sumwx\t sumwx2\t numEntries\n";
104 for (const auto& b : h.bins()) {
105 os << b.xMin() << "\t" << b.xMax() << "\t";
106 os << b.sumW() << "\t" << b.sumW2() << "\t";
107 os << b.sumWX() << "\t" << b.sumWX2() << "\t";
108 os << b.numEntries() << "\n";
109 }
110 os << "END YODA_" << Utils::toUpper("HISTO1D") << "_V2\n\n";
111
112 os.flags(oldflags);
113 }

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), YODA::BinnedStorage< BinContentT, AxisT >::bins(), YODA::DbnStorage< DbnN, AxisT >::integral(), YODA::BinnedStorage< BinContentT, AxisT >::numBins(), YODA::DbnStorage< DbnN, AxisT >::numEntries(), YODA::AnalysisObject::path(), YODA::DbnStorage< DbnN, AxisT >::sumW(), YODA::DbnStorage< DbnN, AxisT >::sumW2(), YODA::DbnStorage< DbnN, AxisT >::sumWA(), and YODA::DbnStorage< DbnN, AxisT >::sumWA2().

Referenced by writeAO().

◆ writeHisto2D()

void YODA::WriterYODA1::writeHisto2D ( std::ostream &  stream,
const Histo2D h 
)
protected

Definition at line 116 of file WriterYODA1.cc.

116 {
117 ios_base::fmtflags oldflags = os.flags();
118 os << scientific << showpoint << setprecision(_aoprecision);
119 os << "BEGIN YODA_" << Utils::toUpper("HISTO2D") << "_V2 " << h.path() << "\n";
120 _writeAnnotations(os, h);
121 //if ( h.totalDbn().numEntries() > 0 )
122 os << "# Mean: (" << h.xMean() << ", " << h.yMean() << ")\n";
123 os << "# Volume: " << h.integral() << "\n";
124 os << "# ID\t ID\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwxy\t numEntries\n";
125 // Total distribution
126 os << "Total \tTotal \t";
127 os << h.sumW() << "\t" << h.sumW2() << "\t";
128 os << h.sumWA(0) << "\t" << h.sumWA2(0) << "\t";
129 os << h.sumWA(1) << "\t" << h.sumWA2(1) << "\t";
130 os << h.crossTerm(0,1) << "\t";
131 os << h.numEntries() << "\n";
132 // Outflows
133 os << "# 2D outflow persistency not currently supported until API is stable\n";
134 // Bins
135 os << "# xlow\t xhigh\t ylow\t yhigh\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwxy\t numEntries\n";
136 for (const auto& b : h.bins()) {
137 os << b.xMin() << "\t" << b.xMax() << "\t";
138 os << b.yMin() << "\t" << b.yMax() << "\t";
139 os << b.sumW() << "\t" << b.sumW2() << "\t";
140 os << b.sumWX() << "\t" << b.sumWX2() << "\t";
141 os << b.sumWY() << "\t" << b.sumWY2() << "\t";
142 os << b.sumWXY() << "\t";
143 os << b.numEntries() << "\n";
144 }
145 os << "END YODA_" << Utils::toUpper("HISTO2D") << "_V2\n\n";
146
147 os.flags(oldflags);
148 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins(), YODA::DbnStorage< DbnN, AxisT >::crossTerm(), YODA::DbnStorage< DbnN, AxisT >::integral(), YODA::DbnStorage< DbnN, AxisT >::numEntries(), YODA::AnalysisObject::path(), YODA::DbnStorage< DbnN, AxisT >::sumW(), YODA::DbnStorage< DbnN, AxisT >::sumW2(), YODA::DbnStorage< DbnN, AxisT >::sumWA(), and YODA::DbnStorage< DbnN, AxisT >::sumWA2().

Referenced by writeAO().

◆ writeProfile1D()

void YODA::WriterYODA1::writeProfile1D ( std::ostream &  stream,
const Profile1D p 
)
protected

Definition at line 151 of file WriterYODA1.cc.

151 {
152 ios_base::fmtflags oldflags = os.flags();
153 os << scientific << showpoint << setprecision(_aoprecision);
154
155 os << "BEGIN YODA_" << Utils::toUpper("PROFILE1D") << "_V2 " << p.path() << "\n";
156 _writeAnnotations(os, p);
157 os << "# ID\t ID\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t numEntries\n";
158 os << "Total \tTotal \t";
159 os << p.sumW() << "\t" << p.sumW2() << "\t";
160 os << p.sumWA(0) << "\t" << p.sumWA2(0) << "\t";
161 os << p.sumWA(1) << "\t" << p.sumWA2(1) << "\t";
162 os << p.numEntries() << "\n";
163 os << "Underflow\tUnderflow\t";
164 os << p.bin(0).sumW() << "\t" << p.bin(0).sumW2() << "\t";
165 os << p.bin(0).sumWX() << "\t" << p.bin(0).sumWX2() << "\t";
166 os << p.bin(0).sumWY() << "\t" << p.bin(0).sumWY2() << "\t";
167 os << p.bin(0).numEntries() << "\n";
168 os << "Overflow\tOverflow\t";
169 os << p.bin(p.numBins()+1).sumW() << "\t" << p.bin(p.numBins()+1).sumW2() << "\t";
170 os << p.bin(p.numBins()+1).sumWX() << "\t" << p.bin(p.numBins()+1).sumWX2() << "\t";
171 os << p.bin(p.numBins()+1).sumWY() << "\t" << p.bin(p.numBins()+1).sumWY2() << "\t";
172 os << p.bin(p.numBins()+1).numEntries() << "\n";
173 os << "# xlow\t xhigh\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t numEntries\n";
174 for (const auto& b : p.bins()) {
175 os << b.xMin() << "\t" << b.xMax() << "\t";
176 os << b.sumW() << "\t" << b.sumW2() << "\t";
177 os << b.sumWX() << "\t" << b.sumWX2() << "\t";
178 os << b.sumWY() << "\t" << b.sumWY2() << "\t";
179 os << b.numEntries() << "\n";
180 }
181 os << "END YODA_" << Utils::toUpper("PROFILE1D") << "_V2\n\n";
182
183 os.flags(oldflags);
184 }

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), YODA::BinnedStorage< BinContentT, AxisT >::bins(), YODA::BinnedStorage< BinContentT, AxisT >::numBins(), YODA::DbnStorage< DbnN, AxisT >::numEntries(), YODA::AnalysisObject::path(), YODA::DbnStorage< DbnN, AxisT >::sumW(), YODA::DbnStorage< DbnN, AxisT >::sumW2(), YODA::DbnStorage< DbnN, AxisT >::sumWA(), and YODA::DbnStorage< DbnN, AxisT >::sumWA2().

Referenced by writeAO().

◆ writeProfile2D()

void YODA::WriterYODA1::writeProfile2D ( std::ostream &  stream,
const Profile2D p 
)
protected

Definition at line 187 of file WriterYODA1.cc.

187 {
188 ios_base::fmtflags oldflags = os.flags();
189 os << scientific << showpoint << setprecision(_aoprecision);
190
191 os << "BEGIN YODA_" << Utils::toUpper("PROFILE2D") << "_V2 " << p.path() << "\n";
192 _writeAnnotations(os, p);
193 os << "# sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwz\t sumwz2\t sumwxy\t numEntries\n";
194 // Total distribution
195 os << "Total \tTotal \t";
196 os << p.sumW() << "\t" << p.sumW2() << "\t";
197 os << p.sumWA(0) << "\t" << p.sumWA2(0) << "\t";
198 os << p.sumWA(1) << "\t" << p.sumWA2(1) << "\t";
199 os << p.sumWA(2) << "\t" << p.sumWA2(2) << "\t";
200 os << p.crossTerm(0,1) << "\t"; // << td.sumWXZ() << "\t" << td.sumWYZ() << "\t";
201 os << p.numEntries() << "\n";
202 // Outflows
203 os << "# 2D outflow persistency not currently supported until API is stable\n";
204 // Bins
205 os << "# xlow\t xhigh\t ylow\t yhigh\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwz\t sumwz2\t sumwxy\t numEntries\n";
206 for (const auto& b : p.bins()) {
207 os << b.xMin() << "\t" << b.xMax() << "\t";
208 os << b.yMin() << "\t" << b.yMax() << "\t";
209 os << b.sumW() << "\t" << b.sumW2() << "\t";
210 os << b.sumWX() << "\t" << b.sumWX2() << "\t";
211 os << b.sumWY() << "\t" << b.sumWY2() << "\t";
212 os << b.sumWZ() << "\t" << b.sumWZ2() << "\t";
213 os << b.sumWXY() << "\t"; // << b.sumWXZ() << "\t" << b.sumWYZ() << "\t";
214 os << b.numEntries() << "\n";
215 }
216 os << "END YODA_" << Utils::toUpper("PROFILE2D") << "_V2\n\n";
217
218 os.flags(oldflags);
219 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins(), YODA::DbnStorage< DbnN, AxisT >::crossTerm(), YODA::DbnStorage< DbnN, AxisT >::numEntries(), YODA::AnalysisObject::path(), YODA::DbnStorage< DbnN, AxisT >::sumW(), YODA::DbnStorage< DbnN, AxisT >::sumW2(), YODA::DbnStorage< DbnN, AxisT >::sumWA(), and YODA::DbnStorage< DbnN, AxisT >::sumWA2().

Referenced by writeAO().

◆ writeScatter1D()

void YODA::WriterYODA1::writeScatter1D ( std::ostream &  stream,
const Scatter1D s 
)
protected

Definition at line 222 of file WriterYODA1.cc.

222 {
223 ios_base::fmtflags oldflags = os.flags();
224 os << scientific << showpoint << setprecision(_aoprecision);
225
226 // we promised not to modify const s, but we want to add an annotation
227 // we did not promise to not modify the *clone* of s...
228 auto sclone = s.clone();
229
230 os << "BEGIN YODA_" << Utils::toUpper("SCATTER1D") << "_V2 " << s.path() << "\n";
231 _writeAnnotations(os, sclone);
232
233 //write headers
234 std::string headers="# xval\t xerr-\t xerr+\t";
235 os << headers << "\n";
236
237 //write points
238 for (const Point1D& pt : s.points()) {
239 // fill central value
240 os << pt.x() << "\t" << pt.xErrMinus() << "\t" << pt.xErrPlus() ;
241 os << "\n";
242 }
243 os << "END YODA_" << Utils::toUpper("SCATTER1D") << "_V2\n\n";
244
245 os << flush;
246 os.flags(oldflags);
247 }
PointND< 1 > Point1D
User-familiar alias.
Definition Point.h:714

References YODA::ScatterND< N >::clone(), YODA::AnalysisObject::path(), and YODA::ScatterND< N >::points().

Referenced by writeAO().

◆ writeScatter2D()

void YODA::WriterYODA1::writeScatter2D ( std::ostream &  stream,
const Scatter2D s 
)
protected
Todo:
Change ordering to {vals} {errs} {errs} ...
Todo:
Change ordering to {vals} {errs} {errs} ...

Definition at line 250 of file WriterYODA1.cc.

250 {
251 ios_base::fmtflags oldflags = os.flags();
252 os << scientific << showpoint << setprecision(_aoprecision);
253 os << "BEGIN YODA_" << Utils::toUpper("SCATTER2D") << "_V2 " << s.path() << "\n";
254
255 // Write annotations.
256 // We promised not to modify const s, but we want to add an annotation;
257 // We did not promise to not modify the *clone* of s;
258 // Judge not, lest ye be judged
259 auto sclone = s.clone();
260 _writeAnnotations(os, sclone);
261
262 //write headers
264 std::string headers="# xval\t xerr-\t xerr+\t yval\t yerr-\t yerr+\t";
265 os << headers << "\n";
266
267 //write points
268 for (const Point2D& pt : s.points()) {
270 // fill central value
271 os << pt.x() << "\t" << pt.xErrMinus() << "\t" << pt.xErrPlus() << "\t";
272 os << pt.y() << "\t" << pt.yErrMinus() << "\t" << pt.yErrPlus() ;
273 os << "\n";
274 }
275 os << "END YODA_" << Utils::toUpper("SCATTER2D") << "_V2\n\n";
276
277 os << flush;
278 os.flags(oldflags);
279 }
PointND< 2 > Point2D
Definition Point.h:715

References YODA::ScatterND< N >::clone(), YODA::AnalysisObject::path(), and YODA::ScatterND< N >::points().

Referenced by writeAO().

◆ writeScatter3D()

void YODA::WriterYODA1::writeScatter3D ( std::ostream &  stream,
const Scatter3D s 
)
protected
Todo:
Change ordering to {vals} {errs} {errs} ...
Todo:
Change ordering to {vals} {errs} {errs} ...

Definition at line 282 of file WriterYODA1.cc.

282 {
283 ios_base::fmtflags oldflags = os.flags();
284 os << scientific << showpoint << setprecision(_aoprecision);
285 os << "BEGIN YODA_" << Utils::toUpper("SCATTER3D") << "_V2 " << s.path() << "\n";
286
287 // write annotations
288 // we promised not to modify const s, but we want to add an annotation
289 // we did not promise to not modify the *clone* of s...
290 auto sclone = s.clone();
291 _writeAnnotations(os, sclone);
292
293 //write headers
295 std::string headers="# xval\t xerr-\t xerr+\t yval\t yerr-\t yerr+\t zval\t zerr-\t zerr+\t";
296 os << headers << "\n";
297
298 //write points
299 for (const Point3D& pt : s.points()) {
301 // fill central value
302 os << pt.x() << "\t" << pt.xErrMinus() << "\t" << pt.xErrPlus() << "\t";
303 os << pt.y() << "\t" << pt.yErrMinus() << "\t" << pt.yErrPlus() << "\t";
304 os << pt.z() << "\t" << pt.zErrMinus() << "\t" << pt.zErrPlus() ;
305 os << "\n";
306 }
307 os << "END YODA_" << Utils::toUpper("SCATTER3D") << "_V2\n\n";
308
309 os << flush;
310 os.flags(oldflags);
311 }
PointND< 3 > Point3D
Definition Point.h:716

References YODA::ScatterND< N >::clone(), YODA::AnalysisObject::path(), and YODA::ScatterND< N >::points().

Referenced by writeAO().


The documentation for this class was generated from the following files: