Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
JROOT::JRootFileReader< T, false > Class Template Referenceabstract

Tempate specialisation of JRootFileReader for TTree incompatible iteration. More...

#include <JRootFileReader.hh>

Inheritance diagram for JROOT::JRootFileReader< T, false >:
JLANG::JAccessibleObjectIterator< T > JLANG::JRewindableObjectIterator< T > JROOT::JRootInputFile JLANG::JObjectIterator< T > JLANG::JAccessible JLANG::JObjectIterator< T > JLANG::JRewindable< T > JROOT::JRootFile JLANG::JThrow< JAccessible > JLANG::JAccessible JLANG::JStorage< JClass_t, JMemory_t > JLANG::JThrow< JAccessible > JLANG::JPointer< JClass_t > JLANG::JAbstractPointer< JClass_t > JLANG::JEquals< JAbstractPointer< JClass_t > >

Public Types

typedef
JAccessibleObjectIterator< T >
::pointer_type 
pointer_type
 
typedef JMemory_t< JClass_t > memory_type
 

Public Member Functions

 JRootFileReader ()
 Default constructor. More...
 
 JRootFileReader (const char *file_name, const char *key=getName(JType< T >()))
 Constructor. More...
 
virtual void rewind ()
 Rewind. More...
 
virtual void open (const char *file_name)
 Open file. More...
 
virtual bool hasNext ()
 Check availability of next element. More...
 
virtual const pointer_typenext ()
 Get next element. More...
 
virtual skip_type skip (const skip_type ns)
 Skip items. More...
 
Short_t getCycle () const
 Get cycle number of last read object. More...
 
virtual skip_type skip (const skip_type ns)
 Skip items. More...
 
virtual bool is_open () const =0
 Check is device is open. More...
 
virtual void close ()=0
 Close device. More...
 
TFile * getFile () const
 Get file. More...
 
virtual bool is_open () const
 Check is file is open. More...
 
virtual void close ()
 Close file. More...
 
virtual void reset ()
 Reset pointer. More...
 
template<class T >
void reset (const JPointer< T > &pointer)
 Reset pointer. More...
 
void reset (JClass_t *p)
 Reset pointer. More...
 
void recreate ()
 Recreate object in memory. More...
 
void create ()
 Create object in memory. More...
 
void create (const unsigned int size)
 Create array of objects in memory. More...
 
virtual JClass_t * get () const
 Get pointer. More...
 
virtual void set (JClass_t *p)
 Set pointer. More...
 
template<class T >
void set (const JPointer< T > &pointer)
 Set pointer. More...
 
JClass_t *const & getReference () const
 Get rereference to internal pointer. More...
 
JClass_t *& getReference ()
 Get rereference to internal pointer. More...
 
virtual bool equals (const JAbstractPointer &object) const
 Equals. More...
 
bool is_valid () const
 Check validity of pointer. More...
 
JClass_t * operator-> () const
 Smart pointer operator. More...
 
 operator JClass_t * () const
 Type conversion operator. More...
 

Static Public Member Functions

static void Throw (const bool option)
 Enable/disable throw option. More...
 
static int Throw (const JException &error, const int value=-1)
 Throw exception or return error. More...
 

Protected Member Functions

void release ()
 Release memory. More...
 

Protected Attributes

Short_t cycleOld
 
Short_t cycleNew
 
T * __p
 
TString name
 

Static Protected Attributes

static bool do_throw
 throw option More...
 

Detailed Description

template<class T>
class JROOT::JRootFileReader< T, false >

Tempate specialisation of JRootFileReader for TTree incompatible iteration.

The methods JROOT::actionAtFileOpen and JROOT::actionAtFileRead are called at opening of each file and reading of each object, respectively.

This class implements the JLANG::JAccessibleObjectIterator interface.

Definition at line 91 of file JRootFileReader.hh.

Member Typedef Documentation

template<class T >
typedef JAccessibleObjectIterator<T>::pointer_type JROOT::JRootFileReader< T, false >::pointer_type

Definition at line 98 of file JRootFileReader.hh.

template<class JClass_t, template< class > class JMemory_t = JNew>
typedef JMemory_t<JClass_t> JLANG::JStorage< JClass_t, JMemory_t >::memory_type
inherited

Definition at line 33 of file JStorage.hh.

Constructor & Destructor Documentation

