Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JROOT::JRootReader Class Reference

Implementation for ASCII input of objects with ROOT dictionary. More...

#include <JRootStreamer.hh>

Inheritance diagram for JROOT::JRootReader:
JLANG::JStreamState JDATABASE::JDBReader< T >

Public Member Functions

 JRootReader (std::istream &in, const JEquationParameters &parameters, const JRootDictionary_t &dictionary)
 Constructor.
 
const JRootDictionary_tgetDictionary () const
 Get dictionary.
 
template<class T >
JRootReaderget (T &object)
 Read object according equation format.
 
JRootReaderget (const JRootReadableClass &cls)
 Read ROOT class according equation format.
 
template<class T >
JRootReadergetObject (T &object)
 Read object.
 
JRootReadergetObject (const JRootReadableClass &cls)
 Read ROOT class.
 
JRootReadergetObject (JRootReadableClass &cls)
 Read ROOT class.
 

Private Member Functions

template<class T >
JRootReadergetObject (T &object, const JBool< true > &option)
 Read object.
 
template<class T >
JRootReadergetObject (T &object, const JBool< false > &option)
 Read object.
 
template<class JElement_t , class JAllocator_t >
JRootReadergetObject (std::vector< JElement_t, JAllocator_t > &object, const JBool< false > &option)
 Read object.
 

Private Attributes

const JRootDictionary_tdictionary
 
std::ios & __from
 
std::ios & __to
 

Detailed Description

Implementation for ASCII input of objects with ROOT dictionary.

The method JRootReader::get is compatible with equation formatting, i.e:

<key>[<division><key>]<separator><value>[<white space><value>]*<end of line>

In this, the key corresponds to the name of a data member, which can be recursively parsed via a division character.

The method JRootReader::getObject relates to simple formatting, i.e:

<value>[<white space><value>]*

The default format for input of std::vector<T> is

<number of elements>[<white space><value>]*

Definition at line 60 of file JRootStreamer.hh.

Constructor & Destructor Documentation

◆ JRootReader()

JROOT::JRootReader::JRootReader ( std::istream & in,
const JEquationParameters & parameters,
const JRootDictionary_t & dictionary )
inline

Constructor.

Parameters
ininput stream
parametersequation parameters
dictionarydictionary

Definition at line 72 of file JRootStreamer.hh.

74 :
75 std::istream(in.rdbuf()),
76 JStreamState(in, static_cast<std::istream&>(*this)),
78 {
79 imbue(std::locale(in.getloc(), new JLANG::JEquationFacet(parameters)));
80 }
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
JStreamState(std::ostream &from, std::ostream &to)
Constructor.
const JRootDictionary_t & dictionary

Member Function Documentation

◆ getDictionary()

const JRootDictionary_t & JROOT::JRootReader::getDictionary ( ) const
inline

Get dictionary.

Returns
dictionary

Definition at line 88 of file JRootStreamer.hh.

89 {
90 return dictionary;
91 }

◆ get() [1/2]

template<class T >
JRootReader & JROOT::JRootReader::get ( T & object)
inline

Read object according equation format.

Parameters
objectobject
Returns
this ROOT reader

Definition at line 101 of file JRootStreamer.hh.

102 {
103 return this->get(JRootReadableClass(object));
104 }
JRootReader & get(T &object)
Read object according equation format.

◆ get() [2/2]

JRootReader & JROOT::JRootReader::get ( const JRootReadableClass & cls)
inline

Read ROOT class according equation format.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 113 of file JRootStreamer.hh.

