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

Persistency writer for YODA 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 &c)
 
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 (std::ostream &stream, const std::vector< const AnalysisObject * > &aos)
 
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)
 
template<typename AOITER >
void write (const std::string &filename, const AOITER &begin, const AOITER &end)
 

Detailed Description

Persistency writer for YODA 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 c 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 42 of file WriterYODA1.cc.

42 {
43 const string aotype = ao.type();
44 if (aotype == "Counter") {
45 writeCounter(stream, dynamic_cast<const Counter&>(ao));
46 } else if (aotype == "Histo1D") {
47 writeHisto1D(stream, dynamic_cast<const Histo1D&>(ao));
48 } else if (aotype == "Histo2D") {
49 writeHisto2D(stream, dynamic_cast<const Histo2D&>(ao));
50 } else if (aotype == "Profile1D") {
51 writeProfile1D(stream, dynamic_cast<const Profile1D&>(ao));
52 } else if (aotype == "Profile2D") {
53 writeProfile2D(stream, dynamic_cast<const Profile2D&>(ao));
54 } else if (aotype == "Scatter1D") {
55 writeScatter1D(stream, dynamic_cast<const Scatter1D&>(ao));
56 } else if (aotype == "Scatter2D") {
57 writeScatter2D(stream, dynamic_cast<const Scatter2D&>(ao));
58 } else if (aotype == "Scatter3D") {
59 writeScatter3D(stream, dynamic_cast<const Scatter3D&>(ao));
60 } else {
61 stream << "# Type " << aotype << " not supported in the legacy writer.\n";
62 // Skip writing other AO types since they were not supported in YODA1.
63 }
64 }
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:904
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:902
ScatterND< 2 > Scatter2D
Definition Scatter.h:903

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 67 of file WriterYODA1.cc.

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

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 81 of file WriterYODA1.cc.

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

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
Todo:
Disabled for now, reinstate with a full set of outflow info to allow marginalisation

Definition at line 119 of file WriterYODA1.cc.

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

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 159 of file WriterYODA1.cc.

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

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
Todo:
Disabled for now, reinstate with a full set of outflow info to allow marginalisation

Definition at line 195 of file WriterYODA1.cc.

195 {
196 ios_base::fmtflags oldflags = os.flags();
197 os << scientific << showpoint << setprecision(_aoprecision);
198
199 os << "BEGIN YODA_" << Utils::toUpper("PROFILE2D") << "_V2 " << p.path() << "\n";
200 _writeAnnotations(os, p);
201 os << "# sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwz\t sumwz2\t sumwxy\t numEntries\n";
202 // Total distribution
203 os << "Total \tTotal \t";
204 os << p.sumW() << "\t" << p.sumW2() << "\t";
205 os << p.sumWA(0) << "\t" << p.sumWA2(0) << "\t";
206 os << p.sumWA(1) << "\t" << p.sumWA2(1) << "\t";
207 os << p.sumWA(2) << "\t" << p.sumWA2(2) << "\t";
208 os << p.crossTerm(0,1) << "\t"; // << td.sumWXZ() << "\t" << td.sumWYZ() << "\t";
209 os << p.numEntries() << "\n";
210 // Outflows
212 os << "# 2D outflow persistency not currently supported until API is stable\n";
213 // Bins
214 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";
215 for (const auto& b : p.bins()) {
216 os << b.xMin() << "\t" << b.xMax() << "\t";
217 os << b.yMin() << "\t" << b.yMax() << "\t";
218 os << b.sumW() << "\t" << b.sumW2() << "\t";
219 os << b.sumWX() << "\t" << b.sumWX2() << "\t";
220 os << b.sumWY() << "\t" << b.sumWY2() << "\t";
221 os << b.sumWZ() << "\t" << b.sumWZ2() << "\t";
222 os << b.sumWXY() << "\t"; // << b.sumWXZ() << "\t" << b.sumWYZ() << "\t";
223 os << b.numEntries() << "\n";
224 }
225 os << "END YODA_" << Utils::toUpper("PROFILE2D") << "_V2\n\n";
226
227 os.flags(oldflags);
228 }

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 231 of file WriterYODA1.cc.

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

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 259 of file WriterYODA1.cc.

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

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 291 of file WriterYODA1.cc.

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

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: