Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
JROOT::JRootReader Class Reference

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

#include <JRootStreamer.hh>

Inheritance diagram for JROOT::JRootReader:
JLANG::JStreamState

Classes

struct  JDefaultHelper
 Default helper class for formatting. More...
 
struct  JHelper
 Helper class for user formatting. More...
 
struct  JHelper< vector< JAANET::physics > >
 Specialisation of std::vector<JAANET::physics> for reading one element at a time. More...
 

Public Member Functions

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

Static Public Member Functions

template<class T >
static JRootReadergetObject (JRootReader &reader, T &object)
 Read object. More...
 

Protected Member Functions

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

Protected Attributes

const JRootDictionary_tdictionary
 

Detailed Description

Implementation for ASCII input of objects with ROOT dictionary.

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

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

and method JRootReader::getObject with 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 61 of file JRootStreamer.hh.

Constructor & Destructor Documentation

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

Constructor.

Parameters
ininput stream
parametersequation parameters
dictionarydictionary

Definition at line 105 of file JRootStreamer.hh.

107  :
108  std::istream(in.rdbuf()),
109  JStreamState(in, static_cast<std::istream&>(*this)),
110  dictionary(dictionary)
111  {
112  imbue(std::locale(in.getloc(), new JLANG::JEquationFacet(parameters)));
113  }
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
JStreamState(std::ostream &from, std::ostream &to)
Constructor.
Definition: JStreamState.hh:32
const JRootDictionary_t & dictionary

Member Function Documentation

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

Get dictionary.

Returns
dictionary

Definition at line 121 of file JRootStreamer.hh.

122  {
123  return dictionary;
124  }
const JRootDictionary_t & dictionary
template<class T >
static JRootReader& JROOT::JRootReader::getObject ( JRootReader reader,
T &  object 
)
inlinestatic

Read object.

This method transfers the reading of the given object to the template JHelper class so that the default format can be changed through specialisation of this class.

Parameters
readerROOT reader
objectobject
Returns
ROOT reader

Definition at line 138 of file JRootStreamer.hh.

139  {
140  return JRootReader::JHelper<T>::getObject(reader, object);
141  }
static JRootReader & getObject(JRootReader &reader, T &object)
Read object.
template<class T >
JRootReader& JROOT::JRootReader::get ( T &  object)
inline

Read object according equation format.

Parameters
objectobject
Returns
this ROOT reader

Definition at line 151 of file JRootStreamer.hh.

152  {
153  return this->get(JRootClassReader(object));
154  }
ROOT class for reading object.
Definition: JRootClass.hh:478
template<class T >
JRootReader& JROOT::JRootReader::getObject ( T &  object)
inline

Read object.

Parameters
objectobject
Returns
this ROOT reader

Definition at line 164 of file JRootStreamer.hh.

165  {
166  return this->getObject(object, JBool<JRedirectAvailable<T>::has_istream>());
167  }
static JRootReader & getObject(JRootReader &reader, T &object)
Read object.
Auxiliary template class for type bool.
Definition: JBool.hh:20
Test availability of redirect operators.
JRootReader& JROOT::JRootReader::get ( const JRootClassReader cls)
inline

Read ROOT class according equation format.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 176 of file JRootStreamer.hh.

177  {
178  using namespace std;
179  using namespace JLANG;
180 
181  if (cls.is_valid()) {
182 
183  const JEquationFacet& facet = use_facet<JEquationFacet>(this->getloc());
184 
185  for (JEquation equation; *this >> equation; ) {
186 
187  const JRootClassReader abc = cls.find(equation.getKey().c_str());
188 
189  bool okay = abc.is_valid();
190 
191  if (okay) {
192 
193  JRedirectString redirect(*this, equation.getValue());
194 
195  if (facet.isDivision (equation.getSeparator()))
196  this->get(abc);
197  else if (facet.isSeparator(equation.getSeparator()))
198  this->getObject(abc);
199  else
200  okay = false;
201 
202  okay &= (!this->fail() || this->eof());
203  }
204 
205  if (!okay) {
206  throw JException("Error parsing: " + equation.toString());
207  }
208  }
209  }
210 
211  return *this;
212  }
General exception.
Definition: JException.hh:40
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
static JRootReader & getObject(JRootReader &reader, T &object)
Read object.
bool is_valid() const
Check validity of this addressable class.
Definition: JRootClass.hh:422
General purpose equation class.
Definition: JEquation.hh:47
ROOT class for reading object.
Definition: JRootClass.hh:478
bool fail(std::istream &in)
Check for stream state.
Definition: JParser.hh:93
bool isSeparator(const char c) const
Test for separator character.
bool isDivision(const char c) const
Test for division character.
JRootAddressableClass find(const char *name) const
Find addressable base class or data member with given name within current class.
Definition: JRootClass.hh:433
This class can be used to temporarily redirect an input stream to an input string.
JRootReader& JROOT::JRootReader::getObject ( const JRootClassReader cls)
inline