template<class T >
JROOT::JRootFileReader< T, false >::JRootFileReader ( )
inline

Default constructor.

Definition at line 104 of file JRootFileReader.hh.

104  :
105  cycleOld(0),
106  cycleNew(1),
107  __p (NULL),
108  name(getName(JType<T>()))
109  {}
const char * getName()
Get ROOT name of given data type.
template<class T >
JROOT::JRootFileReader< T, false >::JRootFileReader ( const char *  file_name,
const char *  key = getName(JType<T>()) 
)
inline

Constructor.

Parameters
file_namefile name
keykey of object to be read

Definition at line 118 of file JRootFileReader.hh.

119  :
120  cycleOld(0),
121  cycleNew(1),
122  __p (NULL),
123  name(key)
124  {
125  open(file_name);
126  }
virtual void open(const char *file_name)
Open file.

Member Function Documentation

template<class T >
virtual void JROOT::JRootFileReader< T, false >::rewind ( )
inlinevirtual

Rewind.

Implements JLANG::JRewindable< T >.

Definition at line 132 of file JRootFileReader.hh.

133  {
134  cycleOld = 0;
135  cycleNew = 1;
136  }
template<class T >
virtual void JROOT::JRootFileReader< T, false >::open ( const char *  file_name)
inlinevirtual

Open file.

Parameters
file_namefile name

Reimplemented from JROOT::JRootInputFile.

Definition at line 144 of file JRootFileReader.hh.

145  {
146  JRootInputFile::open(file_name);
147 
148  actionAtFileOpen<T>(this->getFile());
149 
150  rewind();
151  }
TFile * getFile() const
Get file.
Definition: JRootFile.hh:65
virtual void open(const char *file_name)
Open file.
Definition: JRootFile.hh:131
template<class T >
virtual bool JROOT::JRootFileReader< T, false >::hasNext ( )
inlinevirtual

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 159 of file JRootFileReader.hh.

160  {
161  if (is_open()) {
162 
163  if (cycleOld != cycleNew) {
164 
165  TString key(name);
166 
167  key += ';';
168  key += cycleNew;
169 
170  cycleOld = cycleNew;
171  __p = NULL;
172 
173  getObject(getFile(), key, __p);
174 
175  actionAtFileRead<T>(__p);
176  }
177 
178  return (cycleOld == cycleNew && __p != NULL);
179  }
180 
181  return false;
182  }
TFile * getFile() const
Get file.
Definition: JRootFile.hh:65
void getObject(TFile *file, const char *key, T *&ps)
Read object from ROOT file.
virtual bool is_open() const =0
Check is device is open.
template<class T >
virtual const pointer_type& JROOT::JRootFileReader< T, false >::next ( )
inlinevirtual

Get next element.

Returns
pointer to element.

Implements JLANG::JObjectIterator< T >.

Definition at line 190 of file JRootFileReader.hh.

191  {
192  static pointer_type ps;
193 
194  if (hasNext()) {
195 
196  ++cycleNew;
197 
198  ps.reset(__p);
199 
200  } else {
201 
202  ps.reset(NULL);
203  }
204 
205  return ps;
206  }
virtual bool hasNext()
Check availability of next element.
JAccessibleObjectIterator< T >::pointer_type pointer_type
template<class T >
virtual skip_type JROOT::JRootFileReader< T, false >::skip ( const skip_type  ns)
inlinevirtual

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

Definition at line 215 of file JRootFileReader.hh.

216  {
217  using namespace std;
218 
219  if (ns < (skip_type) cycleNew + (skip_type) numeric_limits<Short_t>::max())
220  cycleNew += (Short_t) ns;
221  else
222  cycleNew = numeric_limits<Short_t>::max();
223 
224  return cycleNew - cycleOld;
225  }
unsigned int skip_type
Type definition for number of objects to skip.
template<class T >
Short_t JROOT::JRootFileReader< T, false >::getCycle ( ) const
inline

Get cycle number of last read object.

Returns
cycle number

Definition at line 233 of file JRootFileReader.hh.

234  {
235  return cycleOld;
236  }
template<class T>
virtual skip_type JLANG::JObjectIterator< T >::skip ( const skip_type  ns)
inlinevirtualinherited

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

