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

Persistency writer for flat text format. More...

#include <WriterFLAT.h>

Inheritance diagram for YODA::WriterFLAT:
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 flat text format.

Definition at line 16 of file WriterFLAT.h.

Member Function Documentation

◆ create()

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

Singleton creation function.

Definition at line 25 of file WriterFLAT.cc.

References YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), and YODA::Writer::setPrecision().

25  {
26  static WriterFLAT _instance;
27  _instance.setPrecision(6);
28  return _instance;
29  }

◆ write() [1/8]

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

Write out object ao to output stream stream.

Definition at line 11 of file WriterFLAT.h.

12  {
13 

◆ write() [2/8]

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

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

Definition at line 18 of file WriterFLAT.h.

26 :
27 

◆ write() [3/8]

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

Write out object ao to file filename.

Definition at line 21 of file WriterFLAT.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::WriterFLAT::write ( const std::string &  filename,
const T &  ao 
)
inlinestatic

Write out pointer-like object ao to file filename.

Definition at line 33 of file WriterFLAT.h.

◆ write() [5/8]

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

Definition at line 43 of file WriterFLAT.h.

43  { }
44 
45  };

◆ write() [6/8]

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

Definition at line 49 of file WriterFLAT.h.

◆ write() [7/8]

template<typename AOITER >
static void YODA::WriterFLAT::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 WriterFLAT.h.

◆ write() [8/8]

template<typename AOITER >
static void YODA::WriterFLAT::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 WriterFLAT.h.

◆ writeCounter()

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

Implements YODA::Writer.

Definition at line 42 of file WriterFLAT.cc.

References YODA::Counter::err(), YODA::AnalysisObject::path(), and YODA::Counter::val().

42  {
43  ios_base::fmtflags oldflags = os.flags();
44  os << scientific << showpoint << setprecision(_precision);
45 
46  os << "# BEGIN COUNTER " << c.path() << "\n";
47  _writeAnnotations(os, c);
48  os << "# value\t error\n";
49  os << c.val() << "\t" << c.err() << "\n";
50  os << "# END COUNTER\n\n";
51 
52  os << flush;
53  os.flags(oldflags);
54  }

◆ writeHisto1D()

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

Implements YODA::Writer.

Definition at line 57 of file WriterFLAT.cc.

References YODA::mkScatter(), and YODA::AnalysisObject::setAnnotation().

57  {
58  Scatter2D tmp = mkScatter(h);
59  tmp.setAnnotation("Type", "Histo1D");
60  writeScatter2D(os, tmp);
61  }
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:9
void writeScatter2D(std::ostream &stream, const Scatter2D &s)
Definition: WriterFLAT.cc:104

◆ writeHisto2D()