Read ROOT class.

Parameters
clsROOT class
Returns
this ROOT reader

Definition at line 221 of file JRootStreamer.hh.

222  {
223  if (cls.is_valid()) {
224 
225  JRootDictionary_t::const_iterator i = this->getDictionary().find(cls.getTypename());
226 
227  if (i != this->getDictionary().end()) {
228 
229  i->second->getObject(*this, cls.getAddress());
230 
231  } else if (cls.getClass() != NULL) {
232 
233  if (cls.getClass()->GetListOfBases() != NULL) {
234 
235  TIterator* i = cls.getClass()->GetListOfBases()->MakeIterator();
236 
237  for (const TBaseClass* p; (p = (const TBaseClass*) i->Next()) != NULL && (bool) (*this); ) {
238  this->getObject(cls.get(*p));
239  }
240  }
241 
242  if (cls.getClass()->GetListOfDataMembers() != NULL) {
243 
244  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
245 
246  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL && (bool) (*this); ) {
247  this->getObject(cls.get(*p));
248  }
249  }
250  }
251  }
252 
253  return *this;
254  }
const char * getTypename() const
Get type name.
Definition: JRootClass.hh:178
pointer_type getAddress() const
Get address.
Definition: JRootClass.hh:411
static JRootReader & getObject(JRootReader &reader, T &object)
Read object.
bool is_valid() const
Check validity of this addressable class.
Definition: JRootClass.hh:422
JRootAddressableClass get(const TDataMember &data_member) const
Get addressable class of given data member.
Definition: JRootClass.hh:444
TClass * getClass() const
Get class.
Definition: JRootClass.hh:167
const JRootDictionary_t & getDictionary() const
Get dictionary.
template<class T >
JRootReader& JROOT::JRootReader::getObject ( T &  object,
const JBool< true > &  option 
)
inlineprotected

Read object.

Parameters
objectobject
optiontrue
Returns
this ROOT reader

Definition at line 266 of file JRootStreamer.hh.

267  {
268  *this >> object;
269 
270  return *this;
271  }
template<class T >
JRootReader& JROOT::JRootReader::getObject ( T &  object,
const JBool< false > &  option 
)
inlineprotected

Read object.

Parameters
objectobject
optionfalse
Returns
this ROOT reader

Definition at line 282 of file JRootStreamer.hh.

283  {
284  return this->getObject(JRootClassReader(object));
285  }
static JRootReader & getObject(JRootReader &reader, T &object)
Read object.
ROOT class for reading object.
Definition: JRootClass.hh:478
template<class JElement_t , class JAllocator_t >
JRootReader& JROOT::JRootReader::getObject ( std::vector< JElement_t, JAllocator_t > &  object,
const JBool< false > &  option 
)
inlineprotected

Read object.

Parameters
objectobject
optionfalse
Returns
this ROOT reader

Definition at line 296 of file JRootStreamer.hh.

297  {
298  int n = 0;
299 
300  this->getObject(n);
301 
302  for (JElement_t element; n != 0 && this->getObject(element); --n) {
303  object.push_back(element);
304  }
305 
306  return *this;
307  }
static JRootReader & getObject(JRootReader &reader, T &object)
Read object.

Member Data Documentation

const JRootDictionary_t& JROOT::JRootReader::dictionary
protected

Definition at line 310 of file JRootStreamer.hh.


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