Reimplemented in JLANG::JPipe< T >, JLANG::JPipe< JTail_t >, JLANG::JPipe< JHead_t >, JLANG::JSTDObjectIterator< T >, JLANG::JAbstractObjectReader< T >, JLANG::JAbstractObjectReader< JNullType >, JLANG::JAbstractObjectReader< const T >, JLANG::JAbstractObjectReader< JTail_t >, JLANG::JAbstractObjectReader< JHead_t >, JLANG::JAbstractObjectReader< KM3NETDAQ::KM3NETDAQ::JDAQEvent >, JLANG::JAbstractObjectReader< JDAQSummaryslice >, and JLANG::JAbstractObjectReader< JTypeList< JDAQEvent, JTypelist_t > >.

Definition at line 88 of file JObjectIterator.hh.

89  {
90  skip_type i = 0;
91 
92  for ( ; i != ns && hasNext(); ++i) {
93  next();
94  }
95 
96  return i;
97  }
unsigned int skip_type
Type definition for number of objects to skip.
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.
virtual bool JLANG::JAccessible::is_open ( ) const
pure virtualinherited
virtual void JLANG::JAccessible::close ( )
pure virtualinherited
static void JLANG::JThrow< JAccessible >::Throw ( const bool  option)
inlinestaticinherited

Enable/disable throw option.

Parameters
optiontrue enable; false disable

Definition at line 37 of file JThrow.hh.

38  {
39  do_throw = option;
40  }
static bool do_throw
throw option
Definition: JThrow.hh:28
static int JLANG::JThrow< JAccessible >::Throw ( const JException error,
const int  value = -1 
)
inlinestaticinherited

Throw exception or return error.

Parameters
errorexception
valuereturn code
Returns
return code

Definition at line 50 of file JThrow.hh.

51  {
52  using namespace std;
53 
54  if (do_throw) {
55  throw error;
56  }
57 
58  cerr << error.what() << endl;
59 
60  return value;
61  }
static bool do_throw
throw option
Definition: JThrow.hh:28
virtual const char * what() const
Get error message.
Definition: JException.hh:65
TFile* JROOT::JRootFile::getFile ( ) const
inlineinherited

Get file.

Returns
pointer to file

Definition at line 65 of file JRootFile.hh.

66  {
67  return get();
68  }
virtual bool JROOT::JRootFile::is_open ( ) const
inlinevirtualinherited

Check is file is open.

Returns
true if open; else false

Implements JLANG::JAccessible.

Definition at line 76 of file JRootFile.hh.

77  {
78  return (is_valid() && getFile()->IsOpen());
79  }
bool is_valid() const
Check validity of pointer.
TFile * getFile() const
Get file.
Definition: JRootFile.hh:65
virtual void JROOT::JRootFile::close ( )
inlinevirtualinherited

Close file.

Implements JLANG::JAccessible.

Reimplemented in JROOT::JRootOutputFile, JSUPPORT::JAutoTreeWriter< JKey_t >, and JSUPPORT::JAutoTreeWriter< JNET::JTag >.

Definition at line 85 of file JRootFile.hh.

86  {
87  if (is_open()) {
88  getFile()->Close();
89  }
90 
91  reset();
92  }
virtual void reset()
Reset pointer.
Definition: JStorage.hh:42
TFile * getFile() const
Get file.
Definition: JRootFile.hh:65
virtual bool is_open() const
Check is file is open.
Definition: JRootFile.hh:76
template<class JClass_t, template< class > class JMemory_t = JNew>
virtual void JLANG::JStorage< JClass_t, JMemory_t >::reset ( )
inlinevirtualinherited

Reset pointer.

The allocated memory is released.

Reimplemented from JLANG::JPointer< JClass_t >.

