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

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

#include <Reader.h>

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

Public Member Functions

virtual ~Reader ()
 Virtual destructor. More...
 
Reading multiple analysis objects,
template<typename CONT >
std::enable_if< YODA::Pushable< CONT, AnalysisObject * >::value >::type read (std::istream &stream, CONT &aos)
 Read in a collection of objects objs from output stream stream. More...
 
virtual void read (std::istream &stream, std::vector< AnalysisObject *> &aos)=0
 Read in a collection of objects objs from output stream stream. More...
 
std::vector< AnalysisObject * > read (std::istream &stream)
 Read in a collection of objects from output stream stream. More...
 
template<typename CONT >
std::enable_if< YODA::Pushable< CONT, AnalysisObject * >::value >::type read (const std::string &filename, CONT &aos)
 Read in a collection of objects objs from file filename. More...
 
void read (const std::string &filename, std::vector< AnalysisObject *> &aos)
 Read in a collection of objects objs from file filename. More...
 
std::vector< AnalysisObject * > read (const std::string &filename)
 Read in a collection of objects from output stream stream. More...
 

Detailed Description

Pure virtual base class for various output writers.

Definition at line 21 of file Reader.h.

Constructor & Destructor Documentation

◆ ~Reader()

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

Virtual destructor.

Definition at line 25 of file Reader.h.

25 {}

Member Function Documentation

◆ read() [1/6]

template<typename CONT >
std::enable_if<YODA::Pushable<CONT,AnalysisObject*>::value>::type YODA::Reader::read ( std::istream &  stream,
CONT &  aos 
)
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 39 of file Reader.h.

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

39  {
40  // if CONT==std::vector<AnalysisObject*>, the compiler should select
41  // the virtual method below, since it prefers non-templated methods in the lookup
42  // otherwise we would enter a endless recursion. Check in case of problems.
43  std::vector<AnalysisObject*> v_aos;
44  read(stream, v_aos);
45  for (const AnalysisObject* ao : v_aos) aos.push_back(ao);
46  }
std::enable_if< YODA::Pushable< CONT, AnalysisObject * >::value >::type read(std::istream &stream, CONT &aos)
Read in a collection of objects objs from output stream stream.
Definition: Reader.h:39

◆ read() [2/6]

virtual void YODA::Reader::read ( std::istream &  stream,
std::vector< AnalysisObject *> &  aos 
)
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, YODA::ReaderAIDA, and YODA::ReaderYODA.

◆ read() [3/6]

std::vector<AnalysisObject*> YODA::Reader::read ( std::istream &  stream)
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 59 of file Reader.h.

References read().

59  {
60  std::vector<AnalysisObject*> rtn;
61  read(stream, rtn);
62  return rtn;
63  }
std::enable_if< YODA::Pushable< CONT, AnalysisObject * >::value >::type read(std::istream &stream, CONT &aos)
Read in a collection of objects objs from output stream stream.
Definition: Reader.h:39

◆ read() [4/6]

template<typename CONT >
std::enable_if<YODA::Pushable<CONT,AnalysisObject*>::value>::type YODA::Reader::read ( const std::string &  filename,
CONT &  aos 
)
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 75 of file Reader.h.

References read().

75  {
76  // if CONT==std::vector<AnalysisObject*>, the compiler should select
77  // the virtual method below, since it prefers non-templated methods in the lookup
78  // otherwise we would enter a endless recursion. Check in case of problems.
79  std::vector<AnalysisObject*> v_aos;
80  read(filename, v_aos);
81  for (const AnalysisObject* ao : v_aos) aos.push_back(ao);
82  }
std::enable_if< YODA::Pushable< CONT, AnalysisObject * >::value >::type read(std::istream &stream, CONT &aos)
Read in a collection of objects objs from output stream stream.
Definition: Reader.h:39

◆ read() [5/6]

void YODA::Reader::read ( const std::string &  filename,
std::vector< AnalysisObject *> &  aos 
)
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 89 of file Reader.h.

References read().

89  {
90  if (filename != "-") {
91  try {
92  std::ifstream instream;
93  instream.open(filename.c_str());
94  read(instream, aos);
95  instream.close();
96  } catch (std::ifstream::failure& e) {
97  throw WriteError("Writing to filename " + filename + " failed: " + e.what());
98  }
99  } else {
100  try {
101  read(std::cin, aos);
102  } catch (std::runtime_error& e) {
103  throw ReadError("Writing to stdout failed: " + std::string(e.what()));
104  }
105  }
106  }
std::enable_if< YODA::Pushable< CONT, AnalysisObject * >::value >::type read(std::istream &stream, CONT &aos)
Read in a collection of objects objs from output stream stream.
Definition: Reader.h:39

◆ read() [6/6]

std::vector<AnalysisObject*> YODA::Reader::read ( const std::string &  filename)
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 112 of file Reader.h.

References YODA::mkReader(), and read().

112  {
113  std::vector<AnalysisObject*> rtn;
114  read(filename, rtn);
115  return rtn;
116  }
std::enable_if< YODA::Pushable< CONT, AnalysisObject * >::value >::type read(std::istream &stream, CONT &aos)
Read in a collection of objects objs from output stream stream.
Definition: Reader.h:39

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