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()
Set precision of numerical quantities for current AO in this writer's output. Definition at line 181 of file Writer.h. 181 {
182 if (needsDP) _aoprecision = std::numeric_limits<double>::max_digits10;
183 else if (_precision > 0) _aoprecision = _precision;
184 else _aoprecision = 6;
185 }
Referenced by write(). ◆ setPrecision()
Set precision of numerical quantities in this writer's output. Definition at line 176 of file Writer.h. 176 {
177 _precision = precision;
178 }
Referenced by YODA::WriterFLAT::create(), YODA::WriterH5::create(), YODA::WriterYODA::create(), YODA::WriterYODA1::create(), YODA::write(), YODA::write(), YODA::write(), YODA::write(), YODA::write(), YODA::write(), and write(). ◆ useCompression()
Use libz compression? Definition at line 188 of file Writer.h. 188 {
189 _compress = compress;
190 }
Referenced by YODA::mkWriter(), and write(). ◆ write() [1/10]
Write out object ao to file filename. Definition at line 56 of file Writer.cc. 56 {
57 std::vector<const AnalysisObject*> vec{&ao};
58 write(filename, vec);
59 }
void write(const std::string &filename, const AnalysisObject &ao) Write out object ao to file filename. Definition Writer.cc:56 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/10]
template<typename AOITER >
Write out the objects specified by start iterator begin and end iterator end to file filename.
Definition at line 130 of file Writer.h. 130 {
131 std::vector<const AnalysisObject*> vec;
132 // vec.reserve(std::distance(begin, end));
133 for (AOITER ipao = begin; ipao != end; ++ipao) vec.push_back(&(**ipao));
134
135 if (filename != "-") {
136 try {
137 const size_t lastdot = filename.find_last_of(".");
138 std::string fmt = Utils::toLower(lastdot == std::string::npos ? filename : filename.substr(lastdot+1));
140 useCompression(compress);
141 #ifdef HAVE_HDF5
142 // check if the requested format is H5
143 if (Utils::startswith(fmt, "h5")) {
144 try {
145 YODA_H5::File h5(filename, YODA_H5::File::OpenOrCreate | YODA_H5::File::Truncate);
146 write(h5, vec);
147 } catch(...) {
148 throw WriteError("Failed to open HDF5 file " + filename);
149 }
150 return;
151 }
152 #endif
153 // try writing to stream
154 std::ofstream stream;
155 stream.exceptions(std::ofstream::failbit | std::ofstream::badbit);
156 stream.open(filename.c_str());
157 if (stream.fail())
158 throw WriteError("Writing to filename " + filename + " failed");
159 write(stream, vec);
160 } catch (std::ofstream::failure& e) {
161 throw WriteError("Writing to filename " + filename + " failed: " + e.what());
162 }
163 } else {
164 try {
165 write(std::cout, vec);
166 } catch (std::runtime_error& e) {
167 throw WriteError("Writing to stdout failed: " + std::string(e.what()));
168 }
169 }
170
171 }
References YODA::enableH5compression, useCompression(), and write(). ◆ write() [3/10]
template<typename RANGE >
◆ write() [4/10]
template<typename T >
◆ write() [5/10]
◆ write() [6/10]
template<typename AOITER >
Write out the objects specified by start iterator begin and end iterator end to output stream stream.
Definition at line 117 of file Writer.h. 117 {
118 std::vector<const AnalysisObject*> vec;
119 // vec.reserve(std::distance(begin, end));
120 for (AOITER ipao = begin; ipao != end; ++ipao) vec.push_back(&(**ipao));
121 write(stream, vec, precision);
122 }
References write(). ◆ write() [7/10]
template<typename RANGE >
◆ write() [8/10]
Write out a vector of AO pointers (untemplated=exact type-match) to the given stream
Definition at line 69 of file Writer.cc. 69 {
70 std::unique_ptr<std::ostream> zos;
71 std::ostream* os = &stream;
72
73 setPrecision(precision);
74
75 // Write numbers in the "C" locale
76 std::locale prev_locale = os->getloc();
77 os->imbue(std::locale::classic());
78
79 // Wrap the stream if needed
80 if (_compress) {
81 #ifdef HAVE_LIBZ
82 // Doesn't work to always create zstr wrapper: have to only create if compressing :-/
83 // zstr::ostream zstream(stream);
84 // ostream& os = _compress ? zstream : stream;
85 os = new zstr::ostream(stream);
86 zos.reset(os);
87 #else
88 throw UserError("YODA was compiled without zlib support: can't write to a compressed stream");
89 #endif
90 }
91
92 // Write the data components
94 writeHead(*os);
95 bool first = true;
96 for (const AnalysisObject* aoptr : aos) {
98 if (!first) *os << "\n"; //< blank line between items
99 writeBody(*os, aoptr);
100 first = false;
101 }
102 writeFoot(*os);
103 *os << flush;
104
105 os->imbue(prev_locale);
106 }
virtual void writeHead(std::ostream &) Write any opening boilerplate required by the format to stream. Definition Writer.h:199 virtual void writeFoot(std::ostream &stream) Write any closing boilerplate required by the format to stream. Definition Writer.h:214 virtual void writeBody(std::ostream &stream, const AnalysisObject *ao) Write the body elements corresponding to AnalysisObject ao to stream. Definition Writer.cc:109 void setAOPrecision(const bool needsDP=false) Set precision of numerical quantities for current AO in this writer's output. Definition Writer.h:181 void setPrecision(int precision) Set precision of numerical quantities in this writer's output. Definition Writer.h:176 References setAOPrecision(), setPrecision(), writeBody(), writeFoot(), and writeHead(). ◆ write() [9/10]
template<typename T >
◆ write() [10/10]
Write out a vector of AO pointers (untemplated=exact type-match) to the given stream
Definition at line 63 of file Writer.cc. 63 {
64 writeAOS(file, aos);
65 }
virtual void writeAOS(YODA_H5::File &file, const vector< const AnalysisObject * > &aos)=0 References writeAOS(). ◆ writeAO()
Implemented in YODA::WriterFLAT, YODA::WriterYODA, and YODA::WriterYODA1. Referenced by writeBody(). ◆ writeAOS()
Implemented in YODA::WriterH5. Referenced by write(). ◆ writeBody() [1/3]
Write the body elements corresponding to AnalysisObject pointer ao to stream. Definition at line 114 of file Writer.cc. 114 {
115 try {
116 writeAO(stream, ao);
117 }
118 catch(...) {
119 ostringstream oss;
120 oss << "Unrecognised analysis object type " << ao.type() << " in Writer::write";
121 throw Exception(oss.str());
122 }
123 }
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 109 of file Writer.cc. 109 {
110 if (!ao) throw WriteError("Attempting to write a null AnalysisObject*");
111 writeBody(stream, *ao);
112 }
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 211 of file Writer.h. 211{ writeBody(stream, *ao); }
References writeBody(). Referenced by writeBody(). ◆ writeFoot()
◆ writeHead()
The documentation for this class was generated from the following files: Generated on Fri Mar 7 2025 09:06:41 for YODA - Yet more Objects for Data Analysis by |