Reimplemented in JLANG::JSharedPointer< JClass_t, JMemory_t >, JLANG::JSharedPointer< JPHYSICS::JRadiation >, JLANG::JSharedPointer< JAccessibleObjectIterator< KM3NETDAQ::KM3NETDAQ::JDAQEvent > >, JLANG::JSharedPointer< JObjectIterator< T > >, JLANG::JSharedPointer< JFIT::JMEstimator >, JLANG::JSharedPointer< JAbstractAutoPointer< JBase_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JNullType > >, JLANG::JSharedPointer< match_type >, JLANG::JSharedPointer< JAccessibleObjectIterator< JDAQSummaryslice > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTypeList< JDAQEvent, JTypelist_t > > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTail_t > >, JLANG::JSharedPointer< JLOGGER::JLogger >, JLANG::JSharedPointer< JAccessibleObjectIterator< T > >, JLANG::JSharedPointer< JParserElementInterface >, JLANG::JSharedPointer< const JDETECTOR::JModuleRouter >, JLANG::JSharedPointer< JExceptionHandler >, JLANG::JSharedPointer< JObjectOutput< JHead_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JHead_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JTail_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JHead_t > >, JLANG::JSharedPointer< JObjectOutput< T > >, JLANG::JSharedPointer< JBase_t >, JLANG::JSharedPointer< JObjectOutput< JTail_t > >, JLANG::JSharedPointer< JPropertiesElementInterface >, JLANG::JSharedPointer< JRewindableObjectIterator< const T > >, JLANG::JSharedPointer< JRewindableObjectIterator< T > >, JLANG::JSharedPointer< JAccessibleObjectOutput< T > >, JLANG::JSharedPointer< JNET::JControlHost >, and JLANG::JSharedPointer< JTOOLS::JMultiMapTransformer >.

Definition at line 42 of file JStorage.hh.

43  {
44  if (this->is_valid()) {
45  this->release();
46  }
47 
49  }
bool is_valid() const
Check validity of pointer.
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
void release()
Release memory.
Definition: JStorage.hh:91
template<class JClass_t>
template<class T >
void JLANG::JPointer< JClass_t >::reset ( const JPointer< T > &  pointer)
inlineinherited

Reset pointer.

Parameters
pointerpointer to object

Definition at line 108 of file JPointer.hh.

109  {
110  this->reset(pointer.get());
111  }
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
virtual JClass_t * get() const
Get pointer.
Definition: JPointer.hh:64
template<class JClass_t>
void JLANG::JAbstractPointer< JClass_t >::reset ( JClass_t *  p)
inlineinherited

Reset pointer.

Parameters
ppointer to object

Definition at line 92 of file JAbstractPointer.hh.

93  {
94  if (this->get() != p) {
95 
96  this->reset();
97 
98  if (p != NULL) {
99  this->set(p);
100  }
101  }
102  }
virtual void reset()=0
Reset pointer.
virtual void set(JClass_t *p)=0
Set pointer.
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::recreate ( )
inlineinherited

Recreate object in memory.

A new object is created if no memory is allocated yet, else the previously created object is maintained.

Definition at line 57 of file JStorage.hh.

58  {
59  if (!this->is_valid()) {
60  this->set(memory_type::create());
61  }
62  }
bool is_valid() const
Check validity of pointer.
virtual void set(JClass_t *p)
Set pointer.
Definition: JPointer.hh:75
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::create ( )
inlineinherited

Create object in memory.

The memory allocated by a previously created object will be released.

Definition at line 69 of file JStorage.hh.

70  {
71  this->reset(memory_type::create());
72  }
virtual void reset()
Reset pointer.
Definition: JStorage.hh:42
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::create ( const unsigned int  size)
inlineinherited

Create array of objects in memory.

The memory allocated by previously created objects will be released.

Parameters
sizenumber of elements

Definition at line 81 of file JStorage.hh.

82  {
83  this->reset(memory_type::create(size));
84  }
virtual void reset()
Reset pointer.
Definition: JStorage.hh:42
template<class JClass_t, template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::release ( )
inlineprotectedinherited

Release memory.

Definition at line 91 of file JStorage.hh.

92  {
93  memory_type::release(this->get());
94  }
template<class JClass_t>
virtual JClass_t* JLANG::JPointer< JClass_t >::get ( ) const
inlinevirtualinherited
template<class JClass_t>
virtual void JLANG::JPointer< JClass_t >::set ( JClass_t *  p)
inlinevirtualinherited

Set pointer.

Parameters
ppointer to object

Implements JLANG::JAbstractPointer< JClass_t >.

