Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JROOT::JRootFileReader< T, false > Class Template Reference

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

Static Public Member Functions

static void Throw (const bool option)
 Enable/disable throw option.
 
static int Throw (const JException_t &error, const int value=-1)
 Throw exception or return error.
 
static void release (JClass_t *p)
 Release memory.
 

Protected Member Functions

void release ()
 Release memory.
 

Protected Attributes

Short_t cycleOld
 
Short_t cycleNew
 
T * __p
 
TString name
 

Static Protected Attributes

static bool do_throw
 throw option
 

Private Member Functions

void do_open (const char *file_name)
 Open file.
 
void do_close ()
 Close file.
 

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 66 of file JRootFileReader.hh.

Member Typedef Documentation

◆ pointer_type

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

Definition at line 73 of file JRootFileReader.hh.

◆ memory_type

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

Definition at line 33 of file JStorage.hh.

Constructor & Destructor Documentation

◆ JRootFileReader() [1/2]

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

Default constructor.

Definition at line 79 of file JRootFileReader.hh.

79 :
80 cycleOld(0),
81 cycleNew(1),
82 __p (NULL),
83 name(getName(JType<T>()))
84 {}
const char * getName()
Get ROOT name of given data type.

◆ JRootFileReader() [2/2]

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 93 of file JRootFileReader.hh.

94 :
95 cycleOld(0),
96 cycleNew(1),
97 __p (NULL),
98 name(key)
99 {
100 open(file_name);
101 }
virtual void open(const char *file_name) override
Open file.

Member Function Documentation

◆ rewind()

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

Rewind.

Implements JLANG::JRewindable< T >.

Definition at line 107 of file JRootFileReader.hh.

108 {
109 cycleOld = 0;
110 cycleNew = 1;
111 }

◆ open()

template<class T >
virtual void JROOT::JRootFileReader< T, false >::open ( const char * file_name)
inlineoverridevirtual

Open file.

Parameters
file_namefile name

Implements JLANG::JAccessible.

Definition at line 119 of file JRootFileReader.hh.

120 {
121 JRootInputFile::open(file_name);
122
124
125 rewind();
126 }
virtual void rewind() override
Rewind.
TFile * getFile() const
Get file.
Definition JRootFile.hh:66
virtual void open(const char *file_name) override
Open file.
Definition JRootFile.hh:136
void actionAtFileOpen(TFile *file)
General action method at file open.

◆ hasNext()

template<class T >
virtual bool JROOT::JRootFileReader< T, false >::hasNext ( )
inlineoverridevirtual

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 134 of file JRootFileReader.hh.

135 {
136 if (is_open()) {
137
138 if (cycleOld != cycleNew) {
139
140 TString key(name);
141
142 key += ';';
143 key += cycleNew;
144
146 __p = NULL;
147
148 getObject(getFile(), key, __p);
149
151 }
152
153 return (cycleOld == cycleNew && __p != NULL);
154 }
155
156 return false;
157 }
virtual bool is_open() const =0
Check is device is open.
void actionAtFileRead(T *object)
General action method at file read.
void getObject(TFile *file, const TString &key, T *&ps)
Read object from ROOT file.

◆ next()

template<class T >
virtual const pointer_type & JROOT::JRootFileReader< T, false >::next ( )
inlineoverridevirtual

Get next element.

Returns
pointer to element.

Implements JLANG::JObjectIterator< T >.

Definition at line 165 of file JRootFileReader.hh.

166 {
167 static pointer_type ps;
168
169 if (hasNext()) {
170
171 ++cycleNew;
172
173 ps.reset(__p);
174
175 } else {
176
177 ps.reset(NULL);
178 }
179
180 return ps;
181 }
virtual bool hasNext() override
Check availability of next element.
JAccessibleObjectIterator< T >::pointer_type pointer_type

◆ skip()

template<class T >
virtual skip_type JROOT::JRootFileReader< T, false >::skip ( const skip_type ns)
inlineoverridevirtual

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

Reimplemented from JLANG::JObjectIterator< T >.

Definition at line 190 of file JRootFileReader.hh.

191 {
192 using namespace std;
193
194 if (ns < (skip_type) cycleNew + (skip_type) numeric_limits<Short_t>::max())
195 cycleNew += (Short_t) ns;
196 else
197 cycleNew = numeric_limits<Short_t>::max();
198
199 return cycleNew - cycleOld;
200 }
unsigned int skip_type
Type definition for number of objects to skip.

◆ getCycle()

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 208 of file JRootFileReader.hh.

209 {
210 return cycleOld;
211 }

◆ close()

virtual void JROOT::JRootInputFile::close ( )
inlineoverridevirtualinherited

Close file.

Implements JLANG::JAccessible.

Definition at line 145 of file JRootFile.hh.

146 {
147 do_close();
148 }
void do_close()
Close file.
Definition JRootFile.hh:180

◆ do_open()

void JROOT::JRootInputFile::do_open ( const char * file_name)
inlineprivateinherited

Open file.

The file is not opened when no file exists with the given name.

Parameters
file_namefile name

Definition at line 158 of file JRootFile.hh.

