yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
IO.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of YODA -- Yet more Objects for Data Analysis
4// Copyright (C) 2008-2024 The YODA collaboration (see AUTHORS for details)
5//
6#ifndef YODA_IO_h
7#define YODA_IO_h
8
9#include "YODA/Writer.h"
10#include "YODA/Reader.h"
11
12namespace YODA {
13
14
17
19 inline void write(const std::string& filename, const AnalysisObject& ao, int precision=-1) {
20 Writer& w = mkWriter(filename);
21 if (precision > 0) w.setPrecision(precision);
22 w.write(filename, ao);
23 }
24
26 template <typename RANGE>
27 inline void write(const std::string& filename, const RANGE& aos, int precision=-1) {
28 Writer& w = mkWriter(filename);
29 if (precision > 0) w.setPrecision(precision);
30 w.write(filename, aos);
31 }
32
35 template <typename AOITER>
36 inline void write(const std::string& filename, const AOITER& begin, const AOITER& end, int precision=-1) {
37 Writer& w = mkWriter(filename);
38 if (precision > 0) w.setPrecision(precision);
39 w.write(filename, begin, end);
40 }
41
43
44
47
49 inline void write(std::ostream& os, const AnalysisObject& ao, const std::string& fmt, int precision=-1) {
50 Writer& w = mkWriter(fmt);
51 if (precision > 0) w.setPrecision(precision);
52 w.write(os, ao);
53 }
54
56 template <typename RANGE>
57 inline void write(std::ostream& os, const RANGE& aos, const std::string& fmt, int precision=-1) {
58 Writer& w = mkWriter(fmt);
59 if (precision > 0) w.setPrecision(precision);
60 w.write(os, aos);
61 }
62
65 template <typename AOITER>
66 inline void write(std::ostream& os, const AOITER& begin, const AOITER& end, const std::string& fmt, int precision=-1) {
67 Writer& w = mkWriter(fmt);
68 if (precision > 0) w.setPrecision(precision);
69 w.write(os, begin, end);
70 }
71
73
74
77
85 inline void read(const std::string& filename, std::vector<AnalysisObject*>& aos,
86 const std::string& match = "",
87 const std::string& unmatch = "") {
88 Reader& r = mkReader(filename);
89 r.read(filename, aos, match, unmatch);
90 }
91
98 inline std::vector<AnalysisObject*> read(const std::string& filename,
99 const std::string& match = "",
100 const std::string& unmatch = "") {
101 std::vector<AnalysisObject*> rtn;
102 read(filename, rtn, match, unmatch);
103 return rtn;
104 }
105
107
108
111
118 inline void read(std::istream& is, std::vector<AnalysisObject*>& aos, const std::string& fmt,
119 const std::string& match = "", const std::string& unmatch = "") {
120 Reader& r = mkReader(fmt);
121 r.read(is, aos, match, unmatch);
122 }
123
129 inline std::vector<AnalysisObject*> read(std::istream& is, const std::string& fmt,
130 const std::string& match = "",
131 const std::string& unmatch = "") {
132 std::vector<AnalysisObject*> rtn;
133 read(is, rtn, fmt, match, unmatch);
134 return rtn;
135 }
136
138
139
140}
141
142#endif
AnalysisObject is the base class for histograms and scatters.
Pure virtual base class for various output writers.
Definition Reader.h:23
std::enable_if_t< YODA::Pushable< CONT, AnalysisObject * >::value > read(std::istream &stream, CONT &aos, const std::string &match="", const std::string &unmatch="")
Read in a collection of objects objs from output stream stream.
Definition Reader.h:50
Pure virtual base class for various output writers.
Definition Writer.h:19
void write(const std::string &filename, const AnalysisObject &ao)
Write out object ao to file filename.
Definition Writer.cc:49
void setPrecision(int precision)
Set precision of numerical quantities in this writer's output.
Definition Writer.h:143
Anonymous namespace to limit visibility.
Reader & mkReader(const std::string &format_name)
Factory function to make a reader object by format name or a filename.
Definition Reader.cc:15
void write(const std::string &filename, const AnalysisObject &ao, int precision=-1)
Write out object ao to file filename.
Definition IO.h:19
void read(const std::string &filename, std::vector< AnalysisObject * > &aos, const std::string &match="", const std::string &unmatch="")
Read in a collection of objects objs from file filename.
Definition IO.h:85
Writer & mkWriter(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition Writer.cc:25