yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
YODA::Reader Class Referenceabstract

Pure virtual base class for various output writers. More...

#include <Reader.h>

Inheritance diagram for YODA::Reader:
YODA::ReaderFLAT YODA::ReaderYODA

Public Types

using TypeRegisterItr = typename std::unordered_map< std::string, std::unique_ptr< AOReaderBase > >::const_iterator
 Convenience alias for AO Reader.
 

Public Member Functions

virtual ~Reader ()
 Virtual destructor.
 
Reading multiple analysis objects,
template<typename CONT >
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.
 
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.
 
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.
 
template<typename CONT >
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 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.
 
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.
 
Utilities
template<typename T >
void registerType ()
 AO type registration.
 
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 path filtering)
 

Detailed Description

Pure virtual base class for various output writers.

Definition at line 23 of file Reader.h.

Member Typedef Documentation

◆ TypeRegisterItr

using YODA::Reader::TypeRegisterItr = typename std::unordered_map<std::string, std::unique_ptr<AOReaderBase> >::const_iterator

Convenience alias for AO Reader.

Definition at line 28 of file Reader.h.

Constructor & Destructor Documentation

◆ ~Reader()

virtual YODA::Reader::~Reader ( )
inlinevirtual

Virtual destructor.

Definition at line 31 of file Reader.h.

31 {
32 // This is technically leaking memory, but since this
33 // is a (static) singleton, there should be no issue.
34 // Cython relies on it for data-structure alignment, too.
35 for (auto& aor : _register) { aor.second.release(); }
36 }

Member Function Documentation

◆ patternCheck()

bool YODA::Reader::patternCheck ( const std::string &  path,
const std::vector< std::regex > &  patterns,
const std::vector< std::regex > &  unpatterns 
)
inline

Check if a string matches any of the given patterns, and that it doesn't match any unpatterns (for path filtering)

Definition at line 150 of file Reader.h.

151 {
152 bool skip = false;
153 if (patterns.size()) {
154 skip = true;
155 for (const std::regex& re : patterns) {
156 if (std::regex_search(path, re)) { skip = false; break; }
157 }
158 }
159 if (!skip && unpatterns.size()) {
160 for (const std::regex& re : unpatterns) {
161 if (std::regex_search(path, re)) { skip = true; break; }
162 }
163 }
164 return !skip;
165 }

◆ read() [1/6]

std::vector< AnalysisObject * > YODA::Reader::read ( const std::string &  filename,
const std::string &  match = "",
const std::string &  unmatch = "" 
)
inline

Read in a collection of objects from output stream stream.

This version returns a vector by value, involving copying, and is hence less CPU efficient than the alternative version where a vector is filled by reference.

Definition at line 128 of file Reader.h.

129 {
130 std::vector<AnalysisObject*> rtn;
131 read(filename, rtn, match, unmatch);
132 return rtn;
133 }
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

References read().

◆ read() [2/6]

template<typename CONT >
std::enable_if_t< YODA::Pushable< CONT, AnalysisObject * >::value > YODA::Reader::read ( const std::string &  filename,
CONT &  aos,
const std::string &  match = "",
const std::string &  unmatch = "" 
)
inline

Read in a collection of objects objs from file filename.

This version fills (actually, appends to) a variable supplied container Note: SFINAE is used to check for a void push_back(const AnalysisObject*) method

Todo:
Extend SFINAE Pushable cf. Writer to allow adding to containers of smart ptr type

Definition at line 88 of file Reader.h.

88 {
89 // if CONT==std::vector<AnalysisObject*>, the compiler should select
90 // the virtual method below, since it prefers non-templated methods in the lookup
91 // otherwise we would enter a endless recursion. Check in case of problems.
92 std::vector<AnalysisObject*> v_aos;
93 read(filename, v_aos, match, unmatch);
94 for (const AnalysisObject* ao : v_aos) aos.push_back(ao);
95 }

References read().

◆ read() [3/6]

void YODA::Reader::read ( const std::string &  filename,
std::vector< AnalysisObject * > &  aos,
const std::string &  match = "",
const std::string &  unmatch = "" 
)
inline

Read in a collection of objects objs from file filename.

This version fills (actually, appends to) a supplied vector, avoiding copying, and is hence CPU efficient.

Definition at line 102 of file Reader.h.

103 {
104 if (filename != "-") {
105 try {
106 std::ifstream instream;
107 instream.open(filename.c_str());
108 if (instream.fail())
109 throw ReadError("Reading from filename " + filename + " failed");
110 read(instream, aos, match, unmatch);
111 instream.close();
112 } catch (std::ifstream::failure& e) {
113 throw ReadError("Reading from filename " + filename + " failed: " + e.what());
114 }
115 } else {
116 try {
117 read(std::cin, aos, match, unmatch);
118 } catch (std::runtime_error& e) {
119 throw ReadError("Reading from stdin failed: " + std::string(e.what()));
120 }
121 }
122 }

References read().

◆ read() [4/6]

std::vector< AnalysisObject * > YODA::Reader::read ( std::istream &  stream,
const std::string &  match = "",
const std::string &  unmatch = "" 
)
inline

Read in a collection of objects from output stream stream.

This version returns a vector by value, involving copying, and is hence less CPU efficient than the alternative version where a vector is filled by reference.

Definition at line 71 of file Reader.h.

72 {
73 std::vector<AnalysisObject*> rtn;
74 read(stream, rtn, match, unmatch);
75 return rtn;
76 }

References read().

◆ read() [5/6]

template<typename CONT >
std::enable_if_t< YODA::Pushable< CONT, AnalysisObject * >::value > YODA::Reader::read ( std::istream &  stream,
CONT &  aos,
const std::string &  match = "",
const std::string &  unmatch = "" 
)
inline

Read in a collection of objects objs from output stream stream.

This version fills (actually, appends to) a variable supplied container Note: SFINAE is used to check for a void push_back(const AnalysisObject*) method

Todo:
Extend SFINAE Pushable cf. Writer to allow adding to containers of smart ptr type

Definition at line 50 of file Reader.h.

50 {
51 // if CONT==std::vector<AnalysisObject*>, the compiler should select
52 // the virtual method below, since it prefers non-templated methods in the lookup
53 // otherwise we would enter a endless recursion. Check in case of problems.
54 std::vector<AnalysisObject*> v_aos;
55 read(stream, v_aos, match, unmatch);
56 for (const AnalysisObject* ao : v_aos) aos.push_back(ao);
57 }

References read().

Referenced by read(), read(), YODA::read(), read(), YODA::read(), read(), and read().

◆ read() [6/6]

virtual void YODA::Reader::read ( std::istream &  stream,
std::vector< AnalysisObject * > &  aos,
const std::string &  match = "",
const std::string &  unmatch = "" 
)
pure virtual

Read in a collection of objects objs from output stream stream.

This version fills (actually, appends to) a supplied vector, avoiding copying, and is hence CPU efficient.

Implemented in YODA::ReaderFLAT, and YODA::ReaderYODA.

◆ registerType()

template<typename T >
void YODA::Reader::registerType ( )
inline

AO type registration.

Definition at line 142 of file Reader.h.

142 {
143 const string key = Utils::toUpper(T().type());
144 const TypeRegisterItr& res = _register.find(key);
145 if (res == _register.end()) _register[key] = std::make_unique<AOReader<T>>();
146 }
typename std::unordered_map< std::string, std::unique_ptr< AOReaderBase > >::const_iterator TypeRegisterItr
Convenience alias for AO Reader.
Definition Reader.h:28

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