|
YODA - Yet more Objects for Data Analysis 2.0.2
|
Go to the documentation of this file.
16#include <unordered_map>
28 using TypeRegisterItr = typename std::unordered_map<std::string, std::unique_ptr<AOReaderBase>>::const_iterator;
35 for ( auto& aor : _register) { aor.second.release(); }
48 template< typename CONT>
49 typename std::enable_if_t<YODA::Pushable<CONT,AnalysisObject*>::value>
50 read(std::istream& stream, CONT& aos, const std::string& match = "", const std::string& unmatch = "") {
54 std::vector<AnalysisObject*> v_aos;
55 read(stream, v_aos, match, unmatch);
64 virtual void read(std::istream& stream, std::vector<AnalysisObject*>& aos,
65 const std::string& match = "", const std::string& unmatch = "") = 0;
71 std::vector<AnalysisObject*> read(std::istream& stream, const std::string& match = "",
72 const std::string& unmatch = "") {
73 std::vector<AnalysisObject*> rtn;
74 read(stream, rtn, match, unmatch);
86 template< typename CONT>
87 typename std::enable_if_t<YODA::Pushable<CONT,AnalysisObject*>::value>
88 read( const std::string& filename, CONT& aos, const std::string& match = "", const std::string& unmatch = "") {
92 std::vector<AnalysisObject*> v_aos;
93 read(filename, v_aos, match, unmatch);
102 void read( const std::string& filename, std::vector<AnalysisObject*>& aos, const std::string& match = "",
103 const std::string& unmatch = "") {
104 if (filename != "-") {
106 std::ifstream instream;
107 instream.open(filename.c_str());
109 throw ReadError( "Reading from filename " + filename + " failed");
110 read(instream, aos, match, unmatch);
112 } catch (std::ifstream::failure& e) {
113 throw ReadError( "Reading from filename " + filename + " failed: " + e.what());
117 read(std::cin, aos, match, unmatch);
118 } catch (std::runtime_error& e) {
119 throw ReadError( "Reading from stdin failed: " + std::string(e.what()));
128 std::vector<AnalysisObject*> read( const std::string& filename, const std::string& match = "",
129 const std::string& unmatch = "") {
130 std::vector<AnalysisObject*> rtn;
131 read(filename, rtn, match, unmatch);
143 const string key = Utils::toUpper(T().type());
145 if (res == _register.end()) _register[key] = std::make_unique<AOReader<T>>();
150 bool patternCheck( const std::string& path, const std::vector<std::regex>& patterns,
151 const std::vector<std::regex>& unpatterns) {
153 if (patterns.size()) {
155 for ( const std::regex& re : patterns) {
156 if (std::regex_search(path, re)) { skip = false; break; }
159 if (!skip && unpatterns.size()) {
160 for ( const std::regex& re : unpatterns) {
161 if (std::regex_search(path, re)) { skip = true; break; }
170 std::unordered_map<string, std::unique_ptr<AOReaderBase>> _register;
176 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.
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::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.
|