Reimplemented in JLANG::JSharedPointer< JClass_t, JMemory_t >, JLANG::JSharedPointer< JPHYSICS::JRadiation >, JLANG::JSharedPointer< JAccessibleObjectIterator< KM3NETDAQ::KM3NETDAQ::JDAQEvent > >, JLANG::JSharedPointer< JObjectIterator< T > >, JLANG::JSharedPointer< JFIT::JMEstimator >, JLANG::JSharedPointer< JAbstractAutoPointer< JBase_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JNullType > >, JLANG::JSharedPointer< match_type >, JLANG::JSharedPointer< JAccessibleObjectIterator< JDAQSummaryslice > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTypeList< JDAQEvent, JTypelist_t > > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTail_t > >, JLANG::JSharedPointer< JLOGGER::JLogger >, JLANG::JSharedPointer< JAccessibleObjectIterator< T > >, JLANG::JSharedPointer< JParserElementInterface >, JLANG::JSharedPointer< const JDETECTOR::JModuleRouter >, JLANG::JSharedPointer< JExceptionHandler >, JLANG::JSharedPointer< JObjectOutput< JHead_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JHead_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JTail_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JHead_t > >, JLANG::JSharedPointer< JObjectOutput< T > >, JLANG::JSharedPointer< JBase_t >, JLANG::JSharedPointer< JObjectOutput< JTail_t > >, JLANG::JSharedPointer< JPropertiesElementInterface >, JLANG::JSharedPointer< JRewindableObjectIterator< const T > >, JLANG::JSharedPointer< JRewindableObjectIterator< T > >, JLANG::JSharedPointer< JAccessibleObjectOutput< T > >, JLANG::JSharedPointer< JNET::JControlHost >, and JLANG::JSharedPointer< JTOOLS::JMultiMapTransformer >.

Definition at line 75 of file JPointer.hh.

76  {
77  this->__p = p;
78  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
template<class JClass_t>
template<class T >
void JLANG::JPointer< JClass_t >::set ( const JPointer< T > &  pointer)
inlineinherited

Set pointer.

Parameters
pointerpointer to object

Definition at line 96 of file JPointer.hh.

97  {
98  this->set(pointer.get());
99  }
virtual JClass_t * get() const
Get pointer.
Definition: JPointer.hh:64
virtual void set(JClass_t *p)
Set pointer.
Definition: JPointer.hh:75
template<class JClass_t>
JClass_t* const& JLANG::JPointer< JClass_t >::getReference ( ) const
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 119 of file JPointer.hh.

120  {
121  return __p;
122  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
template<class JClass_t>
JClass_t* & JLANG::JPointer< JClass_t >::getReference ( )
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 130 of file JPointer.hh.

131  {
132  return __p;
133  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
template<class JClass_t>
virtual bool JLANG::JAbstractPointer< JClass_t >::equals ( const JAbstractPointer< JClass_t > &  object) const
inlinevirtualinherited

Equals.

The equality is evaluated by comparison of the internal pointers.

Parameters
objectabstract pointer
Returns
true if equals; else false

Definition at line 48 of file JAbstractPointer.hh.

49  {
50  return this->get() == object.get();
51  }
template<class JClass_t>
bool JLANG::JAbstractPointer< JClass_t >::is_valid ( ) const
inlineinherited

Check validity of pointer.

Returns
true if pointer not null; else false

Definition at line 81 of file JAbstractPointer.hh.

82  {
83  return this->get() != NULL;
84  }
template<class JClass_t>
JClass_t* JLANG::JAbstractPointer< JClass_t >::operator-> ( ) const
inlineinherited

Smart pointer operator.

Returns
pointer to object

Definition at line 110 of file JAbstractPointer.hh.

111  {
112  if (!is_valid())
113  throw JNullPointerException("JAbstractPointer::operator->()");
114  else
115  return this->get();
116  }
bool is_valid() const
Check validity of pointer.
Exception for null pointer operation.
Definition: JException.hh:198
template<class JClass_t>
JLANG::JAbstractPointer< JClass_t >::operator JClass_t * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 124 of file JAbstractPointer.hh.

125  {
126  return this->get();
127  }

Member Data Documentation

template<class T >
Short_t JROOT::JRootFileReader< T, false >::cycleOld
protected

Definition at line 239 of file JRootFileReader.hh.

template<class T >
Short_t JROOT::JRootFileReader< T, false >::cycleNew
protected

Definition at line 240 of file JRootFileReader.hh.

template<class T >
T* JROOT::JRootFileReader< T, false >::__p
protected

Definition at line 241 of file JRootFileReader.hh.

template<class T >
TString JROOT::JRootFileReader< T, false >::name
protected

Definition at line 242 of file JRootFileReader.hh.

bool JLANG::JThrow< JAccessible >::do_throw
staticprotectedinherited

throw option

Set default throw option to true.

Definition at line 28 of file JThrow.hh.


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