YODA::Writer Class Referenceabstract Pure virtual base class for various output writers. More...
Inheritance diagram for YODA::Writer:
Detailed DescriptionConstructor & Destructor Documentation◆ ~Writer()
Member Function Documentation◆ setAOPrecision()
◆ setPrecision()
Set precision of numerical quantities in this writer's output. Definition at line 143 of file Writer.h. 143 {
144 _precision = precision;
145 }
Referenced by YODA::WriterFLAT::create(), YODA::WriterYODA::create(), YODA::WriterYODA1::create(), YODA::write(), YODA::write(), YODA::write(), YODA::write(), YODA::write(), and YODA::write(). ◆ useCompression()
Use libz compression? Definition at line 153 of file Writer.h. 153 {
154 _compress = compress;
155 }
Referenced by YODA::mkWriter(), and write(). ◆ write() [1/9]
Write out object ao to file filename. Definition at line 49 of file Writer.cc. 49 {
50 std::vector<const AnalysisObject*> vec{&ao};
51 write(filename, vec);
52 }
void write(const std::string &filename, const AnalysisObject &ao) Write out object ao to file filename. Definition Writer.cc:49 References write(). Referenced by write(), YODA::write(), write(), YODA::write(), write(), YODA::write(), write(), YODA::write(), YODA::write(), YODA::write(), write(), write(), write(), and write(). ◆ write() [2/9]
template<typename AOITER >
Write out the objects specified by start iterator begin and end iterator end to file filename.
Definition at line 109 of file Writer.h. 109 {
110 std::vector<const AnalysisObject*> vec;
111 // vec.reserve(std::distance(begin, end));
112 for (AOITER ipao = begin; ipao != end; ++ipao) vec.push_back(&(**ipao));
113
114 if (filename != "-") {
115 try {
116 const size_t lastdot = filename.find_last_of(".");
117 std::string fmt = Utils::toLower(lastdot == std::string::npos ? filename : filename.substr(lastdot+1));
118 const bool compress = (fmt == "gz");
119 useCompression(compress);
120 //
121 std::ofstream stream;
122 stream.exceptions(std::ofstream::failbit | std::ofstream::badbit);
123 stream.open(filename.c_str());
124 if (stream.fail())
125 throw WriteError("Writing to filename " + filename + " failed");
126 write(stream, vec);
127 } catch (std::ofstream::failure& e) {
128 throw WriteError("Writing to filename " + filename + " failed: " + e.what());
129 }
130 } else {
131 try {
132 write(std::cout, vec);
133 } catch (std::runtime_error& e) {
134 throw WriteError("Writing to stdout failed: " + std::string(e.what()));
135 }
136 }
137
138 }
References useCompression(), and write(). ◆ write() [3/9]
template<typename RANGE >
◆ write() [4/9]
template<typename T >
◆ write() [5/9]
◆ write() [6/9]
template<typename AOITER >
Write out the objects specified by start iterator begin and end iterator end to output stream stream.
Definition at line 96 of file Writer.h. 96 {
97 std::vector<const AnalysisObject*> vec;
98 // vec.reserve(std::distance(begin, end));
99 for (AOITER ipao = begin; ipao != end; ++ipao) vec.push_back(&(**ipao));
100 write(stream, vec);
101 }
References write(). ◆ write() [7/9]
template<typename RANGE >
◆ write() [8/9]
Write out a vector of AO pointers (untemplated=exact type-match) to the given stream
Definition at line 55 of file Writer.cc. 55 {
56 std::unique_ptr<std::ostream> zos;
57 std::ostream* os = &stream;
58
59 // Write numbers in the "C" locale
60 std::locale prev_locale = os->getloc();
61 os->imbue(std::locale::classic());
62
63 // Wrap the stream if needed
64 if (_compress) {
65 #ifdef HAVE_LIBZ
66 // Doesn't work to always create zstr wrapper: have to only create if compressing :-/
67 // zstr::ostream zstream(stream);
68 // ostream& os = _compress ? zstream : stream;
69 os = new zstr::ostream(stream);
70 zos.reset(os);
71 #else
72 throw UserError("YODA was compiled without zlib support: can't write to a compressed stream");
73 #endif
74 }
75
76 // Write the data components
78 writeHead(*os);
79 bool first = true;
80 for (const AnalysisObject* aoptr : aos) {
82 try {
83 if (!first) *os << "\n"; //< blank line between items
84 writeBody(*os, aoptr);
85 first = false;
86 } catch (const LowStatsError& ex) {
88 std::cerr << "LowStatsError in writing AnalysisObject " << aoptr->title() << ":\n" << ex.what() << "\n";
89 }
90 }
91 writeFoot(*os);
92 *os << flush;
93
94 os->imbue(prev_locale);
95 }
virtual void writeHead(std::ostream &) Write any opening boilerplate required by the format to stream. Definition Writer.h:164 virtual void writeFoot(std::ostream &stream) Write any closing boilerplate required by the format to stream. Definition Writer.h:179 virtual void writeBody(std::ostream &stream, const AnalysisObject *ao) Write the body elements corresponding to AnalysisObject ao to stream. Definition Writer.cc:98 void setAOPrecision(const bool needsDP=false) Set precision of numerical quantities for current AO in this writer's output. Definition Writer.h:148 References setAOPrecision(), writeBody(), writeFoot(), and writeHead(). ◆ write() [9/9]
template<typename T >
◆ writeAO()
Implemented in YODA::WriterFLAT, YODA::WriterYODA, and YODA::WriterYODA1. Referenced by writeBody(). ◆ writeBody() [1/3]
Write the body elements corresponding to AnalysisObject pointer ao to stream. Definition at line 103 of file Writer.cc. 103 {
104 try {
105 writeAO(stream, ao);
106 }
107 catch(...) {
108 ostringstream oss;
109 oss << "Unrecognised analysis object type " << ao.type() << " in Writer::write";
110 throw Exception(oss.str());
111 }
112 }
virtual void writeAO(std::ostream &stream, const AnalysisObject &ao)=0 References YODA::AnalysisObject::type(), and writeAO(). ◆ writeBody() [2/3]
Write the body elements corresponding to AnalysisObject ao to stream. Definition at line 98 of file Writer.cc. 98 {
99 if (!ao) throw WriteError("Attempting to write a null AnalysisObject*");
100 writeBody(stream, *ao);
101 }
References writeBody(). Referenced by write(), and writeBody(). ◆ writeBody() [3/3]
template<typename T >
Write the body elements corresponding to AnalysisObject ao to stream.
Definition at line 176 of file Writer.h. 176{ writeBody(stream, *ao); }
References writeBody(). Referenced by writeBody(). ◆ writeFoot()
◆ writeHead()
The documentation for this class was generated from the following files: Generated on Mon Oct 28 2024 13:47:24 for YODA - Yet more Objects for Data Analysis by 1.9.8 |