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

Persistency writer for YODA H5 format. More...

#include <WriterH5.h>

Inheritance diagram for YODA::WriterH5:
YODA::Writer

Static Public Member Functions

static Writercreate ()
 Singleton creation function.
 

Protected Member Functions

void writeAOS (YODA_H5::File &file, const std::vector< const AnalysisObject * > &aos)
 
- 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 (YODA_H5::File &file, const std::vector< const AnalysisObject * > &aos)
 
void write (std::ostream &stream, const std::vector< const AnalysisObject * > &aos, int precision=-1)
 
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, int precision=-1)
 
template<typename AOITER >
void write (const std::string &filename, const AOITER &begin, const AOITER &end)
 

Detailed Description

Persistency writer for YODA H5 format.

Definition at line 15 of file WriterH5.h.

Member Function Documentation

◆ create()

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

Singleton creation function.

Definition at line 17 of file WriterH5.cc.

17 {
18 static WriterH5 _instance;
19 _instance.setPrecision(6); //< not used
20 return _instance;
21 }

References YODA::Writer::setPrecision().

Referenced by YODA::mkWriter().

◆ writeAOS()

void YODA::WriterH5::writeAOS ( YODA_H5::File &  file,
const std::vector< const AnalysisObject * > &  aos 
)
protectedvirtual

Implements YODA::Writer.

Definition at line 30 of file WriterH5.cc.

30 {
31
32 // Work out the length of the concatenated serialized streams
33 size_t annolen = 0, datalen = 0;
34 vector<size_t> annosizes, datasizes, labelsizes;
35 annosizes.reserve(aos.size());
36 labelsizes.reserve(aos.size());
37 datasizes.reserve(aos.size()+1); //< +1 for # of AOs requiring error labels
38 vector<string> labels; // list of error labels
39 for (const AnalysisObject* ao : aos) {
40 annosizes.emplace_back(ao->lengthMeta() - 1); //< skip "Title" key
41 datasizes.emplace_back(ao->lengthContent());
42 annolen += annosizes.back();
43 datalen += datasizes.back();
44 // if the AO is an Estimate, extract the error labels
45 ao->_extractLabels(labels, labelsizes);
46 }
47 datasizes.emplace_back(labelsizes.size());
48 //size_t annochunk = annolen/aos.size();
49 //size_t datachunk = datalen/aos.size();
50 size_t annochunk = std::min(annolen, (size_t)1200);
51 size_t datachunk = std::min(datalen, (size_t)1500);
52
53 // create empty H5 DataSets
54 H5DataSetWriter<string> annoset(h5, "annotations", annolen, annochunk, _compress);
55 H5DataSetWriter<double> dataset(h5, "content", datalen, datachunk, _compress);
56
57 // Now that we know the sizes of all AOs,
58 // fill an uber-vector of serialized sub-vectors
59 // as well as a map of edge handlers for binned AOs
60 map<string, EdgeHandlerBasePtr> layout;
61 layout["sizeinfo"] = std::make_shared<EdgeHandler<size_t>>();
62 static_pointer_cast<EdgeHandler<size_t>>(layout["sizeinfo"])->extend(std::move(annosizes));
63 static_pointer_cast<EdgeHandler<size_t>>(layout["sizeinfo"])->extend(std::move(datasizes));
64 static_pointer_cast<EdgeHandler<size_t>>(layout["sizeinfo"])->extend(std::move(labelsizes));
65 vector<string> aoinfo; aoinfo.reserve(H5FileManager::AO_META*aos.size());
66 for (const AnalysisObject* ao : aos) {
67
68 // save metadata about this AO
69 aoinfo.emplace_back(ao->path());
70 aoinfo.emplace_back(Utils::toUpper(ao->type()));
71
72 // retrieve annotations for this AO
73 vector<string> annos = ao->serializeMeta(); //< skips Path and Title
74 annos.emplace_back(ao->title()); // title value should be at the end
75
76 // retrieve content for this AO
77 vector<double> content = ao->serializeContent();
78
79 // write to file
80 annoset.writeSlice(std::move(annos));
81 dataset.writeSlice(std::move(content));
82
83 // if the AO is a Fillable, extract its binning
84 ao->_extractEdges(layout, labels);
85 }
86
87 // write AO metadata
88 auto meta = H5DataSet(h5, "aoinfo", std::move(aoinfo), _compress);
89
90 // write layout and attribute for file-level metadata
91 meta.createAttribute("meta", vector<size_t>{YODA_H5_FORMAT_VERSION, aos.size()});
92
93 // write error source labels
94 (void)H5DataSet(h5, "labels", std::move(labels), _compress);
95
96 // write bin edges
97 for (const auto& item : layout) {
98 item.second->writeToFile(item.first, h5, _compress);
99 }
100
101 }
static constexpr size_t AO_META
Definition H5Utils.h:276
YODA_H5::DataSet H5DataSet(YODA_H5::File &h5file, const string &label, vector< T > &&data, bool compress)
Helper method to construct and fill a YODA_H5::DataSet.
Definition H5Utils.h:35
static const size_t YODA_H5_FORMAT_VERSION
Definition WriterH5.cc:27

References YODA::H5FileManager::AO_META, YODA::H5DataSet(), YODA::H5DataSetWriter< T >::writeSlice(), and YODA::YODA_H5_FORMAT_VERSION.


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