void YODA::WriterFLAT::writeHisto2D ( std::ostream &  stream,
const Histo2D h 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 64 of file WriterFLAT.cc.

References YODA::mkScatter(), and YODA::AnalysisObject::setAnnotation().

64  {
65  Scatter3D tmp = mkScatter(h);
66  tmp.setAnnotation("Type", "Histo2D");
67  writeScatter3D(os, tmp);
68  }
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:9
void writeScatter3D(std::ostream &stream, const Scatter3D &s)
Definition: WriterFLAT.cc:122

◆ writeProfile1D()

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

Implements YODA::Writer.

Definition at line 71 of file WriterFLAT.cc.

References YODA::mkScatter(), and YODA::AnalysisObject::setAnnotation().

71  {
72  Scatter2D tmp = mkScatter(p);
73  tmp.setAnnotation("Type", "Profile1D");
74  writeScatter2D(os, tmp);
75  }
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:9
void writeScatter2D(std::ostream &stream, const Scatter2D &s)
Definition: WriterFLAT.cc:104

◆ writeProfile2D()

void YODA::WriterFLAT::writeProfile2D ( std::ostream &  stream,
const Profile2D p 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 78 of file WriterFLAT.cc.

References YODA::mkScatter(), and YODA::AnalysisObject::setAnnotation().

78  {
79  Scatter3D tmp = mkScatter(h);
80  tmp.setAnnotation("Type", "Profile2D");
81  writeScatter3D(os, tmp);
82  }
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:9
void writeScatter3D(std::ostream &stream, const Scatter3D &s)
Definition: WriterFLAT.cc:122

◆ writeScatter1D()

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

Implements YODA::Writer.

Definition at line 87 of file WriterFLAT.cc.

References YODA::AnalysisObject::path(), and YODA::Scatter1D::points().

87  {
88  ios_base::fmtflags oldflags = os.flags();
89  os << scientific << showpoint << setprecision(_precision);
90 
91  os << "# BEGIN VALUE " << s.path() << "\n";
92  _writeAnnotations(os, s);
93  os << "# value\t errminus\t errplus\n";
94  for (const Point1D& pt : s.points()) {
95  os << pt.x() << "\t" << pt.xErrMinus() << "\t" << pt.xErrPlus() << "\n";
96  }
97  os << "# END VALUE\n\n";
98 
99  os << flush;
100  os.flags(oldflags);
101  }

◆ writeScatter2D()

void YODA::WriterFLAT::writeScatter2D ( std::ostream &  stream,
const Scatter2D s 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 104 of file WriterFLAT.cc.

References YODA::AnalysisObject::path(), and YODA::Scatter2D::points().

104  {
105  ios_base::fmtflags oldflags = os.flags();
106  os << scientific << showpoint << setprecision(_precision);
107 
108  os << "# BEGIN HISTO1D " << s.path() << "\n";
109  _writeAnnotations(os, s);
110  os << "# xlow\t xhigh\t val\t errminus\t errplus\n";
111  for (const Point2D& pt : s.points()) {
112  os << pt.x()-pt.xErrMinus() << "\t" << pt.x()+pt.xErrPlus() << "\t";
113  os << pt.y() << "\t" << pt.yErrMinus() << "\t" << pt.yErrPlus() << "\n";
114  }
115  os << "# END HISTO1D\n\n";
116 
117  os << flush;
118  os.flags(oldflags);
119  }

◆ writeScatter3D()

void YODA::WriterFLAT::writeScatter3D ( std::ostream &  stream,
const Scatter3D s 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 122 of file WriterFLAT.cc.

References YODA::AnalysisObject::path(), and YODA::Scatter3D::points().

122  { // , bool asHist2D) {
123  ios_base::fmtflags oldflags = os.flags();
124  os << scientific << showpoint << setprecision(_precision);
125 
126  os << "# BEGIN HISTO2D " << s.path() << "\n";
127  _writeAnnotations(os, s);
128 
129  // if (asHist2D) { // Extension of what writeScatter2D does
130  os << "# xlow\t xhigh\t ylow\t yhigh\t val\t errminus\t errplus\n";
131  for (const Point3D& pt : s.points()) {
132  os << pt.x()-pt.xErrMinus() << "\t" << pt.x()+pt.xErrPlus() << "\t";
133  os << pt.y()-pt.yErrMinus() << "\t" << pt.y()+pt.yErrPlus() << "\t";
134  os << pt.z() << "\t" << pt.zErrMinus() << "\t" << pt.zErrPlus() << "\n";
135  }
136 
137  // } else { // What writerYODA should do... let's just put this in there (generalised for multiple errs).
138  // os << "# xval\t xerr-\t xerr+\t yval\t yerr-\t yerr+\t zval\t zerr-\t zerr+\n";
139  // for (const Point3D& pt : s.points()) {
140  // os << pt.x() << "\t" << pt.xErrMinus() << "\t" << pt.xErrMinus() << "\t";
141  // os << pt.y() << "\t" << pt.yErrMinus() << "\t" << pt.yErrMinus() << "\t";
142  // os << pt.z() << "\t" << pt.zErrMinus() << "\t" << pt.zErrMinus() << "\n";
143  // }
144  // }
145 
146  os << "# END HISTO2D\n\n";
147 
148  os << flush;
149  os.flags(oldflags);
150  }

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