114 {
115 using namespace std;
116 using namespace JPP;
117
118 if (cls.is_valid()) {
119
120 const JEquationFacet& facet = use_facet<JEquationFacet>(this->getloc());
121
122 for (JEquation equation; *this >> equation; ) {
123
124 const JRootReadableClass abc = cls.find(equation.getKey().c_str());
125
126 bool status = abc.is_valid();
127
128 if (status) {
129
130 JRedirectString redirect(*this, equation.getValue());
131
132 if (facet.isDivision (equation.getSeparator()))
133 this->get(abc);
134 else if (facet.isSeparator(equation.getSeparator()))
135 this->getObject(abc);
136 else
137 status = false;
138
139 status &= (!this->fail() || this->eof());
140 }
141
142 if (!status) {
143 THROW(JException, "Error parsing: " << equation);
144 }
145 }
146 }
147
148 return *this;
149 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
bool isSeparator(const char c) const
Test for separator character.
bool isDivision(const char c) const
Test for division character.
General purpose equation class.
Definition JEquation.hh:47
General exception.
Definition JException.hh:24
This class can be used to temporarily redirect an input stream to an input string.
JRootReader & getObject(T &object)
Read object.
bool fail(std::istream &in)
Check for stream state.
Definition JParser.hh:98
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool is_valid() const
Check validity of this addressable class.
JRootAddressableClass find(const char *const name) const
Find addressable base class or data member with given name within current class.
ROOT class for reading into object.

◆ getObject() [1/6]

template<class T >
JRootReader & JROOT::JRootReader::getObject ( T & object)
inline

Read object.

Parameters
objectobject
Returns
this ROOT reader

Definition at line 159 of file JRootStreamer.hh.

160 {
161 return this->getObject(object, JBool<JStreamAvailable<T>::has_istream>());
162 }
Test availability of stream operators.

◆ getObject() [2/6]

JRootReader & JROOT::JRootReader::getObject ( const JRootReadableClass & cls)
inline

Read ROOT class.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 171 of file JRootStreamer.hh.

172 {
173 if (cls.is_valid()) {
174
175 JRootDictionary_t::const_iterator i = this->getDictionary().find(cls.getTypename());
176
177 if (i != this->getDictionary().end()) {
178
179 i->second->getObject(*this, cls.getAddress());
180
181 } else if (cls.getClass() != NULL) {
182
183 if (cls.getClass()->GetListOfBases() != NULL) {
184
185 std::unique_ptr<TIterator> i(cls.getClass()->GetListOfBases()->MakeIterator());
186
187 for (const TBaseClass* p; (p = (const TBaseClass*) i->Next()) != NULL && (bool) (*this); ) {
188 this->getObject(cls.get(*p));
189 }
190 }
191
192 if (cls.getClass()->GetListOfDataMembers() != NULL) {
193
194 std::unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator());
195
196 for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL && (bool) (*this); ) {
197 this->getObject(cls.get(*p));
198 }
199 }
200 }
201 }
202
203 return *this;
204 }
const JRootDictionary_t & getDictionary() const
Get dictionary.

◆ getObject() [3/6]

JRootReader & JROOT::JRootReader::getObject ( JRootReadableClass & cls)
inline

Read ROOT class.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 213 of file JRootStreamer.hh.

214 {
215 return getObject(const_cast<const JRootReadableClass&>(cls));
216 }

◆ getObject() [4/6]

template<class T >
JRootReader & JROOT::JRootReader::getObject ( T & object,
const JBool< true > & option )
inlineprivate

Read object.

Parameters
objectobject
optiontrue
Returns
this ROOT reader

Definition at line 227 of file JRootStreamer.hh.

228 {
229 *this >> object;
230
231 return *this;
232 }

◆ getObject() [5/6]

template<class T >
JRootReader & JROOT::JRootReader::getObject ( T & object,
const JBool< false > & option )
inlineprivate

Read object.

Parameters
objectobject
optionfalse
Returns
this ROOT reader

Definition at line 243 of file JRootStreamer.hh.

244 {
245 return this->getObject(JRootReadableClass(object));
246 }

◆ getObject() [6/6]

template<class JElement_t , class JAllocator_t >
JRootReader & JROOT::JRootReader::getObject ( std::vector< JElement_t, JAllocator_t > & object,
const JBool< false > & option )
inlineprivate

Read object.

Parameters
objectobject
optionfalse
Returns
this ROOT reader

Definition at line 257 of file JRootStreamer.hh.

258 {
259 int n = 0;
260
261 this->getObject(n);
262
263 for (JElement_t element; n != 0 && this->getObject(element); --n) {
264 object.push_back(element);
265 }
266
267 return *this;
268 }
const int n
Definition JPolint.hh:791

Member Data Documentation

◆ dictionary

const JRootDictionary_t& JROOT::JRootReader::dictionary
private

Definition at line 271 of file JRootStreamer.hh.

◆ __from

std::ios& JLANG::JStreamState::__from
privateinherited

Definition at line 67 of file JStreamState.hh.

◆ __to

std::ios& JLANG::JStreamState::__to
privateinherited

Definition at line 68 of file JStreamState.hh.


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