yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.9.0
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...
 
Index mkIndex (const std::string &filename)
 Make file index. More...
 
virtual Index mkIndex (std::istream &stream)=0
 Make stream index. 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 23 of file Reader.h.

Constructor & Destructor Documentation

◆ ~Reader()

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

Virtual destructor.

Definition at line 27 of file Reader.h.

27 {}

Member Function Documentation

◆ mkIndex() [1/2]

Index YODA::Reader::mkIndex ( const std::string &  filename)
inline

Make file index.

Makes an index of a file's contents.

Parameters
[in]filenamePath to the file to index.
Returns
See also
Index

Definition at line 129 of file Reader.h.

References YODA::mkReader().

Referenced by YODA::mkIndex().

129  {
130  if (filename != "-") {
131  try {
132  std::ifstream instream;
133  instream.open(filename.c_str());
134  Index idx(mkIndex(instream));
135  instream.close();
136  return idx;
137  } catch (std::ifstream::failure& e) {
138  throw WriteError("Reading of filename " + filename +
139  " failed: " + e.what());
140  }
141  } else {
142  try {
143  return mkIndex(std::cin);
144  } catch (std::runtime_error& e) {
145  throw ReadError("Reading from stdin failed: " + std::string(e.what()));
146  }
147  }
148  }
Index mkIndex(const std::string &filename)
Make file index.
Definition: Reader.h:129

◆ mkIndex() [2/2]

virtual Index YODA::Reader::mkIndex ( std::istream &  stream)
pure virtual

Make stream index.

Makes an index of an input stream's contents.

Parameters
[in]streamInput stream to index.
Returns
See also
Index

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

◆ 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 41 of file Reader.h.

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

41  {
42  // if CONT==std::vector<AnalysisObject*>, the compiler should select
43  // the virtual method below, since it prefers non-templated methods in the lookup
44  // otherwise we would enter a endless recursion. Check in case of problems.
45  std::vector<AnalysisObject*> v_aos;
46  read(stream, v_aos);
47  for (const AnalysisObject* ao : v_aos) aos.push_back(ao);
48  }
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:41

◆ 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 61 of file Reader.h.

References read().

61  {
62  std::vector<AnalysisObject*> rtn;
63  read(stream, rtn);
64  return rtn;
65  }
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:41

◆ 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 77 of file Reader.h.

References read().

77  {
78  // if CONT==std::vector<AnalysisObject*>, the compiler should select
79  // the virtual method below, since it prefers non-templated methods in the lookup
80  // otherwise we would enter a endless recursion. Check in case of problems.
81  std::vector<AnalysisObject*> v_aos;
82  read(filename, v_aos);
83  for (const AnalysisObject* ao : v_aos) aos.push_back(ao);
84  }
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:41

◆ 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 91 of file Reader.h.

References read().

91  {
92  if (filename != "-") {
93  try {
94  std::ifstream instream;
95  instream.open(filename.c_str());
96  read(instream, aos);
97  instream.close();
98  } catch (std::ifstream::failure& e) {
99  throw WriteError("Writing to filename " + filename + " failed: " + e.what());
100  }
101  } else {
102  try {
103  read(std::cin, aos);
104  } catch (std::runtime_error& e) {
105  throw ReadError("Writing to stdout failed: " + std::string(e.what()));
106  }
107  }
108  }
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:41

◆ 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 114 of file Reader.h.

References read().

114  {
115  std::vector<AnalysisObject*> rtn;
116  read(filename, rtn);
117  return rtn;
118  }
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:41

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