|
YODA - Yet more Objects for Data Analysis 2.1.0
|
Go to the documentation of this file.
16#include <YODA/highfive/H5File.hpp>
18#include <highfive/H5File.hpp>
19#define YODA_H5 HighFive
28#include <unordered_map>
40 using TypeRegisterItr = typename std::unordered_map<std::string, std::unique_ptr<AOReaderBase>>::const_iterator;
47 for ( auto& aor : _register) { aor.second.release(); }
60 template< typename CONT>
61 typename std::enable_if_t<YODA::Pushable<CONT,AnalysisObject*>::value>
62 read(std::istream& stream, CONT& aos, const std::string& match = "", const std::string& unmatch = "") {
66 std::vector<AnalysisObject*> v_aos;
67 read(stream, v_aos, match, unmatch);
76 virtual void read(std::istream& stream, std::vector<AnalysisObject*>& aos,
77 const std::string& match = "", const std::string& unmatch = "") = 0;
85 virtual void read( const YODA_H5::File& file, std::vector<AnalysisObject*>& aos,
86 const std::string& match = "", const std::string& unmatch = "") = 0;
93 std::vector<AnalysisObject*> read(std::istream& stream, const std::string& match = "",
94 const std::string& unmatch = "") {
95 std::vector<AnalysisObject*> rtn;
96 read(stream, rtn, match, unmatch);
106 std::vector<AnalysisObject*> read( const YODA_H5::File& file, const std::string& match = "",
107 const std::string& unmatch = "") {
108 std::vector<AnalysisObject*> rtn;
109 read(file, rtn, match, unmatch);
122 template< typename CONT>
123 typename std::enable_if_t<YODA::Pushable<CONT,AnalysisObject*>::value>
124 read( const std::string& filename, CONT& aos, const std::string& match = "", const std::string& unmatch = "") {
128 std::vector<AnalysisObject*> v_aos;
129 read(filename, v_aos, match, unmatch);
138 void read( const std::string& filename, std::vector<AnalysisObject*>& aos,
139 const std::string& match = "", const std::string& unmatch = "") {
140 if (filename != "-") {
142 const size_t lastdot = filename.find_last_of( ".");
143 std::string fmt = Utils::toLower(lastdot == std::string::npos ? filename : filename.substr(lastdot+1));
146 if (Utils::startswith(fmt, "h5")) {
148 const YODA_H5::File h5(filename, YODA_H5::File::ReadOnly);
149 read(h5, aos, match, unmatch);
151 throw ReadError( "Reading from filename " + filename + " failed: " + e.what());
156 std::ifstream instream;
157 instream.open(filename.c_str());
159 throw ReadError( "Reading from filename " + filename + " failed");
160 read(instream, aos, match, unmatch);
162 } catch (std::ifstream::failure& e) {
163 throw ReadError( "Reading from filename " + filename + " failed: " + e.what());
167 read(std::cin, aos, match, unmatch);
168 } catch (std::runtime_error& e) {
169 throw ReadError( "Reading from stdin failed: " + std::string(e.what()));
178 std::vector<AnalysisObject*> read( const std::string& filename, const std::string& match = "",
179 const std::string& unmatch = "") {
180 std::vector<AnalysisObject*> rtn;
181 read(filename, rtn, match, unmatch);
193 const string key = Utils::toUpper(T().type());
195 if (res == _register.end()) _register[key] = std::make_unique<AOReader<T>>();
200 bool patternCheck( const std::string& path, const std::vector<std::regex>& patterns,
201 const std::vector<std::regex>& unpatterns) {
203 if (patterns.size()) {
205 for ( const std::regex& re : patterns) {
206 if (std::regex_search(path, re)) { skip = false; break; }
209 if (!skip && unpatterns.size()) {
210 for ( const std::regex& re : unpatterns) {
211 if (std::regex_search(path, re)) { skip = true; break; }
220 std::unordered_map<string, std::unique_ptr<AOReaderBase>> _register;
226 Reader& mkReader( const std::string& format_name);
AnalysisObject is the base class for histograms and scatters.
Error for file reading errors.
Pure virtual base class for various output writers.
std::enable_if_t< YODA::Pushable< CONT, AnalysisObject * >::value > read(const std::string &filename, CONT &aos, const std::string &match="", const std::string &unmatch="") Read in a collection of objects objs from file filename.
virtual void read(const YODA_H5::File &file, std::vector< AnalysisObject * > &aos, const std::string &match="", const std::string &unmatch="")=0 Read in a collection of objects objs from an HDF5 file.
void registerType() AO type registration.
virtual void read(std::istream &stream, std::vector< AnalysisObject * > &aos, const std::string &match="", const std::string &unmatch="")=0 Read in a collection of objects objs from output stream stream.
virtual ~Reader() Virtual destructor.
typename std::unordered_map< std::string, std::unique_ptr< AOReaderBase > >::const_iterator TypeRegisterItr Convenience alias for AO Reader.
std::vector< AnalysisObject * > read(const std::string &filename, const std::string &match="", const std::string &unmatch="") Read in a collection of objects from output stream stream.
std::vector< AnalysisObject * > read(const YODA_H5::File &file, const std::string &match="", const std::string &unmatch="") Read in a collection of objects from an H5 file.
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.
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.
bool patternCheck(const std::string &path, const std::vector< std::regex > &patterns, const std::vector< std::regex > &unpatterns) Check if a string matches any of the given patterns, and that it doesn't match any unpatterns (for pa...
std::vector< AnalysisObject * > read(std::istream &stream, const std::string &match="", const std::string &unmatch="") Read in a collection of objects from output stream stream.
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.
|