159 {
160 set(TFile::Open(file_name, "READ"));
161
162 if (!is_open()) {
163 Throw(MAKE_EXCEPTION(JFileOpenException, "Error opening file " << file_name));
164 }
165
166 if (getFile()->TestBit(TFile::kRecovered)) {
167
168 const char* const value = getenv(ROOT_FILE_RECOVERY_DISABLE);
169
170 if (value != NULL && strcmp(value,"0") != 0) {
171 Throw(MAKE_EXCEPTION(JFileRecoveryException, "Error recovery file " << file_name << " disabled"));
172 }
173 }
174 }
#define MAKE_EXCEPTION(JException_t, A)
Make exception.
virtual void set(JClass_t *p) override
Set pointer.
Definition JPointer.hh:75
static void Throw(const bool option)
Definition JThrow.hh:37
virtual bool is_open() const override
Check is file is open.
Definition JRootFile.hh:77
static const char *const ROOT_FILE_RECOVERY_DISABLE
Environment variable to disable ROOT file recovery.
Definition JRootFile.hh:37

◆ do_close()

void JROOT::JRootInputFile::do_close ( )
inlineprivateinherited

Close file.

Definition at line 180 of file JRootFile.hh.

181 {
182 if (getFile() != NULL && getFile()->IsOpen()) {
183 getFile()->Close();
184 }
185
186 reset();
187 }
virtual void reset() override
Reset pointer.
Definition JStorage.hh:42

◆ getFile()

TFile * JROOT::JRootFile::getFile ( ) const
inlineinherited

Get file.

Returns
pointer to file

Definition at line 66 of file JRootFile.hh.

67 {
68 return get();
69 }
virtual JClass_t * get() const override
Get pointer.
Definition JPointer.hh:64

◆ is_open()

virtual bool JROOT::JRootFile::is_open ( ) const
inlineoverridevirtualinherited

Check is file is open.

Returns
true if open; else false

Implements JLANG::JAccessible.

Definition at line 77 of file JRootFile.hh.

78 {
79 return (getFile() != NULL && getFile()->IsOpen());
80 }

◆ Throw() [1/2]

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 }

◆ Throw() [2/2]

static int JLANG::JThrow< JAccessible >::Throw ( const JException_t & error,
const int value = -1 )
inlinestaticinherited

Throw exception or return error.

Parameters
errorexception
valuereturn code
Returns
return code

Definition at line 51 of file JThrow.hh.

52 {
53 using namespace std;
54
55 if (do_throw) {
56 throw error;
57 }
58
59 cerr << error.what() << endl;
60
61 return value;
62 }

◆ reset() [1/3]

template<class JClass_t , template< class > class JMemory_t = JNew>
virtual void JLANG::JStorage< JClass_t, JMemory_t >::reset ( )
inlineoverridevirtualinherited

Reset pointer.

The allocated memory is released.

Reimplemented from JLANG::JPointer< JClass_t >.

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

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() override
Reset pointer.
Definition JPointer.hh:84
void release()
Release memory.
Definition JStorage.hh:91

◆ reset() [2/3]

template<class JClass_t , template< class > class JMemory_t = JNew>
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 }

◆ reset() [3/3]

template<class JClass_t >
void JLANG::JAbstractPointer< JClass_t >::reset ( JClass_t * p)
inlineinherited

Reset pointer.

Parameters
ppointer to object

Definition at line 94 of file JAbstractPointer.hh.

95 {
96 if (this->get() != p) {
97
98 this->reset();
99
100 if (p != NULL) {
101 this->set(p);
102 }
103 }
104 }
virtual void set(JClass_t *p)=0
Set pointer.
virtual JClass_t * get() const =0
Get pointer.
virtual void reset()=0
Reset pointer.

◆ recreate()

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 }

◆ create() [1/2]

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 }

◆ create() [2/2]

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 }

◆ release() [1/2]

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 }

◆ release() [2/2]

template<class JClass_t >
static void JLANG::JNew< JClass_t >::release ( JClass_t * p)
inlinestaticinherited

Release memory.

Parameters
ppointer to data

Definition at line 41 of file JMemory.hh.

42 {
43 delete p;
44 }

◆ get()

template<class JClass_t >
virtual JClass_t * JLANG::JPointer< JClass_t >::get ( ) const
inlineoverridevirtualinherited

◆ set() [1/2]

template<class JClass_t >
virtual void JLANG::JPointer< JClass_t >::set ( JClass_t * p)
inlineoverridevirtualinherited

Set pointer.

Parameters
ppointer to object

Implements JLANG::JAbstractPointer< JClass_t >.

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

Definition at line 75 of file JPointer.hh.

76 {
77 this->__p = p;
78 }

◆ set() [2/2]

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 }

◆ getReference() [1/2]

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 }

◆ getReference() [2/2]

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 }

◆ equals()

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 50 of file JAbstractPointer.hh.

51 {
52 return this->get() == object.get();
53 }

◆ is_valid()

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 83 of file JAbstractPointer.hh.

84 {
85 return this->get() != NULL;
86 }

◆ operator->()

template<class JClass_t >
JClass_t * JLANG::JAbstractPointer< JClass_t >::operator-> ( ) const
inlineinherited

Smart pointer operator.

Returns
pointer to object

Definition at line 112 of file JAbstractPointer.hh.

113 {
114 if (!is_valid())
115 THROW(JNullPointerException, "JAbstractPointer::operator->()");
116 else
117 return this->get();
118 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.

◆ operator JClass_t *()

template<class JClass_t >
JLANG::JAbstractPointer< JClass_t >::operator JClass_t * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 126 of file JAbstractPointer.hh.

127 {
128 return this->get();
129 }

Member Data Documentation

◆ cycleOld

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

Definition at line 214 of file JRootFileReader.hh.

◆ cycleNew

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

Definition at line 215 of file JRootFileReader.hh.

◆ __p

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

Definition at line 216 of file JRootFileReader.hh.

◆ name

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

Definition at line 217 of file JRootFileReader.hh.

◆ do_throw

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: