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

Persistency writer for YODA flat text format. More...

#include <WriterYODA.h>

Inheritance diagram for YODA::WriterYODA:
YODA::Writer

Static Public Member Functions

static Writercreate ()
 Singleton creation function. More...
 
Writing a single analysis object.
static void write (std::ostream &stream, const AnalysisObject &ao)
 Write out object ao to output stream stream. More...
 
template<typename T >
static std::enable_if< DerefableToAO< T >::value >::type write (std::ostream &stream, const T &ao)
 Write out pointer-like object ao to output stream stream. More...
 
static void write (const std::string &filename, const AnalysisObject &ao)
 Write out object ao to file filename. More...
 
template<typename T >
static std::enable_if< DerefableToAO< T >::value >::type write (const std::string &filename, const T &ao)
 Write out pointer-like object ao to file filename. More...
 
Writing multiple analysis objects by collection.
template<typename RANGE >
static std::enable_if< CIterable< RANGE >::value >::type write (std::ostream &stream, const RANGE &aos)
 
template<typename RANGE >
static std::enable_if< CIterable< RANGE >::value >::type write (const std::string &filename, const RANGE &aos)
 
Writing multiple analysis objects by iterator range.
template<typename AOITER >
static void write (std::ostream &stream, const AOITER &begin, const AOITER &end)
 
template<typename AOITER >
static void write (const std::string &filename, const AOITER &begin, const AOITER &end)
 

Protected Member Functions

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. More...
 
virtual void writeBody (std::ostream &stream, const AnalysisObject *ao)
 Write the body elements corresponding to AnalysisObject ao to stream. More...
 
virtual void writeBody (std::ostream &stream, const AnalysisObject &ao)
 Write the body elements corresponding to AnalysisObject pointer ao to stream. More...
 
template<typename T >
std::enable_if< DerefableToAO< T >::value >::type writeBody (std::ostream &stream, const T &ao)
 Write the body elements corresponding to AnalysisObject ao to stream. More...
 
virtual void writeFoot (std::ostream &stream)
 Write any closing boilerplate required by the format to stream. More...
 

Additional Inherited Members

- Public Member Functions inherited from YODA::Writer
virtual ~Writer ()
 Virtual destructor. More...
 
void setPrecision (int precision)
 Set precision of numerical quantities in this writer's output. More...
 
void useCompression (bool compress=true)
 Use libz compression? More...
 
void write (const std::string &filename, const AnalysisObject &ao)
 Write out object ao to file filename. More...
 
void write (std::ostream &stream, const AnalysisObject &ao)
 Write out object ao to output stream stream. More...
 
template<typename T >
std::enable_if< DerefableToAO< T >::value >::type write (std::ostream &stream, const T &ao)
 Write out pointer-like object ao to output stream stream. More...
 
template<typename T >
std::enable_if< DerefableToAO< T >::value >::type write (const std::string &filename, const T &ao)
 Write out pointer-like object ao to file filename. More...
 
void write (std::ostream &stream, const std::vector< const AnalysisObject *> &aos)
 
template<typename RANGE >
std::enable_if< CIterable< RANGE >::value >::type write (std::ostream &stream, const RANGE &aos)
 
template<typename RANGE >
std::enable_if< CIterable< RANGE >::value >::type write (const std::string &filename, const RANGE &aos)
 Write out a collection of objects objs to file filename. More...
 
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 16 of file WriterYODA.h.

Member Function Documentation

◆ create()

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

Singleton creation function.

Definition at line 20 of file WriterYODA.cc.

References YODA::Writer::setPrecision().

20  {
21  static WriterYODA _instance;
22  _instance.setPrecision(6);
23  return _instance;
24  }

◆ write() [1/8]

static void YODA::WriterYODA::write ( std::ostream &  stream,
const AnalysisObject ao 
)
inlinestatic

Write out object ao to output stream stream.

Definition at line 11 of file WriterYODA.h.

12  {
13 

◆ write() [2/8]

template<typename T >
static std::enable_if<DerefableToAO<T>::value>::type YODA::WriterYODA::write ( std::ostream &  stream,
const T &  ao 
)
inlinestatic

Write out pointer-like object ao to output stream stream.

Definition at line 18 of file WriterYODA.h.

26 :
27 

◆ write() [3/8]

static void YODA::WriterYODA::write ( const std::string &  filename,
const AnalysisObject ao 
)
inlinestatic

Write out object ao to file filename.

Definition at line 21 of file WriterYODA.h.

26  :
27 
28  void writeCounter(std::ostream& stream, const Counter& c);

◆ write() [4/8]

template<typename T >
static std::enable_if<DerefableToAO<T>::value>::type YODA::WriterYODA::write ( const std::string &  filename,
const T &  ao 
)
inlinestatic

Write out pointer-like object ao to file filename.

Definition at line 33 of file WriterYODA.h.

◆ write() [5/8]

template<typename RANGE >
static std::enable_if<CIterable<RANGE>::value>::type YODA::WriterYODA::write ( std::ostream &  stream,
const RANGE &  aos 
)
inlinestatic

Definition at line 43 of file WriterYODA.h.

43  { }
44 
45  };

◆ write() [6/8]

template<typename RANGE >
static std::enable_if<CIterable<RANGE>::value>::type YODA::WriterYODA::write ( const std::string &  filename,
const RANGE &  aos 
)
inlinestatic

Definition at line 49 of file WriterYODA.h.

◆ write() [7/8]

template<typename AOITER >
static void YODA::WriterYODA::write ( std::ostream &  stream,
const AOITER &  begin,
const AOITER &  end 
)
inlinestatic

Write out the objects specified by start iterator begin and end iterator end to output stream stream.

Todo:
Add SFINAE trait checking for AOITER = DerefableToAO

Definition at line 69 of file WriterYODA.h.

◆ write() [8/8]

template<typename AOITER >
static void YODA::WriterYODA::write ( const std::string &  filename,
const AOITER &  begin,
const AOITER &  end 
)
inlinestatic

Write out the objects specified by start iterator begin and end iterator end to file filename.

Todo:
Add SFINAE trait checking for AOITER = DerefableToAO

Definition at line 78 of file WriterYODA.h.

◆ writeCounter()

void YODA::WriterYODA::writeCounter ( std::ostream &  stream,
const Counter c 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 55 of file WriterYODA.cc.

55  {
56  ios_base::fmtflags oldflags = os.flags();
57  os << scientific << showpoint << setprecision(_precision);
58 
59  os << "BEGIN " << _iotypestr("COUNTER") << " " << c.path() << "\n";
60  _writeAnnotations(os, c);
61  os << "# sumW\t sumW2\t numEntries\n";
62  os << c.sumW() << "\t" << c.sumW2() << "\t" << c.numEntries() << "\n";
63  os << "END " << _iotypestr("COUNTER") << "\n\n";
64 
65  os.flags(oldflags);
66  }

◆ writeHisto1D()

void YODA::WriterYODA::writeHisto1D ( std::ostream &  stream,
const Histo1D h 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 69 of file WriterYODA.cc.

69  {
70  ios_base::fmtflags oldflags = os.flags();
71  os << scientific << showpoint << setprecision(_precision);
72 
73  os << "BEGIN " << _iotypestr("HISTO1D") << " " << h.path() << "\n";
74  _writeAnnotations(os, h);
75  try {
76  //if ( h.totalDbn().effNumEntries() > 0 ) {
77  os << "# Mean: " << h.xMean() << "\n";
78  os << "# Area: " << h.integral() << "\n";
79  } catch (LowStatsError& e) {
80  //
81  }
82  os << "# ID\t ID\t sumw\t sumw2\t sumwx\t sumwx2\t numEntries\n";
83  os << "Total \tTotal \t";
84  os << h.totalDbn().sumW() << "\t" << h.totalDbn().sumW2() << "\t";
85  os << h.totalDbn().sumWX() << "\t" << h.totalDbn().sumWX2() << "\t";
86  os << h.totalDbn().numEntries() << "\n";
87  os << "Underflow\tUnderflow\t";
88  os << h.underflow().sumW() << "\t" << h.underflow().sumW2() << "\t";
89  os << h.underflow().sumWX() << "\t" << h.underflow().sumWX2() << "\t";
90  os << h.underflow().numEntries() << "\n";
91  os << "Overflow\tOverflow\t";
92  os << h.overflow().sumW() << "\t" << h.overflow().sumW2() << "\t";
93  os << h.overflow().sumWX() << "\t" << h.overflow().sumWX2() << "\t";
94  os << h.overflow().numEntries() << "\n";
95  os << "# xlow\t xhigh\t sumw\t sumw2\t sumwx\t sumwx2\t numEntries\n";
96  for (const HistoBin1D& b : h.bins()) {
97  os << b.xMin() << "\t" << b.xMax() << "\t";
98  os << b.sumW() << "\t" << b.sumW2() << "\t";
99  os << b.sumWX() << "\t" << b.sumWX2() << "\t";
100  os << b.numEntries() << "\n";
101  }
102  os << "END " << _iotypestr("HISTO1D") << "\n\n";
103 
104  os.flags(oldflags);
105  }

◆ writeHisto2D()

void YODA::WriterYODA::writeHisto2D ( std::ostream &  stream,
const Histo2D h 
)
protectedvirtual
Todo:
Disabled for now, reinstate with a full set of outflow info to allow marginalisation

Implements YODA::Writer.

Definition at line 108 of file WriterYODA.cc.

108  {
109  ios_base::fmtflags oldflags = os.flags();
110  os << scientific << showpoint << setprecision(_precision);
111 
112  os << "BEGIN " << _iotypestr("HISTO2D") << " " << h.path() << "\n";
113  _writeAnnotations(os, h);
114  try {
115  //if ( h.totalDbn().numEntries() > 0 )
116  os << "# Mean: (" << h.xMean() << ", " << h.yMean() << ")\n";
117  os << "# Volume: " << h.integral() << "\n";
118  } catch (LowStatsError& e) {
119  //
120  }
121  os << "# ID\t ID\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwxy\t numEntries\n";
122  // Total distribution
123  const Dbn2D& td = h.totalDbn();
124  os << "Total \tTotal \t";
125  os << td.sumW() << "\t" << td.sumW2() << "\t";
126  os << td.sumWX() << "\t" << td.sumWX2() << "\t";
127  os << td.sumWY() << "\t" << td.sumWY2() << "\t";
128  os << td.sumWXY() << "\t";
129  os << td.numEntries() << "\n";
130  // Outflows
132  os << "# 2D outflow persistency not currently supported until API is stable\n";
133  // for (int ix = -1; ix <= 1; ++ix) {
134  // for (int iy = -1; iy <= 1; ++iy) {
135  // if (ix == 0 && iy == 0) continue;
136  // os << "Outflow\t" << ix << ":" << iy << "\t";
137  // const Dbn2D& d = h.outflow(ix, iy);
138  // os << d.sumW() << "\t" << d.sumW2() << "\t";
139  // os << d.sumWX() << "\t" << d.sumWX2() << "\t";
140  // os << d.sumWY() << "\t" << d.sumWY2() << "\t";
141  // os << d.sumWXY() << "\t";
142  // os << d.numEntries() << "\n";
143  // }
144  // }
145  // Bins
146  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";
147  for (const HistoBin2D& b : h.bins()) {
148  os << b.xMin() << "\t" << b.xMax() << "\t";
149  os << b.yMin() << "\t" << b.yMax() << "\t";
150  os << b.sumW() << "\t" << b.sumW2() << "\t";
151  os << b.sumWX() << "\t" << b.sumWX2() << "\t";
152  os << b.sumWY() << "\t" << b.sumWY2() << "\t";
153  os << b.sumWXY() << "\t";
154  os << b.numEntries() << "\n";
155  }
156  os << "END " << _iotypestr("HISTO2D") << "\n\n";
157 
158  os.flags(oldflags);
159  }

◆ writeProfile1D()

void YODA::WriterYODA::writeProfile1D ( std::ostream &  stream,
const Profile1D p 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 162 of file WriterYODA.cc.

162  {
163  ios_base::fmtflags oldflags = os.flags();
164  os << scientific << showpoint << setprecision(_precision);
165 
166  os << "BEGIN " << _iotypestr("PROFILE1D") << " " << p.path() << "\n";
167  _writeAnnotations(os, p);
168  os << "# ID\t ID\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t numEntries\n";
169  os << "Total \tTotal \t";
170  os << p.totalDbn().sumW() << "\t" << p.totalDbn().sumW2() << "\t";
171  os << p.totalDbn().sumWX() << "\t" << p.totalDbn().sumWX2() << "\t";
172  os << p.totalDbn().sumWY() << "\t" << p.totalDbn().sumWY2() << "\t";
173  os << p.totalDbn().numEntries() << "\n";
174  os << "Underflow\tUnderflow\t";
175  os << p.underflow().sumW() << "\t" << p.underflow().sumW2() << "\t";
176  os << p.underflow().sumWX() << "\t" << p.underflow().sumWX2() << "\t";
177  os << p.underflow().sumWY() << "\t" << p.underflow().sumWY2() << "\t";
178  os << p.underflow().numEntries() << "\n";
179  os << "Overflow\tOverflow\t";
180  os << p.overflow().sumW() << "\t" << p.overflow().sumW2() << "\t";
181  os << p.overflow().sumWX() << "\t" << p.overflow().sumWX2() << "\t";
182  os << p.overflow().sumWY() << "\t" << p.overflow().sumWY2() << "\t";
183  os << p.overflow().numEntries() << "\n";
184  os << "# xlow\t xhigh\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t numEntries\n";
185  for (const ProfileBin1D& b : p.bins()) {
186  os << b.xMin() << "\t" << b.xMax() << "\t";
187  os << b.sumW() << "\t" << b.sumW2() << "\t";
188  os << b.sumWX() << "\t" << b.sumWX2() << "\t";
189  os << b.sumWY() << "\t" << b.sumWY2() << "\t";
190  os << b.numEntries() << "\n";
191  }
192  os << "END " << _iotypestr("PROFILE1D") << "\n\n";
193 
194  os.flags(oldflags);
195  }

◆ writeProfile2D()

void YODA::WriterYODA::writeProfile2D ( std::ostream &  stream,
const Profile2D p 
)
protectedvirtual
Todo:
Disabled for now, reinstate with a full set of outflow info to allow marginalisation

Implements YODA::Writer.

Definition at line 198 of file WriterYODA.cc.

198  {
199  ios_base::fmtflags oldflags = os.flags();
200  os << scientific << showpoint << setprecision(_precision);
201 
202  os << "BEGIN " << _iotypestr("PROFILE2D") << " " << p.path() << "\n";
203  _writeAnnotations(os, p);
204  os << "# sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwz\t sumwz2\t sumwxy\t numEntries\n";
205  // Total distribution
206  const Dbn3D& td = p.totalDbn();
207  os << "Total \tTotal \t";
208  os << td.sumW() << "\t" << td.sumW2() << "\t";
209  os << td.sumWX() << "\t" << td.sumWX2() << "\t";
210  os << td.sumWY() << "\t" << td.sumWY2() << "\t";
211  os << td.sumWZ() << "\t" << td.sumWZ2() << "\t";
212  os << td.sumWXY() << "\t"; // << td.sumWXZ() << "\t" << td.sumWYZ() << "\t";
213  os << td.numEntries() << "\n";
214  // Outflows
216  os << "# 2D outflow persistency not currently supported until API is stable\n";
217  // for (int ix = -1; ix <= 1; ++ix) {
218  // for (int iy = -1; iy <= 1; ++iy) {
219  // if (ix == 0 && iy == 0) continue;
220  // os << "Outflow\t" << ix << ":" << iy << "\t";
221  // const Dbn3D& d = p.outflow(ix, iy);
222  // os << d.sumW() << "\t" << d.sumW2() << "\t";
223  // os << d.sumWX() << "\t" << d.sumWX2() << "\t";
224  // os << d.sumWY() << "\t" << d.sumWY2() << "\t";
225  // os << d.sumWZ() << "\t" << d.sumWZ2() << "\t";
226  // os << d.sumWXY() << "\t"; // << d.sumWXZ() << "\t" << d.sumWYZ() << "\t";
227  // os << d.numEntries() << "\n";
228  // }
229  // }
230  // Bins
231  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";
232  for (const ProfileBin2D& b : p.bins()) {
233  os << b.xMin() << "\t" << b.xMax() << "\t";
234  os << b.yMin() << "\t" << b.yMax() << "\t";
235  os << b.sumW() << "\t" << b.sumW2() << "\t";
236  os << b.sumWX() << "\t" << b.sumWX2() << "\t";
237  os << b.sumWY() << "\t" << b.sumWY2() << "\t";
238  os << b.sumWZ() << "\t" << b.sumWZ2() << "\t";
239  os << b.sumWXY() << "\t"; // << b.sumWXZ() << "\t" << b.sumWYZ() << "\t";
240  os << b.numEntries() << "\n";
241  }
242  os << "END " << _iotypestr("PROFILE2D") << "\n\n";
243 
244  os.flags(oldflags);
245  }

◆ writeScatter1D()

void YODA::WriterYODA::writeScatter1D ( std::ostream &  stream,
const Scatter1D s 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 248 of file WriterYODA.cc.

248  {
249  ios_base::fmtflags oldflags = os.flags();
250  os << scientific << showpoint << setprecision(_precision);
251 
252  os << "BEGIN " << _iotypestr("SCATTER1D") << " " << s.path() << "\n";
253  _writeAnnotations(os, s);
254 
255  //write headers
256  std::string headers="# xval\t xerr-\t xerr+\t";
257  os << headers << "\n";
258 
259  //write points
260  for (const Point1D& pt : s.points()) {
261  // fill central value
262  os << pt.x() << "\t" << pt.xErrMinus() << "\t" << pt.xErrPlus() ;
263  os << "\n";
264  }
265  os << "END " << _iotypestr("SCATTER1D") << "\n\n";
266 
267  os << flush;
268  os.flags(oldflags);
269  }

◆ writeScatter2D()

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

Implements YODA::Writer.

Definition at line 272 of file WriterYODA.cc.

272  {
273  ios_base::fmtflags oldflags = os.flags();
274  os << scientific << showpoint << setprecision(_precision);
275  os << "BEGIN " << _iotypestr("SCATTER2D") << " " << s.path() << "\n";
276  // write annotations
277  _writeAnnotations(os, s);
278 
279  //write headers
281  std::string headers="# xval\t xerr-\t xerr+\t yval\t yerr-\t yerr+\t";
282  os << headers << "\n";
283 
284  //write points
285  for (const Point2D& pt : s.points()) {
287  // fill central value
288  os << pt.x() << "\t" << pt.xErrMinus() << "\t" << pt.xErrPlus() << "\t";
289  os << pt.y() << "\t" << pt.yErrMinus() << "\t" << pt.yErrPlus() ;
290  os << "\n";
291  }
292  os << "END " << _iotypestr("SCATTER2D") << "\n\n";
293 
294  os << flush;
295  os.flags(oldflags);
296  }

◆ writeScatter3D()

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

Implements YODA::Writer.

Definition at line 299 of file WriterYODA.cc.

299  {
300  ios_base::fmtflags oldflags = os.flags();
301  os << scientific << showpoint << setprecision(_precision);
302  os << "BEGIN " << _iotypestr("SCATTER3D") << " " << s.path() << "\n";
303  // write the annotations
304  _writeAnnotations(os, s);
305 
306  // std::vector<std::string> variations= s.variations();
307  //write headers
309  std::string headers="# xval\t xerr-\t xerr+\t yval\t yerr-\t yerr+\t zval\t zerr-\t zerr+\t";
310  os << headers << "\n";
311 
312  //write points
313  for (const Point3D& pt : s.points()) {
315  // fill central value
316  os << pt.x() << "\t" << pt.xErrMinus() << "\t" << pt.xErrPlus() << "\t";
317  os << pt.y() << "\t" << pt.yErrMinus() << "\t" << pt.yErrPlus() << "\t";
318  os << pt.z() << "\t" << pt.zErrMinus() << "\t" << pt.zErrPlus() ;
319  os << "\n";
320  }
321  os << "END " << _iotypestr("SCATTER3D") << "\n\n";
322 
323  os << flush;
324  os.flags(oldflags);
325  }

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